:root {
  --bg: #f7f7f5;
  --surface: #fcfcfb;
  --border: #e6e5e0;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #74736e;
  --grid: #ecebe7;
  --axis: #c9c8c2;
  --series: #2a78d6;
  --series-soft: #2a78d61f;
  --critical: #d03b3b;
  --good: #0a8a0a;
  --radius: 14px;
  --hatch: rgba(17, 24, 33, .10);
  --font-display: "Chakra Petch", "Bahnschrift", "Segoe UI", system-ui, sans-serif;
  --font-body: "Barlow", "Segoe UI", system-ui, -apple-system, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121211;
    --surface: #1a1a19;
    --border: #2c2c2a;
    --text: #ffffff;
    --text-2: #c3c2b7;
    --muted: #9a9990;
    --grid: #262624;
    --axis: #44443f;
    --series: #3987e5;
    --series-soft: #3987e526;
    --critical: #e66767;
    --good: #3fbf3f;
    --hatch: rgba(238, 241, 245, .10);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 16px/1.45 var(--font-body);
  font-variant-numeric: tabular-nums;
}
main {
  max-width: 880px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 32px max(16px, env(safe-area-inset-left));
  display: grid;
  gap: 14px;
}
h1, h2 { font-family: var(--font-display); font-weight: 600; letter-spacing: .01em; margin: 0; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.1rem; }
.hero-value, .tile .value, .fuel-tiles .value, .tooltip strong, .heat, .segmented button { font-family: var(--font-display); }
a { color: var(--series); }
.muted { color: var(--muted); font-size: 0.85rem; }
.label { color: var(--text-2); font-size: 0.8rem; }

.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.fetch { display: flex; align-items: center; gap: 8px; }
button {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; cursor: pointer;
}
#refresh { width: 40px; height: 40px; display: grid; place-items: center; }
#refresh:hover { border-color: var(--axis); }
#refresh.spin svg { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { #refresh.spin svg { animation: none; } }

.banner {
  margin: 0; padding: 10px 14px; border-radius: 10px;
  border: 1px solid var(--critical); color: var(--text); background: var(--surface);
  font-size: 0.9rem;
}
.banner::before { content: "⚠ "; color: var(--critical); }

.hero, .card, .tile {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.hero { padding: 18px 18px 16px; }
.hero-value { font-size: clamp(2.2rem, 9vw, 3.2rem); font-weight: 650; letter-spacing: -0.02em; line-height: 1.1; margin: 2px 0 4px; }
.hero-value .unit { font-size: 1rem; font-weight: 500; color: var(--text-2); }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
@media (max-width: 480px) { .tiles { grid-template-columns: 1fr 1fr; } .tiles .tile:last-child { grid-column: span 2; } }
.tile { padding: 12px 14px; }
.tile .value { font-size: 1.35rem; font-weight: 600; margin-top: 2px; }
.tile .value small { font-size: 0.8rem; font-weight: 500; color: var(--text-2); }

.card { padding: 14px 14px 12px; display: grid; gap: 10px; min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.note { margin: 0; font-size: 0.8rem; color: var(--muted); }
.empty { margin: 0; color: var(--muted); font-size: 0.9rem; }

.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; padding: 2px; gap: 2px; }
.segmented button { border: 0; padding: 6px 10px; min-height: 34px; border-radius: 8px; background: transparent; color: var(--text-2); }
.segmented button[aria-checked="true"] { background: var(--series-soft); color: var(--text); font-weight: 600; }

/* charts */
.chart { position: relative; width: 100%; min-width: 0; }
.chart-svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart-svg:focus { outline: none; }
.chart-svg:focus-visible { outline: 2px solid var(--series); outline-offset: 4px; border-radius: 4px; }
.axis text { fill: var(--muted); font-size: 11px; }
.grid { stroke: var(--grid); stroke-width: 1; }
.baseline { stroke: var(--axis); stroke-width: 1; }
.series-line { fill: none; stroke: var(--series); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.series-dot { fill: var(--series); stroke: var(--surface); stroke-width: 2; }
.series-dot.hot { stroke-width: 2.5; }
.series-bar { fill: var(--series); }
.bar:hover .series-bar, .bar:focus-within .series-bar { opacity: 0.75; }
.bar-hit:focus { outline: none; }
.bar-hit:focus-visible { outline: 2px solid var(--series); }
.crosshair { stroke: var(--axis); stroke-width: 1; stroke-dasharray: 3 3; }
.hit { fill: transparent; pointer-events: all; }
.tooltip {
  position: absolute; pointer-events: none; z-index: 2;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 10px; box-shadow: 0 4px 16px #0000001f; white-space: nowrap;
  display: grid; font-size: 0.8rem;
}
.tooltip strong { color: var(--text); font-size: 0.95rem; }
.tooltip span { color: var(--text-2); }
.tooltip[hidden] { display: none; }

/* service */
.service-form { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 420px) { .service-form { grid-template-columns: 1fr; } }
.service-form label { display: grid; gap: 4px; font-size: 0.8rem; color: var(--text-2); }
input {
  font: inherit; font-size: 16px; color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 10px; padding: 9px 12px; width: 100%;
}
input:focus { outline: 2px solid var(--series); outline-offset: -1px; }
.svc-result { font-size: 0.9rem; }
.svc-result strong { color: var(--text); font-size: 1.1rem; }
.svc-result .overdue { color: var(--critical); font-weight: 600; }

/* table */
.table-wrap { overflow-x: auto; max-height: 420px; overflow-y: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { padding: 8px 6px; text-align: left; border-bottom: 1px solid var(--border); }
th { position: sticky; top: 0; background: var(--surface); color: var(--text-2); font-weight: 500; font-size: 0.8rem; }
.num { text-align: right; }
td.num.zero, td.num.none { color: var(--muted); }
.tag { display: block; color: var(--muted); font-size: 0.75rem; }

footer { text-align: center; padding-top: 4px; }

/* fuel */
.small-btn { padding: 6px 12px; min-height: 34px; font-size: 0.85rem; }
.primary-btn { padding: 9px 18px; min-height: 40px; background: var(--series); color: #fff; border-color: transparent; font-weight: 600; }
.primary-btn:disabled { opacity: 0.6; cursor: default; }
.fuel-form { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 12px; border: 1px solid var(--border); border-radius: 10px; }
.fuel-form[hidden] { display: none; }
.fuel-form label { display: grid; gap: 4px; font-size: 0.8rem; color: var(--text-2); }
.fuel-form label[hidden] { display: none; }
.fuel-form .wide { grid-column: 1 / -1; }
.fuel-form .opt { color: var(--muted); font-size: 0.75rem; }
.fuel-actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
@media (max-width: 420px) { .fuel-form { grid-template-columns: 1fr; } }
.form-msg { margin: 0; font-size: 0.85rem; color: var(--text-2); min-height: 1em; }
.form-msg:empty { display: none; }
.form-msg.bad { color: var(--critical); }
.fuel-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px 14px; }
.fuel-tiles .value { font-size: 1.15rem; font-weight: 600; }
.fuel-tiles .value small { font-size: 0.75rem; font-weight: 500; color: var(--text-2); }
.del-btn { border: 0; background: transparent; color: var(--muted); min-width: 32px; min-height: 32px; padding: 0 6px; font-size: 1rem; }
.del-btn:hover { color: var(--critical); }
.del-btn.armed { color: var(--critical); font-size: 0.8rem; font-weight: 600; border: 1px solid var(--critical); border-radius: 8px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
#fuel .table-wrap table { min-width: 560px; }

/* service sync */
.service-form .wide { grid-column: 1 / -1; }
.service-form label[hidden] { display: none; }
.service-form .opt { color: var(--muted); font-size: 0.75rem; }

/* month-by-month heatmap */
.heatmap { position: relative; min-width: 0; }
.heat-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.heat { border-collapse: separate; border-spacing: 2px; font-size: 13px; width: 100%; }
.heat th { padding: 4px 2px; text-align: center; color: var(--muted); font-weight: 500; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; }
.heat td { padding: 0; }
.heat td.cell { height: 36px; min-width: 46px; text-align: center; border-radius: 4px; font-weight: 500; cursor: default; }
.heat td.cell.empty { background: transparent; }
.heat td.cell.sparse { font-style: italic; background-image: repeating-linear-gradient(135deg, var(--hatch) 0 3px, transparent 3px 6px); }
.heat td.cell.partial { box-shadow: inset 0 0 0 1.5px var(--muted); }
.heat td.cell:focus { outline: none; }
.heat td.cell:focus-visible, .heat td.cell:hover { outline: 2px solid var(--text); outline-offset: 1px; }
.heat .yr { position: sticky; left: 0; z-index: 1; background: var(--surface); text-align: left; padding-right: 8px; color: var(--text); font: 600 14px var(--font-display); letter-spacing: 0; text-transform: none; }
.heat thead .yr { color: transparent; }
.heat .tot { text-align: right; padding-left: 10px; font-weight: 600; white-space: nowrap; }
.heat thead .tot { text-align: right; }

/* consent banner (same markup/behaviour as butenasg.uk, styled for this app) */
.consent-banner {
  position: fixed; bottom: max(16px, env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
  z-index: 200; width: min(640px, calc(100vw - 32px));
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  font: 400 14px/1.45 var(--font-body); color: var(--text-2);
  box-shadow: 0 8px 32px rgba(0, 0, 0, .35);
}
.consent-banner p { margin: 0; flex: 1; min-width: 200px; }
.consent-banner .cb-actions { display: flex; gap: 8px; flex-shrink: 0; margin-left: auto; }
.consent-banner button {
  font: 600 12px var(--font-display); text-transform: uppercase; letter-spacing: .08em;
  min-height: 38px; padding: 0 16px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--border); background: transparent; color: var(--text-2);
}
.consent-banner .btn-accept { background: var(--series); border-color: var(--series); color: #fff; }
.consent-banner .btn-accept:hover { filter: brightness(1.08); }
.consent-banner .btn-decline:hover { color: var(--text); border-color: var(--axis); }
@media print { .consent-banner { display: none; } }

/* owner unlock (footer) */
footer { display: grid; gap: 8px; justify-items: center; }
.link-btn { border: 0; background: none; padding: 4px 6px; color: var(--muted); font: inherit; font-size: 0.85rem; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.link-btn:hover { color: var(--text); }
.owner { display: grid; gap: 8px; justify-items: center; }
.unlock-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: center; }
.unlock-form input { width: 200px; }
.unlock-form .form-msg { flex-basis: 100%; text-align: center; }
