/* Maize Planner. Tokens follow the live pacificseeds.com.au site (as mirrored by
   the Foundation Farm Field Days app), not the print palette. */

@font-face {
  font-family: "Manrope";
  font-style: normal;
  font-display: swap;
  font-weight: 200 800;
  src: url("fonts/manrope-latin-wght-5.3.0.woff2") format("woff2-variations"),
       url("fonts/manrope-latin-wght-5.3.0.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329,
    U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  --brand: #0678cd;
  --brand-hover: #137cd1;
  --link: #0565ad;
  --ink: #000000;
  --h3: #092a40;
  --body: #4a4a4a;
  --muted: #5d6b78;
  --nav: #355675;
  --navy: #182d3e;
  --line: #d5d9de;
  --pale: #f0f4f7;
  --util: #eeeeee;
  --error: #b8323f;
  --surface: #ffffff;
  --font: "Manrope", Arial, Helvetica, sans-serif;
  --hdr: 64px;
  --side: 340px;
  --sheet-h: 0px;
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
  background: var(--surface);
  color: var(--body);
  font: 15px/1.6 var(--font);
}

h1, h2, h3, h4 {
  color: var(--ink);
  font-weight: 700;
  letter-spacing: -0.012em;
  line-height: 1.2;
}

a { color: var(--link); text-underline-offset: 2px; }
a:hover { color: var(--brand-hover); }

:focus-visible {
  outline: 3px solid var(--brand);
  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;
}

.skip {
  position: absolute;
  left: 12px;
  top: -60px;
  z-index: 2000;
  padding: 10px 16px;
  background: var(--surface);
  border: 1.25px solid var(--brand);
  border-radius: 6px;
  color: var(--brand);
  font-weight: 600;
}
.skip:focus { top: 8px; }

/* ---------- buttons: outline only ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 6px 20px;
  border: 1.25px solid var(--brand);
  border-radius: 6px;
  background: var(--surface);
  color: var(--brand);
  font: 500 15px/1.2 var(--font);
  cursor: pointer;
  text-decoration: none;
  transition: background-color 150ms, color 150ms;
}
.btn:hover { background: var(--brand-hover); border-color: var(--brand-hover); color: #fff; }
.btn:focus-visible { outline-color: var(--h3); }
.btn-quiet { border-color: var(--line); color: var(--nav); }
.btn-quiet:hover { border-color: var(--nav); background: var(--pale); color: var(--nav); }
.btn-icon { min-width: 44px; padding: 6px 10px; }
.btn svg { width: 18px; height: 18px; flex: none; }

/* ---------- header ---------- */
.top {
  flex: none;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  z-index: 1100;
}
.top-row {
  display: flex;
  align-items: center;
  gap: 20px;
  height: var(--hdr);
  padding: 0 20px;
  min-width: 0;
}
.brand {
  display: inline-flex;
  align-items: center;
  flex: none;
  padding: 6px 0;
}
.brand img { display: block; height: 34px; width: auto; }
.app-name {
  margin: 0;
  min-width: 0;
  font-size: 18px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-left: 20px;
  border-left: 1px solid var(--line);
  line-height: 32px;
}
.tabs {
  display: flex;
  align-self: stretch;
  gap: 4px;
  margin-left: 12px;
}
.tab {
  position: relative;
  display: inline-flex;
  align-items: center;
  padding: 0 14px;
  border: 0;
  background: none;
  color: var(--nav);
  font: 600 15px/1.2 var(--font);
  cursor: pointer;
  white-space: nowrap;
}
.tab::after {
  content: "";
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 0;
  height: 3px;
  border-radius: 3px 3px 0 0;
  background: transparent;
}
.tab:hover { color: var(--brand); }
.tab[aria-selected="true"] { color: var(--ink); font-weight: 700; }
.tab[aria-selected="true"]::after { background: var(--brand); }
.tab:focus-visible { outline-offset: -3px; }
.settings-toggle { display: none; margin-left: auto; flex: none; }

/* ---------- layout ---------- */
.layout {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: var(--side) minmax(0, 1fr);
}
main {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}
.view { position: absolute; inset: 0; }
.scroll-view { overflow: auto; background: var(--surface); }

/* ---------- controls ---------- */
.controls {
  overflow: auto;
  padding: 8px 20px 28px;
  background: var(--surface);
  border-right: 1px solid var(--line);
  overscroll-behavior: contain;
}
.drawer-head { display: none; }
.group { margin: 18px 0 0; padding: 0; border: 0; min-width: 0; }
.group > legend, .label {
  display: block;
  padding: 0;
  margin: 0 0 6px;
  color: var(--h3);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.4;
}
.field { margin-top: 18px; }
.field-row { display: flex; gap: 12px; align-items: flex-end; }
.field-row > * { min-width: 0; }
.hint { margin: 6px 0 0; color: var(--muted); font-size: 13px; line-height: 1.5; }
.error { margin: 6px 0 0; color: var(--error); font-size: 14px; font-weight: 600; line-height: 1.45; }

.choices { display: grid; gap: 8px; }
.choices.two { grid-template-columns: 1fr 1fr; }
.choice {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 46px;
  padding: 8px 12px;
  border: 1.25px solid var(--nav);
  border-radius: 6px;
  background: var(--surface);
  color: var(--h3);
  font-size: 15px;
  line-height: 1.3;
  cursor: pointer;
}
.choice:hover { border-color: var(--brand); background: var(--pale); }
.choice:has(input:checked) { border-color: var(--brand); box-shadow: inset 0 0 0 1px var(--brand); background: var(--pale); font-weight: 600; }
.choice:has(input:focus-visible) { outline: 3px solid var(--brand); outline-offset: 2px; }
.choice:has(input:disabled) { cursor: not-allowed; border-style: dashed; border-color: var(--line); color: var(--muted); background: var(--surface); box-shadow: none; font-weight: 400; }
.choice input { margin: 0; width: 18px; height: 18px; flex: none; accent-color: var(--brand); }
.choice input:focus-visible { outline: none; }

.check { display: flex; gap: 10px; align-items: flex-start; margin-top: 10px; color: var(--h3); font-size: 15px; line-height: 1.4; cursor: pointer; }
.check input { margin: 2px 0 0; width: 18px; height: 18px; flex: none; accent-color: var(--brand); }

select, input[type="number"] {
  display: block;
  width: 100%;
  height: 50px;
  padding: 0 14px;
  border: 1.25px solid var(--nav);
  border-radius: 6px;
  background-color: var(--surface);
  color: #1c2b39;
  font: 16px var(--font);
  -webkit-appearance: none;
  appearance: none;
}
select {
  padding-right: 44px;
  background-image: url("assets/chevron.svg");
  background-repeat: no-repeat;
  background-position: right 16px center;
  background-size: 12px 8px;
  text-overflow: ellipsis;
}
input[type="number"] { -moz-appearance: textfield; }
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
select:focus-visible, input[type="number"]:focus-visible { outline-color: var(--h3); }
[aria-invalid="true"] { border: 2px solid var(--error); }
.crm-field { width: 120px; flex: none; }

.plant-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.plant-value { color: var(--ink); font-size: 20px; font-weight: 700; letter-spacing: -0.012em; }
input[type="range"] {
  display: block;
  width: 100%;
  height: 44px;
  margin: 0;
  accent-color: var(--brand);
  cursor: pointer;
}

details.model { margin-top: 22px; border-top: 1px solid var(--line); padding-top: 12px; }
details.model > summary {
  display: flex;
  align-items: center;
  min-height: 44px;
  color: var(--h3);
  font-weight: 600;
  cursor: pointer;
}
details.model .field:first-of-type { margin-top: 8px; }
details.model .btn { margin-top: 16px; }

.foot { margin: 24px 0 0; padding-top: 12px; border-top: 1px solid var(--line); color: var(--muted); font-size: 13px; line-height: 1.5; }

/* ---------- map ---------- */
#map {
  position: absolute;
  inset: 0;
  background: #e8eaec;
  font: 14px/1.5 var(--font);
}
#map:focus-visible { outline: 3px solid var(--brand); outline-offset: -3px; }
.leaflet-container { font-family: var(--font); }
.leaflet-bar a { color: var(--h3); }
.leaflet-control-attribution { font-size: 11px; line-height: 1.45; color: #333; background: rgb(255 255 255 / 0.9) !important; }
.leaflet-control-attribution a { color: var(--link); }
.leaflet-tooltip {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--h3);
  font: 13px/1.45 var(--font);
  box-shadow: 0 3px 10px rgb(9 42 64 / 0.18);
}
.leaflet-tooltip strong { color: var(--ink); }
.leaflet-bottom { transition: bottom 120ms; }

/* legend */
.legend {
  max-width: 270px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--h3);
  font-size: 13px;
  line-height: 1.45;
  box-shadow: 0 2px 8px rgb(9 42 64 / 0.12);
}
.legend > summary {
  display: block;
  padding: 10px 36px 10px 12px;
  color: var(--ink);
  font-weight: 700;
  cursor: pointer;
  position: relative;
  list-style: none;
}
.legend > summary::-webkit-details-marker { display: none; }
.legend > summary::after {
  content: "";
  position: absolute;
  right: 14px;
  top: 16px;
  width: 12px;
  height: 8px;
  background: url("assets/chevron.svg") no-repeat center / 12px 8px;
  transform: rotate(180deg);
}
.legend:not([open]) > summary::after { transform: none; }
.legend-body { padding: 0 12px 10px; max-height: 46vh; overflow: auto; }
.legend ul { margin: 0; padding: 0; list-style: none; }
.legend li { display: flex; align-items: center; gap: 8px; padding: 1px 0; }
.legend .note { margin: 6px 0 0; color: var(--muted); font-size: 12px; }
.legend .changed { margin: 6px 0 0; color: var(--error); font-size: 12px; font-weight: 700; }
.sw {
  display: inline-block;
  flex: none;
  width: 18px;
  height: 14px;
  border: 1px solid var(--nav);
  border-radius: 3px;
}

/* detail panel */
.detail {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 1000;
  width: 370px;
  max-height: calc(100% - 24px);
  overflow: auto;
  padding: 16px 18px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 3px 14px rgb(9 42 64 / 0.22);
  overscroll-behavior: contain;
}
.detail-head { display: flex; align-items: flex-start; gap: 12px; }
.detail-head h2 { flex: 0 1 auto; margin: 4px auto 2px 0; font-size: 19px; }
/* The heading takes focus only so screen readers land on it (tabindex -1); it is not a control, so no ring. */
.detail-head h2:focus, .detail-head h2:focus-visible { outline: none; }
.detail-head .km { color: var(--muted); font-size: 14px; font-weight: 500; letter-spacing: 0; }
.detail .sub { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.5; }
.detail .far { margin: 10px 0 0; padding: 8px 12px; background: var(--pale); border-radius: 6px; color: var(--h3); font-size: 14px; font-weight: 600; }
.facts { margin: 8px 0 0; }
.facts div {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 14px;
  padding: 7px 0;
  border-bottom: 1px solid var(--line);
}
.facts dt { color: var(--muted); font-size: 14px; line-height: 1.4; }
.facts dd { margin: 0; color: var(--ink); font-size: 14px; font-weight: 700; text-align: right; white-space: nowrap; }
.detail .hint { font-size: 12.5px; }

.chart { display: block; width: 100%; max-width: 340px; height: auto; margin-top: 10px; }
.chart text { font: 11px var(--font); fill: var(--muted); }
.chart .grid { stroke: #e3e7eb; }
.chart .median { fill: none; stroke: var(--brand); stroke-width: 2; }
.chart .safe { fill: none; stroke: #e0761e; stroke-width: 2; }
.chart .range { fill: #71c5e8; fill-opacity: 0.3; }
.chart .now { stroke: var(--h3); }
.chart .hyb { stroke: var(--ink); stroke-dasharray: 4 3; }
.chart-key { display: flex; flex-wrap: wrap; gap: 4px 14px; margin: 4px 0 0; color: var(--muted); font-size: 12.5px; }
.chart-key span { display: inline-flex; align-items: center; gap: 6px; }
.chart-key i { display: inline-block; width: 16px; height: 3px; border-radius: 2px; }
.chart-key .k-median { background: var(--brand); }
.chart-key .k-safe { background: #e0761e; }
.chart-key .k-range { height: 12px; background: rgb(113 197 232 / 0.45); border: 1px solid var(--nav); }

/* ---------- region guide ---------- */
.page { padding: 22px 24px 40px; }
.page h2 { margin: 0 0 6px; font-size: 22px; }
.guide-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 18px; margin-top: 14px; }
.guide-actions .hint { margin: 0; flex: 1 1 280px; }
.table-wrap {
  max-width: 100%;
  overflow-x: auto;
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
}
.guide {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  line-height: 1.35;
  font-variant-numeric: tabular-nums;
}
.guide thead th {
  padding: 9px 8px;
  background: var(--pale);
  color: var(--h3);
  font-weight: 600;
  text-align: center;
  white-space: nowrap;
}
.guide th[scope="row"], .guide thead th.reg {
  position: sticky;
  left: 0;
  z-index: 1;
  min-width: 190px;
  max-width: 260px;
  padding: 6px 12px;
  background: var(--surface);
  color: var(--ink);
  font-weight: 600;
  text-align: left;
  white-space: normal;
}
.guide thead th.reg { background: var(--pale); }
.guide tbody tr { border-top: 1px solid var(--line); }
.guide td { padding: 6px 8px; min-width: 56px; text-align: center; white-space: nowrap; border-left: 2px solid var(--surface); }
.guide td.n { color: var(--muted); }
.guide abbr { text-decoration: none; }
.guide.changed-model caption { color: var(--error); }

/* ---------- how it works ---------- */
.prose { max-width: 780px; }
.prose h2 { font-size: 24px; margin: 0 0 12px; }
.prose h3 { margin: 26px 0 8px; font-size: 17px; color: var(--h3); }
.prose ul { padding-left: 20px; margin: 0; }
.prose li { margin: 6px 0; }

/* ---------- loading and error ---------- */
.loading {
  position: absolute;
  inset: 0;
  z-index: 1500;
  display: grid;
  place-content: center;
  gap: 12px;
  padding: 24px;
  background: var(--surface);
  text-align: center;
}
.loading p { margin: 0; color: var(--h3); font-weight: 600; }
.loading .bar { width: min(240px, 70vw); height: 4px; margin: 0 auto; border-radius: 2px; background: var(--pale); overflow: hidden; }
.loading .bar::before { content: ""; display: block; width: 40%; height: 100%; background: var(--brand); animation: slide 1.2s ease-in-out infinite; }
.loading .late { visibility: hidden; animation: reveal 0s linear 20s forwards; color: var(--muted); font-weight: 400; font-size: 14px; }
.load-error { max-width: 460px; padding: 22px 24px; border: 2px solid var(--h3); border-radius: 12px; text-align: left; }
.load-error h2 { margin: 0 0 6px; font-size: 19px; color: var(--h3); }
.load-error p { margin: 0 0 14px; color: var(--body); font-weight: 400; }
@keyframes slide { 0% { transform: translateX(-100%); } 100% { transform: translateX(250%); } }
@keyframes reveal { to { visibility: visible; } }

.backdrop { display: none; }

/* ---------- below 1024px: drawer controls, bottom-sheet detail ---------- */
@media (max-width: 1023.98px) {
  :root { --hdr: 56px; }
  .top-row { flex-wrap: wrap; height: auto; row-gap: 0; padding: 0 16px; gap: 12px; }
  .brand { height: var(--hdr); }
  .brand img { height: 26px; }
  .app-name { flex: 1 1 0; font-size: 16px; padding-left: 12px; line-height: 26px; }
  .settings-toggle { display: inline-flex; }
  .tabs {
    order: 5;
    flex: 1 0 100%;
    margin: 0 -16px;
    height: 44px;
    gap: 0;
    border-top: 1px solid var(--line);
  }
  .tab { flex: 1 1 0; justify-content: center; padding: 0 6px; font-size: 14px; }
  .layout { grid-template-columns: minmax(0, 1fr); }
  .controls {
    position: fixed;
    z-index: 1300;
    top: var(--top-h, 100px);
    bottom: 0;
    left: 0;
    width: min(380px, 100%);
    border-right: 1px solid var(--line);
    box-shadow: 0 8px 24px rgb(9 42 64 / 0.2);
    display: none;
  }
  .controls.open { display: block; }
  .drawer-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    position: sticky;
    top: -8px;
    z-index: 2;
    margin: -8px -20px 0;
    padding: 10px 20px;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
  }
  .drawer-head h2 { margin: 0; font-size: 18px; }
  .backdrop.open {
    display: block;
    position: fixed;
    inset: 0;
    top: var(--top-h, 100px);
    z-index: 1250;
    background: rgb(24 45 62 / 0.45);
  }
  .detail {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    max-height: min(52%, 460px);
    border-radius: 12px 12px 0 0;
    border-bottom: 0;
    padding: 14px 16px 12px;
  }
  .leaflet-bottom { bottom: var(--sheet-h); }
  .legend { max-width: 230px; font-size: 12.5px; }
  .legend-body { max-height: 30vh; }
  .page { padding: 18px 16px 32px; }
  .chart { max-width: 440px; }
}

@media (max-width: 479.98px) {
  .brand img { height: 22px; }
  .app-name { font-size: 15px; padding-left: 10px; }
  .settings-toggle { padding: 6px 11px; }
  .settings-toggle span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }
  .legend { max-width: 196px; font-size: 12px; line-height: 1.3; }
  .legend > summary { padding: 8px 32px 8px 10px; }
  .legend-body { padding: 0 10px 8px; max-height: 32vh; }
  .sw { width: 15px; height: 12px; }
  .leaflet-control-attribution { font-size: 10px; }
  .leaflet-bottom.leaflet-left .leaflet-control { margin-bottom: 34px; }
  .facts dd { white-space: normal; }
  .guide { font-size: 12.5px; }
  .guide th[scope="row"], .guide thead th.reg { min-width: 132px; max-width: 150px; padding: 6px 8px; font-size: 12px; }
  .guide td { min-width: 48px; padding: 6px 5px; }
}

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

/* ---------- print: A4 landscape, the active view only ---------- */
.print-only { display: none; }
@media print {
  @page { size: A4 landscape; margin: 10mm; }
  html, body { height: auto; overflow: visible; display: block; background: #fff; font-size: 10pt; }
  .top, .controls, .backdrop, .skip, .loading, #detail, .guide-actions .btn, .leaflet-control-container { display: none !important; }
  .layout, main { display: block; overflow: visible; height: auto; }
  .view { position: static; }
  .scroll-view { overflow: visible; }
  .page { padding: 0; }
  .print-only { display: block; margin: 0 0 4mm; color: var(--h3); font-size: 9pt; }
  .page h2 { font-size: 14pt; }
  .table-wrap { overflow: visible; border: 0; border-radius: 0; margin-top: 3mm; }
  .guide { width: 100%; font-size: 8pt; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .guide thead th, .guide td { padding: 1.4mm 1mm; min-width: 0; }
  .guide th[scope="row"], .guide thead th.reg { position: static; min-width: 0; max-width: 62mm; padding: 1.4mm 2mm; }
  .guide tr { break-inside: avoid; }
  #mapView { position: relative; height: 180mm; }
}
