/* Польовий журнал: папір, чорнило, земля. Контраст розрахований на сонце. */
:root {
  --paper: #f4efe4;
  --paper-2: #ebe3d3;
  --card: #fffdf8;
  --ink: #1d2a44;
  --ink-soft: #55607a;
  --line: #cfc4ad;
  --soil: #8a5a2b;
  --done: #2f7d4f;
  --done-bg: #d7ecdc;
  --pending: #b7791f;
  --pending-bg: #f8e7c4;
  --absent-bg: #d9d4ca;
  --error: #b42318;
  --error-bg: #fbe0dc;
  --focus: #2b59c3;
  --radius-s: 6px;
  --radius-m: 12px;
  --cell: 44px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 16px/1.4 var(--font);
  color: var(--ink);
  background: var(--paper);
  background-image: repeating-linear-gradient(0deg, transparent 0 27px, rgba(29, 42, 68, .05) 27px 28px);
  min-height: 100dvh;
  padding-bottom: env(safe-area-inset-bottom);
}
a { color: var(--ink); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
main { padding: 12px 16px 96px; max-width: 1400px; margin: 0 auto; outline: none; }
h1 { font-size: 1.35rem; margin: 0; letter-spacing: -.01em; }
h2 { font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: var(--soil); margin: 0 0 10px; }
small { color: var(--ink-soft); font-weight: 400; }
code { background: var(--paper-2); padding: 1px 5px; border-radius: 4px; }

/* ---------- верхня панель ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  padding: calc(8px + env(safe-area-inset-top)) 16px 8px;
  background: var(--ink); color: var(--paper);
}
.brand { color: inherit; text-decoration: none; font-weight: 700; margin-right: auto; }
.brand span { font-weight: 400; opacity: .7; margin-left: 4px; font-size: .9em; }
.sync, .icon-btn {
  font: inherit; border: 1px solid rgba(244, 239, 228, .35); background: transparent; color: inherit;
  border-radius: 999px; padding: 6px 12px; min-height: 36px; cursor: pointer;
}
.icon-btn { font-size: 1.2rem; padding: 4px 12px; }
.sync[data-state="pending"] { background: var(--pending); border-color: var(--pending); }
.sync[data-state="offline"] { background: #6b6455; }
.sync[data-state="error"] { background: var(--error); border-color: var(--error); }
.menu {
  position: fixed; right: 12px; top: 56px; z-index: 20; display: grid;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-m);
  box-shadow: 0 12px 32px rgba(29, 42, 68, .18); overflow: hidden; min-width: 260px;
}
.menu[hidden], .toast[hidden] { display: none; }
.menu a, .menu button {
  font: inherit; text-align: left; padding: 14px 16px; border: 0; background: none;
  color: var(--ink); text-decoration: none; cursor: pointer; border-bottom: 1px solid var(--paper-2);
}
.menu a:hover, .menu button:hover { background: var(--paper); }

/* ---------- кнопки й поля ---------- */
button, .primary, .ghost { font: inherit; cursor: pointer; }
.primary {
  background: var(--ink); color: var(--paper); border: 0; border-radius: var(--radius-s);
  padding: 14px 22px; font-weight: 600; min-height: 52px;
  box-shadow: 0 2px 0 #0d1526; transition: transform .08s ease, box-shadow .08s ease;
}
.primary:active { transform: translateY(2px); box-shadow: none; }
.primary.alt { background: var(--soil); box-shadow: 0 2px 0 #5c3b1a; }
.ghost { color: var(--ink-soft); padding: 12px 4px; margin-right: auto; font-size: .9rem; }
input[type="text"], input[type="password"], input[type="date"], input:not([type]), textarea {
  font: inherit; font-size: 1.15rem; width: 100%;
  padding: 10px 12px; min-height: 48px; border: 2px solid var(--line); border-radius: var(--radius-s);
  background: var(--card); color: var(--ink); font-variant-numeric: tabular-nums;
}
input:focus, textarea:focus { border-color: var(--ink); outline: none; box-shadow: 0 0 0 3px rgba(43, 89, 195, .2); }

/* ---------- схема ділянки ---------- */
.map-head { display: grid; gap: 10px; margin-bottom: 12px; }
.tabs { display: flex; gap: 6px; overflow-x: auto; }
.tab {
  text-decoration: none; padding: 8px 14px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--card); white-space: nowrap;
}
.tab[aria-selected="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.search { display: flex; gap: 8px; }
.search button { border: 2px solid var(--ink); background: var(--card); border-radius: var(--radius-s); padding: 0 16px; font-weight: 600; }
.progress { display: flex; align-items: center; gap: 10px; font-variant-numeric: tabular-nums; }
.progress .bar { flex: 1; height: 10px; background: var(--paper-2); border-radius: 999px; overflow: hidden; }
.progress .bar span { display: block; height: 100%; background: var(--done); transition: width .3s ease; }
.legend { list-style: none; display: flex; flex-wrap: wrap; gap: 4px 14px; padding: 0; margin: 0; font-size: .8rem; color: var(--ink-soft); }
.legend li { display: flex; align-items: center; gap: 6px; }
.legend .cell { width: 16px; height: 16px; min-height: 0; border-radius: 4px; display: inline-block; }

.grid-scroll {
  overflow: auto; margin: 0 -16px; padding: 4px 16px 16px;
  max-height: calc(100dvh - 250px); overscroll-behavior: contain;
}
.plot-grid {
  display: grid; gap: 3px; width: max-content;
  grid-template-columns: 34px repeat(var(--cols), var(--cell));
  grid-template-rows: 46px 22px repeat(var(--rows), var(--cell));
}
.corner, .row-head, .combo-head {
  position: sticky; background: var(--paper); z-index: 2;
  display: flex; align-items: center; justify-content: center;
  font-size: .75rem; color: var(--ink-soft); font-variant-numeric: tabular-nums;
}
.corner { top: 0; left: 0; z-index: 3; grid-row: 1; grid-column: 1; }
.corner.sub { top: 46px; grid-row: 2; }
.rowno-head { position: sticky; top: 46px; z-index: 2; grid-row: 2; background: var(--paper);
  display: flex; align-items: center; justify-content: center; font-size: .72rem; color: var(--ink-soft);
  font-variant-numeric: tabular-nums; }
.row-head { left: 0; grid-column: 1; font-weight: 600; }
.combo-head {
  top: 0; grid-row: 1; flex-direction: column; line-height: 1.1;
  border-bottom: 3px solid var(--soil); font-weight: 700; color: var(--ink); font-size: .85rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 4px;
}
.combo-head small { font-size: .65rem; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.cell {
  position: relative; display: flex; align-items: center; justify-content: center;
  min-height: var(--cell); border-radius: var(--radius-s);
  text-decoration: none; font-weight: 700; font-variant-numeric: tabular-nums;
  background: var(--card); border: 1.5px solid var(--line); color: var(--ink);
  transition: transform .08s ease;
}
.cell:active { transform: scale(.94); }
.cell i { position: absolute; top: 1px; right: 4px; font-style: normal; color: var(--soil); }
.cell.empty { background: transparent; border-style: dashed; color: var(--ink-soft); font-weight: 400; }
.cell.done { background: var(--done-bg); border-color: var(--done); color: #17432a; }
.cell.pending { background: var(--pending-bg); border-color: var(--pending); }
.cell.absent { background: var(--absent-bg); color: var(--ink-soft); text-decoration: line-through; }
.cell.error { background: var(--error-bg); border-color: var(--error); }
.cell.uncertain { box-shadow: inset 0 0 0 3px #e0a100; }

/* ---------- картка куща ---------- */
.sample { max-width: 720px; margin: 0 auto; }
.sample-head { display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: start; margin: 4px 0 12px; }
.sample-head h1 { font-size: 2rem; font-variant-numeric: tabular-nums; }
.sample-head h1 small { font-size: .9rem; }
.back, .step a {
  display: inline-flex; align-items: center; justify-content: center; width: 48px; height: 48px;
  border-radius: 50%; background: var(--card); border: 1.5px solid var(--line); text-decoration: none; font-size: 1.3rem;
}
.step { display: flex; gap: 6px; }
.where { margin: 2px 0 0; color: var(--ink-soft); font-size: .9rem; }
.flag { background: #fde9a8; color: #6b4b00; padding: 1px 6px; border-radius: 4px; font-size: .8rem; margin-left: 4px; }
.seedling {
  background: var(--paper-2); border-radius: var(--radius-m); padding: 10px 14px; margin-bottom: 14px; font-size: .9rem;
}
.seedling summary { cursor: pointer; font-weight: 600; }
.seedling dl, .derived { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px 16px; margin: 10px 0 0; }
dt { font-size: .75rem; color: var(--ink-soft); }
dd { margin: 0; font-weight: 700; font-variant-numeric: tabular-nums; }
.group {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-m);
  padding: 14px; margin-bottom: 12px; box-shadow: 0 1px 0 var(--line);
}
.fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.field { display: grid; gap: 4px; min-width: 0; }
.field label, legend { font-size: .85rem; font-weight: 600; }
.field.enum, .field.text, .field.bool { grid-column: 1 / -1; }
fieldset.field { border: 0; padding: 0; margin: 0; }
.field.bool { display: flex; align-items: center; gap: 10px; flex-direction: row-reverse; justify-content: flex-end; }
.field.bool input, .check input { width: 26px; height: 26px; accent-color: var(--ink); }
.check { display: flex; align-items: center; gap: 10px; margin: 8px 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip span {
  display: inline-block; padding: 10px 14px; border-radius: 999px; border: 1.5px solid var(--line);
  background: var(--card); cursor: pointer; user-select: none;
}
.chip input:checked + span { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.chip input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }
.err { color: var(--error); margin: 0; font-size: .85rem; font-weight: 600; }
.live { background: #f3f6fb; border-color: #c9d3e6; }
.warn { margin: 12px 0 0; padding: 10px 12px 10px 28px; background: var(--pending-bg); border-radius: var(--radius-s); color: #6b4300; }
.hint { color: var(--ink-soft); font-size: .85rem; }
.actions {
  position: sticky; bottom: 0; display: flex; gap: 10px; justify-content: flex-end; align-items: center;
  padding: 12px 0 calc(12px + env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--paper) 30%);
}
form.is-absent .group:not(:first-of-type):not(.live) { opacity: .4; }

/* ---------- службові екрани ---------- */
.login { max-width: 360px; margin: 12vh auto 0; display: grid; gap: 18px; }
.login form { display: grid; gap: 10px; }
.empty-state { text-align: center; margin-top: 15vh; }
.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: var(--paper); padding: 12px 18px; border-radius: var(--radius-m);
  z-index: 30; max-width: calc(100vw - 32px); box-shadow: 0 8px 24px rgba(0, 0, 0, .25);
}
.toast[data-kind="error"] { background: var(--error); }

@media (max-width: 420px) {
  :root { --cell: 40px; }
  .sample-head h1 { font-size: 1.6rem; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ---------- облікові записи ---------- */
.menu-user { margin: 0; padding: 12px 16px 8px; font-size: .8rem; color: var(--ink-soft); border-bottom: 1px solid var(--paper-2); }
.menu-user:empty { display: none; }
.menu [hidden] { display: none; }
fieldset.bare { border: 0; padding: 0; margin: 0; min-width: 0; }
.readonly-note { background: var(--paper-2); border-left: 4px solid var(--soil); padding: 10px 12px; border-radius: var(--radius-s); font-size: .9rem; }
.user-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.user-row { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; justify-content: space-between;
  padding: 10px 0; border-bottom: 1px solid var(--paper-2); }
.user-row.inactive .who { opacity: .55; }
.user-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.user-actions select, .field select { font: inherit; min-height: 44px; padding: 6px 10px; border: 2px solid var(--line);
  border-radius: var(--radius-s); background: var(--card); color: var(--ink); }
.ghost-btn { font: inherit; min-height: 44px; padding: 6px 12px; border: 1.5px solid var(--line); border-radius: var(--radius-s);
  background: var(--card); color: var(--ink); cursor: pointer; }
.ghost-btn:hover { border-color: var(--ink); }
.role-help { margin: 12px 0 0; padding-left: 18px; color: var(--ink-soft); font-size: .85rem; }
.login form label { font-weight: 600; font-size: .9rem; }
.actions[hidden] { display: none; }

/* ---------- аналіз ---------- */
.analysis { max-width: 980px; margin: 0 auto; }
.analysis .tabs { margin-bottom: 12px; }
.an-form { display: grid; gap: 12px; }
.an-form .field select, .rule select, .rule input { font: inherit; min-height: 44px; padding: 6px 10px; border: 2px solid var(--line);
  border-radius: var(--radius-s); background: var(--card); color: var(--ink); max-width: 100%; }
.actions.inline { position: static; background: none; padding: 4px 0 0; justify-content: flex-start; flex-wrap: wrap; }
.rule { display: grid; grid-template-columns: minmax(0, 1fr) 64px 110px 44px; gap: 6px; margin-bottom: 6px; }
.table-scroll { overflow-x: auto; margin: 0 -14px; padding: 0 14px; }
.stat-table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; font-size: .92rem; }
.stat-table th, .stat-table td { padding: 7px 8px; border-bottom: 1px solid var(--paper-2); text-align: center; white-space: nowrap; }
.stat-table th:first-child, .stat-table td:first-child { text-align: left; }
.stat-table thead th { font-size: .78rem; color: var(--ink-soft); border-bottom: 2px solid var(--ink); }
.stat-table tfoot td { font-weight: 700; border-top: 2px solid var(--ink); }
.stat-table .letters { font-weight: 700; color: var(--soil); letter-spacing: .05em; }
.stat-table.corr td { min-width: 64px; }
.stat-table.corr td small { display: block; font-size: .7rem; color: var(--ink-soft); }
.stat-table.corr .row-label { text-align: left; font-weight: 400; font-size: .8rem; white-space: normal; min-width: 160px; }
.stat-table.corr .diag { color: var(--ink-soft); }
.r-strong { background: #c9e4d2; font-weight: 700; }
.r-mid { background: #e6f1e9; }
.r-strong.neg { background: #f3cfc9; }
.r-mid.neg { background: #f9e4e0; }
.stat-footer { font-size: .9rem; margin: 10px 0 4px; }
.chart { width: 100%; height: auto; display: block; margin-top: 6px; }
.chart text { font: 11px var(--font); fill: var(--ink-soft); }
.chart .axis-title { font-size: 12px; fill: var(--ink); }
.chart .tick line { stroke: var(--paper-2); }
.chart .bar { fill: var(--soil); opacity: .75; }
.chart .bar:hover { opacity: 1; }
.chart .box line, .chart .box rect { stroke: var(--ink); stroke-width: 1.5; }
.chart .box rect { fill: #e9dcc4; }
.chart .box .median { stroke: var(--soil); stroke-width: 3; }
.chart .mean { fill: var(--ink); }
.chart .dot { fill: var(--ink); opacity: .55; }
.chart .fit { stroke: var(--soil); stroke-width: 2.5; }

/* ---------- довідка ---------- */
.help-btn { text-decoration: none; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; min-width: 36px; }
.help { max-width: 760px; margin: 0 auto; }
.help-toc { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.help-toc a { text-decoration: none; padding: 6px 10px; border: 1px solid var(--line); border-radius: 999px; background: var(--card); font-size: .85rem; }
.help-body section { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-m); padding: 6px 16px 12px; margin-bottom: 12px; scroll-margin-top: 70px; }
.help-body h2 { font-size: 1.05rem; text-transform: none; letter-spacing: 0; color: var(--ink); margin: 12px 0 6px; }
.help-body h3 { font-size: .95rem; margin: 14px 0 4px; color: var(--soil); }
.help-body p, .help-body li { line-height: 1.55; }
.help-meta { color: var(--ink-soft); font-size: .85rem; }
.warn-note { background: var(--pending-bg); border-radius: var(--radius-s); padding: 8px 12px; }
.sw { display: inline-block; width: 14px; height: 14px; border-radius: 3px; vertical-align: -2px; border: 1.5px solid var(--line); background: var(--card); }
.sw.done { background: var(--done-bg); border-color: var(--done); }
.sw.pending { background: var(--pending-bg); border-color: var(--pending); }
.sw.absent { background: var(--absent-bg); }
.sw.uncertain { box-shadow: inset 0 0 0 3px #e0a100; }
@media (max-width: 520px) {
  .rule { grid-template-columns: minmax(0, 1fr) 56px 84px 44px; }
}
