/* NTN 衛星無人機主控台：筆電 / 平板（含直向），淺色 / 深色 */

:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-2: #f7f9fc;
  --text: #17202c;
  --muted: #566173;
  --border: #d5dbe4;
  --primary: #0a5fd1;
  --primary-hover: #084fb0;
  --on-primary: #ffffff;
  --danger: #c22a2a;
  --on-danger: #ffffff;
  --danger-bg: #fdecec;
  --warn: #9a4b00;
  --warn-strong: #d97706;
  --warn-bg: #fff3e0;
  --ok: #17803a;
  --ok-bg: #e7f6ec;
  --info: #0a5fd1;
  --info-bg: #e7f0fd;
  --sim: #0f766e;
  --sim-bg: #dff5f2;
  --real: #c22a2a;
  --focus: #ffbf47;
  --shadow: 0 1px 2px rgba(15, 25, 40, .06), 0 2px 8px rgba(15, 25, 40, .06);
  --radius: 12px;
  --topbar-h: 56px;
  --track: #7c3aed;
  --mission: #ea580c;
  color-scheme: light;
}

[data-theme="dark"] {
  --bg: #0e131a;
  --surface: #171f2a;
  --surface-2: #1d2734;
  --text: #e9eef5;
  --muted: #a3afc0;
  --border: #2f3b4c;
  --primary: #5aa2ff;
  --primary-hover: #7bb5ff;
  --on-primary: #08121f;
  --danger: #ff7070;
  --on-danger: #1a0606;
  --danger-bg: #3a1b1d;
  --warn: #ffc26b;
  --warn-strong: #f59e0b;
  --warn-bg: #3a2c14;
  --ok: #59d68a;
  --ok-bg: #163222;
  --info: #7bb5ff;
  --info-bg: #17283f;
  --sim: #4fd1c5;
  --sim-bg: #123532;
  --real: #ff7070;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 2px 10px rgba(0, 0, 0, .3);
  --track: #c4a1ff;
  --mission: #ffa057;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-text-size-adjust: 100%;
}
[hidden] { display: none !important; }
h1, h2, h3, h4 { margin: 0; line-height: 1.3; }
p { margin: .4rem 0; }
a { color: var(--primary); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip-link { position: absolute; left: -9999px; top: 0; z-index: 3000; background: var(--surface); padding: .5rem 1rem; }
.skip-link:focus { left: .5rem; top: .5rem; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.strong { font-weight: 600; }
.center { text-align: center; }

/* ---------------------------------------------------------------- 按鈕 / 表單 */
.btn {
  appearance: none;
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: 44px; padding: .5rem 1rem;
  border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer;
  touch-action: manipulation;
  transition: background .15s, border-color .15s, opacity .15s;
}
.btn:hover:not(:disabled) { border-color: var(--primary); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.is-busy { cursor: progress; }
.btn-sm { min-height: 36px; padding: .3rem .7rem; font-size: .9rem; }
.btn-lg { min-height: 52px; padding: .65rem 1.3rem; font-size: 1.05rem; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: var(--on-danger); }
.btn-danger-outline { color: var(--danger); border-color: var(--danger); }
.btn-warn { color: var(--warn); border-color: var(--warn-strong); background: var(--warn-bg); }
.btn-ghost { background: transparent; }
.btn-row { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-top: .6rem; }
.btn-row.center { justify-content: center; }
.btn-col { display: flex; flex-direction: column; gap: .4rem; }
.row-label { font-size: .875rem; color: var(--muted); font-weight: 600; }

.input, select.input {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px;
  min-height: 44px; padding: .4rem .6rem; width: 100%;
}
.input-lg { font-size: 1.25rem; min-height: 52px; }
.field { display: flex; flex-direction: column; gap: .3rem; margin: .5rem 0; font-weight: 600; }
.field > .muted { font-weight: 400; }
.field-error { color: var(--danger); font-weight: 600; min-height: 0; margin: .3rem 0; }
.field-error:empty { display: none; }
.check { display: flex; align-items: center; gap: .5rem; margin: .3rem 0; cursor: pointer; }
.check input { width: 20px; height: 20px; }

/* ---------------------------------------------------------------- 頂部列 */
.topbar {
  position: sticky; top: 0; z-index: 1100;
  display: flex; align-items: center; flex-wrap: wrap; gap: .5rem 1rem;
  min-height: var(--topbar-h); padding: .4rem 1rem;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; font-size: 1.05rem; }
.brand-mark { color: var(--primary); font-size: 1.2rem; }
.brand-mark.big { font-size: 2.5rem; }
.mock-flag {
  font-size: .75rem; font-weight: 700; padding: .15rem .5rem; border-radius: 999px;
  background: repeating-linear-gradient(45deg, var(--warn-bg), var(--warn-bg) 6px, transparent 6px, transparent 12px);
  border: 1px dashed var(--warn-strong); color: var(--warn);
}
.tabs { display: flex; gap: .25rem; }
.tabs a {
  display: inline-flex; align-items: center; min-height: 44px; padding: 0 .9rem;
  border-radius: 8px; color: var(--muted); text-decoration: none; font-weight: 600;
}
.tabs a:hover { color: var(--text); background: var(--surface-2); }
.tabs a[aria-current="page"] { color: var(--primary); background: var(--info-bg); }
.topbar-right { margin-left: auto; display: flex; align-items: center; flex-wrap: wrap; gap: .5rem; }
.session { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }
.conn { display: inline-flex; align-items: center; gap: .35rem; font-size: .85rem; color: var(--muted); }
.user { display: inline-flex; align-items: center; gap: .4rem; }
.user-name { font-weight: 600; }
.role-badge { font-size: .75rem; font-weight: 700; padding: .1rem .5rem; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); }
.role-admin { color: var(--danger); border-color: var(--danger); }
.role-presenter { color: var(--primary); border-color: var(--primary); }
.lang-select { font: inherit; min-height: 36px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: 0 .4rem; }

.dot { display: inline-block; width: .7rem; height: .7rem; border-radius: 50%; flex: none; }
.dot-ok { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-bg); }
.dot-bad { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-bg); }

.global-banner {
  position: sticky; top: var(--topbar-h); z-index: 1050;
  background: var(--danger); color: var(--on-danger); padding: .6rem 1rem; font-weight: 600; text-align: center;
}
/* 登入服務暫時連不上：提醒，不是錯誤（操作仍可嘗試） */
.global-banner-warn { background: var(--warn-bg); color: var(--text); border-bottom: 3px solid var(--warn-strong); }

/* ---------------------------------------------------------------- 畫面 */
main { display: block; }
main:focus { outline: none; }
.screen.center { display: flex; align-items: center; justify-content: center; min-height: calc(100dvh - var(--topbar-h)); padding: 1.5rem; }
.login-card {
  max-width: 460px; width: 100%; text-align: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 2rem 1.5rem;
  display: flex; flex-direction: column; gap: .8rem; align-items: center;
}
.login-card .btn { width: 100%; }
.notice {
  background: var(--warn-bg); color: var(--text); border-left: 4px solid var(--warn-strong);
  padding: .6rem .8rem; border-radius: 8px; display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; justify-content: space-between;
  font-weight: 600;
}

/* ---------------------------------------------------------------- 主控台版面 */
.console {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(380px, 440px);
  height: calc(100dvh - var(--topbar-h));
}
.map-pane { position: relative; min-height: 300px; }
.map { position: absolute; inset: 0; background: var(--surface-2); }
.side-pane {
  overflow-y: auto; padding: .9rem; display: flex; flex-direction: column; gap: .8rem;
  border-left: 1px solid var(--border); background: var(--bg);
  overscroll-behavior: contain;
}
.console.is-real .side-pane { border-left: 6px solid var(--real); }
.console.is-real .map-pane { box-shadow: inset 0 0 0 6px var(--real); }

/* 平板直向 / 窄螢幕：地圖在上，資訊在下 */
@media (max-width: 1023px) {
  .console { display: block; height: auto; }
  .map-pane { height: 50vh; height: 50dvh; min-height: 320px; }
  .side-pane { overflow: visible; border-left: none; padding: .8rem; }
  .console.is-real .side-pane { border-left: none; border-top: 6px solid var(--real); }
}
@media (min-width: 700px) and (max-width: 1023px) {
  .side-pane { display: grid; grid-template-columns: 1fr 1fr; align-items: start; }
  .side-pane > .vehicle-header, .side-pane > .banners, .side-pane > .stats { grid-column: 1 / -1; }
}
@media (max-width: 600px) {
  .topbar { padding: .4rem .6rem; }
  .brand-text { font-size: .95rem; }
  .tabs { order: 3; width: 100%; overflow-x: auto; }
}

/* 地圖上的工具 */
.map-tools { position: absolute; top: .6rem; right: .6rem; z-index: 800; display: flex; gap: .4rem; flex-wrap: wrap; justify-content: flex-end; }
.map-btn { box-shadow: var(--shadow); }
.map-btn.active { border-color: var(--primary); color: var(--primary); }
.map-legend {
  position: absolute; left: .6rem; bottom: 1.6rem; z-index: 800;
  display: grid; grid-template-columns: auto 1fr; gap: .2rem .45rem; align-items: center;
  background: color-mix(in srgb, var(--surface) 92%, transparent); border: 1px solid var(--border); border-radius: 8px;
  padding: .4rem .6rem; font-size: .78rem; box-shadow: var(--shadow); max-width: 60%;
}
.lg { display: inline-block; width: 18px; height: 0; }
.lg-ac { width: 12px; height: 12px; border-radius: 50%; background: var(--primary); justify-self: center; }
.lg-track { border-top: 3px solid var(--track); }
.lg-mission { border-top: 3px dashed var(--mission); }
.lg-home { width: 18px; height: 18px; line-height: 18px; text-align: center; border-radius: 50%; background: var(--ok); color: #fff; font-weight: 700; font-size: .7rem; }
@media (max-width: 600px) { .map-legend { display: none; } }
/* 測試模式：工具列在左下，圖例往上讓位 */
.is-mock .map-legend { bottom: 4.2rem; }

.goto-panel {
  position: absolute; left: .6rem; top: .6rem; z-index: 900; width: min(360px, calc(100% - 1.2rem));
  background: var(--surface); border: 2px solid var(--primary); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: .8rem 1rem;
}
.goto-panel h3 { font-size: 1.05rem; }
.goto-info { font-weight: 600; }
.map.picking, .map.picking .leaflet-interactive { cursor: crosshair; }

/* Leaflet 深色：反轉圖磚，維持標記顏色 */
[data-theme="dark"] .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.9) contrast(.9); }
[data-theme="dark"] .leaflet-container { background: #1b222c; }
[data-theme="dark"] .leaflet-control-zoom a,
[data-theme="dark"] .leaflet-control-attribution { background: var(--surface); color: var(--text); }
[data-theme="dark"] .leaflet-control-attribution a { color: var(--primary); }
.leaflet-container { font: inherit; }
.leaflet-control-zoom a { width: 36px !important; height: 36px !important; line-height: 36px !important; }

.map-icon { background: none; border: none; }
.aircraft { width: 40px; height: 40px; }
.ac-rot { width: 40px; height: 40px; transition: transform .6s ease; }
.ac-halo { fill: var(--primary); opacity: .18; }
.ac-body { fill: var(--primary); stroke: #fff; stroke-width: 2; stroke-linejoin: round; }
.aircraft.armed .ac-halo { opacity: .3; }
.aircraft.offline .ac-body { fill: #8a94a3; }
.aircraft.offline .ac-halo { fill: #8a94a3; }
.home-pin {
  width: 28px; height: 28px; border-radius: 50%; background: var(--ok); color: #fff;
  border: 2px solid #fff; font-weight: 800; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 1px 4px rgba(0,0,0,.35);
}
.wp-pin {
  width: 22px; height: 22px; border-radius: 50%; background: var(--mission); color: #fff;
  border: 2px solid #fff; font-size: .7rem; font-weight: 700; display: flex; align-items: center; justify-content: center;
}
.target-pin {
  width: 30px; height: 30px; border-radius: 50%; border: 3px solid var(--danger);
  background: radial-gradient(circle, var(--danger) 0 4px, transparent 5px);
  animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse { 50% { transform: scale(1.15); } }
@media (prefers-reduced-motion: reduce) { .target-pin { animation: none; } .ac-rot { transition: none; } }
.track-line { stroke: var(--track); }
.mission-line { stroke: var(--mission); }
.target-line { stroke: var(--danger); }

/* ---------------------------------------------------------------- 卡片 */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: .9rem 1rem;
}
.card-title { font-size: 1.05rem; margin-bottom: .4rem; }

.vehicle-header { display: flex; flex-direction: column; gap: .25rem; }
.vehicle-title { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.vehicle-name { font-size: 1.35rem; }
.vehicle-select { font: inherit; font-size: 1.1rem; font-weight: 700; min-height: 44px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: 0 .5rem; max-width: 100%; }
.kind-hint { font-size: .9rem; color: var(--muted); margin: 0; }
.kind-badge { font-size: .85rem; font-weight: 800; padding: .2rem .7rem; border-radius: 999px; letter-spacing: .02em; }
.kind-sim { background: var(--sim-bg); color: var(--sim); border: 2px solid var(--sim); }
.kind-real { background: var(--real); color: #fff; border: 2px solid var(--real); text-transform: uppercase; }

.banners { display: flex; flex-direction: column; gap: .5rem; }
.banners:not(:has(.banner:not([hidden]))) { display: none; }
.banner { display: flex; gap: .6rem; align-items: flex-start; padding: .65rem .8rem; border-radius: 10px; font-weight: 600; border-left: 5px solid; }
.banner-icon { flex: none; width: 1.5rem; height: 1.5rem; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 800; }
.banner-info { background: var(--info-bg); border-color: var(--info); }
.banner-info .banner-icon { background: var(--info); color: var(--on-primary); }
.banner-warn { background: var(--warn-bg); border-color: var(--warn-strong); }
.banner-warn .banner-icon { background: var(--warn-strong); color: #fff; }
.banner-danger { background: var(--danger-bg); border-color: var(--danger); }
.banner-danger .banner-icon { background: var(--danger); color: var(--on-danger); }

/* 狀態卡片 */
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .5rem; }
@media (min-width: 700px) and (max-width: 1023px) { .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: .55rem .7rem; min-width: 0; }
.stat-label { font-size: .8rem; color: var(--muted); font-weight: 600; }
.stat-value { font-size: 1.35rem; font-weight: 700; display: flex; align-items: center; gap: .4rem; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.stat-sub { font-size: .82rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.stat-link { grid-column: 1 / -1; }
@media (min-width: 700px) and (max-width: 1023px) { .stat-link { grid-column: span 2; } }
.stat-link.is-offline { border-color: var(--danger); background: var(--danger-bg); }
.stat-mode.is-armed .stat-sub { color: var(--warn); font-weight: 600; }
.battery-bar { height: 6px; border-radius: 3px; background: var(--surface-2); border: 1px solid var(--border); margin-top: .3rem; overflow: hidden; }
.battery-fill { height: 100%; background: var(--ok); transition: width .5s; }
.stat-battery.is-low .battery-fill { background: var(--danger); }
.stat-battery.is-low .stat-value { color: var(--danger); }

/* 控制權 */
.control-holder { font-size: 1.1rem; font-weight: 700; margin: .2rem 0; }
.control-holder.is-mine { color: var(--ok); }
.control-holder.is-other { color: var(--warn); }
.control-idle { background: var(--surface-2); border-radius: 8px; padding: .4rem .6rem; font-size: .9rem; font-variant-numeric: tabular-nums; }
.control-idle.is-urgent { background: var(--warn-bg); color: var(--warn); font-weight: 700; }
.admin-row { border-top: 1px dashed var(--border); padding-top: .6rem; }

/* 指令進度 */
.progress-list { display: flex; flex-direction: column; gap: .7rem; }
.progress-item { border: 1px solid var(--border); border-radius: 10px; padding: .7rem .8rem; background: var(--surface-2); }
.progress-item.status-failed { border-color: var(--danger); background: var(--danger-bg); }
.progress-item.status-confirmed { border-color: var(--ok); }
.progress-item.status-unconfirmed { border-color: var(--warn-strong); }
.progress-head { display: flex; justify-content: space-between; gap: .5rem; align-items: center; flex-wrap: wrap; }
.progress-explain { font-size: .95rem; margin: .5rem 0 .2rem; }
.steps { list-style: none; display: grid; grid-template-columns: repeat(4, 1fr); gap: .25rem; padding: 0; margin: .7rem 0 .2rem; counter-reset: s; }
.step { position: relative; display: flex; flex-direction: column; align-items: center; text-align: center; font-size: .75rem; color: var(--muted); }
.step::before { content: ""; position: absolute; top: 9px; left: -50%; right: 50%; height: 3px; background: var(--border); z-index: 0; }
.step:first-child::before { display: none; }
.step-dot { width: 20px; height: 20px; border-radius: 50%; background: var(--surface); border: 3px solid var(--border); z-index: 1; margin-bottom: .25rem; }
.step.done { color: var(--text); }
.step.done .step-dot { background: var(--ok); border-color: var(--ok); }
.step.done::before { background: var(--ok); }
.step.current { color: var(--primary); font-weight: 700; }
.step.current .step-dot { border-color: var(--primary); background: var(--info-bg); animation: blink 1.2s ease-in-out infinite; }
.step.current::before { background: var(--ok); }
.step.warn .step-dot { background: var(--warn-strong); border-color: var(--warn-strong); }
.step.warn { color: var(--warn); }
.status-failed .step:not(.done) .step-dot, .status-cancelled .step:not(.done) .step-dot { border-color: var(--danger); }
@keyframes blink { 50% { box-shadow: 0 0 0 5px var(--info-bg); } }
@media (prefers-reduced-motion: reduce) { .step.current .step-dot { animation: none; } }
.pbar-wrap { display: flex; align-items: center; gap: .5rem; margin: .4rem 0; }
.pbar { flex: 1; height: 10px; border-radius: 5px; background: var(--surface); border: 1px solid var(--border); overflow: hidden; }
.pbar-fill { height: 100%; background: var(--primary); transition: width .4s; }

.chip { display: inline-block; font-size: .78rem; font-weight: 700; padding: .12rem .55rem; border-radius: 999px; white-space: nowrap; border: 1px solid transparent; }
.chip-queued, .chip-sending { background: var(--info-bg); color: var(--info); border-color: var(--info); }
.chip-delivered { background: var(--info-bg); color: var(--primary); border-color: var(--primary); }
.chip-confirmed { background: var(--ok-bg); color: var(--ok); border-color: var(--ok); }
.chip-unconfirmed { background: var(--warn-bg); color: var(--warn); border-color: var(--warn-strong); }
.chip-failed { background: var(--danger-bg); color: var(--danger); border-color: var(--danger); }
.chip-cancelled { background: var(--surface-2); color: var(--muted); border-color: var(--border); }

/* 操作按鈕 */
.action-note { background: var(--info-bg); border-radius: 8px; padding: .5rem .7rem; font-weight: 600; }
.action-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .6rem; margin-top: .4rem; }
.btn-big { flex-direction: column; min-height: 84px; font-size: 1.1rem; border-width: 2px; border-radius: 12px; text-align: center; }
.btn-icon { font-size: 1.6rem; line-height: 1; }
.btn-act:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.btn-act:not(:disabled):hover { background: var(--info-bg); }
.btn-act.active { background: var(--primary); color: var(--on-primary); }
.action-grid .btn-big:last-child:nth-child(odd) { grid-column: 1 / -1; }
.reset-row { margin-top: .9rem; border-top: 1px dashed var(--border); padding-top: .8rem; }
.btn-reset { width: 100%; flex-direction: row; min-height: 60px; border-color: var(--danger); color: var(--danger); }
.btn-reset:not(:disabled):hover { background: var(--danger-bg); }

/* 任務 */
.mission-list { display: flex; flex-direction: column; gap: .4rem; margin: .4rem 0; }
.mission-option {
  display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; column-gap: .6rem;
  border: 1px solid var(--border); border-radius: 10px; padding: .55rem .7rem; cursor: pointer; min-height: 44px;
}
.mission-option input { grid-row: 1 / 3; width: 20px; height: 20px; align-self: center; }
.mission-option:has(input:checked) { border-color: var(--mission); background: color-mix(in srgb, var(--mission) 10%, var(--surface)); }
.mission-name { font-weight: 600; }

/* 參數 */
.param-rows { display: flex; flex-direction: column; gap: .9rem; }
.param-row { border-top: 1px solid var(--border); padding-top: .6rem; }
.param-row:first-child { border-top: none; padding-top: 0; }
.param-head { display: flex; justify-content: space-between; align-items: baseline; gap: .5rem; font-weight: 600; }
.param-value { font-size: 1.2rem; font-weight: 700; color: var(--primary); font-variant-numeric: tabular-nums; }
.param-foot { display: flex; justify-content: space-between; align-items: center; gap: .5rem; flex-wrap: wrap; }
.slider { width: 100%; height: 36px; accent-color: var(--primary); }

/* 最近指令 */
.history { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; }
.history-item { display: grid; grid-template-columns: auto 1fr auto; grid-template-areas: "time title chip" "time by chip"; gap: 0 .6rem; padding: .45rem 0; border-top: 1px solid var(--border); align-items: center; }
.history-item:first-child { border-top: none; }
.history-time { grid-area: time; font-variant-numeric: tabular-nums; color: var(--muted); font-size: .85rem; }
.history-title { grid-area: title; font-weight: 600; }
.history-by { grid-area: by; }
.history-item .chip { grid-area: chip; }

/* ---------------------------------------------------------------- 一般頁面 */
.page { max-width: 1100px; margin: 0 auto; padding: 1rem; display: flex; flex-direction: column; gap: 1rem; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: .55rem .6rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th { font-size: .85rem; color: var(--muted); background: var(--surface-2); }
.table .row-denied td { background: color-mix(in srgb, var(--danger-bg) 60%, transparent); }
.cell-actions { display: flex; gap: .4rem; flex-wrap: wrap; }
.upload-form { max-width: 520px; }
.filters { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0 .8rem; align-items: end; }
.filters-actions { grid-column: 1 / -1; justify-content: flex-end; }
.filters .field-error { grid-column: 1 / -1; }
@media (max-width: 800px) { .filters { grid-template-columns: 1fr 1fr; } }
/* 窄螢幕：表格改為卡片 */
@media (max-width: 700px) {
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr { border: 1px solid var(--border); border-radius: 10px; margin-bottom: .6rem; padding: .3rem .2rem; }
  .table td { border: none; padding: .25rem .6rem; display: grid; grid-template-columns: 7rem 1fr; gap: .5rem; }
  .table td::before { content: attr(data-label); color: var(--muted); font-size: .8rem; font-weight: 600; }
  .table td[colspan]::before { content: none; }
}

/* ---------------------------------------------------------------- 對話框 / 提示 */
.dialog {
  border: none; border-radius: var(--radius); padding: 0; width: min(520px, calc(100vw - 2rem));
  background: var(--surface); color: var(--text); box-shadow: 0 10px 40px rgba(0,0,0,.35);
}
.dialog::backdrop { background: rgba(10, 15, 25, .55); }
.dialog-danger { border-top: 6px solid var(--danger); }
.dialog-body { padding: 1.2rem 1.3rem; display: flex; flex-direction: column; gap: .3rem; }
.dialog-title { font-size: 1.25rem; margin-bottom: .3rem; }
.dialog-error { color: var(--danger); font-weight: 600; }
.dialog-actions { display: flex; justify-content: flex-end; gap: .6rem; margin-top: .8rem; flex-wrap: wrap; }
@media (max-width: 480px) { .dialog-actions .btn { flex: 1; } }

.toasts { position: fixed; right: 1rem; bottom: 1rem; z-index: 2000; display: flex; flex-direction: column; gap: .5rem; max-width: min(420px, calc(100vw - 2rem)); }
.toast {
  display: flex; gap: .6rem; align-items: flex-start; justify-content: space-between;
  background: var(--surface); color: var(--text); border: 1px solid var(--border); border-left: 6px solid var(--info);
  border-radius: 10px; padding: .7rem .8rem; box-shadow: var(--shadow); font-weight: 600;
}
.toast-success { border-left-color: var(--ok); }
.toast-warn { border-left-color: var(--warn-strong); }
.toast-error { border-left-color: var(--danger); }
.toast-close { background: none; border: none; color: var(--muted); font-size: 1.3rem; cursor: pointer; min-width: 32px; min-height: 32px; }

/* ---------------------------------------------------------------- 假資料測試工具 */
.mockbar {
  position: fixed; left: 1rem; bottom: 1rem; z-index: 1900; width: min(320px, calc(100vw - 2rem));
  background: var(--surface); border: 2px dashed var(--warn-strong); border-radius: var(--radius); box-shadow: var(--shadow);
  max-height: calc(100dvh - 6rem); overflow-y: auto;
}
.mockbar-head { width: 100%; min-height: 44px; background: var(--warn-bg); color: var(--warn); border: none; font: inherit; font-weight: 700; cursor: pointer; border-radius: 10px 10px 0 0; }
.mockbar-body { padding: .6rem .8rem; }
.mockbar h4 { margin: .6rem 0 .3rem; font-size: .9rem; }
.mockbar .btn { justify-content: flex-start; }
.mockbar:has(.mockbar-body[hidden]) { width: auto; }

/* ================================================================ v1.1：真實機操控（規格 §12） */

/* 角色標籤 */
.role-pilot, .role-adminPilot { color: var(--real); border-color: var(--real); background: var(--danger-bg); }

/* 失聯提醒（所有頁面頂端） */
.alert-bar {
  position: sticky; top: var(--topbar-h); z-index: 1060;
  background: var(--danger); color: var(--on-danger);
  display: flex; flex-direction: column;
}
.alert-row { display: flex; align-items: center; gap: .7rem; padding: .55rem 1rem; flex-wrap: wrap; }
.alert-row + .alert-row { border-top: 1px solid color-mix(in srgb, var(--on-danger) 30%, transparent); }
.alert-icon {
  flex: none; width: 1.8rem; height: 1.8rem; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  background: var(--on-danger); color: var(--danger); font-weight: 900; font-size: 1.1rem;
  animation: alert-pulse 1.2s ease-in-out infinite;
}
@keyframes alert-pulse { 50% { transform: scale(1.18); } }
.alert-body { flex: 1 1 260px; display: flex; flex-direction: column; min-width: 0; }
.alert-text { font-weight: 800; font-size: 1.05rem; }
.alert-sub { font-size: .9rem; font-weight: 600; opacity: .95; }
.alert-actions { display: flex; gap: .4rem; flex-wrap: wrap; }
.alert-btn { background: var(--on-danger); color: var(--danger); border-color: var(--on-danger); }
.alert-btn:hover:not(:disabled) { border-color: var(--text); }
@media (prefers-reduced-motion: reduce) { .alert-icon { animation: none; } }

/* 登入效期提醒 */
.session-banner {
  position: sticky; top: var(--topbar-h); z-index: 1055;
  display: flex; align-items: center; justify-content: space-between; gap: .6rem 1rem; flex-wrap: wrap;
  background: var(--warn-bg); color: var(--text); border-bottom: 3px solid var(--warn-strong); padding: .55rem 1rem;
}
.session-banner.is-expired { background: var(--danger-bg); border-bottom-color: var(--danger); }
.session-body { display: flex; flex-direction: column; min-width: 0; flex: 1 1 280px; }
.session-sub { font-size: .9rem; color: var(--muted); }
.session-actions { display: flex; gap: .4rem; flex-wrap: wrap; }

/* 主控台：失聯橫幅更醒目 */
.banner-linklost { border-left-width: 8px; font-size: 1.02rem; }
.banner-linklost .banner-icon { animation: alert-pulse 1.2s ease-in-out infinite; }
@media (prefers-reduced-motion: reduce) { .banner-linklost .banner-icon { animation: none; } }

/* 限制值 */
.limits-line {
  margin: .2rem 0 0; font-size: .9rem; font-weight: 600;
  background: var(--surface); border: 1px dashed var(--real); border-radius: 8px; padding: .3rem .6rem;
}
.stat-home.is-near-limit { border-color: var(--warn-strong); background: var(--warn-bg); }
.limit-circle { stroke: var(--real); fill: var(--real); }
.lg-limit { width: 14px; height: 14px; border-radius: 50%; border: 2px dashed var(--real); justify-self: center; }
.target-pin.is-out { border-color: #8a94a3; background: radial-gradient(circle, #8a94a3 0 4px, transparent 5px); animation: none; }
.goto-limit { font-weight: 600; color: var(--real); }
.param-range.is-limited { color: var(--warn); font-weight: 600; }

/* 操作說明：真實機 / 限制值未設定時用警示色 */
.action-note.is-warn { background: var(--warn-bg); border-left: 4px solid var(--warn-strong); }
/* 真實機上需要輸入機號的按鈕：右上角小標示 */
.btn-big.needs-id { position: relative; }
.btn-big.needs-id::after {
  content: attr(data-badge);
  position: absolute; top: .3rem; right: .35rem;
  font-size: .68rem; font-weight: 700; line-height: 1.2; padding: .05rem .4rem; border-radius: 999px;
  background: var(--danger-bg); color: var(--real); border: 1px solid var(--real);
}

/* 真實機的確認視窗 */
.dialog-real { border-top: 10px solid var(--real); box-shadow: 0 0 0 4px color-mix(in srgb, var(--real) 45%, transparent), 0 10px 40px rgba(0,0,0,.35); }
.dialog-real::backdrop { background: rgba(70, 8, 8, .6); }
.dialog-real-strip {
  display: flex; gap: .7rem; align-items: flex-start;
  background: var(--real); color: #fff; border-radius: 10px; padding: .6rem .8rem; margin-bottom: .5rem;
}
[data-theme="dark"] .dialog-real-strip { color: #1a0606; }
.dialog-real-strip strong { font-size: 1.05rem; letter-spacing: .02em; }
.dialog-real-icon {
  flex: none; width: 1.7rem; height: 1.7rem; border-radius: 50%; background: #fff; color: var(--real);
  display: flex; align-items: center; justify-content: center; font-weight: 900;
}
[data-theme="dark"] .dialog-real-icon { background: #1a0606; }
.type-confirm { border: 2px dashed var(--real); border-radius: 10px; padding: .3rem .8rem .5rem; margin-top: .5rem; background: var(--danger-bg); }
.type-confirm-input { font-variant-numeric: tabular-nums; letter-spacing: .15em; font-weight: 800; text-align: center; max-width: 12rem; }

/* 控制權：最近變更 */
.control-last-change { border-top: 1px dashed var(--border); padding-top: .4rem; margin-top: .5rem; }
