:root {
  color-scheme: dark;
  font-family: Inter, "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  background: #0b1117;
  color: #eef5fb;
  --accent: #f2b84b;
  --accent-soft: rgba(242, 184, 75, 0.16);
  --border: rgba(159, 184, 204, 0.18);
  --muted: #91a6b6;
  --panel: rgba(13, 21, 29, 0.94);
  --positive: #54d2a0;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  background: #0b1117;
}

button {
  font: inherit;
}

.app-shell {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-rows: 68px minmax(0, 1fr);
  background: #0b1117;
}

.topbar {
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-width: 0;
  padding: 0 20px;
  border-bottom: 1px solid var(--border);
  background: #0e161e;
}

.brand-block,
.topbar-status,
.system-state {
  display: flex;
  align-items: center;
}

.brand-block {
  min-width: 0;
  gap: 12px;
}

.brand-mark {
  width: 30px;
  height: 30px;
  flex: 0 0 30px;
  border: 2px solid #66c8e8;
  border-radius: 6px;
  box-shadow: inset 0 0 0 6px rgba(102, 200, 232, 0.12);
}

.eyebrow,
.panel-kicker {
  color: #6f8da1;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0;
}

h1 {
  margin: 3px 0 0;
  overflow: hidden;
  color: #e9f2f8;
  font-size: 17px;
  line-height: 1.15;
  letter-spacing: 0;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-status {
  gap: 10px;
}

.system-state {
  gap: 7px;
  color: #b9d9ca;
  font-size: 12px;
}

.system-state i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--positive);
  box-shadow: 0 0 12px rgba(84, 210, 160, 0.7);
}

.system-clock {
  min-width: 68px;
  color: #aec1cf;
  font-variant-numeric: tabular-nums;
  font-size: 12px;
}

.toolbar-button {
  height: 34px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 5px;
  color: #cbd9e3;
  background: #131e28;
  cursor: pointer;
}

.toolbar-button:hover,
.toolbar-button:focus-visible {
  border-color: rgba(102, 200, 232, 0.58);
  outline: none;
}

.workspace {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.viewer,
.canvas-host,
.canvas-host canvas {
  position: absolute;
  inset: 0;
}

.canvas-host canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.model-status {
  position: absolute;
  left: 146px;
  top: 14px;
  z-index: 2;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 5px;
  color: #9bb0bf;
  background: rgba(11, 17, 23, 0.8);
  font-size: 11px;
}

.zone-legend {
  position: absolute;
  left: 146px;
  bottom: 14px;
  z-index: 2;
  display: flex;
  gap: 14px;
  padding: 8px 11px;
  border: 1px solid var(--border);
  border-radius: 5px;
  color: #9fb1be;
  background: rgba(11, 17, 23, 0.82);
  font-size: 11px;
}

.zone-legend span {
  display: flex;
  align-items: center;
  gap: 6px;
}

.zone-legend i {
  width: 8px;
  height: 8px;
  border-radius: 2px;
}

.zone-a {
  background: #59bce6;
}

.zone-b {
  background: #54d2a0;
}

.sensor-dot {
  border-radius: 50% !important;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
}

.hover-label {
  position: absolute;
  z-index: 7;
  max-width: 220px;
  padding: 7px 10px;
  border: 1px solid var(--accent);
  border-radius: 4px;
  color: #eff6fa;
  background: rgba(8, 13, 18, 0.94);
  pointer-events: none;
  font-size: 11px;
  transform: translate(12px, 12px);
}

.category-rail {
  position: absolute;
  left: 14px;
  top: 14px;
  bottom: auto;
  z-index: 4;
  width: 116px;
  display: grid;
  grid-template-rows: repeat(4, 92px);
  gap: 10px;
}

.category-button {
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: flex-start;
  gap: 5px;
  padding: 13px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: #b9c9d4;
  background: rgba(14, 22, 30, 0.9);
  cursor: pointer;
  text-align: left;
}

.category-button:hover,
.category-button:focus-visible,
.category-button.is-active {
  border-color: var(--accent);
  outline: none;
  background: rgba(18, 29, 39, 0.96);
}

.category-button.is-active {
  box-shadow: inset 3px 0 0 var(--accent);
}

.category-code {
  color: var(--accent);
  font-size: 10px;
  font-weight: 800;
}

.category-button > span:nth-child(2) {
  color: #edf5fa;
  font-size: 14px;
  font-weight: 650;
}

.category-button small {
  color: #7f97a8;
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}

.data-panel {
  position: absolute;
  right: 14px;
  top: 14px;
  bottom: 14px;
  z-index: 4;
  width: min(390px, calc(100vw - 170px));
  overflow: auto;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--panel);
  scrollbar-color: #334958 transparent;
  scrollbar-width: thin;
}

.panel-heading,
.section-heading,
.range-meta,
.zone-row,
.device-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.panel-heading {
  gap: 12px;
  padding-bottom: 15px;
  border-bottom: 1px solid var(--border);
}

.panel-heading h2 {
  margin: 4px 0 0;
  font-size: 20px;
  letter-spacing: 0;
}

.normal-badge {
  flex: 0 0 auto;
  padding: 5px 8px;
  border: 1px solid rgba(84, 210, 160, 0.4);
  border-radius: 4px;
  color: #8be3be;
  background: rgba(84, 210, 160, 0.09);
  font-size: 10px;
}

.primary-reading {
  padding: 18px 0 16px;
}

.primary-reading > span {
  color: var(--muted);
  font-size: 11px;
}

.primary-reading > strong {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
}

.primary-reading b {
  color: #f4f8fb;
  font-size: 38px;
  line-height: 1;
  font-weight: 650;
}

.primary-reading strong small {
  color: var(--accent);
  font-size: 13px;
}

.range-bar,
.zone-bar {
  overflow: hidden;
  border-radius: 2px;
  background: #22303b;
}

.range-bar {
  height: 5px;
  margin-top: 14px;
}

.range-bar i,
.zone-bar i {
  display: block;
  height: 100%;
  background: var(--accent);
  transition: width 450ms ease;
}

.range-meta {
  margin-top: 6px;
  color: #60798a;
  font-size: 9px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  border-top: 1px solid var(--border);
  border-left: 1px solid var(--border);
}

.metric-cell {
  min-width: 0;
  padding: 12px;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.metric-cell span {
  display: block;
  overflow: hidden;
  color: #8198a8;
  font-size: 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.metric-cell strong {
  display: block;
  margin-top: 6px;
  color: #e6f0f6;
  font-size: 18px;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.metric-cell small {
  margin-left: 4px;
  color: #7f98aa;
  font-size: 10px;
}

.trend-section,
.zone-comparison,
.device-section {
  padding-top: 17px;
}

.section-heading h3 {
  margin: 0;
  color: #cad9e3;
  font-size: 12px;
  font-weight: 600;
}

.section-heading span {
  color: var(--accent);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}

.trend-chart {
  width: 100%;
  height: 126px;
  display: block;
  margin-top: 8px;
  overflow: visible;
}

.chart-grid line {
  stroke: rgba(149, 174, 192, 0.13);
  stroke-width: 1;
}

.trend-area {
  fill: var(--accent-soft);
  stroke: none;
}

.trend-line {
  fill: none;
  stroke: var(--accent);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.4;
}

.trend-dot {
  fill: #f5f9fb;
  stroke: var(--accent);
  stroke-width: 2;
}

.chart-axis {
  display: flex;
  justify-content: space-between;
  margin-top: -5px;
  color: #607789;
  font-size: 9px;
}

.zone-row {
  display: grid;
  grid-template-columns: 36px minmax(80px, 1fr) 74px;
  gap: 10px;
  min-height: 34px;
  color: #94a9b8;
  font-size: 10px;
}

.zone-row strong {
  color: #cddbe4;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 550;
}

.zone-bar {
  height: 4px;
}

.device-list {
  margin-top: 8px;
  border-top: 1px solid var(--border);
}

.device-row {
  width: 100%;
  min-height: 38px;
  gap: 10px;
  padding: 0 2px;
  border: 0;
  border-bottom: 1px solid var(--border);
  color: #9fb2bf;
  background: transparent;
  cursor: pointer;
  font-size: 10px;
  text-align: left;
}

.device-row:hover,
.device-row:focus-visible,
.device-row.is-selected {
  color: #eff6fa;
  outline: none;
}

.device-row span:first-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.device-row span:last-child {
  color: var(--positive);
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-rows: 58px minmax(0, 1fr);
  }

  .topbar {
    padding: 0 12px;
  }

  .eyebrow,
  .system-state,
  .system-clock,
  #fullscreen {
    display: none;
  }

  h1 {
    font-size: 14px;
  }

  .brand-mark {
    width: 26px;
    height: 26px;
    flex-basis: 26px;
  }

  .toolbar-button {
    height: 32px;
    padding: 0 9px;
    font-size: 11px;
  }

  .viewer {
    bottom: 46%;
  }

  .category-rail {
    left: 8px;
    right: 8px;
    top: auto;
    bottom: calc(46% + 8px);
    width: auto;
    height: 62px;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    grid-template-rows: 1fr;
  }

  .category-button {
    align-items: center;
    gap: 2px;
    min-width: 0;
    padding: 6px 4px;
    text-align: center;
  }

  .category-button.is-active {
    box-shadow: inset 0 3px 0 var(--accent);
  }

  .category-button > span:nth-child(2) {
    font-size: 11px;
  }

  .category-button small {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .data-panel {
    left: 0;
    right: 0;
    top: 54%;
    bottom: 0;
    width: auto;
    padding: 14px;
    border-width: 1px 0 0;
    border-radius: 0;
  }

  .model-status {
    left: 8px;
    top: 8px;
  }

  .zone-legend {
    display: none;
  }

  .panel-heading {
    padding-bottom: 10px;
  }

  .panel-heading h2 {
    font-size: 17px;
  }

  .primary-reading {
    padding: 12px 0;
  }

  .primary-reading b {
    font-size: 31px;
  }

  .metric-cell {
    padding: 10px;
  }

  .trend-chart {
    height: 105px;
  }
}

@media (max-width: 420px) {
  .brand-block {
    gap: 8px;
  }

  .brand-mark {
    display: none;
  }

  .topbar-status {
    gap: 4px;
  }

  .normal-badge {
    display: none;
  }

  .category-code {
    display: none;
  }
}
