/* Tokens ------------------------------------------------------------------ */
:root {
  color-scheme: light dark;
  /* Chart surface, ink and series: validated palette, keep as is. */
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --accent: #2a78d6;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  /* Status (fixed palette, always paired with a label). */
  --good: #0ca30c;
  --warning: #fab219;
  --critical: #d03b3b;
  /* Interface. */
  --page: #f1f0ec;
  --border: rgba(11, 11, 11, 0.08);
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.06);
  --accent-fill: #1e66c1; /* white text 5.6:1 */
  --accent-ink: #1f5fae;  /* links on the surface 6.2:1 */
  --accent-soft: color-mix(in srgb, var(--accent) 12%, var(--surface));
  --good-soft: color-mix(in srgb, var(--good) 14%, var(--surface));
  --warn-soft: color-mix(in srgb, var(--warning) 24%, var(--surface));
  --critical-soft: color-mix(in srgb, var(--critical) 12%, var(--surface));
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px;
  --r-s: 6px; --r-m: 10px; --r-l: 16px;
  --fs-s: 0.8125rem; --fs-m: 1rem; --fs-l: 1.25rem; --fs-xl: 1.75rem; --fs-hero: 3.25rem;
}
@media (prefers-color-scheme: dark) {
  :root {
    --surface: #1a1a19;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --grid: #2c2c2a;
    --axis: #383835;
    --accent: #3987e5;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --page: #0d0d0d;
    --border: rgba(255, 255, 255, 0.08);
    --shadow: none;
    --accent-ink: #7fb0ee;
  }
}

/* Base ---------------------------------------------------------------------- */
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
}
main { max-width: 960px; margin: 0 auto; padding: var(--s3); }
main.wide { max-width: 1680px; }
h1 { font-size: 1.5rem; margin: var(--s2) 0 var(--s3); }
h2 { font-size: var(--fs-l); margin: 0 0 var(--s3); }
h3 { font-size: var(--fs-s); color: var(--ink-2); margin: var(--s4) 0 var(--s1); }
a { color: var(--accent-ink); }
small, .sub, .note { color: var(--ink-2); }
.sub { font-size: var(--fs-s); }
.note { white-space: pre-line; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.head { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); flex-wrap: wrap; margin-bottom: var(--s3); }
.head :is(h1, h2) { margin: 0; }
footer { display: flex; justify-content: center; flex-wrap: wrap; gap: var(--s2); padding: var(--s4) 0; }
footer form { margin: 0; }
footer .version { flex-basis: 100%; text-align: center; color: var(--ink-2); font-size: var(--fs-s); }

/* Navigation: top bar on desktop, tab bar at the bottom on phones. */
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.ico { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; flex: none; }
header.top { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
header.top nav { display: flex; align-items: center; max-width: 960px; margin: 0 auto; padding: 0 var(--s3); }
header.top.wide nav { max-width: 1680px; }
.brand { display: flex; align-items: center; gap: 6px; font-weight: 700; color: var(--ink); text-decoration: none; margin-right: var(--s4); }
.brand .ico { color: var(--accent); }
.tab { display: flex; align-items: center; padding: 14px 10px; color: var(--ink-2); text-decoration: none; border-bottom: 2px solid transparent; }
.tab .ico { display: none; }
.tab[aria-current] { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }
@media (max-width: 640px) {
  header.top { position: fixed; inset: auto 0 0 0; border-top: 1px solid var(--border); border-bottom: 0; padding-bottom: env(safe-area-inset-bottom); }
  header.top nav { padding: 0; }
  .brand { display: none; }
  .tab { flex: 1; flex-direction: column; justify-content: center; gap: 2px; padding: 6px 0; min-height: 56px; font-size: 0.75rem; border: 0; }
  .tab .ico { display: block; }
  .tab[aria-current] { color: var(--accent-ink); }
  main { padding-bottom: calc(88px + env(safe-area-inset-bottom)); }
}

/* Cards, tiles, pills ------------------------------------------------------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-l); box-shadow: var(--shadow); padding: var(--s4); margin-bottom: var(--s3); }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s3); margin-bottom: var(--s3); }
.tiles .card { margin: 0; }
.tile { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.tile.stock { grid-column: 1 / -1; }
@media (min-width: 900px) {
  .tiles { grid-template-columns: 1.5fr 1fr 1fr; }
  .tile.stock { grid-column: auto; grid-row: span 2; }
}
.label { font-size: var(--fs-s); font-weight: 600; color: var(--ink-2); }
.hero { font-size: var(--fs-hero); font-weight: 700; line-height: 1.05; white-space: nowrap; }
.hero .unit { font-size: 0.45em; font-weight: 600; color: var(--ink-2); }
.value { font-size: var(--fs-xl); font-weight: 700; line-height: 1.15; font-variant-numeric: tabular-nums; }
.value small { font-size: var(--fs-s); font-weight: 500; }
.proj { display: flex; align-items: center; flex-wrap: wrap; gap: var(--s2); margin: var(--s3) 0 2px; padding-top: var(--s3); border-top: 1px solid var(--grid); font-weight: 600; }
.proj::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--good); }
.proj.warn::before { background: var(--warning); }
meter { appearance: none; width: 100%; height: 6px; margin: 6px 0 2px; border: 0; border-radius: 3px; background: var(--grid); }
meter::-webkit-meter-bar { background: var(--grid); border: 0; height: 6px; border-radius: 3px; }
meter::-webkit-meter-optimum-value { background: var(--ink-2); border-radius: 3px; }
meter::-moz-meter-bar { background: var(--ink-2); border-radius: 3px; }
.due meter::-webkit-meter-optimum-value { background: var(--warning); }
.due meter::-moz-meter-bar { background: var(--warning); }
.pill { display: inline-block; font-size: var(--fs-s); font-weight: 600; line-height: 1.6; padding: 0 8px; border-radius: 999px; background: var(--grid); color: var(--ink); white-space: nowrap; }
.pill.warn { background: var(--warn-soft); }
.pill.good { background: var(--good-soft); }
.pill.accent { background: var(--accent-soft); color: var(--accent-ink); }
.pills { display: flex; flex-wrap: wrap; gap: var(--s2); margin-bottom: var(--s3); }
.zero { color: var(--muted); }
.alert { color: var(--critical); font-weight: 700; }

/* Messages. */
.flash, .error { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); border-radius: var(--r-m); padding: var(--s2) var(--s2) var(--s2) var(--s4); margin: 0 0 var(--s3); font-weight: 600; }
.flash { background: var(--good-soft); border: 1px solid color-mix(in srgb, var(--good) 35%, transparent); }
.error { background: var(--critical-soft); border: 1px solid color-mix(in srgb, var(--critical) 40%, transparent); min-height: 44px; }
.flash form { margin: 0; }

/* Buttons and fields -------------------------------------------------------- */
button, .button, input, select, textarea { font: inherit; color: inherit; }
button, .button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 8px 16px; border: 0; border-radius: var(--r-m);
  background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; text-decoration: none; cursor: pointer;
}
button:hover, .button:hover { background: color-mix(in srgb, var(--accent) 20%, var(--surface)); }
.primary, .primary:hover { background: var(--accent-fill); color: #fff; }
.primary:hover { background: color-mix(in srgb, var(--accent-fill) 85%, #000); }
.ghost, .link { background: transparent; color: var(--ink-2); }
.ghost:hover, .link:hover { background: var(--grid); }
.danger, .danger:hover { background: var(--critical); color: #fff; }
.small { min-height: 32px; padding: 4px 10px; font-size: var(--fs-s); }
.block { width: 100%; }
input, select, textarea { min-height: 44px; padding: 8px 10px; border: 1px solid var(--axis); border-radius: var(--r-m); background: var(--surface); width: 100%; }
:is(input, select, textarea):focus { outline: 0; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
label { display: flex; flex-direction: column; gap: 4px; margin-bottom: var(--s3); font-weight: 500; }
label small { font-weight: 400; }
label.inline { flex-direction: row; align-items: center; gap: var(--s2); }
label.inline input[type="checkbox"] { width: auto; min-height: 0; accent-color: var(--critical); }
.form { max-width: 560px; }
.actions-row { display: flex; gap: var(--s2); align-items: center; }
.actions-row .primary { flex: 1; }
.danger-zone { max-width: 560px; }
details.danger-zone > summary { cursor: pointer; color: var(--ink-2); min-height: 32px; }
details.danger-zone[open] > summary { margin-bottom: var(--s3); }

/* Login. */
.login { max-width: 360px; margin: 12vh auto 0; text-align: center; padding: var(--s5); }
.login h1 { margin: var(--s2) 0 0; }
.login .sub { margin: 0 0 var(--s5); }
.login label { text-align: left; }
.mark { width: 48px; height: 48px; color: var(--accent); stroke-width: 1.5; }
button[aria-busy="true"] { cursor: progress; }
button[aria-busy="true"]::before {
  content: ""; width: 1em; height: 1em; border: 2px solid currentColor; border-right-color: transparent;
  border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(1turn); } }
@media (prefers-reduced-motion: reduce) { button[aria-busy="true"]::before { animation-duration: 2.4s; } }

/* Home: quick entry ------------------------------------------------------- */
.quick { display: flex; flex-direction: column; gap: var(--s3); }
.quick .head { margin: 0; }
.when > summary { list-style: none; cursor: pointer; color: var(--accent-ink); font-weight: 600; min-height: 44px; display: flex; align-items: center; }
.when > summary::-webkit-details-marker { display: none; }
.when > summary::after { content: "▾"; margin-left: 4px; }
.when input { margin-top: var(--s1); }
.refill { display: flex; flex-wrap: wrap; gap: var(--s2); }
.presets { order: -1; display: flex; gap: var(--s2); flex: 1 1 100%; }
.presets button { flex: 1; min-height: 56px; font-size: var(--fs-l); }
.custom, .ash { display: flex; gap: var(--s2); flex: 1 1 100%; }
.custom input { flex: 1; width: auto; }
.ash button { flex: 1; }
.ash select { width: auto; }

/* Event list (home, journal, purchases) ----------------------------------- */
.events { list-style: none; margin: 0; padding: 0; }
.events li + li { border-top: 1px solid var(--grid); }
.events a { display: grid; grid-template-columns: 3.75rem 1fr; gap: 0 var(--s3); align-items: start; padding: var(--s2) 0; min-height: 48px; color: inherit; text-decoration: none; }
.events a:hover .badge { text-decoration: underline; }
.events time { font-size: var(--fs-s); font-weight: 600; line-height: 1.3; padding-top: 3px; }
.events time small { display: block; font-weight: 400; color: var(--muted); }
.events .body { min-width: 0; }
.events b { font-weight: 500; }
.events .note, .clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; font-size: var(--fs-s); }
.events .empty { padding: var(--s3) 0; color: var(--ink-2); }
.badge { font-weight: 600; }
.badge::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; background: var(--dot, var(--muted)); }
.t-remplissage { --dot: var(--accent); }
.t-achat, .t-inventaire { --dot: var(--good); }
.t-intervention, .t-entretien { --dot: var(--warning); }
.t-cendrier { --dot: var(--ink-2); }
.t-allumage, .t-extinction { --dot: var(--ink); }
.t-panne { --dot: var(--critical); }
.t-absence { --dot: var(--muted); }
.t-panne .badge { color: var(--critical); }
.t-note .badge::before { background: none; box-shadow: inset 0 0 0 1.5px var(--muted); }

/* Journal filters. */
.chips { display: flex; gap: var(--s2); overflow-x: auto; padding-bottom: var(--s1); margin-bottom: var(--s2); scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips a { flex: none; display: inline-flex; align-items: center; min-height: 40px; padding: 0 14px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); color: var(--ink); font-size: var(--fs-s); text-decoration: none; }
.chips a[aria-current] { background: var(--accent-fill); border-color: transparent; color: #fff; font-weight: 600; }

/* Tables ------------------------------------------------------------------ */
.scroll { overflow-x: auto; }
table.data { border-collapse: collapse; width: 100%; font-size: var(--fs-s); }
table.data.compact { width: auto; min-width: 50%; }
table.data :is(th, td) { padding: 10px 8px; border-bottom: 1px solid var(--grid); vertical-align: top; text-align: left; }
table.data td { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.data td.text { text-align: left; white-space: normal; }
table.data thead th { color: var(--ink-2); font-weight: 600; border-bottom-color: var(--axis); white-space: nowrap; }
table.data thead th:not(:first-child) { text-align: right; }
table.data thead th.text { text-align: left; }
table.data th small { font-weight: 400; }
table.data td.actions { white-space: nowrap; }
@media (max-width: 640px) {
  table.stack, table.stack tbody { display: block; }
  table.stack thead { display: none; }
  table.stack tr { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s2) var(--s4); padding: var(--s3) 0; border-bottom: 1px solid var(--grid); }
  table.stack tbody th { grid-column: 1 / -1; font-size: var(--fs-m); border: 0; padding: 0; }
  table.stack td { border: 0; padding: 0; text-align: left; white-space: normal; }
  table.stack td[data-label]::before { content: attr(data-label); display: block; font-size: 0.75rem; color: var(--ink-2); }
  table.stack td.actions { grid-column: 1 / -1; }
}
details > summary { cursor: pointer; }
details.year > summary { padding: var(--s2) 0; font-weight: 600; color: var(--ink-2); min-height: 44px; display: flex; align-items: center; }

/* Quote sheet (desktop) ---------------------------------------------------- */
table.sheet { border-collapse: separate; border-spacing: 0; width: 100%; font-size: var(--fs-s); }
table.sheet :is(th, td) { height: 44px; padding: 0 3px; border-bottom: 1px solid var(--grid); white-space: nowrap; text-align: left; background: var(--surface); }
table.sheet thead th { height: 36px; padding: 0 8px; color: var(--ink-2); font-weight: 600; border-bottom-color: var(--axis); }
table.sheet thead th.num { text-align: right; }
table.sheet :is(td, th):first-child { position: sticky; left: 0; z-index: 1; }
table.sheet :is(input, select) { width: auto; min-height: 34px; padding: 4px 6px; border-color: transparent; background: transparent; border-radius: var(--r-s); }
table.sheet input[type="date"] { width: 9.25em; }
table.sheet tr:hover :is(input, select), table.sheet tr.new :is(input, select) { border-color: var(--grid); }
table.sheet :is(input, select):focus { border-color: var(--accent); background: var(--surface); }
table.sheet td.out { text-align: right; font-variant-numeric: tabular-nums; padding: 0 6px; }
table.sheet td.out small { display: block; }
table.sheet td.perkg { font-size: var(--fs-m); font-weight: 700; background: var(--accent-soft); }
.star { color: var(--good); }
.qty { display: flex; align-items: center; gap: 2px; color: var(--muted); }
tr.quote { scroll-margin-top: 64px; }
tr.best td { background: color-mix(in srgb, var(--good) 9%, var(--surface)); }
tr.best td.perkg { background: color-mix(in srgb, var(--good) 18%, var(--surface)); }
tr.best td:first-child { box-shadow: inset 3px 0 0 var(--good); }
tr.new td { border-top: 2px solid var(--axis); }
.sheet .actions { display: flex; align-items: center; gap: var(--s1); height: 44px; }
/* With the script, a row shows "Enregistrer" only once modified, in place of its other actions. */
.js tr.quote:not(.dirty):not(.new) .save, .js tr.dirty .idle { display: none; }
tr.dirty .save { background: var(--accent-fill); color: #fff; }
.icon-btn { width: 32px; min-height: 32px; padding: 0; background: transparent; color: var(--ink-2); }
.icon-btn:hover { background: var(--critical-soft); color: var(--critical); }
.hint { font-size: var(--fs-s); color: var(--ink-2); margin: var(--s2) 0 0; }

/* Chart ------------------------------------------------------------------- */
.legend { list-style: none; display: flex; flex-wrap: wrap; gap: 4px 16px; padding: 0; margin: 0 0 8px; font-size: var(--fs-s); color: var(--ink-2); }
.key { display: inline-block; width: 16px; height: 3px; border-radius: 2px; margin-right: 6px; vertical-align: middle; background: var(--c); }
.chart { width: 100%; height: auto; display: block; }
.s1 { --c: var(--series-1); }
.s2 { --c: var(--series-2); }
.s3 { --c: var(--series-3); }
.s4 { --c: var(--series-4); }
/* The SVG scales with the card width: strokes keep their real size, text
   sizes (in viewBox units, 640 wide) are set per screen width to stay ~11px. */
.grid, .axis, .line, .dot { vector-effect: non-scaling-stroke; }
.grid { stroke: var(--grid); stroke-width: 1; }
.axis { stroke: var(--axis); stroke-width: 1; }
.tick { fill: var(--muted); font-size: 8.5px; font-variant-numeric: tabular-nums; }
.line { fill: none; stroke: var(--c); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.dot { fill: var(--c); stroke: var(--surface); stroke-width: 2; }
.end { fill: var(--ink); font-size: 9.5px; font-weight: 600; }
.bar { fill: var(--series-1); }
.bar:hover { fill: var(--accent-fill); }
.band { fill: var(--grid); opacity: 0.8; }
.forecast-band { fill: var(--accent-soft); }
.base { stroke: var(--axis); stroke-width: 1; vector-effect: non-scaling-stroke; }
.temp { fill: none; stroke: var(--series-2); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.temp.forecast { stroke-dasharray: 4 3; }
/* Home: the previous seasons as one range, the projection, the bags available. */
.range { --range: color-mix(in srgb, var(--ink) 12%, transparent); fill: var(--range); stroke: var(--range); stroke-width: 1; vector-effect: non-scaling-stroke; }
.line.projection { stroke-dasharray: 5 4; }
.available { stroke: var(--ink-2); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.runout { fill: var(--surface); stroke: var(--ink); stroke-width: 2; vector-effect: non-scaling-stroke; }
.key.dashed { background: repeating-linear-gradient(90deg, var(--c) 0 5px, transparent 5px 8px); }
.key.range { height: 10px; background: color-mix(in srgb, var(--ink) 12%, transparent); }
.key.available { height: 2px; background: var(--ink-2); }
.key.temp { background: var(--series-2); }
.chart-title { margin-top: var(--s5); }
@media (max-width: 900px) {
  .tick { font-size: 11px; }
  .end { font-size: 12px; }
}
@media (max-width: 600px) {
  .tick { font-size: 19px; }
  .end { font-size: 21px; }
  .dot { r: 7px; }
  .available-label { display: none; } /* in the legend; no room for it here */
}

@media print {
  header.top, form, .button, .chips { display: none; }
  .card { border: 0; padding: 0; box-shadow: none; }
}
