/* DATABRIDGE dashboard.
 *
 * Written for a phone held in a plant room, in daylight, by someone wearing
 * gloves: big targets, high contrast, no hover-only affordances.
 *
 * Colours are the validated eight-slot categorical palette plus its chrome and
 * status roles. Dark mode is a selected set of steps for the dark surface, not
 * an inversion, and the theme toggle wins over the OS setting in both
 * directions.
 */

:root {
  color-scheme: light;
  --surface-1: #fcfcfb;
  --surface-2: #f9f9f7;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --ink-muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);

  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #4a3aa7;
  --series-8: #e34948;

  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --good-text: #006300;

  --radius: 10px;
  --gap: 16px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --surface-2: #0d0d0d;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --ink-muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-7: #9085e9;
    --series-8: #e66767;
    --good-text: #0ca30c;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1: #1a1a19;
  --surface-2: #0d0d0d;
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --ink-muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --series-6: #008300;
  --series-7: #9085e9;
  --series-8: #e66767;
  --good-text: #0ca30c;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--surface-2);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3 { line-height: 1.25; margin: 0 0 8px; }
h1 { font-size: 22px; }
h2 { font-size: 18px; }
h3 { font-size: 15px; }
p { margin: 0 0 10px; }
a { color: var(--series-1); }

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

/* ------------------------------------------------------------------ chrome */

header.top {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
header.top .brand { font-weight: 700; letter-spacing: 0.04em; }
header.top .spacer { flex: 1; }
header.top .mod { color: var(--ink-2); font-size: 13px; }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; padding: 3px 9px; border-radius: 999px;
  border: 1px solid var(--border); color: var(--ink-2);
  white-space: nowrap;
}
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-muted); }
.pill.online .dot { background: var(--good); }
.pill.offline .dot { background: var(--critical); }
.pill.pro { border-color: var(--series-1); color: var(--series-1); }

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: var(--gap);
}

/* ------------------------------------------------------------------- home */

.choices { display: grid; gap: var(--gap); grid-template-columns: 1fr; }
@media (min-width: 720px) { .choices { grid-template-columns: repeat(3, 1fr); } }

.choice {
  display: block; text-align: left; width: 100%;
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px 18px;
  cursor: pointer; font: inherit; color: inherit;
  transition: border-color .12s, transform .12s;
}
.choice:hover, .choice:focus-visible { border-color: var(--series-1); transform: translateY(-1px); }
.choice .n { font-size: 12px; color: var(--ink-muted); letter-spacing: .08em; }
.choice h2 { margin: 6px 0 6px; }
.choice p { color: var(--ink-2); font-size: 14px; margin: 0; }
.choice .tag {
  display: inline-block; margin-top: 10px; font-size: 12px;
  padding: 2px 8px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--ink-2);
}

/* ------------------------------------------------------------------ forms */

label { display: block; font-size: 13px; color: var(--ink-2); margin: 10px 0 4px; }
input, select, textarea, button { font: inherit; }
input[type=text], input[type=number], input[type=password], input[type=date],
input[type=email], select, textarea {
  width: 100%; padding: 10px 12px;
  background: var(--surface-2); color: var(--ink);
  border: 1px solid var(--border); border-radius: 8px;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--series-1); outline-offset: 1px; border-color: transparent;
}
.row { display: grid; gap: 12px; grid-template-columns: 1fr 1fr; }
.row-3 { display: grid; gap: 12px; grid-template-columns: repeat(3, 1fr); }
@media (max-width: 560px) { .row, .row-3 { grid-template-columns: 1fr; } }

button {
  padding: 11px 16px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--ink);
}
button:hover { border-color: var(--ink-muted); }
button.primary { background: var(--series-1); border-color: var(--series-1); color: #fff; }
button.primary:hover { filter: brightness(1.07); }
button.danger { color: var(--critical); border-color: var(--critical); background: transparent; }
button:disabled { opacity: .5; cursor: not-allowed; }
button.link { background: none; border: none; color: var(--series-1); padding: 4px 2px; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }

.msg { padding: 10px 12px; border-radius: 8px; margin: 10px 0; font-size: 14px; }
.msg.err { background: rgba(208, 59, 59, .12); color: var(--critical);
           border: 1px solid rgba(208, 59, 59, .3); }
.msg.ok  { background: rgba(12, 163, 12, .12); color: var(--good-text);
           border: 1px solid rgba(12, 163, 12, .3); }
.msg.info { background: var(--surface-2); border: 1px solid var(--border); color: var(--ink-2); }
.msg.warn { background: rgba(250, 178, 25, .14); border: 1px solid rgba(250, 178, 25, .4);
            color: var(--ink); }

.hint { font-size: 12.5px; color: var(--ink-muted); margin-top: 4px; }
.empty { color: var(--ink-muted); font-size: 14px; padding: 18px 0; text-align: center; }

/* ------------------------------------------------------------------ entry */

.entry { max-width: 400px; margin: 8vh auto; padding: 16px; }
.entry .card { padding: 24px; }
.entry .brand { font-weight: 700; letter-spacing: .06em; font-size: 14px; color: var(--ink-2); }
.entry h1 { margin: 6px 0 2px; }
.entry .site { color: var(--ink-muted); font-size: 14px; margin-bottom: 18px; }
.entry .or { text-align: center; color: var(--ink-muted); font-size: 13px; margin: 18px 0 6px; }
.entry .uid { font-size: 12px; color: var(--ink-muted); text-align: center; margin-top: 18px;
              letter-spacing: .08em; }

/* ---------------------------------------------------------------- devices */

.dev-list { display: flex; flex-direction: column; gap: 10px; }
.dev {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; border: 1px solid var(--border);
  border-radius: 8px; background: var(--surface-1);
}
.dev .slot {
  width: 30px; height: 30px; flex: none; border-radius: 6px;
  background: var(--surface-2); border: 1px solid var(--border);
  display: grid; place-items: center; font-size: 13px; color: var(--ink-2);
  font-variant-numeric: tabular-nums;
}
.dev .meta { flex: 1; min-width: 0; }
.dev .meta .nm { font-weight: 600; }
.dev .meta .sub { font-size: 12.5px; color: var(--ink-muted);
                  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dev .state { font-size: 12px; display: flex; align-items: center; gap: 5px; }
.dev .state .dot { width: 8px; height: 8px; border-radius: 50%; }
.dev .state.ok .dot { background: var(--good); }
.dev .state.stale .dot { background: var(--warning); }
.dev .state.err .dot { background: var(--critical); }
.dev .state.off .dot { background: var(--ink-muted); }

.param-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 6px; }
.param {
  display: flex; align-items: center; gap: 8px; padding: 7px 9px;
  border: 1px solid var(--border); border-radius: 7px; font-size: 13px; cursor: pointer;
}
.param input { width: auto; }
.param.off { opacity: .42; cursor: not-allowed; }
.param .u { color: var(--ink-muted); font-size: 12px; margin-left: auto; }
.group-head { font-size: 12px; text-transform: uppercase; letter-spacing: .06em;
              color: var(--ink-muted); margin: 14px 0 6px; }

.regs { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 12px;
        background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px;
        padding: 10px; overflow-x: auto; white-space: pre; color: var(--ink-2); }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-muted);
     font-weight: 600; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-scroll { overflow-x: auto; }

/* ---------------------------------------------------------------- charts */

.chart { display: block; overflow: visible; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .tick { fill: var(--ink-muted); font-size: 11px; }
.chart .tick-y { text-anchor: end; }
.chart .axis-title { fill: var(--ink-muted); font-size: 11px; }
.chart .crosshair { stroke: var(--axis); stroke-width: 1; stroke-dasharray: 3 3; }

.chart-host { position: relative; }
.chart-tip {
  position: absolute; top: 6px; pointer-events: none;
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; font-size: 12.5px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .14); min-width: 140px; z-index: 5;
}
.chart-tip .tip-t { color: var(--ink-muted); margin-bottom: 4px; }
.chart-tip .tip-r { display: flex; align-items: center; gap: 6px; }
.chart-tip .tip-r b { margin-left: auto; font-variant-numeric: tabular-nums; }
.sw { width: 9px; height: 9px; border-radius: 2px; flex: none; display: inline-block; }

.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 10px; font-size: 13px; }
.legend span.item { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-2); }

.bars { display: flex; flex-direction: column; gap: 8px; }
.bar-row { display: grid; grid-template-columns: minmax(90px, 1.2fr) 3fr auto;
           align-items: center; gap: 10px; font-size: 13.5px; }
.bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-2); }
.bar-track { background: var(--surface-2); border-radius: 4px; height: 16px; overflow: hidden; }
.bar-fill { display: block; height: 100%; border-radius: 4px; }
.bar-value { font-variant-numeric: tabular-nums; color: var(--ink); white-space: nowrap; }

.stats { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.stat { background: var(--surface-1); border: 1px solid var(--border);
        border-radius: var(--radius); padding: 14px; }
.stat-label { font-size: 12px; color: var(--ink-muted); text-transform: uppercase;
              letter-spacing: .05em; }
.stat-value { font-size: 26px; font-weight: 650; margin: 4px 0 2px; }
.stat-unit { font-size: 14px; color: var(--ink-2); margin-left: 4px; font-weight: 400; }
.stat-foot { font-size: 12px; display: flex; gap: 8px; align-items: center; }
.delta.good { color: var(--good-text); }
.delta.bad { color: var(--critical); }
.delta.flat { color: var(--ink-muted); }
.stat-note { color: var(--ink-muted); }

/* ------------------------------------------------------------------- SLD */

.sld { font-size: 14px; }
.sld ul { list-style: none; margin: 0; padding-left: 22px; position: relative; }
.sld > ul { padding-left: 0; }
.sld li { position: relative; padding: 4px 0; }
.sld ul ul li::before {
  content: ""; position: absolute; left: -13px; top: 0; bottom: 50%;
  border-left: 1px solid var(--axis); border-bottom: 1px solid var(--axis);
  width: 10px; border-bottom-left-radius: 5px;
}
.sld ul ul li:not(:last-child)::after {
  content: ""; position: absolute; left: -13px; top: 50%; bottom: 0;
  border-left: 1px solid var(--axis);
}
.node { display: inline-flex; align-items: center; gap: 10px; flex-wrap: wrap;
        padding: 7px 11px; border: 1px solid var(--border); border-radius: 8px;
        background: var(--surface-1); }
.node .role { font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
              color: var(--ink-muted); }
.node .kwh { font-variant-numeric: tabular-nums; color: var(--ink-2); }
.node.incomer { border-color: var(--series-1); }

.recon { margin-top: 8px; }
.recon .bad { color: var(--critical); }
.recon .warn { color: var(--ink); }

/* ------------------------------------------------------------- subscribe */

.price { font-size: 34px; font-weight: 700; }
.price small { font-size: 15px; font-weight: 400; color: var(--ink-2); }
.sell { list-style: none; padding: 0; margin: 14px 0; }
.sell li { padding: 7px 0 7px 26px; position: relative; color: var(--ink-2); }
.sell li::before { content: "→"; position: absolute; left: 4px; color: var(--series-1); }

.finding { border-left: 3px solid var(--ink-muted); padding: 4px 0 4px 14px; margin: 14px 0; }
.finding.good { border-color: var(--good); }
.finding.warn { border-color: var(--warning); }
.finding.info { border-color: var(--series-1); }
.finding h3 { margin: 0 0 4px; }
.finding p { color: var(--ink-2); margin: 0; font-size: 14px; }

.crumb { background: none; border: none; color: var(--series-1); padding: 0;
         font-size: 14px; cursor: pointer; margin-bottom: 10px; }

.spin { display: inline-block; width: 14px; height: 14px; border-radius: 50%;
        border: 2px solid var(--border); border-top-color: var(--series-1);
        animation: spin .7s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .spin { animation: none; }
  .choice { transition: none; }
}

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
