:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --ink: #15202b;
  --muted: #5b6875;
  --line: #d9e0e6;
  --accent: #0f4c75;
  --accent-ink: #ffffff;
  --water: #2f80c0;
  --ok: #1f7a4d;
  --warn: #a35f00;
  --bad: #b3261e;
  --ok-bg: #e6f4ec;
  --warn-bg: #fdf1df;
  --bad-bg: #fbe9e8;
  --radius: 6px;
  --focus: 0 0 0 3px rgba(47, 128, 192, 0.45);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1418;
    --surface: #161e24;
    --ink: #e6edf3;
    --muted: #93a1ad;
    --line: #2a353e;
    --accent: #5aa9e6;
    --accent-ink: #06121b;
    --water: #4a9fe0;
    --ok: #5cc48e;
    --warn: #e7a74a;
    --bad: #f07a72;
    --ok-bg: #11291d;
    --warn-bg: #2f230f;
    --bad-bg: #331614;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--accent); }
code { font: 0.92em ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
h1 { font-size: 1.45rem; margin: 0 0 12px; line-height: 1.2; }
h2 { font-size: 1.05rem; margin: 0 0 8px; }
p { margin: 0 0 10px; }
.muted { color: var(--muted); }
.hint { display: block; color: var(--muted); font-size: 0.85rem; font-weight: 400; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.topbar {
  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(--accent); color: var(--accent-ink);
}
.brand { color: inherit; font-weight: 700; text-decoration: none; font-size: 1.1rem; }
.topbar nav { display: flex; align-items: center; gap: 4px; }
.topbar nav a, .topbar .linklike {
  color: inherit; text-decoration: none; padding: 6px 8px; border-radius: var(--radius);
  font: inherit; font-size: 0.95rem; background: none; border: 0; cursor: pointer;
}
.topbar nav a:hover, .topbar .linklike:hover { background: rgba(255, 255, 255, 0.14); }
.topbar form { margin: 0; }

main { max-width: 760px; margin: 0 auto; padding: 16px 16px 48px; }
main > section { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
main > section.narrow { max-width: 380px; margin: 32px auto; }
.pagehead, .sectionhead { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.pagehead h1, .sectionhead h2 { margin: 0; min-width: 0; overflow-wrap: anywhere; }

button, .button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 8px 14px; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font: inherit; font-size: 0.95rem; text-decoration: none; cursor: pointer; white-space: nowrap;
}
button:hover, .button:hover { border-color: var(--muted); }
button.primary, .button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
button.danger-text { color: var(--bad); }
button:disabled { opacity: 0.6; cursor: progress; }
:focus-visible { outline: none; box-shadow: var(--focus); }

input, select {
  width: 100%; min-height: 40px; padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); color: var(--ink); font: inherit;
}
input[type="checkbox"], input[type="radio"] { width: 18px; min-height: 18px; height: 18px; margin: 0; accent-color: var(--accent); }
label { display: block; font-weight: 600; font-size: 0.95rem; }
label > input, label > select { margin-top: 4px; }
.stack { display: grid; gap: 14px; }
.form-wide { max-width: 520px; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px 14px; margin: 0; display: grid; gap: 12px; background: var(--surface); }
legend { font-weight: 700; padding: 0 4px; }
label.radio, label.check-line { display: flex; align-items: center; gap: 10px; font-weight: 400; }
.inline-form { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 10px; }
.inline-form form { margin: 0; }
.inline-form label { flex: 1 1 140px; }
.inline-form label > input, .inline-form label > select { margin-top: 0; }

.flash { padding: 10px 12px; border-radius: var(--radius); border: 1px solid transparent; }
.flash-ok { background: var(--ok-bg); color: var(--ok); }
.flash-warn { background: var(--warn-bg); color: var(--warn); }
.flash-bad { background: var(--bad-bg); color: var(--bad); }
.flash a { color: inherit; font-weight: 600; }

.status { font-weight: 600; font-size: 0.9rem; display: inline-flex; align-items: center; gap: 6px; margin: 0; }
.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.status-ok { color: var(--ok); }
.status-warn { color: var(--warn); }
.status-bad { color: var(--bad); }
.status-muted { color: var(--muted); }

/* gauge */
.gauge { width: 28px; height: 44px; flex: none; }
.gauge-big { width: 56px; height: 88px; }
.gauge-shell { fill: none; stroke: var(--line); stroke-width: 2; }
.gauge-fill { fill: var(--water); }
.gauge-warn .gauge-fill { fill: var(--warn); }
.gauge-bad .gauge-fill, .gauge-muted .gauge-fill { fill: var(--muted); }

/* tank list */
.tanklist { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.tanklist li + li { border-top: 1px solid var(--line); }
.tankrow { display: flex; align-items: center; gap: 14px; padding: 12px 14px; color: inherit; text-decoration: none; }
.tankrow:hover { background: var(--bg); }
.tankrow-main { flex: 1; min-width: 0; display: grid; gap: 2px; }
.tankrow-name { font-weight: 700; overflow-wrap: anywhere; }
.tankrow-main .muted { font-size: 0.88rem; }
.tankrow-side { display: grid; justify-items: end; gap: 2px; }
.pct { font-size: 1.6rem; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.pct small { font-size: 0.55em; font-weight: 600; margin-left: 1px; }
.empty-state { text-align: center; padding: 32px 16px; }

/* tank detail */
.hero { display: grid; grid-template-columns: auto 1fr; gap: 6px 18px; align-items: center; }
.hero-main p { margin: 0; }
.hero-pct { font-size: 2.6rem; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.hero-pct small { font-size: 0.45em; margin-left: 2px; }
.hero-litres { color: var(--muted); margin: 4px 0 6px !important; }
.facts { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px 16px; margin: 10px 0 0; padding-top: 12px; border-top: 1px solid var(--line); }
.facts dt { color: var(--muted); font-size: 0.8rem; }
.facts dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; }
.hero-actions { grid-column: 1 / -1; display: flex; align-items: center; gap: 12px; margin-top: 6px; }

.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.segmented a { padding: 6px 12px; text-decoration: none; color: var(--ink); font-size: 0.9rem; }
.segmented a + a { border-left: 1px solid var(--line); }
.segmented a[aria-current="page"] { background: var(--accent); color: var(--accent-ink); }

.chart { display: grid; grid-template-columns: 38px 1fr; grid-template-rows: 190px auto; margin: 0; }
.chart-y { position: relative; font-size: 0.75rem; color: var(--muted); }
.chart-y span { position: absolute; right: 8px; transform: translateY(-50%); font-variant-numeric: tabular-nums; }
.chart-y .y100 { top: 1.9%; } .chart-y .y75 { top: 25.9%; } .chart-y .y50 { top: 50%; } .chart-y .y25 { top: 74.1%; } .chart-y .y0 { top: 98.1%; }
.chart-area { position: relative; min-width: 0; }
.chart-plot { display: block; width: 100%; height: 100%; }
.chart-plot .grid { stroke: var(--line); stroke-width: 1; vector-effect: non-scaling-stroke; }
.chart-plot .threshold { stroke: var(--warn); stroke-width: 1; stroke-dasharray: 4 4; opacity: 0.7; vector-effect: non-scaling-stroke; }
.chart-plot .line { fill: none; stroke: var(--water); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.chart-empty { position: absolute; inset: 0; display: grid; place-items: center; margin: 0; color: var(--muted); }
.chart-x { grid-column: 2; display: flex; white-space: nowrap; justify-content: space-between; gap: 4px; font-size: 0.75rem; color: var(--muted); padding-top: 4px; font-variant-numeric: tabular-nums; }

.levels { display: grid; gap: 8px; margin-bottom: 6px; }
.levelrow {
  display: grid; gap: 8px; align-items: center;
  grid-template-columns: 28px minmax(0, 1.3fr) 96px minmax(0, 1.2fr) 168px;
  grid-template-areas: "chk label pct dir actions";
}
.levelrow label { font-weight: 400; }
.levelrow label > input, .levelrow label > select { margin-top: 0; }
.levelrow .check { grid-area: chk; display: flex; justify-content: center; }
.levelrow .lv-label { grid-area: label; }
.levelrow .lv-pct { grid-area: pct; position: relative; }
.levelrow .lv-dir { grid-area: dir; }
.levelrow .lv-pct input { padding-right: 24px; }
.levelrow .lv-pct .unit { position: absolute; right: 9px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.levelrow-actions { grid-area: actions; display: flex; gap: 6px; justify-content: flex-end; }
.levelrow-new { padding-top: 8px; border-top: 1px dashed var(--line); }

.events { list-style: none; margin: 0; padding: 0; }
.events li { padding: 8px 0; border-top: 1px solid var(--line); }
.events li:first-child { border-top: 0; padding-top: 0; }
.events time { font-size: 0.8rem; color: var(--muted); font-variant-numeric: tabular-nums; }

.secretbox { display: grid; gap: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin: 0 0 16px; }
.secretbox dt { color: var(--muted); font-size: 0.85rem; }
.secretbox dd { margin: 2px 0 0; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.secretbox code { overflow-wrap: anywhere; font-size: 1rem; }
.secretbox .secret { font-weight: 700; }
.steps { padding-left: 20px; }
.steps li { margin-bottom: 6px; }

.chats { list-style: none; margin: 0; padding: 0; }
.chat { padding: 12px 0; border-top: 1px solid var(--line); }
.chat:first-child { border-top: 0; padding-top: 0; }

/* telegram */
h3 { font-size: 0.95rem; margin: 14px 0 6px; }
.linkcode .code {
  font: 700 2rem/1.1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; letter-spacing: 0.12em;
  margin: 4px 0 8px; user-select: all; overflow-wrap: anywhere;
}
.chat-label { display: flex; gap: 8px; align-items: center; }
.chat-label label { flex: 1; min-width: 0; }
.chat-label input { margin-top: 0; font-weight: 600; }
.chat .muted { font-size: 0.88rem; margin: 6px 0 0; overflow-wrap: anywhere; }
.chat .inline-form { margin-top: 8px; }

.tick { border: 0; border-top: 1px solid var(--line); border-radius: 0; padding: 12px 0 0; gap: 10px; }
.tick:first-of-type { border-top: 0; padding-top: 0; }
.tick-head { font-weight: 400; }
.tick-options { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) minmax(0, 1fr); gap: 8px; }
.tick-options label { font-weight: 400; font-size: 0.85rem; color: var(--muted); }
.tick:has(.tick-head input:not(:checked)) .tick-options { opacity: 0.5; }

.grid { width: 100%; border-collapse: collapse; margin-bottom: 12px; }
.grid th, .grid td { border-bottom: 1px solid var(--line); padding: 8px 6px; text-align: left; vertical-align: top; }
.grid thead th { font-size: 0.85rem; color: var(--muted); font-weight: 600; overflow-wrap: anywhere; }
.grid tbody th { font-weight: 600; overflow-wrap: anywhere; }
.grid .cell { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; font-weight: 400; cursor: pointer; min-height: 32px; justify-content: center; }
.grid .cell-chat { display: none; }
.grid .cell-note { font-size: 0.75rem; color: var(--muted); }

@media (max-width: 560px) {
  h1 { font-size: 1.3rem; }
  .levelrow {
    grid-template-columns: 28px minmax(0, 1fr) 88px;
    grid-template-areas: "chk label pct" ". dir dir" ". actions actions";
    padding-bottom: 10px; border-bottom: 1px solid var(--line);
  }
  .levelrow-new { border-bottom: 0; }
  .levelrow-actions { justify-content: flex-start; }
  .hero-pct { font-size: 2.2rem; }
  .chart { grid-template-columns: 34px 1fr; grid-template-rows: 160px auto; }
  .chart-x span:nth-child(even) { visibility: hidden; }
  .tick-options { grid-template-columns: 1fr 1fr; }
  .tick-options label:first-child { grid-column: 1 / -1; }
  /* grid becomes one block per tank, chats listed inside */
  .grid thead { display: none; }
  .grid, .grid tbody, .grid tr, .grid th, .grid td { display: block; }
  .grid tr { border-top: 1px solid var(--line); padding: 10px 0; }
  .grid tbody tr:first-child { border-top: 0; padding-top: 0; }
  .grid th, .grid td { border: 0; padding: 4px 0; }
  .grid tbody th { padding-bottom: 6px; }
  .grid .cell { flex-direction: row; flex-wrap: wrap; align-items: center; justify-content: flex-start; gap: 4px 10px; min-height: 36px; }
  .grid .cell-chat { display: inline; }
  .grid .cell-note { flex-basis: 100%; padding-left: 28px; }
}
