:root {
  --bg: #0b1a2e;
  --bg2: #10243d;
  --card: #15304f;
  --card2: #1b3a5e;
  --line: #24476f;
  --text: #e8f0fa;
  --muted: #8fa9c6;
  --accent: #38b6ff;
  --accent2: #ffb547;
  --pos: #4ade80;
  --neg: #f87171;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; overscroll-behavior: none; }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0 0 6px; }
h2 { font-size: 20px; }
h3 { font-size: 15px; color: var(--muted); margin: 18px 0 8px; text-transform: uppercase; letter-spacing: .04em; }
p { margin: 8px 0; }

.app { display: flex; flex-direction: column; height: 100dvh; max-width: 560px; margin: 0 auto; }

/* Topo */
.topbar { padding: calc(10px + var(--safe-t)) 14px 8px; background: linear-gradient(180deg, #0e2340, var(--bg)); border-bottom: 1px solid var(--line); }
.top-row { display: flex; align-items: center; gap: 10px; }
.top-row.small { font-size: 12px; color: var(--muted); margin-top: 4px; }
.company { font-weight: 700; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cash { font-weight: 800; font-size: 20px; color: var(--pos); font-variant-numeric: tabular-nums; }
.cash.neg { color: var(--neg); }
.day-bar { flex: 1; height: 4px; background: var(--line); border-radius: 2px; overflow: hidden; }
.day-bar span { display: block; height: 100%; background: var(--accent); transition: width .25s linear; }

/* Conteúdo */
.content { flex: 1; overflow-y: auto; padding: 12px 12px 20px; -webkit-overflow-scrolling: touch; }
.content.tab-map { padding: 0; overflow: hidden; position: relative; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 4px 0 10px; }
.section-head h3 { margin: 0; }
.empty { color: var(--muted); text-align: center; padding: 30px 10px; }
.empty.small { padding: 10px; }
.muted { color: var(--muted); font-weight: 400; font-size: 13px; }
.note { color: var(--muted); font-size: 13px; }
.warn { color: var(--accent2); }
.pos { color: var(--pos); }
.neg { color: var(--neg); }

/* Cartões */
.card { display: block; width: 100%; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px; margin-bottom: 10px; color: inherit; font: inherit; text-align: left; }
button.card { cursor: pointer; }
button.card:active { background: var(--card2); }
.card.row, .row { display: flex; align-items: center; gap: 10px; }
.card.disabled, .card:disabled { opacity: .45; }
.card.hl { border-color: var(--accent); }
.grow { flex: 1; min-width: 0; }
.title { font-weight: 700; }
.sub { color: var(--muted); font-size: 13px; }
.right { text-align: right; font-weight: 700; white-space: nowrap; }
.right small { display: block; font-weight: 400; color: var(--muted); font-size: 11px; }
.bar { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; margin: 6px 0 3px; }
.bar span { display: block; height: 100%; background: var(--accent); }
.bar.wear span { background: linear-gradient(90deg, var(--pos), var(--accent2) 60%, var(--neg)); background-size: 100vw 100%; }
.tag { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; background: var(--line); }
.tag.ok { background: #14532d; color: #bbf7d0; }
.tag.wait { background: #713f12; color: #fde68a; }
.tag.maint { background: #1e3a8a; color: #bfdbfe; }
.tag.bad { background: #7f1d1d; color: #fecaca; }
.tag.idle { background: #3f3f46; color: #e4e4e7; }
.kv { display: flex; justify-content: space-between; padding: 4px 0; }
.kv.sub-kv { font-size: 13px; color: var(--muted); padding-left: 10px; }
.kv.total { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 8px; }
.specs { display: flex; flex-wrap: wrap; gap: 6px 12px; font-size: 13px; color: var(--muted); margin: 8px 0 10px; }

/* Gráfico */
.chart { display: flex; align-items: flex-end; gap: 4px; height: 160px; }
.chart .col { flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; }
.chart .col span { width: 100%; border-radius: 4px 4px 0 0; }
.chart .col span.pos { background: var(--pos); }
.chart .col span.neg { background: var(--neg); }
.chart .col small { font-size: 10px; color: var(--muted); margin-top: 3px; }

/* Botões e campos */
.btn { border: 1px solid var(--line); background: var(--card2); color: var(--text); padding: 10px 14px; border-radius: 12px; font: inherit; font-weight: 600; cursor: pointer; }
.btn:active { filter: brightness(1.2); }
.btn:disabled { opacity: .4; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #04223a; }
.btn.danger { background: transparent; border-color: var(--neg); color: var(--neg); }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn.block { width: 100%; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.actions .btn { flex: 1; }
.field { display: block; margin: 12px 0; font-size: 14px; }
.field input:not([type=range]), .field select { display: block; width: 100%; margin-top: 6px; padding: 11px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg2); color: var(--text); font: inherit; }
.field input[type=range] { width: 100%; margin-top: 10px; accent-color: var(--accent); }
.danger-zone { margin-top: 30px; text-align: center; }

/* Barra de abas */
.tabbar { display: flex; border-top: 1px solid var(--line); background: var(--bg2); padding-bottom: var(--safe-b); }
.tabbar button { flex: 1; background: none; border: 0; color: var(--muted); font: inherit; font-size: 11px; padding: 8px 0 6px; display: flex; flex-direction: column; align-items: center; gap: 2px; cursor: pointer; }
.tabbar button span { font-size: 20px; filter: grayscale(1) opacity(.7); }
.tabbar button.on { color: var(--accent); }
.tabbar button.on span { filter: none; }

/* Mapa */
.map-wrap { position: absolute; inset: 0; background: radial-gradient(ellipse at center, #123257, #08162a); }
.map { width: 100%; height: 100%; display: block; touch-action: none; user-select: none; cursor: grab; }
.map .grid { stroke: #1d3d63; stroke-width: calc(.15px * var(--z, 1)); }
.map .equator { stroke: #2a5584; stroke-width: calc(.25px * var(--z, 1)); stroke-dasharray: 1 1; }
.map .route { fill: none; stroke: var(--muted); stroke-width: calc(.35px * var(--z, 1)); stroke-dasharray: 1 .8; opacity: .7; }
.map .route.active { stroke: var(--accent); stroke-dasharray: none; opacity: 1; }
.map .ap .dot { fill: #6b8bb0; r: calc(var(--r) * 1px * var(--z)); }
.map .ap.served .dot { fill: var(--accent); }
.map .ap.hub .dot { fill: var(--accent2); stroke: #fff; stroke-width: calc(.25px * var(--z)); }
.map .ap .hit { fill: transparent; r: calc(4px * var(--z)); }
.map .ap text.hidden { display: none; }
.map .ap text { fill: var(--text); font-size: calc(2.6px * var(--z)); font-weight: 700; paint-order: stroke; stroke: #08162a; stroke-width: calc(.6px * var(--z)); pointer-events: none; transform: translate(calc(2.2px * var(--z)), calc(.9px * var(--z))); transform-box: view-box; }
.map-hint { position: absolute; left: 0; right: 0; bottom: 8px; text-align: center; font-size: 12px; color: var(--muted); pointer-events: none; }

/* Folha inferior */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.5); opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 10; }
.sheet-backdrop.open { opacity: 1; pointer-events: auto; }
.sheet { position: fixed; left: 50%; bottom: 0; width: 100%; max-width: 560px; max-height: 88dvh; overflow-y: auto; transform: translate(-50%, 105%); transition: transform .25s ease; background: var(--bg2); border-radius: 20px 20px 0 0; border-top: 1px solid var(--line); padding: 8px 16px calc(16px + var(--safe-b)); z-index: 11; }
.sheet.open { transform: translate(-50%, 0); }
.grip { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 4px auto 12px; }
.list { margin-top: 10px; }

/* Aviso */
.toast { position: fixed; left: 50%; top: calc(80px + var(--safe-t)); transform: translate(-50%, -20px); background: #0f5132; color: #d1fae5; padding: 10px 16px; border-radius: 12px; opacity: 0; transition: all .2s; z-index: 20; pointer-events: none; max-width: 90vw; text-align: center; font-size: 14px; }
.toast.err { background: #7f1d1d; color: #fee2e2; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Início */
.start { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 20px; background: radial-gradient(ellipse at top, #1a4475, var(--bg)); }
.start-card { width: 100%; max-width: 420px; }
.start h1 { font-size: 34px; text-align: center; }
.start .sub { text-align: center; font-size: 15px; }
.logo { font-size: 56px; text-align: center; color: var(--accent2); }

/* Avisos, botões em linha e seletor segmentado */
.alert { display: block; width: 100%; text-align: left; font: inherit; font-size: 13px; color: #fde68a; background: #422006; border: 1px solid #a16207; border-radius: 12px; padding: 10px 12px; margin-bottom: 12px; cursor: pointer; }
.alert.floating { position: absolute; top: 10px; left: 10px; right: 10px; width: auto; z-index: 2; }
.row.btns { gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.row.btns .btn { flex: 1; }
.btn small { display: block; font-weight: 400; font-size: 11px; opacity: .8; }
.seg { display: flex; gap: 4px; background: var(--bg2); border: 1px solid var(--line); border-radius: 12px; padding: 4px; margin: 8px 0; }
.seg button { flex: 1; border: 0; background: none; color: var(--muted); font: inherit; font-size: 13px; font-weight: 600; padding: 9px 6px; border-radius: 9px; cursor: pointer; }
.seg button.on { background: var(--accent); color: #04223a; }
.kv b { text-align: right; }
.tabbar button { font-size: 10px; }
.miles { color: #c4b5fd; font-weight: 700; }
.btn.rush { flex: none; text-align: center; border-color: #8b5cf6; background: #2e1065; color: #ede9fe; }
.alert.info { color: #bfdbfe; background: #172554; border-color: #1d4ed8; }
.staff-nums { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; margin: 10px 0 6px; text-align: center; }
.staff-nums b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; }
.staff-nums small { color: var(--muted); font-size: 11px; }
#h-miles { cursor: pointer; padding: 2px 6px; margin: -2px -6px; border-radius: 8px; }
#h-miles:active { background: var(--card2); }
.streak { display: flex; gap: 6px; margin: 10px 0 4px; }
.streak span { flex: 1; height: 8px; border-radius: 4px; background: var(--line); }
.streak span.on { background: #8b5cf6; }
.map .plane use { fill: #fff; stroke: #0b1a2e; stroke-width: .18; filter: drop-shadow(0 0 .6px rgba(56,182,255,.9)); }
.map .plane .hit { fill: transparent; }
.map .plane { cursor: pointer; }

/* Planejador */
.timeline { margin: 12px 0 8px; }
.tl-track { position: relative; height: 30px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.tl-leg { position: absolute; top: 4px; bottom: 4px; border-radius: 5px; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.tl-leg.back { opacity: .65; }
.tl-leg span { font-size: 10px; font-weight: 800; color: #04223a; }
.tl-ticks { position: relative; height: 16px; font-size: 10px; color: var(--muted); }
.tl-ticks span { position: absolute; transform: translateX(-50%); top: 2px; }
.tl-ticks span:first-child { transform: none; }
.tl-ticks span:last-child { transform: translateX(-100%); }
.trip { display: flex; align-items: center; gap: 10px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px; margin-bottom: 8px; }
.trip .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.add-trip { gap: 6px; flex-wrap: wrap; }
.add-trip select { flex: 1 1 100%; padding: 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg2); color: var(--text); font: inherit; font-size: 16px; }
.add-trip .btn { flex: 1; }
.section-head .row { gap: 6px; }
/* Malha do dia */
table.sched { width: 100%; border-collapse: collapse; font-size: 13px; }
.sched th { text-align: left; color: var(--muted); font-weight: 600; font-size: 11px; padding: 6px 4px; border-bottom: 1px solid var(--line); }
.sched td { padding: 7px 4px; border-bottom: 1px solid var(--line); vertical-align: top; }
.sched .num { text-align: right; white-space: nowrap; }
.sched small { color: var(--muted); }
.sched tr.done td { opacity: .75; }
.sched tr.air td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
/* Resultado do pouso no mapa */
.map .pop { font-size: calc(2.6px * var(--z)); font-weight: 800; paint-order: stroke; stroke: #08162a; stroke-width: calc(.6px * var(--z)); text-anchor: middle; pointer-events: none; animation: pop-rise 2.6s ease-out forwards; }
.map .pop.pos { fill: var(--pos); }
.map .pop.neg { fill: var(--neg); }
@keyframes pop-rise { 0% { opacity: 0; transform: translateY(0); } 12% { opacity: 1; } 100% { opacity: 0; transform: translateY(calc(-6px * var(--z))); } }
@media (prefers-reduced-motion: reduce) { .map .pop { animation-duration: 0s; } }
.card.cta { border-color: var(--accent2); background: linear-gradient(135deg, #3b2a0a, var(--card)); cursor: pointer; }
.card.cta .title { color: var(--accent2); font-size: 17px; }
.card.cta.floating { position: absolute; top: 10px; left: 10px; right: 10px; width: auto; z-index: 2; }
.cabin-bar { display: flex; height: 14px; border-radius: 7px; overflow: hidden; margin: 4px 0 12px; border: 1px solid var(--line); }
.cabin-bar .j { background: var(--accent2); }
.cabin-bar .y { background: var(--accent); }
