/* Pflanzen – the only stylesheet. Every page is built from the components in templates/_ui.html; there is no
   page-specific CSS. Sizes come only from the tokens below (spacing scale 4/8/12/16/24/32, controls 44 px).
   Anti-jump rules: fixed heights for head, tabs, rows, controls and action bar; buttons keep their size when their
   label changes; images carry their size; scrollbar space is always reserved; messages never push content. */

/* ---------- 1. Tokens ---------- */
:root {
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px;
  --control: 44px;            /* height of every control, minimum tap size */
  --radius: 8px;              /* controls */
  --radius-card: 12px;
  --head: 56px;               /* page head */
  --tabs: 44px;
  --row: 56px;                /* minimum height of a list row */
  --bottom-nav: 64px;
  --sidebar: 240px;
  --content-max: 1200px;
  --gutter: 16px;
  --safe-bottom: max(env(safe-area-inset-bottom), 8px);
  --btn-min: 120px;           /* buttons in the action bar and cards keep one width */
  --font: Jost, system-ui, sans-serif;
  --weight-text: 420; --weight-medium: 520; --weight-strong: 580;

  --bg: #f5f6f1;
  --surface: #ffffff;
  --text: #1b1d1a;
  --muted: #5b5f57;
  --line: #dde0d6;
  --accent-text: #ffffff;
  --ok: #2c6e45;    --ok-soft: #e3f1e7;
  --warn: #8a5a00;  --warn-soft: #fbf0d9;
  --danger: #b3261e; --danger-soft: #fbe7e5;
  --shadow: 0 1px 2px rgb(27 29 26 / 6%), 0 1px 3px rgb(27 29 26 / 8%);
  color-scheme: light;
}
/* Accents (WCAG ≥ 4.5:1 against --surface in light and dark) */
:root, :root[data-accent="green"] { --accent: #2f7a4b; --accent-soft: #e4f1e8; }
:root[data-accent="blue"]    { --accent: #3a5a9c; --accent-soft: #e6ecf7; }
:root[data-accent="orange"]  { --accent: #b34d14; --accent-soft: #fbeadf; }
:root[data-accent="purple"]  { --accent: #5b4596; --accent-soft: #ece8f5; }
:root[data-accent="magenta"] { --accent: #a3427c; --accent-soft: #f6e7f0; }

@font-face {
  font-family: "Jost";  /* SIL OFL, fonts/jost-OFL.txt */
  font-style: normal;
  font-display: swap;
  font-weight: 100 900;
  src: url("fonts/jost.woff2") format("woff2");
}

/* Dark: by device, data-theme forces light or dark. The block is repeated because CSS has no mixin. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121411; --surface: #1b1d1a; --text: #eef0e8; --muted: #a6aa9f; --line: #393c35;
    --accent-text: #121411;
    --ok: #74c793; --ok-soft: #1c3324; --warn: #e2b04f; --warn-soft: #3a2e14; --danger: #f2897c; --danger-soft: #3a1c1a;
    --shadow: none; color-scheme: dark;
  }
  :root:not([data-theme="light"]), :root:not([data-theme="light"])[data-accent="green"] { --accent: #6cc58f; --accent-soft: #1e3326; }
  :root:not([data-theme="light"])[data-accent="blue"]    { --accent: #9db8ec; --accent-soft: #222d43; }
  :root:not([data-theme="light"])[data-accent="orange"]  { --accent: #f0a173; --accent-soft: #3a2618; }
  :root:not([data-theme="light"])[data-accent="purple"]  { --accent: #b4a3e8; --accent-soft: #2a2440; }
  :root:not([data-theme="light"])[data-accent="magenta"] { --accent: #e79cc8; --accent-soft: #3a2132; }
}
:root[data-theme="dark"] {
  --bg: #121411; --surface: #1b1d1a; --text: #eef0e8; --muted: #a6aa9f; --line: #393c35;
  --accent-text: #121411;
  --ok: #74c793; --ok-soft: #1c3324; --warn: #e2b04f; --warn-soft: #3a2e14; --danger: #f2897c; --danger-soft: #3a1c1a;
  --shadow: none; color-scheme: dark;
}
:root[data-theme="dark"], :root[data-theme="dark"][data-accent="green"] { --accent: #6cc58f; --accent-soft: #1e3326; }
:root[data-theme="dark"][data-accent="blue"]    { --accent: #9db8ec; --accent-soft: #222d43; }
:root[data-theme="dark"][data-accent="orange"]  { --accent: #f0a173; --accent-soft: #3a2618; }
:root[data-theme="dark"][data-accent="purple"]  { --accent: #b4a3e8; --accent-soft: #2a2440; }
:root[data-theme="dark"][data-accent="magenta"] { --accent: #e79cc8; --accent-soft: #3a2132; }

/* ---------- 2. Base ---------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scrollbar-gutter: stable; }
body {
  margin: 0; min-height: 100dvh;
  font: var(--weight-text) 16px/1.5 var(--font);
  background: var(--bg); color: var(--text);
  font-variant-numeric: tabular-nums;
}
a { color: var(--accent); }
h1, h2, h3, p, ul, ol, fieldset { margin: 0; }
ul, ol { padding: 0; list-style: none; }
fieldset { border: 0; padding: 0; min-width: 0; }
legend { padding: 0; }
strong, b { font-weight: var(--weight-medium); }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .92em; overflow-wrap: anywhere; }
img { display: block; max-width: 100%; }
.icon { flex: none; display: block; }
.muted { color: var(--muted); }
.small { font-size: .875rem; line-height: 1.43; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- 3. Shell: sidebar (wide) or bottom navigation (phone) ---------- */
.shell { display: flex; min-height: 100dvh; }
.sidebar { display: none; }
.main {
  flex: 1; min-width: 0; display: flex; flex-direction: column;
  padding: 0 var(--gutter) calc(var(--bottom-nav) + var(--safe-bottom));
}
.main > * { width: 100%; max-width: var(--content-max); margin-inline: auto; }

.bottom-nav {
  position: fixed; inset: auto 0 0 0; z-index: 20;
  display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr);
  height: calc(var(--bottom-nav) + var(--safe-bottom)); padding-bottom: var(--safe-bottom);
  background: var(--surface); border-top: 1px solid var(--line);
}
.bottom-nav a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: .75rem; line-height: 1;
}
.bottom-nav a[aria-current="page"] { color: var(--accent); font-weight: var(--weight-medium); }

@media (min-width: 1024px) {
  .sidebar {
    position: sticky; top: 0; height: 100dvh; width: var(--sidebar); flex: none;
    display: flex; flex-direction: column; gap: var(--s5); padding: var(--s5) var(--s4);
    background: var(--surface); border-right: 1px solid var(--line);
  }
  .bottom-nav { display: none; }
  .main { padding: 0 var(--s6) var(--s6); }
}
.brand { display: flex; align-items: center; gap: var(--s2); height: var(--control); padding: 0 var(--s2);
  color: var(--text); text-decoration: none; font-weight: var(--weight-strong); font-size: 1.125rem; }
.brand .icon { color: var(--accent); }
.side-nav { flex: 1; display: flex; flex-direction: column; gap: var(--s1); }
.side-nav a {
  display: flex; align-items: center; gap: var(--s3); height: var(--control); padding: 0 var(--s3);
  border-radius: var(--radius); color: var(--text); text-decoration: none;
}
.side-nav a:hover { background: var(--bg); }
.side-nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: var(--weight-medium); }
.side-user { display: flex; align-items: center; gap: var(--s3); min-height: var(--row); padding: 0 var(--s2); border-top: 1px solid var(--line); padding-top: var(--s3); }
.side-user > span:not(.avatar) { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- 4. Page head and tabs (fixed heights: the content always starts at the same y) ---------- */
.page-head { display: grid; grid-template-columns: minmax(0, 1fr) var(--control); align-items: center; gap: var(--s3); height: var(--head); }
.page-title { font-size: 1.5rem; line-height: 2rem; font-weight: var(--weight-strong); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.head-slot { width: var(--control); height: var(--control); }
.tabs {
  display: flex; gap: var(--s1); height: var(--tabs); overflow-x: auto; scrollbar-width: none;
  border-bottom: 1px solid var(--line); margin-bottom: var(--s4);
}
.tabs::-webkit-scrollbar { display: none; }
.tabs a {
  flex: none; display: flex; align-items: center; height: var(--tabs); padding: 0 var(--s3);
  color: var(--muted); text-decoration: none; border-bottom: 2px solid transparent; white-space: nowrap;
}
.tabs a[aria-current="page"] { color: var(--accent); border-bottom-color: var(--accent); font-weight: var(--weight-medium); }
.page-head + .content { margin-top: var(--s2); }

/* ---------- 5. Grid: 4 / 8 / 12 columns by available content width ---------- */
.content { container-type: inline-size; flex: 1; }
.grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--s4); align-items: start; }
.span-full, .span-half, .span-third { grid-column: 1 / -1; }
@container (min-width: 680px) {
  .grid { grid-template-columns: repeat(8, minmax(0, 1fr)); }
  .span-half, .span-third { grid-column: span 4; }
}
@container (min-width: 1000px) {
  .grid { grid-template-columns: repeat(12, minmax(0, 1fr)); }
  .span-half { grid-column: span 6; }
  .span-third { grid-column: span 4; }
}

/* ---------- 6. Card ---------- */
.card {
  display: flex; flex-direction: column; gap: var(--s3); min-width: 0;
  padding: var(--s4); background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-card); box-shadow: var(--shadow);
}
.card-title { font-size: 1.125rem; line-height: 1.75rem; font-weight: var(--weight-strong); }
.card-danger { border-color: var(--danger); }
.stack { display: flex; flex-direction: column; gap: var(--s3); }

/* ---------- 7. List rows: text left, actions right, fixed minimum height ---------- */
.list { display: flex; flex-direction: column; }
.row {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: var(--s3);
  min-height: var(--row); padding: var(--s2) 0; border-top: 1px solid var(--line);
}
.list > .row:first-child { border-top: 0; }
.list > li:not(.row) { padding-bottom: var(--s3); }  /* form or details belonging to the row above */
.row-lead { display: grid; grid-template-columns: var(--control) minmax(0, 1fr) auto; }
.row-text { min-width: 0; display: flex; flex-direction: column; }
.row-text > strong { overflow-wrap: anywhere; }
.row-meta { color: var(--muted); font-size: .875rem; line-height: 1.43; overflow-wrap: anywhere; }
.row-aside { display: flex; align-items: center; gap: var(--s2); justify-content: flex-end; }

/* ---------- 8. Forms ---------- */
.field { display: flex; flex-direction: column; gap: var(--s1); min-width: 0; }
.field-label { font-weight: var(--weight-medium); font-size: .9375rem; }
.field-hint { color: var(--muted); font-size: .875rem; line-height: 1.43; }
.input {
  width: 100%; height: var(--control); padding: 0 var(--s3);
  font: inherit; font-size: 16px; /* 16 px: iOS does not zoom */
  color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius);
}
.input:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 1px var(--accent); }
select.input { appearance: none; padding-right: var(--s6);
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; }
.check { display: flex; align-items: center; gap: var(--s3); min-height: var(--control); cursor: pointer; }
.check input { width: 20px; height: 20px; margin: 0; accent-color: var(--accent); flex: none; }
.inline-form { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: var(--s2); align-items: end; }
.form-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--s3); }
@container (min-width: 680px) { .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* ---------- 9. Buttons: one height, fixed minimum width, label changes never resize ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  height: var(--control); min-width: var(--btn-min); padding: 0 var(--s4);
  font: inherit; font-weight: var(--weight-medium); white-space: nowrap; text-decoration: none; cursor: pointer;
  border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface); color: var(--text);
}
.btn:hover { border-color: var(--accent); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .45; cursor: not-allowed; pointer-events: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-quiet { border-color: transparent; background: transparent; color: var(--accent); min-width: 0; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-block { width: 100%; }
.btn-icon { min-width: var(--control); width: var(--control); padding: 0; }

/* ---------- 10. Action bar: secondary left, primary right – the same place on every page ---------- */
.action-bar {
  position: sticky; bottom: calc(var(--bottom-nav) + var(--safe-bottom)); z-index: 10;
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: var(--s3); align-items: center;
  margin-top: var(--s4); padding: var(--s3) 0;
  background: var(--bg); border-top: 1px solid var(--line);
}
.action-bar > :last-child { justify-self: end; }
@media (min-width: 1024px) { .action-bar { bottom: 0; } }

/* ---------- 11. Feedback: notices, chips, empty state, offline bar ---------- */
.notice { padding: var(--s3) var(--s4); border-radius: var(--radius); background: var(--accent-soft); }
.notice-ok { background: var(--ok-soft); color: var(--ok); }
.notice-error { background: var(--danger-soft); color: var(--danger); }
.notice-warn { background: var(--warn-soft); color: var(--warn); }
.chip {
  display: inline-flex; align-items: center; height: 24px; padding: 0 var(--s2); border-radius: 12px;
  font-size: .75rem; font-weight: var(--weight-medium); background: var(--bg); color: var(--muted); white-space: nowrap;
}
.chip-ok { background: var(--ok-soft); color: var(--ok); }
.chip-warn { background: var(--warn-soft); color: var(--warn); }
.chip-danger { background: var(--danger-soft); color: var(--danger); }
.empty { display: flex; flex-direction: column; align-items: center; gap: var(--s2); padding: var(--s6) var(--s4); text-align: center; color: var(--muted); }
.empty .icon { color: var(--accent); }
.offline-bar {
  position: fixed; inset: 0 0 auto 0; z-index: 30; margin: 0; padding: var(--s1) var(--s4);
  text-align: center; font-size: .875rem; background: var(--warn-soft); color: var(--warn);
}

/* ---------- 12. Media: avatar, QR code, codes, colour swatches ---------- */
.avatar { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; flex: none; display: flex; align-items: center; justify-content: center; background: var(--accent-soft); color: var(--accent); }
.avatar-sm { width: 24px; height: 24px; }
.avatar-lg { width: 96px; height: 96px; }
.qr { width: 200px; height: 200px; background: #fff; border-radius: var(--radius); padding: var(--s2); }
.codes { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s2); }
.codes code { display: block; padding: var(--s2); text-align: center; background: var(--bg); border-radius: var(--radius); }
.copy-box { padding: var(--s3); background: var(--bg); border-radius: var(--radius); }
.swatches { display: flex; flex-wrap: wrap; gap: var(--s3); }
.swatch { position: relative; width: var(--control); height: var(--control); cursor: pointer; }
.swatch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.swatch span { display: block; width: 100%; height: 100%; border-radius: 50%; border: 2px solid var(--line); }
.swatch input:checked + span { border-color: var(--text); box-shadow: inset 0 0 0 3px var(--surface); }
.swatch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.swatch-green span { background: #2f7a4b; }
.swatch-blue span { background: #3a5a9c; }
.swatch-orange span { background: #b34d14; }
.swatch-purple span { background: #5b4596; }
.swatch-magenta span { background: #a3427c; }
.swatch-own span { background: conic-gradient(#e33, #ec3, #3c5, #3ae, #73e, #e3a, #e33); }
.swatch-own input[type="color"] { position: absolute; inset: auto 0 -6px auto; width: 20px; height: 20px; opacity: 0; }
.details > summary { display: flex; align-items: center; min-height: var(--control); cursor: pointer; color: var(--accent); font-weight: var(--weight-medium); }

/* ---------- 13. Login pages: one centred card ---------- */
.auth-shell { display: flex; align-items: flex-start; justify-content: center; min-height: 100dvh; padding: var(--s6) var(--gutter); }
.auth-card { width: 100%; max-width: 440px; container-type: inline-size; }
.divider { display: flex; align-items: center; gap: var(--s3); color: var(--muted); font-size: .875rem; }
.divider::before, .divider::after { content: ""; flex: 1; border-top: 1px solid var(--line); }
