/* Layout: one-screen operations console — top bar, three columns (flight status | live twin | tools), status strip.
   Narrow screens stack: twin view first, then status, then tools.
   Dark-first (night ops), with a high-contrast daylight theme for outdoor use. */
:root {
  --bg: #0a1017;
  --panel: #0f1720;
  --panel-2: #15202c;
  --panel-3: #1b2836;
  --line: #1f2d3b;
  --line-strong: #2b3d50;
  --fg: #dce6ef;
  --fg-2: #b4c2d0;
  --muted: #7f92a6;
  --accent: #58a8ff;
  --accent-fg: #03111f;
  --accent-soft: rgba(88, 168, 255, 0.14);
  --plan: #f3efe4;
  --plan-fg: #14110a;
  --good: #3ccb7f;
  --warn: #f2a83a;
  --crit: #ff5d62;
  --good-soft: rgba(60, 203, 127, 0.14);
  --warn-soft: rgba(242, 168, 58, 0.15);
  --crit-soft: rgba(255, 93, 98, 0.16);
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.45);
  --overlay: rgba(8, 13, 19, 0.78);
  --overlay-fg: #e6eef6;
  --scrim: rgba(3, 7, 12, 0.62);
  /* instrument colours (same in both themes: aviation convention) */
  --pfd-sky-top: #1b5a9e;
  --pfd-sky: #4a8fd1;
  --pfd-ground: #8a5a32;
  --pfd-ground-bot: #5b3a1e;
  --pfd-symbol: #ffd23f;
  --pfd-ink: #ffffff;
  --pfd-tape: rgba(5, 10, 16, 0.55);
  /* 3D scene */
  --sky-top: #0b1a2c;
  --sky-horizon: #2a4561;
  --ground3d: #1a2430;
  --grid-major: #4c637a;
  --grid-minor: #2f4052;
  --map-bg: #111a23;
  --map-grid: rgba(150, 175, 200, 0.16);
  --map-grid-label: rgba(170, 190, 210, 0.6);

  --font-ui: "IBM Plex Sans", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", system-ui, sans-serif;
  --font-num: "Barlow Semi Condensed", "IBM Plex Sans", "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --radius: 10px;
  --radius-sm: 7px;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #e9eef3; --panel: #ffffff; --panel-2: #f3f6f9; --panel-3: #e8eef4; --line: #d5dee7; --line-strong: #bccad8;
    --fg: #101c28; --fg-2: #33475b; --muted: #5a6d80; --accent: #0f6fd6; --accent-fg: #ffffff; --accent-soft: rgba(15, 111, 214, 0.1); --plan: #1c232b; --plan-fg: #ffffff;
    --good: #0f8a4c; --warn: #a96400; --crit: #cf2b31; --good-soft: rgba(15, 138, 76, 0.1); --warn-soft: rgba(169, 100, 0, 0.11); --crit-soft: rgba(207, 43, 49, 0.1);
    --shadow: 0 8px 30px rgba(20, 40, 60, 0.18); --overlay: rgba(255, 255, 255, 0.86); --overlay-fg: #0f1b27; --scrim: rgba(15, 28, 40, 0.38);
    --sky-top: #4f8fcf; --sky-horizon: #d7e6f1; --ground3d: #a3b39d; --grid-major: #66796c; --grid-minor: #8c9d8f;
    --map-bg: #e3e9ee; --map-grid: rgba(40, 70, 100, 0.16); --map-grid-label: rgba(30, 55, 80, 0.65);
    color-scheme: light;
  }
}
:root[data-theme="light"] {
  --bg: #e9eef3; --panel: #ffffff; --panel-2: #f3f6f9; --panel-3: #e8eef4; --line: #d5dee7; --line-strong: #bccad8;
  --fg: #101c28; --fg-2: #33475b; --muted: #5a6d80; --accent: #0f6fd6; --accent-fg: #ffffff; --accent-soft: rgba(15, 111, 214, 0.1); --plan: #1c232b; --plan-fg: #ffffff;
  --good: #0f8a4c; --warn: #a96400; --crit: #cf2b31; --good-soft: rgba(15, 138, 76, 0.1); --warn-soft: rgba(169, 100, 0, 0.11); --crit-soft: rgba(207, 43, 49, 0.1);
  --shadow: 0 8px 30px rgba(20, 40, 60, 0.18); --overlay: rgba(255, 255, 255, 0.86); --overlay-fg: #0f1b27; --scrim: rgba(15, 28, 40, 0.38);
  --sky-top: #4f8fcf; --sky-horizon: #d7e6f1; --ground3d: #a3b39d; --grid-major: #66796c; --grid-minor: #8c9d8f;
  --map-bg: #e3e9ee; --map-grid: rgba(40, 70, 100, 0.16); --map-grid-label: rgba(30, 55, 80, 0.65);
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 13px/1.45 var(--font-ui); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.num, .tabular { font-variant-numeric: tabular-nums; }
svg { stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.app {
  height: 100%;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  gap: 10px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 10px 8px;
}

/* ------------------------------------------------------------------ top bar */
.topbar { display: flex; align-items: center; gap: 14px; min-width: 0; }
.brand { display: flex; align-items: center; gap: 10px; flex: none; }
.brand-mark { width: 30px; height: 30px; color: var(--accent); stroke-width: 2; }
.brand-mark rect { fill: var(--accent); stroke: none; }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-name { font-family: var(--font-num); font-weight: 700; font-size: 19px; letter-spacing: 0.04em; }
.brand-sub { font-size: 11px; color: var(--muted); letter-spacing: 0.08em; }

.conn { display: flex; align-items: center; gap: 10px; padding: 6px 12px 6px 10px; border-radius: 999px; border: 1px solid var(--line-strong); background: var(--panel); cursor: pointer; flex: none; max-width: 300px; }
.conn:hover { border-color: var(--accent); }
.conn-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); flex: none; box-shadow: 0 0 0 3px var(--panel-3); }
.conn[data-state="connected"] .conn-dot { background: var(--good); box-shadow: 0 0 0 3px var(--good-soft); }
.conn[data-state="connecting"] .conn-dot, .conn[data-state="reconnecting"] .conn-dot { background: var(--warn); animation: blink 1s infinite; }
.conn[data-state="error"] .conn-dot { background: var(--crit); }
.conn-main { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.15; min-width: 0; }
#connLabel { font-weight: 600; white-space: nowrap; }
.conn-sub { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 240px; }

.fleet { display: flex; gap: 6px; flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; padding: 2px; }
.fleet::-webkit-scrollbar { display: none; }
.chip-v { display: flex; align-items: center; gap: 8px; padding: 5px 10px 5px 6px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); cursor: pointer; flex: none; text-align: left; }
.chip-v:hover { border-color: var(--line-strong); }
.chip-v[aria-selected="true"] { border-color: var(--accent); background: var(--accent-soft); }
.chip-v .sw { width: 6px; align-self: stretch; border-radius: 3px; }
.chip-v .cv-main { display: flex; flex-direction: column; line-height: 1.15; }
.chip-v .cv-id { font-family: var(--font-num); font-weight: 700; font-size: 14px; }
.chip-v .cv-sub { font-size: 11px; color: var(--muted); white-space: nowrap; }
.chip-v .cv-batt { font-family: var(--font-num); font-size: 12px; color: var(--fg-2); margin-left: 4px; }
.chip-v[data-stale="true"] { opacity: 0.6; }
.chip-v[data-stale="true"] .cv-sub { color: var(--crit); }
.chip-v .armed-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.chip-v .armed-dot.on { background: var(--warn); box-shadow: 0 0 0 3px var(--warn-soft); }
.fleet-empty { color: var(--muted); font-size: 12px; align-self: center; }

.top-actions { display: flex; gap: 6px; flex: none; }
.icon-btn { position: relative; width: 36px; height: 36px; border-radius: 9px; border: 1px solid var(--line); background: var(--panel); display: grid; place-items: center; cursor: pointer; color: var(--fg-2); }
.icon-btn:hover { color: var(--fg); border-color: var(--line-strong); }
.icon-btn svg { width: 19px; height: 19px; }
.icon-btn[aria-pressed="false"] .wave { opacity: 0; }
.icon-btn[aria-pressed="false"] { color: var(--muted); }
.badge { position: absolute; top: -5px; right: -5px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--crit); color: #fff; font-size: 11px; font-weight: 600; display: grid; place-items: center; font-variant-numeric: tabular-nums; }
.badge.warn { background: var(--warn); color: #1c1300; }

.banner { display: flex; align-items: center; gap: 12px; padding: 8px 14px; border-radius: var(--radius-sm); background: var(--accent-soft); border: 1px solid var(--accent); font-weight: 500; }
.banner.crit { background: var(--crit-soft); border-color: var(--crit); }
.banner.warn { background: var(--warn-soft); border-color: var(--warn); }
.banner .grow { flex: 1; min-width: 0; }

/* ------------------------------------------------------------------ workspace */
.workspace { display: grid; grid-template-columns: 296px minmax(0, 1fr) 368px; gap: 10px; min-height: 0; }
.col { min-height: 0; overflow-y: auto; overflow-x: hidden; display: flex; flex-direction: column; gap: 10px; scrollbar-width: thin; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.card-title { font-size: 11px; font-weight: 600; letter-spacing: 0.1em; color: var(--muted); text-transform: uppercase; margin: 0 0 8px; display: flex; align-items: center; gap: 8px; }
.card-title .spacer { flex: 1; }

/* vehicle status */
.vs-head { display: flex; align-items: center; gap: 10px; }
.vs-swatch { width: 8px; height: 38px; border-radius: 4px; }
.vs-name { font-family: var(--font-num); font-size: 24px; font-weight: 700; line-height: 1; }
.vs-meta { font-size: 11.5px; color: var(--muted); line-height: 1.3; }
.vs-link { margin-left: auto; text-align: right; font-size: 11px; color: var(--muted); }
.bars { display: inline-flex; gap: 2px; align-items: flex-end; height: 14px; vertical-align: -2px; }
.bars i { width: 4px; background: var(--line-strong); border-radius: 1px; }
.bars i.on { background: var(--good); }
.bars.warn i.on { background: var(--warn); }
.bars.crit i.on { background: var(--crit); }
.vs-pills { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--panel-3); color: var(--fg-2); border: 1px solid transparent; }
.pill.mode { background: var(--accent-soft); color: var(--accent); border-color: color-mix(in srgb, var(--accent) 40%, transparent); }
.pill.armed { background: var(--warn-soft); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 45%, transparent); }
.pill.good { background: var(--good-soft); color: var(--good); }
.pill.crit { background: var(--crit-soft); color: var(--crit); border-color: color-mix(in srgb, var(--crit) 45%, transparent); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.vs-tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.tile { background: var(--panel-2); border-radius: 8px; padding: 7px 9px; min-width: 0; }
.tile-l { font-size: 11px; color: var(--muted); }
.tile-v { font-family: var(--font-num); font-size: 21px; font-weight: 600; line-height: 1.1; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tile-v small { font-size: 12px; color: var(--muted); font-weight: 500; margin-left: 2px; }
.tile.warn .tile-v { color: var(--warn); }
.tile.crit .tile-v { color: var(--crit); }
.batt-meter { height: 4px; border-radius: 2px; background: var(--line); margin-top: 4px; overflow: hidden; }
.batt-meter i { display: block; height: 100%; background: var(--good); border-radius: 2px; }
.tile.warn .batt-meter i { background: var(--warn); }
.tile.crit .batt-meter i { background: var(--crit); }
.empty-state { color: var(--muted); font-size: 12.5px; line-height: 1.6; }
.empty-state strong { color: var(--fg); display: block; font-size: 14px; margin-bottom: 2px; }

.pfd-card { padding: 6px; }
#pfd { display: block; width: 100%; aspect-ratio: 4 / 3; border-radius: 7px; }

/* actions */
.act-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.act-grid .span2 { grid-column: span 2; }
.act-grid .span3 { grid-column: span 3; }
.btn { height: 34px; padding: 0 10px; border-radius: var(--radius-sm); border: 1px solid var(--line-strong); background: var(--panel-2); color: var(--fg); font-weight: 500; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap; }
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.42; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); font-weight: 600; }
.btn.warn { border-color: color-mix(in srgb, var(--warn) 55%, transparent); color: var(--warn); }
.btn.danger { border-color: color-mix(in srgb, var(--crit) 55%, transparent); color: var(--crit); }
.btn.solid-danger { background: var(--crit); border-color: var(--crit); color: #fff; }
.btn.sm { height: 28px; font-size: 12px; padding: 0 8px; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--fg-2); }
.btn.ghost:hover:not(:disabled) { background: var(--panel-3); border-color: transparent; }
.btn[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.btn.busy { pointer-events: none; opacity: 0.7; }
.btn.busy::after { content: ""; width: 12px; height: 12px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin 0.8s linear infinite; }
.takeoff-box { display: flex; align-items: center; gap: 4px; }
.stepper { display: flex; align-items: center; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); height: 34px; overflow: hidden; background: var(--panel-2); }
.stepper button { width: 26px; height: 100%; border: 0; background: transparent; cursor: pointer; color: var(--fg-2); }
.stepper button:hover { background: var(--panel-3); }
.stepper input { width: 38px; border: 0; background: transparent; text-align: center; font-family: var(--font-num); font-size: 15px; font-weight: 600; -moz-appearance: textfield; }
.stepper input::-webkit-inner-spin-button { -webkit-appearance: none; }
.stepper span { font-size: 11px; color: var(--muted); padding-right: 6px; }
.mode-row { display: flex; gap: 6px; }
.mode-row select { flex: 1; min-width: 0; }
.select, select, .input, input[type="text"], input[type="number"], input[type="url"], input[type="password"] { height: 32px; border-radius: var(--radius-sm); border: 1px solid var(--line-strong); background: var(--panel-2); padding: 0 8px; min-width: 0; }
input[type="range"] { accent-color: var(--accent); width: 100%; }
input[type="checkbox"] { accent-color: var(--accent); width: 15px; height: 15px; }
.hold-btn { position: relative; overflow: hidden; }
.hold-btn .hold-fill { position: absolute; inset: 0; background: var(--crit); transform-origin: left; transform: scaleX(0); opacity: 0.35; pointer-events: none; }
.act-sep { grid-column: span 3; height: 1px; background: var(--line); margin: 4px 0; }
.act-label { grid-column: span 3; font-size: 11px; color: var(--muted); letter-spacing: 0.06em; }

/* telemetry */
.kv { display: grid; grid-template-columns: 1fr 1fr; column-gap: 12px; row-gap: 3px; }
.kv div { display: flex; justify-content: space-between; gap: 6px; min-width: 0; border-bottom: 1px dashed var(--line); padding: 3px 0; }
.kv dt, .kv .k { color: var(--muted); font-size: 12px; white-space: nowrap; }
.kv .v { font-family: var(--font-num); font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; }
.kv .v.warn { color: var(--warn); } .kv .v.crit { color: var(--crit); }
.kv .wide { grid-column: span 2; }
.motors { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 10px; }
.motor { text-align: center; font-size: 11px; color: var(--muted); }
.motor .mbar { height: 46px; border-radius: 5px; background: var(--panel-2); position: relative; overflow: hidden; margin-bottom: 3px; border: 1px solid var(--line); }
.motor .mbar i { position: absolute; left: 0; right: 0; bottom: 0; background: var(--accent); opacity: 0.85; }
.motor .mbar.fail i { background: var(--crit); }
.motor b { display: block; color: var(--fg); font-family: var(--font-num); font-size: 13px; font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------------ view */
.view { position: relative; min-height: 0; border-radius: var(--radius); overflow: hidden; background: var(--map-bg); border: 1px solid var(--line); }
.pane { position: absolute; overflow: hidden; background: var(--map-bg); }
.pane canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.view[data-layout="3d"] .pane-3d, .view[data-layout="map"] .pane-map { inset: 0; z-index: 1; }
.view[data-layout="3d"] .pane-map, .view[data-layout="map"] .pane-3d {
  right: 12px; bottom: 12px; width: min(34%, 340px); aspect-ratio: 4 / 3; z-index: 3; border-radius: 9px; border: 1px solid var(--line-strong); box-shadow: var(--shadow);
}
.view[data-layout="split"] .pane-3d { inset: 0 50% 0 0; border-right: 1px solid var(--line-strong); }
.view[data-layout="split"] .pane-map { inset: 0 0 0 50%; }
.pip-hit { display: none; position: absolute; inset: 0; z-index: 6; background: transparent; border: 0; cursor: pointer; }
.view[data-layout="3d"] .pane-map .pip-hit, .view[data-layout="map"] .pane-3d .pip-hit { display: block; }
.view[data-layout="3d"] .pane-map .map-tools, .view[data-layout="map"] .pane-3d .view-tools,
.view[data-layout="3d"] .pane-map .map-attr, .view[data-layout="map"] .pane-3d .labels .lbl-wp { display: none; }
.view[data-layout="map"] .pane-3d .labels .lbl { font-size: 10px; padding: 1px 5px; }

.view-tools, .map-tools { position: absolute; top: 10px; left: 10px; z-index: 5; display: flex; gap: 0; background: var(--overlay); border: 1px solid var(--line-strong); border-radius: 8px; padding: 3px; backdrop-filter: blur(6px); }
.map-tools { left: auto; right: 10px; }
.view[data-layout="split"] .pane-3d .view-tools { left: 10px; }
.seg { height: 28px; padding: 0 10px; border: 0; border-radius: 6px; background: transparent; color: var(--overlay-fg); cursor: pointer; font-size: 12.5px; white-space: nowrap; opacity: 0.82; }
.seg:hover { opacity: 1; background: var(--accent-soft); }
.seg[aria-pressed="true"] { background: var(--accent); color: var(--accent-fg); opacity: 1; font-weight: 600; }
.layout-switch { position: absolute; z-index: 7; left: 12px; bottom: 12px; display: flex; background: var(--overlay); border: 1px solid var(--line-strong); border-radius: 8px; padding: 3px; backdrop-filter: blur(6px); }
.empty-3d { position: absolute; z-index: 4; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(380px, calc(100% - 32px)); display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; padding: 16px 18px; border-radius: 12px; background: var(--overlay); color: var(--overlay-fg); border: 1px solid var(--line-strong); backdrop-filter: blur(6px); }
.empty-3d strong { font-size: 15px; }
.empty-3d span { font-size: 12.5px; line-height: 1.6; opacity: 0.85; }
.view[data-layout="map"] .pane-3d .empty-3d { display: none; }
.pane-note { cursor: pointer; position: absolute; left: 10px; bottom: 54px; z-index: 4; max-width: min(420px, 70%); padding: 7px 10px; border-radius: 7px; background: var(--overlay); color: var(--overlay-fg); font-size: 12px; border: 1px solid var(--line-strong); }
.pane-map .pane-note { bottom: 28px; left: auto; right: 10px; }
.map-attr { position: absolute; right: 6px; bottom: 4px; z-index: 4; font-size: 10.5px; color: var(--overlay-fg); background: var(--overlay); padding: 1px 6px; border-radius: 4px; opacity: 0.8; }
.pick-hint { position: absolute; z-index: 8; top: 52px; left: 50%; transform: translateX(-50%); padding: 7px 14px; border-radius: 999px; background: var(--accent); color: var(--accent-fg); font-weight: 600; box-shadow: var(--shadow); white-space: nowrap; }

.labels { position: absolute; inset: 0; pointer-events: none; z-index: 2; overflow: hidden; }
.lbl { position: absolute; left: 0; top: 0; transform: translate(-50%, -100%); padding: 2px 7px 2px 5px; border-radius: 5px; background: var(--overlay); color: var(--overlay-fg); font-size: 11.5px; white-space: nowrap; display: flex; align-items: center; gap: 5px; border: 1px solid var(--line-strong); font-variant-numeric: tabular-nums; will-change: transform; }
.lbl i { width: 8px; height: 8px; border-radius: 2px; flex: none; }
.lbl b { font-family: var(--font-num); font-size: 13px; }
.lbl.sel { border-color: var(--accent); }
.lbl.stale { color: var(--crit); }
.lbl-wp { position: absolute; left: 0; top: 0; transform: translate(-50%, -130%); font-family: var(--font-num); font-weight: 700; font-size: 12px; color: var(--overlay-fg); background: var(--overlay); border-radius: 4px; padding: 0 5px; border: 1px solid var(--line-strong); }

.ctx { position: absolute; z-index: 9; min-width: 180px; background: var(--panel); border: 1px solid var(--line-strong); border-radius: 9px; box-shadow: var(--shadow); padding: 5px; }
.ctx .ctx-coord { font-family: var(--font-mono); font-size: 11px; color: var(--muted); padding: 4px 8px 6px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.ctx button { display: flex; width: 100%; text-align: left; padding: 7px 9px; border: 0; background: transparent; border-radius: 6px; cursor: pointer; }
.ctx button:hover { background: var(--accent-soft); }
.ctx button:disabled { opacity: 0.4; cursor: not-allowed; }

/* ------------------------------------------------------------------ right column */
.col-right { gap: 0; }
.tabs { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; padding-bottom: 0; flex: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { padding: 7px 11px 8px; border: 1px solid transparent; border-bottom: 0; border-radius: 8px 8px 0 0; background: transparent; color: var(--muted); cursor: pointer; white-space: nowrap; font-weight: 500; }
.tab:hover { color: var(--fg); }
.tab[aria-selected="true"] { background: var(--panel); color: var(--fg); border-color: var(--line); position: relative; }
.tab[aria-selected="true"]::after { content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; background: var(--panel); }
.tab .tdot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--crit); margin-left: 5px; vertical-align: 2px; }
.tab-body { flex: 1; min-height: 0; overflow-y: auto; border-top-left-radius: 0; }
.tab-panel { display: flex; flex-direction: column; gap: 12px; }
.section-h { font-size: 11px; font-weight: 600; letter-spacing: 0.1em; color: var(--muted); text-transform: uppercase; display: flex; align-items: center; gap: 8px; }
.section-h .spacer { flex: 1; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row .grow { flex: 1; min-width: 0; }
.field { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.field label, .field .fl { font-size: 11.5px; color: var(--muted); }
.field-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.field-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.field .unit-input { display: flex; align-items: center; gap: 4px; }
.field .unit-input input { width: 100%; }
.field .unit-input span { font-size: 11px; color: var(--muted); }
.hint { font-size: 12px; color: var(--muted); line-height: 1.55; }
.hint code, .mono { font-family: var(--font-mono); font-size: 11.5px; }
.progress { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.progress i { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.2s; }
.summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.summary .tile-v { font-size: 18px; }

/* mission list */
.wp-list { display: flex; flex-direction: column; gap: 4px; max-height: 300px; overflow-y: auto; }
.wp { display: grid; grid-template-columns: 24px minmax(0, 1fr) 62px 56px 26px; align-items: center; gap: 6px; padding: 4px 6px; border-radius: 7px; background: var(--panel-2); border: 1px solid transparent; }
.wp.sel { border-color: var(--accent); }
.wp.cur { box-shadow: inset 3px 0 0 var(--good); }
.wp-n { font-family: var(--font-num); font-weight: 700; text-align: center; background: var(--plan); color: var(--plan-fg); box-shadow: 0 0 0 1px var(--line-strong); border-radius: 5px; font-size: 12px; line-height: 20px; }
.wp-c { font-family: var(--font-mono); font-size: 11px; color: var(--fg-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wp input { height: 26px; width: 100%; padding: 0 5px; font-size: 12px; }
.wp .x { width: 24px; height: 24px; border: 0; background: transparent; color: var(--muted); cursor: pointer; border-radius: 5px; }
.wp .x:hover { color: var(--crit); background: var(--crit-soft); }
.wp-head { display: grid; grid-template-columns: 24px minmax(0, 1fr) 62px 56px 26px; gap: 6px; font-size: 11px; color: var(--muted); padding: 0 6px; }

/* tables */
.tbl-wrap { overflow: auto; max-height: 460px; border: 1px solid var(--line); border-radius: 8px; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 12px; }
.tbl th { position: sticky; top: 0; background: var(--panel-2); text-align: left; font-weight: 600; color: var(--muted); padding: 6px 8px; font-size: 11px; z-index: 1; }
.tbl td { padding: 4px 8px; border-top: 1px solid var(--line); vertical-align: middle; }
.tbl td.mono, .tbl td.n { font-family: var(--font-mono); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.tbl td.n { text-align: right; }
.tbl tr.click { cursor: pointer; }
.tbl tr.click:hover td { background: var(--accent-soft); }
.tbl tr.sel td { background: var(--accent-soft); }
.tbl input { height: 26px; width: 100%; font-family: var(--font-mono); font-size: 11.5px; }
.tbl tr.changed td:first-child { box-shadow: inset 3px 0 0 var(--warn); }
.tbl tr.saved input { border-color: var(--good); }
.tbl tr.err input { border-color: var(--crit); }
pre.json { margin: 0; padding: 10px; background: var(--panel-2); border-radius: 8px; font-family: var(--font-mono); font-size: 11.5px; overflow: auto; max-height: 260px; color: var(--fg-2); }

/* events */
.ev-list { display: flex; flex-direction: column; gap: 2px; }
.ev { display: grid; grid-template-columns: 4px 56px 30px minmax(0, 1fr); gap: 8px; align-items: start; padding: 5px 6px 5px 0; border-bottom: 1px solid var(--line); font-size: 12.5px; }
.ev .stripe { align-self: stretch; border-radius: 2px; background: var(--line-strong); }
.ev.warn .stripe { background: var(--warn); } .ev.critical .stripe { background: var(--crit); } .ev.info .stripe { background: var(--accent); opacity: 0.6; }
.ev .t { font-family: var(--font-mono); font-size: 11px; color: var(--muted); padding-top: 1px; }
.ev .who { font-family: var(--font-num); font-weight: 700; font-size: 12px; }
.ev .txt { overflow-wrap: anywhere; }
.ev.critical .txt { color: var(--crit); font-weight: 500; }
.ev.warn .txt { color: var(--warn); }
.filters { display: flex; gap: 4px; flex-wrap: wrap; }
.filters .btn { height: 26px; font-size: 12px; }

/* charts */
.chart-box { position: relative; }
.chart-box canvas { display: block; width: 100%; height: 220px; }
.chart-tip { position: absolute; pointer-events: none; z-index: 2; background: var(--panel); border: 1px solid var(--line-strong); border-radius: 7px; padding: 6px 8px; font-size: 12px; box-shadow: var(--shadow); white-space: nowrap; font-variant-numeric: tabular-nums; }
.chart-tip .tt { color: var(--muted); font-size: 11px; margin-bottom: 2px; }
.chart-tip .tr { display: flex; align-items: center; gap: 6px; }
.chart-tip .key { width: 10px; height: 3px; border-radius: 2px; }
.legend { display: flex; flex-wrap: wrap; gap: 10px; font-size: 12px; color: var(--fg-2); }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend i { width: 14px; height: 3px; border-radius: 2px; }
.seg-row { display: flex; flex-wrap: wrap; gap: 4px; }
.seg-row .btn { height: 28px; font-size: 12px; padding: 0 9px; }

/* sim */
.slider-row { display: grid; grid-template-columns: 74px minmax(0, 1fr) 62px; gap: 8px; align-items: center; }
.slider-row label { font-size: 12px; color: var(--fg-2); }
.slider-row output { font-family: var(--font-num); font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 6px 0; border-bottom: 1px dashed var(--line); }
.toggle-row .tl { display: flex; flex-direction: column; }
.toggle-row .tl small { color: var(--muted); font-size: 11.5px; }
.switch { position: relative; width: 38px; height: 22px; flex: none; }
.switch input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; z-index: 1; width: 100%; height: 100%; }
.switch span { position: absolute; inset: 0; border-radius: 11px; background: var(--line-strong); transition: background 0.15s; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform 0.15s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(16px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ------------------------------------------------------------------ status bar */
.statusbar { display: flex; align-items: center; gap: 4px 16px; flex-wrap: wrap; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; min-width: 0; }
.sb-item { white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; }
.sb-item b { color: var(--fg-2); font-weight: 600; }
.sb-cursor { margin-left: auto; font-family: var(--font-mono); font-size: 11.5px; }
.rec-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--crit); animation: blink 1.2s infinite; }
.sb-rec button, .sb-replay button { height: 22px; padding: 0 8px; font-size: 11.5px; border-radius: 5px; border: 1px solid var(--line-strong); background: var(--panel); cursor: pointer; }
.sb-replay input[type="range"] { width: 180px; }
.sb-replay select { height: 22px; padding: 0 4px; font-size: 11.5px; }

/* ------------------------------------------------------------------ modal + toasts */
.modal-root { position: fixed; inset: 0; z-index: 50; background: var(--scrim); display: grid; place-items: center; padding: max(16px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) max(16px, env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px)); }
.modal { width: min(560px, 100%); max-height: 100%; overflow: auto; background: var(--panel); border: 1px solid var(--line-strong); border-radius: 14px; box-shadow: var(--shadow); padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.modal.wide { width: min(760px, 100%); }
.modal h2 { margin: 0; font-size: 17px; font-weight: 600; text-wrap: balance; }
.modal .m-body { display: flex; flex-direction: column; gap: 12px; }
.modal .m-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.modal p { margin: 0; line-height: 1.6; color: var(--fg-2); }
.modal.danger h2 { color: var(--crit); }
.link-kinds { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.link-kind { border: 1px solid var(--line-strong); border-radius: 10px; padding: 10px; background: var(--panel-2); cursor: pointer; text-align: left; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.link-kind b { font-size: 13.5px; }
.link-kind small { color: var(--muted); font-size: 11.5px; line-height: 1.4; }
.link-kind[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); }
.link-kind:disabled { opacity: 0.5; cursor: not-allowed; }
.ep-list { display: flex; flex-direction: column; gap: 6px; }
.ep { display: grid; grid-template-columns: 10px minmax(0, 1fr) auto auto; align-items: center; gap: 8px; padding: 7px 9px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); font-size: 12.5px; }
.ep .d { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.ep .d.on { background: var(--good); }
.ep .d.err { background: var(--crit); }
.ep small { color: var(--muted); font-family: var(--font-mono); font-size: 11px; }

.toasts { position: fixed; z-index: 60; top: calc(12px + env(safe-area-inset-top, 0px)); right: max(16px, env(safe-area-inset-right, 0px)); display: flex; flex-direction: column; gap: 8px; width: min(380px, calc(100vw - 32px)); pointer-events: none; }
.toast { pointer-events: auto; display: grid; grid-template-columns: 4px minmax(0, 1fr); gap: 10px; padding: 10px 12px 10px 0; border-radius: 9px; background: var(--panel); border: 1px solid var(--line-strong); box-shadow: var(--shadow); animation: toast-in 0.18s ease-out; overflow: hidden; }
.toast .stripe { border-radius: 0 2px 2px 0; background: var(--accent); }
.toast.good .stripe { background: var(--good); } .toast.warn .stripe { background: var(--warn); } .toast.critical .stripe, .toast.error .stripe { background: var(--crit); }
.toast .tt { font-weight: 600; font-size: 13px; }
.toast .tb { color: var(--fg-2); font-size: 12.5px; overflow-wrap: anywhere; }

@keyframes blink { 50% { opacity: 0.35; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes toast-in { from { transform: translateY(-6px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* ------------------------------------------------------------------ responsive */
@media (max-width: 1360px) { .workspace { grid-template-columns: 272px minmax(0, 1fr) 336px; } }
@media (max-width: 1120px) {
  html, body { height: auto; }
  .app { height: auto; min-height: 100%; }
  .workspace { grid-template-columns: 290px minmax(0, 1fr); grid-template-rows: minmax(560px, 72vh) auto; }
  .col-left { grid-row: 1; }
  .view { grid-row: 1; grid-column: 2; }
  .col-right { grid-column: 1 / -1; grid-row: 2; }
  .tab-body { overflow: visible; }
  .brand-sub { display: none; }
}
@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; gap: 8px; }
  .brand-text { display: none; }
  .conn { flex: 1; max-width: none; }
  .fleet { order: 5; flex-basis: 100%; }
  .workspace { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto; }
  .view { grid-column: 1; grid-row: 1; height: 58vh; min-height: 340px; }
  .col-left { grid-row: 2; overflow: visible; }
  .col-right { grid-row: 3; grid-column: 1; }
  .col { overflow: visible; }
  .view[data-layout="3d"] .pane-map, .view[data-layout="map"] .pane-3d { width: 38%; }
  .view[data-layout="split"] .pane-3d { inset: 0 0 50% 0; border-right: 0; border-bottom: 1px solid var(--line-strong); }
  .view[data-layout="split"] .pane-map { inset: 50% 0 0 0; }
  .view-tools { max-width: calc(100% - 20px); overflow-x: auto; }
  .view-tools .seg, .map-tools .seg { padding: 0 8px; }
  .map-tools { top: auto; bottom: 54px; }
  .link-kinds { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .field-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sb-cursor { margin-left: 0; }
  .sb-replay input[type="range"] { width: 120px; }
}
