:root {
  --bg: #0b1410;
  --bg-2: #101c16;
  --panel: #14231b;
  --panel-2: #1a2d23;
  --line: #24392e;
  --line-2: #2f4a3c;
  --text: #e8efe9;
  --muted: #8fa597;
  --green: #2fae66;
  --green-2: #1f8a4f;
  --gold: #c9a34a;
  --gold-2: #e4c675;
  --red: #d9534f;
  --orange: #e39b3b;
  --blue: #4f8fd9;
  --radius: 10px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: radial-gradient(1200px 600px at 10% -10%, #163024 0%, transparent 60%), var(--bg);
  color: var(--text);
  font: 14px/1.5 Inter, system-ui, sans-serif;
}
.hidden { display: none !important; }
a { color: var(--gold-2); }
h1, h2, h3 { margin: 0; font-weight: 700; }
h1 { font-family: Cinzel, serif; font-size: 26px; letter-spacing: .5px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* ---------- Brand */
.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  width: 40px; height: 40px; flex: none;
  background: url(favicon.svg) center / contain no-repeat;
  filter: drop-shadow(0 2px 6px rgba(47, 174, 102, .35));
}
.brand-name { font-family: Cinzel, serif; font-size: 19px; font-weight: 700; color: var(--gold-2); line-height: 1.1; }
.brand-sub { font-size: 12px; color: var(--muted); }
.brand.big .logo { width: 64px; height: 64px; }
.brand.big .brand-name { font-size: 28px; }

/* ---------- Auth */
.auth { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.auth-card {
  width: 100%; max-width: 400px; background: var(--panel); border: 1px solid var(--line);
  border-top: 3px solid var(--gold); border-radius: var(--radius); padding: 28px; box-shadow: var(--shadow);
}
.auth-card .brand { margin-bottom: 22px; }

/* ---------- Forms */
label { display: grid; gap: 5px; margin-bottom: 12px; font-size: 12px; font-weight: 600; color: var(--muted); }
input, select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--bg-2);
  border: 1px solid var(--line-2); border-radius: 8px; padding: 9px 11px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(47, 174, 102, .18); }
textarea { min-height: 90px; resize: vertical; }
input[type=color] { padding: 2px; height: 38px; }
input[type=checkbox] { width: auto; }
label.check { display: flex; align-items: center; gap: 8px; color: var(--text); font-weight: 500; font-size: 14px; }
.form-error { color: #ff8b87; min-height: 0; margin: 0 0 10px; font-size: 13px; }
.form-error:empty { display: none; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 12px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: 600 13px Inter, sans-serif; color: var(--text); background: var(--panel-2);
  border: 1px solid var(--line-2); border-radius: 8px; padding: 8px 13px; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--green); }
.btn.primary { background: linear-gradient(180deg, var(--green), var(--green-2)); border-color: var(--green-2); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.gold { background: linear-gradient(180deg, var(--gold-2), var(--gold)); border-color: var(--gold); color: #1a1408; }
.btn.danger { color: #ffb3b0; border-color: #5a2a29; background: #2a1514; }
.btn.danger:hover { border-color: var(--red); }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 9px; font-size: 12px; }
.btn.wide { width: 100%; padding: 11px; }
.btn.active { border-color: var(--gold); color: var(--gold-2); }
.icon-btn { background: none; border: 0; color: var(--muted); font-size: 18px; cursor: pointer; padding: 4px 8px; border-radius: 6px; }
.icon-btn:hover { color: var(--text); background: var(--panel-2); }

/* ---------- Layout */
.app { display: grid; grid-template-columns: 240px 1fr; height: 100%; }
.sidebar {
  background: linear-gradient(180deg, #0f1d16, #0b1511); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 18px 14px; gap: 18px; min-height: 0;
}
.menu-toggle { display: none; margin-left: auto; }
nav { display: grid; gap: 2px; flex: 1; align-content: start; }
nav a {
  display: flex; align-items: center; gap: 11px; padding: 9px 11px; border-radius: 8px;
  color: var(--muted); text-decoration: none; font-weight: 500;
}
nav a span { width: 18px; text-align: center; color: var(--green); font-weight: 700; }
nav a:hover { background: var(--panel); color: var(--text); }
nav a.active { background: var(--panel-2); color: var(--text); box-shadow: inset 3px 0 0 var(--gold); }
.user-box { border-top: 1px solid var(--line); padding-top: 14px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.user-box > div { flex: 1 1 100%; }
.user-name { font-weight: 600; }
.user-role { font-size: 12px; color: var(--gold); text-transform: capitalize; }

main { min-width: 0; min-height: 0; overflow: auto; }
.view { display: none; padding: 26px 28px 40px; max-width: 1400px; }
.view.active { display: block; }
.view-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.view-head p { margin: 4px 0 0; color: var(--muted); }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.card + .card { margin-top: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; position: relative; overflow: hidden; }
.stat::after { content: ""; position: absolute; inset: 0 auto 0 0; width: 3px; background: var(--green); }
.stat.gold::after { background: var(--gold); }
.stat-label { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .6px; }
.stat-value { font-size: 26px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat-sub { font-size: 12px; color: var(--muted); }
.cols { display: grid; grid-template-columns: 1.3fr 1fr; gap: 16px; align-items: start; }

/* ---------- Tabellen */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); font-weight: 600; white-space: nowrap; }
tbody tr:hover { background: rgba(255, 255, 255, .02); }
td.actions { text-align: right; white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }

.filters { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; align-items: center; }
.filters input[type=search] { max-width: 280px; }
.filters select { width: auto; }
.pill {
  display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: var(--panel-2); border: 1px solid var(--line-2); white-space: nowrap;
}
.pill.aktiv { color: #7ee2a8; border-color: #285c40; background: #12301f; }
.pill.probezeit { color: #9cc7ff; border-color: #2c4a70; background: #142336; }
.pill.urlaub { color: #ffd38a; border-color: #6a5223; background: #2c2312; }
.pill.inaktiv { color: #c4c4c4; }
.pill.ausgetreten { color: #ffaaa7; border-color: #5a2a29; background: #2a1514; }
.pill.rank { color: var(--gold-2); border-color: #5a4a22; background: #231d0f; }
.plus { color: #7ee2a8; }
.minus { color: #ff8b87; }

/* ---------- Ankündigungen & Log */
.post { border-left: 3px solid var(--line-2); padding: 4px 0 4px 14px; }
.post + .post { margin-top: 16px; }
.post.pinned { border-left-color: var(--gold); }
.post-meta { font-size: 12px; color: var(--muted); }
.post-text { white-space: pre-wrap; margin: 6px 0 0; }
.log-list { list-style: none; margin: 0; padding: 0; }
.log-list li { display: flex; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.log-list time { color: var(--muted); font-size: 12px; min-width: 112px; font-variant-numeric: tabular-nums; }

/* ---------- Karte */
.view.map-view { padding: 0; max-width: none; height: 100%; flex-direction: column; }
.view.map-view.active { display: flex; }
.map-toolbar {
  display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  padding: 12px 16px; border-bottom: 1px solid var(--line); background: var(--bg-2);
}
.toolbar-group { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.toolbar-group input, .toolbar-group select { width: auto; padding: 7px 10px; }
.map-wrap { position: relative; flex: 1; min-height: 420px; }
#map { position: absolute; inset: 0; background: #143d59; }
#map.picking { cursor: crosshair; }
/* Beim Setzen/Zeichnen klickt man durch vorhandene Gebiete hindurch */
#map.picking .leaflet-pane > svg path.leaflet-interactive { pointer-events: none; }
.map-panel {
  position: absolute; top: 12px; right: 12px; z-index: 500; width: 250px; max-height: calc(100% - 60px); overflow: auto;
  background: rgba(16, 28, 22, .94); border: 1px solid var(--line-2); border-radius: var(--radius); padding: 12px; box-shadow: var(--shadow);
}
.map-panel.collapsed .panel-body { display: none; }
.map-panel h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); margin: 12px 0 6px; }
.map-panel .panel-top { display: flex; justify-content: space-between; align-items: center; }
.map-panel .panel-top h3 { margin: 0; color: var(--gold-2); }
.layer-row { display: flex; align-items: center; gap: 8px; padding: 3px 0; cursor: pointer; font-size: 13px; color: var(--text); font-weight: 500; margin: 0; }
.layer-row .count { margin-left: auto; color: var(--muted); font-size: 12px; }
.panel-list { list-style: none; margin: 0; padding: 0; }
.panel-list li { padding: 5px 6px; border-radius: 6px; cursor: pointer; font-size: 13px; display: flex; gap: 6px; align-items: center; }
.panel-list li:hover { background: var(--panel-2); }
.map-hint {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 600;
  background: var(--gold); color: #1a1408; font-weight: 600; padding: 8px 14px; border-radius: 999px; box-shadow: var(--shadow);
  display: flex; gap: 10px; align-items: center;
}
.map-hint .btn { background: #1a1408; color: var(--gold-2); border-color: #1a1408; }
.map-coords {
  position: absolute; left: 12px; bottom: 12px; z-index: 500; background: rgba(11, 20, 16, .88);
  border: 1px solid var(--line-2); padding: 4px 10px; border-radius: 6px; font: 12px ui-monospace, Consolas, monospace; color: var(--muted);
}

.mk {
  width: 30px; height: 30px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg);
  display: grid; place-items: center; border: 2px solid #0b1410; box-shadow: 0 2px 6px rgba(0, 0, 0, .5);
}
.mk span { transform: rotate(45deg); font-size: 14px; line-height: 1; }
.mk.search-hit { outline: 3px solid var(--gold-2); }

.leaflet-container { font: 13px Inter, sans-serif; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--panel); color: var(--text); border: 1px solid var(--line-2); }
.leaflet-popup-content { margin: 14px 16px; min-width: 220px; }
.leaflet-container a.leaflet-popup-close-button { color: var(--muted); }
.leaflet-tooltip { background: var(--panel); color: var(--text); border-color: var(--line-2); }
.leaflet-tooltip-top::before { border-top-color: var(--line-2); }
.leaflet-bar a, .leaflet-control-layers { background: var(--panel); color: var(--text); border-color: var(--line-2); }
.leaflet-bar a:hover { background: var(--panel-2); }
.leaflet-control-attribution { background: rgba(11, 20, 16, .7) !important; color: var(--muted) !important; }
.leaflet-control-attribution a { color: var(--muted); }
.pop-title { font-weight: 700; font-size: 15px; margin-bottom: 2px; }
.pop-cat { font-size: 12px; color: var(--gold-2); }
.pop-desc { white-space: pre-wrap; margin: 8px 0; }
.pop-meta { font-size: 11px; color: var(--muted); }
.pop-coords { font: 12px ui-monospace, Consolas, monospace; background: var(--bg-2); padding: 4px 6px; border-radius: 5px; margin: 6px 0; display: block; }
.pop-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }

/* ---------- Dialog & Toasts */
dialog {
  width: min(560px, calc(100% - 32px)); padding: 0; border: 1px solid var(--line-2); border-top: 3px solid var(--gold);
  border-radius: var(--radius); background: var(--panel); color: var(--text); box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(0, 0, 0, .6); }
dialog header { display: flex; justify-content: space-between; align-items: center; padding: 16px 18px 6px; }
#modal-body { padding: 10px 18px 4px; max-height: 65vh; overflow: auto; }
#modal-error { padding: 0 18px; }
dialog footer { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px 16px; }
dialog footer .spacer { flex: 1; }

#toasts { position: fixed; right: 16px; bottom: 16px; z-index: 2000; display: grid; gap: 8px; }
.toast { background: var(--panel-2); border: 1px solid var(--line-2); border-left: 3px solid var(--green); padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); max-width: 340px; }
.toast.error { border-left-color: var(--red); }

/* ---------- Mobil */
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .sidebar { padding: 10px 16px; gap: 10px; }
  .menu-toggle { display: block; }
  .sidebar nav, .sidebar .user-box { display: none; }
  .sidebar.open nav, .sidebar.open .user-box { display: grid; }
  .sidebar.open .user-box { display: flex; }
  .view { padding: 18px 16px 30px; }
  .cols, .grid-3 { grid-template-columns: 1fr; }
  .map-panel { width: 200px; }
  .map-panel:not(.collapsed) { max-height: 50%; }
}
@media (max-width: 520px) {
  .grid-2 { grid-template-columns: 1fr; }
  .map-panel { left: 12px; right: 12px; width: auto; }
}
