/* Staff app (field log and admin). Colours, fonts, radii and shadows come from ../css/tokens.css,
   loaded first on every page. No inline styles: the CSP blocks them. */

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--page); color: var(--ink); font: 16px/1.5 var(--sans); font-variant-numeric: lining-nums tabular-nums; -webkit-font-smoothing: antialiased; }
a { color: var(--link); text-underline-offset: 3px; }
:focus-visible { outline: 3px solid var(--blue-500); outline-offset: 2px; }
h1, h2 { font-family: var(--serif); font-weight: 600; line-height: 1.15; margin: 0 0 .5em; letter-spacing: -.01em; }
h1 { font-size: clamp(1.7rem, 5vw, 2.3rem); color: var(--navy-900); }
h2 { font-size: 1.25rem; }
h3 { font-size: 1rem; margin: 8px 0 0; }
p { margin: 0 0 1em; }
.wrap { max-width: 1000px; margin: 0 auto; padding: 0 16px; }
.narrow { max-width: 440px; }
main { padding: 24px 0 56px; }
.hint, small { color: var(--muted); font-size: .9rem; }
.lede { color: var(--ink-soft); max-width: 70ch; }
.mono, .hash { font-family: var(--mono); font-weight: 500; }
.page-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 8px 16px; }

/* Header */
.site-head { background: var(--navy-900); color: #fff; position: sticky; top: 0; z-index: 10; }
.site-head .wrap { display: flex; align-items: center; gap: 6px 18px; min-height: 60px; }
.brand { color: #fff; text-decoration: none; display: flex; align-items: center; gap: 9px; font-family: var(--serif); font-weight: 600; white-space: nowrap; }
.brand-mark { width: 28px; height: 28px; flex: none; }
.brand-mark.big { width: 44px; height: 44px; }
.nav { display: flex; gap: 2px; flex-wrap: wrap; }
.nav a { color: #d5e2f2; text-decoration: none; padding: 7px 12px; border-radius: var(--r-pill); font-size: .95rem; transition: background var(--dur) var(--ease); }
.nav a:hover { background: rgba(255, 255, 255, .08); color: #fff; }
.nav a[aria-current="page"] { background: var(--blue-50); color: var(--navy-950); }
.who { margin-left: auto; font-size: .9rem; color: #d5e2f2; display: flex; gap: 12px; align-items: center; }
.site-head .link { color: #fff; }
.head-link { display: none; color: #fff; }

/* Bottom tab bar and More sheet (phones only) */
.tabbar, .sheet { display: none; }
@media (max-width: 720px) {
  .site-head .nav { display: none; }
  .site-head .wrap { min-height: 54px; }
  .who .signout { display: none; }
  body.has-tabbar main { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }
  .tabbar { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; background: var(--card); border-top: 1px solid var(--line); box-shadow: 0 -6px 20px -12px rgba(16, 24, 40, .25); padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); }
  .tabbar a, .tabbar button { flex: 1; display: grid; justify-items: center; gap: 2px; padding: 6px 4px; min-height: 52px; border: 0; background: none; font: 600 .78rem/1.2 var(--sans); color: var(--muted); text-decoration: none; border-radius: var(--r-md); cursor: pointer; }
  .tabbar [aria-current="page"] { color: var(--navy-900); background: var(--blue-50); }
  .tab-icon { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
  .tab-icon circle { fill: currentColor; stroke: none; }
  .sheet:not([hidden]) { display: block; position: fixed; inset: 0; z-index: 30; background: rgba(13, 20, 33, .4); }
  .sheet-panel { position: absolute; left: 8px; right: 8px; bottom: calc(76px + env(safe-area-inset-bottom)); background: var(--card); border-radius: var(--r-lg); box-shadow: var(--shadow-2); padding: 8px; display: grid; }
  .sheet-panel a, .sheet-panel button { display: block; text-align: left; padding: 14px 16px; border-radius: var(--r-md); font: 600 1rem/1.2 var(--sans); color: var(--ink); text-decoration: none; background: none; border: 0; cursor: pointer; }
  .sheet-panel [aria-current="page"] { background: var(--blue-50); }
  .sheet-panel .signout { color: var(--bad); border-top: 1px solid var(--line); border-radius: 0; margin-top: 4px; }
  /* Field log: Save sits where the tab bar would be; Nodes is one tap away in the header. */
  body.log-page .tabbar { display: none; }
  body.log-page .head-link { display: inline; }
  body.log-page main { padding-bottom: calc(110px + env(safe-area-inset-bottom)); }
}

/* Cards and forms */
.card { background: var(--card); border-radius: var(--r-lg); box-shadow: var(--shadow-1); padding: 20px; margin: 0 0 18px; }
.card > h2:first-child { margin-top: 0; }
.form { display: grid; gap: 14px; }
.form label, .filters label { display: grid; gap: 5px; font-size: .88rem; font-weight: 600; color: var(--ink-soft); }
input, select, textarea { font: inherit; font-weight: 400; width: 100%; padding: 10px 12px; min-height: 46px; border: 1px solid var(--line-strong); border-radius: var(--r-sm); background: #fff; color: var(--ink); }
input:focus, select:focus, textarea:focus { border-color: var(--blue-700); outline: 2px solid rgba(56, 97, 251, .18); outline-offset: 0; }
.row2, .row3 { display: grid; gap: 12px; grid-template-columns: 1fr 1fr; }
.row3 { grid-template-columns: 2fr 1fr 1fr; }
fieldset { border: 1px solid var(--line); border-radius: var(--r-md); padding: 12px 14px 14px; margin: 0; display: grid; gap: 12px; min-width: 0; }
legend { font-size: .9rem; font-weight: 600; color: var(--ink-soft); padding: 0 6px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 50px; padding: 10px 20px; border: 1px solid var(--navy-900); border-radius: var(--r-pill); background: var(--navy-900); color: #fff; font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; transition: background var(--dur) var(--ease); }
.btn:hover { background: var(--blue-700); border-color: var(--blue-700); }
.btn.secondary { background: transparent; color: var(--navy-900); }
.btn.secondary:hover { background: var(--page); }
.btn.small { min-height: 36px; padding: 4px 14px; font-size: .88rem; }
.btn:disabled { opacity: .55; cursor: default; }
.link { background: none; border: 0; padding: 0; font: inherit; color: var(--link); text-decoration: underline; cursor: pointer; }

/* Observations: three-state yes/no buttons and count steppers */
.obs-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.obs-item { display: grid; gap: 6px; }
.obs-name { font-size: .88rem; font-weight: 600; color: var(--ink-soft); }
.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--page); border-radius: var(--r-md); padding: 3px; gap: 3px; }
.seg button { min-height: 44px; border: 0; border-radius: 9px; background: transparent; font: 600 .95rem/1 var(--sans); color: var(--ink-soft); cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--navy-900); color: #fff; box-shadow: var(--shadow-1); }
.seg button.no[aria-pressed="true"] { background: var(--ink-soft); }
.stepper { display: grid; grid-template-columns: 46px 1fr 46px; gap: 4px; }
.stepper button { min-height: 46px; border: 1px solid var(--line-strong); border-radius: var(--r-sm); background: #fff; font: 600 1.3rem/1 var(--sans); color: var(--navy-900); cursor: pointer; }
.stepper input { text-align: center; font-weight: 600; -moz-appearance: textfield; appearance: textfield; }
.stepper input::-webkit-inner-spin-button, .stepper input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.obs-hint { grid-column: 1 / -1; margin: -4px 0 0; }

/* Photo */
.photo-pick input[type="file"] { position: absolute; width: 1px; height: 1px; opacity: 0; }
.form .photo-btn, .photo-btn { display: flex; align-items: center; justify-content: center; gap: 10px; min-height: 54px; border: 1.5px dashed var(--line-strong); border-radius: var(--r-md); background: var(--page); font-weight: 600; color: var(--navy-900); cursor: pointer; }
.photo-pick input:focus-visible + .photo-btn { outline: 3px solid var(--blue-500); outline-offset: 2px; }
.photo-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; }
.photo-preview { display: flex; align-items: center; gap: 12px; }
.photo-preview img { width: 88px; height: 66px; object-fit: cover; border-radius: var(--r-sm); }

/* Status */
.bar { display: flex; flex-wrap: wrap; gap: 8px; }
.status { display: inline-flex; align-items: center; gap: 6px; padding: 3px 11px; border-radius: var(--r-pill); background: var(--ok-bg); border: 1px solid var(--ok-line); font-size: .85rem; }
.status::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--ok); }
.status.warn { background: var(--warn-bg); border-color: var(--warn-line); }
.status.warn::before { background: var(--watch); }
.toast { padding: 11px 14px; border-radius: var(--r-md); background: var(--ok-bg); border: 1px solid var(--ok-line); margin: 0 0 12px; }
.toast.error { background: var(--bad-bg); border-color: var(--bad-line); }
.toast.warn { background: var(--warn-bg); border-color: var(--warn-line); }
#msg .toast, #create-msg .toast, #user-msg .toast { margin: 0; }

/* Tabs (segmented) */
.tabs { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; margin: 4px 0 14px; padding: 4px; background: var(--page-2); border-radius: var(--r-pill); }
.tabs button { min-height: 44px; border: 0; background: transparent; color: var(--ink-soft); border-radius: var(--r-pill); font: inherit; font-weight: 600; cursor: pointer; }
.tabs button[aria-selected="true"] { background: var(--card); color: var(--navy-900); box-shadow: var(--shadow-1); }

/* Save button on the field log */
.save-bar { margin-top: 4px; }
@media (max-width: 720px) {
  .save-bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; margin: 0; padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); background: var(--card); border-top: 1px solid var(--line); box-shadow: 0 -6px 20px -12px rgba(16, 24, 40, .25); }
  .save-bar .btn { width: 100%; }
}

/* Queue */
.queue-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.queue-head h2 { margin: 0; }
.queue { list-style: none; padding: 0; margin: 10px 0 0; }
.queue li { display: flex; justify-content: space-between; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.queue li.refused { color: var(--bad); }
.row-actions { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; flex: none; }

/* Tables */
.scroll { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: .92rem; }
th, td { text-align: left; padding: 10px 12px 10px 0; border-bottom: 1px solid var(--line); white-space: nowrap; }
thead th { color: var(--muted); font-weight: 600; font-size: .85rem; }
tbody tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; }
.h-Watch { color: var(--watch); font-weight: 600; }
.h-Lost { color: var(--bad); font-weight: 600; }
.filters { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr; gap: 10px; margin: 0 0 8px; }
.id-link { font-family: var(--mono); font-weight: 500; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: 0; }

/* Node page */
.facts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px 16px; }
.facts span { display: block; color: var(--muted); font-size: .85rem; font-weight: 500; }
.facts .missing { color: var(--watch); }
.check { padding: 12px 14px; border-radius: var(--r-md); border: 1px solid; }
.check.ok { background: var(--ok-bg); border-color: var(--ok-line); }
.check.bad { background: var(--bad-bg); border-color: var(--bad-line); color: var(--bad); }
.history { list-style: none; padding: 0; margin: 0; }
.history li { background: var(--card); border-radius: var(--r-md); box-shadow: var(--shadow-1); padding: 14px 16px; margin: 0 0 10px; display: grid; gap: 4px; }
.history .when, .history .hash, .history .gps { color: var(--muted); font-size: .85rem; }
.history .note { background: var(--blue-50); border-radius: var(--r-sm); padding: 6px 10px; font-size: .92rem; }
.history img { max-width: 100%; width: 320px; border-radius: var(--r-sm); margin-top: 6px; }
.node-title { font-family: var(--mono); font-weight: 500; letter-spacing: -.02em; }

/* Collapsible forms (sales, prices) */
details.drawer { background: var(--card); border-radius: var(--r-lg); box-shadow: var(--shadow-1); margin: 0 0 18px; }
details.drawer > summary { list-style: none; cursor: pointer; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; font-family: var(--serif); font-weight: 600; font-size: 1.15rem; color: var(--navy-900); }
details.drawer > summary::-webkit-details-marker { display: none; }
details.drawer > summary::after { content: '+'; font: 600 1.5rem/1 var(--sans); width: 36px; height: 36px; display: grid; place-items: center; border-radius: 50%; background: var(--navy-900); color: #fff; }
details.drawer[open] > summary::after { content: '\2212'; }
details.drawer > .form { padding: 0 20px 20px; }

@media (max-width: 640px) {
  .row3 { grid-template-columns: 1fr 1fr; }
  .row3 > :first-child { grid-column: 1 / -1; }
  .filters { grid-template-columns: 1fr 1fr; }
  .filters > :first-child { grid-column: 1 / -1; }
  .facts { grid-template-columns: 1fr 1fr; }
  .card { padding: 16px; }
  main { padding-top: 18px; }
}

/* Sign-in */
.signin-page main { padding: 0; }
.signin { min-height: 100vh; display: grid; align-items: center; padding: 40px 0; }
.signin h1 { display: flex; align-items: center; gap: 12px; font-size: 1.9rem; }
.signin .card { padding: 22px; }
.signin-art { display: none; }
@media (min-width: 900px) {
  .signin-page { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); min-height: 100vh; }
  .signin-art { display: flex; flex-direction: column; justify-content: flex-end; padding: 56px; color: #fff; background: linear-gradient(180deg, rgba(13, 20, 33, .25), rgba(13, 20, 33, .88)), url(../../img/plantlets-600.webp) center / cover no-repeat, var(--navy-900); }
  .signin-art p { max-width: 34ch; font-family: var(--serif); font-size: 1.6rem; line-height: 1.25; margin: 0 0 12px; }
  .signin-art span { color: #c5d6ec; font-size: .9rem; }
}

/* QR label sheet (labels.html). A4 portrait, cut along the grey lines. */
.labels { display: grid; grid-template-columns: repeat(var(--label-cols, 4), 1fr); gap: 0; background: #fff; margin-top: 16px; width: 100%; box-sizing: border-box; }
.label { border: 1px dashed #c9d2ca; padding: 2.5mm 3mm; text-align: center; break-inside: avoid; display: grid; justify-items: center; gap: 1.5mm; }
.label svg { width: 100%; max-width: var(--qr-size, 34mm); height: auto; display: block; }
.label strong { font-size: var(--id-size, 14pt); letter-spacing: .02em; line-height: 1; }
.label span { font-size: 7pt; color: #555; }
.labels-warn { background: var(--warn-bg); border: 1px solid var(--warn-line); border-radius: var(--r-sm); padding: 10px 12px; }
@media print {
  @page { size: A4 portrait; margin: 8mm; }
  .site-head, .tabbar, .sheet, .no-print { display: none !important; }
  body, .wrap, main { background: #fff; margin: 0; padding: 0; max-width: none; }
  body.has-tabbar main { padding: 0; }
  .labels { margin: 0; }
}

/* Milestone 4: lab, sales, plots */
h2.sub { margin-top: 22px; font-size: 1.05rem; }
td.wrap-cell { white-space: normal; min-width: 140px; }
tr.withdrawn td { color: var(--muted); text-decoration: line-through; }
tr.withdrawn td:last-child { text-decoration: none; }
.inline-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: end; padding: 6px 0; }
.inline-form label { display: grid; gap: 4px; flex: 1 1 240px; font-size: .9rem; }
.check-row { display: flex !important; align-items: center; gap: 8px; }
.check-row input { width: auto; min-height: 0; }
#plots-card form { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.sub { color: var(--muted); margin: -4px 0 12px; }
details.drawer.inner { box-shadow: none; background: var(--page); margin: 14px 0 0; border-radius: var(--r-md); }
details.drawer.inner > summary { font-size: 1rem; padding: 12px 16px; }
details.drawer.inner > summary::after { width: 30px; height: 30px; font-size: 1.2rem; }
details.drawer.inner > .form { padding: 0 16px 16px; }
