/* HeatVibe — every colour lives here, so one change restyles the whole app. */
:root {
  --accent: #2563EB;
  --ok: #16A34A;
  --alert: #DC2626;
  --off: #98A2B3;
  --bg: #F5F6F8;
  --card: #FFFFFF;
  --text: #1B1F24;
  --muted: #667085;
  --line: #E3E6EA;
  --temp: #EA580C;
  --vib: #2563EB;
  --vib-peak: #93C5FD;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418;
    --card: #1A1F25;
    --text: #E7E9EC;
    --muted: #98A2B3;
    --line: #2A3139;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
a { color: var(--accent); text-decoration: none; }
h1 { font-size: 24px; margin: 8px 0 12px; }
h2 { font-size: 16px; margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
[hidden] { display: none !important; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--card); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; color: var(--text); display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.topbar nav { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; justify-content: flex-end; }
.badge { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; color: #fff; }
.badge.live { background: var(--ok); }
.badge.reconnecting { background: var(--off); }
.inline { display: inline; margin: 0; }
.linkbtn { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; cursor: pointer; }

.wrap { max-width: 1100px; margin: 0 auto; padding: 16px; }

/* ---------- cards and controls ---------- */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 16px; margin-bottom: 14px;
}
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row > label { flex: 1; min-width: 140px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); }
input {
  font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; width: 100%;
}
input[type=checkbox] { width: auto; }
.btn {
  font: inherit; font-weight: 600; border: 0; border-radius: 8px; padding: 10px 16px;
  background: var(--accent); color: #fff; cursor: pointer;
}
.btn.grey { background: var(--line); color: var(--text); }
.btn.danger { background: var(--alert); }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; background: var(--card); border: 1px solid var(--line); }
.flash.error { border-color: var(--alert); color: var(--alert); }
.flash.ok { border-color: var(--ok); }
.flash.key { border-color: var(--accent); word-break: break-all; font-family: ui-monospace, Consolas, monospace; font-size: 13px; }

.pill { font-size: 12px; font-weight: 600; padding: 2px 10px; border-radius: 999px; background: var(--line); color: var(--text); }
.pill.ok { background: var(--ok); color: #fff; }
.pill.alert { background: var(--alert); color: #fff; }
.pill.offline { background: var(--off); color: #fff; }

/* ---------- login ---------- */
.login { max-width: 360px; margin: 8vh auto 0; text-align: center; }
.login img { border-radius: 16px; }
.login h1 { margin-bottom: 0; }
.login form { text-align: left; margin-top: 16px; }

/* ---------- machines (home) ---------- */
.notice { display: flex; align-items: center; justify-content: space-between; gap: 12px; border-color: var(--accent); }
.notice p { margin: 2px 0 0; }
.counts { display: flex; gap: 16px; margin-bottom: 14px; color: var(--muted); }
.counts b { color: var(--text); }
.counts .c-alert b { color: var(--alert); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.mcard {
  display: block; color: var(--text); margin: 0;
  border-left: 5px solid var(--off);
}
.mcard.ok { border-left-color: var(--ok); }
.mcard.alert { border-left-color: var(--alert); }
.mcard .top { display: flex; justify-content: space-between; align-items: start; gap: 8px; }
.mcard .name { font-weight: 700; font-size: 16px; }
.mcard .nums { display: flex; gap: 20px; margin: 12px 0 6px; }
.mcard .nums b { display: block; font-size: 24px; font-variant-numeric: tabular-nums; }
.mcard .nums .hot { color: var(--alert); }
.mcard .unit { font-size: 13px; color: var(--muted); font-weight: 400; }

/* ---------- machine detail ---------- */
.back { display: inline-block; margin-bottom: 4px; }
.titlerow { display: flex; align-items: center; gap: 10px; }
.titlerow h1 { margin-bottom: 4px; }
.tabs { display: inline-flex; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 3px; margin: 8px 0 14px; }
.tabs button { font: inherit; border: 0; background: none; color: var(--text); padding: 6px 14px; border-radius: 6px; cursor: pointer; }
.tabs button.on { background: var(--accent); color: #fff; }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.tile { display: flex; flex-direction: column; gap: 4px; }
.tile b { font-size: 34px; font-variant-numeric: tabular-nums; }
.tile b.hot { color: var(--alert); }
.chart { height: 280px; display: flex; flex-direction: column; }
.chart canvas { flex: 1; min-height: 0; }

/* ---------- admin ---------- */
.tablewrap { overflow-x: auto; }
table.admin { width: 100%; border-collapse: collapse; }
table.admin th, table.admin td { text-align: left; padding: 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.admin th { font-size: 13px; color: var(--muted); font-weight: 600; }
.limits { display: flex; gap: 6px; }
.limits input { width: 90px; }
.actions { white-space: nowrap; }
.members { list-style: none; margin: 0; padding: 0; }
.members li { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }

/* ---------- Windows high-contrast mode: colours are replaced, so mark status by shape too ---------- */
@media (forced-colors: active) {
  .mcard.alert { border-left-style: double; border-left-width: 8px; }
  .mcard.offline { border-left-style: dashed; }
  .pill, .badge { border: 1px solid CanvasText; }
  .tabs button.on { outline: 2px solid Highlight; }
}

/* ---------- phones ---------- */
@media (max-width: 600px) {
  h1 { font-size: 21px; }
  .wrap { padding: 12px; }
  .topbar { flex-wrap: wrap; }
  .topbar nav { gap: 12px; font-size: 14px; }
  .cards { grid-template-columns: 1fr; }
  .tile b { font-size: 28px; }
  .chart { height: 240px; }
  .notice { flex-direction: column; align-items: stretch; }
  /* First-session exercise: make the Admin table rows stack as cards here. */
}
