/* croplog — field data logger for AGRI20035.
   Warm paper surfaces, one deep leaf-green accent, monospaced numerals for
   anything measured. Three themes: light, dark, and "field" for direct sun.
   No webfonts: the app must look identical with no network. */

/* ---- tokens ------------------------------------------------------------ */

:root {
  color-scheme: light;

  --paper: #FAFAF7;
  --card: #FFFFFF;
  --soft: #F1F1EC;

  --ink: #171A17;
  --ink-2: #2A2E2A;
  --ink-3: #565B54;
  --ink-4: #8B9086;
  --ink-5: #C6C9C0;

  --line: rgba(23, 26, 23, 0.12);
  --line-soft: rgba(23, 26, 23, 0.07);
  --line-faint: rgba(23, 26, 23, 0.04);

  --accent: #1E6B41;
  --accent-soft: rgba(30, 107, 65, 0.10);
  --on-accent: #FFFFFF;

  --ok: #1E6B41;
  --ok-soft: rgba(30, 107, 65, 0.10);
  --warn: #9A6A0B;
  --warn-soft: rgba(154, 106, 11, 0.12);
  --bad: #B3392E;
  --bad-soft: rgba(179, 57, 46, 0.10);
  --info: #20657A;
  --info-soft: rgba(32, 101, 122, 0.10);

  --focus: #1E6B41;

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Roboto Mono", Menlo, Consolas, monospace;

  --fs-cap: 12px;
  --fs-meta: 13px;
  --fs-body: 15px;
  --fs-em: 17px;
  --fs-sec: 20px;
  --fs-title: 24px;
  --fs-huge: 34px;

  --w-reg: 400;
  --w-med: 500;
  --w-strong: 600;

  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-7: 32px;

  --r-card: 14px;
  --r-ctl: 11px;
  --r-sheet: 18px;

  --shadow-card: 0 1px 2px rgba(23, 26, 23, 0.05);
  --shadow-pop: 0 1px 3px rgba(23, 26, 23, 0.06), 0 8px 24px -12px rgba(23, 26, 23, 0.16);
  --shadow-modal: 0 24px 60px -20px rgba(23, 26, 23, 0.35);

  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  --tap: 48px;
  --border-w: 1px;
  --maxw: 560px;

  /* floating pill nav */
  --nav-glass: rgba(255, 255, 255, 0.72);
  --nav-border: rgba(255, 255, 255, 0.55);
  --nav-blur: blur(28px) saturate(180%);
  --nav-shadow: 0 8px 32px -8px rgba(23, 26, 23, 0.20);
}

:root[data-theme="dark"] {
  color-scheme: dark;

  --paper: #121410;
  --card: #1B1E19;
  --soft: #242821;

  --ink: #F2F3EE;
  --ink-2: #DADDD4;
  --ink-3: #A8AEA2;
  --ink-4: #7C8378;
  --ink-5: #4C5248;

  --line: rgba(242, 243, 238, 0.14);
  --line-soft: rgba(242, 243, 238, 0.08);
  --line-faint: rgba(242, 243, 238, 0.05);

  --accent: #5FBF87;
  --accent-soft: rgba(95, 191, 135, 0.15);
  --on-accent: #0C1A12;

  --ok: #5FBF87;
  --ok-soft: rgba(95, 191, 135, 0.15);
  --warn: #E0A94A;
  --warn-soft: rgba(224, 169, 74, 0.15);
  --bad: #E5796B;
  --bad-soft: rgba(229, 121, 107, 0.15);
  --info: #5FB3CE;
  --info-soft: rgba(95, 179, 206, 0.15);

  --focus: #5FBF87;

  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-pop: 0 1px 3px rgba(0, 0, 0, 0.5), 0 8px 24px -12px rgba(0, 0, 0, 0.7);
  --shadow-modal: 0 24px 60px -20px rgba(0, 0, 0, 0.8);

  --nav-glass: rgba(32, 36, 30, 0.74);
  --nav-border: rgba(242, 243, 238, 0.14);
  --nav-blur: blur(28px) saturate(180%);
  --nav-shadow: 0 8px 32px -8px rgba(0, 0, 0, 0.6);
}

/* Direct sunlight. Maximum luminance, nothing under ~7:1, solid fills instead
   of tints, borders instead of shadows, heavier weights instead of larger type
   so that toggling never reflows the layout. */
:root[data-theme="field"] {
  color-scheme: light;

  --paper: #FFFFFF;
  --card: #FFFFFF;
  --soft: #EDEEE8;

  --ink: #0B0B0C;
  --ink-2: #17191B;
  --ink-3: #2E3438;
  --ink-4: #49525A;
  --ink-5: #49525A;

  --line: rgba(11, 11, 12, 0.65);
  --line-soft: rgba(11, 11, 12, 0.40);
  --line-faint: rgba(11, 11, 12, 0.25);

  --accent: #0E5C33;
  --accent-soft: #CDE8D6;
  --on-accent: #FFFFFF;

  --ok: #0E5C33;
  --ok-soft: #CDE8D6;
  --warn: #7A3B06;
  --warn-soft: #FBDF9D;
  --bad: #8F1D1D;
  --bad-soft: #F6D2D2;
  --info: #10485C;
  --info-soft: #CFE5EE;

  --focus: #0B0B0C;

  --w-reg: 500;
  --w-med: 600;
  --w-strong: 700;

  --border-w: 1.5px;

  --shadow-card: none;
  --shadow-pop: none;
  --shadow-modal: 0 0 0 2px rgba(11, 11, 12, 0.8);

  /* Solid, not glass: a translucent blur is unreadable in direct sun. */
  --nav-glass: #FFFFFF;
  --nav-border: rgba(11, 11, 12, 0.65);
  --nav-blur: none;
  --nav-shadow: none;
}

/* ---- reset ------------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: var(--fs-body);
  font-weight: var(--w-reg);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
  margin: 0;
}

/* 16px minimum stops iOS Safari zooming the viewport on focus. */
input, select, textarea { font-size: 16px; }

button { background: none; border: none; cursor: pointer; }

h1, h2, h3, p { margin: 0; }

a { color: var(--accent); }

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.hidden { display: none !important; }

.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;
}

.num {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

/* ---- app shell --------------------------------------------------------- */

#app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.screen {
  flex: 1;
  width: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 var(--sp-4) calc(6rem + env(safe-area-inset-bottom));
}

.apphead {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--paper);
  border-bottom: var(--border-w) solid var(--line-soft);
  padding-top: env(safe-area-inset-top);
}

.apphead-in {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: var(--sp-3) var(--sp-4);
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  min-height: 56px;
}

.apphead-title {
  font-size: var(--fs-em);
  font-weight: var(--w-strong);
  letter-spacing: -0.01em;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.apphead-sub {
  display: block;
  font-size: var(--fs-cap);
  font-weight: var(--w-reg);
  color: var(--ink-3);
  letter-spacing: 0;
}

.iconbtn {
  width: 44px;
  height: 44px;
  border-radius: var(--r-ctl);
  display: grid;
  place-items: center;
  color: var(--ink-3);
  flex: none;
}

.iconbtn:active { background: var(--soft); transform: scale(0.94); }
.iconbtn svg { width: 22px; height: 22px; }

/* ---- floating pill nav -------------------------------------------------- */
/* Same shape as the PetPak owner app: a glass pill that floats clear of the
   screen edge rather than a bar welded to it, collapsing to icons-only when
   you scroll down so it stays reachable without covering content. */

.tabbar {
  position: fixed;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 30;
  width: min(92vw, 360px);
  margin-bottom: env(safe-area-inset-bottom);
  /* Animating width does cause layout, but only inside this fixed-position
     subtree of four tabs, and only twice per scroll gesture rather than per
     frame. Measured on a 6x-throttled CPU: p95 frame 9.2ms, no long tasks.
     There is no transform that narrows a container without distorting the
     icons and labels inside it. */
  transition: width 0.3s var(--ease);
}

.tabbar.is-collapsed { width: min(64vw, 264px); }

.tabbar-in {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px;
  width: 100%;
  padding: 6px 8px;
  border-radius: 999px;
  background: var(--nav-glass);
  border: var(--border-w) solid var(--nav-border);
  box-shadow: var(--nav-shadow);
  backdrop-filter: var(--nav-blur);
  -webkit-backdrop-filter: var(--nav-blur);
}

.tabbar.is-collapsed .tabbar-in { padding: 4px 6px; }

.tab {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 0;
  gap: 2px;
  padding: 8px 6px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: var(--w-med);
  color: var(--ink-3);
  /* Only the active-pill fill cross-fades. The 2px padding and gap changes
     snap, which is invisible next to a 300ms width animation and costs no
     layout. */
  transition: background 0.3s var(--ease), color 0.3s var(--ease);
}

.tabbar.is-collapsed .tab { padding: 6px 4px; gap: 0; }

.tab svg { width: 18px; height: 18px; stroke-width: 2; }

/* Inverts with the theme for free: ink and paper both flip. */
.tab[aria-current="page"] {
  background: var(--ink);
  color: var(--paper);
  font-weight: var(--w-strong);
}

.tab:active { transform: scale(0.95); }

.tab-label {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  opacity: 1;
  max-height: 16px;
  /* max-height is animated deliberately, and it is the only height change left
     in the pill: the padding and gap transitions were removed because they
     moved things 2px for real layout cost.
       - Snapping it instead would make the pill jump shorter while its width
         is still sliding over 300ms, and the opacity fade would never be seen,
         because a zero-height label is already gone.
       - grid-template-rows, the usual modern replacement, animates layout too,
         so it trades one layout property for another rather than avoiding one.
     Cost measured with this rule active, on a 6x-throttled CPU across 403
     frames of repeated collapse and expand: p95 frame 9.2ms, zero long tasks,
     zero frames over 50ms. See the note on .tabbar above. */
  transition: opacity 0.3s var(--ease), max-height 0.3s var(--ease);
}

.tabbar.is-collapsed .tab-label { opacity: 0; max-height: 0; }

/* ---- cards and rows ---------------------------------------------------- */

.card {
  background: var(--card);
  border: var(--border-w) solid var(--line-soft);
  border-radius: var(--r-card);
  box-shadow: var(--shadow-card);
  padding: var(--sp-4);
  margin-bottom: var(--sp-3);
}

.card-title {
  font-size: var(--fs-em);
  font-weight: var(--w-strong);
  letter-spacing: -0.01em;
}

.section-label {
  font-size: var(--fs-cap);
  font-weight: var(--w-strong);
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--ink-4);
  margin: var(--sp-6) 0 var(--sp-2);
}

.muted { color: var(--ink-3); }
.meta { font-size: var(--fs-meta); color: var(--ink-3); }
.cap { font-size: var(--fs-cap); color: var(--ink-4); }

/* State lives in the word and, at most, a faint wash. Never a border stripe. */
.s-ok { color: var(--ok); font-weight: var(--w-med); }
.s-warn { color: var(--warn); font-weight: var(--w-med); }
.s-bad { color: var(--bad); font-weight: var(--w-med); }
.s-idle { color: var(--ink-4); }
.wash-ok { background: var(--ok-soft); }
.wash-warn { background: var(--warn-soft); }
.wash-bad { background: var(--bad-soft); }

/* ---- buttons ----------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-height: var(--tap);
  padding: 0 var(--sp-5);
  border-radius: var(--r-ctl);
  border: var(--border-w) solid var(--line);
  background: var(--card);
  color: var(--ink);
  font-size: var(--fs-em);
  font-weight: var(--w-med);
  transition: transform 0.12s var(--ease);
}

.btn:active { transform: scale(0.97); background: var(--soft); }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
  font-weight: var(--w-strong);
}

.btn-primary:active { background: var(--accent); filter: brightness(0.94); }

.btn-block { display: flex; width: 100%; }
.btn-sm { min-height: 40px; padding: 0 var(--sp-4); font-size: var(--fs-body); }

.btn[disabled] { opacity: 0.45; pointer-events: none; }

/* ---- toast ------------------------------------------------------------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(84px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(8px);
  z-index: 60;
  max-width: calc(100vw - 32px);
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-ctl);
  background: var(--ink);
  color: var(--paper);
  font-size: var(--fs-meta);
  box-shadow: var(--shadow-pop);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s var(--ease), transform 0.18s var(--ease);
}

.toast.on { opacity: 1; transform: translateX(-50%) translateY(0); pointer-events: auto; }
.toast button { color: var(--paper); font-weight: var(--w-strong); text-decoration: underline; }

/* ---- offline / sync pill ----------------------------------------------- */

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: var(--fs-cap);
  font-weight: var(--w-med);
  background: var(--soft);
  color: var(--ink-3);
  flex: none;
}

.pill-warn { background: var(--warn-soft); color: var(--warn); }
.pill-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

/* ---- boot / empty ------------------------------------------------------ */

.boot {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  gap: var(--sp-4);
  padding: var(--sp-6);
  text-align: center;
}

.spin {
  width: 26px; height: 26px;
  border: 2.5px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.empty {
  text-align: center;
  padding: var(--sp-7) var(--sp-4);
  color: var(--ink-3);
}

.empty-title {
  font-size: var(--fs-em);
  font-weight: var(--w-strong);
  color: var(--ink-2);
  margin-bottom: var(--sp-2);
}

/* ---- onboarding -------------------------------------------------------- */

.onboard {
  min-height: 100dvh;
  max-width: var(--maxw);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: var(--sp-4);
  padding: var(--sp-6) var(--sp-5)
    calc(var(--sp-7) + env(safe-area-inset-bottom));
  text-align: left;
}

.onboard-mark { color: var(--accent); }

.onboard-title {
  font-size: var(--fs-huge);
  font-weight: var(--w-strong);
  letter-spacing: -0.025em;
  line-height: 1.1;
}

.onboard-lede {
  font-size: var(--fs-em);
  color: var(--ink-3);
  line-height: 1.5;
  max-width: 34ch;
}

.onboard-actions {
  margin-top: var(--sp-2);
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}

.screen-top { padding-top: var(--sp-3); }

/* ---- form controls ----------------------------------------------------- */

.input {
  width: 100%;
  min-height: var(--tap);
  padding: 0 var(--sp-3);
  border-radius: var(--r-ctl);
  border: var(--border-w) solid var(--line);
  background: var(--paper);
  color: var(--ink);
}

.input::placeholder { color: var(--ink-4); }
.input:focus-visible { border-color: var(--accent); }

textarea.input {
  min-height: 88px;
  padding: var(--sp-3);
  line-height: 1.45;
  resize: vertical;
}

.field-label {
  font-size: var(--fs-meta);
  font-weight: var(--w-med);
  color: var(--ink-3);
  margin-bottom: var(--sp-2);
}

.field { margin-bottom: var(--sp-4); }

.numgrid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--sp-2);
}

.numgrid-b {
  min-height: 52px;
  border-radius: var(--r-ctl);
  border: var(--border-w) solid var(--line);
  background: var(--paper);
  font-size: var(--fs-em);
  font-weight: var(--w-med);
  color: var(--ink-2);
  transition: transform 0.12s var(--ease);
}

.numgrid-b:active { transform: scale(0.95); }

.numgrid-b[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
  font-weight: var(--w-strong);
}

/* ---- row cards --------------------------------------------------------- */

.rowcard {
  width: 100%;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  text-align: left;
  min-height: 64px;
  padding: var(--sp-3) var(--sp-4);
  margin-bottom: var(--sp-2);
  background: var(--card);
  border: var(--border-w) solid var(--line-soft);
  border-radius: var(--r-card);
  box-shadow: var(--shadow-card);
  color: inherit;
}

/* These read as flat cards without an affordance, so they get the two things
   that say "tap me": a chevron, and a surface that lifts off the page. */
.rowcard {
  background: var(--card);
  cursor: pointer;
}

.rowcard:active { background: var(--soft); transform: scale(0.985); }

.rowcard-end { display: flex; align-items: center; gap: var(--sp-2); flex: none; }
.rowcard-count { font-size: var(--fs-meta); font-weight: var(--w-strong); }

.rowcard-chev {
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--accent);
  border-bottom: 2px solid var(--accent);
  transform: rotate(-45deg);
  flex: none;
  margin-right: 2px;
}

/* A hairline is invisible on a dark surface, so lean on the border there. */
:root[data-theme="dark"] .rowcard { border-color: var(--line); }

.rowcard-main { flex: 1; min-width: 0; display: block; }

.rowcard-title {
  display: block;
  font-size: var(--fs-body);
  font-weight: var(--w-strong);
  color: var(--ink);
}

.rowcard-sub {
  display: block;
  font-size: var(--fs-meta);
  color: var(--ink-3);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rowcard-go {
  font-size: var(--fs-meta);
  font-weight: var(--w-med);
  color: var(--accent);
  flex: none;
}

/* ---- key/value rows, people -------------------------------------------- */

.kv {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  padding: var(--sp-2) 0;
  border-bottom: var(--border-w) solid var(--line-faint);
}

.kv:last-of-type { border-bottom: 0; }
.kv-k { flex: none; width: 92px; font-size: var(--fs-meta); color: var(--ink-3); padding-top: 1px; }
.kv-v { flex: 1; min-width: 0; word-break: break-word; }

.person {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2) 0;
}

.avatar {
  flex: none;
  width: 36px; height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: var(--fs-meta);
  font-weight: var(--w-strong);
  letter-spacing: 0.02em;
}

.person-main { flex: 1; min-width: 0; }
.person-name { display: block; font-weight: var(--w-med); }
.person-role { display: block; font-size: var(--fs-cap); color: var(--ink-4); }

.stack-actions {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  margin-top: var(--sp-6);
}

/* ---- bottom sheet ------------------------------------------------------ */

.sheet-bg {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(10, 12, 10, 0.42);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fade 0.16s var(--ease);
}

.sheet {
  width: 100%;
  max-width: var(--maxw);
  max-height: 88dvh;
  overflow-y: auto;
  background: var(--card);
  border-radius: var(--r-sheet) var(--r-sheet) 0 0;
  box-shadow: var(--shadow-modal);
  padding: var(--sp-3) var(--sp-4)
    calc(var(--sp-5) + env(safe-area-inset-bottom));
  animation: rise 0.2s var(--ease);
}

.sheet-grip {
  width: 38px; height: 4px;
  border-radius: 2px;
  background: var(--ink-5);
  margin: 0 auto var(--sp-4);
}

.sheet-actions {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  margin-top: var(--sp-3);
}

.codebox {
  padding: var(--sp-3);
  border-radius: var(--r-ctl);
  background: var(--soft);
  border: var(--border-w) solid var(--line-faint);
  font-size: var(--fs-meta);
  word-break: break-all;
  line-height: 1.4;
  color: var(--ink-2);
}

@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(14px); } }

/* ---- plot map ---------------------------------------------------------- */

.plotmap-wrap { margin: var(--sp-2) 0 var(--sp-4); }

.plotmap {
  display: grid;
  grid-template-columns: 22px 1fr 8px 1fr;
  gap: 4px;
  align-items: center;
}

.pm-band {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
}

.pm-crop {
  font-size: var(--fs-cap);
  font-weight: var(--w-med);
  color: var(--ink-3);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-bottom: 2px;
}

.pm-rep {
  font-size: var(--fs-cap);
  color: var(--ink-4);
  text-align: center;
}

.pm-gap { width: 8px; }

.pm-cell {
  position: relative;
  height: 48px;
  border-radius: 10px;
  border: var(--border-w) solid var(--line-soft);
  background: var(--soft);
  color: var(--ink-2);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  transition: transform 0.12s var(--ease);
}

.pm-cell:active { transform: scale(0.94); }
.pm-cell .pm-p { font-size: 11px; color: var(--ink-4); line-height: 1.1; }
.pm-cell .pm-v { font-size: 12px; font-weight: var(--w-med); line-height: 1.1; }
.pm-cell .pm-tick { display: block; line-height: 0; }

.pm-cell.pm-partial { background: var(--warn-soft); border-color: transparent; }
.pm-cell.pm-partial .pm-p { color: var(--warn); }

.pm-cell.pm-done {
  background: var(--ok);
  border-color: var(--ok);
  color: var(--on-accent);
}

.pm-cell.pm-done .pm-p { color: var(--on-accent); opacity: 0.75; }

.pm-cell.pm-skipped {
  border-style: dashed;
  border-color: var(--line);
  background: transparent;
  color: var(--ink-4);
}

.pm-cell.pm-now {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* Queued on this phone, not yet acknowledged by the server. */
.pm-cell.pm-pending::after {
  content: "";
  position: absolute;
  top: 3px;
  right: 3px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  border: 1.5px solid currentColor;
  opacity: 0.7;
}

.pm-by {
  position: absolute;
  right: 3px;
  bottom: 2px;
  font-size: 8px;
  font-weight: var(--w-strong);
  letter-spacing: 0.02em;
  opacity: 0.8;
}

.pm-legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-3);
  margin-top: var(--sp-3);
  font-size: var(--fs-cap);
  color: var(--ink-4);
}

.pm-legend-i { display: inline-flex; align-items: center; gap: 5px; }

.pm-sw {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  border: var(--border-w) solid var(--line-soft);
  background: var(--soft);
}

.pm-sw.pm-partial { background: var(--warn-soft); border-color: transparent; }
.pm-sw.pm-done { background: var(--ok); border-color: var(--ok); }
.pm-sw.pm-skipped { background: transparent; border-style: dashed; border-color: var(--line); }

/* ---- segmented control, progress --------------------------------------- */

.segrow {
  display: flex;
  gap: var(--sp-1);
  padding: 3px;
  background: var(--soft);
  border-radius: var(--r-ctl);
  margin-bottom: var(--sp-3);
}

.seg {
  flex: 1;
  min-height: 40px;
  border-radius: 9px;
  font-size: var(--fs-body);
  font-weight: var(--w-med);
  color: var(--ink-3);
}

.seg.on {
  background: var(--card);
  color: var(--ink);
  font-weight: var(--w-strong);
  box-shadow: var(--shadow-card);
}

.progress-line {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  margin-bottom: var(--sp-3);
}

.progress-bar {
  flex: 1;
  height: 4px;
  border-radius: 2px;
  background: var(--line-soft);
  overflow: hidden;
}

/* Scaled rather than widened: this bar advances after every committed
   measurement, and animating width would force layout on each frame just as
   the keypad is trying to feel instant. The parent clips the ends. */
.progress-bar > span {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: left center;
  transition: transform 0.25s var(--ease);
}

/* A labelled break inside a sheet, used to split the visit report into its
   inside-plot and outside-plot halves. */
.sheet-sec {
  margin: var(--sp-5) 0 var(--sp-3);
  padding-top: var(--sp-4);
  border-top: var(--border-w) solid var(--line-soft);
  font-size: var(--fs-meta);
  font-weight: var(--w-strong);
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--ink-3);
}

/* ---- first-run walkthrough ---------------------------------------------- */

.tour {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  padding: calc(env(safe-area-inset-top) + 14px) 20px
    calc(env(safe-area-inset-bottom) + 16px);
}

.tour-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: var(--maxw);
  width: 100%;
  margin: 0 auto;
}

.tour-dots { display: flex; gap: 6px; }

.tour-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--line);
}

.tour-dot.on { background: var(--accent); }

.tour-slidehost {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: pan-y;
}

.tour-slide {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 16px;
  max-width: 330px;
  animation: tour-in 0.24s var(--ease);
}

@keyframes tour-in {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: none; }
}

.tour-art {
  width: 92px;
  height: 92px;
  border-radius: 50%;
  background: var(--soft);
  display: grid;
  place-items: center;
  color: var(--accent);
}

.tour-art svg { width: 42px; height: 42px; }

.tour-title {
  font-size: var(--fs-title);
  font-weight: var(--w-strong);
  letter-spacing: -0.01em;
}

.tour-body { color: var(--ink-2); line-height: 1.55; }

.tour > .btn {
  max-width: var(--maxw);
  width: 100%;
  margin: 0 auto;
}

/* ---- round screen: one page per measurement round ----------------------- */

.round-head { margin-bottom: var(--sp-4); }

.round-title {
  font-size: var(--fs-title);
  font-weight: var(--w-strong);
  letter-spacing: -0.01em;
  margin-bottom: 2px;
}

.roundplot { margin-bottom: var(--sp-6); }

.roundplot-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--sp-3);
  margin-bottom: var(--sp-2);
}

.roundplot-title {
  font-size: var(--fs-em);
  font-weight: var(--w-strong);
}

.roundplot .progress-bar { margin-bottom: var(--sp-3); }
.roundplot .plotmap-wrap { margin-bottom: var(--sp-3); }

/* ---- desktop entry grid ------------------------------------------------- */
/* The round as a worksheet-shaped table, shown on wide fine-pointer layouts. */

.dgrid-wrap { overflow-x: auto; }

.dgrid {
  width: 100%;
  border-collapse: collapse;
  background: var(--card);
  border: var(--border-w) solid var(--line);
  border-radius: var(--r-card);
  /* border-radius needs separate borders to clip; keep it simple: square
     table inside the section, softened by the page around it. */
  border-radius: 0;
}

.dgrid th,
.dgrid td {
  border: var(--border-w) solid var(--line-soft);
}

.dg-crop {
  padding: 8px 6px 4px;
  font-size: var(--fs-meta);
  font-weight: var(--w-strong);
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--ink-3);
  text-align: center;
  border-bottom: none;
}

.dg-m {
  padding: 2px 6px 8px;
  font-size: var(--fs-meta);
  font-weight: var(--w-med);
  color: var(--ink-3);
  text-align: center;
  border-top: none;
}

.dg-corner {
  width: 64px;
  font-size: var(--fs-meta);
  font-weight: var(--w-med);
  color: var(--ink-3);
  background: var(--soft);
}

.dg-tag { background: var(--soft); text-align: center; }

.dg-taglink {
  width: 100%;
  min-height: 44px;
  font-size: var(--fs-meta);
  font-weight: var(--w-med);
  color: var(--ink-2);
  text-decoration: underline;
  text-decoration-color: var(--line);
  text-underline-offset: 3px;
}

.dg-cell { position: relative; padding: 0; min-width: 86px; }

.dg-in {
  width: 100%;
  min-height: 44px;
  border: 0;
  background: transparent;
  text-align: center;
  font-size: var(--fs-body);
  color: var(--ink);
}

.dg-in:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  background: var(--accent-soft);
}

.dg-in.dg-bad {
  color: var(--bad);
  outline: 2px solid var(--bad);
  outline-offset: -2px;
}

.dg-n {
  position: absolute;
  top: 2px;
  right: 4px;
  font-size: 10px;
  color: var(--ink-3);
  pointer-events: none;
}

/* ---- desktop layout ------------------------------------------------------ */

@media (min-width: 900px) and (pointer: fine) {
  /* Sheets become centred dialogs; a bottom drawer is a thumb pattern. */
  .sheet-bg { align-items: center; padding: 28px; }
  .sheet {
    max-width: 560px;
    border-radius: var(--r-card);
    animation: fade 0.16s var(--ease);
  }
  .sheet-grip { display: none; }

  /* The worksheet needs elbow room; reading screens stay at --maxw. */
  .screen-wide { max-width: 900px; }
}

@media (hover: hover) and (pointer: fine) {
  .rowcard:hover,
  .duerow:hover { background: var(--soft); }
  .btn:not(.btn-primary):hover { background: var(--soft); }
  .pm-cell.pm-empty:hover { border-color: var(--accent); }
  .chip:hover { border-color: var(--accent); }
}

/* ---- capture screen ---------------------------------------------------- */

.capture {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  max-width: var(--maxw);
  margin: 0 auto;
  padding-top: env(safe-area-inset-top);
}

.cap-head {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3) 0;
}

.cap-head-main { flex: 1; min-width: 0; }

.cap-head-title {
  font-size: var(--fs-meta);
  font-weight: var(--w-med);
  color: var(--ink-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 5px;
}

.cap-head-main .progress-line { margin-bottom: 0; }

/* The map inside capture is a compact orientation aid, not the main event:
   smaller cells, no legend. */
.cap-map { padding: var(--sp-3) var(--sp-4) 0; }
.cap-map .plotmap-wrap { margin: 0; }
.cap-map .pm-cell { height: 38px; border-radius: 8px; }
.cap-map .pm-cell .pm-v { font-size: 11px; }
.cap-map .pm-legend { display: none; }
.cap-map .pm-crop { font-size: 11px; }

.cap-identity {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-5) var(--sp-3) var(--sp-3);
  margin-top: auto;
}

.cap-identity-mid { flex: 1; min-width: 0; text-align: center; }

.cap-code {
  font-size: var(--fs-huge);
  font-weight: var(--w-strong);
  letter-spacing: 0.02em;
  line-height: 1.1;
}

.cap-ticker {
  font-size: var(--fs-meta);
  color: var(--ink-4);
  margin-top: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.slots {
  display: flex;
  gap: var(--sp-3);
  padding: 0 var(--sp-4);
}

.slot-wrap { flex: 1; min-width: 0; }

.slot {
  width: 100%;
  height: 84px;
  border-radius: var(--r-card);
  border: var(--border-w) solid var(--line);
  background: var(--card);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  text-align: center;
}

.slot.on {
  outline: 2px solid var(--focus);
  outline-offset: -1px;
  background: var(--accent-soft);
}

.slot-l {
  font-size: 11px;
  font-weight: var(--w-med);
  letter-spacing: 0.08em;
  color: var(--ink-4);
}

.slot-row { display: flex; align-items: baseline; gap: 4px; }

.slot-v {
  font-size: 32px;
  font-weight: var(--w-strong);
  line-height: 1.05;
}

.slot-v.is-stored { color: var(--ink-3); }
.slot.on .slot-v.is-stored { color: var(--ink-2); }
.slot-u { font-size: var(--fs-meta); color: var(--ink-4); }

.steppers { display: flex; gap: var(--sp-2); margin-top: var(--sp-2); }

.stepbtn {
  flex: 1;
  min-height: 40px;
  border-radius: 10px;
  border: var(--border-w) solid var(--line);
  background: var(--card);
  font-size: 20px;
  font-weight: var(--w-strong);
  color: var(--ink-2);
}

.stepbtn:active { transform: scale(0.95); background: var(--soft); }

.cap-warn {
  min-height: 20px;
  padding: var(--sp-2) var(--sp-4) 0;
  font-size: var(--fs-meta);
  text-align: center;
}

/* ---- keypad ------------------------------------------------------------ */

.pad {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-3) calc(var(--sp-3) + env(safe-area-inset-bottom));
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.pk {
  height: 54px;
  border-radius: 12px;
  border: var(--border-w) solid var(--line);
  background: var(--card);
  font-size: 24px;
  font-weight: var(--w-med);
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  transition: transform 0.1s var(--ease);
}

.pk:active { transform: scale(0.95); background: var(--soft); }

.pk-aux {
  font-family: var(--font-sans);
  font-size: var(--fs-body);
  color: var(--ink-3);
}

.pk-next {
  grid-column: 4;
  grid-row: 3 / span 2;
  height: auto;
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
  font-family: var(--font-sans);
  font-size: var(--fs-em);
  font-weight: var(--w-strong);
}

.pk-dim { opacity: 0.28; pointer-events: none; }

.shake { animation: shake 0.32s var(--ease); }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  50% { transform: translateX(5px); }
  80% { transform: translateX(-3px); }
}

/* ---- review sheet rows ------------------------------------------------- */

.reviewrow {
  width: 100%;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  min-height: 44px;
  padding: var(--sp-2) 0;
  border-bottom: var(--border-w) solid var(--line-faint);
  text-align: left;
  color: inherit;
}

.reviewrow:active { background: var(--soft); }
.reviewrow.is-empty .reviewrow-vals { color: var(--ink-4); }
.reviewrow-code { flex: none; width: 74px; font-size: var(--fs-meta); color: var(--ink-3); }
.reviewrow-vals { flex: 1; font-size: var(--fs-body); }
.reviewrow-by { flex: none; }

/* ---- log rows, checkboxes, two-column fields --------------------------- */

.row2 { display: flex; gap: var(--sp-3); }
.row2 > .field { flex: 1; min-width: 0; }

.logrow {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2) 0;
  border-bottom: var(--border-w) solid var(--line-faint);
}

.logrow-main { flex: 1; min-width: 0; }
.logrow-title { display: block; font-size: var(--fs-body); font-weight: var(--w-med); }

/* Two lines, not one: visit rows carry an inside and an outside report plus
   photo counts, and a single ellipsised line was cutting the outside half. */
.logrow-sub {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  font-size: var(--fs-meta);
  color: var(--ink-3);
  overflow: hidden;
}

.linkbtn {
  flex: none;
  min-height: 40px;
  padding: 0 var(--sp-2);
  font-size: var(--fs-meta);
  color: var(--ink-4);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.linkbtn:active { color: var(--bad); }

.checkrow {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  min-height: var(--tap);
  padding: var(--sp-2) 0;
  border-bottom: var(--border-w) solid var(--line-faint);
  cursor: pointer;
}

.checkrow:last-of-type { border-bottom: 0; }

.check {
  flex: none;
  width: 24px;
  height: 24px;
  accent-color: var(--accent);
}

.checkrow-main { flex: 1; min-width: 0; }
.checkrow-title { display: block; font-size: var(--fs-body); font-weight: var(--w-med); }
.checkrow-sub { display: block; font-size: var(--fs-meta); color: var(--ink-3); }

/* ---- photos ------------------------------------------------------------ */

.photo-actions { margin-bottom: var(--sp-2); }

.photogrid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--sp-1);
}

.photocell {
  position: relative;
  aspect-ratio: 1;
  border-radius: 10px;
  overflow: hidden;
  background: var(--soft);
  border: var(--border-w) solid var(--line-faint);
  padding: 0;
}

.photocell img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photocell:active { transform: scale(0.97); }
.photocell.is-pending img { opacity: 0.55; }

.photocell-tag {
  position: absolute;
  left: 4px;
  bottom: 4px;
  padding: 1px 5px;
  border-radius: 5px;
  background: rgba(10, 12, 10, 0.62);
  color: #fff;
  font-size: 9px;
  font-weight: var(--w-strong);
  letter-spacing: 0.04em;
}

.photocell-sync {
  position: absolute;
  right: 4px;
  top: 4px;
  padding: 1px 5px;
  border-radius: 5px;
  background: var(--warn);
  color: #fff;
  font-size: 9px;
  font-weight: var(--w-strong);
}

.chiprow {
  display: flex;
  gap: var(--sp-2);
  overflow-x: auto;
  padding-bottom: var(--sp-1);
  scrollbar-width: none;
}

.chiprow::-webkit-scrollbar { display: none; }

.chip {
  flex: none;
  min-height: 40px;
  padding: 0 var(--sp-4);
  border-radius: 999px;
  border: var(--border-w) solid var(--line);
  background: var(--card);
  font-size: var(--fs-meta);
  font-weight: var(--w-med);
  color: var(--ink-3);
  white-space: nowrap;
}

.chip.on {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
  font-weight: var(--w-strong);
}

.viewer {
  position: fixed;
  inset: 0;
  z-index: 70;
  background: rgba(8, 10, 8, 0.96);
  display: flex;
  flex-direction: column;
}

.viewer-img {
  flex: 1;
  display: grid;
  place-items: center;
  overflow: auto;
  padding: var(--sp-4);
  padding-top: calc(var(--sp-4) + env(safe-area-inset-top));
}

.viewer-img img { max-width: 100%; max-height: 100%; object-fit: contain; }

.viewer-bar {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4) calc(var(--sp-3) + env(safe-area-inset-bottom));
  background: rgba(8, 10, 8, 0.9);
  color: #F2F3EE;
}

.viewer-meta { flex: 1; min-width: 0; font-size: var(--fs-meta); }
.viewer-meta .cap { color: rgba(242, 243, 238, 0.6); }
.viewer-bar .btn { background: transparent; border-color: rgba(242, 243, 238, 0.28); color: #F2F3EE; }

/* ---- manual ------------------------------------------------------------ */

.manual-card { padding: 0; overflow: hidden; }

.manual-head {
  width: 100%;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  text-align: left;
  padding: var(--sp-3) var(--sp-4);
  min-height: 56px;
  color: inherit;
}

.manual-head:active { background: var(--soft); }
.manual-head-main { flex: 1; min-width: 0; }
.manual-title { display: block; font-weight: var(--w-strong); }
.manual-week { display: block; font-size: var(--fs-cap); color: var(--ink-4); }

.manual-chev {
  flex: none;
  font-size: 22px;
  color: var(--ink-4);
  transition: transform 0.18s var(--ease);
}

.manual-head[aria-expanded="true"] .manual-chev { transform: rotate(90deg); }

.manual-body { padding: 0 var(--sp-4) var(--sp-4); }
.manual-h { font-size: var(--fs-body); font-weight: var(--w-strong); margin: var(--sp-4) 0 var(--sp-2); }
.manual-p { font-size: var(--fs-body); color: var(--ink-2); margin-bottom: var(--sp-3); line-height: 1.55; }
.manual-ul, .manual-ol { margin: 0 0 var(--sp-3); padding-left: var(--sp-5); color: var(--ink-2); }
.manual-ul li, .manual-ol li { margin-bottom: var(--sp-2); line-height: 1.5; }

.manual-note {
  padding: var(--sp-3);
  border-radius: var(--r-ctl);
  background: var(--warn-soft);
  color: var(--ink-2);
  font-size: var(--fs-meta);
  line-height: 1.5;
  margin-bottom: var(--sp-3);
}

.manual-note strong { color: var(--warn); }

.manual-fig { margin: 0 0 var(--sp-4); }
.manual-fig figcaption { margin-top: var(--sp-2); }

/* Figure 1, redrawn: six planting columns, three per crop. */
.fig-plot {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-2);
  padding: var(--sp-3);
  background: var(--soft);
  border-radius: var(--r-ctl);
}

.fig-crop-label {
  font-size: var(--fs-cap);
  font-weight: var(--w-strong);
  text-align: center;
  margin-bottom: 6px;
  color: var(--ink-3);
}

.fig-cols { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }

.fig-col {
  height: 76px;
  border-radius: 5px;
  border: var(--border-w) solid var(--line);
  background: var(--card);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 4px;
  position: relative;
}

.fig-col::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 22px;
  bottom: 6px;
  width: 2px;
  background: var(--ink-4);
  transform: translateX(-50%);
}

.fig-crop-1 .fig-col { background: var(--accent-soft); }
.fig-col-n { font-size: 10px; color: var(--ink-4); }

/* Figure 1, redrawn: three replication bands, tagged plants marked. */
.fig-rep {
  padding: var(--sp-3);
  background: var(--soft);
  border-radius: var(--r-ctl);
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.fig-band { display: flex; align-items: center; gap: var(--sp-2); }
.fig-band-l { font-size: var(--fs-cap); color: var(--ink-4); width: 22px; flex: none; }

.fig-band-cells {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 4px;
  padding: var(--sp-2);
  background: var(--card);
  border: var(--border-w) solid var(--line-soft);
  border-radius: 6px;
}

.fig-dot {
  height: 14px;
  border-radius: 3px;
  background: var(--ink-5);
}

.fig-dot.on { background: var(--accent); }

/* Table 1.1 */
.tablewrap { overflow-x: auto; margin-bottom: var(--sp-3); }

.t11 { width: 100%; border-collapse: collapse; font-size: var(--fs-meta); }

.t11 th, .t11 td {
  text-align: left;
  padding: 7px 8px;
  border-bottom: var(--border-w) solid var(--line-faint);
  white-space: nowrap;
}

.t11 thead th {
  font-size: var(--fs-cap);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-4);
  font-weight: var(--w-strong);
}

.t11 tbody th { vertical-align: middle; color: var(--ink-3); font-weight: var(--w-med); }
.t11 tr.is-you td, .t11 tr.is-you th { background: var(--accent-soft); font-weight: var(--w-strong); }

/* ---- photos attached to a form before it is saved ---------------------- */

.attachstrip {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  margin-bottom: var(--sp-3);
}

.attach {
  position: relative;
  width: 72px;
  height: 72px;
  border-radius: 10px;
  overflow: hidden;
  background: var(--soft);
  border: var(--border-w) solid var(--line-faint);
  flex: none;
}

.attach img { width: 100%; height: 100%; object-fit: cover; display: block; }

.attach-x {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: rgba(10, 12, 10, 0.7);
  color: #fff;
  font-size: 16px;
  line-height: 1;
  display: grid;
  place-items: center;
}

.attach-x:active { background: var(--bad); }

/* Upload state lives on the thumbnail itself: spinner while compressing and
   dispatching, a tick once safely queued, a mark if it was refused. */
.attach.is-uploading img { opacity: 0.4; }

.attach-spin {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}

.attach-tick,
.attach-err {
  position: absolute;
  left: 3px;
  bottom: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 10px;
  font-weight: var(--w-strong);
  color: #fff;
}

.attach-tick { background: var(--ok); }
.attach-err { background: var(--bad); }

/* ---- practicals 2-5 ------------------------------------------------------ */

/* An entry row that opens for editing: same anatomy as a logrow, but the main
   area is a real button. */
button.logrow-open {
  text-align: left;
  display: block;
}

.prac-computed .kv {
  background: var(--soft);
  border-radius: var(--r-ctl);
  padding: 10px 12px;
}

/* ---- print view ---------------------------------------------------------- */

.printpage {
  max-width: 900px;
  margin: 0 auto;
  padding: 20px 20px 60px;
  background: var(--paper);
}

.print-actions {
  display: flex;
  gap: 10px;
  justify-content: space-between;
  margin-bottom: 18px;
}

.pr-title { font-size: 22px; font-weight: var(--w-strong); margin-bottom: 4px; }
.pr-meta { font-size: var(--fs-meta); color: var(--ink-3); margin-bottom: 14px; }
.pr-h2 { font-size: 16px; font-weight: var(--w-strong); margin: 20px 0 8px; }
.pr-h3 { font-size: var(--fs-meta); font-weight: var(--w-med); color: var(--ink-2); margin: 10px 0 6px; }

.pr-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  margin-bottom: 10px;
}

.pr-table th,
.pr-table td {
  border: 1px solid var(--ink-3);
  padding: 5px 7px;
  text-align: left;
  vertical-align: top;
}

.pr-table th { font-weight: var(--w-med); background: var(--soft); }

@media print {
  /* Paper gets the worksheets and nothing else. */
  .noprint, .tabbar, .apphead, .toast { display: none !important; }
  body { background: #fff; }
  .printpage { max-width: none; padding: 0; background: #fff; color: #000; }
  .pr-table th, .pr-table td { border-color: #000; }
  .pr-table th { background: #eee; }
  .pr-h2 { break-after: avoid; }
  .pr-table { break-inside: auto; }
  tr { break-inside: avoid; }
}

/* ---- results ------------------------------------------------------------- */

.res-sec { margin-bottom: var(--sp-6); }
.res-sub { font-size: var(--fs-em); font-weight: var(--w-strong); margin: var(--sp-4) 0 var(--sp-2); }
.res-scroll { overflow-x: auto; margin: var(--sp-2) 0; }

.res-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card);
  font-size: var(--fs-meta);
}

.res-table th,
.res-table td {
  border: var(--border-w) solid var(--line-soft);
  padding: 7px 9px;
  text-align: right;
  white-space: nowrap;
}

.res-table th:first-child,
.res-table td:first-child { text-align: left; }

.res-table th {
  font-weight: var(--w-med);
  color: var(--ink-3);
  background: var(--soft);
}

/* Significance carried by weight, not a coloured stripe. */
.res-sig td { font-weight: var(--w-strong); }

/* ---- display math: fractions and sigmas from flexbox --------------------- */

.eq { margin: var(--sp-4) 0; }

.eq-lead {
  display: flex;
  gap: 10px;
  align-items: baseline;
  font-size: var(--fs-body);
  color: var(--ink-2);
  line-height: 1.5;
}

.eq-n {
  flex: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--soft);
  color: var(--ink-2);
  font-size: 12px;
  display: grid;
  place-items: center;
  transform: translateY(3px);
}

.eq-math {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 12px 6px;
  font-size: 17px;
  color: var(--ink);
}

.eq-math sub { font-size: 11px; }

.frac {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  vertical-align: middle;
  margin: 0 2px;
}

.frac-t,
.frac-b {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 1px 8px;
}

.frac-t { border-bottom: 1.5px solid var(--ink); }

.sig {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  line-height: 1;
}

.sig-s { font-size: 1.45em; }

.sig-u {
  font-size: 9px;
  color: var(--ink-3);
  margin-top: 2px;
  letter-spacing: 0.02em;
}

.eq-df { border-collapse: collapse; font-size: var(--fs-body); }

.eq-df td {
  border: var(--border-w) solid var(--line-soft);
  padding: 6px 12px;
}

.eq-df td:last-child { text-align: center; }

.res-workedbox {
  margin-top: var(--sp-3);
  padding: var(--sp-3) var(--sp-3) var(--sp-2);
  background: var(--soft);
  border-radius: var(--r-ctl);
}

.res-workedbox .eq-math { padding: 8px 4px; }

/* ---- watering rota ------------------------------------------------------- */

.rota-row {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  margin-bottom: 8px;
}

.rota-day {
  flex: none;
  width: 96px;
  font-size: var(--fs-meta);
  font-weight: var(--w-med);
  color: var(--ink-2);
}

.rota-sel { flex: 1; }

.rota-notify {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: var(--border-w) solid var(--line-soft);
  font-size: var(--fs-body);
  color: var(--ink);
}

.rota-notify input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

/* ---- home: week, turn, feed, stats -------------------------------------- */

.weekline { display: flex; align-items: center; gap: var(--sp-3); }

.weeknum {
  flex: none;
  width: 46px; height: 46px;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent);
  display: grid;
  place-items: center;
  font-size: 20px;
  font-weight: var(--w-strong);
}

.duerow {
  width: 100%;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  min-height: 52px;
  padding: var(--sp-2) 0;
  border-top: var(--border-w) solid var(--line-faint);
  text-align: left;
  color: inherit;
  margin-top: var(--sp-2);
}

.duerow:active { background: var(--soft); }
.duerow-main { flex: 1; min-width: 0; }
.duerow-title { display: block; font-weight: var(--w-med); }
.duerow-sub { display: block; font-size: var(--fs-meta); color: var(--ink-3); }
.duerow-go { flex: none; font-size: var(--fs-meta); font-weight: var(--w-med); }

.turn-row { display: flex; align-items: center; gap: var(--sp-3); }
.turn-main { flex: 1; min-width: 0; }
.turn-name { font-size: var(--fs-em); font-weight: var(--w-strong); }

.avatar-lg { width: 48px; height: 48px; font-size: var(--fs-body); }

.feedrow {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  padding: var(--sp-2) 0;
  border-bottom: var(--border-w) solid var(--line-faint);
}

.feedrow:last-child { border-bottom: 0; }
.feedrow-main { flex: 1; min-width: 0; }
.feedrow-text { display: block; font-size: var(--fs-meta); color: var(--ink-2); line-height: 1.45; }
.feedrow-text strong { font-weight: var(--w-strong); color: var(--ink); }

.statgrid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--sp-3);
}

.stat {
  padding: var(--sp-3);
  border-radius: var(--r-ctl);
  background: var(--soft);
}

.stat-n { font-size: 24px; font-weight: var(--w-strong); line-height: 1.1; }
.stat-of { font-size: var(--fs-meta); font-weight: var(--w-reg); color: var(--ink-4); }
.stat-l { font-size: var(--fs-cap); color: var(--ink-3); margin-top: 2px; }

.cmp { margin-top: var(--sp-3); }
.cmp-label { margin-bottom: var(--sp-1); }
.cmp-row { display: flex; align-items: center; gap: var(--sp-2); margin-bottom: 5px; }
.cmp-name { flex: none; width: 54px; font-size: var(--fs-cap); color: var(--ink-3); }

.cmp-track {
  flex: 1;
  height: 14px;
  border-radius: 7px;
  background: var(--soft);
  overflow: hidden;
}

.cmp-fill { display: block; height: 100%; border-radius: 7px; }
.cmp-in { background: var(--accent); }
.cmp-out { background: var(--ink-4); }
.cmp-val { flex: none; width: 46px; text-align: right; font-size: var(--fs-meta); }

/* ---- explainers --------------------------------------------------------- */

.explain { background: var(--accent-soft); border-color: transparent; }
.explain-list { margin: var(--sp-3) 0; padding-left: var(--sp-5); }

.explain-list li {
  margin-bottom: var(--sp-2);
  font-size: var(--fs-meta);
  line-height: 1.5;
  color: var(--ink-2);
}

.explain-link {
  display: block;
  width: 100%;
  min-height: 40px;
  font-size: var(--fs-meta);
  color: var(--ink-3);
  text-decoration: underline;
  text-underline-offset: 3px;
  text-align: left;
  margin-bottom: var(--sp-1);
}

.cap-plain {
  font-size: var(--fs-cap);
  color: var(--ink-3);
  margin-top: 3px;
  line-height: 1.3;
}

.helpmark {
  display: grid;
  place-items: center;
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 1.5px solid currentColor;
  font-size: 13px;
  font-weight: var(--w-strong);
  line-height: 1;
}

.datewrap { margin-bottom: var(--sp-3); }

.datewrap input {
  width: 100%;
  min-height: 56px;
  padding: 0 var(--sp-4);
  border-radius: var(--r-card);
  border: var(--border-w) solid var(--line);
  background: var(--card);
  box-shadow: var(--shadow-card);
  font-size: var(--fs-em);
  color: var(--ink);
}

.datewrap input:focus-visible { border-color: var(--accent); }

/* ---- several plants in one square -------------------------------------- */

.readings {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: var(--sp-3) var(--sp-4) 0;
}

.reading {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 34px;
  padding: 0 8px 0 10px;
  border-radius: 999px;
  border: var(--border-w) solid var(--line);
  background: var(--card);
  font-size: var(--fs-meta);
  color: var(--ink-2);
}

.reading:active { background: var(--bad-soft); border-color: var(--bad); }
.reading-x { color: var(--ink-4); font-size: 15px; line-height: 1; }

.addplant {
  display: block;
  width: calc(100% - var(--sp-4) * 2);
  margin: var(--sp-2) var(--sp-4) 0;
  min-height: 40px;
  border-radius: var(--r-ctl);
  border: var(--border-w) dashed var(--line);
  background: transparent;
  font-size: var(--fs-meta);
  font-weight: var(--w-med);
  color: var(--accent);
}

.addplant:active { background: var(--accent-soft); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
