/* =====================================================================
   Solar Monitor web app: look and feel
   Colours are set once here as "tokens" and used everywhere by name.
   Dark mode follows the phone's setting.
   ===================================================================== */

:root {
  color-scheme: light;
  --bg:            #f3f4f6;
  --surface:       #ffffff;
  --border:        #e2e4e8;
  --text:          #0b0b0b;
  --text-2:        #52514e;
  --text-3:        #7a7975;
  --brand:         #9c3631;   /* WarDew brick red (from the logo) */
  --series:        #2a78d6;   /* power line, string bars */
  --grid:          #e9e9e6;

  /* status colours: always shown with an icon + word, never colour alone */
  --good:          #0ca30c;
  --warning:       #fab219;
  --critical:      #d03b3b;
  --good-bg:       #e7f6e7;
  --warning-bg:    #fff4dc;
  --critical-bg:   #fbe7e7;

  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg:          #111111;
    --surface:     #1a1a19;
    --border:      #2c2c2a;
    --text:        #ffffff;
    --text-2:      #c3c2b7;
    --text-3:      #8f8e86;
    --brand:       #9c3631;
    --series:      #3987e5;
    --grid:        #2c2c2a;
    --good-bg:     #12301a;
    --warning-bg:  #3a2e0c;
    --critical-bg: #3c1616;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.4;
}

[hidden] { display: none !important; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--brand); color: #fff;
}
.brand { display: flex; align-items: center; }
.brand-logo { height: 40px; width: auto; display: block; }
.topbar-right { display: flex; align-items: center; gap: 8px; font-size: .9rem; }
.site-name { font-weight: 600; white-space: nowrap; }
.login-logo { display: block; width: 100%; max-width: 300px; margin: 0 auto 18px; border-radius: 10px; }
.btn-link { background: none; border: 0; color: inherit; font: inherit; text-decoration: underline; cursor: pointer; padding: 6px; }

/* ---------- layout ---------- */
.view { max-width: 720px; margin: 0 auto; padding: 16px 16px 40px; }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; margin-bottom: 14px;
}
h1 { font-size: 1.4rem; margin: 0 0 8px; }
h2 { font-size: 1.05rem; margin: 22px 0 10px; color: var(--text-2); font-weight: 600; }
.muted { color: var(--text-2); }
.small { font-size: .85rem; color: var(--text-3); }
.error { color: var(--critical); min-height: 1.2em; }

/* ---------- login ---------- */
.login-card { max-width: 380px; margin: 40px auto; }
.login-card label { display: block; margin: 14px 0 0; font-size: .9rem; color: var(--text-2); }
.login-card input {
  display: block; width: 100%; margin-top: 6px; padding: 12px;
  font-size: 1rem; border-radius: 10px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text);
}
.btn-primary {
  margin-top: 18px; width: 100%; padding: 13px; font-size: 1rem; font-weight: 600;
  border: 0; border-radius: 10px; background: var(--series); color: #fff; cursor: pointer;
}
.btn-primary:disabled { opacity: .6; }

/* ---------- site status banner ---------- */
.banner {
  display: flex; align-items: center; gap: 12px;
  border-radius: var(--radius); padding: 16px; margin-bottom: 14px; border: 1px solid;
}
.banner .icon { font-size: 1.8rem; line-height: 1; }
.banner .title { font-weight: 700; font-size: 1.15rem; }
.banner.ok   { background: var(--good-bg);     border-color: var(--good); }
.banner.bad  { background: var(--critical-bg); border-color: var(--critical); }

/* ---------- alarms ---------- */
.alarm {
  display: flex; gap: 12px; align-items: flex-start;
  border-left: 5px solid var(--warning);
}
.alarm.critical { border-left-color: var(--critical); }
.alarm.cleared  { border-left-color: var(--text-3); opacity: .8; }
.alarm .body { flex: 1; min-width: 0; }
.alarm .what { font-weight: 600; }
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .03em;
  padding: 2px 8px; border-radius: 999px; margin-bottom: 4px;
}
.badge.critical { background: var(--critical-bg); color: var(--text); border: 1px solid var(--critical); }
.badge.warning  { background: var(--warning-bg);  color: var(--text); border: 1px solid var(--warning); }
.badge.info, .badge.cleared { background: var(--bg); color: var(--text-2); border: 1px solid var(--border); }
.btn-ack {
  flex: none; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--series);
  background: transparent; color: var(--series); font-weight: 600; cursor: pointer;
}
.acked { font-size: .85rem; color: var(--text-3); white-space: nowrap; }
.empty { text-align: center; color: var(--text-2); }
details summary { cursor: pointer; color: var(--text-2); margin: 18px 0 10px; }

/* ---------- combiner cards ---------- */
a.combiner { display: block; color: inherit; text-decoration: none; }
.combiner .row1 { display: flex; justify-content: space-between; align-items: baseline; }
.combiner .name { font-weight: 700; font-size: 1.1rem; }
.combiner .chev { color: var(--text-3); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.stat .label { font-size: .78rem; color: var(--text-3); }
.stat .value { font-size: 1.25rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .unit  { font-size: .85rem; font-weight: 500; color: var(--text-2); }
.pill { display: inline-flex; gap: 4px; align-items: center; font-size: .85rem; margin-top: 10px; }

/* ---------- combiner detail ---------- */
.back { display: inline-block; margin-bottom: 10px; color: var(--series); text-decoration: none; font-weight: 600; }
.strings { display: grid; gap: 8px; }
.string-row { display: grid; grid-template-columns: 70px 1fr 82px; gap: 10px; align-items: center; }
.string-row .lbl { font-size: .9rem; color: var(--text-2); }
.string-row .track { display: block; height: 14px; background: var(--grid); border-radius: 4px; overflow: hidden; }
.string-row .fill { display: block; height: 100%; background: var(--series); border-radius: 0 4px 4px 0; }
.string-row.low .fill   { background: var(--warning); }
.string-row.fuse .fill  { background: var(--critical); }
.string-row .val { text-align: right; font-variant-numeric: tabular-nums; font-size: .9rem; }
.string-row .flag { display: block; font-size: .72rem; font-weight: 700; }
.string-row.unused { opacity: .45; }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; }
.kv div:nth-child(odd) { color: var(--text-2); }
.kv div:nth-child(even) { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- chart ---------- */
.chart-wrap { position: relative; }
.chart-wrap svg { display: block; width: 100%; height: auto; overflow: visible; touch-action: pan-y; }
.chart-wrap .axis text { fill: var(--text-3); font-size: 11px; }
.chart-wrap .gridline { stroke: var(--grid); stroke-width: 1; }
.chart-wrap .line { fill: none; stroke: var(--series); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart-wrap .cross { stroke: var(--text-3); stroke-width: 1; }
.chart-wrap .dot { fill: var(--series); stroke: var(--surface); stroke-width: 2; }
.tooltip {
  position: absolute; pointer-events: none; transform: translate(-50%, -110%);
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 10px; font-size: .85rem; white-space: nowrap;
  box-shadow: 0 4px 12px rgba(0,0,0,.15);
}
.tooltip b { font-variant-numeric: tabular-nums; }
