/* Farm Manager — calm, list-first. Tokens shared with the Farm Profit redesign. */
:root {
  --bg: #f8f1e1;            --bg-deep: #efe4cd;
  --card: #fffdf7;          --card-warm: #fdf8ec;   --card-soft: #f4ecda;
  --ink: #1c2a1f;           --ink-2: #374a3c;       --muted: #566a5d;   --whisper: #9aab9f;
  --primary: #2d5a3d;       --primary-dark: #1a3a28; --primary-light: #4a7a5c; --primary-soft: #d6e8dc;
  --forest: #6b4c2a;        --forest-dark: #4a3318; --forest-light: #8a6b42; --forest-soft: #ebe0d0;
  --wheat: #b8922a;         --wheat-dark: #6f5710;  --wheat-soft: #f0e4c0;
  --profit: #2a6a42;        --profit-soft: #d0e8d6;
  --loss: #b83a2a;          --loss-soft: #f2d6d0;
  --warning: #c49a2a;       --warning-soft: #f5eac8;
  --border: #d8c9a8;        --border-soft: #e7dcc2; --border-strong: #b3a37e;
  --shadow-sm: 0 1px 3px rgba(92,61,30,.08);
  --shadow: 0 3px 12px rgba(92,61,30,.09), 0 1px 3px rgba(92,61,30,.05);
  --shadow-lg: 0 16px 36px rgba(92,61,30,.13), 0 5px 12px rgba(92,61,30,.06);
  --serif: 'Fraunces','Iowan Old Style',Georgia,serif;
  --sans: 'Geist',system-ui,-apple-system,sans-serif;
  --mono: 'Geist Mono',ui-monospace,'SF Mono',monospace;
  --r-sm: 8px; --r: 12px; --r-lg: 16px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--sans); font-size: 16px; line-height: 1.5;
  min-height: 100vh;
}
h1,h2,h3 { font-family: var(--serif); color: var(--primary-dark); margin: 0 0 .4rem; }
p { margin: .3rem 0; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-size: .92em; }
.hidden { display: none !important; }
.icon { width: 1.1em; height: 1.1em; vertical-align: -0.18em; fill: none; }
a { color: var(--primary); }

.skip-link { position: absolute; left: -999px; top: 0; background: var(--card); padding: .5rem 1rem; z-index: 100; }
.skip-link:focus { left: .5rem; }

button { font: inherit; cursor: pointer; border: none; border-radius: 999px; padding: .62rem 1.15rem;
  display: inline-flex; align-items: center; gap: .45rem; min-height: 44px; }
button.primary, #authSubmitBtn, #pendingOverlay button, #appModalSubmit {
  background: var(--primary); color: #fff; font-weight: 600; }
button.primary:hover { background: var(--primary-dark); }
button.secondary { background: var(--card); color: var(--primary-dark); border: 1.5px solid var(--border); }
button.secondary:hover { border-color: var(--border-strong); }
button.danger { background: var(--loss); color: #fff; font-weight: 600; }
button.icon-btn { min-height: 36px; min-width: 36px; padding: .3rem; border-radius: 50%; background: transparent; color: var(--muted); }
button.icon-btn:hover { background: var(--card-soft); color: var(--loss); }
button:disabled { opacity: .55; cursor: default; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2.5px solid var(--wheat); outline-offset: 2px; }

input, select, textarea {
  font: inherit; font-size: 16px; /* ≥16px stops iOS auto-zoom */
  color: var(--ink); background: var(--card);
  border: 1.5px solid var(--border); border-radius: var(--r-sm);
  padding: .55rem .7rem; width: 100%; min-height: 44px;
}
textarea { min-height: 70px; resize: vertical; }
label { display: block; font-size: .82rem; font-weight: 600; color: var(--ink-2); margin: .55rem 0 .2rem; }

/* ── App bar + tabs ─────────────────────────────────────────── */
.appbar { position: sticky; top: 0; z-index: 30;
  background: linear-gradient(160deg, var(--primary-dark), var(--primary));
  color: #f8efd9; box-shadow: var(--shadow); }
.appbar-inner { display: flex; align-items: baseline; gap: .7rem; padding: .7rem 1rem .1rem; max-width: 1080px; margin: 0 auto; width: 100%; }
.appbar-title h1 { font-size: 1.25rem; color: #f8efd9; margin: 0; display: inline; }
.appbar-title h1 em { color: var(--wheat); font-style: italic; }
.appbar-sub { font-size: .75rem; color: rgba(248,239,217,.75); margin-left: .55rem; }
.app-tabs { display: flex; gap: .25rem; overflow-x: auto; scrollbar-width: none; padding: .4rem .8rem .55rem; max-width: 1080px; margin: 0 auto; width: 100%; }
.app-tabs::-webkit-scrollbar { display: none; }
.app-tab-btn { background: transparent; color: rgba(248,239,217,.85); border-radius: 999px; padding: .5rem .95rem; white-space: nowrap; font-weight: 500; }
.app-tab-btn:hover { color: #fff; background: rgba(248,239,217,.14); }
.app-tab-btn.active { background: var(--bg); color: var(--primary-dark); font-weight: 650; }

/* ── Banners ────────────────────────────────────────────────── */
.offline-banner, .warn-banner, .notice-banner {
  padding: .55rem 1rem; text-align: center; font-size: .9rem;
  display: flex; gap: .5rem; align-items: center; justify-content: center; }
.offline-banner { background: var(--warning-soft); color: var(--wheat-dark); position: sticky; top: 0; z-index: 40; }
.warn-banner { background: var(--warning-soft); color: var(--wheat-dark); }
.notice-banner { background: var(--primary-soft); color: var(--primary-dark); }

/* ── Period scope chips ─────────────────────────────────────── */
.period-scope-wrap { background: var(--bg-deep); border-bottom: 1px solid var(--border-soft); }
.period-scope { display: flex; gap: .4rem; overflow-x: auto; scrollbar-width: none; padding: .5rem 1rem; max-width: 1080px; margin: 0 auto; }
.period-scope::-webkit-scrollbar { display: none; }
.scope-chip { background: var(--card); border: 1.5px solid var(--border); color: var(--ink-2);
  border-radius: 999px; padding: .32rem .85rem; min-height: 38px; white-space: nowrap; font-size: .9rem; }
.scope-chip.active { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }

/* ── Layout ─────────────────────────────────────────────────── */
main { max-width: 1080px; margin: 0 auto; padding: 1rem 1rem 4rem; }
.app-tab-panel { display: none; }
.app-tab-panel.active { display: block; }
.toolbar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-bottom: .9rem; }
.toolbar input[type=search] { flex: 1 1 220px; max-width: 340px; }
.section-head { display: flex; align-items: center; justify-content: space-between; margin: 1.2rem 0 .5rem; }
.section-head h2 { font-size: 1.1rem; margin: 0; }
.section-note { font-size: .85rem; margin: -.2rem 0 .6rem; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .8rem; }
.version-line { text-align: center; font-size: .8rem; margin-top: 1.5rem; }

.card { background: var(--card); border: 1px solid var(--border-soft); border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm); padding: 1rem 1.1rem; margin-bottom: 1rem; }
.card-title { font-size: 1.02rem; margin-bottom: .5rem; }

/* ── Results cards ──────────────────────────────────────────── */
.result-card { background: var(--card); border: 1px solid var(--border-soft); border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm); padding: .6rem .6rem .4rem; margin-bottom: 1rem; }
.result-card > header { display: flex; align-items: baseline; gap: .6rem; padding: .35rem .55rem .45rem; }
.result-card > header h3 { margin: 0; font-size: 1.15rem; }
.result-card > header .rc-period { color: var(--muted); font-size: .85rem; }
.result-card.farm-total { background: var(--card-warm); border-color: var(--border); }
.result-card.batch-card { margin-left: 1.2rem; background: var(--card-warm); border-left: 3px solid var(--wheat); }
.result-card.batch-card > header h3 { font-size: 1rem; }
.result-card.batch-card .stat-row.hero .sr-value { font-size: 1.2rem; }
.stat-row { display: flex; align-items: baseline; justify-content: space-between; gap: .8rem;
  width: 100%; text-align: left; background: transparent; border: none; border-radius: var(--r-sm);
  border-bottom: 1px solid var(--border-soft); padding: .62rem .55rem; min-height: 44px; }
.stat-row:last-child { border-bottom: none; }
.stat-row:hover { background: var(--card-soft); }
.stat-row .sr-label { color: var(--ink-2); font-size: .92rem; }
.stat-row .sr-value { font-family: var(--mono); font-weight: 600; white-space: nowrap; }
.stat-row.hero { background: var(--primary-soft); border-radius: var(--r); border-bottom: none; margin: .2rem 0; }
.stat-row.hero .sr-label { font-weight: 650; color: var(--primary-dark); }
.stat-row.hero .sr-value { font-family: var(--serif); font-size: 1.5rem; font-weight: 700; color: var(--primary-dark); }
.stat-row.hero .sr-value.na { font-size: .95rem; font-family: var(--sans); font-weight: 500; color: var(--muted); }
.sr-value.positive { color: var(--profit); }
.sr-value.negative { color: var(--loss); }

/* ── List rows (feed / meat / sales / settings) ─────────────── */
.row-list { display: flex; flex-direction: column; gap: .45rem; }
.list-row { display: flex; align-items: center; gap: .7rem; width: 100%; text-align: left;
  background: var(--card); border: 1px solid var(--border-soft); border-radius: var(--r);
  padding: .6rem .8rem; min-height: 52px; box-shadow: none; }
button.list-row:hover { border-color: var(--border-strong); box-shadow: var(--shadow-sm); }
.list-row .lr-main { flex: 1 1 auto; min-width: 0; }
.list-row .lr-title { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-row .lr-sub { font-size: .82rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-row .lr-num { font-family: var(--mono); font-weight: 600; white-space: nowrap; text-align: right; }
.list-row .lr-num .sub { display: block; font-size: .78rem; color: var(--muted); font-weight: 400; }
.chip { display: inline-block; background: var(--forest-soft); color: var(--forest-dark);
  border-radius: 999px; padding: .06rem .55rem; font-size: .76rem; font-weight: 600; margin-right: .25rem; }
.chip.warn { background: var(--loss-soft); color: var(--loss); }
.chip.gold { background: var(--wheat-soft); color: var(--wheat-dark); }

/* ── Empty state ────────────────────────────────────────────── */
.empty-ill { text-align: center; padding: 1.6rem 1rem 2rem; color: var(--muted); }
.empty-ill .scene { width: 190px; max-width: 60%; opacity: .9; }
.empty-ill h4 { font-family: var(--serif); color: var(--ink-2); margin: .6rem 0 .2rem; }
.empty-ill .actions { justify-content: center; }

/* ── Modal / sheets ─────────────────────────────────────────── */
.modal-overlay { position: fixed; inset: 0; background: rgba(28,42,31,.5); z-index: 60;
  display: flex; align-items: flex-start; justify-content: center; padding: 4vh 1rem; overflow-y: auto; }
.modal-card { background: var(--card); border-radius: var(--r-lg); box-shadow: var(--shadow-lg);
  padding: 1.1rem 1.2rem 1.2rem; width: 100%; max-width: 480px; margin-bottom: 4vh; }
.modal-card.wide { max-width: 760px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; gap: .8rem; margin-bottom: .4rem; }
.modal-header h2 { margin: 0; font-size: 1.15rem; }
.modal-note { color: var(--muted); font-size: .9rem; display: none; }
.modal-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 .8rem; }
.modal-grid .full { grid-column: 1 / -1; }
.check-inline { display: flex; align-items: center; gap: .5rem; font-weight: 500; margin-top: .8rem; }
.check-inline input { width: auto; min-height: 0; }

/* ── Split (allocation) editor ──────────────────────────────── */
.split-row { display: grid; grid-template-columns: 1.8fr .8fr .7fr auto; gap: .4rem; align-items: center; margin: .3rem 0; }
.split-row .split-lbs { font-family: var(--mono); font-size: .85rem; color: var(--muted); text-align: right; }
.split-remainder { font-family: var(--mono); font-weight: 600; margin: .4rem 0; }
.split-remainder.ok { color: var(--profit); }
.split-remainder.off { color: var(--loss); }

/* ── Import review ──────────────────────────────────────────── */
.import-status { font-size: .9rem; color: var(--ink-2); min-height: 1.2em; white-space: pre-line; }
.table-scroll { overflow-x: auto; margin: .6rem 0; }
.review-table { border-collapse: collapse; width: 100%; font-size: .9rem; }
.review-table th { text-align: left; color: var(--muted); font-size: .78rem; padding: .3rem .4rem; border-bottom: 1.5px solid var(--border); }
.review-table td { padding: .25rem .3rem; border-bottom: 1px solid var(--border-soft); }
.review-table input, .review-table select { min-height: 38px; padding: .3rem .4rem; }
.review-table tr.skipped { opacity: .5; }
.raw-preview pre { background: var(--card-soft); border-radius: var(--r-sm); padding: .6rem; font-size: .72rem; overflow-x: auto; max-height: 260px; }

/* ── Show-your-work sheet ───────────────────────────────────── */
.work-formula { background: var(--card-warm); border: 1px solid var(--border-soft); border-radius: var(--r);
  padding: .7rem .9rem; font-family: var(--mono); font-size: .95rem; margin: .5rem 0 .8rem; }
.work-table { border-collapse: collapse; width: 100%; font-size: .9rem; }
.work-table th { text-align: left; color: var(--muted); font-size: .78rem; padding: .3rem .45rem; border-bottom: 1.5px solid var(--border); }
.work-table td { padding: .42rem .45rem; border-bottom: 1px solid var(--border-soft); }
.work-table td.num, .work-table th.num { text-align: right; font-family: var(--mono); white-space: nowrap; }
.work-table tfoot td { font-weight: 700; border-top: 2px solid var(--border-strong); border-bottom: none; }
.work-table tbody tr[data-edit] { cursor: pointer; }
.work-table tbody tr[data-edit]:hover { background: var(--card-soft); }

/* ── Changelog ──────────────────────────────────────────────── */
.cl-body { max-height: 60vh; overflow-y: auto; }
.cl-release { padding: .7rem 0; border-bottom: 1px solid var(--border-soft); }
.cl-release:last-child { border-bottom: none; }
.cl-head { display: flex; gap: .6rem; align-items: baseline; }
.cl-ver { font-family: var(--mono); font-weight: 700; color: var(--primary-dark); }
.cl-date { font-size: .8rem; color: var(--muted); }
.cl-headline { font-family: var(--serif); font-weight: 650; margin: .15rem 0 .3rem; }
.cl-list { margin: 0; padding-left: 1.2rem; font-size: .9rem; }
.cl-list li { margin-bottom: .3rem; }

/* ── Toast ──────────────────────────────────────────────────── */
#toastHost { position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: .4rem; z-index: 90; width: min(94vw, 420px); }
.toast { background: var(--primary-dark); color: #fff; border-radius: var(--r); padding: .65rem 1rem;
  box-shadow: var(--shadow-lg); font-size: .92rem; text-align: center; }
.toast.err { background: var(--loss); }
.toast.warn { background: var(--wheat-dark); }

/* ── Auth / loading overlays ────────────────────────────────── */
.auth-overlay { position: fixed; inset: 0; background: var(--bg); z-index: 70; display: flex;
  align-items: center; justify-content: center; padding: 1rem; }
.auth-card { background: var(--card); border: 1px solid var(--border-soft); border-radius: var(--r-lg);
  box-shadow: var(--shadow); padding: 1.6rem 1.5rem; width: 100%; max-width: 380px; }
.auth-card h1 { font-size: 1.4rem; }
.auth-card button { width: 100%; justify-content: center; margin-top: 1rem; }
.auth-links { font-size: .88rem; margin-top: .9rem; text-align: center; }
.auth-error { display: none; background: var(--loss-soft); color: var(--loss); border-radius: var(--r-sm);
  padding: .5rem .7rem; font-size: .88rem; margin: .5rem 0; }
.auth-error.visible { display: block; }
.auth-error.notice { background: var(--profit-soft); color: var(--profit); }
#loadingOverlay { position: fixed; inset: 0; background: var(--bg); z-index: 80; display: flex;
  flex-direction: column; align-items: center; justify-content: center; gap: .6rem; color: var(--muted); }

/* ── Responsive ─────────────────────────────────────────────── */
@media (max-width: 640px) {
  .modal-grid { grid-template-columns: 1fr; }
  .modal-overlay { padding: 0; align-items: stretch; }
  .modal-card { border-radius: 0; min-height: 100vh; max-width: none; margin: 0; }
  .split-row { grid-template-columns: 1fr 1fr; }
  .split-row .split-lbs { text-align: left; }
  .appbar-sub { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* Role gating: hide editing controls for viewers/pending. */
body.role-viewer .editor-only, body.role-pending .editor-only { display: none !important; }
body.is-offline main { padding-top: .5rem; }
