:root {
  color-scheme: light;
  --paper: #faf8f2;
  --panel: #fffefa;
  --shell: #f6f3e7;
  --line: #e8dfca;
  --ink: #332d25;
  --muted: #6e6658;
  --brown: #594a3a;
  --green: #37634e;
  --green-light: #e8f0e9;
  --red: #8b4237;
  --serif: 'Noto Serif SC Variable', 'Songti SC', SimSun, serif;
  --sans: 'Noto Sans SC Variable', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  --radius: 0;
  --rail: 72px;
  background: var(--paper);
  color: var(--ink);
  font: 400 14px/1.55 var(--sans);
  font-synthesis: none;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body, h1, h2, p, ul { margin: 0; }
ul { padding: 0; list-style: none; }
a { color: inherit; text-decoration: none; }
button, input { font: inherit; }
button { color: inherit; cursor: pointer; }
button:disabled { cursor: wait; opacity: .66; }
:focus-visible { outline: 2px solid var(--green); outline-offset: 3px; }
html { scroll-padding: 20px; }
h1 { font: 800 28px/1.3 var(--serif); }
h2 { font: 800 16px/1.4 var(--serif); }
.muted { color: var(--muted); }
button svg, .rail-item svg, .metric-header svg {
  display: block;
  width: 18px;
  height: 18px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.outline-button, .primary-button, .quiet-button {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  min-height: 36px;
  padding: 6px 12px;
  font-weight: 600;
  background: var(--shell);
}
.outline-button:hover, .quiet-button:hover { background: #eee9da; }
.outline-button { display: inline-flex; align-items: center; gap: 6px; }
.primary-button { background: var(--brown); color: #fffefa; border-color: var(--brown); }
.primary-button:hover { background: #443628; }
.quiet-button { background: transparent; border-color: transparent; color: var(--muted); }

.dashboard-page {
  min-height: 100vh;
  padding-inline-start: var(--rail);
  background: linear-gradient(180deg, #f6f1e4 0, var(--paper) 250px);
}
.rail {
  position: fixed;
  z-index: 5;
  inset: 0 auto auto 0;
  width: var(--rail);
  background: #faf7ed;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 12px 11px 16px;
  overflow: hidden;
  max-height: 100vh;
  transition: width .18s ease, box-shadow .18s ease;
}
.rail:hover, .rail:has(:focus-visible) {
  width: 192px;
  box-shadow: 8px 12px 25px #483b2314;
  overflow-y: auto;
}
.rail-brand, .rail-item { display: flex; align-items: center; white-space: nowrap; }
.rail-brand { gap: 10px; padding: 5px 6px 15px; }
.rail-brand-name { font: 800 20px var(--serif); }
.rail-item { gap: 13px; padding: 0 13px; min-height: 45px; color: var(--muted); border: 1px solid transparent; }
.rail-item + .rail-item { margin-top: 4px; }
.rail-item span, .rail-brand-name { opacity: 0; }
.rail:hover span, .rail:has(:focus-visible) span { opacity: 1; }
.rail-item:hover { background: var(--shell); }
.rail-item.is-active {
  color: var(--brown);
  background: #f1ead9;
  border-color: #e9deca;
  font-weight: 600;
}
.rail-item svg { width: 22px; height: 22px; }

.topbar { background: #faf7ed; border-bottom: 1px solid var(--line); }
.topbar-inner {
  max-width: 888px;
  margin: auto;
  min-height: 58px;
  padding-inline: 24px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.topbar-title { font-weight: 600; }
.topbar-brand { display: none; }
.logout-form { margin-inline-start: auto; }

.dashboard { max-width: 888px; margin: auto; padding: 29px 24px 44px; }
.overview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px 24px;
  margin-bottom: 20px;
}
.overview-date { color: var(--muted); margin-top: 6px; }
.head-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; justify-content: flex-end; }
.sample-badge {
  padding: 4px 8px;
  color: #635027;
  background: #f6efd8;
  border: 1px solid #e9ddbd;
  font-weight: 600;
  white-space: nowrap;
}
.sample-badge.is-live { background: var(--green-light); color: var(--green); border-color: #d9e5dc; }
.update-time { min-width: 100%; text-align: end; color: var(--muted); font-variant-numeric: tabular-nums; }
.connection-error { border: 1px solid #d6a69b; background: #fcf0eb; color: var(--red); padding: 10px 13px; margin-bottom: 16px; }

.metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 20px; }
.metric {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 13px 14px 12px;
  background: var(--panel);
}
.metric-visitor { border-top: 3px solid var(--brown); padding-top: 11px; }
.metric-health { background: #eff3ea; border-color: #dbe5d8; }
.metric-header { display: flex; gap: 4px; justify-content: space-between; align-items: center; }
.metric-header h2 { font: 600 14px/1.4 var(--sans); }
.metric-header svg { color: #7d705b; }
.metric-value { display: flex; align-items: baseline; gap: 7px; margin-top: 9px; }
.metric-value strong { font: 800 24px/1.2 var(--serif); font-variant-numeric: lining-nums tabular-nums; }
.metric-value span { color: var(--muted); }
.metric-health .metric-value strong, .metric-health .metric-header svg { color: var(--green); }
.metric-health.has-error .metric-value strong, .metric-health.has-error .metric-header svg { color: var(--red); }
.metric-note { margin-top: 7px; color: var(--muted); }

.panel { min-width: 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
.trend-panel { margin-bottom: 20px; }
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  padding: 16px;
}
.panel-context { color: var(--muted); white-space: nowrap; }
.trend-head { flex-wrap: wrap; padding-bottom: 10px; }
.segmented {
  display: inline-flex;
  align-items: stretch;
  padding: 3px;
  border: 1px solid var(--line);
  background: var(--shell);
}
.segmented button, .metric-switch button {
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
  min-height: 34px;
  padding-inline: 9px;
}
.segmented button:hover, .metric-switch button:hover { color: var(--ink); background: #eee9dc; }
.segmented button[aria-pressed="true"] { background: var(--panel); border-color: var(--line); color: var(--ink); font-weight: 600; }
.chart-controls { display: flex; align-items: center; justify-content: space-between; padding: 0 16px; gap: 4px 8px; }
.metric-switch { display: flex; flex-wrap: wrap; gap: 3px; }
.metric-switch button { padding-inline: 8px; }
.metric-switch button[aria-pressed="true"] {
  color: var(--green);
  background: var(--green-light);
  border-color: #d9e5dc;
  font-weight: 600;
}
.chart-frame { position: relative; padding: 8px 16px 0; }
#trend-chart { display: block; width: 100%; height: 225px; }
.chart-tooltip {
  position: absolute;
  z-index: 1;
  padding: 6px 9px;
  background: #3e372d;
  color: #fffefa;
  box-shadow: 0 4px 12px #30271c25;
  pointer-events: none;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.chart-footer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 10px;
  padding: 10px 16px 15px;
  border-top: 1px solid #efe8d7;
}
.chart-footer:has(details[open]) { grid-template-columns: 1fr; }
.chart-footer summary { color: var(--brown); font-weight: 600; cursor: pointer; width: max-content; }
.chart-footer summary:hover { text-decoration: underline; text-underline-offset: 3px; }
.table-wrap { max-height: 210px; overflow: auto; margin-top: 8px; }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th, td { text-align: right; padding: 7px 8px; border-bottom: 1px solid #efe8d7; }
th:first-child, td:first-child { text-align: left; }
th { font-weight: 600; background: var(--shell); }

.detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.detail-panel .panel-head { border-bottom: 1px solid var(--line); }
.check-list, .resource-list, .device-list { padding-inline: 16px; }
.check-item {
  display: grid;
  grid-template-columns: 12px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  padding: 10px 0;
}
.check-item + .check-item, .device-item + .device-item { border-top: 1px solid #efe8d7; }
.status-dot, .device-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #47745e;
}
.status-dot.has-error { background: var(--red); }
.check-name { font-weight: 600; }
.check-extra { color: var(--muted); }
.check-status { color: var(--green); font-weight: 600; }
.check-status.has-error { color: var(--red); }
.check-reading { text-align: end; font-variant-numeric: tabular-nums; }
.error-summary {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-inline: 16px;
  padding-block: 10px;
  border-top: 1px solid #efe8d7;
  color: var(--muted);
}
.error-summary strong { color: var(--ink); }
.resource-list { padding-block: 8px 12px; }
.resource-item { padding-block: 4px; }
.resource-row { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.resource-name, .resource-value { font-weight: 600; }
.resource-value { font-variant-numeric: tabular-nums; }
.resource-meta { color: var(--muted); }
.resource-track { display: block; height: 4px; margin-top: 4px; background: #eee8d8; }
.resource-fill { display: block; height: 100%; background: #6c8b77; }
.device-strip { display: flex; gap: 3px; height: 7px; margin: 16px 16px 6px; }
.device-item { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding-block: 7px; }
.device-name { display: flex; gap: 8px; align-items: center; }
.tone-green { background: #527965; }
.tone-brown { background: #8b7357; }
.tone-tan { background: #c8aa77; }
.version-table th, .version-table td { padding-inline: 16px; }
.version-table th:nth-child(n+2), .version-table td:nth-child(n+2) { padding-inline: 5px; }
.version-table th:last-child, .version-table td:last-child { padding-right: 16px; }
.panel-empty { padding: 12px 16px; }

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
  background: linear-gradient(165deg, #f3ebda, var(--paper) 65%);
}
.login-panel { width: min(420px, 100%); padding: 26px; border: 1px solid var(--line); background: var(--panel); }
.login-panel img { display: block; border: 1px solid var(--line); margin-bottom: 14px; }
.login-panel p { margin-top: 8px; }
.login-panel form { display: grid; gap: 9px; margin-top: 20px; }
.login-panel label { font-weight: 600; }
.login-panel input { width: 100%; min-height: 42px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; padding: 7px 9px; color: var(--ink); }
.login-panel .primary-button { margin-top: 5px; min-height: 42px; }
.login-panel .login-error { color: var(--red); margin: 0; }

@media (max-width: 900px) {
  html { scroll-padding-bottom: calc(72px + env(safe-area-inset-bottom)); }
  .dashboard-page { padding-inline-start: 0; }
  .rail, .rail:hover, .rail:has(:focus-visible) {
    inset: auto 0 0;
    width: 100%;
    padding: 0 12px env(safe-area-inset-bottom);
    border: 0;
    border-top: 1px solid var(--line);
    box-shadow: 0 -3px 12px #483b230b;
  }
  .rail-brand { display: none; }
  .rail nav { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .rail-item { flex-direction: column; justify-content: center; gap: 3px; min-height: 56px; padding: 6px 3px; }
  .rail-item + .rail-item { margin-top: 0; }
  .rail-item span { opacity: 1; }
  .rail-item.is-active { border-color: transparent; }
  .topbar-brand { display: inline-flex; align-items: center; gap: 6px; font: 800 20px var(--serif); }
  .topbar-title { border-left: 1px solid var(--line); padding-left: 10px; color: var(--muted); }
  .dashboard { padding-bottom: calc(80px + env(safe-area-inset-bottom)); }
}

@media (max-width: 600px) {
  .topbar-inner { gap: 7px; padding-inline: 12px; }
  .topbar-brand img { display: none; }
  .quiet-button { padding-inline: 5px; }
  .dashboard { padding-inline: 12px; padding-top: 19px; }
  .overview-head { gap: 12px; margin-bottom: 14px; }
  .head-controls { width: 100%; justify-content: flex-start; }
  .update-time { min-width: 0; text-align: start; margin-left: auto; }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-bottom: 14px; }
  .metric { padding-inline: 10px; }
  .trend-panel { margin-bottom: 14px; }
  .panel-head { padding-inline: 12px; }
  .trend-head { align-items: flex-start; }
  .chart-controls, .chart-footer { padding-inline: 10px; }
  .chart-frame { padding-inline: 7px; }
  #trend-chart { height: 196px; }
  .detail-grid { grid-template-columns: 1fr; gap: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .rail { transition: none; }
}
