/* Himmelsblick - mobiles, modernes UI
   Ziel: Klar, ruhig, leicht lesbar, iOS/Android-tauglich. */

:root {
  --bg: #f1f5f9;
  --bg-grad: linear-gradient(180deg, #e0f2fe 0%, #f1f5f9 100%);
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --primary: #0ea5e9;
  --primary-hover: #0284c7;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 4px 12px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 8px 30px rgba(15, 23, 42, 0.10);
  --radius: 14px;
  --radius-sm: 10px;
  --status-none: #10b981;
  --status-short: #f59e0b;
  --status-persistent: #ef4444;
  --status-unknown: #94a3b8;
  --safe-top: env(safe-area-inset-top, 0);
  --safe-bottom: env(safe-area-inset-bottom, 0);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c1424;
    --bg-grad: linear-gradient(180deg, #0c1424 0%, #0f172a 100%);
    --surface: #111c2e;
    --surface-2: #0f1827;
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --border: #1e2b40;
    --shadow: 0 1px 2px rgba(0,0,0,0.3), 0 4px 12px rgba(0,0,0,0.3);
    --shadow-lg: 0 8px 30px rgba(0,0,0,0.4);
  }
}

[data-theme="dark"] {
  --bg: #0c1424;
  --bg-grad: linear-gradient(180deg, #0c1424 0%, #0f172a 100%);
  --surface: #111c2e;
  --surface-2: #0f1827;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --border: #1e2b40;
  --shadow: 0 1px 2px rgba(0,0,0,0.3), 0 4px 12px rgba(0,0,0,0.3);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.4);
}

[data-theme="light"] {
  --bg: #f1f5f9;
  --bg-grad: linear-gradient(180deg, #e0f2fe 0%, #f1f5f9 100%);
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow-x: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
  font-size: 15px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg-grad);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: var(--safe-bottom);
}

a { color: var(--primary); }

/* ---- Topbar ---- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(12px + var(--safe-top)) 16px 12px;
  background: color-mix(in oklab, var(--surface) 92%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
}
.brand h1 {
  font-size: 18px;
  margin: 0;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.brand-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  color: #fff;
  background: linear-gradient(135deg, var(--primary), #6366f1);
}

.topbar-actions { display: flex; gap: 6px; }

.icon-btn {
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.05s;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn:active { transform: scale(0.96); }

/* ---- Search bar ---- */
.search-bar {
  position: relative;
  padding: 12px 16px 0;
}
.search-wrap {
  display: flex;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0 8px 0 12px;
  box-shadow: var(--shadow);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.search-wrap:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--primary) 25%, transparent);
}
.search-icon { color: var(--text-muted); flex: 0 0 auto; }
#location-input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text);
  font-size: 16px; /* iOS-Zoom verhindern */
  padding: 12px 8px;
}
.locate-btn {
  border: none;
  background: var(--primary);
  color: #fff;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.locate-btn:hover { background: var(--primary-hover); }
.locate-btn:active { transform: scale(0.96); }

.suggestions {
  position: absolute;
  z-index: 20;
  top: calc(100% + 4px);
  left: 16px;
  right: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  list-style: none;
  margin: 0;
  padding: 4px;
  box-shadow: var(--shadow-lg);
  max-height: 320px;
  overflow-y: auto;
  display: none;
}
.suggestions.open { display: block; }
.suggestions li {
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 14px;
}
.suggestions li:hover, .suggestions li.active {
  background: var(--surface-2);
}
.suggestions li .name { font-weight: 600; }
.suggestions li .detail {
  color: var(--text-muted);
  font-size: 12px;
  display: block;
  margin-top: 2px;
}

/* ---- Layout ---- */
.layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  padding: 12px 16px 24px;
  max-width: 1400px;
  margin: 0 auto;
}

.map-card {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  height: 50vh;
  min-height: 320px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}
#map { position: absolute; inset: 0; }

.map-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: color-mix(in oklab, var(--surface) 70%, transparent);
  backdrop-filter: blur(2px);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
  z-index: 5;
}
.map-overlay.visible { opacity: 1; pointer-events: auto; }

.loader {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  padding: 10px 16px;
  border-radius: 999px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  font-size: 14px;
}
.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.legend {
  position: absolute;
  z-index: 4;
  bottom: 8px;
  left: 8px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.legend-item {
  background: color-mix(in oklab, var(--surface) 92%, transparent);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  font-size: 11px;
  padding: 4px 8px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
}
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot.you { background: #6366f1; box-shadow: 0 0 0 3px color-mix(in oklab, #6366f1 30%, transparent); }
.dot.plane { background: var(--primary); }

/* ---- Sidebar / Cards ---- */
.sidebar {
  display: grid;
  gap: 12px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.card-header { margin-bottom: 12px; }
.card-header h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.005em;
}
.card-sub {
  color: var(--text-muted);
  font-size: 12px;
}
.empty {
  color: var(--text-muted);
  font-size: 13px;
  padding: 12px 0;
}

/* ---- Contrail card ---- */
.contrail-card {
  background-image:
    radial-gradient(60% 80% at 100% 0%, color-mix(in oklab, var(--primary) 12%, transparent), transparent 70%),
    radial-gradient(50% 80% at 0% 100%, color-mix(in oklab, #6366f1 10%, transparent), transparent 70%);
}
.contrail-gauge {
  display: flex;
  gap: 16px;
  align-items: center;
}
.gauge-circle {
  position: relative;
  flex: 0 0 auto;
  width: 92px;
  height: 92px;
  border-radius: 50%;
  display: flex;
  align-items: baseline;
  justify-content: center;
  background: conic-gradient(var(--gauge-color, var(--status-unknown)) calc(var(--gauge-pct, 0) * 1%), var(--surface-2) 0);
  box-shadow: inset 0 0 0 8px var(--surface);
  font-weight: 700;
  font-size: 28px;
  letter-spacing: -0.02em;
  transition: background 0.4s ease;
}
.gauge-circle::after {
  content: "";
  position: absolute;
  inset: 8px;
  border-radius: 50%;
  background: var(--surface);
  z-index: 0;
}
.gauge-value, .gauge-suffix { z-index: 1; position: relative; }
.gauge-suffix {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
  margin-left: 1px;
  align-self: flex-start;
  margin-top: 6px;
}
.gauge-detail { flex: 1 1 auto; }
.gauge-detail p {
  margin: 6px 0 0;
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.4;
}

.badge {
  display: inline-block;
  padding: 4px 10px;
  font-size: 12px;
  border-radius: 999px;
  background: var(--status-unknown);
  color: #fff;
  font-weight: 600;
  letter-spacing: 0.01em;
  text-transform: uppercase;
}
.badge.none { background: var(--status-none); }
.badge.short_lived { background: var(--status-short); }
.badge.persistent { background: var(--status-persistent); }
.badge.unknown { background: var(--status-unknown); }

/* ---- Weather table ---- */
.weather-table {
  display: grid;
  gap: 6px;
}
.wx-row {
  display: grid;
  grid-template-columns: 60px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  font-size: 13px;
}
.wx-row .fl {
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.wx-row .vals {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  color: var(--text-muted);
}
.wx-row .val { display: inline-flex; align-items: center; gap: 4px; }
.wx-row .val strong { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.wx-row .pill {
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
}
.wx-row .pill.none { background: var(--status-none); }
.wx-row .pill.short_lived { background: var(--status-short); }
.wx-row .pill.persistent { background: var(--status-persistent); }
.wx-row .pill.unknown { background: var(--status-unknown); }

/* ---- Flights list ---- */
.flights-list {
  display: grid;
  gap: 6px;
  max-height: 420px;
  overflow-y: auto;
}
.flight-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.12s, transform 0.05s;
}
.flight-row:hover { background: color-mix(in oklab, var(--surface-2) 60%, var(--primary) 8%); }
.flight-row:active { transform: scale(0.99); }
.flight-row.active { outline: 2px solid var(--primary); }
.flight-row .icon {
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--primary);
  color: #fff;
  border-radius: 8px;
  flex: 0 0 auto;
}
.flight-row .meta { line-height: 1.3; min-width: 0; }
.flight-row .headline {
  font-weight: 600;
  font-size: 14px;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 6px;
}
.flight-row .sub {
  color: var(--text-muted);
  font-size: 12px;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}
.flight-row .alt {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.flight-row .alt .ft { font-weight: 700; font-size: 14px; display: block; }
.flight-row .alt .speed { color: var(--text-muted); font-size: 11px; display: block; }

.row-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--status-unknown);
  flex: 0 0 auto;
}
.row-dot.none { background: var(--status-none); }
.row-dot.short_lived { background: var(--status-short); }
.row-dot.persistent { background: var(--status-persistent); }

/* ---- Popup-Inhalt: lesbare Hierarchie ---- */
.popup .pop-route {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.3;
  margin-bottom: 2px;
}
.popup .pop-sub {
  color: var(--text-muted);
  font-size: 12px;
  margin-bottom: 8px;
}
.popup .pop-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin: 8px 0;
}
.popup .pop-grid > div {
  background: var(--surface-2);
  border-radius: 8px;
  padding: 8px 10px;
}
.popup .pop-grid span {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.popup .pop-grid strong {
  display: block;
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.popup .pop-grid em {
  display: block;
  font-style: normal;
  font-size: 11px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.popup .pop-tech {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px 0 4px;
}
.popup .pop-tech span {
  font-size: 11px;
  padding: 2px 8px;
  background: var(--surface-2);
  border-radius: 999px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}
.popup .pop-contrail {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 500;
  background: color-mix(in oklab, var(--status-unknown) 12%, var(--surface));
  color: var(--text);
}
.popup .pop-contrail.none      { background: color-mix(in oklab, var(--status-none) 14%, var(--surface)); }
.popup .pop-contrail.short_lived { background: color-mix(in oklab, var(--status-short) 18%, var(--surface)); }
.popup .pop-contrail.persistent { background: color-mix(in oklab, var(--status-persistent) 18%, var(--surface)); }
.popup .pop-contrail-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--status-unknown);
  flex: 0 0 auto;
}
.popup .pop-contrail.none .pop-contrail-dot      { background: var(--status-none); }
.popup .pop-contrail.short_lived .pop-contrail-dot { background: var(--status-short); }
.popup .pop-contrail.persistent .pop-contrail-dot { background: var(--status-persistent); }

/* ---- Bands ---- */
.bands { display: grid; gap: 6px; }
.band {
  display: grid;
  grid-template-columns: 110px 1fr 32px;
  gap: 10px;
  align-items: center;
  font-size: 13px;
}
.band .label { color: var(--text-muted); font-variant-numeric: tabular-nums; }
.band .bar {
  position: relative;
  height: 8px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}
.band .bar > span {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  background: linear-gradient(90deg, var(--primary), #6366f1);
  border-radius: 999px;
}
.band .count { font-weight: 700; text-align: right; }

/* ---- Footer ---- */
.footer {
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
  padding: 16px;
  max-width: 800px;
  margin: 0 auto;
}
.footer p { margin: 4px 0; }
.footer .hint { font-size: 11px; }
.footer a { color: var(--text-muted); text-decoration: underline; text-decoration-color: var(--border); }

/* ---- Map markers ----
   Wichtig: KEIN transform auf der Marker-Wurzel (.aircraft-marker) - MapLibre
   nutzt translate3d/rotate dort fuer Positionierung. Nur Farbe/Filter veraendern. */
.aircraft-marker {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--primary);
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.4));
  transition: color 0.2s ease, filter 0.2s ease;
}
.aircraft-marker svg {
  width: 22px;
  height: 22px;
  display: block;
  pointer-events: none;
}
.aircraft-marker.selected {
  color: #ef4444;
  filter: drop-shadow(0 2px 6px rgba(239, 68, 68, 0.7));
}
.aircraft-marker.persistent { color: #ef4444; }
.aircraft-marker.short_lived { color: #f59e0b; }
.aircraft-marker.none { color: #10b981; }

.user-marker {
  width: 18px;
  height: 18px;
  background: #6366f1;
  border-radius: 50%;
  border: 3px solid #fff;
  box-shadow: 0 0 0 3px color-mix(in oklab, #6366f1 35%, transparent), 0 1px 4px rgba(0,0,0,0.3);
}

.maplibregl-popup-content {
  background: var(--surface);
  color: var(--text);
  border-radius: 12px !important;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
  padding: 12px 14px !important;
  font-size: 13px;
  min-width: 240px;
  max-width: 320px;
}
.maplibregl-popup-tip { display: none; }

/* ---- Toast ---- */
.toast {
  position: fixed;
  bottom: calc(20px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 10px 16px;
  border-radius: 999px;
  box-shadow: var(--shadow-lg);
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 50;
  max-width: calc(100% - 32px);
  text-align: center;
}
.toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---- Desktop layout ---- */
@media (min-width: 1024px) {
  .layout {
    grid-template-columns: minmax(0, 1fr) 380px;
    align-items: start;
  }
  .map-card {
    height: calc(100vh - 180px);
    min-height: 500px;
    position: sticky;
    top: 132px;
  }
  .sidebar {
    max-height: calc(100vh - 180px);
    overflow-y: auto;
    padding-right: 4px;
  }
}

@media (min-width: 1400px) {
  .layout { grid-template-columns: minmax(0, 1fr) 420px; }
}
