:root {
  --ink: #1c140f;
  --ink-soft: #43362e;
  --muted: #74655b;
  --paper: #f3eee6;
  --paper-2: #fbf7f2;
  --line: #e4d8c8;
  --beam: #241812;
  --pod: #c4622d;
  --pod-deep: #8d3e16;
  --leaf: #245443;
  --leaf-soft: #d9ebe2;
  --heat: #b64024;
  --sun: #c8892a;
  --gold: #8d6b32;
  --alert: #8d2e2a;
  --alert-bg: #f8e6e1;
  --watch-bg: #f8efd4;
  --ok-bg: #e4f1e8;
  --serif: "Fraunces", "Iowan Old Style", Palatino, Georgia, serif;
  --sans: "Outfit", "Avenir Next", "Segoe UI", sans-serif;
  --shadow: 0 18px 40px rgba(36, 24, 18, 0.06);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  min-height: 100vh;
  background:
    radial-gradient(1200px 500px at 0% -10%, rgba(196, 98, 45, 0.08), transparent 50%),
    var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.45;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3, p { margin: 0; }
h1 {
  font-family: var(--serif);
  font-weight: 460;
  font-size: clamp(2rem, 4vw, 3.1rem);
  letter-spacing: -0.03em;
  line-height: 1.05;
}
h2 {
  font-family: var(--serif);
  font-weight: 560;
  font-size: 1.55rem;
  letter-spacing: -0.02em;
}
h3 { font-size: 1rem; font-weight: 600; }

.beam {
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: 64px;
  padding: 10px 18px;
  background: var(--beam);
  color: #f6efe6;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.brand svg { flex: 0 0 auto; }
.brand b {
  font-family: var(--serif);
  font-size: 1.35rem;
  font-weight: 560;
  letter-spacing: 0.08em;
}
.brand span {
  display: block;
  color: #d9c7b6;
  font-size: 0.82rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 42vw;
}
.beam-spacer { flex: 1; }
.langs { display: flex; gap: 4px; }
.langs button, .icon-btn {
  border: 1px solid rgba(246, 239, 230, 0.2);
  background: transparent;
  color: #f6efe6;
  border-radius: 999px;
  padding: 6px 10px;
  min-height: 36px;
}
.langs button[aria-pressed="true"] {
  background: #f6efe6;
  color: var(--beam);
  border-color: #f6efe6;
}

.ribbon {
  background: #efe2c4;
  color: #3d2c14;
  padding: 10px 18px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #e2d1aa;
}
.ribbon p { flex: 1 1 18rem; min-width: 0; margin: 0; font-size: 0.92rem; }
.ribbon .row { display: flex; gap: 8px; flex-wrap: wrap; }

.layout {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  min-height: calc(100vh - 64px);
}
.nav {
  padding: 16px 12px 32px;
  border-right: 1px solid var(--line);
  position: sticky;
  top: 0;
  align-self: start;
  max-height: 100vh;
  overflow: auto;
}
.nav button {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  text-align: left;
  border: 0;
  background: transparent;
  color: var(--ink-soft);
  border-radius: 999px;
  padding: 8px 12px;
  margin: 2px 0;
  min-height: 40px;
}
.nav button[aria-current="page"] {
  background: var(--beam);
  color: #f6efe6;
}
.nav .count {
  min-width: 1.3rem;
  height: 1.3rem;
  border-radius: 999px;
  background: var(--heat);
  color: white;
  font-size: 0.75rem;
  display: inline-grid;
  place-items: center;
  padding: 0 5px;
}
.nav button[aria-current="page"] .count { background: #f6efe6; color: var(--heat); }

.main {
  padding: 28px 28px 80px;
  max-width: 1180px;
}
.kicker {
  color: var(--gold);
  font-size: 0.78rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-weight: 600;
  margin-bottom: 8px;
}
.lede { color: var(--ink-soft); max-width: 68ch; margin-top: 8px; }

.roles { display: flex; flex-wrap: wrap; gap: 8px; margin: 18px 0 8px; }
.roles button, .chip {
  border: 1px solid var(--line);
  background: var(--paper-2);
  border-radius: 999px;
  padding: 8px 12px;
  min-height: 40px;
}
.roles button[aria-pressed="true"] {
  background: var(--leaf);
  color: #f4fbf7;
  border-color: var(--leaf);
}

.brief { list-style: none; padding: 0; margin: 18px 0; display: grid; gap: 12px; }
.brief li {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 14px;
  align-items: start;
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px 16px 16px 14px;
  box-shadow: var(--shadow);
}
.brief li span {
  font-family: var(--serif);
  font-size: 1.6rem;
  color: var(--pod);
  line-height: 1;
  padding-top: 2px;
}
.brief li p {
  font-family: var(--serif);
  font-size: 1.28rem;
  line-height: 1.3;
  font-weight: 460;
}
.brief li[data-level="alert"] { background: var(--alert-bg); border-color: #efcfc8; }
.brief li[data-level="watch"] { background: var(--watch-bg); }
.brief li[data-level="info"] { background: var(--paper-2); }

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin: 8px 0 18px;
}
.stat {
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px 14px;
  min-height: 92px;
}
.stat em { display: block; color: var(--muted); font-style: normal; font-size: 0.82rem; }
.stat b {
  display: block;
  margin-top: 4px;
  font-family: var(--serif);
  font-size: 1.8rem;
  font-weight: 560;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}
.stat small { color: var(--muted); }

.quick { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 20px; }

.btn, button.btn {
  border: 1px solid var(--beam);
  background: var(--beam);
  color: #f6efe6;
  border-radius: 999px;
  padding: 10px 16px;
  min-height: 44px;
}
.btn.light {
  background: transparent;
  color: var(--ink);
  border-color: var(--line);
}
.btn.leaf { background: var(--leaf); border-color: var(--leaf); }
.btn.heat { background: var(--heat); border-color: var(--heat); }
.btn.warn { background: transparent; color: var(--alert); border-color: #e4b2ab; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.grid-2 { display: grid; grid-template-columns: 1.3fr 0.7fr; gap: 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.stack { display: grid; gap: 12px; }
.section { margin-top: 26px; }
.section header { margin-bottom: 10px; }

.card {
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px;
}
.card + .card { margin-top: 12px; }
.card header { display: flex; justify-content: space-between; gap: 10px; align-items: start; margin-bottom: 8px; }
.card .meta { color: var(--muted); font-size: 0.88rem; }
.pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: var(--line);
  color: var(--ink-soft);
  white-space: nowrap;
}
.pill.ok { background: var(--ok-bg); color: var(--leaf); }
.pill.watch { background: var(--watch-bg); color: #7a5a12; }
.pill.alert { background: var(--alert-bg); color: var(--alert); }
.pill.demo { background: #efe2c4; color: #6a4e1e; }

form.card, .form {
  display: grid;
  gap: 10px;
}
.fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.fields .wide { grid-column: 1 / -1; }
.field { display: grid; gap: 4px; }
.field span { font-size: 0.82rem; color: var(--muted); }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: white;
  border-radius: 12px;
  padding: 10px 12px;
  min-height: 44px;
}
textarea { min-height: 88px; resize: vertical; }
.check {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
}
.check input { width: auto; min-height: 0; }

.flash {
  border-radius: 12px;
  padding: 10px 12px;
  margin-bottom: 12px;
  background: var(--ok-bg);
  color: var(--leaf);
}
.flash.bad { background: var(--alert-bg); color: var(--alert); }

.chart { width: 100%; height: auto; display: block; }
.chart text { fill: var(--muted); font-size: 11px; font-family: var(--sans); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; color: var(--muted); font-size: 0.85rem; margin-top: 6px; }
.legend i { display: inline-block; width: 14px; height: 3px; margin-right: 6px; vertical-align: middle; }

.timeline { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.timeline li { display: grid; grid-template-columns: 9.5rem 1fr; gap: 10px; }
.timeline time { color: var(--muted); font-size: 0.82rem; }

table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 500; font-size: 0.8rem; }

.plano { width: 100%; background: #f7f3ea; border-radius: 16px; border: 1px solid var(--line); }
.plano polygon { cursor: pointer; stroke: var(--ink); stroke-width: 1.2; }
.plano polygon.active { stroke: var(--pod); stroke-width: 2.4; }
.note {
  font-size: 0.92rem;
  color: var(--ink-soft);
  max-width: 72ch;
}
.note strong { color: var(--ink); font-weight: 600; }
details.card summary { cursor: pointer; font-weight: 600; }
details.card ol, details.card ul { margin: 8px 0 0; padding-left: 1.1rem; }
details.card li { margin: 4px 0; }
.split { display: flex; justify-content: space-between; gap: 12px; align-items: end; flex-wrap: wrap; }
.up { color: var(--leaf); }
.down { color: var(--heat); }
.hidden { display: none; }
.checks { display: flex; flex-wrap: wrap; gap: 8px 14px; }

@media (max-width: 980px) {
  .stats, .grid-3 { grid-template-columns: 1fr 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .layout { display: block; }
  .nav {
    position: sticky;
    top: 0;
    z-index: 4;
    max-height: none;
    display: flex;
    gap: 6px;
    overflow-x: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    background: rgba(243, 238, 230, 0.94);
    backdrop-filter: blur(8px);
    padding: 8px;
  }
  .nav button { width: auto; white-space: nowrap; border: 1px solid var(--line); background: var(--paper-2); }
  .main { padding: 18px 14px 72px; }
  .timeline li, .fields { grid-template-columns: 1fr; }
  .ribbon { flex-direction: column; align-items: stretch; }
  .brand span { max-width: 46vw; }
}
@media (max-width: 560px) {
  .stats { grid-template-columns: 1fr 1fr; }
  .brief li p { font-size: 1.12rem; }
  .beam { padding: 8px 10px; gap: 8px; }
  .langs button { padding: 6px 8px; }
}

@media print {
  .beam, .nav, .ribbon, .quick, .roles, form, .no-print, .flash, details.dossier, .path-bar { display: none !important; }
  .print-only { display: block !important; }
  .sheet td { vertical-align: top; padding: 4px 8px; border-bottom: 1px solid #ccc; font-size: 11pt; }
  .sheet td:first-child { width: 45%; color: #333; }
  .layout { display: block; }
  body { background: white; }
  .main { max-width: none; padding: 0; }
  .card { break-inside: avoid; }
}
@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; }
}

/* V2: origin cards */
.sources { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.sources li { color: var(--muted); font-size: 0.74rem; overflow-wrap: anywhere; }
details.card > summary .meta { font-weight: 400; }

/* V4: path, modes, posts, the buyer's file */
.print-only { display: none; }
.modes { display: flex; gap: 4px; margin-right: 8px; }
.modes button { border: 1px solid rgba(246, 239, 230, 0.2); background: transparent; color: #f6efe6; border-radius: 999px; padding: 6px 12px; min-height: 36px; font: inherit; font-size: 0.82rem; cursor: pointer; }
.modes button[aria-pressed="true"] { background: #c4622d; border-color: #c4622d; color: #fff; }
.holder { display: grid; gap: 4px; margin-top: 14px; padding: 10px 8px 0; border-top: 1px solid var(--line, rgba(0,0,0,.1)); font-size: 0.78rem; color: var(--muted); }
.holder select { width: 100%; min-height: 38px; }
.path-bar { display: flex; gap: 4px; margin: 4px 0 6px; }
.path-bar i { flex: 1; height: 10px; border-radius: 999px; background: rgba(36, 24, 18, 0.12); }
.path-bar i.done { background: #245443; }
.path-bar i.now { background: #c8892a; }
.path-bar.wide i { height: 12px; }
details.step > summary, details.dossier > summary { cursor: pointer; font-weight: 600; }
details.step.later { opacity: 0.72; }
.tasks { list-style: none; padding: 0; margin: 10px 0 0; display: grid; gap: 8px; }
.tasks li { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.tasks li.ok span { color: #245443; }
.checks.column { display: grid; gap: 8px; margin: 8px 0 12px; }
.q { padding: 8px 0; border-bottom: 1px dashed rgba(36, 24, 18, 0.12); }
.q:last-of-type { border-bottom: 0; }
.table-wrap { overflow-x: auto; }
/* Guided mode: the fields that ask for an instrument most fincas do not have yet stay out of the way. */
[data-mode="simple"] label.field:has(> [name="ph"]),
[data-mode="simple"] label.field:has(> [name="brix"]),
[data-mode="simple"] label.field:has(> [name="ambient"]) { display: none; }
@media (max-width: 860px) {
  .modes button { padding: 6px 9px; font-size: 0.76rem; }
  .beam { flex-wrap: wrap; row-gap: 6px; }
}
@media (max-width: 860px) {
  .ribbon p { flex: 0 0 auto; font-size: 0.84rem; }
  .ribbon { padding: 8px 12px; gap: 8px; }
}
.card.next { border-left: 4px solid #c8892a; margin-bottom: 18px; }
.card.next .tasks { list-style: none; }
.photos { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 6px 0; }
.photos figure { position: relative; margin: 0; }
.photos img { width: 96px; height: 96px; object-fit: cover; border-radius: 10px; display: block; }
.photos figure .btn { position: absolute; top: 2px; right: 2px; min-height: 28px; padding: 0 8px; }
.photos.compact img { width: 56px; height: 56px; }
.photos.compact .photo-add { font-size: 0.78rem; padding: 4px 10px; min-height: 32px; }
@media print { .photos .btn, .photo-add { display: none !important; } }
.levels { padding-left: 1.2rem; display: grid; gap: 8px; margin: 8px 0 0; }
[data-mode="simple"] .roles { display: none; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 10px 0; }
.chip[aria-pressed="true"] { background: var(--leaf); color: #f4fbf7; border-color: var(--leaf); }
.labels { gap: 0; }
.label { border: 1px dashed #777; padding: 10px 14px; break-inside: avoid; }
.label p { margin: 2px 0; }
.label-farm { font-size: 0.85rem; color: #444; }
.label-code { font-size: 1.5rem; font-weight: 600; letter-spacing: 0.02em; }
@media print {
  body[data-print="labels"] main .kicker, body[data-print="labels"] main h2, body[data-print="labels"] main .lede,
  body[data-print="labels"] main .section.stack > :not(.labels), body[data-print="labels"] .export, body[data-print="labels"] footer { display: none !important; }
  body[data-print="labels"] .labels { display: grid !important; grid-template-columns: 1fr 1fr; }
}

/* V6: the parcel plan */
.plan-table { overflow-x: auto; max-width: 100%; margin: 10px 0; border: 1px solid var(--line, #d9d2c5); border-radius: 10px; }
.plan-table table { border-collapse: collapse; font-size: 0.82rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.plan-table th, .plan-table td { padding: 5px 8px; text-align: right; border-bottom: 1px solid var(--line, #e6e0d4); }
.plan-table tbody th, .plan-table thead th:first-child { text-align: left; position: sticky; left: 0; background: var(--paper, #fbf8f1); max-width: 11rem; white-space: normal; }
.plan-table tr.strong th, .plan-table tr.strong td { font-weight: 600; }
.neg { color: #a23a22; }
ul.rows { list-style: none; padding: 0; margin: 8px 0; }
ul.rows li { display: flex; justify-content: space-between; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--line, #e6e0d4); }
button.link { background: none; border: 0; padding: 0; color: #a23a22; text-decoration: underline; font: inherit; cursor: pointer; white-space: nowrap; }
.section.stack > * { min-width: 0; }
article.plan { min-width: 0; max-width: 100%; overflow: hidden; }
article.plan .plan-table { width: 100%; box-sizing: border-box; }
.plan-table tbody th { min-width: 7.5rem; }

/* V7: country rules */
.md { overflow-wrap: anywhere; line-height: 1.55; }
.md h3, .md h4, .md h5, .md h6 { margin: 1.1em 0 0.3em; }
.md ul, .md ol { padding-left: 1.3em; }
.md blockquote { margin: 0.6em 0; padding: 0.2em 0.9em; border-left: 3px solid var(--line); color: var(--ink-soft); }
.md pre { overflow-x: auto; padding: 10px; background: var(--paper); border-radius: 8px; font-size: 0.85rem; }
.md code { background: var(--paper); padding: 0 4px; border-radius: 4px; font-size: 0.9em; }
.md-table { overflow-x: auto; max-width: 100%; }
.md-table table { border-collapse: collapse; font-size: 0.88rem; }
.md-table th, .md-table td { border: 1px solid var(--line); padding: 5px 8px; text-align: left; vertical-align: top; }
details.norma { min-width: 0; }
details.norma > summary { cursor: pointer; }
.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(13rem, 1fr)); gap: 4px 14px; margin-bottom: 10px; }

/* V7: finish for phone and desktop */
:focus-visible { outline: 3px solid #e0a23a; outline-offset: 2px; border-radius: 6px; }
.nav .nav-all { display: none; }
.md { max-width: 72ch; }
.ribbon-text { cursor: default; }
@media (min-width: 861px) {
  .nav { scrollbar-width: thin; padding-bottom: 48px; }
  .nav button:hover { background: rgba(36, 24, 18, 0.06); }
  .btn:hover, .chip:hover, .roles button:hover { filter: brightness(0.97); }
  .main { padding-bottom: 96px; }
}
@media (min-width: 1500px) {
  .section.stack { gap: 18px; }
}
@media (max-width: 860px) {
  /* header: brand and languages on one line, the two modes as one wide switch under them */
  .beam { display: grid; grid-template-columns: 1fr auto; grid-template-areas: "brand langs" "modes modes"; row-gap: 8px; min-height: 0; align-items: center; }
  .beam .brand { grid-area: brand; min-width: 0; }
  .beam .beam-spacer { display: none; }
  .beam .langs { grid-area: langs; }
  .beam .modes { grid-area: modes; margin: 0; display: grid; grid-template-columns: 1fr 1fr; }
  .beam .modes button { min-height: 38px; font-size: 0.85rem; }
  .langs button { min-width: 38px; min-height: 38px; }
  /* the example ribbon: two lines, the rest on a tap; its two buttons side by side */
  .ribbon-text { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; cursor: pointer; }
  .ribbon-text.open { display: block; }
  .ribbon .row { flex-wrap: nowrap; }
  .ribbon .row .btn { flex: 1 1 0; padding: 8px 10px; font-size: 0.86rem; min-height: 40px; white-space: normal; }
  /* the nav: a button shows every screen at once; closed, the right edge fades to say there is more */
  .nav .nav-all { display: inline-flex; flex: 0 0 auto; width: auto; align-items: center; gap: 6px; order: -1; }
  .nav .nav-all-label { display: none; }
  .nav button { min-height: 42px; }
  .nav:not(.open) { -webkit-mask-image: linear-gradient(to right, #000 88%, transparent); mask-image: linear-gradient(to right, #000 88%, transparent); scrollbar-width: none; }
  .nav:not(.open)::-webkit-scrollbar { display: none; }
  .nav.open { flex-wrap: wrap; max-height: 70vh; overflow-y: auto; padding-bottom: 12px; box-shadow: 0 12px 24px rgba(36, 24, 18, 0.18); }
  .nav.open .nav-all-label { display: inline; }
  .nav.open .nav-all { width: 100%; justify-content: flex-start; background: var(--beam); color: #f6efe6; }
  .nav.open button:not(.nav-all) { flex: 1 1 44%; white-space: normal; }
  /* the nine roles of the day screen: one line that slides, not four lines of chips */
  .roles { flex-wrap: nowrap; overflow-x: auto; margin: 12px -14px 6px; padding: 2px 14px; scrollbar-width: none; }
  .roles::-webkit-scrollbar { display: none; }
  .roles button { flex: 0 0 auto; }
  .main { padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px)); }
  h2 { overflow-wrap: anywhere; }
  .btn { min-height: 44px; }
}
@media (max-width: 380px) {
  .brand span { display: none; }
}
