:root {
    --bg: #10141a;
    --panel: #171d26;
    --border: #263040;
    --text: #e6edf5;
    --muted: #8b9bb0;
    --accent: #4da3ff;
}

* { box-sizing: border-box; }

html, body {
    height: 100%;
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.page { display: flex; flex-direction: column; height: 100%; }
.page > main { flex: 1; min-height: 0; }

.map-shell { position: relative; height: 100%; }
.map { position: absolute; inset: 0; }

.panel {
    position: absolute;
    top: 1rem;
    left: 1rem;
    z-index: 1000;
    width: 15rem;
    padding: 1rem;
    background: color-mix(in srgb, var(--panel) 92%, transparent);
    border: 1px solid var(--border);
    border-radius: 0.6rem;
}

.panel h1 { margin: 0 0 0.75rem; font-size: 1.1rem; letter-spacing: 0.02em; }

/* The panel is tall, and on a laptop it covers a good part of the map. Collapsing slides it
   out of the way rather than unmounting it, so scroll position and every control's state
   survive - and so the transition has something to animate. */
.panel {
    max-height: calc(100% - 2rem);
    overflow-y: auto;
    transition: transform 0.18s ease, opacity 0.18s ease;
}
.panel.collapsed {
    transform: translateX(calc(-100% - 1.5rem));
    opacity: 0;
    /* Keeps hidden controls out of the tab order and unclickable. */
    visibility: hidden;
}

.panel-toggle {
    position: absolute;
    top: 1rem;
    left: 1rem;
    z-index: 1001;
    width: 1.9rem;
    height: 1.9rem;
    display: grid;
    place-items: center;
    padding: 0;
    background: color-mix(in srgb, var(--panel) 92%, transparent);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 0.4rem;
    cursor: pointer;
    transition: transform 0.18s ease;
}

/* Sits at the panel's top-right corner while open, and at the screen edge once closed. */
.map-shell:not(.panel-hidden) .panel-toggle { transform: translateX(14.1rem); }

.panel-toggle-icon {
    width: 0.85rem;
    height: 0.85rem;
    border-left: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(45deg) translate(1px, -1px);
    transition: transform 0.18s ease;
}
.map-shell.panel-hidden .panel-toggle-icon {
    transform: rotate(-135deg) translate(1px, -1px);
}

.visually-hidden {
    position: absolute;
    width: 1px; height: 1px;
    margin: -1px; padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

/* On a phone the panel is most of the screen, so it starts out of the way and the toggle is
   the primary control. */
@media (max-width: 40rem) {
    .panel { width: min(17rem, calc(100vw - 4rem)); }
    .map-shell:not(.panel-hidden) .panel-toggle { transform: translateX(min(16.1rem, calc(100vw - 5rem))); }
}

.layer-toggles { display: flex; flex-direction: column; gap: 0.35rem; font-size: 0.85rem; }
.layer-toggles label { display: flex; align-items: center; gap: 0.45rem; cursor: pointer; }

.feed-status {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0.15rem 0.6rem;
    margin: 0.9rem 0 0;
    font-size: 0.78rem;
    color: var(--muted);
}
.feed-status dt { color: var(--muted); }
.feed-status dd { margin: 0; color: var(--text); }

.logout { margin-top: 0.9rem; }
.logout button, .login-card button {
    width: 100%;
    padding: 0.5rem;
    background: var(--accent);
    color: #06121f;
    border: 0;
    border-radius: 0.35rem;
    font-weight: 600;
    cursor: pointer;
}
.logout button { background: transparent; color: var(--muted); border: 1px solid var(--border); font-weight: 400; }

.overlay-status {
    margin: 0.45rem 0 0;
    font-size: 0.72rem;
    color: var(--muted);
    font-style: italic;
}

.animate-row {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin-top: 0.5rem;
    font-size: 0.78rem;
    color: var(--muted);
    cursor: pointer;
}
.animate-row input { margin: 0; }

/* The particle canvas sits above the colour field but below the contact markers, which are
   appended to the same pane afterwards. */
.wind-particle-canvas, .wind-arrow-canvas, .weather-field-canvas { pointer-events: none; }

/* The field sits under the wind glyphs and the contacts, which are appended to the same pane
   after it. */
.weather-field-canvas { z-index: 1; }
.wind-particle-canvas, .wind-arrow-canvas { z-index: 2; }
.contact-canvas { z-index: 3; }

/* ---- type filters ---- */

/* A <details> so two ten-item lists do not push the timeline controls off a laptop screen. */
.filter-block { margin-top: 0.9rem; }
.filter-block > summary { cursor: pointer; margin: 0; list-style: revert; }
.filter-block > summary::marker { color: var(--muted); }

.filter-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.15rem 0.5rem;
    margin-top: 0.45rem;
}
.filter-grid label {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.75rem;
    color: var(--text);
    cursor: pointer;
}
.filter-grid input { margin: 0; }

/* Mirrors the fill colours in contact-canvas.js, so the list doubles as the map's legend. */
.swatch {
    width: 0.6rem;
    height: 0.6rem;
    border-radius: 0.15rem;
    flex: none;
}
.swatch-ac-0 { background: #9aa7b4; }
.swatch-ac-1 { background: #8fd6ff; }
.swatch-ac-2 { background: #7fe0c0; }
.swatch-ac-3 { background: #c9b3ff; }
.swatch-ac-4 { background: #ffd479; }
.swatch-ac-5 { background: #ffb04d; }
.swatch-ac-6 { background: #ff9ecb; }
.swatch-ac-7 { background: #ff7a7a; }
.swatch-ac-8 { background: #b8c4d0; }
.swatch-ve-0 { background: #9aa7b4; }
.swatch-ve-1 { background: #6fe3a1; }
.swatch-ve-2 { background: #ff8f6b; }
.swatch-ve-3 { background: #7fb4ff; }
.swatch-ve-4 { background: #66e0e0; }
.swatch-ve-5 { background: #d5c26b; }
.swatch-ve-6 { background: #c0a0ff; }
.swatch-ve-7 { background: #a0e0c0; }
.swatch-ve-8 { background: #ff7a7a; }
.swatch-ve-9 { background: #9aa7b4; }
.swatch-ve-10 { background: #e0d060; }

.filter-reset {
    margin-top: 0.5rem;
    padding: 0.25rem 0.6rem;
    background: transparent;
    color: var(--muted);
    border: 1px solid var(--border);
    border-radius: 0.3rem;
    font-size: 0.7rem;
    cursor: pointer;
}

/* ---- popups ---- */

.popup-sub { color: var(--muted); font-size: 0.7rem; margin-bottom: 0.35rem; }
.popup-row { display: flex; justify-content: space-between; gap: 0.9rem; font-size: 0.75rem; }
.popup-row span { color: var(--muted); }
.popup-details { margin-top: 0.3rem; padding-top: 0.3rem; border-top: 1px solid rgba(255,255,255,0.12); }
.popup-loading, .popup-note { color: var(--muted); font-size: 0.7rem; font-style: italic; }

/* ---- panel: overlay picker + legend ---- */

.panel-heading {
    margin: 0.9rem 0 0.4rem;
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
}
.panel-heading:first-of-type { margin-top: 0.4rem; }

.overlay-picker { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.85rem; }
.overlay-picker label { display: flex; align-items: center; gap: 0.45rem; cursor: pointer; }

.opacity-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.5rem;
    font-size: 0.75rem;
    color: var(--muted);
}
.opacity-row input { flex: 1; min-width: 0; accent-color: var(--accent); }

.legend {
    position: absolute;
    right: 1rem;
    bottom: 5.2rem;
    z-index: 1000;
    display: grid;
    grid-template-columns: auto 1fr auto;
    grid-template-areas: "title title title" "lo bar hi";
    align-items: center;
    gap: 0.25rem 0.5rem;
    padding: 0.5rem 0.7rem;
    background: color-mix(in srgb, var(--panel) 94%, transparent);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    font-size: 0.7rem;
    color: var(--muted);
}
.legend-title { grid-area: title; color: var(--text); font-weight: 600; }
.legend-lo { grid-area: lo; }
.legend-hi { grid-area: hi; }
.legend-bar {
    grid-area: bar;
    width: 9rem;
    height: 0.55rem;
    border-radius: 0.28rem;
    border: 1px solid var(--border);
}

.hidden { display: none !important; }

/* Overlay sits above tiles but below markers, so aircraft stay readable over a heavy field. */
.weather-overlay-image { z-index: 250; }

.wind-arrow { color: rgba(255, 255, 255, 0.72); font-size: 0.72rem; }
.wind-arrow span { display: block; line-height: 1; transform-origin: 50% 50%; }

/* ---- travel paths ---- */

.track-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    font-size: 0.78rem;
    color: var(--muted);
}
.track-row select {
    flex: 1;
    min-width: 0;
    padding: 0.25rem;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 0.3rem;
    font-size: 0.75rem;
}

.track-hint { margin: 0.45rem 0 0; font-size: 0.7rem; color: var(--muted); }
.track-info { margin: 0.45rem 0 0; font-size: 0.72rem; color: #9fe0ff; line-height: 1.35; }
.track-clear {
    width: 100%;
    margin-top: 0.5rem;
    padding: 0.35rem;
    background: transparent;
    color: var(--muted);
    border: 1px solid var(--border);
    border-radius: 0.3rem;
    font-size: 0.72rem;
    cursor: pointer;
}

/* Leaflet paths take stroke from CSS when given a className. */
.track-line { fill: none; }
.track-aircraft { stroke: #ffd479; }
.track-vessel { stroke: #6fe3a1; }
.track-start { stroke: #ffffff; fill: #ffffff; }

/* ---- timeline ---- */

.timeline {
    position: absolute;
    left: 50%;
    bottom: 1.1rem;
    transform: translateX(-50%);
    z-index: 1000;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    width: min(46rem, calc(100% - 2rem));
    padding: 0.6rem 0.9rem;
    background: color-mix(in srgb, var(--panel) 94%, transparent);
    border: 1px solid var(--border);
    border-radius: 0.6rem;
}

.tl-button {
    flex: none;
    width: 2.1rem;
    height: 2.1rem;
    display: grid;
    place-items: center;
    background: transparent;
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 0.35rem;
    font-size: 0.75rem;
    cursor: pointer;
}
.tl-button:hover { border-color: var(--accent); color: var(--accent); }

.tl-slider {
    flex: 1;
    min-width: 0;
    accent-color: var(--accent);
    cursor: pointer;
}
.tl-slider:disabled { cursor: default; opacity: 0.4; }

.tl-label {
    flex: none;
    min-width: 11rem;
    text-align: right;
    font-variant-numeric: tabular-nums;
    font-size: 0.78rem;
    color: var(--muted);
}
.tl-label-past { color: #ffd479; }
.tl-label-future { color: #7fd7ff; }

.tl-future {
    flex: none;
    padding: 0.25rem 0.5rem;
    background: rgba(127, 215, 255, 0.14);
    border: 1px solid rgba(127, 215, 255, 0.45);
    border-radius: 0.3rem;
    font-size: 0.66rem;
    color: #7fd7ff;
    white-space: nowrap;
}

.tl-live {
    flex: none;
    padding: 0.3rem 0.6rem;
    background: transparent;
    color: var(--muted);
    border: 1px solid var(--border);
    border-radius: 0.35rem;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    cursor: pointer;
}
/* Solid while following the feed, outline while parked in the past. */
.tl-live-on { background: var(--accent); color: #06121f; border-color: var(--accent); }

/* Leaflet renders divIcon content in a plain div; these keep the glyphs centred and rotatable. */
.marker span { display: block; line-height: 1; transform-origin: 50% 50%; }
.marker-weather { color: var(--accent); font-size: 0.8rem; }

/* Aircraft and vessels are painted into this one canvas instead of being a DOM marker each.
   Their colours live in contact-canvas.js because a canvas fill cannot read a stylesheet. */
.contact-canvas { pointer-events: none; }
.map-canvas { pointer-events: none; }

.attribution {
    padding: 0.4rem 0.8rem;
    font-size: 0.7rem;
    color: var(--muted);
    background: var(--panel);
    border-top: 1px solid var(--border);
}
.attribution a { color: var(--muted); }

.login-shell { display: grid; place-items: center; gap: 0.75rem; height: 100%; padding: 1rem; }
.login-card {
    width: min(22rem, 100%);
    padding: 1.75rem;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
}
.login-card h1 { margin: 0; font-size: 1.4rem; }
.login-sub { margin: 0.2rem 0 1.25rem; color: var(--muted); font-size: 0.85rem; }
.login-card label { display: block; margin-bottom: 0.3rem; font-size: 0.8rem; color: var(--muted); }
.login-card input {
    width: 100%;
    margin-bottom: 0.9rem;
    padding: 0.55rem;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 0.35rem;
}
/* Directory connectivity probe. Sits outside the card because it is a diagnostic, not a
   step in signing in. */
.login-check {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    width: min(22rem, 100%);
}
.login-check-button {
    padding: 0.35rem 0.9rem;
    background: transparent;
    color: var(--muted);
    border: 1px solid var(--border);
    border-radius: 0.35rem;
    font-size: 0.8rem;
    cursor: pointer;
}
.login-check-result { font-size: 0.8rem; font-weight: 600; }
.login-check-result.ok { color: #7ddba1; }
.login-check-result.bad { color: #ffb4b4; }

.login-error {
    margin: 0 0 0.9rem;
    padding: 0.5rem 0.65rem;
    background: #3a1d1d;
    border: 1px solid #5c2b2b;
    border-radius: 0.35rem;
    font-size: 0.8rem;
    color: #ffb4b4;
}
