/* Theo dõi chuyến bay – giao diện */
:root {
  --font: "Segoe UI", system-ui, -apple-system, "SF Pro Text", Roboto, "Helvetica Neue", Arial, sans-serif;
  --navy: #0b1f30;
  --navy2: #12304a;
  --bg: #eef3f6;
  --surface: #ffffff;
  --surface2: #f4f8fa;
  --ink: #13293a;
  --ink2: #48606f;
  --ink3: #7a8e9a;
  --line: #dde6eb;
  --brand: #0e7490;
  --brand2: #0b5f77;
  --brand-soft: #e3f3f7;
  --accent: #f2a33a;
  --live: #12a971;
  --last: #77848f;
  --est: #df8a14;
  --route: #d98f2b;
  --track: #0e8fb3;
  --danger: #cf3f36;
  --danger-soft: #fdeceb;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(10, 35, 55, .12);
  --shadow-sm: 0 2px 8px rgba(10, 35, 55, .08);
  --top-h: 58px;
  --panel-w: 392px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #07121b;
  --surface: #0f1e2b;
  --surface2: #132637;
  --ink: #e2ecf2;
  --ink2: #a7bac6;
  --ink3: #7a90a0;
  --line: #1e3445;
  --brand: #3fb6d8;
  --brand2: #66c9e6;
  --brand-soft: #123447;
  --danger-soft: #3a1714;
  --shadow: 0 10px 30px rgba(0, 0, 0, .45);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, .35);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font); color: var(--ink); background: var(--bg);
  font-size: 14px; line-height: 1.45; overflow: hidden;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .45; }
:focus-visible { outline: 3px solid var(--brand); outline: 3px solid color-mix(in srgb, var(--brand) 55%, transparent); outline-offset: 2px; }
svg { width: 18px; height: 18px; flex: 0 0 auto; }
[hidden] { display: none !important; }
h2 { font-size: 15px; margin: 0; letter-spacing: .1px; }
a { color: var(--brand); }

/* ---------- Thanh trên ---------- */
.topbar {
  height: calc(var(--top-h) + var(--safe-t)); padding: var(--safe-t) 18px 0;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: linear-gradient(100deg, var(--navy) 0%, var(--navy2) 100%); color: #fff;
  position: relative; z-index: 30; box-shadow: 0 2px 14px rgba(0, 0, 0, .18);
}
.brand { display: flex; align-items: center; gap: 11px; min-width: 0; }
.brand-mark { width: 38px; height: 38px; border-radius: 11px; box-shadow: 0 0 0 1px rgba(255,255,255,.12); }
.brand-text { min-width: 0; }
.brand-text b { display: block; font-size: 18px; letter-spacing: 1.6px; font-weight: 800; line-height: 1.15; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-text small { display: block; font-size: 11px; color: #9fc3d4; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.top-right { display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 99px; font-size: 12px; background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.14); }
.chip .dot { width: 7px; height: 7px; border-radius: 50%; background: #8aa0ad; }
.chip.on .dot { background: #4ade80; }
.chip.off .dot { background: #fbbf24; }
.clock { font-variant-numeric: tabular-nums; font-size: 15px; font-weight: 600; color: #dcecf3; min-width: 44px; text-align: right; }
.fm-btn { display: inline-flex; align-items: center; gap: 7px; padding: 8px 14px; border-radius: 10px; border: 0; background: var(--accent); color: #2b1a00; font-weight: 700; font-size: 13px; box-shadow: 0 3px 12px rgba(242,163,58,.35); }
.fm-btn:hover { filter: brightness(1.05); }

/* ---------- Bố cục ---------- */
.layout { height: calc(100vh - var(--top-h) - var(--safe-t)); height: calc(100dvh - var(--top-h) - var(--safe-t)); display: grid; grid-template-columns: var(--panel-w) minmax(0, 1fr); }
.panel { grid-column: 1; grid-row: 1; background: var(--surface); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; z-index: 10; }
.mapwrap { grid-column: 2; grid-row: 1; position: relative; overflow: hidden; background: #d4e8f1; isolation: isolate; }
#map { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; outline: none; }
#map.grabbing { cursor: grabbing; }
#map:focus-visible { box-shadow: inset 0 0 0 3px color-mix(in srgb, var(--brand) 50%, transparent); }

.sheet-grip { display: none; }

/* ---------- Đo đạc ---------- */
.telemetry { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1px; background: var(--line); border-bottom: 1px solid var(--line); }
.tcell { background: var(--surface); padding: 9px 12px 10px; min-width: 0; }
.tcell small { display: block; font-size: 10.5px; text-transform: uppercase; letter-spacing: .7px; color: var(--ink3); font-weight: 700; }
.tcell b { display: block; font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.tcell b .u { font-size: 11px; font-weight: 600; color: var(--ink3); margin-left: 3px; }
.tcell b.na { font-size: 12px; font-weight: 600; color: var(--ink3); padding-top: 3px; white-space: normal; }
.telemetry.is-last .tcell b { color: var(--last); }

/* ---------- Tab ---------- */
.tabs { display: grid; grid-template-columns: repeat(5, 1fr); padding: 6px 8px 0; gap: 2px; border-bottom: 1px solid var(--line); background: var(--surface); }
.tab { border: 0; background: none; padding: 8px 2px 9px; display: flex; flex-direction: column; align-items: center; gap: 3px; color: var(--ink3); font-size: 11.5px; font-weight: 600; border-bottom: 2.5px solid transparent; border-radius: 8px 8px 0 0; }
.tab svg { width: 19px; height: 19px; }
.tab:hover { color: var(--ink2); background: var(--surface2); }
.tab.active { color: var(--brand); border-bottom-color: var(--brand); }
.panes { flex: 1; overflow-y: auto; padding: 14px 14px 20px; overscroll-behavior: contain; scrollbar-width: thin; }
.pane-h { display: flex; justify-content: space-between; align-items: center; margin: 2px 2px 12px; }
.panel-foot { padding: 9px 14px calc(9px + var(--safe-b)); font-size: 11.5px; color: var(--ink3); border-top: 1px solid var(--line); text-align: center; background: var(--surface); }

/* ---------- Thẻ ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; box-shadow: var(--shadow-sm); }
.card-h { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 10px; }
.card.danger { border-color: color-mix(in srgb, var(--danger) 30%, var(--line)); }
.tag { font-size: 11px; font-weight: 700; color: var(--ink3); background: var(--surface2); border: 1px solid var(--line); padding: 3px 8px; border-radius: 99px; white-space: nowrap; }
.tag.good { color: var(--live); border-color: color-mix(in srgb, var(--live) 35%, transparent); background: color-mix(in srgb, var(--live) 10%, transparent); }
.tag.warn { color: var(--est); border-color: color-mix(in srgb, var(--est) 35%, transparent); background: color-mix(in srgb, var(--est) 10%, transparent); }
.tag.bad { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, transparent); background: var(--danger-soft); }
.tag.rec { color: #fff; background: var(--danger); border-color: var(--danger); }
.status-line { display: flex; gap: 8px; align-items: flex-start; margin: 0 0 4px; font-size: 13px; color: var(--ink2); }
.sub-line { margin: 4px 0 8px; font-size: 12.5px; color: var(--ink2); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ink3); flex: 0 0 auto; margin-top: 5px; display: inline-block; }
.dot.good { background: var(--live); box-shadow: 0 0 0 3px color-mix(in srgb, var(--live) 22%, transparent); }
.dot.wait { background: var(--accent); }
.dot.bad { background: var(--danger); }
.dot.off { background: var(--last); }
.hint { margin: 10px 0 0; font-size: 12px; color: var(--ink3); line-height: 1.55; }
.hint b { color: var(--ink2); }

/* ---------- Nút ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 42px; padding: 9px 12px; border-radius: 11px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font-weight: 650; font-size: 13px; transition: transform .12s, background .12s, filter .12s; text-align: center; }
.btn:hover:not(:disabled) { background: var(--surface2); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--brand2); }
.btn.soft { background: var(--brand-soft); border-color: transparent; color: var(--brand); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink2); }
.btn.warn { background: var(--danger-soft); border-color: transparent; color: var(--danger); }
.btn.on { background: var(--live); border-color: var(--live); color: #fff; }
.btn.sm { min-height: 36px; padding: 6px 10px; font-size: 12.5px; }
.btn.rec { width: 100%; background: var(--navy); color: #fff; border-color: var(--navy); min-height: 46px; font-size: 14px; }
.btn.rec svg { color: #ff6b5f; }
.btn.rec.active { background: var(--danger); border-color: var(--danger); }
.btn.rec.active svg { color: #fff; }
:root[data-theme="dark"] .btn.rec:not(.active) { background: #1b3a52; border-color: #1b3a52; }
.icon-btn { display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--ink2); }
.icon-btn:hover { background: var(--surface2); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.row3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 10px; }
.row-btns { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }

/* ---------- Biểu mẫu ---------- */
.field { display: block; min-width: 0; }
.field > span { display: block; font-size: 11.5px; font-weight: 700; color: var(--ink3); margin-bottom: 5px; }
.field select, .field input { width: 100%; height: 40px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface2); padding: 0 10px; font-size: 13.5px; color: var(--ink); min-width: 0; }
.field input[type="datetime-local"] { font-size: 12.5px; padding: 0 6px; }
.route-pick { display: grid; grid-template-columns: minmax(0,1fr) auto minmax(0,1fr); gap: 6px; align-items: end; }
.route-pick .swap { margin-bottom: 1px; }
.route-info { font-size: 12.5px; color: var(--ink2); margin: 9px 0 0; padding: 8px 10px; background: var(--surface2); border-radius: 10px; }
.route-info b { color: var(--ink); }
.switch { display: flex; align-items: center; gap: 10px; margin-top: 12px; font-size: 13px; color: var(--ink2); cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .sw { width: 40px; height: 24px; border-radius: 99px; background: var(--line); position: relative; flex: 0 0 auto; transition: background .15s; }
.switch .sw::after { content: ""; position: absolute; left: 3px; top: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .15s; }
.switch input:checked + .sw { background: var(--est); }
.switch input:checked + .sw::after { transform: translateX(16px); }
.switch input:focus-visible + .sw { outline: 3px solid var(--brand); outline: 3px solid color-mix(in srgb, var(--brand) 55%, transparent); outline-offset: 2px; }
.trip-sum { margin-top: 12px; display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 8px; }
.trip-sum div { background: var(--surface2); border-radius: 10px; padding: 8px 10px; min-width: 0; }
.trip-sum small { display: block; font-size: 10.5px; color: var(--ink3); text-transform: uppercase; font-weight: 700; letter-spacing: .5px; }
.trip-sum b { display: block; font-size: 15px; font-variant-numeric: tabular-nums; }
.trip-sum em { font-style: normal; font-size: 11px; color: var(--ink3); display: block; }
.trip-sum .est b { color: var(--est); }

.rec-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 10px; }
.rec-stats div { background: var(--surface2); border-radius: 10px; padding: 7px 9px; min-width: 0; }
.rec-stats small { display: block; font-size: 10.5px; color: var(--ink3); font-weight: 700; text-transform: uppercase; letter-spacing: .4px; }
.rec-stats b { font-variant-numeric: tabular-nums; font-size: 14px; white-space: nowrap; }

.legend { display: flex; flex-wrap: wrap; gap: 8px 14px; font-size: 11.5px; color: var(--ink2); padding: 2px 4px 6px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.lg { display: inline-block; width: 22px; height: 0; border-top: 3px solid; }
.lg.live { width: 10px; height: 10px; border: 0; border-radius: 50%; background: var(--live); box-shadow: 0 0 0 2px #fff, 0 0 0 3px var(--live); }
.lg.last { width: 10px; height: 10px; border: 0; border-radius: 50%; background: var(--last); box-shadow: 0 0 0 2px #fff, 0 0 0 3px var(--last); }
.lg.est { width: 12px; height: 12px; border: 2px dashed var(--est); border-radius: 50%; }
.lg.route { border-top: 2.5px dashed var(--route); }
.lg.track { border-color: var(--track); }

/* ---------- Lịch sử ---------- */
.history { display: grid; gap: 10px; }
.hcard { border: 1px solid var(--line); border-radius: 13px; padding: 12px; background: var(--surface); box-shadow: var(--shadow-sm); }
.hcard.viewing { border-color: var(--brand); box-shadow: 0 0 0 2px color-mix(in srgb, var(--brand) 25%, transparent); }
.hcard-h { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.hcard-h b { font-size: 14px; word-break: break-word; }
.hcard .meta { font-size: 12px; color: var(--ink3); margin: 3px 0 8px; }
.hstats { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 4px; margin-bottom: 9px; }
.hstats div { font-size: 11px; color: var(--ink3); min-width: 0; }
.hstats b { display: block; color: var(--ink); font-size: 13px; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hactions { display: flex; flex-wrap: wrap; gap: 6px; }
.hactions .btn { min-height: 32px; padding: 5px 9px; font-size: 12px; }
.empty { text-align: center; color: var(--ink3); font-size: 13px; padding: 28px 12px; border: 1.5px dashed var(--line); border-radius: 14px; }

/* ---------- Dữ liệu ---------- */
.filelist { list-style: none; padding: 0; margin: 8px 0 0; display: grid; gap: 3px; font-size: 12px; color: var(--ink2); max-height: 150px; overflow: auto; }
.filelist li { display: flex; justify-content: space-between; gap: 8px; padding: 3px 8px; background: var(--surface2); border-radius: 7px; }
.filelist li.ok::after { content: "✓"; color: var(--live); font-weight: 800; }
.filelist li.miss::after { content: "thiếu"; color: var(--danger); font-weight: 700; }
.meter { height: 8px; border-radius: 99px; background: var(--surface2); overflow: hidden; border: 1px solid var(--line); }
.meter i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--brand), #36c3a5); }

/* ---------- Cài đặt ---------- */
.set-group { margin-bottom: 14px; }
.set-group > h3 { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--ink3); margin: 4px 4px 8px; }
.set-row { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 11px 12px; margin-bottom: 6px; }
.set-row > label, .set-row > .lbl { display: block; font-size: 13px; font-weight: 650; margin-bottom: 7px; }
.set-row .note { font-size: 11.5px; color: var(--ink3); margin-top: 6px; }
.seg { display: flex; flex-wrap: wrap; gap: 4px; background: var(--surface2); padding: 3px; border-radius: 10px; }
.seg button { flex: 1 1 auto; border: 0; background: transparent; border-radius: 8px; padding: 7px 8px; font-size: 12.5px; font-weight: 650; color: var(--ink2); min-width: 46px; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--brand); box-shadow: var(--shadow-sm); }
.set-row .switch { margin-top: 0; }

/* ---------- Trợ giúp ---------- */
.prose h2 { margin: 6px 0 8px; }
.prose h3 { font-size: 14px; margin: 14px 0 4px; }
.prose p, .prose li { font-size: 13px; color: var(--ink2); line-height: 1.6; }
.prose ol, .prose ul { padding-left: 20px; margin: 4px 0 10px; }
.prose .muted { color: var(--ink3); font-size: 12px; }
.pill { display: inline-block; font-size: 10.5px; font-weight: 800; letter-spacing: .5px; padding: 2px 7px; border-radius: 6px; margin-right: 4px; color: #fff; }
.pill.live { background: var(--live); }
.pill.last { background: var(--last); }
.pill.est { background: transparent; color: var(--est); border: 1.5px dashed var(--est); }
.version { text-align: center; font-size: 11.5px; color: var(--ink3); }

/* ---------- Lớp phủ trên bản đồ ---------- */
.map-top { position: absolute; top: 12px; left: 12px; right: 70px; display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-start; pointer-events: none; z-index: 2; }
.state-chip, .view-chip { pointer-events: auto; display: flex; align-items: center; gap: 9px; padding: 7px 12px 7px 10px; border-radius: 13px; background: var(--surface); background: color-mix(in srgb, var(--surface) 94%, transparent); box-shadow: var(--shadow); border: 1px solid var(--line); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); max-width: 100%; }
.state-chip .dot { margin-top: 0; width: 11px; height: 11px; }
.state-chip b { display: block; font-size: 12px; letter-spacing: .7px; }
.state-chip small { display: block; font-size: 11.5px; color: var(--ink2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.state-chip > div { min-width: 0; }
.state-live .dot { background: var(--live); box-shadow: 0 0 0 4px color-mix(in srgb, var(--live) 25%, transparent); animation: pulse 2s infinite; }
.state-live b { color: var(--live); }
.state-last .dot { background: var(--last); }
.state-last b { color: var(--last); }
.state-est .dot { background: transparent; border: 2px dashed var(--est); }
.state-est b { color: var(--est); }
.state-none .dot { background: var(--ink3); }
.state-wait .dot { background: var(--accent); animation: pulse 1.4s infinite; }
.state-wait b { color: var(--est); }
@keyframes pulse { 50% { opacity: .45; } }
@media (prefers-reduced-motion: reduce) { .state-live .dot, .state-wait .dot { animation: none; } }
.view-chip { font-size: 12.5px; font-weight: 650; gap: 6px; padding: 5px 5px 5px 12px; }
.view-chip button { border: 0; background: var(--surface2); border-radius: 8px; width: 28px; height: 28px; display: grid; place-items: center; color: var(--ink2); }
.view-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }

.map-ctrl { position: absolute; right: 12px; top: 12px; display: grid; gap: 7px; z-index: 3; }
.mbtn { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); background: color-mix(in srgb, var(--surface) 95%, transparent); color: var(--ink); box-shadow: var(--shadow-sm); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.mbtn:hover { background: var(--surface2); }
.mbtn svg { width: 21px; height: 21px; }
.mbtn[aria-pressed="true"] { background: var(--brand); color: #fff; border-color: var(--brand); }
.mbtn.heading[aria-pressed="true"] { background: var(--navy); border-color: var(--navy); }
#compassIcon { transition: transform .15s; }
.layers-pop { position: absolute; right: 64px; top: 12px; width: 236px; z-index: 4; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); padding: 10px 12px 12px; }
.pop-title { font-size: 11px; font-weight: 800; letter-spacing: .8px; text-transform: uppercase; color: var(--ink3); margin: 4px 0 8px; }
.style-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 8px; }
.style-opt { border: 1.5px solid var(--line); border-radius: 10px; padding: 0; overflow: hidden; background: var(--surface); text-align: left; font-size: 12px; font-weight: 650; color: var(--ink2); }
.style-opt i { display: block; height: 34px; }
.style-opt span { display: block; padding: 5px 8px; }
.style-opt[aria-pressed="true"] { border-color: var(--brand); color: var(--brand); }
.chk { display: flex; align-items: center; gap: 8px; font-size: 13px; padding: 4px 0; color: var(--ink2); cursor: pointer; }
.chk input { width: 17px; height: 17px; accent-color: var(--brand); }

.progress-mini { position: absolute; left: 50%; transform: translateX(-50%); bottom: 34px; display: flex; align-items: center; gap: 9px; padding: 8px 14px; border-radius: 99px; background: var(--surface); background: color-mix(in srgb, var(--surface) 94%, transparent); border: 1px solid var(--line); box-shadow: var(--shadow); font-size: 12px; z-index: 2; width: min(460px, calc(100% - 140px)); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
.progress-mini b { font-size: 12.5px; letter-spacing: .5px; }
.pm-bar { flex: 1; height: 4px; border-radius: 4px; background: var(--line); position: relative; min-width: 60px; }
.pm-bar i { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 4px; background: var(--route); width: 0; }
.pm-bar svg { position: absolute; top: 50%; width: 18px; height: 18px; color: var(--route); transform: translate(-50%, -50%) rotate(90deg); left: 0; }
.pm-bar.est i { background: repeating-linear-gradient(90deg, var(--est) 0 6px, transparent 6px 9px); }
#pmText { color: var(--ink2); white-space: nowrap; font-variant-numeric: tabular-nums; }
.scalebar { position: absolute; left: 12px; bottom: 12px; font-size: 11px; color: var(--ink2); display: flex; flex-direction: column; gap: 2px; z-index: 2; pointer-events: none; text-shadow: 0 0 3px var(--surface), 0 0 3px var(--surface); }
.scalebar i { display: block; height: 6px; border: 2px solid var(--ink2); border-top: 0; width: 80px; }
.attrib { position: absolute; right: 8px; bottom: 6px; font-size: 10px; color: var(--ink2); background: var(--surface); background: color-mix(in srgb, var(--surface) 70%, transparent); padding: 2px 6px; border-radius: 6px; pointer-events: none; z-index: 2; }
.toast { position: absolute; left: 50%; top: 70px; transform: translate(-50%, -8px); background: var(--navy); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 13px; max-width: min(92%, 520px); box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s; z-index: 20; text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.update-bar { position: absolute; left: 50%; top: 12px; transform: translateX(-50%); z-index: 21; background: var(--navy); color: #fff; border-radius: 12px; padding: 8px 8px 8px 14px; font-size: 13px; box-shadow: var(--shadow); display: flex; align-items: center; gap: 10px; }
.update-bar button { border: 0; background: var(--accent); color: #2b1a00; font-weight: 700; border-radius: 8px; padding: 6px 12px; }

/* ---------- Hộp thoại ---------- */
.dlg { border: 0; padding: 0; border-radius: 18px; width: min(640px, calc(100vw - 24px)); max-height: min(86dvh, 820px); background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.dlg::backdrop { background: rgba(5, 15, 25, .55); backdrop-filter: blur(2px); }
.dlg-h { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); }
.dlg-body { padding: 4px 18px 18px; overflow: auto; max-height: calc(min(86dvh, 820px) - 64px); }

/* ---------- Chế độ bay ---------- */
.fm-top, .fm-hud { display: none; }
body.fm .topbar, body.fm .panel, body.fm .map-top, body.fm .progress-mini, body.fm #fitBtn, body.fm #layersBtn, body.fm .layers-pop { display: none !important; }
body.fm .layout { height: 100vh; height: 100dvh; grid-template-columns: 1fr; }
body.fm .mapwrap { grid-column: 1; }
body.fm .map-ctrl { top: calc(78px + var(--safe-t)); }
body.fm .fm-top { display: flex; position: absolute; left: 0; right: 0; top: 0; z-index: 5; align-items: center; gap: 10px; padding: calc(10px + var(--safe-t)) 12px 10px; background: linear-gradient(180deg, rgba(4,16,28,.97) 0, rgba(4,16,28,.9) 70%, rgba(4,16,28,0)); color: #e9f4f6; }
.fm-exit { width: 42px; height: 42px; border-radius: 12px; border: 1px solid rgba(255,255,255,.18); background: rgba(255,255,255,.08); color: #fff; display: grid; place-items: center; flex: 0 0 auto; }
.fm-route { flex: 1; min-width: 0; }
.fm-route b { display: block; font-size: 18px; letter-spacing: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fm-route small { display: block; font-size: 12px; color: #9fc3d4; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fm-state { display: flex; align-items: center; gap: 7px; padding: 7px 11px; border-radius: 99px; font-size: 11.5px; font-weight: 800; letter-spacing: .6px; background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.16); white-space: nowrap; }
.fm-state .dot { margin: 0; width: 9px; height: 9px; }
.fm-state.state-live { color: #5ef0b0; } .fm-state.state-live .dot { background: #34d399; }
.fm-state.state-last { color: #c3ccd3; } .fm-state.state-last .dot { background: #9aa6b0; }
.fm-state.state-est { color: #ffc368; } .fm-state.state-est .dot { background: transparent; border: 2px dashed #ffc368; }
.fm-state.state-wait { color: #ffc368; } .fm-state.state-wait .dot { background: #ffc368; }
.fm-tool { display: flex; align-items: center; gap: 6px; height: 42px; padding: 0 12px; border-radius: 12px; border: 1px solid rgba(255,255,255,.18); background: rgba(255,255,255,.08); color: #e9f4f6; font-size: 12.5px; font-weight: 650; }
.fm-tool[aria-pressed="true"] { background: #ffb547; color: #2b1a00; border-color: #ffb547; }
body.fm .fm-hud { display: block; position: absolute; left: 0; right: 0; bottom: 0; z-index: 5; padding: 16px 16px calc(12px + var(--safe-b)); background: linear-gradient(0deg, rgba(4,16,28,.98) 75%, rgba(4,16,28,.85) 92%, rgba(4,16,28,0)); color: #e9f4f6; }
.fm-progress { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 14px; max-width: 1100px; margin: 0 auto 12px; }
.fm-end b { display: block; font-size: 24px; letter-spacing: 1.5px; font-weight: 800; }
.fm-end small { display: block; font-size: 12px; color: #9fc3d4; font-variant-numeric: tabular-nums; }
.fm-end.right { text-align: right; }
.fm-track { position: relative; height: 34px; margin-top: 8px; }
.fm-rail { position: absolute; left: 0; right: 0; top: 50%; height: 4px; transform: translateY(-50%); background: rgba(255,255,255,.14); border-radius: 4px; overflow: hidden; }
.fm-rail i { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: linear-gradient(90deg, #ffb547, #ffd38a); border-radius: 4px; }
.fm-track.est .fm-rail i { background: repeating-linear-gradient(90deg, #ffb547 0 8px, transparent 8px 12px); }
.fm-plane { position: absolute; top: 50%; left: 0; width: 26px; height: 26px; color: #fff; transform: translate(-50%, -50%) rotate(90deg); filter: drop-shadow(0 2px 6px rgba(0,0,0,.6)); transition: left .6s; }
.fm-track.est .fm-plane { color: #ffc368; opacity: .9; }
.fm-track small { position: absolute; left: 50%; top: -12px; white-space: nowrap; transform: translateX(-50%); font-size: 11px; color: #9fc3d4; font-variant-numeric: tabular-nums; }
.fm-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; max-width: 1100px; margin: 0 auto; }
.fm-cell { background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.1); border-radius: 13px; padding: 9px 12px; min-width: 0; }
.fm-cell small { display: block; font-size: 10.5px; text-transform: uppercase; letter-spacing: .8px; color: #8fb4c6; font-weight: 700; }
.fm-cell b { display: inline-block; font-size: 25px; font-weight: 750; font-variant-numeric: tabular-nums; white-space: nowrap; line-height: 1.2; }
.fm-cell b.small { font-size: 13.5px; font-weight: 650; line-height: 1.35; white-space: normal; }
.fm-cell b.na { color: #6f93a6; font-weight: 600; }
.fm-cell b.na + em { display: block; margin: 0; font-size: 11px; white-space: nowrap; }
.fm-cell b.est { color: #ffc368; }
.fm-cell b.last { color: #c3ccd3; }
.fm-cell em { font-style: normal; font-size: 12px; color: #8fb4c6; margin-left: 4px; }
.fm-cell em.block { display: block; margin: 2px 0 0; }
.fm-note { max-width: 1100px; margin: 10px auto 0; font-size: 11px; color: #7f9fb0; text-align: center; }
body.fm .scalebar { bottom: auto; top: calc(84px + var(--safe-t)); color: #cfe3ea; text-shadow: none; }
body.fm .scalebar i { border-color: #cfe3ea; }
body.fm .attrib { display: none; }
body.fm .mbtn { background: rgba(8,28,44,.8); border-color: rgba(255,255,255,.14); color: #e9f4f6; }

/* ---------- Di động: bottom sheet ---------- */
@media (max-width: 899px) {
  :root { --top-h: 52px; }
  .topbar { padding-left: 12px; padding-right: 10px; }
  .brand-mark { width: 32px; height: 32px; border-radius: 9px; }
  .brand-text b { font-size: 14.5px; letter-spacing: .6px; }
  .brand-text small { font-size: 10px; max-width: 46vw; }
  .clock { display: none; }
  .chip.net { padding: 5px 8px; }
  .chip.net span { display: none; }
  .fm-btn { padding: 8px 10px; }
  .layout { display: block; position: relative; }
  .mapwrap { position: absolute; inset: 0; }
  .panel {
    position: fixed; left: 0; right: 0; bottom: 0; height: calc(92vh - var(--top-h)); height: calc(92dvh - var(--top-h)); border-right: 0;
    border-radius: 20px 20px 0 0; box-shadow: 0 -8px 30px rgba(5, 20, 35, .22);
    transform: translateY(calc(100% - var(--peek, 196px))); transition: transform .28s cubic-bezier(.2,.8,.2,1);
    will-change: transform; z-index: 15;
  }
  .panel[data-sheet="half"] { transform: translateY(calc(100% - 56vh)); transform: translateY(calc(100% - 56dvh)); }
  .panel[data-sheet="full"] { transform: translateY(0); }
  .panel.dragging { transition: none; }
  .sheet-grip { display: block; padding: 8px 0 4px; touch-action: none; cursor: grab; }
  .sheet-grip span { display: block; width: 42px; height: 5px; border-radius: 9px; background: var(--line); margin: 0 auto; }
  .telemetry { touch-action: none; }
  .tcell { padding: 6px 10px 7px; }
  .tcell b { font-size: 15px; }
  .tabs { padding: 2px 4px 0; }
  .tab { font-size: 10.5px; padding: 6px 0 7px; }
  .panes { padding: 12px 12px 18px; }
  .map-top { top: 10px; left: 10px; right: 64px; }
  .map-ctrl { right: 10px; top: 10px; gap: 6px; }
  .mbtn { width: 42px; height: 42px; }
  .layers-pop { right: 60px; top: 10px; }
  .progress-mini { bottom: calc(var(--peek, 196px) + 26px); width: calc(100% - 24px); padding: 7px 12px; }
  .scalebar { bottom: calc(var(--peek, 196px) + 10px); }
  .progress-mini:not([hidden]) ~ .scalebar { bottom: calc(var(--peek, 196px) + 78px); }
  .attrib { bottom: calc(var(--peek, 196px) + 6px); }
  .toast { top: 62px; }
  body.fm .fm-hud { padding: 12px 10px calc(10px + var(--safe-b)); }
  .fm-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 5px; }
  .fm-cell { padding: 6px 8px; border-radius: 10px; }
  .fm-cell small { font-size: 9px; letter-spacing: .3px; }
  .fm-cell b { font-size: 17px; }
  .fm-cell em { font-size: 10.5px; margin-left: 2px; }
  .fm-cell b.small { font-size: 11px; }
  .fm-end b { font-size: 18px; }
  .fm-end small { font-size: 11px; }
  .fm-route b { font-size: 15px; }
  .fm-tool span { display: none; }
  .fm-state { padding: 6px 9px; font-size: 10.5px; }
}
@media (max-width: 430px) { .brand-text small { display: none; } .chip.net { display: none; } .brand-text b { font-size: 14px; letter-spacing: .3px; } .brand { gap: 9px; } }
@media (max-width: 380px) {
  .brand-text b { font-size: 13.5px; letter-spacing: .3px; }
  .fm-btn span { display: none; }
  .fm-btn { padding: 8px 11px; }
  .chip.net { display: none; }
  .fm-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .fm-grid .fm-cell:last-child { grid-column: span 2; }
  .fm-cell b { font-size: 17px; }
  .rec-stats b { font-size: 13px; }
  .hstats { grid-template-columns: repeat(2, minmax(0,1fr)); }
}
@media (max-width: 899px) and (orientation: landscape) and (max-height: 500px) {
  .fm-grid { grid-template-columns: repeat(8, minmax(0, 1fr)); }
  .fm-progress { margin-bottom: 6px; }
  .fm-cell b { font-size: 15px; }
  .panel { height: calc(100dvh - var(--top-h)); }
}
@media (min-width: 900px) and (max-width: 1180px) { :root { --panel-w: 350px; } }
@media print { .map-ctrl, .panel, .topbar { display: none; } }
