/* Leitstelle – Design · © ff144 */

:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f0f1f4;
  --border: #dfe2e7;
  --text: #1b1f24;
  --muted: #667080;
  --accent: #c62828;
  --accent-hover: #a91f1f;
  --accent-soft: #fde8e8;
  --fw: #d32f2f;
  --rd: #f2a516;
  --rd-text: #3b2a00;
  --ok: #2e7d32;
  --ok-soft: #e3f3e4;
  --info-soft: #e6effb;
  --target: #1565c0;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 2px 8px rgba(16,24,40,.06);
  --radius: 10px;
  --topbar-h: 52px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0f1216;
  --surface: #171b21;
  --surface-2: #1f242c;
  --border: #2b313b;
  --text: #e6e9ee;
  --muted: #8d96a5;
  --accent: #e5484d;
  --accent-hover: #f16a6e;
  --accent-soft: #3a1b1d;
  --fw: #e5484d;
  --rd: #f5b83d;
  --rd-text: #2b1f00;
  --ok: #4caf50;
  --ok-soft: #17301a;
  --info-soft: #172538;
  --target: #4d9bff;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 14px rgba(0,0,0,.3);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100vh; display: flex; flex-direction: column;
}
a { color: var(--accent); }
h1 { font-size: 1.35rem; margin: 0 0 .75rem; }
h2 { font-size: 1.05rem; margin: 1.5rem 0 .6rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .85em; }
.pad { padding: 1rem; }
code { background: var(--surface-2); padding: .1em .35em; border-radius: 4px; font-size: .9em; }
hr { border: 0; border-top: 1px solid var(--border); margin: 1.25rem 0; }
[hidden] { display: none !important; }

/* ---------- Kopfzeile ---------- */
.topbar {
  height: var(--topbar-h); display: flex; align-items: center; gap: 1.25rem;
  padding: 0 1rem; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 1000;
}
.brand { display: flex; align-items: center; gap: .55rem; font-weight: 700; color: var(--text); text-decoration: none; white-space: nowrap; }
.brand-mark { width: 22px; height: 22px; border-radius: 6px; background: var(--accent); position: relative; flex: none; }
.brand-mark::before, .brand-mark::after { content: ""; position: absolute; background: #fff; left: 50%; top: 50%; transform: translate(-50%,-50%); }
.brand-mark::before { width: 12px; height: 3px; }
.brand-mark::after { width: 3px; height: 12px; }
.brand-mark.big { width: 44px; height: 44px; border-radius: 12px; }
.brand-mark.big::before { width: 22px; height: 5px; }
.brand-mark.big::after { width: 5px; height: 22px; }
.mainnav { display: flex; gap: .25rem; overflow-x: auto; }
.mainnav a { color: var(--muted); text-decoration: none; padding: .4rem .7rem; border-radius: 8px; white-space: nowrap; font-weight: 500; }
.mainnav a:hover { color: var(--text); background: var(--surface-2); }
.mainnav a.active { color: var(--text); background: var(--surface-2); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: .5rem; }
.user-chip { color: var(--text); text-decoration: none; font-size: .9rem; padding: .3rem .6rem; border-radius: 8px; }
.user-chip:hover { background: var(--surface-2); }
.icon-btn {
  border: 1px solid transparent; background: transparent; color: var(--muted); cursor: pointer;
  width: 32px; height: 32px; border-radius: 8px; display: inline-grid; place-items: center; font-size: 14px;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.danger:hover { color: var(--accent); }
#themeToggle .i-sun { display: none; }
:root[data-theme="dark"] #themeToggle .i-sun { display: block; }
:root[data-theme="dark"] #themeToggle .i-moon { display: none; }

/* ---------- Inhalt ---------- */
.main { width: 100%; max-width: 1200px; margin: 0 auto; padding: 1.25rem 1rem 2rem; flex: 1; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.25rem; margin-bottom: 1rem; }
.card.narrow { max-width: 520px; margin: 1rem auto; }
.card.narrow-wide { max-width: 760px; margin: 0 auto 1rem; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: .75rem; }
.card-head h1 { margin: 0; }
.page-head { margin-bottom: 1rem; }
.prose { max-width: 820px; margin: 0 auto 1rem; }
.prose li { margin-bottom: .3rem; }

.footer { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; padding: .6rem 1rem; color: var(--muted); font-size: .8rem; border-top: 1px solid var(--border); background: var(--surface); }
.footer a { color: var(--muted); }

/* ---------- Meldungen ---------- */
.flash { padding: .7rem .9rem; border-radius: 8px; margin: 0 0 1rem; border: 1px solid var(--border); background: var(--surface-2); }
.flash-success { background: var(--ok-soft); border-color: transparent; }
.flash-error { background: var(--accent-soft); border-color: transparent; }
.flash-info { background: var(--info-soft); border-color: transparent; }
.main-map > .flash { margin: .5rem; position: absolute; z-index: 1100; left: 0; right: 0; }

/* ---------- Formulare ---------- */
.form { display: flex; flex-direction: column; gap: .85rem; }
label, .label-like { display: flex; flex-direction: column; gap: .3rem; font-size: .88rem; font-weight: 500; }
.label-like { margin-bottom: .4rem; display: block; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: .55rem .7rem; width: 100%; font-weight: 400;
}
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 0; border-color: var(--accent); }
textarea { resize: vertical; }
label.check { flex-direction: row; align-items: center; gap: .5rem; font-weight: 400; }
label.check input { width: auto; }
.row { display: flex; gap: .75rem; flex-wrap: wrap; }
.row .grow { flex: 1 1 180px; }
.w-plz { width: 110px; }
.w-sm { max-width: 110px; }
fieldset { border: 1px solid var(--border); border-radius: 8px; padding: .75rem; margin: 0; }
legend { font-size: .88rem; font-weight: 500; padding: 0 .3rem; }
.perm-box { display: flex; flex-direction: column; gap: .5rem; }
.form-actions { display: flex; gap: .5rem; margin-top: 1.25rem; flex-wrap: wrap; }
.inline { display: inline; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }

.seg { display: flex; gap: .5rem; flex-wrap: wrap; }
.seg-opt { flex: 1 1 150px; }
.seg-opt input { position: absolute; opacity: 0; pointer-events: none; }
.seg-opt > span { display: flex; align-items: center; gap: .5rem; padding: .55rem .7rem; border: 1px solid var(--border); border-radius: 8px; cursor: pointer; font-weight: 500; }
.seg-opt input:checked + span { border-color: var(--accent); background: var(--accent-soft); }
.seg-opt input:focus-visible + span { outline: 2px solid var(--accent); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  font: inherit; font-weight: 600; padding: .55rem 1rem; border-radius: 8px; cursor: pointer;
  background: var(--accent); color: #fff; border: 1px solid var(--accent); text-decoration: none;
}
.btn:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); border-color: var(--border); }
.btn-ghost.danger { color: var(--accent); }
.btn-sm { padding: .3rem .6rem; font-size: .85rem; }
.btn-block { width: 100%; }

/* ---------- Tabellen, Tags ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: .6rem .6rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
.table tr:last-child td { border-bottom: 0; }
.table td.right { text-align: right; }
.fz-table td { padding: .35rem .4rem; vertical-align: middle; }
.fz-table input { padding: .4rem .55rem; }
.tag { display: inline-block; font-size: .75rem; padding: .12rem .5rem; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); margin: 0 .2rem .2rem 0; }
.tag-ok { color: var(--ok); background: var(--ok-soft); border-color: transparent; }
.tag-role { color: var(--text); font-weight: 600; }
.tags { display: flex; flex-wrap: wrap; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: .4rem 1rem; margin: 0 0 1rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: .75rem; margin-bottom: 1rem; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem 1rem; display: flex; flex-direction: column; }
.stat-num { font-size: 1.6rem; font-weight: 700; }
.stat-label { color: var(--muted); font-size: .85rem; }

/* ---------- Login ---------- */
.page-login .main { display: grid; place-items: center; }
.login-wrap { width: 100%; max-width: 380px; }
.login-card { padding: 1.75rem; }
.login-head { text-align: center; margin-bottom: 1rem; }
.login-head .brand-mark { margin: 0 auto .75rem; display: block; }
.login-head h1 { margin: 0 0 .2rem; }

/* ---------- Wachen-Symbole ---------- */
.wmark {
  display: inline-grid; place-items: center; min-width: 26px; height: 26px; padding: 0 4px;
  border-radius: 7px; font-weight: 800; font-size: 12px; color: #fff; background: var(--fw);
  border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.35); line-height: 1;
}
.wmark-rettung { background: var(--rd); color: var(--rd-text); border-radius: 50%; }
.wmark-kombi { background: linear-gradient(135deg, var(--fw) 50%, var(--rd) 50%); font-size: 10px; }
.wmark-sm { min-width: 22px; height: 22px; font-size: 10px; border-width: 1.5px; box-shadow: none; vertical-align: middle; }
.wmark-sm.wmark-kombi { font-size: 8px; }
.wmark-wrap, .tmark-wrap { background: none; border: 0; }
.wmark-wrap .wmark { width: 30px; height: 30px; }

.tmark { position: relative; display: block; width: 28px; height: 28px; }
.tmark-dot { position: absolute; inset: 7px; border-radius: 50%; background: var(--target); border: 3px solid #fff; box-shadow: 0 1px 5px rgba(0,0,0,.4); }
.tmark-pulse { position: absolute; inset: 0; border-radius: 50%; background: var(--target); opacity: .35; animation: pulse 1.8s ease-out infinite; }
@keyframes pulse { 0% { transform: scale(.5); opacity: .5; } 100% { transform: scale(2.2); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .tmark-pulse { animation: none; } }

.route-line.route-fw { stroke: var(--fw); }
.route-line.route-rd { stroke: var(--rd); }
.route-line.route-sel { stroke: var(--target); }
.dist-box { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.15; }
.chips { align-items: center; flex-wrap: wrap; }
.check-list { list-style: none; padding: 0; margin: 0; }
.check-list li { display: flex; gap: .6rem; padding: .55rem 0; border-bottom: 1px solid var(--border); align-items: flex-start; }
.check-list li:last-child { border-bottom: 0; }
.ck { flex: none; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 13px; color: #fff; }
.ck-ok { background: var(--ok); }
.ck-bad { background: var(--accent); }
.ck-warn { background: var(--rd); color: var(--rd-text); }
.mode-opts { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.mode-opts .seg-opt > span { flex-direction: column; align-items: flex-start; gap: .2rem; height: 100%; }
@media (max-width: 640px) { .mode-opts { grid-template-columns: 1fr; } }

/* ---------- Einsatzkarte ---------- */
.page-map { height: 100vh; overflow: hidden; }
.main-map { flex: 1; min-height: 0; position: relative; }
.page-map .footer { padding: .35rem 1rem; }
.map-layout { display: grid; grid-template-columns: 1fr 380px; height: 100%; }
.map-area { position: relative; min-height: 0; }
.map { position: absolute; inset: 0; background: var(--surface-2); }
.map-hint { position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); z-index: 500; background: var(--surface); padding: .25rem .6rem; border-radius: 999px; border: 1px solid var(--border); pointer-events: none; opacity: .9; }

.search-box { position: absolute; top: 12px; left: 56px; right: 12px; max-width: 560px; z-index: 900; }
.search-box.static { position: relative; top: auto; left: auto; right: auto; max-width: none; z-index: 950; }
.search-field {
  display: flex; align-items: center; gap: .5rem; background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; padding: 0 .4rem 0 .75rem; box-shadow: var(--shadow); color: var(--muted);
}
.search-box.static .search-field { box-shadow: none; }
.search-field:focus-within { border-color: var(--accent); }
.search-field input { border: 0; padding: .7rem 0; background: transparent; outline: none; font-size: 1rem; }
.search-field input:focus { outline: none; }
.search-field input::-webkit-search-cancel-button { display: none; }
.suggest {
  list-style: none; margin: .35rem 0 0; padding: .3rem; background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: var(--shadow); max-height: 340px; overflow-y: auto; position: absolute; left: 0; right: 0;
}
.suggest li { padding: .5rem .65rem; border-radius: 7px; cursor: pointer; display: flex; flex-direction: column; }
.suggest li.active, .suggest li[data-i]:hover { background: var(--surface-2); }
.suggest .s-title { font-weight: 600; }
.suggest .s-sub { color: var(--muted); font-size: .85rem; }
.suggest .suggest-msg { color: var(--muted); cursor: default; }

.side { background: var(--surface); border-left: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; }
.side-head { padding: 1rem 1rem .75rem; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: .6rem; }
.side-head h2 { margin: 0; }
.chips { display: flex; gap: .35rem; }
.chip { font: inherit; font-size: .82rem; padding: .3rem .7rem; border-radius: 999px; border: 1px solid var(--border); background: transparent; color: var(--muted); cursor: pointer; }
.chip:hover { color: var(--text); }
.chip.active { background: var(--text); color: var(--surface); border-color: var(--text); }
.target-card { margin: .75rem 1rem 0; padding: .7rem .85rem; border-radius: 8px; background: var(--info-soft); border-left: 3px solid var(--target); }
.tc-label { font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--target); font-weight: 700; }
.tc-title { font-weight: 600; }

.wachen-list { list-style: none; margin: 0; padding: .5rem; overflow-y: auto; flex: 1; }
.wache { padding: .7rem .7rem; border-radius: 8px; cursor: pointer; border: 1px solid transparent; display: flex; flex-direction: column; gap: .3rem; }
.wache + .wache { margin-top: .15rem; }
.wache:hover { background: var(--surface-2); }
.wache.sel { border-color: var(--accent); background: var(--surface-2); }
.wache:focus-visible { outline: 2px solid var(--accent); }
.wache-top { display: flex; align-items: center; gap: .55rem; }
.wache-name { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.wache-name strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank { width: 20px; text-align: center; color: var(--muted); font-weight: 700; font-size: .85rem; flex: none; }
.dist { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.badges { display: flex; gap: .3rem; flex-wrap: wrap; }
.badge { font-size: .7rem; font-weight: 700; padding: .1rem .45rem; border-radius: 4px; }
.badge-fw { background: var(--fw); color: #fff; }
.badge-rd { background: var(--rd); color: var(--rd-text); }
.note { color: var(--muted); font-style: italic; }
.fz-list { display: flex; flex-wrap: wrap; gap: .25rem; }
.fz { font-size: .76rem; padding: .1rem .45rem; border-radius: 5px; background: var(--surface-2); border: 1px solid var(--border); white-space: nowrap; }
.fz-rn { color: var(--muted); }
.pop-fz { margin-top: .35rem; display: flex; flex-wrap: wrap; gap: .2rem; }

.mini-map { height: 340px; border-radius: 8px; border: 1px solid var(--border); margin-bottom: .75rem; cursor: crosshair; }

/* ---------- Leaflet anpassen ---------- */
.leaflet-container { font: inherit; background: var(--surface-2); }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.leaflet-popup-content { margin: .7rem .85rem; font-size: .88rem; }
.leaflet-bar a, .leaflet-bar a:hover { background: var(--surface); color: var(--text); border-color: var(--border); }
.leaflet-control-attribution { background: color-mix(in srgb, var(--surface) 80%, transparent) !important; color: var(--muted); }
.leaflet-control-attribution a { color: var(--muted); }
:root[data-theme="dark"] .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.9) contrast(.9) saturate(.6); }

/* ---------- Mobil / Tablet ---------- */
@media (max-width: 900px) {
  .map-layout { grid-template-columns: 1fr; grid-template-rows: 55% 45%; }
  .side { border-left: 0; border-top: 1px solid var(--border); }
  .grid-2 { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .map-hint { display: none; }
}
@media (max-width: 640px) {
  .topbar { gap: .5rem; padding: 0 .5rem; }
  .user-chip { display: none; }
  .brand { font-size: 0; gap: 0; }
  .search-box { left: 50px; right: 8px; top: 8px; }
}
