/* Smart Fertilizer Dosage Unit - control panel (light theme) */
:root {
  color-scheme: light;
  --page: #f1f5f3;
  --surface: #ffffff;
  --surface-2: #f5f8f7;
  --ink: #10201c;
  --ink-2: #435954;
  --muted: #6f837e;
  --line: #e0e8e5;
  --line-2: #cdd8d4;
  --grid: #e8eeeb;
  --axis: #c3cfca;
  --brand: #0f766e;
  --brand-ink: #0b5f58;
  --brand-soft: #e1f3ef;
  --series: #0f766e;
  --series-wash: rgba(15, 118, 110, 0.1);
  --on: #0f9f6e;
  --on-soft: #e5f6ee;
  --good: #16a34a;
  --good-ink: #166534;
  --warn: #f59e0b;
  --warn-ink: #8a4b06;
  --warn-soft: #fef5e4;
  --crit: #dc2626;
  --crit-soft: #fdecec;
  /* nutrient pumps */
  --n: #15803d;
  --n-soft: #e7f5ec;
  --p: #c2410c;
  --p-soft: #fcede4;
  --k: #7c3aed;
  --k-soft: #f0eafd;
  --m: #0369a1;
  --m-soft: #e3f1f9;
  /* water tank */
  --water: #2f86c4;
  --water-top: #74bde8;
  --water-ink: #0b4f7d;
  --water-soft: #e4f1fa;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(16, 40, 32, 0.05), 0 4px 14px rgba(16, 40, 32, 0.04);
  --shadow-lg: 0 16px 40px rgba(16, 40, 32, 0.18);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; min-height: 100%; background: var(--page); color: var(--ink); font: 15px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; color: inherit; }
a { color: var(--brand-ink); }
h1, h2, h3 { margin: 0; line-height: 1.2; letter-spacing: -0.01em; }
h1 { font-size: 25px; font-weight: 750; }
h2 { font-size: 17px; font-weight: 700; }
h3 { font-size: 15px; font-weight: 650; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.text-warn { color: var(--warn-ink); }
.mono { font-family: ui-monospace, "SFMono-Regular", Consolas, monospace; font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

/* ------------------------------------------------------------ shell */
.shell { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }
.side {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 18px 14px;
  background: linear-gradient(180deg, #0a3833 0%, #0c4639 55%, #0e5440 100%); color: #d4ebe4;
}
.brand { display: flex; align-items: center; gap: 11px; padding: 4px 8px 20px; }
.brand svg { width: 38px; height: 38px; flex: none; }
.brand b { display: block; font-size: 14.5px; line-height: 1.2; letter-spacing: -0.005em; }
.brand span { display: block; font-size: 12px; color: var(--muted); margin-top: 2px; }
.side .brand b { color: #fff; }
.side .brand span { color: #93b9ae; }
.side .brand svg rect { fill: #13907f; }
.nav { display: flex; flex-direction: column; gap: 3px; }
.nav a {
  display: flex; align-items: center; gap: 11px; padding: 10px 12px; border-radius: 10px;
  color: #b4d3ca; text-decoration: none; font-weight: 550;
}
.nav a svg { width: 19px; height: 19px; flex: none; }
.nav a:hover { background: rgba(255, 255, 255, 0.07); color: #fff; }
.nav a[aria-current="page"] { background: rgba(255, 255, 255, 0.14); color: #fff; box-shadow: inset 3px 0 0 #34d399; }
.side :focus-visible { outline-color: #6ee7b7; }
.side-foot { margin-top: auto; border-top: 1px solid rgba(255, 255, 255, 0.12); padding-top: 12px; }
.who { display: flex; align-items: center; gap: 10px; padding: 6px 8px; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; background: var(--brand-soft); color: var(--brand-ink);
  display: grid; place-items: center; font-weight: 700; flex: none; text-transform: uppercase;
}
.side .avatar { background: #34d399; color: #053b2f; }
.who-name { font-weight: 600; line-height: 1.2; }
.side .who-name { color: #fff; }
.side .muted { color: #93b9ae; }
.side-actions { display: flex; gap: 6px; padding: 6px 8px 0; }
.side .btn { background: rgba(255, 255, 255, 0.08); border-color: rgba(255, 255, 255, 0.16); color: #e3f3ee; }
.side .btn:hover { background: rgba(255, 255, 255, 0.15); }

.content { min-width: 0; }
.scrim { display: none; }
.main { min-width: 0; padding: 26px 32px 48px; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; }
.page-head p { margin: 4px 0 0; color: var(--muted); }

.topbar { display: none; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side {
    position: fixed; z-index: 40; left: 0; top: 0; width: 280px; transform: translateX(-102%);
    transition: transform 0.2s ease; box-shadow: var(--shadow-lg);
  }
  .shell.nav-open .side { transform: none; }
  .scrim { position: fixed; inset: 0; z-index: 30; background: rgba(10, 30, 26, 0.4); }
  .shell.nav-open .scrim { display: block; }
  .topbar {
    display: flex; position: sticky; top: 0; z-index: 20; align-items: center; gap: 10px;
    background: var(--surface); border-bottom: 1px solid var(--line); padding: 10px 16px;
  }
  .topbar .brand { padding: 0; min-width: 0; }
  .topbar .brand svg { width: 32px; height: 32px; }
  .topbar .brand b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .topbar .brand span { display: none; }
  .topbar .pill { margin-left: auto; }
  .main { padding: 18px 16px 40px; }
  h1 { font-size: 21px; }
}

/* ------------------------------------------------------------ primitives */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 18px 20px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; padding: 16px 20px 0; }
.card-head + .card-body { padding-top: 14px; }
.card-body { padding: 16px 20px 18px; }
.head-ico { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand); flex: none; }
.head-ico svg { width: 17px; height: 17px; }
.head-sub { margin: 4px 0 0; max-width: 62ch; }
.grid { display: grid; gap: 16px; }
.g-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.split { grid-template-columns: minmax(0, 1fr); }
@media (min-width: 1320px) { .split { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); } }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.spacer { flex: 1; }
.grow { flex: 1; min-width: 0; }
.row > .input { flex: 1; width: auto; min-width: 0; }
@media (max-width: 1200px) { .g-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 760px) { .g-2, .g-3, .g-4 { grid-template-columns: 1fr; } }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  min-height: 38px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--line-2);
  background: var(--surface); color: var(--ink); font-weight: 600; cursor: pointer; white-space: nowrap;
  text-decoration: none; transition: background 0.12s, border-color 0.12s;
}
.btn svg { width: 17px; height: 17px; }
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-ink); }
.btn-danger { color: var(--crit); border-color: #f3c3c3; }
.btn-danger:hover { background: var(--crit-soft); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { min-height: 32px; padding: 0 10px; font-size: 13.5px; border-radius: 8px; }
.btn-lg { min-height: 46px; padding: 0 20px; font-size: 15.5px; border-radius: 12px; }
.btn-lg svg { width: 19px; height: 19px; }
.icon-btn { width: 38px; padding: 0; }

.pill { display: inline-flex; align-items: center; gap: 7px; padding: 4px 11px; border-radius: 999px; font-size: 13px; font-weight: 600; background: var(--surface-2); color: var(--ink-2); white-space: nowrap; border: 1px solid var(--line); }
.pill svg { width: 14px; height: 14px; }
.pill-good { background: #e6f6ec; color: var(--good-ink); border-color: #c9ebd5; }
.pill-warn { background: var(--warn-soft); color: var(--warn-ink); border-color: #f7ddb0; }
.pill-crit { background: var(--crit-soft); color: #a52828; border-color: #f4c9c9; }
.pill-brand { background: var(--brand-soft); color: var(--brand-ink); border-color: #c4e6df; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; flex: none; }
.dot.pulse { animation: blink 1.4s ease-in-out infinite; }
@keyframes blink { 50% { opacity: 0.3; } }
/* nutrient colours (after .dot so they win) */
.c-n { background: var(--n); }
.c-p { background: var(--p); }
.c-k { background: var(--k); }
.c-gap { background: repeating-linear-gradient(45deg, var(--surface-2), var(--surface-2) 6px, var(--line) 6px, var(--line) 12px); }

.segmented { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 2px; }
.segmented button { border: 0; background: transparent; padding: 6px 12px; border-radius: 7px; font-weight: 600; color: var(--ink-2); cursor: pointer; font-size: 13.5px; white-space: nowrap; }
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(16, 40, 32, 0.12); }

.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.field small { color: var(--muted); font-size: 12.5px; }
.input, select.input {
  min-height: 40px; border: 1px solid var(--line-2); border-radius: 10px; padding: 0 12px; background: var(--surface);
  width: 100%;
}
.input:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
.check { display: flex; align-items: center; gap: 9px; font-weight: 550; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--brand); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 600px) { .form-grid, .form-grid.g3 { grid-template-columns: 1fr; } }
.error-box { background: var(--crit-soft); color: #9b2121; border-radius: 10px; padding: 10px 12px; font-size: 14px; }
.note { background: var(--brand-soft); color: var(--brand-ink); border-radius: 10px; padding: 10px 12px; font-size: 14px; }
.note-warn { background: var(--warn-soft); color: var(--warn-ink); }
.note svg { width: 18px; height: 18px; flex: none; vertical-align: -4px; }  /* icons in notes: never full size */
.note-row { display: flex; align-items: flex-start; gap: 10px; }

.days { display: flex; gap: 6px; flex-wrap: wrap; }
.days button { width: 44px; height: 36px; border-radius: 9px; border: 1px solid var(--line-2); background: var(--surface); cursor: pointer; font-weight: 600; font-size: 13px; }
.days button[aria-pressed="true"] { background: var(--brand); border-color: var(--brand); color: #fff; }

/* switch (pump + rule toggles) */
.switch { position: relative; width: 50px; height: 28px; border-radius: 999px; background: #cfd8d4; border: 0; cursor: pointer; flex: none; transition: background 0.15s; padding: 0; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2); transition: transform 0.15s; }
.switch[aria-checked="true"] { background: var(--on); }
.switch[aria-checked="true"]::after { transform: translateX(22px); }
.switch:disabled { opacity: 0.5; cursor: not-allowed; }

/* ------------------------------------------------------------ control panel */
.nodes .node { padding: 14px 16px; }
.node { display: flex; gap: 12px; align-items: flex-start; }
.node-ico { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand); flex: none; }
.node-ico svg { width: 21px; height: 21px; }
.node-top { justify-content: space-between; gap: 8px; }
.node .meta { color: var(--muted); font-size: 13px; margin-top: 6px; }
/* signal indicator: 4 bars, coloured by strength */
.link-line { display: flex; align-items: center; gap: 8px; margin-top: 8px; font-size: 13px; font-weight: 600; color: var(--ink-2); }
.link-line.off { color: var(--muted); font-weight: 500; }
.sig { display: inline-flex; align-items: flex-end; gap: 2px; height: 14px; flex: none; }
.sig i { display: block; width: 4px; border-radius: 1px; background: var(--line-2); }
.sig i:nth-child(1) { height: 30%; }
.sig i:nth-child(2) { height: 55%; }
.sig i:nth-child(3) { height: 78%; }
.sig i:nth-child(4) { height: 100%; }
.sig-3 i.on, .sig-4 i.on { background: var(--good); }
.sig-2 i.on { background: var(--warn); }
.sig-1 i.on { background: var(--crit); }
.sig.dim i.on { background: var(--muted); }
.node-actions { margin-top: 10px; }

.tile { --tone: var(--brand); --tone-soft: var(--brand-soft); position: relative; overflow: hidden; padding: 16px 18px 12px; display: flex; flex-direction: column; gap: 2px; }
.tile::before { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 3px; background: var(--tone); }
.tone-tds { --tone: #0f766e; --tone-soft: #e1f3ef; }
.tone-ph { --tone: #6d28d9; --tone-soft: #efe9fd; }
.tone-temp { --tone: #0369a1; --tone-soft: #e3f1f9; }
.tile-top { display: flex; align-items: center; gap: 10px; }
.tile-ico { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; background: var(--tone-soft); color: var(--tone); flex: none; }
.tile-ico svg { width: 18px; height: 18px; }
.tile-label { font-size: 13.5px; font-weight: 650; color: var(--ink-2); }
.tile-value { display: flex; align-items: baseline; gap: 6px; margin-top: 8px; }
.tile-value b { font-size: 36px; font-weight: 750; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.tile-value span { color: var(--muted); font-weight: 600; }
.tile-spark { height: 44px; margin-top: 6px; }
.tile-foot { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.tile.stale .tile-value b { color: var(--muted); }
.spark-line { fill: none; stroke: var(--tone, var(--series)); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.spark-area { fill: var(--tone-soft, var(--series-wash)); }
.spark-dot { fill: var(--tone, var(--series)); stroke: var(--surface); stroke-width: 2; }

/* nutrient mix */
.mix-card { border-color: #cfe6df; }
.mix-body { gap: 18px; }
.recipes-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.recipes-row .label { font-size: 11.5px; font-weight: 750; letter-spacing: 0.07em; text-transform: uppercase; color: var(--muted); }
.chips { display: flex; gap: 8px; flex-wrap: wrap; flex: 1; min-width: 0; }
.chip {
  display: inline-flex; align-items: center; gap: 8px; padding: 5px 12px 5px 9px; border-radius: 999px;
  border: 1px solid var(--line-2); background: var(--surface); cursor: pointer; font-weight: 600; font-size: 13.5px;
}
.chip { white-space: nowrap; max-width: 100%; }
.chip-name { overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 640px) { .recipes-row .chips { order: 3; flex-basis: 100%; } }
.chip:hover { background: var(--surface-2); }
.chip[aria-pressed="true"] { border-color: var(--brand); background: var(--brand-soft); color: var(--brand-ink); }
.chip-ratio { color: var(--muted); font-weight: 500; font-variant-numeric: tabular-nums; }
.mini-bar { display: inline-flex; width: 38px; height: 8px; border-radius: 4px; overflow: hidden; background: var(--line); flex: none; gap: 1px; }
.mini-bar > span { flex: 1 1 0; }
.mini-bar.lg { width: 64px; height: 12px; border-radius: 6px; }

.ratio { display: flex; flex-direction: column; gap: 10px; }
.ratio-row {
  display: grid; grid-template-columns: 36px minmax(200px, 1.3fr) minmax(120px, 1.7fr) auto; align-items: center; gap: 14px;
  padding: 10px 12px; border-radius: 12px; background: var(--surface-2); border: 1px solid transparent; transition: background 0.15s, border-color 0.15s;
}
.ratio-row.off { opacity: 0.72; }
.ratio-row.invalid { border-color: var(--warn); background: var(--warn-soft); }
.ratio-name b { display: block; }
.num-wrap { display: flex; align-items: center; gap: 6px; font-weight: 700; color: var(--ink-2); }
.num-in { width: 76px; min-height: 40px; padding: 0 8px; text-align: right; font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; }
.range { width: 100%; height: 28px; margin: 0; accent-color: var(--brand); cursor: pointer; touch-action: pan-y; }
.range:disabled { cursor: not-allowed; opacity: 0.55; }
.range-n { accent-color: var(--n); }
.range-p { accent-color: var(--p); }
.range-k { accent-color: var(--k); }
@media (max-width: 640px) {
  .ratio-row { grid-template-columns: 36px 1fr auto; row-gap: 6px; }
  .ratio-row .range { grid-column: 1 / -1; order: 3; }
}

.cycle-wrap { position: relative; }
.cycle { display: flex; gap: 2px; height: 36px; border-radius: 10px; overflow: hidden; background: var(--surface-2); }
.cseg { flex: 1 1 0; min-width: 0; display: flex; align-items: center; justify-content: center; overflow: hidden; white-space: nowrap; color: #fff; font-size: 12.5px; font-weight: 700; }
.cseg.c-gap { color: var(--muted); }
.cycle-cursor { position: absolute; top: -5px; bottom: -5px; width: 3px; margin-left: -1.5px; border-radius: 2px; background: var(--ink); box-shadow: 0 0 0 2px var(--surface); pointer-events: none; }
.cycle-foot { display: flex; justify-content: space-between; gap: 6px 14px; flex-wrap: wrap; margin-top: 8px; }
.cycle-now { font-size: 13px; font-weight: 700; color: var(--brand-ink); }

.run {
  display: grid; grid-template-columns: minmax(160px, auto) 1fr; gap: 16px; align-items: center; padding: 14px 16px;
  border-radius: 12px; background: linear-gradient(135deg, #e3f5f0 0%, #f0f9f4 100%); border: 1px solid #cbe8df;
}
.run-time { display: block; font-size: 27px; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.run-ml { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.run-cell { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.run-cell .dot { display: inline-block; margin-right: 6px; vertical-align: 1px; }
.run-cell b { font-size: 18px; font-variant-numeric: tabular-nums; }
.run-cell.total b { color: var(--brand-ink); }
@media (max-width: 700px) {
  .run { grid-template-columns: 1fr; }
  .run-ml { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
.mix-actions { gap: 12px; }

/* delivered today */
.today { display: flex; flex-direction: column; align-items: stretch; gap: 20px; }
.donut { width: 190px; height: 190px; flex: none; margin: 4px auto 0; }
.donut svg { display: block; width: 100%; height: 100%; }
.donut-bg { stroke: var(--surface-2); }
.donut-seg.d-n { stroke: var(--n); }
.donut-seg.d-p { stroke: var(--p); }
.donut-seg.d-k { stroke: var(--k); }
.donut-center { font-size: 20px; font-weight: 750; fill: var(--ink); }
.donut-sub { font-size: 12px; fill: var(--muted); }
.today-list { display: flex; flex-direction: column; gap: 10px; }
.today-row { display: flex; align-items: center; gap: 10px; padding-bottom: 9px; border-bottom: 1px solid var(--line); }
.today-row b { min-width: 72px; text-align: right; font-variant-numeric: tabular-nums; }

/* pumps */
.relays-wrap { container-type: inline-size; }
.relay-state { font-weight: 750; font-size: 13px; letter-spacing: 0.05em; color: var(--muted); }
.pumps { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
@container (min-width: 900px) { .pumps { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@container (max-width: 460px) { .pumps { grid-template-columns: 1fr; } }
.pump {
  --accent: var(--m); --accent-soft: var(--m-soft);
  border: 1.5px solid var(--line); border-radius: 14px; padding: 14px; display: flex; flex-direction: column; gap: 10px;
  background: var(--surface); transition: border-color 0.15s, background 0.15s;
}
.pump.pump-n { --accent: var(--n); --accent-soft: var(--n-soft); }
.pump.pump-p { --accent: var(--p); --accent-soft: var(--p-soft); }
.pump.pump-k { --accent: var(--k); --accent-soft: var(--k-soft); }
.pump.on { border-color: var(--accent); background: var(--accent-soft); }
.pump.on .relay-state { color: var(--accent); }
.pump.pending { border-color: var(--warn); }
.pump.pending .relay-state { color: var(--warn-ink); }
.pump-head { display: flex; align-items: center; gap: 10px; }
.pump-head b { display: block; font-size: 15px; line-height: 1.25; }
.pump-badge {
  width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; flex: none;
  font-weight: 800; font-size: 16px; color: #fff; background: var(--m);
}
.pump-badge.pump-n { background: var(--n); }
.pump-badge.pump-p { background: var(--p); }
.pump-badge.pump-k { background: var(--k); }
.pump-badge.pump-m { background: var(--m); }
.pump.slot .pump-badge { animation: ring 1.3s ease-out infinite; }
@keyframes ring {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 55%, transparent); }
  100% { box-shadow: 0 0 0 11px color-mix(in srgb, var(--accent) 0%, transparent); }
}
.pump-status { display: flex; flex-direction: column; gap: 4px; }
.pump-meter { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.pump-rate { font-size: 19px; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.duty { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.duty > span { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.3s; }
/* water tank: live level, inflow while the inlet runs, auto-fill thresholds */
.tank-view { display: flex; align-items: center; gap: 26px; margin-top: 10px; }
.tank-info { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.tank-liters { font-weight: 650; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.tank-progress { font-weight: 650; color: var(--water-ink); font-variant-numeric: tabular-nums; }
.tank { position: relative; flex: none; width: 92px; height: 150px; margin-right: 56px; }
.tank-body { position: absolute; inset: 0; border: 2px solid var(--line-2); border-top-width: 3px; border-radius: 6px 6px 16px 16px; background: var(--surface-2); overflow: hidden; }
.tank-water { position: absolute; left: 0; right: 0; bottom: 0; height: 0; background: linear-gradient(180deg, var(--water-top), var(--water)); transition: height 1.2s ease; }
.tank-water::before { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 4px; background: rgba(255, 255, 255, 0.55); }
.tank.low .tank-water { background: linear-gradient(180deg, #f3c97a, var(--warn)); }
.tank.stale .tank-water { filter: grayscale(0.85); opacity: 0.7; }
.tank.filling .tank-water { background-image: repeating-linear-gradient(-45deg, rgba(255, 255, 255, 0.16) 0 8px, transparent 8px 16px), linear-gradient(180deg, var(--water-top), var(--water));
  background-size: 23px 23px, auto; animation: tank-rise 0.9s linear infinite; }
.tank-stream { position: absolute; top: 0; left: 26%; width: 7px; height: 0; border-radius: 0 0 4px 4px; opacity: 0;
  background: repeating-linear-gradient(180deg, var(--water) 0 7px, var(--water-top) 7px 14px); transition: height 1.2s ease, opacity 0.3s; }
.tank.filling .tank-stream { opacity: 1; animation: tank-pour 0.5s linear infinite; }
.tank-mark { position: absolute; left: 0; width: 92px; border-top: 2px dashed var(--ink-2); opacity: 0.55; pointer-events: none; }
.tank-mark span { position: absolute; left: 100px; top: -9px; font-size: 11.5px; font-weight: 700; color: var(--ink-2); white-space: nowrap; }
.tank-mark.mark-on { border-color: var(--warn-ink); }
.tank-mark.mark-on span { color: var(--warn-ink); }
@keyframes tank-rise { to { background-position: 0 -23px, 0 0; } }
@keyframes tank-pour { to { background-position: 0 14px; } }
.tank-lock { display: flex; align-items: center; gap: 8px; background: var(--water-soft); color: var(--water-ink); margin-top: 10px; }
.relays-wrap > .tank-lock { margin: 0 0 12px; }
.pump.locked { opacity: 0.62; }
/* emergency stop pressed at the actuator box */
.estop-banner { display: flex; align-items: center; gap: 14px; padding: 14px 18px; border-radius: var(--radius);
  background: var(--crit-soft); color: #8f1d1d; border: 2px solid var(--crit); font-size: 14.5px; }
.estop-banner b { display: block; font-size: 17px; letter-spacing: 0.01em; }
.estop-banner svg { flex: none; width: 28px; height: 28px; color: var(--crit); }
.estop-banner .btn svg { width: 18px; height: 18px; color: inherit; }
.btn-estop { background: var(--crit); border-color: var(--crit); color: #fff; font-weight: 800; letter-spacing: 0.03em; }
.btn-estop:hover { background: #b91c1c; border-color: #b91c1c; }
.btn-estop:disabled { opacity: 0.7; }
/* temporarily disabled on the Pi: greyed, still clickable to show the caution */
.btn-estop.btn-estop-off, .btn-estop.btn-estop-off:hover { background: var(--surface-2); border-color: var(--line-2); color: var(--muted); }
@media (max-width: 460px) { .tank-view { gap: 14px; } .tank { width: 74px; height: 128px; } .tank-mark { width: 74px; } .tank-mark span { left: 80px; } }
.deliver-row { margin-top: 8px; gap: 6px; }
.ml-in { width: 72px; padding: 5px 8px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); color: var(--ink); font: inherit; }

.feed { list-style: none; margin: 0; padding: 0; }
.feed li { display: flex; gap: 12px; padding: 11px 0; border-top: 1px solid var(--line); align-items: flex-start; }
.feed li:first-child { border-top: 0; }
.feed-ico { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; flex: none; background: var(--surface-2); color: var(--ink-2); }
.feed-ico svg { width: 17px; height: 17px; }
.feed-ico.c-relay { background: var(--m-soft); color: var(--m); }
.feed-ico.c-mix { background: var(--brand-soft); color: var(--brand); }
.feed-ico.c-rule { background: #f1eefc; color: #4a3aa7; }
.feed-ico.c-auth { background: #eaf6ee; color: var(--good-ink); }
.feed-ico.c-auth-bad, .feed-ico.c-bad { background: var(--crit-soft); color: #a52828; }
.feed-ico.c-device { background: #fdf3ea; color: #9a4a17; }
.feed-ico.c-user { background: #eef1f0; color: var(--ink-2); }
.feed-text { min-width: 0; flex: 1; }
.feed-text .sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.feed-time { color: var(--muted); font-size: 12.5px; white-space: nowrap; }

/* ------------------------------------------------------------ charts */
.chart-card .card-head p { margin: 2px 0 0; font-size: 12.5px; color: var(--muted); }
.chart { position: relative; height: 210px; }
.chart svg { display: block; width: 100%; height: 100%; overflow: visible; }
.chart .grid-line { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
.chart .base-line { stroke: var(--axis); stroke-width: 1; shape-rendering: crispEdges; }
.chart .tick { fill: var(--muted); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.chart .band { fill: var(--series-wash); }
.chart .line { fill: none; stroke: var(--series); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .end-dot { fill: var(--series); stroke: var(--surface); stroke-width: 2; }
.chart .end-label { fill: var(--ink); font-size: 12px; font-weight: 650; }
.chart .cross { stroke: var(--ink-2); stroke-width: 1; shape-rendering: crispEdges; }
.chart .cross-dot { fill: var(--series); stroke: var(--surface); stroke-width: 2; }
.chart .lane-label { fill: var(--ink-2); font-size: 12px; font-weight: 600; }
.chart .lane-bg { fill: var(--surface-2); }
.chart .seg { fill: var(--series); }
.chart .seg:hover, .chart .seg:focus { fill: var(--brand-ink); outline: none; }
.chart .empty { fill: var(--muted); font-size: 13px; }
.chart.loading svg { opacity: 0.45; transition: opacity 0.2s; }
.chart.bars { height: 240px; }
.chart .bar.d-n { fill: var(--n); }
.chart .bar.d-p { fill: var(--p); }
.chart .bar.d-k { fill: var(--k); }
.chart g:focus { outline: none; }
.chart g:focus .bar, .chart g:hover .bar { opacity: 0.85; }
.chart-tip {
  position: absolute; pointer-events: none; z-index: 5; min-width: 140px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow-lg);
  padding: 8px 10px; font-size: 12.5px; opacity: 0; transition: opacity 0.1s;
}
.chart-tip.show { opacity: 1; }
.chart-tip .t { color: var(--muted); margin-bottom: 4px; }
.chart-tip .v { display: flex; align-items: center; gap: 7px; }
.chart-tip .v b { font-size: 15px; margin-left: auto; }
.chart-tip .key { width: 12px; height: 2px; background: var(--series); border-radius: 1px; flex: none; }
.chart-tip .key.d-n, .chart-tip .key.d-p, .chart-tip .key.d-k { width: 10px; height: 10px; border-radius: 3px; }
.chart-tip .key.d-n { background: var(--n); }
.chart-tip .key.d-p { background: var(--p); }
.chart-tip .key.d-k { background: var(--k); }
.chart-tip .r { color: var(--ink-2); margin-top: 2px; }
.timeline { height: 190px; }
.legend { display: flex; flex-wrap: wrap; gap: 8px 18px; margin-top: 12px; font-size: 13px; color: var(--ink-2); }
.legend .dot { display: inline-block; margin-right: 7px; vertical-align: 0; }

.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 16px; }

table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data th { text-align: left; font-weight: 600; color: var(--ink-2); border-bottom: 1px solid var(--line-2); padding: 9px 10px; white-space: nowrap; background: var(--surface-2); position: sticky; top: 0; }
table.data td { border-bottom: 1px solid var(--line); padding: 9px 10px; vertical-align: middle; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data .ratio-cell { gap: 8px; }
table.data .detail { max-width: 280px; white-space: normal; margin-top: 4px; }
table.data .empty-row { text-align: center; padding: 30px 10px; }
.table-wrap { overflow: auto; max-height: 560px; border-radius: 0 0 var(--radius) var(--radius); }
.load-more { justify-content: center; margin-top: 12px; }

/* ------------------------------------------------------------ lists */
.list-item { display: flex; gap: 14px; align-items: center; padding: 16px 20px; border-top: 1px solid var(--line); }
.list-item:first-child { border-top: 0; }
.card-head + .list-item, .card-head + div > .list-item:first-child { margin-top: 10px; }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .title { font-weight: 650; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.list-item .desc { color: var(--ink-2); margin-top: 3px; }
.list-item .meta { color: var(--muted); font-size: 12.5px; margin-top: 4px; }
@media (max-width: 640px) { .list-item { flex-wrap: wrap; } .list-item .actions { width: 100%; } }

.device-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 13.5px; margin: 14px 0 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.kv dd.row { flex-wrap: nowrap; gap: 4px; }
.kv dd.row .mono { min-width: 0; }

.empty-state { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty-state svg { width: 36px; height: 36px; color: var(--axis); margin-bottom: 8px; }

/* ------------------------------------------------------------ login */
.login {
  min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(1200px 500px at 15% -10%, #cdeee3 0%, transparent 60%),
    radial-gradient(900px 480px at 110% 110%, #d9f2e6 0%, transparent 55%), var(--page);
}
.login-card { width: 100%; max-width: 410px; padding: 30px 28px; box-shadow: var(--shadow-lg); }
.login-card .brand { padding: 0 0 22px; }
.login-card .brand b { font-size: 16px; color: var(--ink); }
.login-card form { display: flex; flex-direction: column; gap: 14px; margin-top: 16px; }
.login-foot { margin-top: 18px; display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: 12.5px; }
.login-foot svg { width: 16px; height: 16px; flex: none; }

/* ------------------------------------------------------------ modal + toasts */
.modal-back { position: fixed; inset: 0; z-index: 60; background: rgba(10, 30, 26, 0.42); display: grid; place-items: center; padding: 16px; }
.modal { width: 100%; max-width: 560px; max-height: calc(100vh - 32px); overflow: auto; background: var(--surface); border-radius: 18px; box-shadow: var(--shadow-lg); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 18px 22px 0; }
.modal-body { padding: 16px 22px; display: flex; flex-direction: column; gap: 14px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 0 22px 20px; flex-wrap: wrap; }
.secret { display: flex; gap: 8px; align-items: center; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.secret code { flex: 1; overflow-wrap: anywhere; font-size: 13px; }

.toasts { position: fixed; z-index: 80; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; max-width: min(380px, calc(100vw - 36px)); }
.toast { background: var(--ink); color: #fff; padding: 11px 14px; border-radius: 11px; box-shadow: var(--shadow-lg); font-weight: 550; font-size: 14px; }
.toast.bad { background: #a52828; }
.toast.good { background: #0b5f58; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
