* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; background: var(--bg); color: var(--text); font: 400 var(--t-md)/1.45 var(--font); -webkit-font-smoothing: antialiased; }
body { overflow: hidden; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.mono, .num { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* Scrolling regions never show native scrollbars */
.scroll { overflow-y: auto; overscroll-behavior: contain; scrollbar-width: none; }
.scroll::-webkit-scrollbar { display: none; }

/* ---------- Shell ---------- */
/* Frame (from Vector 1): labelled sidebar that collapses to an icon rail, plus an EFB status bar on top */
#app {
  --rail-w: 216px;
  position: fixed; inset: 0; display: grid; grid-template-columns: var(--rail-w) 1fr; grid-template-rows: auto 1fr;
  padding-top: env(safe-area-inset-top); transition: grid-template-columns 260ms var(--ease);
}
#app.rail-collapsed { --rail-w: var(--rail); }
#rail {
  grid-row: 1 / 3; display: flex; flex-direction: column; gap: 2px; padding: var(--s4) var(--s3); min-width: 0; overflow: hidden;
  background: linear-gradient(180deg, var(--surface) 0%, #0a0e14 100%); border-right: 1px solid var(--line); z-index: 20;
}
#rail .brand { display: flex; align-items: center; gap: 10px; padding: 0 6px; margin-bottom: var(--s5); white-space: nowrap; }
#rail .logo { width: 36px; height: 36px; flex-shrink: 0; }
#rail .logo svg { width: 36px; height: 36px; display: block; }
#rail .brand-name { font-weight: 750; font-size: 16px; letter-spacing: -.01em; line-height: 1.1; }
#rail .brand-name small { display: block; font: 600 9px/1.4 var(--font); letter-spacing: .14em; color: var(--text-3); }
#rail .rail-label { padding: 0 10px; margin: var(--s2) 0 var(--s1); font: 650 10px var(--font); letter-spacing: .12em; text-transform: uppercase; color: var(--text-3); white-space: nowrap; }
#rail .tab {
  position: relative; display: flex; align-items: center; gap: 12px; height: 40px; padding: 0 10px; border-radius: 10px; white-space: nowrap;
  color: var(--text-2); font-size: 14px; font-weight: 550; text-align: left;
  transition: color var(--dur) var(--ease), background-color var(--dur) var(--ease), transform 160ms var(--ease);
}
#rail .tab svg { flex-shrink: 0; width: 20px; height: 20px; }
#rail .tab:hover { color: var(--text); background: rgba(255,255,255,.03); }
#rail .tab:active { transform: scale(.97); }
#rail .tab[aria-current="page"] { color: var(--text); background: var(--surface-3); box-shadow: inset 0 0 0 1px var(--line); }
#rail .tab[aria-current="page"] svg { color: var(--accent); }
#rail .tab[aria-current="page"]::before { content: ""; position: absolute; left: -12px; top: 10px; bottom: 10px; width: 3px; border-radius: 0 3px 3px 0; background: var(--accent); }
#rail .tab .live-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); margin-left: auto; box-shadow: 0 0 0 4px rgba(63,216,180,.15); }
#rail .spacer { flex: 1; }
#rail .collapse { color: var(--text-3); font-size: 13px; }
#rail .collapse svg { transition: transform 260ms var(--ease); transform: rotate(180deg); }
#rail .me { display: flex; align-items: center; gap: 10px; padding: 6px; margin-top: var(--s2); border-radius: 12px; white-space: nowrap; text-align: left; }
#rail .me:hover { background: rgba(255,255,255,.03); }
#rail .avatar { width: 36px; height: 36px; flex-shrink: 0; border-radius: 50%; display: grid; place-items: center; background: linear-gradient(135deg, #22324c, #141c29); box-shadow: inset 0 0 0 1px var(--line-2); color: var(--text); font: 700 13px var(--font); }
#rail .me b { display: block; font-size: 13px; } #rail .me span { font-size: 11px; color: var(--text-3); }
#app.rail-collapsed #rail { padding-left: 10px; padding-right: 10px; align-items: center; }
#app.rail-collapsed #rail :is(.brand-name, .rail-label, .tab-label, .me-text, .collapse-label, .live-dot) { display: none; }
#app.rail-collapsed #rail .brand { padding: 0; }
#app.rail-collapsed #rail .tab { width: 52px; justify-content: center; padding: 0; }
#app.rail-collapsed #rail .tab[aria-current="page"]::before { left: -10px; }
#app.rail-collapsed #rail .collapse svg { transform: none; }
#app.rail-collapsed #rail .me { padding: 0; }

/* EFB status bar: UTC, local time, internet, battery, simulator */
#statusbar {
  grid-column: 2; display: flex; align-items: center; gap: var(--s4); height: 34px; padding: 0 var(--s5);
  border-bottom: 1px solid var(--line); background: rgba(7,9,13,.82); backdrop-filter: blur(12px); z-index: 15;
  font: 600 10.5px var(--mono); letter-spacing: .06em; color: var(--text-3); white-space: nowrap;
}
#statusbar .utc { color: var(--text); font-size: 13px; letter-spacing: .02em; }
#statusbar .grow { flex: 1; }
#statusbar .sb { display: inline-flex; align-items: center; gap: 6px; }
#statusbar .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--text-3); }
#statusbar .ok .dot { background: var(--ok); } #statusbar .warn .dot { background: var(--warn); } #statusbar .bad .dot { background: var(--danger); }
#statusbar .ok { color: #9ee9d6; } #statusbar .warn { color: #ffd59a; } #statusbar .bad { color: #ff9aa2; }
#statusbar .batt { display: inline-flex; align-items: center; gap: 6px; }
#statusbar .batt i { position: relative; width: 22px; height: 11px; border-radius: 3px; border: 1px solid currentColor; opacity: .9; }
#statusbar .batt i::after { content: ""; position: absolute; right: -3px; top: 3px; width: 2px; height: 4px; border-radius: 0 1px 1px 0; background: currentColor; }
#statusbar .batt i b { position: absolute; left: 1px; top: 1px; bottom: 1px; border-radius: 1.5px; background: var(--ok); }
#statusbar .phase { color: var(--accent); }
#statusbar button.sb { font: inherit; letter-spacing: inherit; padding: 3px 8px; margin: 0 -8px; border-radius: 6px; }
#statusbar button.sb:hover { background: rgba(255,255,255,.04); }
#view { grid-column: 2; position: relative; overflow: hidden auto; scrollbar-width: none; }
#view::-webkit-scrollbar { display: none; }
#view.enter > * { animation: enter 280ms var(--ease) both; }
@keyframes enter { from { opacity: 0; transform: translateY(8px); } }

/* Phones: bottom tab bar */
@media (max-width: 599px) {
  #app, #app.rail-collapsed { grid-template-columns: 1fr; grid-template-rows: auto 1fr auto; }
  #statusbar, #view { grid-column: 1; }
  #statusbar { height: 28px; padding: 0 var(--s4); gap: var(--s3); }
  #statusbar .local, #statusbar .batt-wrap { display: none; }
  #rail { grid-row: 3; flex-direction: row; justify-content: space-around; align-items: center; padding: var(--s1) var(--s2) calc(var(--s1) + env(safe-area-inset-bottom)); border-right: 0; border-top: 1px solid var(--line); }
  #rail :is(.brand, .rail-label, .spacer, .collapse, .me-text, .live-dot) { display: none; }
  #rail .tab, #app.rail-collapsed #rail .tab { width: auto; flex: 1; height: auto; flex-direction: column; gap: 3px; padding: 6px 0; font-size: 10.5px; justify-content: center; }
  #rail .tab .tab-label { display: block !important; }
  #rail .tab[aria-current="page"]::before { display: none; }
  #rail .me { margin: 0; padding: 0; }
  #rail .avatar { width: 32px; height: 32px; }
}

/* ---------- Page ---------- */
.page { max-width: 1100px; margin: 0 auto; padding: var(--s5) var(--s5) var(--s6); }
@media (max-width: 599px) { .page { padding: var(--s4); } }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--s4); margin-bottom: var(--s5); }
.page-head h1 { font-size: var(--t-xl); font-weight: 750; letter-spacing: -.02em; }
.eyebrow { font-size: var(--t-xs); font-weight: 650; letter-spacing: .08em; text-transform: uppercase; color: var(--text-3); }
.muted { color: var(--text-2); }
.faint { color: var(--text-3); }
.stack { display: flex; flex-direction: column; gap: var(--s4); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s4); }
@media (max-width: 820px) { .grid-2 { grid-template-columns: 1fr; } }

/* ---------- Card ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: var(--s5); box-shadow: var(--shadow); }
.card.tight { padding: var(--s4); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); margin-bottom: var(--s3); }
.card-head h2 { font-size: var(--t-md); font-weight: 650; }

/* ---------- Buttons ---------- */
.btn {
  height: 44px; padding: 0 var(--s4); border-radius: var(--r-sm); display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  background: var(--surface-3); color: var(--text); font-weight: 600; font-size: var(--t-sm); border: 1px solid var(--line);
  transition: transform 160ms var(--ease), background-color var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.btn:active { transform: scale(.97); }
.btn.ink { background: var(--ink); color: var(--ink-text); border-color: transparent; box-shadow: 0 1px 0 rgba(255,255,255,.6) inset; }
.btn.ghost { background: transparent; }
.btn.sm { height: 34px; padding: 0 var(--s3); font-size: 12.5px; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .45; pointer-events: none; }
.icon-btn { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; color: var(--text-2); transition: background-color var(--dur) var(--ease), transform 160ms var(--ease); }
.icon-btn:active { transform: scale(.94); }
.link { color: var(--accent); font-weight: 600; font-size: var(--t-sm); }

/* ---------- Segmented ---------- */
.seg { display: inline-grid; grid-auto-flow: column; grid-auto-columns: 1fr; padding: 3px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--line); }
.seg button { height: 34px; padding: 0 var(--s3); border-radius: 9px; color: var(--text-2); font-size: 12.5px; font-weight: 600; white-space: nowrap; transition: color var(--dur) var(--ease), background-color var(--dur) var(--ease); }
.seg button[aria-pressed="true"] { background: var(--surface-3); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.4); }

/* ---------- Chip, stat, row ---------- */
.chip { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px; border-radius: 999px; font-size: 11.5px; font-weight: 650; background: var(--surface-3); color: var(--text-2); }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.accent { background: var(--accent-soft); color: var(--accent); }
.chip .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.stat .label { font-size: var(--t-xs); font-weight: 650; letter-spacing: .08em; text-transform: uppercase; color: var(--text-3); }
.stat .value { font: 600 var(--t-lg) var(--mono); font-variant-numeric: tabular-nums; margin-top: 2px; }
.row { display: flex; align-items: center; gap: var(--s3); min-height: 56px; padding: var(--s2) 0; border-top: 1px solid var(--line); }
.row:first-child { border-top: 0; }
.row .grow { flex: 1; min-width: 0; }
.row .title { font-weight: 600; }
.row .sub { font-size: var(--t-sm); color: var(--text-2); }
.row.tap { cursor: pointer; transition: background-color var(--dur) var(--ease); border-radius: var(--r-sm); }
.badge { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; font: 800 12px var(--font); color: #fff; flex-shrink: 0; }

/* ---------- Inputs ---------- */
.field { display: flex; align-items: center; gap: var(--s2); height: 44px; padding: 0 var(--s3); border-radius: var(--r-sm); background: var(--surface-2); border: 1px solid var(--line); }
.field input, .field select { flex: 1; background: none; border: 0; outline: none; min-width: 0; }
.field:focus-within { border-color: var(--accent); }

/* ---------- Sheet & toast ---------- */
.overlay { position: absolute; inset: 0; z-index: 50; display: grid; place-items: center; background: rgba(4, 6, 10, .6); opacity: 0; transition: opacity 240ms var(--ease); }
.overlay.open { opacity: 1; }
.sheet {
  width: min(560px, calc(100% - 32px)); max-height: min(86vh, 860px); display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--line-2); border-radius: var(--r-lg); box-shadow: 0 30px 80px rgba(0,0,0,.6);
  transform: translateY(14px) scale(.98); transition: transform 280ms var(--ease);
}
.sheet.wide { width: min(860px, calc(100% - 32px)); }
.overlay.open .sheet { transform: none; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: var(--s4) var(--s4) var(--s2) var(--s5); }
.sheet-head h2 { font-size: var(--t-lg); font-weight: 700; }
.sheet-body { padding: var(--s2) var(--s5) var(--s5); }
.sheet-actions { display: flex; gap: var(--s2); justify-content: flex-end; padding: var(--s3) var(--s5) var(--s5); border-top: 1px solid var(--line); }
@media (max-width: 599px) {
  .overlay { place-items: end stretch; }
  .sheet { width: 100%; max-height: 92vh; border-radius: var(--r-lg) var(--r-lg) 0 0; transform: translateY(100%); }
}
#toast {
  position: absolute; left: 50%; bottom: 28px; z-index: 60; transform: translate(-50%, 16px); opacity: 0; pointer-events: none;
  padding: 10px 16px; border-radius: 12px; background: var(--surface-3); border: 1px solid var(--line-2); font-size: var(--t-sm); font-weight: 600;
  transition: opacity 220ms var(--ease), transform 220ms var(--ease);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
