/* AgroVine design system */
:root {
  --brand: #2f6f2a; --brand-ink: #ffffff; --brand-soft: #e4efdc; --brand-deep: #1f4d1c;
  --bg: #f5f3ec; --surface: #ffffff; --surface-2: #faf9f5; --ink: #1c261d; --muted: #667066; --line: #e4e0d4; --line-strong: #cfcabb;
  --good: #2e8540; --good-soft: #e2f2e4; --bad: #c2412d; --bad-soft: #fbe5e0; --warn: #b7791f; --warn-soft: #fbf0d9; --info: #2b6cb0; --info-soft: #e3eefa;
  --s1: #2f6f2a; --s2: #d9a400; --s3: #2b7bb9; --s4: #c2669b; --s5: #8a6d3b; --s6: #4aa39a;
  --radius: 14px; --radius-sm: 9px; --shadow: 0 1px 2px rgba(30, 40, 30, .06), 0 4px 16px rgba(30, 40, 30, .05);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --side: 248px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --brand: #5fae57; --brand-ink: #0d160d; --brand-soft: #1f3420; --brand-deep: #8fd087;
    --bg: #0f140f; --surface: #172017; --surface-2: #1b251b; --ink: #e6ece4; --muted: #9ba79a; --line: #283428; --line-strong: #364536;
    --good: #5cc36e; --good-soft: #17301b; --bad: #f07a63; --bad-soft: #3a1d17; --warn: #e6b450; --warn-soft: #33290f; --info: #6aa8ec; --info-soft: #14263b;
    --s1: #6fbf65; --s2: #e6b93a; --s3: #5aa3e0; --s4: #e08cbd; --s5: #c4a06a; --s6: #63c7bb;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --brand: #5fae57; --brand-ink: #0d160d; --brand-soft: #1f3420; --brand-deep: #8fd087;
  --bg: #0f140f; --surface: #172017; --surface-2: #1b251b; --ink: #e6ece4; --muted: #9ba79a; --line: #283428; --line-strong: #364536;
  --good: #5cc36e; --good-soft: #17301b; --bad: #f07a63; --bad-soft: #3a1d17; --warn: #e6b450; --warn-soft: #33290f; --info: #6aa8ec; --info-soft: #14263b;
  --s1: #6fbf65; --s2: #e6b93a; --s3: #5aa3e0; --s4: #e08cbd; --s5: #c4a06a; --s6: #63c7bb;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 15px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; line-height: 1.2; margin: 0 0 .2rem; letter-spacing: -.01em; }
h2 { font-size: 1.2rem; margin: 0; }
h3 { font-size: 1rem; margin: 0; }
h4 { font-size: .9rem; margin: .75rem 0 .35rem; }
p { margin: .3rem 0; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85em; background: var(--surface-2); border: 1px solid var(--line); padding: 1px 5px; border-radius: 5px; }
pre.code { background: var(--surface-2); border: 1px solid var(--line); padding: 10px 12px; border-radius: var(--radius-sm); overflow-x: auto; font-size: 12.5px; margin: 0; white-space: pre-wrap; word-break: break-all; }
.muted { color: var(--muted); } .small { font-size: .84rem; } .center { text-align: center; } .right { text-align: right; } .grow { flex: 1; }
.good-text { color: var(--good); } .bad-text { color: var(--bad); } .warn-text { color: var(--warn); display: inline-flex; gap: 4px; align-items: center; }
.icon { flex: none; vertical-align: -3px; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

/* ---------- inputs & buttons ---------- */
.leaflet-control-layers input { width: auto; min-height: 0; margin: 0 6px 0 0; }
input:not([type=checkbox]):not([type=radio]), select, textarea { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius-sm); padding: 9px 11px; width: 100%; min-height: 40px; }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
input[type=checkbox] { width: 18px; height: 18px; min-height: 0; accent-color: var(--brand); margin: 0; }
input[type=color] { padding: 3px; height: 40px; }
input.mini { width: 90px; min-height: 32px; padding: 4px 8px; text-align: right; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: 600 .9rem var(--font); border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); padding: 8px 14px; border-radius: var(--radius-sm); cursor: pointer; min-height: 40px; white-space: nowrap; text-decoration: none !important; transition: background .15s, border-color .15s; }
.btn:hover { background: var(--surface-2); border-color: var(--muted); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.primary:hover { background: var(--brand-deep); border-color: var(--brand-deep); color: var(--bg); }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, transparent); }
.btn.danger:hover { background: var(--bad-soft); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.small { min-height: 32px; padding: 4px 10px; font-size: .82rem; }
.btn.block { width: 100%; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 38px; height: 38px; border: 0; background: transparent; color: var(--ink); border-radius: 50%; cursor: pointer; position: relative; }
.icon-btn:hover { background: var(--surface-2); }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.label { display: flex; flex-direction: column; gap: 5px; font-size: .84rem; font-weight: 600; color: var(--ink); }
.hint { color: var(--muted); font-weight: 400; font-size: .78rem; }
.req { color: var(--bad); }
.switch { position: relative; display: inline-block; width: 44px; height: 24px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--line-strong); border-radius: 24px; transition: .2s; cursor: pointer; }
.switch span:before { content: ''; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; }
.switch input:checked + span { background: var(--brand); }
.switch input:checked + span:before { transform: translateX(20px); }
.checks { display: flex; flex-wrap: wrap; gap: 6px 14px; }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: .9rem; cursor: pointer; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row-form { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.row-form input, .row-form select { width: auto; min-width: 160px; }
.code-input { font-size: 1.6rem; letter-spacing: .4em; text-align: center; font-family: ui-monospace, monospace; }

/* ---------- shell ---------- */
.shell { min-height: 100vh; }
.sidebar { position: fixed; inset: 0 auto 0 0; width: var(--side); background: var(--surface); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 16px 12px; gap: 12px; z-index: 20; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.15rem; color: var(--ink); letter-spacing: -.01em; text-decoration: none !important; }
.logo { display: inline-flex; }
.farm-name { font-size: .85rem; color: var(--muted); padding: 0 4px; }
.farm-select { font-weight: 600; font-size: .88rem; min-height: 36px; padding: 6px 10px; }
.side-nav { display: flex; flex-direction: column; gap: 2px; }
.side-nav a { display: flex; align-items: center; gap: 11px; padding: 8px 10px; color: var(--ink); border-radius: var(--radius-sm); font-weight: 500; font-size: .92rem; text-decoration: none; }
.side-nav a:hover { background: var(--surface-2); }
.side-nav a.active { background: var(--brand-soft); color: var(--brand-deep); font-weight: 650; }
.side-nav a.active .icon { color: var(--brand); }
.side-foot { margin-top: auto; padding: 8px 6px 0; border-top: 1px solid var(--line); }
.content { margin-left: var(--side); min-height: 100vh; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 15; display: flex; align-items: center; gap: 10px; padding: 10px 24px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); min-height: 58px; }
.mobile-only { display: none; }
.sync-status { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--surface); border-radius: 99px; padding: 4px 10px; font: 600 .78rem var(--font); color: var(--muted); cursor: pointer; }
.sync-status.ok { color: var(--good); } .sync-status.pending { color: var(--warn); } .sync-status.off { color: var(--bad); background: var(--bad-soft); }
.bell .badge { position: absolute; top: 2px; right: 2px; background: var(--bad); color: #fff; font-size: 10px; font-weight: 700; min-width: 17px; height: 17px; border-radius: 9px; display: grid; place-items: center; padding: 0 4px; }
.user-btn { display: flex; align-items: center; gap: 8px; background: none; border: 0; color: var(--ink); cursor: pointer; font: 600 .88rem var(--font); padding: 4px; border-radius: 99px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--brand-soft); color: var(--brand-deep); display: grid; place-items: center; font-weight: 700; font-size: .78rem; flex: none; }
main { flex: 1; outline: none; }
.page { max-width: 1320px; margin: 0 auto; padding: 22px 24px 90px; display: flex; flex-direction: column; gap: 16px; }
.page-head { display: flex; flex-wrap: wrap; gap: 12px; justify-content: space-between; align-items: flex-end; }
.page-head .actions { display: flex; flex-wrap: wrap; gap: 8px; }
.back { display: inline-flex; align-items: center; gap: 4px; font-size: .85rem; color: var(--muted); margin-bottom: 4px; }
.bottom-nav { display: none; }
.center-screen { min-height: 100vh; display: grid; place-items: center; padding: 24px; text-align: center; }
.loader { width: 36px; height: 36px; border: 3px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 4px; overflow-x: auto; border-bottom: 1px solid var(--line); margin: -6px 0 0; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a { display: inline-flex; gap: 6px; align-items: center; padding: 9px 12px; color: var(--muted); font-weight: 600; font-size: .88rem; border-bottom: 2px solid transparent; white-space: nowrap; text-decoration: none; }
.tabs a:hover { color: var(--ink); }
.tabs a.active { color: var(--brand-deep); border-bottom-color: var(--brand); }

/* ---------- cards, stats ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); min-width: 0; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 10px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.stack.narrow { max-width: 420px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: flex; flex-direction: column; gap: 2px; box-shadow: var(--shadow); min-width: 0; }
.card .stat { box-shadow: none; background: var(--surface-2); }
.stat-label { font-size: .78rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.stat-value { font-size: 1.5rem; font-weight: 750; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat-sub { font-size: .8rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stat.good .stat-value { color: var(--good); } .stat.bad .stat-value { color: var(--bad); } .stat.warn .stat-value { color: var(--warn); }
.dash-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; align-items: start; }
.two-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 16px; align-items: start; }
.record-grid { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.big { font-size: 1.6rem; font-weight: 750; }
.summary-bar { display: flex; flex-wrap: wrap; gap: 16px; align-items: center; padding: 10px 14px; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm); font-size: .9rem; }
.banner { display: flex; gap: 10px; align-items: center; padding: 10px 14px; border-radius: var(--radius-sm); font-size: .9rem; }
.banner.warn { background: var(--warn-soft); color: var(--warn); } .banner.info { background: var(--info-soft); color: var(--info); }
.module-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 8px; }
.module-opt { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); cursor: pointer; background: var(--surface-2); }
.module-opt:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); }
.module-opt input { margin-top: 3px; }
.module-opt > span { display: flex; flex-direction: column; }
.species-row { display: flex; flex-direction: column; gap: 6px; }

/* ---------- breeding ---------- */
.family { display: flex; flex-direction: column; gap: 10px; }
.fam-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.chip.muted { color: var(--muted); }
.month-bars { display: grid; grid-template-columns: repeat(12, 1fr); gap: 6px; height: 140px; align-items: end; }
.month-bars .mb { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 4px; }
.month-bars .bar { width: 100%; max-width: 34px; min-height: 2px; background: var(--s1); border-radius: 4px 4px 0 0; }
.month-bars .n { font-weight: 700; font-size: .85rem; }

/* ---------- farm questionnaire ---------- */
.q-types { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.q-type { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; padding: 12px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); cursor: pointer; background: var(--surface-2); position: relative; min-height: 86px; }
.q-type input { position: absolute; opacity: 0; pointer-events: none; }
.q-type .icon { color: var(--muted); }
.q-type.on { border-color: var(--brand); background: var(--brand-soft); box-shadow: inset 0 0 0 1px var(--brand); }
.q-type.on .icon { color: var(--brand); }
.q-type:has(input:focus-visible) { outline: 2px solid var(--brand); outline-offset: 2px; }
.q-question { border: 0; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.q-question legend { font-weight: 650; padding: 0; margin-bottom: 2px; }
.q-opt { display: inline-flex; align-items: center; cursor: pointer; }
.q-opt input { position: absolute; opacity: 0; pointer-events: none; }
.q-opt span { padding: 7px 14px; border: 1px solid var(--line-strong); border-radius: 99px; font-size: .88rem; font-weight: 600; background: var(--surface); }
.q-opt input:checked + span { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.q-opt input:focus-visible + span { outline: 2px solid var(--brand); outline-offset: 2px; }
.q-preview { display: flex; flex-direction: column; gap: 6px; padding: 12px; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px dashed var(--line-strong); }
.chip.on { background: var(--brand-soft); color: var(--brand-deep); border-color: transparent; font-weight: 600; }
.auth.wide .auth-inner { grid-template-columns: 1fr; width: min(760px, 100%); }
.auth.wide .auth-aside { display: none; }

/* ---------- import ---------- */
details > summary { cursor: pointer; font-weight: 600; font-size: .9rem; }
details[open] > summary { margin-bottom: 6px; }

/* ---------- milking sheet ---------- */
.milk-sheet { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; }
.milk-row { display: grid; grid-template-columns: auto 1fr 90px; gap: 8px; align-items: center; padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-2); }
.milk-row .muted { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.milk-row.wd { border-color: var(--warn); background: var(--warn-soft); }
.milk-row input { text-align: right; min-height: 36px; padding: 6px 8px; }

/* ---------- herd session picker ---------- */
.picker-tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.picker-tools > input { flex: 1 1 260px; font-size: 1.05rem; }
.picker-count { font-size: .95rem; }
.picker-count strong { font-size: 1.3rem; }
.animal-picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; max-height: 420px; overflow-y: auto; padding: 2px; }
.animal-chip { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--radius-sm); cursor: pointer; background: var(--surface-2); min-width: 0; }
.animal-chip.on { border-color: var(--brand); background: var(--brand-soft); }
.animal-chip .muted { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scan-feedback { min-height: 1.4em; font-weight: 650; }
.scan-feedback.good { color: var(--good); } .scan-feedback.bad { color: var(--bad); }
.sticky-save { position: sticky; bottom: 12px; display: flex; justify-content: flex-end; z-index: 5; }
.sticky-save .btn { box-shadow: 0 6px 18px rgba(0, 0, 0, .2); min-height: 48px; padding: 10px 22px; font-size: 1rem; }
@media (max-width: 860px) { .sticky-save { bottom: 84px; } .sticky-save .btn { width: 100%; } .animal-picker { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); } } .banner.danger { background: var(--bad-soft); color: var(--bad); font-weight: 600; }
.chart-box { position: relative; height: 240px; } .chart-box.tall { height: 320px; }

/* ---------- pills ---------- */
.pill { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 99px; font-size: .76rem; font-weight: 650; white-space: nowrap; background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }
.pill.good { background: var(--good-soft); color: var(--good); border-color: transparent; } .pill.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.pill.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; } .pill.info { background: var(--info-soft); color: var(--info); border-color: transparent; }
.pill.small { font-size: .7rem; padding: 1px 6px; margin-left: 6px; }
.chip { display: inline-flex; align-items: center; gap: 4px; border: 1px solid var(--line); border-radius: 99px; padding: 3px 10px; font-size: .8rem; margin: 2px; color: var(--ink); background: var(--surface-2); }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 4px; flex: none; }

/* ---------- tables ---------- */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.data th { text-align: left; font-size: .74rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 650; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.data td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.data tr:last-child td { border-bottom: 0; }
table.data .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.data tr.click { cursor: pointer; }
table.data tr.click:hover td { background: var(--surface-2); }
table.data tr.tone-warn td:first-child { box-shadow: inset 3px 0 0 var(--warn); }
table.data tr.tone-muted td { color: var(--muted); }
table.data tfoot td { border-top: 2px solid var(--line-strong); }
table.matrix td.center { text-align: center; }
.thumb { width: 40px; height: 40px; border-radius: 8px; object-fit: cover; display: block; }
.thumb.ph { display: grid; place-items: center; background: var(--surface-2); color: var(--muted); }
.empty { display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; padding: 28px 16px; color: var(--muted); }
.empty.ok { color: var(--good); } .empty.error { color: var(--bad); }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; }
.toolbar select { width: auto; }
.search { position: relative; display: flex; align-items: center; flex: 1; min-width: 200px; max-width: 420px; }
.search .icon { position: absolute; left: 11px; color: var(--muted); }
.search input[type=search] { padding-left: 34px; }

/* ---------- forms ---------- */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.form-row { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.form-row > .label { display: block; }
.form-row.full, .form-grid > .full { grid-column: 1 / -1; }
.form-row.readonly .value { font-size: .92rem; padding: 4px 0; }
.lines table { width: 100%; border-collapse: collapse; }
.lines th { text-align: left; font-size: .75rem; color: var(--muted); padding: 4px; }
.lines td { padding: 3px; }
.lines td input, .lines td select { min-height: 36px; padding: 6px 8px; }
.lines .table-scroll { margin-bottom: 6px; }
.img-input { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.img-preview img { max-width: 160px; max-height: 120px; border-radius: 8px; display: block; }
.img-preview.large { min-height: 140px; display: grid; place-items: center; background: var(--surface-2); border: 1px dashed var(--line-strong); border-radius: var(--radius); }
.img-preview.large img { max-width: 100%; max-height: 360px; }

/* ---------- modal ---------- */
.modal-wrap { position: fixed; inset: 0; background: rgba(10, 16, 10, .45); z-index: 100; display: flex; align-items: center; justify-content: center; padding: 16px; animation: fade .15s; }
.modal-wrap.out { opacity: 0; transition: opacity .15s; }
@keyframes fade { from { opacity: 0; } }
.modal { background: var(--surface); border-radius: 18px; width: min(560px, 100%); max-height: calc(100vh - 32px); display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0, 0, 0, .25); animation: pop .18s cubic-bezier(.2, .9, .3, 1.2); }
.modal.wide { width: min(860px, 100%); }
@keyframes pop { from { transform: translateY(10px) scale(.98); } }
.modal header { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-body { padding: 16px 18px; overflow-y: auto; }
.modal footer { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); }
#toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; width: min(480px, calc(100% - 32px)); }
.toast { display: flex; gap: 8px; align-items: center; background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; box-shadow: 0 8px 24px rgba(0, 0, 0, .2); font-size: .9rem; font-weight: 500; animation: pop .2s; pointer-events: auto; }
.toast.error { background: var(--bad); color: #fff; } .toast.warn { background: var(--warn); color: #1a1200; }
.toast.out { opacity: 0; transform: translateY(6px); transition: .3s; }

/* ---------- record ---------- */
.kv-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px 18px; margin: 0; }
.kv dt { font-size: .74rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 650; }
.kv dd { margin: 2px 0 0; font-weight: 500; word-break: break-word; }
.photos { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 14px; }
.photos figure { margin: 0; }
.photo { max-width: 100%; max-height: 320px; border-radius: 10px; display: block; }
.history { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; font-size: .88rem; }
.history li { border-left: 2px solid var(--line); padding-left: 10px; }
.changes { margin: 4px 0 0; padding-left: 16px; color: var(--muted); font-size: .8rem; }
.spark-list { display: flex; flex-wrap: wrap; gap: 8px; }
.spark-list > div { display: flex; flex-direction: column; background: var(--surface-2); border-radius: 8px; padding: 6px 10px; }
.qr-label { display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center; padding: 10px; }
.qr svg { width: 220px; height: 220px; background: #fff; border-radius: 8px; padding: 4px; }

/* ---------- dashboard lists ---------- */
.alert-list, .rec-list, .task-list, .note-list, .mini-list, .field-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 4px; }
.alert-list li a, .alert-list li > div { display: flex; gap: 10px; align-items: flex-start; padding: 8px 10px; border-radius: var(--radius-sm); color: var(--ink); text-decoration: none; }
.alert-list li a:hover { background: var(--surface-2); }
.alert-list b, .rec-list b, .task-list b, .note-list b { display: block; font-size: .9rem; }
.alert-list .dot { width: 9px; height: 9px; border-radius: 50%; margin-top: 7px; flex: none; background: var(--info); }
.alert-list .danger .dot { background: var(--bad); box-shadow: 0 0 0 3px var(--bad-soft); } .alert-list .warn .dot { background: var(--warn); }
.rec-list li { display: flex; gap: 10px; padding: 6px 0; }
.rec-list li > div { display: flex; flex-direction: column; }
.rec-icon { width: 32px; height: 32px; border-radius: 10px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand); flex: none; }
.rec-icon.sell { background: var(--info-soft); color: var(--info); } .rec-icon.reorder { background: var(--warn-soft); color: var(--warn); }
.task-list li { display: flex; gap: 10px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); }
.task-list li:last-child { border: 0; }
.task-list li a { flex: 1; color: var(--ink); text-decoration: none; display: flex; flex-direction: column; }
.task-list li.late .muted { color: var(--bad); }
.note-list a { display: flex; gap: 10px; align-items: center; color: var(--ink); text-decoration: none; padding: 4px 0; }
.note-list a > div { display: flex; flex-direction: column; min-width: 0; }
.mini-list li { padding: 3px 0; font-size: .9rem; }
.wx-mini { display: flex; flex-direction: column; gap: 10px; }
.wx-now { display: flex; gap: 12px; align-items: center; }
.wx-now strong { font-size: 2.4rem; font-weight: 750; letter-spacing: -.03em; }
.wx-now div { display: flex; flex-direction: column; }
.wx-days { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; text-align: center; }
.wx-days > div { display: flex; flex-direction: column; background: var(--surface-2); border-radius: 10px; padding: 6px 2px; }
.rain { color: var(--info); }
.wx-strip { display: grid; grid-template-columns: repeat(7, minmax(110px, 1fr)); gap: 10px; overflow-x: auto; }
.wx-day { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; display: flex; flex-direction: column; align-items: center; text-align: center; gap: 2px; }
.wx-ic { font-size: 1.8rem; }
.big-actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.big-btn { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; min-height: 120px; border-radius: 20px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font: 700 1.05rem var(--font); cursor: pointer; text-decoration: none !important; box-shadow: var(--shadow); }
.big-btn.in { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.big-btn.out { background: var(--bad); color: #fff; border-color: var(--bad); }
.clock-hero { display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center; padding: 24px 0; }
.clock-hero .big-btn { width: min(320px, 100%); min-height: 180px; font-size: 1.4rem; border-radius: 50%; aspect-ratio: 1; }
.worker-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; }
.worker-tile { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 14px 10px; border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius); cursor: pointer; color: var(--ink); font: inherit; text-align: center; }
.worker-tile:hover { border-color: var(--brand); }
.worker-tile.in { border-color: var(--good); background: var(--good-soft); }
.quick-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.quick { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 18px 10px; border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius); cursor: pointer; color: var(--ink); font: 600 .9rem var(--font); text-align: center; text-decoration: none !important; }
.quick .icon { color: var(--brand); }
.quick:hover { border-color: var(--brand); background: var(--brand-soft); }
.quick.wide { flex-direction: row; justify-content: center; }
.more-list { display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.more-list a { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--line); color: var(--ink); text-decoration: none; }
.more-list a span { flex: 1; }

/* ---------- finance ---------- */
.budget { display: inline-flex; align-items: center; gap: 6px; }
.budget .bar { display: inline-block; height: 6px; width: 60px; background: var(--good); border-radius: 3px; }
.budget .bar.near { background: var(--warn); } .budget .bar.over { background: var(--bad); }
.hbars { display: flex; flex-direction: column; gap: 6px; }
.hbar { display: grid; grid-template-columns: 120px 1fr 80px; gap: 8px; align-items: center; }
.hbar .track { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.hbar .fill { display: block; height: 100%; background: var(--s2); border-radius: 4px; }
.hbar b { text-align: right; }

/* ---------- crops ---------- */
.gantt { display: flex; flex-direction: column; min-width: 720px; }
.card:has(.gantt) { overflow-x: auto; }
.gantt-row { display: grid; grid-template-columns: 170px 1fr; align-items: center; min-height: 44px; border-bottom: 1px solid var(--line); }
.gantt-row.head { min-height: 28px; }
.gantt-label { display: flex; flex-direction: column; padding-right: 10px; font-size: .88rem; }
.gantt-track { position: relative; height: 100%; min-height: 36px; }
.gantt-month { position: absolute; top: 4px; font-size: .74rem; color: var(--muted); padding-left: 3px; border-left: 1px solid var(--line); height: 100%; }
.gantt-bar { position: absolute; top: 8px; height: 22px; border-radius: 6px; color: #fff; font-size: .76rem; font-weight: 650; padding: 0 8px; display: flex; align-items: center; overflow: hidden; white-space: nowrap; text-decoration: none !important; }
.gantt-bar.planned { opacity: .55; background-image: repeating-linear-gradient(45deg, rgba(255, 255, 255, .15) 0 6px, transparent 6px 12px) !important; }
.gantt-dot { position: absolute; bottom: 2px; width: 7px; height: 7px; border-radius: 50%; background: var(--ink); transform: translateX(-50%); opacity: .7; }
.gantt-dot.spraying { background: var(--bad); } .gantt-dot.fertilizer { background: var(--s2); } .gantt-dot.harvest { background: var(--good); }
.gantt-today { position: absolute; top: 0; bottom: 0; border-left: 2px dashed var(--bad); }
table.rotation td { vertical-align: top; min-width: 130px; }
.crop-chip { display: flex; flex-direction: column; border-left: 4px solid; padding: 4px 8px; background: var(--surface-2); border-radius: 6px; color: var(--ink); text-decoration: none !important; margin-bottom: 4px; }

/* ---------- map ---------- */
.page-map { max-width: none; }
.map-wrap { display: grid; grid-template-columns: 1fr 340px; gap: 16px; }
.map-main { position: relative; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); }
.map { height: calc(100vh - 210px); min-height: 420px; background: var(--surface-2); }
.map.short { height: 420px; border-radius: var(--radius); }
.map-toolbar { position: absolute; z-index: 500; top: 10px; left: 56px; right: 60px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; background: var(--surface); padding: 6px 10px; border-radius: 12px; box-shadow: var(--shadow); width: fit-content; max-width: calc(100% - 120px); }
.map-side { display: flex; flex-direction: column; gap: 12px; max-height: calc(100vh - 210px); overflow-y: auto; }
.map.drawing { cursor: crosshair; }
.field-list button { display: flex; width: 100%; align-items: center; gap: 10px; padding: 8px; background: none; border: 0; border-radius: 8px; cursor: pointer; text-align: left; color: var(--ink); font: inherit; }
.field-list button:hover { background: var(--surface-2); }
.field-list .grow { display: flex; flex-direction: column; }
.legend { display: flex; flex-direction: column; gap: 4px; }
.legend > div { display: flex; gap: 8px; align-items: center; }
.field-label { background: rgba(0, 0, 0, .55); color: #fff; border: 0; box-shadow: none; font-weight: 650; font-size: 11px; padding: 2px 6px; border-radius: 6px; }
.field-label:before { display: none; }
.map-pin span { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: #fff; border: 2px solid var(--brand); font-size: 14px; box-shadow: 0 2px 6px rgba(0, 0, 0, .3); color: #1c261d; }
.map-pin { background: none; border: 0; }
.map-pin.pin-warn span { border-color: #c2412d; background: #fde8e4; }
.map-pin.pin-pump.pin-on span { background: #2b7bb9; color: #fff; border-color: #fff; }
.map-pin.pin-machine span { border-color: #d9a400; }
.map-pin.pin-vertex span { width: 14px; height: 14px; background: #ffcc00; border: 2px solid #fff; }
.leaflet-container { font: inherit; }
.leaflet-popup-content { font-size: 13px; }

/* ---------- sensors / ai ---------- */
.sensor-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.sensor { display: flex; flex-direction: column; gap: 3px; padding: 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-2); color: var(--ink); text-decoration: none !important; }
.sensor.warn { border-color: var(--warn); background: var(--warn-soft); }
.sensor.on { border-color: var(--info); background: var(--info-soft); }
.sensor .reading { font-size: 1.5rem; font-weight: 750; }
.yield-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 12px; }
.yield { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; background: var(--surface-2); display: flex; flex-direction: column; gap: 6px; }
.yield-head { display: flex; justify-content: space-between; gap: 10px; }
.yield-head > div { display: flex; flex-direction: column; }
.range { position: relative; height: 8px; background: var(--line); border-radius: 4px; margin: 6px 0; }
.range span { position: absolute; top: 0; bottom: 0; background: var(--brand-soft); border: 1px solid var(--brand); border-radius: 4px; }
.range i { position: absolute; top: -4px; width: 4px; height: 16px; background: var(--brand); border-radius: 2px; transform: translateX(-50%); }
.drivers { list-style: none; padding: 0; margin: 0; font-size: .85rem; }
.drivers li.neg b { color: var(--bad); } .drivers li.pos b { color: var(--good); }
.pest-form { display: flex; flex-direction: column; gap: 10px; max-width: 520px; }
.diag h2 { font-size: 1.4rem; margin-bottom: 6px; }
.scan-video { width: 100%; max-width: 420px; border-radius: 12px; background: #000; }
.integ { display: grid; grid-template-columns: 220px auto 1fr; gap: 10px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); }
.integ:last-child { border: 0; }
.checklist { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.checklist li { display: flex; gap: 12px; align-items: flex-start; }
.checklist li > div { display: flex; flex-direction: column; }
.checklist .tick { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--line-strong); display: grid; place-items: center; flex: none; }
.checklist li.done .tick { background: var(--good); border-color: var(--good); color: #fff; }
.checklist li.done b { text-decoration: line-through; color: var(--muted); }

/* ---------- auth ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; background: radial-gradient(circle at 20% 0%, var(--brand-soft), transparent 50%), var(--bg); }
.auth-inner { display: grid; grid-template-columns: minmax(0, 420px) minmax(0, 380px); gap: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 22px; overflow: hidden; box-shadow: 0 20px 60px rgba(20, 40, 20, .12); width: min(820px, 100%); }
.auth-card { padding: 32px; display: flex; flex-direction: column; gap: 12px; }
.auth-brand { display: flex; align-items: center; gap: 12px; }
.auth-aside { background: var(--brand); color: var(--brand-ink); padding: 32px; display: flex; flex-direction: column; justify-content: center; gap: 16px; }
.ticks { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.ticks li { display: flex; gap: 10px; align-items: flex-start; }

/* ---------- documents / print ---------- */
.doc { font-size: .92rem; }
.doc-head { display: flex; justify-content: space-between; gap: 20px; border-bottom: 2px solid var(--ink); padding-bottom: 10px; margin-bottom: 14px; }
.doc h3 { margin: 18px 0 6px; font-size: 1rem; }
.report table.data { margin-bottom: 6px; }
.payslip { page-break-after: always; border: 1px solid var(--line); padding: 16px; border-radius: 10px; margin-bottom: 16px; }
.print-body { background: #fff; color: #111; padding: 24px; --ink: #111; --muted: #555; --line: #ddd; --surface: #fff; --surface-2: #f6f6f6; }
@media print {
  .sidebar, .topbar, .bottom-nav, .tabs, .page-head .actions, #toasts { display: none !important; }
  .content { margin: 0; } .card { box-shadow: none; border: 0; padding: 0; }
  body { background: #fff; }
}

/* ---------- mobile ---------- */
@media (max-width: 1100px) {
  .record-grid { grid-template-columns: 1fr; }
  .map-wrap { grid-template-columns: 1fr; }
  .map-side { max-height: none; }
  .map { height: 60vh; }
}
@media (max-width: 860px) {
  .sidebar { display: none; }
  .content { margin-left: 0; }
  .mobile-only { display: flex; }
  .user-name { display: none; }
  .topbar { padding: 8px 16px; padding-top: max(8px, env(safe-area-inset-top)); }
  .farm-mobile { min-width: 0; flex: 0 1 150px; }
  .farm-mobile select { width: 100%; min-height: 34px; padding: 4px 8px; font-size: .8rem; }
  .sync-status span { display: none; }
  .page { padding: 16px 16px 100px; gap: 14px; }
  h1 { font-size: 1.35rem; }
  .bottom-nav { display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 30; background: var(--surface); border-top: 1px solid var(--line); padding: 6px 4px max(6px, env(safe-area-inset-bottom)); justify-content: space-around; }
  .bottom-nav a { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: .7rem; font-weight: 600; color: var(--muted); padding: 4px 8px; text-decoration: none; min-width: 56px; }
  .bottom-nav a.active { color: var(--brand); }
  .bottom-nav a.fab { background: var(--brand); color: var(--brand-ink); border-radius: 16px; margin-top: -18px; padding: 10px 14px; box-shadow: 0 6px 16px rgba(0, 0, 0, .2); }
  .form-grid { grid-template-columns: 1fr; }
  .two-col, .dash-grid { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .stat-value { font-size: 1.25rem; }
  .auth-inner { grid-template-columns: 1fr; }
  .auth-aside { display: none; }
  .modal-wrap { align-items: flex-end; padding: 0; }
  .modal, .modal.wide { width: 100%; border-radius: 18px 18px 0 0; max-height: 92vh; }
  .integ { grid-template-columns: 1fr; gap: 4px; }
  .map-toolbar { left: 50px; right: 10px; max-width: none; }
  /* Tables become stacked cards */
  table.data:not(.matrix):not(.rotation) thead { display: none; }
  table.data:not(.matrix):not(.rotation) tr { display: block; padding: 10px 0; border-bottom: 1px solid var(--line); }
  table.data:not(.matrix):not(.rotation) td { display: flex; justify-content: space-between; gap: 12px; padding: 3px 4px; border: 0; text-align: right; }
  table.data:not(.matrix):not(.rotation) td:before { content: attr(data-label); color: var(--muted); font-size: .78rem; text-align: left; font-weight: 600; }
  table.data:not(.matrix):not(.rotation) td[data-label=""]:before { content: none; }
  table.data:not(.matrix):not(.rotation) td.num { justify-content: space-between; }
  .wx-strip { grid-template-columns: repeat(7, 110px); }
  .row-form input, .row-form select { min-width: 0; width: 100%; }
  .row-form .label { flex: 1 1 140px; }
  .hbar { grid-template-columns: 90px 1fr 70px; }
}
@media (max-width: 400px) { .stats { grid-template-columns: 1fr 1fr; gap: 8px; } .stat { padding: 10px 12px; } }
