/* Light is the default, whatever the computer's setting. Dark is opt-in. */
:root {
  color-scheme: light;
  --page: #f3f7f9;
  --page-glow: #dff1f6;
  --surface: #ffffff;
  --surface-2: #f4f9fa;
  --ink: #10242e;
  --ink-2: #43565f;
  --muted: #5f717a;
  --axis: #6d7d85;
  --grid: #e9eff1;
  --baseline: #cfdade;
  --border: rgba(16, 60, 80, 0.1);
  --shadow: 0 1px 2px rgba(16, 60, 80, 0.05), 0 8px 24px rgba(16, 60, 80, 0.05);
  --wash: rgba(0, 127, 158, 0.06);
  --brand: #0f4c6e;
  --accent: #007f9e;
  --accent-text: #00657e;
  --accent-wash: rgba(0, 127, 158, 0.12);
  --context-line: #d3dde1;
  --band: rgba(12, 163, 12, 0.09);
  --good: #0ca30c;
  --good-text: #0a6b0a;
  --good-wash: #e7f6e7;
  --critical: #d03b3b;
  --critical-text: #b42b2b;
  --critical-wash: #fdeeee;
  --offline: #6d7d85;
  --offline-wash: #edf1f3;
  --logo-plate: transparent;
  --seq-0: #e9f4f7;
  --seq-1: #a9d9e4;
  --seq-2: #57b1c7;
  --seq-3: #007f9e;
  --seq-4: #064456;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d1214;
  --page-glow: #122229;
  --surface: #182024;
  --surface-2: #1f292e;
  --ink: #f0efec;
  --ink-2: #c3c2b7;
  --muted: #a3a29a;
  --axis: #98978f;
  --grid: #2a3438;
  --baseline: #3c484d;
  --border: rgba(255, 255, 255, 0.11);
  --shadow: none;
  --wash: rgba(255, 255, 255, 0.06);
  --brand: #4db4cc;
  --accent: #2a9fbc;
  --accent-text: #6cc6db;
  --accent-wash: rgba(42, 159, 188, 0.2);
  --context-line: #3f4b50;
  --band: rgba(12, 163, 12, 0.15);
  --good-text: #4fc94f;
  --good-wash: rgba(12, 163, 12, 0.16);
  --critical-text: #f08a8a;
  --critical-wash: rgba(208, 59, 59, 0.16);
  --offline: #98978f;
  --offline-wash: rgba(255, 255, 255, 0.07);
  --logo-plate: #ffffff;
  --seq-0: #1f2d32;
  --seq-1: #0f4d5e;
  --seq-2: #007f9e;
  --seq-3: #4db4cc;
  --seq-4: #b6e3ed;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: linear-gradient(180deg, var(--page-glow) 0, var(--page) 340px) no-repeat, var(--page);
  color: var(--ink);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

h2 { margin: 0; font-size: 16px; font-weight: 650; letter-spacing: -0.005em; }
p { margin: 0; }
.muted { color: var(--muted); font-size: 13px; }
.note { margin-top: 12px; }
.nowrap { white-space: nowrap; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Header */
.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 12px rgba(16, 60, 80, 0.05);
}
.topbar-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 28px;
  max-width: 1440px;
  margin: 0 auto;
  padding: 8px 28px;
}
.brand-logo {
  display: block;
  height: 54px;
  width: auto;
  max-width: 100%;
  background: var(--logo-plate);
  border-radius: 8px;
}
.tabs { display: flex; gap: 4px; overflow-x: auto; }
.tabs a {
  padding: 7px 16px;
  border-radius: 999px;
  color: var(--ink-2);
  text-decoration: none;
  font-weight: 550;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}
.tabs a:hover { background: var(--wash); color: var(--ink); }
.tabs a[aria-current="page"] { background: var(--accent-wash); color: var(--accent-text); font-weight: 650; }
.top-right { display: flex; align-items: center; gap: 14px; margin-left: auto; }
#freshness { display: inline-flex; align-items: center; gap: 7px; }
#freshness[data-live]::before {
  content: "";
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--good);
  box-shadow: 0 0 0 3px var(--good-wash);
}

main { max-width: 1440px; margin: 0 auto; padding: 20px 28px 48px; }
section { margin-top: 20px; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 18px 20px;
  min-width: 0;
}
.section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px 16px;
  margin-bottom: 12px;
}
.scroll-x { overflow-x: auto; }

/* Filters */
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 18px;
  align-items: flex-end;
  padding: 14px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
}
.spacer { flex: 1; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 12px; font-weight: 550; color: var(--muted); }
.date-group { display: flex; gap: 4px; }
input[type="date"], input[type="search"], select, .btn {
  height: 36px;
  border: 1px solid var(--baseline);
  border-radius: 9px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  padding: 0 12px;
  transition: background 0.15s, border-color 0.15s;
}
input[type="date"]:hover, input[type="search"]:hover, select:hover { border-color: var(--axis); }
select { min-width: 170px; cursor: pointer; }
.search { width: 210px; }
.btn { cursor: pointer; font-weight: 550; }
.btn.icon { width: 36px; padding: 0; font-size: 18px; line-height: 1; }
.btn:hover:not(:disabled) { background: var(--wash); border-color: var(--accent); }
.btn:disabled { opacity: 0.45; cursor: default; }
.filters .check { height: 36px; }

/* Messages */
.banner, .notice {
  margin-top: 16px;
  padding: 11px 16px;
  border-radius: 12px;
  border: 1px solid var(--critical);
  background: var(--critical-wash);
}
.notice { border-color: var(--accent); background: var(--accent-wash); }
.banner .btn { margin-left: 12px; }
.coverage { margin-top: 12px; }
.empty {
  margin-top: 20px;
  padding: 56px 16px;
  text-align: center;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
}
.loading { opacity: 0.55; transition: opacity 0.15s; }
.print-title { display: none; }

/* Summary tiles */
.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 14px;
  margin-top: 16px;
}
#view > .kpis:first-child, #view > .banner[hidden] + .kpis { margin-top: 0; }
.tile {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 16px 18px;
  min-width: 0;
}
.tile .label { color: var(--muted); font-size: 13px; font-weight: 550; padding-right: 38px; }
.tile .value { font-size: 30px; font-weight: 650; line-height: 1.2; margin-top: 6px; letter-spacing: -0.015em; }
.tile .sub { color: var(--muted); font-size: 12px; margin-top: 4px; }
.tile.hero .value { font-size: 48px; line-height: 1.05; letter-spacing: -0.025em; }
.tile-icon {
  position: absolute;
  top: 13px;
  right: 13px;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 10px;
  background: var(--accent-wash);
  color: var(--accent-text);
}
.tile-icon svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tone-good .tile-icon { background: var(--good-wash); color: var(--good-text); }
.tone-bad .tile-icon { background: var(--critical-wash); color: var(--critical-text); }
.tone-muted .tile-icon { background: var(--offline-wash); color: var(--muted); }
.tile.alert { border-color: var(--critical); background: var(--critical-wash); }
.tile.alert .tile-icon { background: var(--critical); color: #fff; }

/* Status pills */
.status {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 10px 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 650;
  white-space: nowrap;
}
.status::before { font-size: 10px; line-height: 1; }
.status.red { color: var(--critical-text); background: var(--critical-wash); }
.status.red::before { content: "▲"; color: var(--critical); }
.status.green { color: var(--good-text); background: var(--good-wash); }
.status.green::before { content: "●"; color: var(--good); }
.status.offline { color: var(--muted); background: var(--offline-wash); }
.status.offline::before { content: "○"; color: var(--offline); }
.breach { font-weight: 650; color: var(--critical-text); }
.muted-cell { color: var(--muted); }

/* Layouts */
.overview-grid {
  display: grid;
  grid-template-columns: minmax(290px, 1fr) minmax(0, 3fr);
  gap: 14px;
  margin-top: 14px;
  align-items: start;
}
.overview-grid section { margin-top: 0; }
.chart-legend { margin-top: 8px; }
.two-col {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr);
  gap: 14px;
  margin-top: 14px;
}
.even-col {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-top: 14px;
}
.two-col section, .even-col section { margin-top: 0; }

/* Charts */
.card svg, .trend svg { display: block; width: 100%; margin-top: 10px; touch-action: pan-y; }
.heat-wrap { margin-top: 12px; }
.heat-wrap svg { width: auto; }
.heat-cell { cursor: pointer; }
.heat-cell:hover, .heat-cell.active { stroke: var(--ink); stroke-width: 1.5; }
.s0 { fill: var(--seq-0); } .s1 { fill: var(--seq-1); } .s2 { fill: var(--seq-2); }
.s3 { fill: var(--seq-3); } .s4 { fill: var(--seq-4); }
.heat-empty { fill: none; stroke: var(--grid); }
.heat-red { fill: var(--critical); stroke: var(--surface); stroke-width: 1.5; pointer-events: none; }
.axis-text { fill: var(--axis); font-size: 11px; font-variant-numeric: tabular-nums; }
.row-text { fill: var(--ink-2); font-size: 12px; }
.heat-keys {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  margin-top: 12px;
  color: var(--ink-2);
  font-size: 12px;
  align-items: center;
}
.heat-key { display: inline-flex; align-items: center; gap: 5px; }
.swatch { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.swatch.empty { border: 1px solid var(--baseline); }
.key-red { color: var(--critical); font-size: 10px; }
.fill-red { fill: var(--critical); }
.fill-accent { fill: var(--accent); }
.hit { fill: transparent; }
.hit:hover, .hit.active { fill: var(--wash); }

.sensor-bars { margin-top: 18px; display: grid; gap: 20px; }
.sbar-head { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; font-weight: 550; }
.sbar-head b { font-weight: 650; font-variant-numeric: tabular-nums; }
.sbar-track { height: 12px; margin: 6px 0 5px; border-bottom: 1px solid var(--baseline); }
.sbar-fill { height: 11px; background: var(--accent); border-radius: 0 4px 4px 0; }
.sbar-sub { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }

.trend-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 14px;
}
.trend { padding: 14px 16px 10px; }
.trend-head { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.trend-head h3 { margin: 0; font-size: 14px; font-weight: 650; }
.gridline { stroke: var(--grid); stroke-width: 1; }
.base { stroke: var(--baseline); stroke-width: 1; }
.band { fill: var(--band); }
.range { fill: var(--accent-wash); }
.context { fill: none; stroke: var(--context-line); stroke-width: 1; stroke-linejoin: round; }
.main-line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.cross { stroke: var(--axis); stroke-width: 1; }
.cross-dot { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; color: var(--ink-2); font-size: 12px; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.key-line { width: 16px; height: 2px; border-radius: 1px; display: inline-block; }
.key-rect { width: 12px; height: 10px; border-radius: 3px; display: inline-block; }

/* Tables */
.table-head { align-items: center; }
.table-filters { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; }
.segmented { display: inline-flex; gap: 2px; padding: 3px; background: var(--surface-2); border-radius: 10px; }
.segmented button {
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink-2);
  padding: 4px 14px;
  font: inherit;
  font-weight: 550;
  cursor: pointer;
}
.segmented button:hover { background: var(--wash); }
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--accent-text); font-weight: 650; box-shadow: 0 1px 3px rgba(16, 60, 80, 0.14); }
.check { display: inline-flex; gap: 7px; align-items: center; font-size: 13px; color: var(--ink-2); cursor: pointer; }
.check input { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); }
table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; margin-top: 10px; }
th {
  text-align: left;
  font-weight: 650;
  color: var(--ink-2);
  font-size: 12px;
  padding: 9px 12px;
  background: var(--surface-2);
  white-space: nowrap;
}
th:first-child { border-radius: 9px 0 0 9px; }
th:last-child { border-radius: 0 9px 9px 0; }
th.num .sort-btn { text-align: right; }
td { padding: 9px 12px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--wash); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.sort-btn { all: unset; cursor: pointer; }
.sort-btn:hover { color: var(--accent-text); }
.sort-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.link-btn {
  background: none;
  border: 0;
  padding: 0;
  color: var(--accent-text);
  font: inherit;
  font-weight: 550;
  cursor: pointer;
}
.link-btn:hover { text-decoration: underline; }
.link-btn.strong { color: var(--ink); font-weight: 650; }
.link-btn.strong:hover { color: var(--accent-text); }
.link-btn[aria-pressed="true"] { color: var(--accent-text); }
.pager { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 12px; margin-top: 14px; }
.pager .btn { height: 32px; }

/* Tooltip */
.tooltip {
  position: fixed;
  z-index: 10;
  max-width: 280px;
  padding: 9px 12px;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: 0 6px 24px rgba(16, 60, 80, 0.18);
  font-size: 12px;
  pointer-events: none;
}
.tip-title { color: var(--muted); margin-bottom: 3px; }
.tip-row { display: flex; gap: 8px; align-items: baseline; }
.tip-row b { font-weight: 650; font-variant-numeric: tabular-nums; }
.tip-row span { color: var(--ink-2); }

/* Photo */
dialog {
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  color: var(--ink);
  padding: 18px;
  width: min(760px, calc(100vw - 32px));
  box-shadow: 0 16px 48px rgba(16, 60, 80, 0.25);
}
dialog::backdrop { background: rgba(16, 36, 46, 0.55); }
.photo-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
#photo-img { display: block; width: 100%; height: auto; border-radius: 10px; background: var(--wash); }
#photo-caption, #photo-error { margin-top: 10px; }

@media (max-width: 1100px) {
  .overview-grid, .two-col, .even-col { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 760px) {
  .topbar { position: static; }
  .topbar-inner { padding: 8px 16px; }
  .top-right { margin-left: 0; width: 100%; justify-content: space-between; order: 3; }
  .tabs { order: 2; width: 100%; }
  main { padding: 16px 16px 40px; }
}

@media (max-width: 560px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tile .value { font-size: 24px; }
  .tile.hero { grid-column: 1 / -1; }
  .tile.hero .value { font-size: 48px; }
  .trend-grid { grid-template-columns: minmax(0, 1fr); }
  .field, select, .search { width: 100%; }
  input[type="date"] { flex: 1; min-width: 0; }
  .spacer { display: none; }
}

@media print {
  body { background: #fff; }
  .topbar { position: static; box-shadow: none; }
  .no-print, .tooltip, .notice, .theme-btn { display: none !important; }
  main { max-width: none; padding: 0 8px; }
  .print-title { display: block; margin-top: 12px; font-size: 18px; }
  .card, .tile { break-inside: avoid; box-shadow: none; }
  .two-col, .even-col { grid-template-columns: minmax(0, 1fr); }
  .pager { display: none; }
}

/* Sign-in page */
.login-page { display: grid; place-items: center; min-height: 100vh; padding: 24px 16px; background: #0a4f6e; }
.aquarium { position: fixed; inset: 0; width: 100%; height: 100%; display: block; z-index: 0; }
.login-card {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 380px;
  padding: 28px;
  /* Frosted glass, so the aquarium shows through softly. */
  background: rgba(255, 255, 255, 0.86);
  -webkit-backdrop-filter: blur(10px) saturate(1.2);
  backdrop-filter: blur(10px) saturate(1.2);
  border: 1px solid rgba(255, 255, 255, 0.6);
  border-radius: 16px;
  box-shadow: 0 20px 50px rgba(0, 25, 40, 0.35), 0 2px 8px rgba(0, 25, 40, 0.2);
}
.login-logo { height: 60px; margin-bottom: 18px; }
.login-card h1 { margin: 0 0 2px; font-size: 22px; font-weight: 650; letter-spacing: -0.01em; }
.login-form { display: flex; flex-direction: column; gap: 14px; margin-top: 20px; }
.login-form input {
  height: 40px;
  border: 1px solid var(--baseline);
  border-radius: 9px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  padding: 0 12px;
}
.login-form input:hover { border-color: var(--axis); }
.login-form .field label { font-size: 13px; }
.btn-primary { height: 40px; background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-text); border-color: var(--accent-text); }
.login-msg { margin-top: 16px; padding: 10px 12px; border-radius: 9px; background: var(--accent-wash); color: var(--ink); font-size: 13px; }
.login-msg.error { background: var(--critical-wash); color: var(--critical-text); }
.logout-form { margin: 0; }

/* Tank page */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.field-label { font-size: 12px; font-weight: 550; color: var(--muted); }
.tank-head { margin-top: 18px; }
.tank-title { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; }
.tank-name { margin: 0; font-size: 26px; font-weight: 700; letter-spacing: -0.015em; }
.tank-head .muted { margin-top: 2px; }
.all-clear { margin-top: 12px; padding: 10px 12px; border-radius: 9px; background: var(--good-wash); color: var(--good-text); font-weight: 550; }
.fish-charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 4px 24px; }
.fish-chart h3 { margin: 10px 0 0; font-size: 13px; font-weight: 650; color: var(--ink-2); }
.photo-strip { display: flex; gap: 12px; overflow-x: auto; padding: 12px 2px 6px; scroll-snap-type: x proximity; }
.photo-thumb {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink-2);
  font: inherit;
  font-size: 12px;
  text-align: left;
  cursor: pointer;
  scroll-snap-align: start;
}
.thumb-frame {
  display: grid;
  place-items: center;
  width: 148px;
  height: 100px;
  border-radius: 10px;
  overflow: hidden;
  background: var(--surface-2);
  border: 2px solid transparent;
  transition: border-color 0.15s, transform 0.15s;
}
.thumb-frame img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-thumb:hover .thumb-frame { border-color: var(--accent); transform: translateY(-1px); }
.photo-thumb.flagged .thumb-frame { border-color: var(--critical); }
.thumb-missing { color: var(--muted); font-size: 12px; }
.thumb-cap { font-variant-numeric: tabular-nums; font-weight: 550; }
.thumb-flag { color: var(--critical-text); font-weight: 550; }
.note-form { display: grid; gap: 8px; margin-top: 12px; }
.note-form textarea {
  width: 100%;
  min-height: 72px;
  resize: vertical;
  border: 1px solid var(--baseline);
  border-radius: 9px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  padding: 10px 12px;
}
.note-form textarea:hover { border-color: var(--axis); }
.note-actions { display: flex; align-items: center; justify-content: flex-end; gap: 12px; }
.note-actions .btn-primary { height: 36px; }
.note-error { color: var(--critical-text); font-size: 13px; margin-right: auto; }
.notes-list { list-style: none; margin: 16px 0 0; padding: 0; display: grid; gap: 10px; }
.note { padding: 12px 14px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); }
.note-meta { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; font-size: 13px; }
.note-del { margin-left: auto; font-size: 13px; color: var(--critical-text); }
.note-text { margin-top: 4px; white-space: pre-wrap; overflow-wrap: anywhere; }
@media (max-width: 560px) {
  .tank-name { font-size: 22px; }
  .thumb-frame { width: 124px; height: 84px; }
}

/* Accounts and users */
.account-btn { display: inline-flex; align-items: center; gap: 8px; }
.role-chip {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.02em;
  background: var(--offline-wash);
  color: var(--ink-2);
  white-space: nowrap;
}
.role-chip.role-admin { background: var(--accent-wash); color: var(--accent-text); }
.role-chip.role-staff { background: var(--good-wash); color: var(--good-text); }
.page-head { margin-top: 18px; }
.page-head .muted { margin-top: 2px; }
.role-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; margin-top: 16px; }
.role-card { padding: 12px 14px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); }
.role-card p { margin-top: 6px; color: var(--ink-2); font-size: 13px; }
.user-form { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 14px 18px; margin-top: 12px; }
.user-form .field.grow { flex: 1 1 300px; }
.user-form input[type="text"], .dialog-form input[type="text"], .dialog-form input[type="password"], select.compact {
  height: 36px;
  border: 1px solid var(--baseline);
  border-radius: 9px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  padding: 0 12px;
}
select.compact { min-width: 0; height: 32px; }
.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; letter-spacing: 0.02em; }
.input-row { display: flex; gap: 6px; }
.input-row input { flex: 1; min-width: 0; }
.field-hint { font-size: 12px; margin-top: 2px; max-width: 34ch; }
.user-form-actions { display: flex; align-items: center; gap: 12px; flex: 1 1 100%; justify-content: flex-end; }
.row-actions { display: inline-flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
.row-actions .btn { height: 32px; padding: 0 10px; }
.btn.danger { color: var(--critical-text); }
.btn.armed { background: var(--critical); border-color: var(--critical); color: #fff; }
.you { color: var(--muted); font-size: 13px; }
.form-dialog { border: 1px solid var(--border); border-radius: 14px; padding: 0; background: var(--surface); color: var(--ink); box-shadow: 0 20px 50px rgba(0, 25, 40, 0.25); width: min(420px, calc(100vw - 32px)); }
.form-dialog::backdrop { background: rgba(10, 30, 40, 0.45); }
.dialog-form { display: grid; gap: 12px; padding: 22px; }
.dialog-form h2 { font-size: 18px; }
.dialog-form .field input { width: 100%; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.dialog-actions .btn-primary { height: 36px; }
@media (max-width: 760px) {
  .account-btn #account-role { display: none; }
}

/* Header buttons: icon and label on wide screens, icon only on phones */
.header-actions { display: flex; align-items: center; gap: 8px; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.icon { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.icon-sun { display: none; }
:root[data-theme="dark"] .icon-sun { display: block; }
:root[data-theme="dark"] .icon-moon { display: none; }
.avatar {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  flex: none;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
}
.account-label { display: inline-flex; align-items: center; gap: 8px; }
.account-btn { padding-left: 6px; }

@media (max-width: 760px) {
  /* Logo and buttons on one row, tabs on the next, the status line last. */
  .topbar-inner {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "logo actions" "tabs tabs" "fresh fresh";
    align-items: center;
    gap: 6px 12px;
    padding: 8px 12px 6px;
  }
  .top-right { display: contents; }
  .brand-logo { grid-area: logo; height: 40px; }
  .header-actions { grid-area: actions; gap: 6px; }
  .tabs {
    grid-area: tabs;
    width: auto;
    margin: 0 -12px;
    padding: 2px 12px;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    /* Fades the edges so it's clear the row scrolls sideways. */
    -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 12px, #000 calc(100% - 24px), transparent 100%);
    mask-image: linear-gradient(90deg, transparent 0, #000 12px, #000 calc(100% - 24px), transparent 100%);
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs a { padding: 8px 14px; font-size: 14px; }
  #freshness { grid-area: fresh; font-size: 12px; min-height: 18px; }
  .btn-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .icon-btn { width: 40px; height: 40px; padding: 0; border-radius: 12px; }
  .account-btn { padding: 0; }
  .avatar { width: 28px; height: 28px; font-size: 13px; }
}

/* Phones: forms, tables and dialogs */
@media (max-width: 560px) {
  h2 { font-size: 15px; }
  .card { padding: 14px; border-radius: 12px; }
  .filters { gap: 10px; padding: 12px; }
  .filters > .btn { flex: 1 1 auto; }
  .date-group .btn { flex: none; }
  .date-group .btn.icon { width: 40px; height: 40px; }
  .date-group input[type="date"] { flex: 1 1 auto; min-width: 0; height: 40px; }
  .date-group { width: 100%; }
  .segmented { width: 100%; }
  .segmented button { flex: 1; }
  .tank-name { font-size: 22px; }
  th, td { padding-left: 8px; padding-right: 8px; }
  .user-form .field { flex: 1 1 100%; }
  .user-form-actions .btn-primary { width: 100%; }
  .row-actions { justify-content: flex-start; }
  .form-dialog { width: calc(100vw - 24px); }
  .dialog-form { padding: 18px; }
  #photo { width: calc(100vw - 16px); max-width: none; }
}
@media (max-width: 560px) {
  /* The headline tile goes first, and a last tile left on its own fills the row. */
  .tile.hero { order: -1; }
  .kpis:has(.tile.hero) .tile:last-child:nth-child(even) { grid-column: 1 / -1; }
  .kpis:not(:has(.tile.hero)) .tile:last-child:nth-child(odd) { grid-column: 1 / -1; }
}
