/* Залік — палітра «чорнозем і пшениця». Світла/темна тема — з налаштувань Telegram. */
:root {
  --bg: #f4efe4;
  --surface: #fffcf5;
  --surface-2: #efe8d9;
  --line: #e2d8c4;
  --ink: #211c15;
  --muted: #776d5e;
  --accent: #b5761a;
  --accent-ink: #ffffff;
  --accent-soft: #f3e2c0;
  --neg: #b2442b;
  --pos: #3f7a3a;
  --card: #241e17;
  --card-ink: #f6eedc;
  --card-muted: #b9ab93;
  --card-hl: #f2bf4a;
  --radius: 14px;
  --font: 'Manrope', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --display: 'Unbounded', 'Manrope', system-ui, sans-serif;
  color-scheme: light;
}
:root[data-theme='dark'] {
  --bg: #13110d;
  --surface: #1d1a15;
  --surface-2: #26221b;
  --line: #322c23;
  --ink: #f1eadb;
  --muted: #a3988a;
  --accent: #e3a83c;
  --accent-ink: #1a1408;
  --accent-soft: #3a2f1b;
  --neg: #ef8b6f;
  --pos: #8fc583;
  --card: #2a241b;
  --card-ink: #f6eedc;
  --card-muted: #b3a58c;
  --card-hl: #f2bf4a;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.4 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  padding: 0 16px calc(24px + env(safe-area-inset-bottom));
  max-width: 560px;
  margin: 0 auto;
  overflow-x: hidden;
}
button { font: inherit; color: inherit; cursor: pointer; }
small { color: var(--muted); font-weight: 500; }

.top { display: flex; align-items: center; justify-content: space-between; padding: 12px 0 8px; }
.brand { font: 700 18px var(--display); letter-spacing: -0.01em; display: flex; align-items: center; gap: 8px; }
.brand-mark { width: 14px; height: 22px; border-radius: 7px 7px 7px 7px / 11px 11px 11px 11px; background: var(--accent); transform: rotate(18deg); box-shadow: inset -3px 0 0 rgba(0,0,0,.15); }
.icon-btn { border: 0; background: var(--surface); width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; border: 1px solid var(--line); }

/* ----- Результат ----- */
.result {
  position: sticky; top: 0; z-index: 5;
  background: var(--card); color: var(--card-ink);
  border-radius: 20px; padding: 16px 18px 14px;
  margin: 0 0 10px;
  box-shadow: 0 8px 24px -14px rgba(0,0,0,.5);
}
.result .k { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--card-muted); font-weight: 600; }
.result .big { font: 700 32px/1.1 var(--display); color: var(--card-hl); letter-spacing: -0.02em; margin: 4px 0 2px; font-variant-numeric: tabular-nums; word-break: break-word; }
.result .big small { font: 600 15px var(--font); color: var(--card-hl); opacity: .85; }
.result .meta { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 13px; color: var(--card-muted); }
.result .meta b { color: var(--card-ink); font-weight: 700; font-variant-numeric: tabular-nums; }
.result .split { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; padding-top: 10px; border-top: 1px solid rgba(255,255,255,.1); }
.result .split .v { font: 700 17px var(--display); font-variant-numeric: tabular-nums; }
.result .diff .v { color: var(--card-hl); }
.result .empty { color: var(--card-muted); font-size: 14px; padding: 6px 0; }
.result .empty b { color: var(--card-ink); display: block; font: 700 18px var(--display); margin-bottom: 4px; }
.result .err { color: #ffb39e; font-size: 14px; }

.actions { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-bottom: 4px; }
.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 12px 16px; font-weight: 700; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.ghost { background: transparent; width: 100%; margin-top: 10px; border-style: dashed; color: var(--accent); }
.hint { font-size: 13px; color: var(--muted); margin: 2px 2px 8px; }

/* ----- Форма ----- */
.form { display: flex; flex-direction: column; gap: 12px; margin-top: 10px; }
.group, .fold { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.label { font-weight: 700; margin-bottom: 8px; }
.label small { font-weight: 500; margin-left: 4px; }
.sub { font-size: 13px; color: var(--muted); margin: 8px 0 0; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; }
.row-between .label { margin: 0; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > span { font-size: 13px; color: var(--muted); font-weight: 600; }
.group > .field + .grid2 { margin-top: 10px; }
.inp { display: flex; align-items: center; background: var(--bg); border: 1.5px solid var(--line); border-radius: 11px; padding: 0 10px; min-height: 46px; transition: border-color .15s; }
.inp:focus-within { border-color: var(--accent); }
.inp.bad { border-color: var(--neg); }
.inp input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--ink); font: 600 17px var(--font); padding: 10px 0; font-variant-numeric: tabular-nums; }
.inp input::placeholder { color: var(--muted); opacity: .6; font-weight: 500; font-size: 14px; }
.inp em { font-style: normal; color: var(--muted); font-size: 13px; font-weight: 600; white-space: nowrap; padding-left: 6px; }
.inp.sm { min-height: 40px; width: 92px; flex: none; }
.inp.sm input { font-size: 16px; text-align: right; padding: 8px 0; }

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chips.scroll { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 2px 16px; }
.chips.scroll::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 1.5px solid var(--line); background: var(--surface); border-radius: 999px; padding: 9px 15px; font-weight: 700; font-size: 14px; white-space: nowrap; }
.chip small { display: block; font-size: 11px; font-weight: 600; }
.chip[aria-checked='true'] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.chip[aria-checked='true'] small { color: inherit; opacity: .7; }
#crops .chip { text-align: left; border-radius: 14px; padding: 8px 14px; }
#methods .chip { flex: 1; text-align: center; }

.seg { display: inline-flex; background: var(--surface-2); border-radius: 11px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; padding: 8px 12px; border-radius: 9px; font-weight: 700; font-size: 14px; color: var(--muted); }
.seg button[aria-pressed='true'] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.seg.small button { padding: 5px 12px; }
.seg.wide { display: flex; margin-top: 10px; }
.seg.wide button { flex: 1; }

.tariffs { display: flex; flex-direction: column; gap: 6px; }
.tg-row { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.tg-row > span { flex: 1; font-weight: 600; font-size: 14px; }
.tg-row input[type='checkbox'] { width: 20px; height: 20px; accent-color: var(--accent); margin: 0; flex: none; }
.tg-row .nobox { padding-left: 30px; }

.link { border: 0; background: none; color: var(--accent); font-weight: 700; padding: 6px 0; font-size: 14px; }
.fold summary { white-space: nowrap; font-weight: 700; cursor: pointer; list-style: none; display: flex; align-items: center; gap: 8px; }
.fold summary::-webkit-details-marker { display: none; }
.fold summary::after { content: ''; margin-left: auto; width: 8px; height: 8px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg); transition: transform .2s; flex: none; }
.fold[open] summary::after { transform: rotate(-135deg); }
.fold[open] summary { margin-bottom: 12px; }
.fold summary small { font-weight: 500; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.pro { font: 700 10px var(--font); letter-spacing: .06em; text-transform: uppercase; background: var(--accent-soft); color: var(--accent); padding: 2px 6px; border-radius: 6px; vertical-align: middle; }

/* Розшифровка */
.bd { border-top: 1px solid var(--line); padding: 10px 0; }
.bd:first-child { border-top: 0; padding-top: 0; }
.bd .t { font-weight: 700; display: flex; justify-content: space-between; gap: 8px; }
.bd .t .ok { color: var(--pos); font-weight: 600; font-size: 13px; }
.bd .f { font-size: 13.5px; color: var(--muted); margin-top: 3px; font-variant-numeric: tabular-nums; }
.bd .f b { color: var(--ink); }
.neg { color: var(--neg) !important; }
.posv { color: var(--pos) !important; }
.bd.total { background: var(--surface-2); border: 0; border-radius: 10px; padding: 10px 12px; margin-top: 6px; }

/* Порівняння */
.cmp { width: 100%; border-collapse: collapse; font-size: 12.5px; font-variant-numeric: tabular-nums; table-layout: fixed; }
.cmp th, .cmp td { padding: 7px 4px; text-align: right; border-bottom: 1px solid var(--line); vertical-align: top; }
.cmp th:first-child, .cmp td:first-child { text-align: left; color: var(--muted); width: 34%; }
.cmp td { white-space: nowrap; }
.cmp td:first-child { white-space: normal; }
.cmp thead th { font-weight: 700; font-size: 12px; color: var(--ink); }
.cmp tr.sum td { font-weight: 700; color: var(--ink); }
.full { grid-column: 1 / -1; }
.full .seg { display: flex; }
.full .seg button { flex: 1; }
.tag { white-space: normal; display: inline-block; font-size: 10.5px; font-weight: 700; padding: 2px 5px; border-radius: 6px; background: var(--surface-2); color: var(--ink); line-height: 1.2; text-align: center; }

.foot { font-size: 12.5px; color: var(--muted); text-align: center; margin: 6px 12px; }

/* Режими */
body:not(.adv) .adv-only { display: none !important; }
body.adv .simple-only { display: none !important; }

/* Шторки */
.sheet { position: fixed; inset: 0; background: rgba(10,8,5,.45); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet[hidden] { display: none; }
.sheet-body { background: var(--bg); width: 100%; max-width: 560px; border-radius: 20px 20px 0 0; padding: 16px 16px calc(24px + env(safe-area-inset-bottom)); max-height: 88vh; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-head h2 { font: 700 18px var(--display); margin: 0; }
.switch-row { display: flex; gap: 12px; align-items: center; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.switch-row > span { flex: 1; display: flex; flex-direction: column; gap: 3px; }
.switch-row small { font-size: 13px; }
.switch { appearance: none; width: 46px; height: 28px; border-radius: 14px; background: var(--line); position: relative; flex: none; transition: background .2s; margin: 0; }
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(18px); }

.set-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.set-card .row-between { margin: 0; }
.set-card .name { flex: 1; font-weight: 700; }
.set-card .name input { width: 100%; border: 0; border-bottom: 1.5px solid var(--line); background: transparent; color: var(--ink); font: 700 16px var(--font); padding: 4px 0; outline: 0; }
.set-card .name input:focus { border-color: var(--accent); }
.set-card .acts { display: flex; gap: 14px; }
.set-card .grid2 .inp { min-height: 40px; }
.set-card .grid2 .inp input { font-size: 15px; }
.badge-def { font-size: 12px; color: var(--pos); font-weight: 700; }

.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 700; z-index: 30; font-size: 14px; }

@media (max-width: 360px) {
  .result .big { font-size: 27px; }
  .grid2 { gap: 8px; }
}
