:root {
  --bg: #0b1629;
  --bg2: #101f38;
  --card: #15284a;
  --card2: #1b3259;
  --line: #24406e;
  --text: #eef3fb;
  --muted: #98a9c6;
  --gold: #d4af37;
  --gold2: #f5d778;
  --ok: #34c77b;
  --warn: #f2b33d;
  --bad: #ef5a5a;
  --blue: #4da3ff;
  --vfr: #34c77b; --mvfr: #4da3ff; --ifr: #ef5a5a; --lifr: #c86bff;
  --radius: 16px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --tab-h: 62px;
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%; overscroll-behavior-y: none; }
a { color: var(--blue); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
h2 { font-size: 1.15rem; margin: 22px 0 10px; color: var(--gold2); letter-spacing: .2px; }
h3 { font-size: 1rem; margin: 0 0 6px; }
small, .muted { color: var(--muted); }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: .86rem; }

#app { display: flex; flex-direction: column; height: 100%; }
#topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 8px;
  padding: calc(var(--safe-t) + 10px) 16px 10px; background: linear-gradient(180deg, #0b1629 70%, rgba(11,22,41,.85));
  border-bottom: 1px solid rgba(36,64,110,.6); backdrop-filter: blur(10px); }
#title { flex: 1; margin: 0; font-size: 1.1rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { background: none; border: 0; color: var(--gold2); font-size: 2rem; line-height: 1; padding: 0 6px 4px 0; cursor: pointer; }
.net { width: 9px; height: 9px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.net.off { background: var(--bad); box-shadow: 0 0 8px var(--bad); }
#view { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 14px 16px calc(var(--tab-h) + var(--safe-b) + 24px); outline: none; }

#tabbar { position: fixed; bottom: 0; left: 0; right: 0; z-index: 6; display: flex; height: calc(var(--tab-h) + var(--safe-b));
  padding-bottom: var(--safe-b); background: rgba(13,26,48,.94); border-top: 1px solid var(--line); backdrop-filter: blur(14px); }
#tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); font-size: .68rem; font-weight: 600; }
#tabbar a svg { width: 25px; height: 25px; }
#tabbar a.active { color: var(--gold2); }
#tabbar a.tab-ai .ti { background: linear-gradient(135deg, var(--gold), #a8841c); color: #0b1629; border-radius: 14px; padding: 4px 10px; }
#tabbar a.tab-ai.active .ti { box-shadow: 0 0 14px rgba(212,175,55,.6); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.card.tap { cursor: pointer; transition: transform .08s; }
.card.tap:active { transform: scale(.985); }
.hero { background: radial-gradient(120% 140% at 0% 0%, #23457d 0%, #13274a 55%, #0f1f3b 100%); border: 1px solid #2c4f86; }
.hero .greet { font-size: 1.35rem; font-weight: 700; }
.hero .sub { color: var(--gold2); font-weight: 600; font-size: .85rem; letter-spacing: 1px; text-transform: uppercase; }
.grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.grid.g3 { grid-template-columns: repeat(3, 1fr); }
.grid.g2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 360px) { .grid { grid-template-columns: repeat(3, 1fr); } }
.tile { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 12px 4px; background: var(--card);
  border: 1px solid var(--line); border-radius: 14px; color: var(--text); font-size: .74rem; text-align: center; font-weight: 600; }
.tile svg { width: 28px; height: 28px; color: var(--gold2); }
.tile:active { background: var(--card2); }
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.kpi { background: var(--bg2); border: 1px solid var(--line); border-radius: 12px; padding: 10px; }
.kpi b { display: block; font-size: 1.25rem; font-variant-numeric: tabular-nums; }
.kpi span { font-size: .72rem; color: var(--muted); }

.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 12px 0; border-bottom: 1px solid rgba(36,64,110,.6); }
.list li:last-child { border-bottom: 0; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--card2);
  color: var(--text); border-radius: 12px; padding: 10px 14px; font-weight: 600; cursor: pointer; min-height: 44px; }
.btn.primary { background: linear-gradient(135deg, var(--gold), #b38f22); color: #0b1629; border: 0; }
.btn.danger { background: rgba(239,90,90,.15); border-color: rgba(239,90,90,.5); color: #ff9c9c; }
.btn.ghost { background: transparent; }
.btn.sm { min-height: 34px; padding: 6px 10px; font-size: .85rem; border-radius: 10px; }
.btn:disabled { opacity: .5; }
.btn.block { width: 100%; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 1px solid var(--line); background: var(--bg2); color: var(--muted); border-radius: 999px; padding: 6px 12px; font-size: .82rem; font-weight: 600; cursor: pointer; }
.chip.on { background: var(--gold); color: #0b1629; border-color: var(--gold); }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .72rem; font-weight: 700; background: var(--card2); color: var(--muted); }
.badge.VFR { background: var(--vfr); color: #062; } .badge.MVFR { background: var(--mvfr); color: #012; }
.badge.IFR { background: var(--ifr); color: #fff; } .badge.LIFR { background: var(--lifr); color: #fff; }
.badge.ok { background: rgba(52,199,123,.2); color: var(--ok); } .badge.bad { background: rgba(239,90,90,.2); color: var(--bad); }
.badge.warn { background: rgba(242,179,61,.2); color: var(--warn); }

label.f { display: block; margin-bottom: 10px; }
label.f > span { display: block; font-size: .78rem; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
input[type=text], input[type=number], input[type=date], input[type=time], input[type=password], input[type=search], select, textarea {
  width: 100%; background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; font-size: 16px; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--gold); }
textarea { resize: vertical; min-height: 90px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.form-grid .full { grid-column: 1 / -1; }
.switch { display: flex; align-items: center; justify-content: space-between; padding: 8px 0; }
.switch input { width: 46px; height: 28px; appearance: none; background: var(--line); border-radius: 999px; position: relative; transition: .2s; flex: none; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: .2s; }
.switch input:checked { background: var(--ok); }
.switch input:checked::after { left: 21px; }
fieldset { border: 1px solid var(--line); border-radius: 12px; margin: 0 0 12px; padding: 10px 12px 2px; }
legend { color: var(--gold2); font-size: .8rem; font-weight: 700; padding: 0 6px; }

#toast { position: fixed; left: 50%; bottom: calc(var(--tab-h) + var(--safe-b) + 16px); transform: translateX(-50%) translateY(20px); opacity: 0;
  background: #f4f6fb; color: #0b1629; padding: 10px 16px; border-radius: 12px; font-weight: 600; font-size: .9rem; z-index: 20; transition: .25s; pointer-events: none; max-width: 90vw; text-align: center; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#modal { position: fixed; inset: 0; z-index: 15; background: rgba(0,0,0,.55); display: flex; align-items: flex-end; }
#modal[hidden] { display: none; }
#modal .sheet { width: 100%; max-height: 92vh; overflow-y: auto; background: var(--bg); border-top: 1px solid var(--line);
  border-radius: 20px 20px 0 0; padding: 16px 16px calc(var(--safe-b) + 20px); animation: up .22s ease-out; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.sheet-head h3 { margin: 0; font-size: 1.1rem; }

/* chat */
.chat-wrap { display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 92%; padding: 10px 13px; border-radius: 16px; word-wrap: break-word; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: linear-gradient(135deg, #2a5aa0, #22497f); border-bottom-right-radius: 4px; white-space: pre-wrap; }
.msg.ai { align-self: flex-start; background: var(--card); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg.ai p { margin: .4em 0; } .msg.ai ul, .msg.ai ol { padding-left: 1.3em; margin: .4em 0; }
.msg.ai pre { background: var(--bg); padding: 8px; border-radius: 8px; overflow-x: auto; }
.msg.ai code { background: var(--bg); padding: 1px 4px; border-radius: 4px; font-size: .88em; }
.msg.ai table { border-collapse: collapse; width: 100%; font-size: .85rem; display: block; overflow-x: auto; }
.msg.ai th, .msg.ai td { border: 1px solid var(--line); padding: 4px 6px; text-align: left; }
.msg .cite { font-size: .7rem; vertical-align: super; color: var(--gold2); margin-left: 1px; }
.sources { margin-top: 8px; border-top: 1px dashed var(--line); padding-top: 6px; font-size: .78rem; }
.sources a { display: block; color: var(--blue); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status-line { font-size: .78rem; color: var(--gold2); display: flex; align-items: center; gap: 6px; }
.dots::after { content: "…"; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .2; } }
.composer { position: fixed; left: 0; right: 0; bottom: calc(var(--tab-h) + var(--safe-b)); z-index: 4; padding: 8px 12px; background: rgba(11,22,41,.96);
  border-top: 1px solid var(--line); display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { min-height: 44px; max-height: 140px; border-radius: 22px; padding: 11px 16px; }
.composer .btn { border-radius: 50%; width: 44px; padding: 0; flex: none; }
.chat-pad { height: 70px; }

.news-item { display: flex; gap: 12px; }
.news-item img { width: 86px; height: 64px; object-fit: cover; border-radius: 10px; flex: none; background: var(--bg2); }
.news-item .t { font-weight: 600; font-size: .95rem; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.raw { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px; white-space: pre-wrap; word-break: break-word; }
.chart-box { position: relative; height: 240px; }
.progress { height: 8px; background: var(--bg2); border-radius: 99px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--gold); width: 0; transition: width .2s; }
.check-item { display: flex; gap: 12px; align-items: flex-start; padding: 12px 4px; border-bottom: 1px solid rgba(36,64,110,.6); cursor: pointer; }
.check-item .box { width: 26px; height: 26px; border: 2px solid var(--gold); border-radius: 8px; flex: none; display: grid; place-items: center; color: #0b1629; font-weight: 900; }
.check-item.done .box { background: var(--ok); border-color: var(--ok); }
.check-item.done .txt { color: var(--muted); text-decoration: line-through; }
.check-item .act { margin-left: auto; color: var(--gold2); font-weight: 700; text-align: right; }
.quiz-opt { display: block; width: 100%; text-align: left; margin: 6px 0; }
.quiz-opt.correct { background: rgba(52,199,123,.2); border-color: var(--ok); }
.quiz-opt.wrong { background: rgba(239,90,90,.2); border-color: var(--bad); }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }
.notice { border-left: 3px solid var(--warn); background: rgba(242,179,61,.08); padding: 10px 12px; border-radius: 8px; font-size: .85rem; margin-bottom: 12px; }
.notice.info { border-color: var(--blue); background: rgba(77,163,255,.08); }
.spinner { width: 18px; height: 18px; border: 2px solid var(--line); border-top-color: var(--gold); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
#map { height: 200px; border-radius: 12px; margin-top: 10px; }
.seg { display: flex; background: var(--bg2); border: 1px solid var(--line); border-radius: 12px; padding: 3px; margin-bottom: 12px; }
.seg button { flex: 1; background: none; border: 0; padding: 8px 4px; border-radius: 9px; font-weight: 600; font-size: .85rem; color: var(--muted); cursor: pointer; }
.seg button.on { background: var(--card2); color: var(--gold2); }
.log-row .route { font-weight: 700; font-variant-numeric: tabular-nums; }
.log-row .meta { font-size: .8rem; color: var(--muted); }
.log-row .hrs { font-weight: 700; color: var(--gold2); font-variant-numeric: tabular-nums; }
.btn svg { width: 20px; height: 20px; flex: none; }
.btn.sm svg { width: 16px; height: 16px; }
