*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

:root {
  --bg:       #0d1117;
  --surface:  #161b22;
  --border:   #30363d;
  --text:     #e6edf3;
  --muted:    #8b949e;
  --blue:     #58a6ff;
  --green:    #3fb950;
  --amber:    #d29922;
  --red:      #f85149;
  --teal:     #2dd4bf;
  --purple:   #bc8cff;
  --radius:   8px;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 14px;
}

/* ── Header ── */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  height: 52px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.header-left  { display: flex; align-items: center; gap: 10px; }
.header-right { display: flex; align-items: center; gap: 10px; }
.logo-icon  { font-size: 20px; }
.logo-text  { font-size: 16px; font-weight: 700; letter-spacing: -.02em; }

.btn-back {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 20px;
  cursor: pointer;
  padding: 4px 6px;
  line-height: 1;
  border-radius: var(--radius);
}
.btn-back:hover { color: var(--text); background: var(--surface); }

select, .btn {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  padding: 5px 10px;
  font-size: 13px;
  cursor: pointer;
}
select:hover, .btn:hover { border-color: var(--blue); }

/* ── Overview ── */
#view-overview {
  padding: 24px 20px;
  overflow-y: auto;
  height: calc(100vh - 52px);
}

#overview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

.device-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  cursor: pointer;
  transition: border-color .15s, transform .1s;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.device-card:hover { border-color: var(--blue); transform: translateY(-1px); }

.device-card-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}
.device-name { font-size: 15px; font-weight: 700; letter-spacing: -.01em; }
.device-ts   { font-size: 11px; color: var(--muted); white-space: nowrap; }

.device-pills { display: flex; gap: 10px; }

.pill {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.pill-label { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.pill-value { font-size: 22px; font-weight: 700; line-height: 1.1; }
.pill-unit  { font-size: 12px; font-weight: 400; color: var(--muted); margin-left: 1px; }
.pill-temperature .pill-value { color: var(--red); }
.pill-humidity    .pill-value { color: var(--blue); }

.device-card-footer {
  font-size: 12px;
  color: var(--muted);
  text-align: right;
}
.device-card:hover .device-card-footer { color: var(--blue); }

/* ── Detail view ── */
#view-detail {
  padding: 20px;
  overflow-y: auto;
  height: calc(100vh - 52px);
}

#charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(480px, 1fr));
  gap: 16px;
}

.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.chart-title {
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
}
.chart-wrap { position: relative; height: 200px; }

/* ── Empty state ── */
#empty-msg {
  text-align: center;
  color: var(--muted);
  padding: 80px 20px;
  font-size: 15px;
  line-height: 1.8;
}
#empty-msg code {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 13px;
}

@media (max-width: 600px) {
  #charts-grid { grid-template-columns: 1fr; }
  #overview-grid { grid-template-columns: 1fr; }
  .header-right { gap: 6px; }
  select, .btn { font-size: 12px; padding: 4px 8px; }
}
