:root {
  color-scheme: dark;
  --bg: #09111b;
  --panel: #111d2c;
  --panel-alt: #0d1724;
  --line: #23374d;
  --muted: #8fa3b8;
  --ink: #e8f1fa;
  --green: #3dd598;
  --yellow: #f5b841;
  --red: #ff6b7a;
  --gray: #8a9bb0;
  --blue: #60b8ff;
  --purple: #a855f7;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.5 system-ui, 'Microsoft JhengHei', sans-serif;
}
header {
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #0d1826;
  gap: 12px;
  flex-wrap: wrap;
}
h1 { font-size: 20px; margin: 0; letter-spacing: 0.5px; }
h2 { font-size: 16px; margin: 0 0 10px; }
h3 { font-size: 14px; margin: 0 0 8px; }
small, .muted { color: var(--muted); }

button, input, select {
  font: inherit;
  background: #18283c;
  color: var(--ink);
  border: 1px solid #324a64;
  border-radius: 6px;
  padding: 7px 10px;
  max-width: 100%;
}
button { cursor: pointer; transition: border-color 0.15s, background 0.15s; }
button:hover { border-color: var(--blue); }
button.primary, .tabs .active, .layer-btn.active {
  background: #165682;
  border-color: #5bb0f0;
  color: #fff;
}

.green { color: var(--green); }
.yellow { color: var(--yellow); }
.red { color: var(--red); }
.gray { color: var(--gray); }
.blue { color: var(--blue); }

.toolbar, .between, .tabs {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.between { justify-content: space-between; }

/* 浮動時間播放器 */
.time-bar.is-floating {
  position: fixed;
  right: 20px;
  bottom: 20px;
  width: min(390px, 92vw);
  z-index: 95;
  border: 1px solid #3f6d9b;
  border-radius: 12px;
  padding: 10px 12px;
  background: rgba(13, 24, 38, 0.92);
  backdrop-filter: blur(12px);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.65);
}
.time-bar.is-collapsed {
  width: auto;
  min-width: 245px;
}
.time-bar.is-collapsed .time-bar-body {
  display: none;
}
.time-bar.is-floating .time-bar-head {
  cursor: move;
  user-select: none;
}
.player-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  display: inline-block;
}
.player-dot.paused {
  background: var(--yellow);
}
.mini-btn {
  padding: 2px 8px;
  font-size: 12px;
  line-height: 1.3;
}
.player-controls {
  display: flex;
  gap: 5px;
  margin-top: 8px;
  align-items: center;
  flex-wrap: nowrap;
}
.player-controls button, .player-controls select {
  padding: 5px 8px;
  font-size: 12px;
  white-space: nowrap;
}
.sim-clock {
  color: #7dd3fc;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

/* 主版面 */
.layout {
  display: grid;
  grid-template-columns: 256px minmax(0, 1fr);
  min-height: calc(100vh - 120px);
}
.layout > aside {
  background: #0d1724;
  border-right: 1px solid var(--line);
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
}
.layout > aside input, .layout > aside select { width: 100%; }
#list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding-right: 2px;
}
.machine {
  width: 100%;
  text-align: left;
  margin: 4px 0;
  background: #111d2c;
  border: 1px solid var(--line);
  padding: 8px 10px;
}
.machine.active {
  background: #1b3652;
  border-color: var(--blue);
}
.machine small { display: block; font-size: 12px; }

main { padding: 16px 20px; min-width: 0; }

/* 精簡即時狀態條（合併原重複 KPI） */
.status-strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 14px;
  margin-bottom: 10px;
  font-size: 13px;
}
.status-strip .strip-group {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}
.status-strip b { font-variant-numeric: tabular-nums; }
.panel, .tile {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px;
}
.tile { padding: 10px 12px; }
.tile b { font-size: 22px; display: block; font-variant-numeric: tabular-nums; }
.tile small { font-size: 11px; }

/* 3D 數位孿生視窗區塊 */
.twin-stage-panel {
  padding: 0;
  overflow: hidden;
  margin-bottom: 16px;
  border: 1px solid #2b4560;
}
.twin-topbar {
  background: #0d1826;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}
.layer-nav { display: flex; gap: 6px; flex-wrap: wrap; }
.layer-btn { padding: 7px 12px; font-weight: 600; font-size: 13px; }
.twin-controls { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; font-size: 12px; }
.twin-controls label { display: flex; align-items: center; gap: 6px; }
.twin-controls input[type=range] { width: 100px; accent-color: var(--blue); }

.twin-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  min-height: 450px;
}
.viewport-wrap {
  position: relative;
  height: 450px;
  background: #09111b;
  overflow: hidden;
}
#threeContainer {
  width: 100%;
  height: 100%;
}
#labelLayer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}
.scene-label {
  position: absolute;
  top: 0;
  left: 0;
  padding: 3px 7px;
  border-radius: 5px;
  background: rgba(11, 20, 32, 0.86);
  border: 1px solid #2e4866;
  color: #e8f1fa;
  font-size: 11px;
  white-space: nowrap;
  user-select: none;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.45);
}
.scene-label.active {
  border-color: #60b8ff;
  background: rgba(20, 62, 102, 0.92);
}
.scene-label .dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  margin-right: 4px;
}
.lbl-green { background: var(--green); color: var(--green); }
.lbl-yellow { background: var(--yellow); color: var(--yellow); }
.lbl-red { background: var(--red); color: var(--red); }
.lbl-gray { background: var(--gray); color: var(--gray); }
.lbl-blue { color: var(--blue); }
.lbl-purple { color: var(--purple); }

.viewport-hint {
  position: absolute;
  left: 12px;
  bottom: 10px;
  background: rgba(9, 17, 27, 0.78);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 11px;
  color: var(--muted);
  pointer-events: none;
}

.hud-sidebar {
  background: #0e1928;
  border-left: 1px solid var(--line);
  padding: 14px 14px 130px;
  overflow-y: auto;
  max-height: 450px;
}
.hud-kv {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 10px 0;
}
.hud-kv div {
  background: #142234;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 9px;
}
.hud-kv small { display: block; font-size: 11px; }
.hud-kv b { font-size: 14px; }
.hud-actions { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.hud-box {
  background: #132032;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  margin-top: 10px;
}
.hud-disclaimer {
  margin-top: 10px;
  padding: 7px 9px;
  border-left: 3px solid var(--yellow);
  background: rgba(245, 184, 65, 0.08);
  font-size: 11px;
  color: var(--muted);
}

/* 原有 V9 儀表板區塊 */
.tabs { margin-bottom: 12px; }
.tabs button { padding: 8px 12px; }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }
.info { display: grid; grid-template-columns: 1fr 155px; gap: 16px; }
.facts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; margin-top: 10px; }
.facts div { border-top: 1px solid var(--line); padding-top: 7px; }
.facts b { display: block; }
.counter { font-size: 30px; color: var(--blue); font-weight: 750; font-variant-numeric: tabular-nums; }
.gauge { width: 116px; height: 116px; border-radius: 50%; display: grid; place-items: center; margin: auto; }
.gauge div { width: 94px; height: 94px; background: var(--panel); border-radius: 50%; display: grid; place-content: center; text-align: center; }
.gauge b { font-size: 28px; }
.part { border-bottom: 1px solid var(--line); padding: 9px 0; }
.part .days { font-size: 18px; font-weight: 700; }
.bar { background: #24374b; height: 8px; border-radius: 6px; overflow: hidden; margin: 5px 0; }
.bar i { display: block; background: currentColor; height: 100%; }
.scroll { max-height: 540px; overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th, td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { position: sticky; top: 0; background: var(--panel); color: var(--muted); }
.tablewrap { overflow: auto; }
.link { background: none; border: 0; color: var(--blue); text-decoration: underline; padding: 0; }
.tip { border-left: 3px solid var(--yellow); padding: 8px 12px; background: rgba(245, 184, 65, 0.08); }
details { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin: 8px 0; }
summary { cursor: pointer; font-weight: 700; }
.simcards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 14px 0; }
.actiongrid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
.action { display: block; text-align: left; padding: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; }
.action strong { display: block; font-size: 26px; line-height: 1.4; }
.workgrid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-bottom: 14px; }
.workitem { display: block; width: 100%; text-align: left; background: transparent; border: 0; border-bottom: 1px solid var(--line); border-radius: 0; padding: 10px 0; }
.workitem:hover { background: #1a2d42; }
.regiongrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 10px 0; }
.region { border: 1px solid var(--line); border-radius: 8px; padding: 10px; text-align: left; }
.region b { display: block; font-size: 19px; }
.timeline-row { display: grid; grid-template-columns: 140px minmax(200px, 1fr) 65px; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.track { height: 12px; background: #26394e; position: relative; border-radius: 4px; }
.track i { position: absolute; top: 0; width: 10px; height: 12px; border-radius: 3px; background: currentColor; transform: translateX(-50%); }
.coveragebar { height: 7px; background: #2a4056; border-radius: 4px; position: relative; margin: 5px 0; }
.coveragebar i { display: block; height: 100%; border-radius: 4px; background: currentColor; }
.coveragebar:after { content: ''; position: absolute; left: 75%; top: -2px; height: 11px; border-left: 2px solid #edf5ff; }
.stockvisual { margin: 8px 0; padding: 8px; background: #0c1724; border-radius: 7px; }
.stockvisual .between { font-size: 12px; }
.healthbreak { font-size: 12px; margin-top: 8px; }
.healthbreak div { display: flex; justify-content: space-between; padding: 4px 0; border-bottom: 1px solid var(--line); }

dialog { width: min(900px, 95vw); max-height: 90vh; overflow: auto; background: var(--panel); color: var(--ink); border: 1px solid var(--line); border-radius: 12px; padding: 22px; }
dialog::backdrop { background: rgba(0, 0, 0, 0.75); }
footer { padding: 18px 20px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; }
[hidden] { display: none !important; }

@media (max-width: 1150px) {
  .twin-body { grid-template-columns: 1fr; }
  .hud-sidebar { border-left: 0; border-top: 1px solid var(--line); max-height: none; }
}
@media (max-width: 960px) {
  .layout { grid-template-columns: 1fr; }
  .layout > aside { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  #list { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; max-height: 220px; }
  .kpis { grid-template-columns: repeat(3, 1fr); }
  .split, .workgrid, .actiongrid { grid-template-columns: 1fr; }
  .simcards { grid-template-columns: repeat(2, 1fr); }
}
@media print {
  body { background: white; color: black; }
  header, .time-bar, aside, .twin-stage-panel, .tabs, footer { display: none !important; }
  dialog[open] { position: static; width: 100%; max-height: none; background: white; color: black; border: 0; }
}
