:root {
    --bg: #06111f;
    --panel: rgba(9, 28, 48, 0.92);
    --panel-strong: #0c2238;
    --line: rgba(127, 206, 255, 0.18);
    --text: #eaf6ff;
    --muted: #8fb2ca;
    --accent: #2fd2ff;
    --accent-strong: #75e6ff;
    --green: #6df5bf;
    --amber: #ffd166;
    --danger: #ff6b7a;
    --shadow: 0 24px 80px rgba(0, 0, 0, 0.36);
    color-scheme: dark;
}

* {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
}

body {
    margin: 0;
    background:
        radial-gradient(circle at 20% 5%, rgba(47, 210, 255, 0.16), transparent 30%),
        linear-gradient(145deg, #04101c 0%, #082037 55%, #081520 100%);
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    letter-spacing: 0;
    overflow: hidden;
}

/* ---------- Top-level view tabs ---------- */
.view-tabs {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 56px;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    background: rgba(3, 15, 28, 0.92);
    border-bottom: 1px solid var(--line);
    z-index: 20;
}

.view-tab {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 40px;
    padding: 0 16px;
    border-radius: 8px;
    background: transparent;
    color: var(--muted);
    border: 1px solid transparent;
    font-weight: 700;
    font-size: 13px;
    text-transform: uppercase;
}

.view-tab i {
    width: 16px;
    height: 16px;
}

.view-tab:hover {
    color: var(--text);
    background: rgba(47, 210, 255, 0.1);
}

.view-tab.is-active {
    color: var(--accent-strong);
    background: rgba(47, 210, 255, 0.16);
    border-color: rgba(117, 230, 255, 0.35);
}

/*
 * .view containers use hard pixel top/bottom bounds (fixed positioning)
 * rather than relying on a chain of flex/grid ancestors to hand down a
 * height. A flex or grid child's default min-height is "auto" (content
 * size), so without every single ancestor explicitly opting out of that,
 * a tall child (e.g. the saved-routes list) just overflows past its
 * rounded panel instead of scrolling inside it. Fixed top/bottom bounds
 * make the available height unambiguous at every level below it.
 */
.view {
    position: fixed;
    top: 56px;
    left: 0;
    right: 0;
    bottom: 0;
    overflow: hidden;
    display: none;
}

.view:not([hidden]) {
    display: flex;
    flex-direction: column;
}

.app-shell {
    flex: 1;
    min-height: 0;
}

button,
input {
    font: inherit;
}

button {
    border: 0;
    cursor: pointer;
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.48;
}

.app-shell {
    display: grid;
    grid-template-columns: minmax(320px, 390px) minmax(0, 1fr);
    height: 100%;
    min-height: 0;
    width: 100%;
}

.sidebar {
    position: relative;
    z-index: 10;
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 18px;
    overflow-y: auto;
    background: rgba(3, 15, 28, 0.82);
    border-right: 1px solid var(--line);
    box-shadow: var(--shadow);
}

.brand {
    display: grid;
    grid-template-columns: 48px 1fr;
    gap: 12px;
    align-items: center;
    padding: 4px 2px 8px;
}

.brand-mark {
    display: grid;
    place-items: center;
    width: 48px;
    aspect-ratio: 1;
    border-radius: 8px;
    background: linear-gradient(150deg, rgba(47, 210, 255, 0.24), rgba(109, 245, 191, 0.12));
    border: 1px solid rgba(117, 230, 255, 0.28);
    color: var(--accent-strong);
}

.brand h1 {
    margin: 0;
    font-size: 20px;
    line-height: 1.15;
    letter-spacing: 0;
}

.brand p {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.35;
}

.panel {
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: 0 14px 34px rgba(0, 0, 0, 0.2);
}

.panel-title,
.panel-title > div {
    display: flex;
    align-items: center;
    gap: 8px;
}

.panel-title {
    margin-bottom: 12px;
    color: var(--accent-strong);
}

.panel-title h2 {
    margin: 0;
    font-size: 14px;
    line-height: 1.2;
    letter-spacing: 0;
    text-transform: uppercase;
}

.row-between {
    justify-content: space-between;
}

.row-between > span {
    display: inline-grid;
    place-items: center;
    min-width: 30px;
    height: 24px;
    padding: 0 8px;
    border-radius: 999px;
    background: rgba(47, 210, 255, 0.12);
    color: var(--accent-strong);
    font-weight: 700;
    font-size: 12px;
}

.field {
    display: grid;
    gap: 7px;
    margin-top: 12px;
}

.field:first-of-type {
    margin-top: 0;
}

.field span {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    color: var(--muted);
    font-size: 13px;
}

.field em {
    color: var(--green);
    font-style: normal;
    white-space: nowrap;
}

input {
    width: 100%;
    min-height: 44px;
    padding: 10px 12px;
    border: 1px solid rgba(127, 206, 255, 0.24);
    border-radius: 8px;
    background: rgba(2, 12, 24, 0.72);
    color: var(--text);
    outline: none;
    transition: border-color 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
}

input::placeholder {
    color: rgba(143, 178, 202, 0.62);
}

input:focus {
    border-color: rgba(47, 210, 255, 0.82);
    background: rgba(3, 18, 34, 0.94);
    box-shadow: 0 0 0 3px rgba(47, 210, 255, 0.13);
}

.airport-line {
    min-height: 34px;
    margin: 7px 0 0;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.3;
}

.airport-line.is-found {
    color: var(--green);
}

.airport-line.is-error {
    color: var(--danger);
}

.route-readout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 14px;
}

.route-readout div,
.time-output {
    min-height: 68px;
    padding: 10px;
    border-radius: 8px;
    background: rgba(47, 210, 255, 0.08);
    border: 1px solid rgba(127, 206, 255, 0.16);
}

.route-readout div:last-child {
    grid-column: 1 / -1;
}

.route-readout span,
.time-output span {
    display: block;
    margin-bottom: 4px;
    color: var(--muted);
    font-size: 12px;
}

.route-readout strong,
.time-output strong {
    display: block;
    color: var(--text);
    font-size: 18px;
    line-height: 1.2;
}

.time-output {
    margin-top: 12px;
}

.time-output strong {
    color: var(--green);
    font-size: 24px;
}

.actions-panel {
    display: grid;
    gap: 10px;
}

.primary-btn,
.button-grid button,
.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 42px;
    border-radius: 8px;
    color: var(--text);
    background: rgba(47, 210, 255, 0.12);
    border: 1px solid rgba(127, 206, 255, 0.22);
    transition: transform 0.16s ease, border-color 0.16s ease, background 0.16s ease;
}

.primary-btn {
    background: linear-gradient(135deg, #0ca8d4, #1878da);
    border-color: rgba(117, 230, 255, 0.45);
    font-weight: 800;
}

.button-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.primary-btn:hover:not(:disabled),
.button-grid button:hover:not(:disabled),
.icon-btn:hover:not(:disabled) {
    transform: translateY(-1px);
    background: rgba(47, 210, 255, 0.2);
    border-color: rgba(117, 230, 255, 0.5);
}

.primary-btn:hover:not(:disabled) {
    background: linear-gradient(135deg, #18bee8, #2290f0);
}

.status-line {
    min-height: 18px;
    margin: 0;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.35;
}

.status-line.is-ok {
    color: var(--green);
}

.status-line.is-error {
    color: var(--danger);
}

.routes-panel {
    flex: 1;
    min-height: 190px;
}

.routes-list {
    display: grid;
    gap: 8px;
}

.route-card {
    display: grid;
    gap: 5px;
    width: 100%;
    padding: 10px;
    border-radius: 8px;
    text-align: left;
    background: rgba(2, 12, 24, 0.58);
    color: var(--text);
    border: 1px solid rgba(127, 206, 255, 0.16);
}

.route-card.is-active {
    border-color: rgba(109, 245, 191, 0.64);
    background: rgba(14, 72, 80, 0.42);
}

.route-card strong {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    font-size: 14px;
}

.route-card span {
    color: var(--muted);
    font-size: 12px;
    line-height: 1.35;
}

.empty-list {
    margin: 10px 0 0;
    color: var(--muted);
    font-size: 13px;
}

.map-stage {
    position: relative;
    min-width: 0;
    background: #07111d;
}

#map {
    position: absolute;
    inset: 0;
    z-index: 0;
}

.map-toolbar {
    position: absolute;
    z-index: 500;
    top: 18px;
    left: 18px;
    right: 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    max-width: 780px;
    padding: 12px;
    border: 1px solid rgba(127, 206, 255, 0.22);
    border-radius: 8px;
    background: rgba(3, 15, 28, 0.86);
    box-shadow: 0 18px 50px rgba(0, 0, 0, 0.26);
    backdrop-filter: blur(10px);
}

.map-toolbar span {
    display: block;
    margin-bottom: 2px;
    color: var(--accent-strong);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0;
}

.map-toolbar strong {
    display: block;
    color: var(--text);
    font-size: 15px;
    line-height: 1.25;
}

.icon-btn {
    width: 42px;
    aspect-ratio: 1;
    flex: 0 0 auto;
    padding: 0;
}

.leaflet-container {
    background: #081520;
    font: inherit;
}

.leaflet-control-layers {
    border: 1px solid rgba(127, 206, 255, 0.24) !important;
    border-radius: 8px !important;
    background: rgba(3, 15, 28, 0.9) !important;
    color: var(--text);
    box-shadow: 0 14px 34px rgba(0, 0, 0, 0.28) !important;
}

.leaflet-control-layers label {
    color: var(--text);
    font-size: 13px;
}

.leaflet-bar a {
    background: rgba(3, 15, 28, 0.92) !important;
    color: var(--text) !important;
    border-color: rgba(127, 206, 255, 0.24) !important;
}

.airport-marker {
    display: grid;
    place-items: center;
    width: 54px;
    min-height: 28px;
    padding: 5px 8px;
    border-radius: 8px;
    background: rgba(3, 15, 28, 0.92);
    border: 1px solid rgba(117, 230, 255, 0.58);
    color: var(--text);
    font-weight: 800;
    font-size: 12px;
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.34);
}

.airport-marker.arrival {
    border-color: rgba(109, 245, 191, 0.66);
}

.route-tooltip {
    padding: 7px 9px !important;
    border: 1px solid rgba(117, 230, 255, 0.48) !important;
    border-radius: 8px !important;
    background: rgba(3, 15, 28, 0.92) !important;
    color: var(--text) !important;
    box-shadow: 0 14px 34px rgba(0, 0, 0, 0.28);
    font-weight: 700;
}

.route-tooltip::before {
    border-top-color: rgba(3, 15, 28, 0.92) !important;
}

.route-arrow-icon {
    background: transparent;
    border: 0;
}

.route-arrow {
    width: 34px;
    height: 34px;
    color: var(--amber);
    filter: drop-shadow(0 7px 14px rgba(0, 0, 0, 0.48));
    transform-origin: center;
}

.route-arrow svg {
    display: block;
    width: 34px;
    height: 34px;
}

/* ---------- Airports directory ---------- */
.airports-directory {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 18px 22px;
    overflow: hidden;
}

.airports-header {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
    flex: 0 0 auto;
}

.airports-header h1 {
    margin: 0;
    font-size: 20px;
}

.airports-header p {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 13px;
}

.airports-search {
    min-width: 260px;
    flex: 1 1 320px;
    max-width: 480px;
    margin-top: 0;
}

.airports-table-wrap {
    flex: 1;
    min-height: 0;
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
}

.airports-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.airports-table thead th {
    position: sticky;
    top: 0;
    z-index: 1;
    text-align: left;
    padding: 10px 12px;
    background: var(--panel-strong);
    color: var(--accent-strong);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    border-bottom: 1px solid var(--line);
}

.airports-table td {
    padding: 9px 12px;
    border-bottom: 1px solid rgba(127, 206, 255, 0.1);
    color: var(--text);
    vertical-align: middle;
}

.airports-table tbody tr:hover {
    background: rgba(47, 210, 255, 0.08);
}

.airports-table .icao-cell {
    font-weight: 800;
    color: var(--accent-strong);
    white-space: nowrap;
}

.airports-table .muted-cell {
    color: var(--muted);
}

.airport-pick-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    min-height: 30px;
    padding: 0 10px;
    border-radius: 6px;
    background: rgba(47, 210, 255, 0.12);
    border: 1px solid rgba(127, 206, 255, 0.24);
    color: var(--text);
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
}

.airport-pick-btn + .airport-pick-btn {
    margin-left: 6px;
}

.airport-pick-btn:hover {
    background: rgba(47, 210, 255, 0.22);
}

.airports-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex: 0 0 auto;
    color: var(--muted);
    font-size: 12px;
}

.airports-footer .primary-btn {
    padding: 0 16px;
}

.airports-empty {
    padding: 24px 12px;
    text-align: center;
    color: var(--muted);
}

@media (max-width: 1024px) {
    .app-shell {
        grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
    }
}

@media (max-width: 900px) {
    body {
        height: auto;
        min-height: 100%;
        overflow-y: auto;
        padding-top: 56px;
    }

    .view {
        position: static;
        top: auto;
        left: auto;
        right: auto;
        bottom: auto;
        overflow: visible;
    }

    .view:not([hidden]) {
        min-height: calc(100vh - 56px);
    }

    .app-shell {
        grid-template-columns: 1fr;
        grid-template-rows: auto 68vh;
        height: auto;
    }

    .sidebar {
        max-height: none;
        border-right: 0;
        border-bottom: 1px solid var(--line);
    }

    .map-stage {
        min-height: 68vh;
    }

    .map-toolbar {
        top: 10px;
        left: 10px;
        right: 10px;
        flex-wrap: wrap;
    }

    .leaflet-top.leaflet-right {
        top: auto;
        bottom: 10px;
    }

    .airports-directory {
        padding: 14px;
    }

    .airports-header {
        align-items: stretch;
    }

    .airports-search {
        max-width: none;
    }

    .airports-table {
        font-size: 12.5px;
    }

    .airports-table th:nth-child(5),
    .airports-table td:nth-child(5) {
        display: none;
    }
}

@media (max-width: 560px) {
    .view-tabs {
        padding: 6px 8px;
    }

    .view-tab span {
        display: none;
    }

    .view-tab {
        min-width: 44px;
        padding: 0 12px;
        justify-content: center;
    }

    .sidebar {
        padding: 12px;
        gap: 10px;
    }

    .brand {
        grid-template-columns: 42px 1fr;
    }

    .brand-mark {
        width: 42px;
    }

    .brand h1 {
        font-size: 18px;
    }

    .panel {
        padding: 12px;
    }

    .route-readout,
    .button-grid {
        grid-template-columns: 1fr;
    }

    .route-readout div:last-child {
        grid-column: auto;
    }

    .map-toolbar {
        align-items: flex-start;
    }

    .airports-table th:nth-child(2),
    .airports-table td:nth-child(2) {
        display: none;
    }

    .airport-pick-btn {
        min-height: 32px;
        padding: 0 8px;
        font-size: 11px;
    }

    .airport-pick-btn + .airport-pick-btn {
        margin-left: 4px;
        margin:10px;
    }
}

/* Larger touch targets and a collapsible layer switcher on touch/small screens */
@media (max-width: 900px), (pointer: coarse) {
    .leaflet-control-layers-toggle {
        width: 40px !important;
        height: 40px !important;
    }

    .leaflet-touch .leaflet-bar a {
        width: 34px;
        height: 34px;
        line-height: 34px;
    }

    .leaflet-control-layers label {
        padding: 3px 0;
    }
}
