:root {
    color-scheme: dark;
    --bg: #090d16;
    --sidebar: #0b0f19;
    --panel: rgba(17, 24, 39, .82);
    --panel-solid: #111827;
    --border: rgba(148, 163, 184, .16);
    --muted: #94a3b8;
    --text: #e5edf7;
    --teal: #00c4b3;
    --blue: #00a3e0;
    --navy: #011e41;
    --amber: #fbbf24;
    --danger: #fb7185;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
    background:
        radial-gradient(circle at 75% 0, rgba(0, 163, 224, .08), transparent 32rem),
        var(--bg);
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.topbar {
    align-items: center;
    backdrop-filter: blur(14px);
    background: rgba(13, 19, 34, .93);
    border-bottom: 1px solid var(--border);
    display: flex;
    gap: 14px;
    height: 68px;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 20;
}
.brand-mark {
    align-items: center;
    background: linear-gradient(135deg, var(--navy), var(--blue), var(--teal));
    border-radius: 13px;
    box-shadow: 0 0 24px rgba(0, 196, 179, .2);
    display: flex;
    font-size: 20px;
    height: 42px;
    justify-content: center;
    width: 42px;
}
.brand-copy h1 { font-size: 17px; letter-spacing: -.02em; margin: 0; }
.brand-copy h1 span {
    background: rgba(0, 163, 224, .13);
    border: 1px solid rgba(0, 163, 224, .25);
    border-radius: 999px;
    color: var(--blue);
    font-size: 10px;
    margin-left: 5px;
    padding: 3px 8px;
}
.brand-copy p, .panel-heading p { color: var(--muted); font-size: 11px; margin: 3px 0 0; }
.crew-badge {
    align-items: center;
    background: rgba(3, 7, 18, .55);
    border: 1px solid var(--border);
    border-radius: 10px;
    display: flex;
    gap: 18px;
    margin-left: auto;
    padding: 7px 12px;
}
.crew-badge div + div { border-left: 1px solid var(--border); padding-left: 18px; }
.crew-badge small { color: var(--muted); display: block; font-size: 9px; }
.crew-badge strong { display: block; font-size: 11px; margin-top: 2px; }
.year-filter {
    align-items: center;
    display: flex;
    gap: 7px;
    margin-left: auto;
}
.year-filter label { color: var(--muted); font-size: 9px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.year-filter select, .year-filter button {
    background: #0b1220;
    border: 1px solid var(--border);
    border-radius: 7px;
    color: var(--text);
    font-size: 11px;
    padding: 7px 9px;
}
.year-filter + .crew-badge { margin-left: 0; }

.button {
    align-items: center;
    border: 1px solid transparent;
    border-radius: 9px;
    cursor: pointer;
    display: inline-flex;
    font-size: 12px;
    font-weight: 700;
    justify-content: center;
    min-height: 38px;
    padding: 8px 15px;
    text-decoration: none;
}
.button-primary { background: linear-gradient(90deg, var(--blue), var(--teal)); color: #03131c; }
.button-subtle { background: rgba(0, 163, 224, .1); border-color: rgba(0, 163, 224, .32); color: var(--blue); }
.button:hover { filter: brightness(1.13); }

.app-shell { display: grid; grid-template-columns: 238px minmax(0, 1fr); min-height: calc(100vh - 68px); }
.sidebar {
    background: var(--sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 14px 12px;
}
.sidebar nav { display: grid; gap: 5px; }
.nav-button {
    align-items: center;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 10px;
    color: var(--muted);
    cursor: pointer;
    display: flex;
    gap: 11px;
    padding: 10px 11px;
    text-align: left;
    width: 100%;
}
.nav-button span { font-size: 17px; text-align: center; width: 19px; }
.nav-button:hover { background: rgba(51, 65, 85, .35); color: var(--text); }
.nav-button.active { background: rgba(0, 196, 179, .09); border-color: rgba(0, 196, 179, .2); color: var(--teal); }
.db-status {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 10px;
    margin-top: auto;
    padding: 12px;
}
.db-status > div { align-items: center; color: var(--muted); display: flex; font-size: 11px; justify-content: space-between; }
.db-status i { background: #34d399; border-radius: 50%; box-shadow: 0 0 9px #34d399; height: 7px; width: 7px; }
.db-status p { color: var(--muted); display: flex; font-family: ui-monospace, monospace; font-size: 10px; justify-content: space-between; margin: 8px 0 0; }
.db-status strong { color: var(--teal); }
.logout-form { border-top: 1px solid var(--border); margin-top: 12px; padding-top: 8px; }

main { min-width: 0; padding: 24px; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }
.alert { border: 1px solid; border-radius: 10px; font-size: 13px; margin-bottom: 18px; padding: 12px 15px; }
.alert-success { background: rgba(52, 211, 153, .08); border-color: rgba(52, 211, 153, .3); color: #6ee7b7; }
.alert-error { background: rgba(251, 113, 133, .08); border-color: rgba(251, 113, 133, .3); color: #fda4af; }

.kpi-grid { display: grid; gap: 13px; grid-template-columns: repeat(6, minmax(0, 1fr)); }
.kpi-card, .panel {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: 0 16px 40px rgba(0, 0, 0, .1);
}
.kpi-card { min-height: 108px; overflow: hidden; padding: 17px; position: relative; }
.kpi-card::after {
    background: radial-gradient(circle, rgba(0, 196, 179, .16), transparent 68%);
    content: "";
    height: 100px;
    position: absolute;
    right: -35px;
    top: 25px;
    width: 100px;
}
.kpi-card p { color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: .08em; margin: 0; text-transform: uppercase; }
.kpi-card h2 { font-family: ui-monospace, "SFMono-Regular", monospace; font-size: clamp(21px, 2vw, 29px); margin: 10px 0 0; }
.kpi-card small { color: var(--teal); font-family: inherit; font-size: 10px; font-weight: 500; }
.panel { padding: 19px; }
.map-panel { margin-top: 20px; }
.map-panel.map-panel-expanded {
    border-radius: 0;
    display: flex;
    flex-direction: column;
    inset: 0;
    margin: 0;
    padding: 20px;
    position: fixed;
    z-index: 1000;
}
body.map-expanded { overflow: hidden; }
.map-panel.map-panel-expanded #route-map {
    flex: 1;
    height: auto;
    min-height: 0;
}
.panel-heading { align-items: center; display: flex; gap: 16px; justify-content: space-between; margin-bottom: 15px; }
.panel-heading h2 { font-size: 17px; margin: 0; }
.filter-buttons { display: flex; flex-wrap: wrap; gap: 7px; justify-content: flex-end; }
.filter-buttons button, .export-links a {
    background: #1e293b;
    border: 1px solid transparent;
    border-radius: 7px;
    color: #cbd5e1;
    cursor: pointer;
    font-size: 10px;
    padding: 7px 10px;
    text-decoration: none;
}
.filter-buttons button.active { background: rgba(0, 196, 179, .13); border-color: rgba(0, 196, 179, .35); color: var(--teal); }
#route-map {
    background: #dbe6ec;
    border: 1px solid var(--border);
    border-radius: 11px;
    height: 390px;
    overflow: hidden;
    width: 100%;
}
.leaflet-container { font-family: inherit; }
.leaflet-control-attribution { font-size: 9px; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip {
    background: #111827;
    color: var(--text);
}
.leaflet-popup-content { font-size: 11px; line-height: 1.5; margin: 10px 13px; }
.leaflet-popup-content strong { color: var(--teal); }
.leaflet-tooltip.airport-code-label {
    background: rgba(1, 30, 65, .92);
    border: 1px solid rgba(255, 255, 255, .82);
    border-radius: 5px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .32);
    color: #fff;
    font-family: ui-monospace, "SFMono-Regular", monospace;
    font-size: 10px;
    font-weight: 800;
    letter-spacing: .05em;
    line-height: 1;
    padding: 4px 6px;
}
.leaflet-tooltip-top.airport-code-label::before {
    border-top-color: rgba(1, 30, 65, .92);
}
.leaflet-overlay-pane path.route-line {
    animation: route-flow 1.8s linear infinite;
    animation-delay: var(--route-delay, 0s);
    stroke-dasharray: 11 9;
    stroke-linecap: round;
}
.leaflet-overlay-pane path.route-line-deadhead {
    animation-duration: 1.25s;
    stroke-dasharray: 4 9;
}
.leaflet-overlay-pane path.airport-dot {
    animation: airport-pulse 2.2s ease-in-out infinite;
    transform-box: fill-box;
    transform-origin: center;
}
@keyframes route-flow {
    to { stroke-dashoffset: -40; }
}
@keyframes airport-pulse {
    0%, 100% { filter: drop-shadow(0 0 1px rgba(0, 163, 224, .35)); transform: scale(1); }
    50% { filter: drop-shadow(0 0 5px rgba(0, 163, 224, .9)); transform: scale(1.22); }
}
@media (prefers-reduced-motion: reduce) {
    .leaflet-overlay-pane path.route-line,
    .leaflet-overlay-pane path.airport-dot {
        animation: none;
    }
}
.map-load-error {
    align-items: center;
    color: #334155;
    display: flex;
    font-size: 13px;
    justify-content: center;
    padding: 30px;
}
.analytics-grid { display: grid; gap: 20px; grid-template-columns: repeat(3, minmax(0, 1fr)); margin-top: 20px; }
.analytics-grid h3 { font-size: 13px; margin: 0 0 16px; }
.analytics-grid canvas { height: 220px; width: 100%; }

.route-row { display: grid; gap: 8px; grid-template-columns: 70px 1fr 55px; margin: 15px 0; }
.route-row span, .route-row strong { font-size: 11px; }
.route-row strong { color: var(--teal); text-align: right; }
.route-track { align-self: center; background: #1e293b; border-radius: 99px; height: 7px; overflow: hidden; }
.route-fill { background: linear-gradient(90deg, var(--blue), var(--teal)); height: 100%; }

.wrapped-intro { margin: 4px auto 14px; max-width: 680px; text-align: center; }
.wrapped-intro span { background: linear-gradient(90deg, var(--teal), var(--blue)); border-radius: 999px; color: #03131c; font-size: 9px; font-weight: 900; padding: 5px 11px; }
.wrapped-intro h2 { font-size: clamp(28px, 3.5vw, 42px); letter-spacing: -.05em; margin: 10px 0 3px; }
.wrapped-intro p { color: var(--muted); font-size: 13px; margin: 0; }
.wrapped-grid { display: grid; gap: 10px; grid-template-columns: repeat(5, minmax(0, 1fr)); margin: auto; max-width: 1250px; }
.wrapped-grid article {
    background: linear-gradient(135deg, var(--navy), #00426a, var(--blue));
    border-radius: 16px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, .25);
    min-height: 155px;
    padding: 16px;
}
.wrapped-grid article:nth-child(2) { background: linear-gradient(135deg, #071520, #006f68, #32d74b); }
.wrapped-grid article:nth-child(3) { background: linear-gradient(135deg, #18002e, #4c1d95, #ec4899); }
.wrapped-grid article:nth-child(4) { background: linear-gradient(135deg, #291703, #a14b05, #fbbf24); }
.wrapped-grid article:nth-child(5) { background: linear-gradient(135deg, #111827, #374151, #9ca3af); }
.wrapped-grid article:nth-child(6) { background: linear-gradient(135deg, #0c1b33, #075985, #38bdf8); }
.wrapped-grid article:nth-child(7) { background: linear-gradient(135deg, #1f1403, #854d0e, #eab308); }
.wrapped-grid article:nth-child(8) { background: linear-gradient(135deg, #1e1033, #6b21a8, #c084fc); }
.wrapped-grid article:nth-child(9) { background: linear-gradient(135deg, #10241a, #166534, #4ade80); }
.wrapped-grid article:nth-child(10) { background: linear-gradient(135deg, #23150f, #9a3412, #fb923c); }
.wrapped-grid small { font-size: 10px; font-weight: 800; letter-spacing: .13em; }
.wrapped-grid strong { display: block; font-size: clamp(30px, 3.7vw, 48px); letter-spacing: -.06em; margin-top: 10px; }
.wrapped-grid p { font-size: 12px; margin: 3px 0 0; }
.load-factor-control {
    align-items: center;
    background: rgba(3, 19, 28, .3);
    border-radius: 10px;
    display: flex;
    font-size: 11px;
    font-weight: 700;
    justify-content: space-between;
    margin-top: 8px;
    padding: 5px 8px;
}
.load-factor-control input {
    background: #071520;
    border: 1px solid rgba(255, 255, 255, .3);
    border-radius: 6px;
    color: var(--text);
    margin-right: 3px;
    padding: 3px 6px;
    text-align: right;
    width: 64px;
}
.overnights-card ol { list-style: none; margin: 8px 0 0; padding: 0; }
.overnights-card li {
    align-items: center;
    border-top: 1px solid rgba(255, 255, 255, .2);
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
}
.overnights-card li strong { font-size: 15px; letter-spacing: 0; margin: 0; }
.overnights-card li span { font-size: 10px; }

.table-tools { display: flex; gap: 10px; margin-bottom: 12px; }
.table-tools input, .table-tools select {
    background: #0b1220;
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    padding: 10px 12px;
}
.table-tools input { flex: 1; }
.table-wrap { border: 1px solid var(--border); border-radius: 12px; overflow: auto; }
table { border-collapse: collapse; font-size: 11px; width: 100%; }
th { background: #0f172a; color: var(--muted); font-size: 9px; letter-spacing: .08em; position: sticky; text-transform: uppercase; top: 0; }
th, td { border-bottom: 1px solid var(--border); padding: 11px 13px; text-align: left; white-space: nowrap; }
tbody tr:hover { background: rgba(30, 41, 59, .4); }
.badge { border-radius: 5px; display: inline-block; font-size: 9px; font-weight: 800; padding: 3px 7px; }
.badge-leg { background: rgba(0, 196, 179, .12); color: var(--teal); }
.badge-dho { background: rgba(251, 191, 36, .12); color: var(--amber); }
.table-count { color: var(--muted); font-size: 10px; text-align: right; }
.export-links { display: flex; gap: 7px; }

.upload-layout { display: grid; gap: 20px; margin: 10px auto; max-width: 820px; }
.upload-layout > div:first-child { text-align: center; }
.upload-layout > div:first-child h2 { margin-bottom: 6px; }
.upload-layout > div:first-child p, .reference-card p, .period-list p { color: var(--muted); font-size: 12px; }
.upload-card {
    background: var(--panel);
    border: 2px dashed #334155;
    border-radius: 18px;
    display: grid;
    gap: 16px;
    padding: 25px;
}
.upload-card:hover { border-color: var(--teal); }
.upload-card label { cursor: pointer; display: grid; gap: 7px; padding: 20px; text-align: center; }
.upload-card label::before { content: "⇧"; color: var(--teal); font-size: 46px; }
.upload-card label span { color: var(--muted); font-size: 11px; }
.upload-card input[type=file] { color: var(--muted); margin: 10px auto 0; max-width: 100%; }
.reference-card {
    align-items: center;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 14px;
    display: flex;
    justify-content: space-between;
    padding: 18px;
}
.reference-card h3, .reference-card p { margin: 0 0 4px; }
.period-list h3 { margin-top: 0; }
.period-list > div { align-items: center; border-top: 1px solid var(--border); display: flex; justify-content: space-between; padding: 11px 0; }
.period-list span { color: var(--muted); font-size: 11px; }

.login-page { align-items: center; display: flex; justify-content: center; min-height: 100vh; padding: 24px; }
.login-card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 24px;
    box-shadow: 0 30px 80px rgba(0, 0, 0, .4);
    max-width: 460px;
    padding: 42px;
    text-align: center;
}
.login-plane { background: linear-gradient(135deg, var(--blue), var(--teal)); border-radius: 18px; color: #02131b; display: grid; font-size: 32px; height: 70px; margin: auto; place-items: center; width: 70px; }
.eyebrow { color: var(--teal); font-size: 10px; font-weight: 900; letter-spacing: .15em; margin-top: 22px; }
.login-card h1 { font-size: 34px; letter-spacing: -.04em; margin: 5px 0 10px; }
.login-card > p:not(.eyebrow) { color: var(--muted); line-height: 1.6; }
.login-button { margin-top: 18px; width: 100%; }
code { font-family: ui-monospace, monospace; }

@media (max-width: 1180px) {
    .kpi-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .wrapped-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .crew-badge { display: none; }
}
@media (max-width: 850px) {
    .app-shell { grid-template-columns: 62px minmax(0, 1fr); }
    .sidebar { padding: 12px 7px; }
    .nav-button { justify-content: center; padding: 10px 7px; }
    .nav-button:not(.active) { color: var(--muted); }
    .nav-button { font-size: 0; }
    .nav-button span { font-size: 18px; }
    .db-status { display: none; }
    .analytics-grid { grid-template-columns: 1fr; }
    .wrapped-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .topbar { padding: 0 13px; }
    .brand-copy p { display: none; }
    main { padding: 16px; }
}
@media (max-width: 620px) {
    .topbar > .button { font-size: 0; padding: 8px; }
    .topbar > .button::after { content: "⇧"; font-size: 18px; }
    .brand-copy h1 span { display: none; }
    .year-filter label { display: none; }
    .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .kpi-card { padding: 13px; }
    #route-map { height: 290px; }
    .panel-heading { align-items: flex-start; flex-direction: column; }
    .wrapped-grid { grid-template-columns: 1fr; }
    .reference-card { align-items: stretch; flex-direction: column; gap: 12px; }
}
