:root {
  color-scheme: light;
  --ink: #24302f;
  --muted: #687471;
  --paper: #fffefa;
  --canvas: #e9e5dc;
  --page: #f4f1e9;
  --line: #d4d0c6;
  --line-strong: #aaa79f;
  --green: #4f816b;
  --amber: #c58b2d;
  --red: #b5463d;
  --offline: #68737c;
  --maintenance: #527b93;
  --focus: #166c86;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 0;
  background: var(--page);
}

body {
  min-width: 0;
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  color: var(--ink);
  background: var(--page);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", sans-serif;
}

html.embed,
html.embed body {
  min-height: 0;
  background: var(--page);
}

html.embed .site-header,
html.embed .data-chain,
html.embed .layout-note,
html.embed footer {
  display: none;
}

html.embed .page-shell {
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 0;
}

button,
summary {
  font: inherit;
}

a {
  color: inherit;
}

button,
a,
summary,
canvas {
  outline-offset: 3px;
}

button:focus-visible,
a:focus-visible,
summary:focus-visible,
canvas:focus-visible {
  outline: 3px solid var(--focus);
}

.skip-link {
  position: fixed;
  z-index: 20;
  top: 8px;
  left: 8px;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(100%);
  padding: 0;
  border: 0;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
}

.skip-link:focus-visible {
  width: auto;
  height: auto;
  overflow: visible;
  clip-path: none;
  padding: 9px 12px;
  border: 1px solid var(--ink);
  background: var(--paper);
  opacity: 1;
  pointer-events: auto;
}

.site-header,
.page-shell,
footer {
  width: min(1480px, calc(100% - 40px));
  margin-inline: auto;
}

.site-header {
  padding: 28px 0 18px;
}

.brand-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
}

.eyebrow,
.section-kicker {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .14em;
  text-decoration: none;
}

h1,
h2,
p {
  overflow-wrap: anywhere;
}

h1 {
  margin: 7px 0 0;
  font-size: clamp(28px, 4vw, 45px);
  line-height: 1;
  letter-spacing: -.035em;
}

.brand-row p {
  margin: 9px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.read-only-badge {
  flex: 0 0 auto;
  padding: 7px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  color: var(--muted);
  background: var(--paper);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .08em;
}

.data-chain {
  margin-top: 24px;
  padding: 12px 15px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--ink);
  background: var(--paper);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.layout-note {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
}

.page-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 360px);
  gap: 16px;
  align-items: start;
}

.map-card,
.details-card {
  min-width: 0;
  border: 1px solid var(--line);
  background: var(--paper);
}

.map-head,
.details-head {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 17px 18px;
  border-bottom: 1px solid var(--line);
}

.map-head h2,
.details-head h2 {
  margin: 4px 0 0;
  font-size: 18px;
  line-height: 1.2;
}

.live-meta {
  min-width: 0;
  display: grid;
  grid-template-columns: auto minmax(0, auto);
  align-items: center;
  justify-items: end;
  column-gap: 7px;
  color: var(--muted);
  font-size: 12px;
  text-align: right;
}

.live-meta time {
  grid-column: 2;
  margin-top: 3px;
  color: #818a87;
  font-variant-numeric: tabular-nums;
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
}

.object-selector {
  min-height: 48px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px;
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
  background: #f8f7f2;
}

.selector-button {
  min-width: 0;
  max-width: 100%;
  padding: 6px 9px;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  color: var(--ink);
  background: var(--paper);
  cursor: pointer;
  font-size: 12px;
  font-weight: 720;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.selector-button.device {
  color: var(--muted);
  border-style: dashed;
}

.selector-button[aria-pressed="true"] {
  color: #fff;
  border-color: var(--ink);
  background: var(--ink);
}

.viewport-shell {
  position: relative;
  min-width: 0;
  height: clamp(430px, 63vh, 700px);
  overflow: hidden;
  background: var(--canvas);
}

#plant-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
}

#plant-canvas:active {
  cursor: grabbing;
}

.loading-state {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 20px;
  color: var(--muted);
  background: var(--canvas);
  font-size: 13px;
}

.loading-state[hidden] {
  display: none;
}

.loading-mark {
  width: 12px;
  height: 12px;
  border: 2px solid var(--line-strong);
  border-top-color: var(--ink);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

.canvas-hint {
  position: absolute;
  right: 10px;
  bottom: 10px;
  max-width: calc(100% - 20px);
  margin: 0;
  padding: 6px 8px;
  border: 1px solid rgba(71, 78, 75, .22);
  color: #4d5754;
  background: rgba(255, 254, 250, .9);
  font-size: 11px;
}

.control-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.control-group {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.icon-button {
  width: 38px;
  height: 38px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  color: var(--ink);
  background: var(--paper);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
}

.icon-button:hover {
  background: #eeece5;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 9px 18px;
  padding: 12px 14px;
  color: var(--muted);
  font-size: 11px;
}

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

.legend-swatch {
  width: 10px;
  height: 10px;
  display: inline-block;
  border: 1px solid rgba(0, 0, 0, .13);
  border-radius: 2px;
}

.legend-swatch.normal { background: var(--green); }
.legend-swatch.warning { background: var(--amber); }
.legend-swatch.critical { background: var(--red); }
.legend-swatch.offline { background: var(--offline); }
.legend-swatch.maintenance { background: var(--maintenance); }

.fallback-panel {
  margin: 0;
  border-top: 1px solid var(--line);
  background: #fbfaf6;
}

.fallback-panel summary {
  padding: 12px 15px;
  cursor: pointer;
  color: var(--ink);
  font-size: 12px;
  font-weight: 760;
}

.fallback-panel > p {
  margin: 0;
  padding: 0 15px 10px;
  color: var(--muted);
  font-size: 12px;
}

.fallback-list {
  display: grid;
  gap: 9px;
  padding: 0 15px 15px;
}

.fallback-line {
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  background: var(--paper);
}

.fallback-line h3 {
  margin: 0 0 7px;
  font-size: 13px;
}

.fallback-line p,
.fallback-line li {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.fallback-line ul {
  margin: 7px 0 0;
  padding-left: 18px;
}

.details-card {
  position: sticky;
  top: 12px;
}

.details-head {
  align-items: flex-start;
}

.status-pill {
  flex: 0 0 auto;
  max-width: 130px;
  padding: 5px 8px;
  border: 1px solid currentColor;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .04em;
  text-align: center;
}

.status-pill.normal { color: #3f735d; background: #f2f8f4; }
.status-pill.warning { color: #95651a; background: #fff8e9; }
.status-pill.critical { color: #a43831; background: #fff2f0; }
.status-pill.offline { color: #59636a; background: #f1f3f4; }
.status-pill.maintenance { color: #3e6981; background: #f0f7fa; }
.status-pill.neutral { color: #69716f; background: #f6f5f1; }

.details-content {
  min-width: 0;
  padding: 18px;
}

.selection-title {
  margin: 0;
  font-size: 23px;
  line-height: 1.12;
  letter-spacing: -.025em;
}

.selection-name {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.metric-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px;
  margin: 18px 0 0;
  padding: 1px;
  background: var(--line);
}

.metric-list div {
  min-width: 0;
  padding: 11px;
  background: var(--paper);
}

.metric-list dt {
  color: var(--muted);
  font-size: 10px;
  font-weight: 760;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.metric-list dd {
  margin: 5px 0 0;
  font-size: 14px;
  font-weight: 740;
  overflow-wrap: anywhere;
}

.alarm-section {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.alarm-section h3 {
  margin: 0 0 10px;
  font-size: 13px;
}

.alarm-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.alarm-item {
  padding: 10px;
  border-left: 3px solid var(--amber);
  background: #fbf8f0;
}

.alarm-item.critical {
  border-left-color: var(--red);
  background: #fff5f3;
}

.alarm-item.normal {
  border-left-color: var(--green);
  background: #f4f8f5;
}

.alarm-item.offline {
  border-left-color: var(--offline);
  background: #f2f3f4;
}

.alarm-item.maintenance {
  border-left-color: var(--maintenance);
  background: #f1f7f9;
}

.alarm-code {
  min-width: 0;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.alarm-item p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.5;
}

.empty-state,
.no-alarms {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

footer {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 0 28px;
  color: var(--muted);
  font-size: 11px;
}

.noscript-note {
  margin: 12px;
  padding: 12px;
  border: 1px solid var(--red);
  background: var(--paper);
}

.map-card:fullscreen,
.map-card:-webkit-full-screen {
  width: 100vw;
  height: 100vh;
  overflow-y: auto;
  background: var(--canvas);
}

.map-card:fullscreen .viewport-shell,
.map-card:-webkit-full-screen .viewport-shell {
  height: calc(100vh - 230px);
  min-height: 360px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@media (max-width: 980px) {
  .page-shell {
    grid-template-columns: minmax(0, 1fr);
  }

  .details-card {
    position: static;
  }

  .viewport-shell {
    height: min(64vh, 590px);
    min-height: 410px;
  }
}

@media (max-width: 560px) {
  .site-header,
  .page-shell,
  footer {
    width: min(100% - 20px, 1480px);
  }

  .site-header {
    padding-top: 20px;
  }

  .brand-row {
    gap: 10px;
  }

  .read-only-badge {
    padding: 5px 7px;
  }

  .data-chain {
    margin-top: 18px;
    padding: 10px;
    font-size: 10px;
  }

  .map-head,
  .details-head {
    align-items: flex-start;
    padding: 14px;
  }

  .map-head {
    display: grid;
  }

  .live-meta {
    justify-items: start;
    text-align: left;
  }

  .viewport-shell {
    height: 430px;
    min-height: 0;
  }

  .control-row {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .control-group {
    flex: 1 1 auto;
  }

  .icon-button {
    width: 36px;
    height: 36px;
  }

  .canvas-hint {
    left: 8px;
    right: 8px;
    text-align: center;
  }

  .details-content {
    padding: 14px;
  }

  footer {
    flex-direction: column;
    gap: 5px;
  }
}

@media (max-width: 350px) {
  .site-header,
  .page-shell,
  footer {
    width: calc(100% - 14px);
  }

  .object-selector {
    padding-inline: 8px;
  }

  .selector-button {
    max-width: 145px;
  }

  .legend {
    gap: 7px 10px;
    padding-inline: 10px;
  }

  .metric-list {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
}
