/* Display face: Bricolage Grotesque (SIL Open Font License), used for the farm name, page titles and figures. */
@font-face {
  font-family: "Bricolage Grotesque";
  src: url("../fonts/bricolage-grotesque-latin-wght.woff2") format("woff2");
  font-weight: 200 800;
  font-display: swap;
}

/* ---------- Themes ----------
   Every colour comes from these tokens. Harvest is the default; Night is the dark
   theme; "device" uses Harvest or Night to match the phone's own setting. */
:root,
:root[data-theme="harvest"],
:root[data-theme="device"] {
  color-scheme: light;
  --bg: #faf5ea;
  --surface: #ffffff;
  --surface-2: #f4ecdc;
  --ink: #2b2012;
  --muted: #6b5d49;
  --line: #e4d8c2;
  --band: #f2a007;
  --band-ink: #2b2012;
  --tray-dot: rgb(43 32 18 / 0.11);
  --link: #8a4f00;
  --tab-mark: #b86e00;
  --primary: #f2a007;
  --primary-ink: #2b2012;
  --focus: #1d4ed8;
  --danger: #a8321f;
  --notice-bg: #fff1cc;
  --notice-ink: #5e4100;
  --shadow: 0 10px 30px rgb(43 32 18 / 0.14);

  --yolk-bg: #fff4d6;  --yolk-line: #f2c969;  --yolk-ink: #8a5600;
  --leaf-bg: #e8f5ec;  --leaf-line: #9cd0ae;  --leaf-ink: #26693f;
  --clay-bg: #fbeae5;  --clay-line: #edb5a6;  --clay-ink: #9a2f1d;
  --sky-bg: #e7f0fa;   --sky-line: #a9c5e8;   --sky-ink: #2a5890;
  --straw-bg: #f7f0dc; --straw-line: #dcc889; --straw-ink: #6e5a1c;
  --teal-bg: #e2f4f2;  --teal-line: #95d2cc;  --teal-ink: #1b625d;
  --plum-bg: #f1eaf7;  --plum-line: #c7b1e0;  --plum-ink: #613b8a;
}

:root[data-theme="night"] {
  color-scheme: dark;
  --bg: #17130d;
  --surface: #221b12;
  --surface-2: #2c2318;
  --ink: #f4ecdd;
  --muted: #b8a88e;
  --line: #3d3122;
  --band: #2b2012;
  --band-ink: #f7c35a;
  --tray-dot: rgb(247 195 90 / 0.10);
  --link: #f5b53d;
  --tab-mark: #f5b53d;
  --primary: #f2a007;
  --primary-ink: #1b140b;
  --focus: #8db8ee;
  --danger: #f09a85;
  --notice-bg: #3a2c0e;
  --notice-ink: #f3cf73;
  --shadow: 0 10px 30px rgb(0 0 0 / 0.5);

  --yolk-bg: #2e2410;  --yolk-line: #6b5320;  --yolk-ink: #f5c45a;
  --leaf-bg: #13261a;  --leaf-line: #2f5e40;  --leaf-ink: #7fd19c;
  --clay-bg: #2e1814;  --clay-line: #6e3a2e;  --clay-ink: #f09a85;
  --sky-bg: #132131;   --sky-line: #2f4f75;   --sky-ink: #8db8ee;
  --straw-bg: #29230f; --straw-line: #5e5226; --straw-ink: #e2cc7e;
  --teal-bg: #0f2826;  --teal-line: #2a5e5a;  --teal-ink: #7ad4cc;
  --plum-bg: #241a30;  --plum-line: #4f3b6e;  --plum-ink: #c4a6ec;
}

/* "Match my device": the same values as Night, applied when the phone is in dark mode. */
@media (prefers-color-scheme: dark) {
  :root[data-theme="device"] {
    color-scheme: dark;
    --bg: #17130d;
    --surface: #221b12;
    --surface-2: #2c2318;
    --ink: #f4ecdd;
    --muted: #b8a88e;
    --line: #3d3122;
    --band: #2b2012;
    --band-ink: #f7c35a;
    --tray-dot: rgb(247 195 90 / 0.10);
    --link: #f5b53d;
    --tab-mark: #f5b53d;
    --primary: #f2a007;
    --primary-ink: #1b140b;
    --focus: #8db8ee;
    --danger: #f09a85;
    --notice-bg: #3a2c0e;
    --notice-ink: #f3cf73;
    --shadow: 0 10px 30px rgb(0 0 0 / 0.5);

    --yolk-bg: #2e2410;  --yolk-line: #6b5320;  --yolk-ink: #f5c45a;
    --leaf-bg: #13261a;  --leaf-line: #2f5e40;  --leaf-ink: #7fd19c;
    --clay-bg: #2e1814;  --clay-line: #6e3a2e;  --clay-ink: #f09a85;
    --sky-bg: #132131;   --sky-line: #2f4f75;   --sky-ink: #8db8ee;
    --straw-bg: #29230f; --straw-line: #5e5226; --straw-ink: #e2cc7e;
    --teal-bg: #0f2826;  --teal-line: #2a5e5a;  --teal-ink: #7ad4cc;
    --plum-bg: #241a30;  --plum-line: #4f3b6e;  --plum-ink: #c4a6ec;
  }
}

/* ---------- Base ---------- */
:root {
  --display: "Bricolage Grotesque", system-ui, sans-serif;
  --body: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --radius: 14px;
  --tap: 44px;
  --gutter: 16px;
}
@media (min-width: 768px) {
  /* Band, tabs and page share one left edge: a 1016px column, centred. */
  :root { --gutter: max(32px, calc((100% - 1016px) / 2)); }
}
* { box-sizing: border-box; }
body { margin: 0; font: 16px/1.5 var(--body); background: var(--bg); color: var(--ink); }
a { color: var(--link); }
h1 { font: 700 1.75rem/1.15 var(--display); letter-spacing: -0.01em; margin: 0 0 16px; }
h2 { font-size: 1.125rem; margin: 0 0 12px; }
.muted { color: var(--muted); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
.icon { width: 20px; height: 20px; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Header band ----------
   The dots are an egg tray seen from above: the farm's own unit of count. */
.band { position: relative; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px var(--gutter); background: var(--band); color: var(--band-ink); }
.band::after { content: ""; position: absolute; inset: 0; pointer-events: none;
  background-image: radial-gradient(circle, var(--tray-dot) 0 5px, transparent 5.5px);
  background-size: 18px 18px; background-position: right 6px center;
  -webkit-mask-image: linear-gradient(to left, #000 0, transparent 55%); mask-image: linear-gradient(to left, #000 0, transparent 55%); }
.brand { position: relative; z-index: 1; display: flex; align-items: center; gap: 10px; min-height: var(--tap); color: inherit; text-decoration: none; }
.brand-mark { width: 28px; height: 28px; stroke-width: 2.2; }
.brand-text { display: flex; flex-direction: column; }
.brand-name { font: 750 1.25rem/1.1 var(--display); letter-spacing: -0.015em; }
.brand-tag { font-size: .75rem; font-weight: 600; letter-spacing: .04em; opacity: .8; }

/* Personal menu: theme and sign out */
.me { position: relative; z-index: 2; }
.me summary { display: flex; align-items: center; gap: 4px; min-height: var(--tap); padding: 0 10px; border-radius: 999px;
  font-weight: 650; list-style: none; cursor: pointer; }
.me summary::-webkit-details-marker { display: none; }
.me summary:hover { background: rgb(0 0 0 / 0.07); }
.me[open] summary .icon { transform: rotate(180deg); }
.me-menu { position: absolute; right: 0; top: calc(100% + 6px); width: 230px; padding: 8px;
  background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.me-who { margin: 4px 8px 8px; font-weight: 650; }
.me-label { display: flex; align-items: center; gap: 6px; margin: 4px 8px; font-size: .75rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.me-label .icon { width: 14px; height: 14px; }
.me-menu button { display: flex; align-items: center; gap: 10px; width: 100%; min-height: var(--tap); padding: 0 8px;
  border: 0; border-radius: 10px; background: none; color: inherit; font: inherit; text-align: left; cursor: pointer; }
.me-menu button:hover { background: var(--surface-2); }
.me-menu button[aria-pressed="true"] { font-weight: 650; }
.me-menu .tick { margin-left: auto; color: var(--tab-mark); }
.me-menu .sign-out { margin-top: 6px; border-top: 1px solid var(--line); border-radius: 0 0 10px 10px; }
.swatch { width: 18px; height: 18px; border-radius: 50%; border: 1px solid var(--line); flex: none; }
.swatch--harvest { background: linear-gradient(135deg, #f2a007 50%, #faf5ea 50%); }
.swatch--night { background: linear-gradient(135deg, #2b2012 50%, #f5b53d 50%); }
.swatch--device { background: linear-gradient(135deg, #f2a007 50%, #2b2012 50%); }
/* Owner admin links: in the personal menu on phones, in the tabs on wider screens. */
.me-admin { list-style: none; margin: 0 0 6px; padding: 0 0 6px; border-bottom: 1px solid var(--line); }
.me-admin:empty { display: none; }
.me-admin a { display: flex; align-items: center; gap: 10px; min-height: var(--tap); padding: 0 8px; border-radius: 10px; color: inherit; text-decoration: none; }
.me-admin a:hover { background: var(--surface-2); }
.tabs .tab-admin { display: none; }
@media (min-width: 768px) {
  .me-admin { display: none; }
  .tabs .tab-admin { display: block; }
}

/* ---------- Navigation ----------
   Phone: a bottom bar within reach of the thumb. Wider screens: tabs under the band. */
.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom); }
.tabs ul { display: flex; margin: 0; padding: 0; list-style: none; overflow-x: auto; scrollbar-width: none; }
.tabs ul::-webkit-scrollbar { display: none; }
/* Up to seven items share the bar equally (the owner sees all seven); below 52px each it scrolls. */
.tabs li { flex: 1 1 0; min-width: 52px; }
.tabs a { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  min-height: 60px; padding: 6px 2px; color: var(--muted); text-decoration: none; font-size: .625rem; font-weight: 700; white-space: nowrap; }
.tabs a[aria-current="page"] { color: var(--ink); }
.tabs a[aria-current="page"]::before { content: ""; position: absolute; top: 0; left: 22%; right: 22%; height: 3px; border-radius: 0 0 3px 3px; background: var(--tab-mark); }
.tabs a[aria-current="page"] .icon { color: var(--tab-mark); }
.page { padding: 20px var(--gutter) 104px; }
/* One tab or none: the phone has no bottom bar, so the page keeps no room for it. */
@media (max-width: 767.98px) {
  .tabs--single { display: none; }
  .tabs--single ~ .page { padding-bottom: 48px; }
}

@media (min-width: 768px) {
  .band { padding-top: 18px; padding-bottom: 40px; }
  .brand-mark { width: 34px; height: 34px; }
  .brand-name { font-size: 1.625rem; }
  .brand-tag { font-size: .8125rem; }
  /* Tab text lines up with the gutter; the 14px link padding hangs outside it. */
  .tabs { position: sticky; top: 0; bottom: auto; margin-top: -24px; padding: 0 calc(var(--gutter) - 14px); border-top: 0;
    border-bottom: 1px solid var(--line); border-radius: 24px 24px 0 0; }
  .tabs ul { overflow: visible; }
  .tabs li { flex: none; }
  .tabs a { flex-direction: row; gap: 8px; min-height: 52px; padding: 0 14px; font-size: .9375rem; }
  .tabs a:hover { color: var(--ink); }
  .tabs a[aria-current="page"]::before { top: auto; bottom: -1px; left: 10px; right: 10px; border-radius: 3px 3px 0 0; }
  .page { padding-top: 28px; padding-bottom: 48px; }
}

/* ---------- Today's figures ---------- */
.stats { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
.stat { margin: 0; padding: 16px; border: 1px solid; border-radius: var(--radius); }
.stat-icon { width: 24px; height: 24px; }
.stat-value { margin: 10px 0 2px; font: 700 1.75rem/1 var(--display); font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.stat-label { margin: 0; font-size: .875rem; color: var(--muted); }
.stat--yolk  { background: var(--yolk-bg);  border-color: var(--yolk-line);  color: var(--yolk-ink); }
.stat--leaf  { background: var(--leaf-bg);  border-color: var(--leaf-line);  color: var(--leaf-ink); }
.stat--clay  { background: var(--clay-bg);  border-color: var(--clay-line);  color: var(--clay-ink); }
.stat--sky   { background: var(--sky-bg);   border-color: var(--sky-line);   color: var(--sky-ink); }
.stat--straw { background: var(--straw-bg); border-color: var(--straw-line); color: var(--straw-ink); }
.stat--teal  { background: var(--teal-bg);  border-color: var(--teal-line);  color: var(--teal-ink); }
.stat--plum  { background: var(--plum-bg);  border-color: var(--plum-line);  color: var(--plum-ink); }
.stat .stat-value { color: var(--ink); }

/* ---------- Content ---------- */
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 20px; }
.page-head h1 { margin: 0; }
.page-head .muted { margin: 6px 0 0; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }
.narrow { max-width: 420px; margin: 32px auto; }
.field { margin-bottom: 14px; }
.field > label { display: block; font-weight: 600; margin-bottom: 4px; }
.field ul { list-style: none; margin: 0; padding: 0; }
.field ul label { display: flex; align-items: center; gap: 8px; min-height: var(--tap); font-weight: 400; }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=tel], select, textarea {
  width: 100%; min-height: var(--tap); padding: 8px 12px; font: inherit; color: var(--ink);
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
}
input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--primary); }
.button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: var(--tap); padding: 0 18px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--ink); font: inherit; font-weight: 650; text-decoration: none; cursor: pointer; }
.button.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.error { color: var(--danger); margin: 4px 0 0; }
.notice, .messages li { background: var(--notice-bg); color: var(--notice-ink); padding: 10px 14px; border-radius: 10px; }
.messages { list-style: none; margin: 0 0 16px; padding: 0; display: grid; gap: 8px; }
.badge { display: inline-block; padding: 2px 10px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface-2); font-size: .8125rem; }
.badge.warn { background: var(--notice-bg); color: var(--notice-ink); border-color: transparent; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; vertical-align: top; padding: 10px 8px; border-bottom: 1px solid var(--line); }
thead th { font-size: .8125rem; color: var(--muted); }
.decide { display: flex; flex-wrap: wrap; align-items: end; gap: 8px; margin-top: 12px; }
.decide label { flex: 1 1 200px; }
.filters { display: grid; gap: 8px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); align-items: end; margin-bottom: 16px; }
code { font-size: .8125rem; word-break: break-word; }

/* ---------- Lists ---------- */
.section-title { margin: 28px 0 12px; }
.plain-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.page-head > .button { white-space: nowrap; }
.field .count-input { text-align: center; font-size: 1.25rem; font-variant-numeric: tabular-nums; }
.entry-form .field ul, .entry-form .field div[id] { display: flex; flex-wrap: wrap; gap: 8px; list-style: none; margin: 0; padding: 0; }
.entry-form .field ul label, .entry-form .field div[id] label { display: inline-flex; align-items: center; gap: 6px; min-height: var(--tap); margin: 0; padding: 0 14px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface-2); }
.entry-form .field ul input, .entry-form .field div[id] input { accent-color: var(--primary); }
.button.wide { width: 100%; }
@media (prefers-reduced-motion: no-preference) {
  .me summary .icon { transition: transform .15s ease; }
}

/* ---------- Checks ---------- */
.alert-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.alert { border: 1px solid; border-radius: 10px; }
.alert a { display: block; padding: 10px 14px; color: inherit; text-decoration: none; }
.alert a:hover { text-decoration: underline; }
.alert--danger { background: var(--clay-bg); border-color: var(--clay-line); color: var(--clay-ink); }
.alert--warning, .alert--warn { background: var(--straw-bg); border-color: var(--straw-line); color: var(--straw-ink); }
.row-flagged { background: var(--clay-bg); color: var(--clay-ink); font-weight: 600; }
.row-muted { color: var(--muted); }
.checks-table th, .checks-table td { white-space: nowrap; }

/* ---------- Dashboard ---------- */
.stat-note { margin: 2px 0 0; font-size: .8125rem; color: var(--muted); }
.section-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin: 28px 0 12px; }
.section-head .section-title { margin: 0; }
.dash-cards { grid-template-columns: repeat(auto-fit, minmax(min(260px, 100%), 1fr)); }
.dash-cards .stat-value { font-size: 1.5rem; }
.how { margin: 8px 0 0; font-size: .8125rem; color: var(--muted); }
.section-title small { font: 400 .875rem var(--body); }
.figures { font-variant-numeric: tabular-nums; }
.figures td, .figures th { white-space: nowrap; }
.flags .badge + .badge { margin-left: 4px; }
/* Charts: one series each, drawn in a single theme hue. Text never takes the series colour. */
.charts { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr)); }
.chart-card { margin: 0; min-width: 0; }
.chart-title { margin: 0; font-size: 1rem; }
.chart-note { margin: 2px 0 10px; font-size: .8125rem; color: var(--muted); }
.chart--leaf { --series: var(--leaf-ink); }
.chart--clay { --series: var(--clay-ink); }
.chart--plum { --series: var(--plum-ink); }
.chart { display: block; width: 100%; height: auto; overflow: visible; }
.chart text { font: 12px var(--body); fill: var(--muted); font-variant-numeric: tabular-nums; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .line { fill: none; stroke: var(--series); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .col { fill: var(--series); }
.chart .hit { fill: transparent; }
.chart-columns .mark:hover .hit { fill: var(--surface-2); }
.chart .dot { fill: var(--series); stroke: var(--surface); stroke-width: 2; opacity: 0; }
.chart .mark:hover .dot, .chart .lone .dot { opacity: 1; }
.chart-table { margin-top: 8px; }
.chart-table summary { cursor: pointer; min-height: var(--tap); display: flex; align-items: center; color: var(--link); font-weight: 600; font-size: .875rem; }
.chart-table table { font-size: .875rem; font-variant-numeric: tabular-nums; }
.chart-table th, .chart-table td { padding: 6px 8px; }

/* ---------- Collection photos ---------- */
input[type=file] { display: block; width: 100%; max-width: 100%; min-height: var(--tap); padding: 8px 0; font: inherit; color: var(--ink); }
input[type=file]::file-selector-button { min-height: var(--tap); margin-right: 12px; padding: 0 16px; border: 1px solid var(--line);
  border-radius: 10px; background: var(--surface-2); color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; }
.photo-preview { display: flex; align-items: center; gap: 12px; margin-top: 8px; }
.photo-preview[hidden] { display: none; }
.photo-preview img { width: 96px; height: 96px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); flex: none; }
.photo-preview-text { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
.photo-link { font-weight: 600; font-size: .875rem; }

@page { margin: 14mm; }
@media print {
  .band, .tabs, .filters, .actions, button, .button, .messages { display: none !important; }
  .page-head { display: none; }
  body, .page { background: #fff !important; color: #000 !important; }
  body * { color: #000 !important; }
  .page { max-width: none; padding: 0; margin: 0; }
  .table-wrap { overflow: visible; }
  .section-title { break-after: avoid; }
}

/* ---------- Record screen ---------- */
.total { margin: 0 0 14px; min-height: 1.5em; font-weight: 700; font-variant-numeric: tabular-nums; }
.total:empty { min-height: 0; margin: 0; }
