/* PaxLog - app styles. Follows the iOS app's look: accent #4A90D9, grouped cards, monospace
   airport codes. Light or dark, from the phone's setting. */

:root {
    --accent: #4A90D9;
    --accent-ink: #ffffff;
    --green: #34C7A0;
    --orange: #F29B38;
    --purple: #9B6BD6;
    --danger: #D9463B;
    --bg: #F2F2F7;
    --card: #FFFFFF;
    --ink: #1C1C1E;
    --muted: #6E6E73;
    --line: #E3E3E8;
    --field: #FFFFFF;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
    --radius: 14px;
    --tabs-height: 64px;
    color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #000000;
        --card: #1C1C1E;
        --ink: #F2F2F7;
        --muted: #98989F;
        --line: #38383A;
        --field: #2C2C2E;
        --shadow: none;
    }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 28px; line-height: 1.2; margin: 8px 0 16px; }
h2 { font-size: 18px; margin: 0 0 12px; }
p { margin: 0 0 12px; }

.muted { color: var(--muted); }
.small { font-size: 14px; }
.center { text-align: center; }
.align-end { text-align: right; }
.code, .hero-code, .hero-number {
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    font-weight: 700;
    letter-spacing: 0.02em;
}

/* ── Layout: content above a bottom tab bar on phones; tabs on top on wide screens ── */

.view {
    max-width: 760px;
    margin: 0 auto;
    padding: 16px 16px calc(var(--tabs-height) + 24px + env(safe-area-inset-bottom));
    outline: none;
}

.tabs {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 10;
    display: flex;
    justify-content: space-around;
    height: calc(var(--tabs-height) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: color-mix(in srgb, var(--card) 92%, transparent);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-top: 1px solid var(--line);
}
body.signed-out .tabs { display: none; }

.tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 600;
}
.tab:hover { text-decoration: none; }
.tab.active { color: var(--accent); }
.tab-icon { font-size: 22px; line-height: 1; }
.tab[href="#/add"] .tab-icon {
    width: 34px; height: 34px; border-radius: 50%;
    display: grid; place-items: center;
    background: var(--accent); color: var(--accent-ink);
    font-size: 24px;
}

@media (min-width: 768px) {
    .view { padding: calc(var(--tabs-height) + 24px) 24px 48px; }
    .tabs {
        top: 0; bottom: auto;
        height: var(--tabs-height);
        padding: 0 max(24px, calc((100% - 760px) / 2));
        justify-content: flex-start;
        gap: 8px;
        border-top: none;
        border-bottom: 1px solid var(--line);
    }
    .tab { flex: 0 0 auto; flex-direction: row; gap: 8px; padding: 0 12px; font-size: 15px; }
    .tab-icon { font-size: 18px; }
    .tab[href="#/add"] .tab-icon { width: 26px; height: 26px; font-size: 18px; }
}

/* ── Building blocks ── */

.card {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
    margin-bottom: 16px;
}

.page-head, .section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.page-head h1 { margin-bottom: 4px; }
.page-head { margin-bottom: 16px; }
.section-head { margin: 24px 0 8px; }
.section-head h2 { margin: 0; }

.icon-btn {
    display: grid; place-items: center;
    width: 40px; height: 40px; border-radius: 50%;
    background: var(--card); box-shadow: var(--shadow);
    color: var(--ink); font-size: 20px;
}
.icon-btn:hover { text-decoration: none; }

.back { display: inline-block; margin-bottom: 8px; font-weight: 600; }

.btn {
    display: inline-flex; align-items: center; justify-content: center;
    min-height: 44px; padding: 0 18px;
    border: 1px solid var(--line); border-radius: 12px;
    background: var(--card); color: var(--ink);
    font: inherit; font-weight: 600; cursor: pointer;
}
.btn:hover { text-decoration: none; filter: brightness(0.97); }
.btn:disabled { opacity: 0.6; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-danger { color: var(--danger); }
.btn-block { display: flex; width: 100%; }

.actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 8px; }

.alert { border-radius: 12px; padding: 12px 14px; margin-bottom: 12px; }
.alert-info { background: color-mix(in srgb, var(--accent) 14%, var(--card)); }
.alert-success { background: color-mix(in srgb, var(--green) 18%, var(--card)); }
.alert-error { background: color-mix(in srgb, var(--danger) 15%, var(--card)); }

.loading, .empty { padding: 32px 16px; text-align: center; color: var(--muted); }
.empty .btn { margin-top: 8px; }

/* ── Forms ── */

.field { display: block; margin-bottom: 14px; }
.field-label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 6px; }
.field-hint { display: block; font-size: 13px; color: var(--muted); margin-top: 4px; }

.input {
    width: 100%; min-height: 44px; padding: 10px 12px;
    border: 1px solid var(--line); border-radius: 10px;
    background: var(--field); color: var(--ink);
    font: inherit;
}
.input:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
.input.code { text-transform: uppercase; }
.input.search { margin-bottom: 16px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.grid-2.tight { gap: 8px; }
@media (max-width: 420px) { .grid-2:not(.tight) { grid-template-columns: 1fr; } }

.chips { display: flex; gap: 8px; margin-top: 8px; }
.chip {
    border: 1px solid var(--line); border-radius: 999px; padding: 4px 12px;
    background: var(--card); color: var(--ink); font: inherit; font-size: 14px; cursor: pointer;
}

details summary { cursor: pointer; color: var(--accent); margin-top: 8px; }
.steps { margin: 12px 0 0 20px; padding: 0; }
.steps li { margin-bottom: 6px; }

/* ── Airline picker ── */

.picker { position: relative; }
.picker-list {
    display: none;
    position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 20;
    max-height: 260px; overflow-y: auto;
    background: var(--card); border: 1px solid var(--line); border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}
.picker-list.open { display: block; }
.picker-option {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 12px; cursor: pointer;
}
.picker-option span:nth-child(2) { flex: 1; }
.picker-option:hover, .picker-option.active { background: color-mix(in srgb, var(--accent) 14%, var(--card)); }

/* ── Airline marks ── */

.airline-mark { flex: 0 0 auto; border-radius: 8px; object-fit: contain; background: #fff; }
.airline-mark-sm { width: 28px; height: 28px; }
.airline-mark-md { width: 40px; height: 40px; }
.airline-mark-lg { width: 56px; height: 56px; }
.airline-badge {
    display: grid; place-items: center;
    background: color-mix(in srgb, var(--accent) 16%, var(--card)); color: var(--accent);
    font: 700 13px ui-monospace, "SF Mono", Menlo, monospace;
}
.airline-mark-lg.airline-badge { font-size: 18px; }

/* ── Home ── */

.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (min-width: 600px) { .tiles { grid-template-columns: repeat(4, 1fr); } }
.tile { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; }
.tile-value { font-size: 26px; font-weight: 800; }
.tile-label { font-size: 13px; color: var(--muted); font-weight: 600; }
.tone-blue .tile-value { color: var(--accent); }
.tone-green .tile-value { color: var(--green); }
.tone-orange .tile-value { color: var(--orange); }
.tone-purple .tile-value { color: var(--purple); }

/* ── Flight lists ── */

.list { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.row {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 14px; color: var(--ink);
    border-bottom: 1px solid var(--line);
}
.row:last-child { border-bottom: none; }
.row:hover { text-decoration: none; background: color-mix(in srgb, var(--accent) 6%, var(--card)); }
.row-main { flex: 1; min-width: 0; }
.row-title { display: flex; align-items: center; gap: 8px; font-size: 17px; }
.row-sub { font-size: 14px; }
.row-side { font-size: 14px; white-space: nowrap; }
.arrow { color: var(--muted); }

.group { margin-bottom: 20px; }
.group-head { font-size: 15px; margin: 0 0 8px 4px; }

/* ── One flight ── */

.flight-hero { text-align: left; }
.hero-airline { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.hero-number { font-size: 20px; }
.hero-route { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px; margin-bottom: 8px; }
.hero-code { font-size: 30px; }
.hero-line {
    position: relative; text-align: center; font-size: 14px; color: var(--muted);
    border-top: 2px dashed var(--line); padding-top: 6px;
}
.details { margin: 0 0 16px; padding: 4px 16px; }
.detail-row { display: flex; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.detail-row:last-child { border-bottom: none; }
.detail-row dt { color: var(--muted); }
.detail-row dd { margin: 0; text-align: right; font-weight: 600; }

/* ── Lookup results ── */

.options { margin-top: 12px; }
.option {
    display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
    border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin-bottom: 10px;
}
.option-main { flex: 1; min-width: 200px; }

/* ── Sign in ── */

.signin { max-width: 380px; margin: 12vh auto 0; text-align: center; }
.signin-icon { width: 88px; height: 88px; border-radius: 20px; box-shadow: var(--shadow); }
.signin h1 { margin-top: 16px; }
.signin .btn { margin: 16px 0; }

/* ── Messages ── */

.toast-area {
    position: fixed; left: 0; right: 0; z-index: 30;
    bottom: calc(var(--tabs-height) + 16px + env(safe-area-inset-bottom));
    display: flex; justify-content: center; pointer-events: none;
}
.toast {
    pointer-events: auto;
    max-width: 90vw; padding: 12px 18px; border-radius: 12px;
    background: var(--ink); color: var(--bg); font-weight: 600;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}
.toast-error { background: var(--danger); color: #fff; }
@media (min-width: 768px) { .toast-area { bottom: 24px; } }

/* ── Home header buttons ── */

.head-buttons { display: flex; gap: 8px; }

/* ── Map ── */

.map {
    height: min(62vh, 560px);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    margin-bottom: 12px;
    background: var(--card);
}
.map .leaflet-popup-content { font: inherit; }

/* ── Stats ── */

.tiles + .section-head { margin-top: 24px; }
.ranking { list-style: none; margin: 0; padding: 0; }
.ranking li { margin-bottom: 10px; }
.ranking-label { display: flex; justify-content: space-between; gap: 12px; font-size: 15px; margin-bottom: 4px; }
.bar-track { height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; }
.bar { display: block; height: 100%; border-radius: 4px; background: var(--accent); }

/* ── Import ── */

.mapping { margin: 12px 0; }
.mapping-row {
    display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); gap: 12px; align-items: center;
    padding: 10px 0; border-bottom: 1px solid var(--line);
}
.mapping-name { font-weight: 600; overflow-wrap: anywhere; }
.issues { margin-top: 12px; }
.issues ul { margin: 8px 0 0 18px; padding: 0; font-size: 14px; }

/* ── Admin ── */

.invite-form { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.invite-form .field { flex: 1; min-width: 220px; margin-bottom: 0; }
.user-row { flex-wrap: wrap; }
.user-row.is-disabled .row-main { opacity: 0.6; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.row-actions .btn { min-height: 36px; padding: 0 12px; font-size: 14px; }
.tags { display: flex; gap: 6px; margin-top: 4px; flex-wrap: wrap; }
.tag {
    font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px;
    background: color-mix(in srgb, var(--accent) 14%, var(--card)); color: var(--accent);
}

/* ── Admin: backup status ── */

.status-list { list-style: none; margin: 0; padding: 0; }
.status { padding: 8px 0 8px 28px; position: relative; }
.status::before { position: absolute; left: 0; top: 8px; font-weight: 800; }
.status-good::before { content: "✓"; color: var(--green); }
.status-warn::before { content: "!"; color: var(--orange); left: 6px; }
.status-bad::before { content: "✕"; color: var(--danger); }
