/* portal.css — the Farm Portal's only stylesheet. Mobile-first: the base rules
   are the phone layout (farms open this on a phone in a hoop house), and the one
   breakpoint at 820px widens it. Palette hexes are lifted verbatim from
   src/styles.css so the portal reads as the same product as the internal app and
   as this service's own /setup page (which is light-themed and declares
   color-scheme: light — the portal commits to the same single look). */
:root {
  color-scheme: light;
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-soft: #eef3f1;
  --ink: #17211b;
  --muted: #66736d;
  --line: #d9e1dc;
  --green: #16774a;
  --green-soft: #e3f3e8;
  --amber: #b87916;
  --amber-soft: #fff2d6;
  --red: #b94a48;
  --red-soft: #fde8e6;
  --blue: #2471a3;
  --blue-soft: #e3f1fb;
  --teal: #0f7c80;
  --shadow: 0 18px 45px rgba(20, 34, 28, 0.08);
}

* { box-sizing: border-box; }

/* MUST outrank the id-selector display rules below (#login is display:grid). The
   UA's own `[hidden] { display: none }` loses to any id selector, so without this
   the login card stays on screen behind the signed-in dashboard. */
[hidden] { display: none !important; }

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(22, 119, 74, 0.06), rgba(36, 113, 163, 0.03) 320px, transparent 680px),
    var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input { font: inherit; }
h1, h2 { margin: 0; letter-spacing: 0; }
.boot, .fine { color: var(--muted); font-size: 13px; }
.boot { padding: 28px 18px; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px;
  clip-path: inset(50%); overflow: hidden;
}
.eyebrow {
  margin: 0 0 6px;
  color: var(--teal);
  font-size: 11px; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase;
}

/* ---- sign in ---- */
#login { display: grid; place-items: center; min-height: 100vh; padding: 20px; }
.login-card {
  width: min(430px, 100%);
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.login-card h1 { font-size: 26px; }
.lede { margin: 8px 0 20px; color: var(--muted); line-height: 1.5; }
.login-card label {
  display: block; margin: 0 0 6px;
  color: var(--muted);
  font-size: 11px; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase;
}
.login-card input {
  width: 100%; min-height: 46px; margin-bottom: 14px; padding: 10px 12px;
  color: var(--ink); background: var(--surface-soft);
  border: 1px solid var(--line); border-radius: 7px;
}
#login-submit {
  width: 100%; min-height: 46px;
  color: #fff; background: #22312a;
  border: 1px solid #22312a; border-radius: 7px; font-weight: 800; cursor: pointer;
}
#login-submit[disabled] { opacity: 0.6; cursor: progress; }
.error {
  margin: 14px 0 0; padding: 10px 12px;
  color: var(--red); background: var(--red-soft);
  border: 1px solid rgba(185, 74, 72, 0.26); border-radius: 7px; font-size: 13px;
}
.error:empty { display: none; }
.fine { margin: 18px 0 0; }

/* ---- shell ---- */
.portal-header {
  display: grid; gap: 14px;
  padding: 18px 16px 16px;
  background: rgba(244, 246, 245, 0.94);
  border-bottom: 1px solid var(--line);
}
.brand h1 { font-size: 24px; line-height: 1.15; }
.tagline { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.header-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.portal-main { padding: 4px 16px 8px; }
.portal-footer {
  padding: 8px 16px 30px;
  color: var(--muted); font-size: 13px;
}

/* ---- chips & buttons (touch targets >= 40px) ---- */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  min-height: 40px; padding: 8px 14px;
  color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 999px;
  font-size: 13px; font-weight: 700; cursor: pointer;
}
.chip.is-active { color: #fff; background: var(--green); border-color: var(--green); }
.ghost-button {
  min-height: 40px; padding: 8px 14px;
  color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 7px;
  font-size: 13px; font-weight: 700; cursor: pointer;
}
.ghost-button.wide { width: 100%; margin-top: 10px; }
#signout { margin-left: auto; }

/* ---- panels ---- */
.panel {
  margin: 16px 0;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.section-title {
  display: flex; align-items: baseline; justify-content: space-between; gap: 10px;
  margin-bottom: 10px;
}
.section-title h2 { font-size: 17px; }
.section-title span { color: var(--muted); font-size: 12px; text-align: right; }
.subtitle { margin: 0 0 12px; color: var(--muted); font-size: 12px; line-height: 1.5; }
.state { margin: 6px 0; color: var(--muted); font-size: 13px; }
.state.is-error { color: var(--red); }

/* ---- tiles ---- */
.tile-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; }
.tile {
  display: flex; flex-direction: column;
  min-height: 108px; padding: 12px;
  background: var(--surface);
  border: 1px solid var(--line); border-top: 5px solid var(--green); border-radius: 8px;
}
.tile span, .tile small { color: var(--muted); font-size: 12px; line-height: 1.35; }
.tile span { min-height: 32px; }
.tile strong { display: block; margin: 8px 0 4px; font-size: 24px; line-height: 1; }
.tile small { margin-top: auto; }

/* ---- chart ---- */
.legend { display: flex; flex-wrap: wrap; gap: 14px; margin-bottom: 6px; }
.legend-key {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--muted); font-size: 12px;
}
.swatch { width: 11px; height: 11px; border-radius: 3px; }
.mom-chart { display: block; width: 100%; height: auto; }

/* ---- tables ---- */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line); border-radius: 8px;
}
table { width: 100%; border-collapse: collapse; min-width: 560px; }
th, td {
  padding: 10px 12px; text-align: left;
  border-bottom: 1px solid var(--line);
  font-size: 13px; vertical-align: top;
}
tr:last-child td { border-bottom: 0; }
th {
  color: var(--muted); background: var(--surface-soft);
  font-size: 11px; font-weight: 800; text-transform: uppercase; white-space: nowrap;
}
th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; }
td small { display: block; margin-top: 2px; color: var(--muted); font-size: 11px; }
td strong { color: var(--green); }
.good { color: var(--green); font-weight: 700; }
.bad { color: var(--red); font-weight: 700; }
.dash { color: var(--muted); cursor: help; border-bottom: 1px dotted var(--line); }
th.sortable { cursor: pointer; user-select: none; }
th.sortable::after {
  content: "\2195"; margin-left: 5px; color: var(--teal); font-size: 10px; opacity: 0.3;
}
th.sortable[data-sort-dir="asc"]::after { content: "\25B2"; opacity: 0.9; }
th.sortable[data-sort-dir="desc"]::after { content: "\25BC"; opacity: 0.9; }

/* ---- market chips ---- */
.chip-label {
  margin: 14px 0 6px;
  color: var(--muted);
  font-size: 11px; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase;
}
.trend-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.market-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px;
  background: var(--surface-soft);
  border: 1px solid var(--line); border-radius: 999px;
  font-size: 12px; white-space: nowrap;
}
.market-chip b { font-weight: 800; }
.market-chip.is-up { color: var(--green); background: var(--green-soft); border-color: rgba(22, 119, 74, 0.24); }
.market-chip.is-down { color: var(--red); background: var(--red-soft); border-color: rgba(185, 74, 72, 0.24); }
.market-chip.is-flat { color: var(--muted); }

/* ---- inventory controls ---- */
.controls { display: grid; gap: 8px; margin-bottom: 10px; }
#inv-search {
  width: 100%; min-height: 40px; padding: 8px 12px;
  color: var(--ink); background: var(--surface-soft);
  border: 1px solid var(--line); border-radius: 7px;
}

/* ---- >= 820px: tiles 4-up, centred column, header on one line ---- */
@media (min-width: 820px) {
  /* Full-bleed border, content aligned to the same 1100px column as .portal-main. */
  .portal-header {
    display: flex; align-items: flex-end; justify-content: space-between;
    padding: 22px max(28px, calc((100% - 1100px) / 2)) 18px;
  }
  .portal-main, .portal-footer { max-width: 1440px; margin: 0 auto; padding-left: 28px; padding-right: 28px; }
  .portal-main { width: 100%; }
  .brand h1 { font-size: 28px; }
  .panel { padding: 18px; }
  .section-title h2 { font-size: 18px; }
  .tile-grid { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }
  .controls { grid-template-columns: auto minmax(180px, 1fr) auto; align-items: center; }
  .ghost-button.wide { width: auto; }
}

/* --- proposal + feedback + drilldown (2026-07-29) ------------------------- */
#proposal-form, #portal-feedback-form { display: grid; gap: 10px; max-width: 560px; }
#proposal-form textarea, #portal-feedback-form textarea {
  width: 100%; padding: 10px; border: 1px solid #d6ddd9; border-radius: 8px; font: inherit;
}
tr.bucket-row { cursor: pointer; }
tr.bucket-row:hover td { background: #f3f7f5; }
tr.bucket-drill > td { background: #f6f8f7; padding: 10px 14px; }
.bucket-lots table { margin: 0; }
.market-chip.is-down b { color: #b3452f; }

.tile-note { margin: 8px 2px 0; font-size: 12.5px; color: #5f6b66; }

/* Parity with the internal screen: no stuck parent header over an open drilldown. */
.table-wrap:has(tr.bucket-drill) thead th { position: static; }

.how-to-read { margin: 0 0 10px; font-size: 13px; color: #5f6b66; }
.how-to-read summary { cursor: pointer; color: #1e7d4f; font-weight: 600; }
.how-to-read ul { margin: 8px 0 0 18px; display: grid; gap: 4px; }

/* Top strains: bounded name column, numbers together (2026-07-30). */
#strains table { table-layout: fixed; }
#strains th:nth-child(1) { width: 34%; }
#strains th:nth-child(2) { width: 22%; }
#strains th:nth-child(3) { width: 18%; }
#strains th:nth-child(4) { width: 26%; }
#strains td.num, #strains th.num { padding-right: 24px; }

/* Print = the downloadable report: chrome off, content only. */
@media print {
  .portal-topbar .chips, .portal-topbar button, #inv-search, #inv-csv, #print-report,
  #proposal-form, #portal-feedback-form, #format-chips, .how-to-read, .ghost-button { display: none !important; }
  .panel { break-inside: avoid; box-shadow: none; border: 1px solid #d6ddd9; }
  body { background: #fff; }
}

/* Market position (2026-08-03 exec ask): share-of-floor bars + capture opportunities */
.mkc-row { margin: 12px 0 16px; }
.mkc-head { display: flex; align-items: center; gap: 10px; font-size: 14px; flex-wrap: wrap; }
.mkc-need { color: var(--green, #16774a); font-weight: 600; font-size: 12.5px; }
.mkc-covered { color: var(--muted, #66736d); font-size: 12.5px; }
.mkc-bar { height: 14px; border-radius: 7px; background: var(--surface-soft, #eef3f1); border: 1px solid var(--line, #d9e1dc); overflow: hidden; margin: 6px 0 4px; }
.mkc-you { height: 100%; background: var(--green, #16774a); border-radius: 7px 0 0 7px; }
.mkc-you.mkc-solo { background: repeating-linear-gradient(45deg, var(--green, #16774a), var(--green, #16774a) 8px, #2c8a5e 8px, #2c8a5e 16px); }
.mkc-sub { display: flex; justify-content: space-between; gap: 10px; font-size: 12.5px; color: var(--muted, #66736d); flex-wrap: wrap; }
.mkc-opps { margin-top: 16px; padding: 12px; border: 1px dashed var(--green, #16774a); border-radius: 10px; background: var(--green-soft, #e3f3e8); }
.mkc-opps-title { margin: 0 0 8px; font-weight: 600; font-size: 13.5px; }
.mkc-opp { display: inline-block; margin: 3px 6px 3px 0; padding: 5px 10px; border-radius: 999px; background: var(--surface, #fff); border: 1px solid var(--line, #d9e1dc); font-size: 12.5px; }
.mkc-opps-note { margin: 8px 0 0; font-size: 12px; color: var(--muted, #66736d); }
