/* LFSB Heavy Watcher - Dark-only, weil die App im Feld und nachts benutzt
   wird. Zahlen laufen durchgehend in Tabellenziffern, damit sich Distanzen
   und Hoehen beim Aktualisieren nicht verschieben. */

:root {
  --bg: #0a1628;
  --bg-2: #0f1f36;
  --surface: #13253f;
  --surface-2: #1a3050;
  --line: #23415f;
  --line-soft: #1a3050;

  --text: #e8eef7;
  --text-dim: #93a8c4;
  --text-faint: #61789a;

  --accent: #ffb02e;
  --accent-dim: #a8741d;
  --confirmed: #ff5e57;
  --candidate: #ffb02e;
  --ok: #35d0a5;

  --radius: 12px;
  --radius-sm: 8px;

  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

* { box-sizing: border-box; }

/* Ohne das ueberstimmt jedes display:flex/grid das hidden-Attribut. */
[hidden] { display: none !important; }

html {
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 50% -20%, #16304f 0%, transparent 70%),
    var(--bg);
  padding-bottom: env(safe-area-inset-bottom);
  -webkit-tap-highlight-color: transparent;
}

.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* --- Login ------------------------------------------------------------- */

.login-wrap {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 32px 28px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .45);
}

.login-card img { width: 64px; height: 64px; border-radius: 14px; display: block; margin: 0 auto 18px; }
.login-card h1 { font-size: 19px; margin: 0 0 4px; text-align: center; letter-spacing: -.01em; }
.login-card p.sub { margin: 0 0 26px; text-align: center; color: var(--text-faint); font-size: 13px; }

label { display: block; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--text-faint); margin-bottom: 6px; }

input[type="text"], input[type="password"] {
  width: 100%;
  padding: 11px 13px;
  margin-bottom: 16px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 16px; /* verhindert das Zoomen auf iOS */
  font-family: inherit;
}

input:focus { outline: 2px solid var(--accent-dim); outline-offset: 1px; border-color: transparent; }

button {
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  padding: 10px 16px;
  transition: background .15s, border-color .15s, opacity .15s;
}

button:hover:not(:disabled) { background: #21395c; }
button:disabled { opacity: .5; cursor: default; }

button.primary {
  width: 100%;
  background: var(--accent);
  border-color: var(--accent);
  color: #241704;
  padding: 12px;
}
button.primary:hover:not(:disabled) { background: #ffbe52; }

.error {
  background: rgba(255, 94, 87, .12);
  border: 1px solid rgba(255, 94, 87, .35);
  color: #ffb3af;
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-size: 13px;
  margin-bottom: 14px;
}

/* --- App-Rahmen -------------------------------------------------------- */

.app { max-width: 720px; margin: 0 auto; padding: 0 14px 40px; }

header.top {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 0 10px;
  background: linear-gradient(var(--bg) 72%, transparent);
  backdrop-filter: blur(8px);
}

header.top img { width: 30px; height: 30px; border-radius: 7px; }
header.top h1 { font-size: 15px; margin: 0; font-weight: 650; letter-spacing: -.01em; }
header.top .spacer { flex: 1; }

.pill {
  font-size: 11px;
  font-family: var(--mono);
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--text-dim);
  white-space: nowrap;
}
.pill.live { color: var(--ok); border-color: rgba(53, 208, 165, .4); }
.pill.stale { color: var(--confirmed); border-color: rgba(255, 94, 87, .4); }

nav.tabs {
  display: flex;
  gap: 4px;
  background: var(--bg-2);
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  padding: 4px;
  margin-bottom: 16px;
}

nav.tabs button {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-faint);
  padding: 8px 6px;
  font-size: 13px;
  border-radius: 7px;
  position: relative;
}
nav.tabs button.active { background: var(--surface-2); color: var(--text); }

.tab-badge {
  display: inline-block;
  min-width: 17px;
  padding: 0 5px;
  margin-left: 5px;
  font-family: var(--mono);
  font-size: 10px;
  line-height: 17px;
  border-radius: 999px;
  background: var(--confirmed);
  color: #2a0b09;
  font-weight: 700;
  vertical-align: 1px;
}

section[hidden] { display: none; }

/* --- Karten ------------------------------------------------------------ */

.card {
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
}

.card.stage-1 { border-left: 3px solid var(--candidate); }
.card.stage-2 { border-left: 3px solid var(--confirmed); }

.card-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 3px; }
.ident { font-family: var(--mono); font-size: 16px; font-weight: 600; letter-spacing: .01em; }
.type {
  font-family: var(--mono);
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 5px;
  background: var(--surface-2);
  color: var(--text-dim);
}
.card-head .spacer { flex: 1; }

.stage-tag {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .09em;
  font-weight: 700;
  padding: 3px 7px;
  border-radius: 5px;
}
.stage-tag.s1 { background: rgba(255, 176, 46, .16); color: var(--candidate); }
.stage-tag.s2 { background: rgba(255, 94, 87, .16); color: var(--confirmed); }
.stage-tag.landed { background: rgba(53, 208, 165, .16); color: var(--ok); }

.callsign { font-size: 12px; color: var(--text-faint); font-family: var(--mono); }

.metrics {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 12px;
}
@media (max-width: 420px) { .metrics { grid-template-columns: repeat(2, 1fr); } }

.metric { background: var(--bg-2); border-radius: var(--radius-sm); padding: 8px 9px; }
.metric .k { font-size: 10px; text-transform: uppercase; letter-spacing: .07em; color: var(--text-faint); }
.metric .v { font-family: var(--mono); font-size: 15px; font-variant-numeric: tabular-nums; margin-top: 2px; }
.metric .v small { font-size: 10px; color: var(--text-faint); margin-left: 2px; }
.v.down { color: var(--ok); }
.v.up { color: var(--text-dim); }

/* Entfernungsbalken: LFSB links, Ringgrenze rechts. */
.bar { height: 3px; background: var(--bg-2); border-radius: 2px; margin-top: 12px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--confirmed), var(--accent)); }

.reason { margin-top: 10px; font-size: 12.5px; color: var(--text-dim); line-height: 1.45; }
.meta-line { margin-top: 8px; font-size: 11px; color: var(--text-faint); font-family: var(--mono); display: flex; gap: 10px; flex-wrap: wrap; }

.card-actions { margin-top: 12px; display: flex; gap: 8px; flex-wrap: wrap; }
.card-actions button { font-size: 12px; padding: 6px 11px; }

.empty { text-align: center; color: var(--text-faint); padding: 44px 16px; font-size: 14px; }
.empty strong { display: block; color: var(--text-dim); margin-bottom: 6px; font-weight: 600; }

/* --- Einstellungen ----------------------------------------------------- */

.setting {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 0;
  border-bottom: 1px solid var(--line-soft);
}
.setting:last-child { border-bottom: none; }
.setting .txt { flex: 1; min-width: 0; }
.setting .txt b { display: block; font-size: 14px; font-weight: 600; }
.setting .txt span { font-size: 12px; color: var(--text-faint); }

h2.section { font-size: 12px; text-transform: uppercase; letter-spacing: .09em; color: var(--text-faint); margin: 24px 0 8px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  font-family: var(--mono);
  font-size: 12px;
  padding: 4px 9px;
  border-radius: 6px;
  background: var(--bg-2);
  border: 1px solid var(--line-soft);
  color: var(--text-dim);
}
.chip.rare { border-color: var(--accent-dim); color: var(--accent); }

.inline-form { display: flex; gap: 8px; margin-top: 10px; }
.inline-form input { margin-bottom: 0; flex: 1; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(20px);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 9px 18px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 50;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .5);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.stat-grid .metric .v { font-size: 13px; }

/* --- Karte -------------------------------------------------------------- */

.map-toolbar { display: flex; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }

.seg {
  display: flex;
  gap: 2px;
  background: var(--bg-2);
  border: 1px solid var(--line-soft);
  border-radius: 9px;
  padding: 3px;
}
.seg button {
  border: none;
  background: transparent;
  color: var(--text-faint);
  font-family: var(--mono);
  font-size: 12px;
  padding: 5px 11px;
  border-radius: 6px;
}
.seg button.active { background: var(--surface-2); color: var(--text); }

.map-stage {
  position: relative;
  aspect-ratio: 1 / 1;
  max-height: 70vh;
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  overflow: hidden;
}
.map-stage > div { position: absolute; inset: 0; }
.map-stage > div[hidden] { display: none; }

/* --- Radar -------------------------------------------------------------- */

.radar { width: 100%; height: 100%; display: block; }

/* Groessen kommen aus map.js, weil die viewBox unabhaengig von der
   Containerbreite 1000 Einheiten misst - hier stehen nur die Farben. */
.radar .ring { fill: none; stroke: var(--line); opacity: .85; }
.radar .ring-label,
.radar .compass,
.radar .airport-label,
.radar .ac-label {
  font-family: var(--mono);
  fill: var(--text-faint);
}
.radar .compass { fill: var(--text-dim); text-anchor: middle; }
.radar .airport-label { fill: var(--text-dim); }
.radar .airport-label.home { fill: var(--accent); }

.radar .runway { stroke: var(--text); stroke-linecap: round; }
.radar .approach { stroke: var(--accent); opacity: .65; }

.radar .airport-home { fill: var(--accent); }
.radar .airport-other { fill: var(--text-dim); }

.radar .trail { fill: none; opacity: .45; stroke-linejoin: round; stroke-linecap: round; }
.radar .trail.selected { opacity: .95; }

.radar .ac { cursor: pointer; }
.radar .ac-label { fill: var(--text-dim); }
.radar .ac.selected .ac-label { fill: var(--text); }
.radar .ac.selected path,
.radar .ac.selected circle { stroke: var(--text); stroke-width: 1; }
.radar .ac-halo { fill: none; stroke: var(--confirmed); opacity: .55; }
.radar .ac.alerted .ac-halo { animation: pulse 2s ease-in-out infinite; }

@keyframes pulse {
  0%, 100% { opacity: .2; }
  50% { opacity: .75; }
}
@media (prefers-reduced-motion: reduce) {
  .radar .ac.alerted .ac-halo { animation: none; opacity: .6; }
}

/* --- Leaflet ------------------------------------------------------------ */

/* Leaflet bringt einen hellen Standardhintergrund mit. Bevor die Kacheln da
   sind - oder wenn sie gar nicht kommen - soll die Flaeche zur App passen. */
#map-geo { background: var(--bg-2); }
/* OpenStreetMap liefert nur helle Standardkacheln. Die App wird nachts
   und im Feld benutzt - deshalb wird die Kachelebene invertiert und
   entsaettigt. Marker, Ringe und Pistenachsen liegen in anderen Ebenen
   und behalten ihre Farben. */
#map-geo .leaflet-tile-pane {
  filter: invert(1) hue-rotate(180deg) brightness(.85) contrast(.9) saturate(.4);
}
#map-geo .leaflet-container { background: var(--bg-2); font-family: var(--sans); }
#map-geo .leaflet-control-attribution {
  background: rgba(10, 22, 40, .78);
  color: var(--text-faint);
  font-size: 10px;
}
#map-geo .leaflet-control-attribution a { color: var(--text-dim); }
#map-geo .leaflet-bar a {
  background: var(--surface);
  color: var(--text);
  border-color: var(--line);
}
#map-geo .leaflet-bar a:hover { background: var(--surface-2); }

.geo-marker { background: none; border: none; }
.geo-plane { width: 28px; height: 28px; overflow: visible; }
.geo-plane .ac-halo { fill: none; stroke: #ff5e57; stroke-width: 1.5; opacity: .6; }
.geo-plane.selected path { stroke: #fff; stroke-width: 1.5; }
.geo-label {
  position: absolute;
  left: 30px;
  top: 7px;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-dim);
  white-space: nowrap;
  text-shadow: 0 0 4px var(--bg), 0 0 4px var(--bg);
  pointer-events: none;
}

/* --- Legende und Detail ------------------------------------------------- */

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  margin: 10px 2px;
  font-size: 11px;
  color: var(--text-faint);
  font-family: var(--mono);
}
.legend i {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 2px;
  margin-right: 5px;
  vertical-align: -1px;
}

.map-hint {
  text-align: center;
  color: var(--text-faint);
  font-size: 12.5px;
  padding: 10px;
}
.map-hint.error { color: var(--confirmed); }
