:root {
  color-scheme: light;
  --bg: #f3f6f8;
  --panel: #ffffff;
  --panel-soft: #eef5f3;
  --text: #17211d;
  --muted: #66756f;
  --line: #d7e2dd;
  --teal: #0f766e;
  --green: #16a34a;
  --amber: #d97706;
  --red: #dc2626;
  --blue: #2563eb;
  --ink: #24312c;
  --shadow: 0 18px 45px rgba(23, 33, 29, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--bg);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background:
    linear-gradient(180deg, rgba(15, 118, 110, 0.09), transparent 380px),
    linear-gradient(90deg, rgba(37, 99, 235, 0.05), rgba(22, 163, 74, 0.04)),
    var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  width: min(1440px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 36px;
}

.topbar,
.control-band,
.reading-panel,
.chart-panel,
.peak-panel {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 88px;
  padding: 18px 20px;
  border-radius: 8px 8px 0 0;
}

.brand {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 14px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(22, 163, 74, 0.96), rgba(37, 99, 235, 0.92)),
    var(--teal);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.35);
  position: relative;
}

.brand-mark::before,
.brand-mark::after {
  content: "";
  position: absolute;
  left: 12px;
  right: 12px;
  border-radius: 999px;
  background: #ffffff;
}

.brand-mark::before {
  top: 13px;
  height: 5px;
}

.brand-mark::after {
  bottom: 13px;
  height: 5px;
}

.brand p,
.brand h1 {
  margin: 0;
}

.brand p,
.field span,
.metric-card span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.brand h1 {
  font-size: 2.35rem;
  line-height: 1.05;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.status-pill,
.device-state {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  border-radius: 999px;
  border: 1px solid var(--line);
  padding: 0 12px;
  color: var(--muted);
  background: #ffffff;
  font-size: 0.86rem;
  font-weight: 750;
  white-space: nowrap;
}

.status-pill.live,
.device-state.online {
  border-color: rgba(22, 163, 74, 0.28);
  color: #14743a;
  background: rgba(22, 163, 74, 0.1);
}

.status-pill.warn {
  border-color: rgba(217, 119, 6, 0.35);
  color: #92400e;
  background: rgba(217, 119, 6, 0.1);
}

.status-pill.error,
.device-state.offline {
  border-color: rgba(220, 38, 38, 0.25);
  color: #991b1b;
  background: rgba(220, 38, 38, 0.08);
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: #ffffff;
  cursor: pointer;
}

.icon-button:hover {
  border-color: rgba(15, 118, 110, 0.35);
  background: var(--panel-soft);
}

.icon {
  display: inline-block;
  position: relative;
  width: 18px;
  height: 18px;
}

.icon.refresh::before {
  content: "↻";
  position: absolute;
  inset: -4px 0 0 -1px;
  font-size: 1.35rem;
  line-height: 1;
}

.icon.pause::before,
.icon.pause::after {
  content: "";
  position: absolute;
  top: 2px;
  width: 5px;
  height: 14px;
  border-radius: 2px;
  background: currentColor;
}

.icon.pause::before {
  left: 3px;
}

.icon.pause::after {
  right: 3px;
}

.icon.play::before {
  content: "";
  position: absolute;
  top: 2px;
  left: 5px;
  width: 0;
  height: 0;
  border-top: 7px solid transparent;
  border-bottom: 7px solid transparent;
  border-left: 10px solid currentColor;
}

.control-band {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(170px, 220px) minmax(130px, 170px);
  gap: 12px;
  padding: 14px 20px 18px;
  border-top: 0;
  border-radius: 0 0 8px 8px;
}

.field {
  display: grid;
  gap: 7px;
  min-width: 0;
}

.field input,
.field select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  color: var(--text);
  background: #ffffff;
  outline: none;
}

.field input:focus,
.field select:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
}

.dashboard {
  display: grid;
  gap: 18px;
  margin-top: 18px;
}

.live-row,
.chart-layout,
.visual-grid {
  display: grid;
  gap: 18px;
}

.live-row {
  grid-template-columns: minmax(320px, 0.88fr) minmax(360px, 1.12fr);
}

.chart-layout {
  grid-template-columns: minmax(0, 1fr) minmax(260px, 340px);
}

.visual-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.reading-panel,
.chart-panel,
.peak-panel {
  min-width: 0;
  border-radius: 8px;
  padding: 18px;
}

.panel-head,
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-head > div {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.muted-label,
.section-head span,
.empty-state span {
  color: var(--muted);
  font-size: 0.9rem;
}

.section-head {
  margin-bottom: 14px;
}

.section-head h2 {
  margin: 0;
  font-size: 1.12rem;
}

#lastSeenLabel {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.gauge-wrap {
  display: grid;
  justify-items: center;
  margin: 16px 0 14px;
}

.gauge {
  --level: 0;
  --gauge-color: var(--teal);
  display: grid;
  place-items: center;
  width: min(300px, 78vw);
  aspect-ratio: 1;
  border-radius: 50%;
  background:
    radial-gradient(circle at center, #ffffff 0 56%, transparent 57%),
    conic-gradient(var(--gauge-color) calc(var(--level) * 1%), #e2e8e4 0);
  box-shadow: inset 0 0 0 1px rgba(23, 33, 29, 0.08), 0 18px 40px rgba(23, 33, 29, 0.08);
}

.gauge-core {
  display: grid;
  place-items: center;
  width: 62%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: inset 0 0 0 1px var(--line);
}

.gauge-core span {
  font-size: 5.15rem;
  font-weight: 850;
  line-height: 0.9;
  letter-spacing: 0;
}

.gauge-core small {
  color: var(--muted);
  font-size: 1rem;
  font-weight: 800;
}

.scale-row {
  display: flex;
  justify-content: space-between;
  width: min(300px, 78vw);
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

canvas {
  display: block;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, #ffffff, #f8fbfa);
}

.spark-canvas {
  height: 128px;
}

.trend-canvas {
  height: 420px;
}

.meter-canvas,
.distribution-canvas {
  height: 240px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.metric-card {
  display: grid;
  align-content: space-between;
  min-height: 112px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #ffffff;
}

.metric-card strong {
  font-size: 2.02rem;
  line-height: 1.05;
}

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

.peak-list li {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  background: #ffffff;
}

.peak-list time {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 750;
}

.peak-list strong {
  font-size: 1.1rem;
}

.devices-panel {
  min-width: 0;
  padding: 4px 0 0;
}

.empty-state {
  display: grid;
  gap: 4px;
  min-height: 108px;
  place-items: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.6);
  text-align: center;
}

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

.device-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.device-card {
  display: grid;
  gap: 12px;
  min-width: 0;
  min-height: 178px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #ffffff;
  cursor: pointer;
  outline: none;
}

.device-card:hover,
.device-card:focus-visible,
.device-card.selected {
  border-color: rgba(15, 118, 110, 0.45);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}

.device-card header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
}

.device-card header strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.device-dot {
  width: 11px;
  height: 11px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--muted);
}

.device-dot.online {
  background: var(--green);
}

.device-dot.warn {
  background: var(--amber);
}

.device-reading {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.device-reading span {
  font-size: 2.5rem;
  font-weight: 850;
  line-height: 1;
}

.device-reading small,
.device-card dt {
  color: var(--muted);
  font-weight: 800;
}

.device-card dl {
  display: grid;
  gap: 8px;
  margin: 0;
}

.device-card dl div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
}

.device-card dt,
.device-card dd {
  margin: 0;
  font-size: 0.86rem;
}

.device-card dd {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 800;
}

@media (max-width: 1080px) {
  .live-row,
  .chart-layout,
  .visual-grid {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 760px) {
  .app-shell {
    width: min(100% - 20px, 1440px);
    padding-top: 10px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .top-actions {
    width: 100%;
    justify-content: flex-end;
  }

  .control-band {
    grid-template-columns: 1fr;
  }

  .trend-canvas {
    height: 330px;
  }
}

@media (max-width: 520px) {
  .topbar,
  .control-band,
  .reading-panel,
  .chart-panel,
  .peak-panel,
  .devices-panel {
    padding-left: 12px;
    padding-right: 12px;
  }

  .brand h1 {
    font-size: 1.55rem;
  }

  .gauge-core span {
    font-size: 3.7rem;
  }

  .metric-grid {
    grid-template-columns: 1fr;
  }

  .metric-card {
    min-height: 92px;
  }

  .metric-card strong {
    font-size: 1.72rem;
  }
}
