/* Единая система оформления.
   Цвета: песочный фон, коричневый — заголовки и фермы, зелёный — действия и «плюс», терракота — «минус».
   Формы: карточки 18px, поля и кнопки 14px, «таблетки» — полностью круглые. Отступы кратны 4: 8 / 12 / 16 / 24. */
:root {
  --bg: #F3ECE1; --surface: #FFFBF5; --surface2: #F5EEE3; --line: #E6DACA; --plate: #EADFCC;
  --text: #3B2A1C; --muted: #8A735D; --brown: #6B4A2B; --brown-ink: #FFF8EE;
  --accent: #4E8A3E; --accent-ink: #FFFFFF; --accent-soft: #E3EEDA;
  --up: #3F7D30; --down: #B4553A; --down-ink: #FFFFFF; --warn-bg: #F6E7C8; --warn-ink: #6E4E12;
  --chart: #4E8A3E;
  --r-card: 18px; --r-ctl: 14px;
}
:root[data-theme="dark"] {
  --bg: #1A140F; --surface: #241C15; --surface2: #2B221A; --line: #3A2E23; --plate: #3A2E22;
  --text: #F1E7DA; --muted: #B29D86; --brown: #D9B48A; --brown-ink: #1A140F;
  --accent: #7DBE68; --accent-ink: #10200B; --accent-soft: #26341D;
  --up: #8FD07A; --down: #E58A6E; --down-ink: #1A140F; --warn-bg: #3A2C12; --warn-ink: #F2CF7F;
  --chart: #68A555;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html.large body { zoom: 1.14; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
body.noscroll { overflow: hidden; }
button, input, select { font: inherit; color: inherit; }
h1 { font-size: 20px; margin: 0; flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; color: var(--brown); font-weight: 750; }
h1 span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
h2 { font-size: 21px; margin: 2px 44px 14px 0; color: var(--brown); text-wrap: balance; }
h2.with-ico { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
h3 { font-size: 12.5px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin: 0 4px 8px; font-weight: 700; }
h4 { margin: 16px 0 6px; font-size: 15px; color: var(--brown); }
p { margin: 0; }
.muted { color: var(--muted); } .small { font-size: 13.5px; } .center { text-align: center; justify-content: center; }
.up { color: var(--up); } .down { color: var(--down); } .zero { color: var(--muted); font-weight: 600; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

#splash { position: fixed; inset: 0; background: var(--bg); }

.ani { display: block; width: 52px; height: 52px; flex: none; }
.ani.h-ico { width: 32px; height: 32px; }
.ani.r-ico { width: 40px; height: 40px; }
.ani.r-ico.sm { width: 34px; height: 34px; }

/* ---- каркас ---- */
.top {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 6px; min-height: 56px;
  padding: calc(8px + env(safe-area-inset-top)) 16px 4px; background: var(--bg);
}
.farm-tabs {
  position: sticky; top: calc(56px + env(safe-area-inset-top)); z-index: 5; display: flex; gap: 8px;
  overflow-x: auto; padding: 4px 16px 12px; background: var(--bg); scrollbar-width: none;
}
.farm-tabs::-webkit-scrollbar { display: none; }
.farm-tabs button {
  flex: none; border: 1px solid var(--line); background: var(--surface); color: var(--text); border-radius: 999px;
  padding: 8px 16px; font-weight: 600; cursor: pointer; white-space: nowrap; transition: background .15s, color .15s;
}
.farm-tabs button.on { background: var(--brown); border-color: var(--brown); color: var(--brown-ink); }
.view { max-width: 640px; margin: 0 auto; padding: 4px 16px calc(100px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 16px; }
.view.enter { animation: enter .22s ease-out; }
@keyframes enter { from { opacity: 0; transform: translateY(6px); } }
.sec { display: flex; flex-direction: column; margin-top: 8px; }

.ic { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.ic.chev { width: 16px; height: 16px; color: var(--muted); opacity: .7; }
.icon-btn { border: 0; background: transparent; width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; cursor: pointer; color: var(--brown); flex: none; }
.icon-btn:active { background: var(--surface2); }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: flex; justify-content: center;
  background: var(--surface); border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.tabs button {
  flex: 1; max-width: 120px; border: 0; background: none; color: var(--muted); display: flex; flex-direction: column;
  align-items: center; gap: 3px; font-size: 11px; padding: 6px 0; border-radius: 12px; cursor: pointer; min-width: 0;
}
.tabs button span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tabs button.on { color: var(--accent); font-weight: 650; }
.tabs button.on .ic { stroke-width: 2.3; }

/* ---- карточки и списки: одна система ---- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-card); padding: 16px; }
.list { display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-card); overflow: hidden; }
.list > * + * { border-top: 1px solid var(--line); }
.list[hidden] { display: none; }
.row-item {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; background: transparent; color: var(--text);
  border: 0; padding: 12px 16px; cursor: pointer; min-height: 58px;
}
.row-item.static { cursor: default; }
.row-item.head { background: var(--surface2); }
.row-item.add { color: var(--up); font-weight: 650; justify-content: center; }
button.row-item:active { background: var(--surface2); }
.row-item small { display: block; margin-top: 1px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.farm-block + .farm-block { margin-top: 10px; }
.count { font-size: 18px; font-variant-numeric: tabular-nums; }

.hero { text-align: center; padding: 20px 16px; }
.big { font-size: 48px; font-weight: 800; line-height: 1.05; letter-spacing: -.02em; font-variant-numeric: tabular-nums; color: var(--brown); }
.hero-farms { margin: 16px -16px -20px; border-top: 1px solid var(--line); display: flex; flex-direction: column; }
.hero-farms button {
  display: flex; align-items: center; gap: 10px; padding: 13px 16px; background: none; border: 0; cursor: pointer; text-align: left; color: var(--text); font-weight: 600;
}
.hero-farms button + button { border-top: 1px solid var(--line); }
.hero-farms button span { flex: 1; }
.hero-farms b { color: var(--brown); font-variant-numeric: tabular-nums; font-size: 17px; }
.hero-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 16px; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tile { display: flex; align-items: center; gap: 12px; text-align: left; cursor: pointer; padding: 14px 12px; min-width: 0; color: var(--text); }
.tile:active { transform: scale(.98); }
.t-body { display: flex; flex-direction: column; min-width: 0; }
.t-name { color: var(--muted); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.t-count { font-size: 26px; line-height: 1.15; font-variant-numeric: tabular-nums; }
.delta { font-size: 12.5px; white-space: nowrap; color: var(--muted); }
.delta.up { color: var(--up); } .delta.down { color: var(--down); }

.stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; text-align: center; padding: 14px 6px; }
.stats span { display: block; font-size: 11.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stats b { font-size: 21px; font-variant-numeric: tabular-nums; }
@media (max-width: 380px) { .stats { grid-template-columns: repeat(3, 1fr); row-gap: 12px; } .pick-grid { grid-template-columns: repeat(3, 1fr) !important; } }

/* ---- график ---- */
.chart { margin: 0; padding: 14px 12px 8px; }
.chart-read { font-size: 14px; color: var(--muted); margin: 0 4px 6px; min-height: 20px; }
.chart-read b { color: var(--text); font-size: 16px; }
.chart svg { display: block; width: 100%; height: auto; touch-action: pan-y; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .ax { fill: var(--muted); font-size: 10.5px; font-variant-numeric: tabular-nums; }
.chart .area { fill: var(--chart); opacity: .13; }
.chart .line { fill: none; stroke: var(--chart); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .cross { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .dot { fill: var(--chart); stroke: var(--surface); stroke-width: 2; }
.chart .hit { fill: transparent; cursor: crosshair; }

/* ---- поиск ---- */
.search { position: relative; }
.search .search-ic { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--muted); display: flex; pointer-events: none; }
.search .search-ic .ic { width: 19px; height: 19px; }
.search input { padding-left: 42px !important; }

/* ---- кнопки ---- */
.row { display: flex; align-items: center; } .gap { gap: 8px; } .wrap { flex-wrap: wrap; } .grow { flex: 1; min-width: 0; }
.btn {
  border: 1px solid var(--line); background: var(--surface); color: var(--text); border-radius: var(--r-ctl);
  padding: 11px 16px; font-weight: 650; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 48px; text-align: center; line-height: 1.2; transition: transform .1s, background .15s;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--down); background: transparent; }
.btn.danger-fill { background: var(--down); border-color: var(--down); color: var(--down-ink); }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: 14px; border-radius: 10px; }
.btn.on { background: var(--accent-soft); border-color: var(--accent); color: var(--up); }
.btn.block { display: flex; width: 100%; }
.btn.left { align-self: flex-start; }
.btn:focus-visible, .row-item:focus-visible, .tile:focus-visible, .farm-tabs button:focus-visible, .tabs button:focus-visible,
.seg button:focus-visible, .switch:focus-visible, .hero-farms button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.link { border: 0; background: none; color: var(--up); padding: 0; cursor: pointer; text-decoration: underline; font: inherit; }
.act-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 8px; }
.act-grid > :last-child:nth-child(odd) { grid-column: 1 / -1; }

.vet-dot { width: 34px; height: 34px; border-radius: 10px; background: var(--accent-soft); color: var(--up); display: grid; place-items: center; flex: none; }
.vet-dot .ic { width: 18px; height: 18px; }
.tag { display: inline-block; background: var(--plate); color: var(--brown); border-radius: 8px; padding: 2px 8px; font-weight: 700; font-variant-numeric: tabular-nums; font-size: 14px; }
.tag.big { font-size: 18px; }
.badge { font-size: 12px; background: var(--surface2); color: var(--muted); padding: 3px 8px; border-radius: 999px; white-space: nowrap; }
.empty { color: var(--muted); text-align: center; padding: 20px 16px; }
.note { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 14px 16px; border-radius: var(--r-card); background: var(--accent-soft); }
.note.warn { background: var(--warn-bg); color: var(--warn-ink); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips.scroll { flex-wrap: nowrap; overflow-x: auto; margin: 0 -16px; padding: 0 16px; scrollbar-width: none; }
.chip-btn { flex: none; padding: 8px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; white-space: nowrap; font-size: 15px; }
.chip-btn.on { background: var(--accent-soft); border-color: var(--accent); color: var(--up); font-weight: 650; }

/* ---- настройки ---- */
.seg { display: flex; background: var(--surface2); border: 1px solid var(--line); border-radius: var(--r-ctl); padding: 3px; gap: 3px; }
.seg button, .seg label { flex: 1; border: 0; background: transparent; border-radius: 11px; padding: 9px 8px; font-weight: 600; cursor: pointer; color: var(--muted); text-align: center; font-size: 14.5px; }
.seg button.on, .seg label:has(input:checked) { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(59, 42, 28, .12); }
.seg label { display: block !important; color: var(--muted) !important; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.set { display: flex; flex-direction: column; padding: 0; }
.set-row { display: flex; flex-direction: column; gap: 8px; padding: 14px 16px; }
.set-row + .set-row { border-top: 1px solid var(--line); }
.set-row > span { font-weight: 600; }
.set-row.inline { flex-direction: row; align-items: center; justify-content: space-between; }
.set-row small { display: block; font-weight: 400; font-size: 13px; }
.switch { position: relative; width: 52px; height: 32px; border-radius: 999px; border: 0; background: var(--line); cursor: pointer; flex: none; transition: background .15s; }
.switch i { position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .18s; }
.switch.on { background: var(--accent); }
.switch.on i { transform: translateX(20px); }
.about p { margin: 0 0 4px; }
.about-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.about-head div { display: flex; flex-direction: column; }
.about-head b { color: var(--brown); font-size: 17px; }
.ani.logo-sm { width: 48px; height: 48px; }
.about ol, .about ul { margin: 0; padding-left: 22px; display: flex; flex-direction: column; gap: 4px; }
.about .ver { font-weight: 650; margin-top: 8px; }

/* ---- первый вход ---- */
.lang-screen {
  min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; padding: 24px max(16px, env(safe-area-inset-left)); text-align: center;
}
.lang-screen .logo { width: 96px; height: 96px; margin-bottom: 6px; }
.lang-screen h1 { flex: none; flex-direction: column; gap: 2px; font-size: 30px; }
.lang-screen h1 small { font-size: 20px; color: var(--muted); font-weight: 600; }
.btn.huge { width: min(320px, 100%); min-height: 58px; font-size: 20px; border-radius: 18px; }
.intro { padding-top: 12px; display: flex; flex-direction: column; gap: 12px; }
.intro h2 { margin: 0; font-size: 26px; }
.form-col { display: flex; flex-direction: column; gap: 8px; }
.pick-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.pick { position: relative; display: flex !important; flex-direction: column; align-items: center; gap: 4px; padding: 8px 4px; border-radius: var(--r-ctl);
  border: 2px solid transparent; background: var(--surface); cursor: pointer; font-size: 13px; color: var(--text) !important; }
.pick input { position: absolute; opacity: 0; pointer-events: none; }
.pick:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.pick:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- формы ---- */
.form { display: flex; flex-direction: column; gap: 12px; }
.form label, .lbl { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); font-weight: 550; }
.form .row label { flex: 1; }
input:not([type=checkbox]):not([type=radio]), select {
  width: 100%; min-height: 48px; padding: 10px 14px; border-radius: var(--r-ctl); border: 1px solid var(--line);
  background-color: var(--surface); color: var(--text); font-size: 16px; appearance: none; -webkit-appearance: none;
}
select { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 19px) 50%, calc(100% - 14px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 34px; }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
input[type=date] { min-width: 0; }
.radio { flex-direction: row !important; align-items: flex-start; gap: 10px !important; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-ctl); padding: 12px 14px; cursor: pointer; }
.radio:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.radio input { margin-top: 3px; accent-color: var(--accent); width: 18px; height: 18px; flex: none; }
.radio b { color: var(--text); display: block; } .radio small { color: var(--muted); font-weight: 400; }
.icon-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(56px, 1fr)); gap: 8px; }
.icon-opt { position: relative; display: grid !important; place-items: center; border-radius: 18px; border: 2.5px solid transparent; cursor: pointer; padding: 2px; }
.icon-opt input { position: absolute; opacity: 0; pointer-events: none; }
.icon-opt:has(input:checked) { border-color: var(--accent); }
.icon-opt:has(input:focus-visible) { outline: 2px solid var(--accent); }

.dl { display: grid; grid-template-columns: auto 1fr; gap: 10px 16px; margin: 0 0 12px; }
.dl dt { color: var(--muted); } .dl dd { margin: 0; overflow-wrap: anywhere; font-weight: 550; }

/* ---- шторка ---- */
#sheet-root { display: none; }
#sheet-root.open { display: block; }
.sheet-bg { position: fixed; inset: 0; z-index: 20; background: rgba(26, 20, 15, .5); animation: fade .2s; }
.sheet {
  position: fixed; z-index: 21; left: 0; right: 0; bottom: 0; margin: 0 auto; max-width: 640px; max-height: 92vh; max-height: 92dvh;
  overflow-y: auto; overscroll-behavior: contain; background: var(--bg); border-radius: 24px 24px 0 0;
  padding: 20px 16px calc(24px + env(safe-area-inset-bottom)); animation: up .26s cubic-bezier(.2, .8, .2, 1);
  display: flex; flex-direction: column;
}
.sheet::before { content: ""; width: 40px; height: 4px; border-radius: 4px; background: var(--line); align-self: center; margin: -10px 0 10px; }
.sheet-body { display: flex; flex-direction: column; gap: 12px; }
.sheet-body > h2 { margin-bottom: 0; }
.sheet .close { position: absolute; top: 12px; right: 12px; }
@keyframes up { from { transform: translateY(60px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

/* ---- окно подтверждения ---- */
#dialog-root { display: none; }
#dialog-root.open { display: block; }
.dlg-bg { position: fixed; inset: 0; z-index: 40; background: rgba(26, 20, 15, .55); animation: fade .15s; }
.dlg {
  position: fixed; z-index: 41; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(360px, calc(100% - 32px));
  background: var(--surface); border-radius: 22px; padding: 22px 18px 18px; box-shadow: 0 20px 50px rgba(0,0,0,.3); animation: pop .18s ease-out;
}
.dlg p { font-size: 17px; font-weight: 600; text-align: center; margin: 4px 4px 18px; text-wrap: balance; }
.dlg-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@keyframes pop { from { opacity: 0; transform: translate(-50%, -46%) scale(.96); } }

/* ---- уведомления ---- */
#toast-root { position: fixed; left: 0; right: 0; bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 30; display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; padding: 0 16px; }
.toast { background: var(--text); color: var(--bg); padding: 11px 16px; border-radius: 14px; font-size: 15px; box-shadow: 0 6px 20px rgba(0,0,0,.2); transition: opacity .3s; max-width: 100%; animation: enter .2s ease-out; }
.toast.bad { background: var(--down); color: var(--down-ink); }
.toast.hide { opacity: 0; }
.toast.undo { display: flex; align-items: center; gap: 14px; pointer-events: auto; padding: 6px 6px 6px 16px; }
.toast.undo button { border: 0; background: transparent; color: #A6D98F; font-weight: 750; padding: 9px 12px; border-radius: 10px; cursor: pointer; }
:root[data-theme="dark"] .toast.undo button { color: #3F7D30; }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
