/* Overhead Flight Tracker – Dashboard
   Dark Mode als Standard, helles Theme über prefers-color-scheme. */

:root {
    --bg: #0b1220;
    --bg-glow: #10203a;
    --surface: #131c2e;
    --surface-2: #1a2540;
    --border: #25324f;
    --text: #e6edf7;
    --muted: #8a9bb8;
    --accent: #38bdf8;
    --accent-soft: rgba(56, 189, 248, 0.14);
    --ok: #34d399;
    --warn: #fbbf24;
    --err: #f87171;
    --radar-line: rgba(56, 189, 248, 0.22);
    --radar-fill: rgba(56, 189, 248, 0.04);
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
    --radius: 16px;
    --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
}

@media (prefers-color-scheme: light) {
    :root {
        --bg: #eef2f8;
        --bg-glow: #dde7f5;
        --surface: #ffffff;
        --surface-2: #f3f6fb;
        --border: #d6deea;
        --text: #0f172a;
        --muted: #5b6b85;
        --accent: #0284c7;
        --accent-soft: rgba(2, 132, 199, 0.1);
        --ok: #059669;
        --warn: #b45309;
        --err: #dc2626;
        --radar-line: rgba(2, 132, 199, 0.25);
        --radar-fill: rgba(2, 132, 199, 0.04);
        --shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
    }
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.45;
    color: var(--text);
    background:
        radial-gradient(1200px 600px at 10% -10%, var(--bg-glow), transparent 60%),
        var(--bg);
    background-attachment: fixed;
}

h1, h2, p {
    margin: 0;
}

a {
    color: var(--accent);
}

.muted {
    color: var(--muted);
}

.mono {
    font-family: var(--mono);
}

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

/* ---------- Header ---------- */

.topbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 16px 24px;
    padding: 20px clamp(16px, 4vw, 40px);
    border-bottom: 1px solid var(--border);
    background: color-mix(in srgb, var(--surface) 70%, transparent);
    backdrop-filter: blur(8px);
    position: sticky;
    top: 0;
    z-index: 10;
}

.brand {
    display: flex;
    align-items: center;
    gap: 14px;
    min-width: 0;
}

.brand-icon {
    width: 40px;
    height: 40px;
    padding: 8px;
    flex: none;
    fill: var(--accent);
    background: var(--accent-soft);
    border-radius: 12px;
}

.brand h1 {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.brand p {
    font-size: 0.85rem;
}

.status {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px 28px;
}

.stat {
    display: flex;
    flex-direction: column;
}

.stat-value {
    font-size: 1.35rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.conn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    font-size: 0.85rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface-2);
}

.conn-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--muted);
}

.conn[data-state="ok"] .conn-dot {
    background: var(--ok);
    box-shadow: 0 0 0 0 var(--ok);
    animation: pulse 2.4s infinite;
}

.conn[data-state="stale"] .conn-dot {
    background: var(--warn);
}

.conn[data-state="error"] .conn-dot {
    background: var(--err);
}

@keyframes pulse {
    0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--ok) 60%, transparent); }
    70% { box-shadow: 0 0 0 8px transparent; }
    100% { box-shadow: 0 0 0 0 transparent; }
}

.notice {
    margin: 16px clamp(16px, 4vw, 40px) 0;
    padding: 12px 16px;
    border-radius: 12px;
    border: 1px solid color-mix(in srgb, var(--warn) 50%, transparent);
    background: color-mix(in srgb, var(--warn) 12%, transparent);
    font-size: 0.9rem;
}

.notice[data-level="error"] {
    border-color: color-mix(in srgb, var(--err) 50%, transparent);
    background: color-mix(in srgb, var(--err) 12%, transparent);
}

/* ---------- Layout ---------- */

.layout {
    display: grid;
    grid-template-columns: minmax(260px, 340px) 1fr;
    gap: 24px;
    align-items: start;
    padding: 24px clamp(16px, 4vw, 40px);
}

.radar-panel {
    position: sticky;
    top: 110px;
    padding: 18px;
}

.flights {
    min-width: 0;
}

/* ---------- Radar ---------- */

.radar {
    display: block;
    width: 100%;
    height: auto;
    aspect-ratio: 1;
}

.radar .ring {
    fill: none;
    stroke: var(--radar-line);
    stroke-width: 0.6;
}

.radar .ring-outer {
    fill: var(--radar-fill);
    stroke-width: 1;
}

.radar .axis {
    stroke: var(--radar-line);
    stroke-width: 0.4;
    stroke-dasharray: 2 3;
}

.radar .label {
    fill: var(--muted);
    font-size: 7px;
    font-family: var(--font);
}

.radar .ring-label {
    font-size: 6px;
    opacity: 0.75;
}

.radar .north {
    fill: var(--accent);
    font-weight: 700;
}

.radar .home {
    fill: var(--accent);
}

.radar .plane {
    cursor: pointer;
}

.radar .plane path {
    fill: var(--text);
    transition: fill 0.2s;
}

.radar .plane text {
    fill: var(--muted);
    font-size: 6.5px;
    font-family: var(--mono);
}

.radar .plane.is-active path,
.radar .plane:hover path {
    fill: var(--accent);
}

.radar .plane.is-active text {
    fill: var(--text);
}

.sector {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin: 14px 0 0;
}

.sector div {
    padding: 8px 10px;
    border-radius: 10px;
    background: var(--surface-2);
}

.sector dt {
    font-size: 0.7rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.sector dd {
    margin: 2px 0 0;
    font-size: 0.85rem;
    font-weight: 600;
    overflow-wrap: anywhere;
}

/* ---------- Karten ---------- */

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(300px, 100%), 1fr));
    gap: 18px;
}

.card {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 18px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    transition: border-color 0.2s, transform 0.2s;
    animation: fade-in 0.35s ease both;
}

.card.is-active,
.card:hover {
    border-color: var(--accent);
}

.card.is-nearest {
    border-color: color-mix(in srgb, var(--accent) 60%, var(--border));
}

@keyframes fade-in {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: none; }
}

.card-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
}

.callsign {
    font-family: var(--mono);
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: 0.02em;
}

.aircraft-line {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-top: 4px;
    font-size: 0.85rem;
}

.badge {
    padding: 2px 8px;
    font-family: var(--mono);
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--accent);
    background: var(--accent-soft);
    border-radius: 6px;
}

.distance {
    display: grid;
    grid-template-columns: auto auto;
    align-items: baseline;
    justify-items: end;
    column-gap: 3px;
    text-align: right;
    flex: none;
}

.distance-value {
    font-size: 1.5rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.distance-unit {
    font-size: 0.8rem;
    color: var(--muted);
}

.direction {
    grid-column: 1 / -1;
    font-size: 0.75rem;
    color: var(--muted);
}

/* Route ZRH ➔ LHR */

.route {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--accent-soft), transparent 80%), var(--surface-2);
    border: 1px solid var(--border);
}

.airport {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.airport-to {
    text-align: right;
}

.code {
    font-family: var(--mono);
    font-size: 1.6rem;
    font-weight: 800;
    letter-spacing: 0.04em;
    line-height: 1.1;
}

.city {
    font-size: 0.8rem;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.route-arrow {
    font-size: 1.3rem;
    color: var(--accent);
}

.route.is-unknown .code {
    color: var(--muted);
}

.route.is-doubtful {
    border-style: dashed;
}

.route-note {
    margin-top: -8px;
    font-size: 0.75rem;
    color: var(--muted);
}

/* Messwerte */

.metrics {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin: 0;
}

.metrics div {
    min-width: 0;
}

.metrics dt {
    font-size: 0.7rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.metrics dd {
    margin: 2px 0 0;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.metrics small {
    display: block;
    font-weight: 400;
    color: var(--muted);
}

.trend {
    color: var(--accent);
}

/* ---------- Leerzustand ---------- */

.empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 56px 24px;
    text-align: center;
}

.empty[hidden] {
    display: none;
}

.empty svg {
    width: 56px;
    height: 56px;
    fill: var(--accent-soft);
    stroke: var(--accent);
    stroke-width: 1.2;
    margin-bottom: 8px;
}

.empty h2 {
    font-size: 1.3rem;
}

/* ---------- Anmeldung (Passkeys) ---------- */

.auth-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 7px 14px;
    font: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 999px;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
}

.btn[hidden] {
    display: none;
}

.btn:hover:not(:disabled) {
    border-color: var(--accent);
}

.btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.btn svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
}

.btn-primary {
    color: #fff;
    background: var(--accent);
    border-color: var(--accent);
}

.btn-primary:hover:not(:disabled) {
    background: color-mix(in srgb, var(--accent) 85%, #000);
}

.btn-danger:hover:not(:disabled) {
    color: var(--err);
    border-color: var(--err);
}

.btn-icon {
    padding: 4px 10px;
    border-radius: 8px;
}

body.is-busy .btn {
    pointer-events: none;
    opacity: 0.7;
}

.mode-banner {
    margin: 16px clamp(16px, 4vw, 40px) 0;
    padding: 10px 16px;
    font-size: 0.9rem;
    border-radius: 12px;
    border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
    background: var(--accent-soft);
}

.mode-banner[hidden] {
    display: none;
}

.dialog {
    width: min(520px, calc(100vw - 32px));
    padding: 20px;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.dialog::backdrop {
    background: rgba(4, 8, 16, 0.6);
    backdrop-filter: blur(2px);
}

.dialog-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.dialog-head h2 {
    font-size: 1.15rem;
}

.dialog-text {
    margin: 8px 0 16px;
    font-size: 0.88rem;
}

.passkey-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: 0 0 16px;
    padding: 0;
    list-style: none;
}

.passkey-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 10px;
    background: var(--surface-2);
}

.passkey-item p {
    font-size: 0.78rem;
}

.passkey-item .badge {
    margin-left: 6px;
}

.passkey-add label {
    display: block;
    margin-bottom: 6px;
    font-size: 0.8rem;
    color: var(--muted);
}

.passkey-add-row {
    display: flex;
    gap: 8px;
}

.passkey-add input {
    flex: 1;
    min-width: 0;
    padding: 8px 12px;
    font: inherit;
    color: var(--text);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 10px;
}

.passkey-add input:focus {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

.dialog-message {
    margin-top: 12px;
    font-size: 0.85rem;
    color: var(--err);
}

.dialog-message[data-level="ok"] {
    color: var(--ok);
}

.toast {
    position: fixed;
    left: 50%;
    bottom: 24px;
    z-index: 50;
    max-width: calc(100vw - 32px);
    padding: 10px 18px;
    font-size: 0.9rem;
    transform: translateX(-50%);
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow);
}

.toast[hidden] {
    display: none;
}

.toast[data-level="error"] {
    border-color: var(--err);
}

.toast[data-level="ok"] {
    border-color: var(--ok);
}

/* ---------- Footer ---------- */

.footer {
    padding: 8px clamp(16px, 4vw, 40px) 32px;
    font-size: 0.8rem;
}

/* ---------- Responsive ---------- */

@media (max-width: 860px) {
    .layout {
        grid-template-columns: minmax(0, 1fr);
    }

    .radar-panel {
        position: static;
        max-width: 420px;
        width: 100%;
        justify-self: center;
    }
}

@media (max-width: 520px) {
    .topbar {
        position: static;
    }

    .status {
        width: 100%;
        justify-content: space-between;
    }

    .grid {
        grid-template-columns: 1fr;
    }

    .code {
        font-size: 1.35rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation: none !important;
        transition: none !important;
    }
}
