/* OUA Admin — MUD design system, stage 1 (shell/tokens). See docs/design-system.md. */
@import url('mud/fonts.css');
@import url('mud/tokens.css');

:root {
  --radius: 8px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --border: 1px solid var(--gray-250);
  --grid-line-color: var(--gray-250);
  --grid-line: 1px solid var(--grid-line-color);
  --grid-line-outer: 1px solid var(--gray-250);
  --grid-line-strong: 2px solid var(--gray-300);
  --grid-line-group: 2px solid var(--gray-400);
  --fs-xs: 12px;
  --fs-sm: 13px;
  --fs-md: 14px;
  --fs-title: 16px;
  --toolbar-gap: 12px;
  --font: var(--font-family-base);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font-family-base);
  color: var(--gray-900);
  background: var(--gray-100);
  font-size: 14px;
  max-width: 100%;
  overflow-x: clip;
}
body { font-variant-numeric: tabular-nums; }

button, input, select, textarea { font-family: inherit; font-size: inherit; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 40px;
  padding: 0 16px;
  border: 1px solid var(--gray-250);
  background: var(--white);
  color: var(--gray-900);
  border-radius: 8px;
  cursor: pointer;
  font-weight: 500;
  font-size: 14px;
  transition: background 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.btn:hover { background: var(--gray-100); }
.btn:active { background: var(--gray-250); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-primary { background: var(--blue-sky-600); border-color: var(--blue-sky-600); color: #fff; }
.btn-primary:hover { background: var(--blue-sky-700); border-color: var(--blue-sky-700); }
.btn-primary:active { background: var(--blue-sky-800); border-color: var(--blue-sky-800); }
.btn-danger { background: var(--red-600); border-color: var(--red-600); color: #fff; }
.btn-danger:hover { background: var(--red-700); border-color: var(--red-700); }
.btn-text {
  background: transparent;
  border-color: transparent;
  color: var(--gray-900);
}
.btn-text:hover { background: var(--gray-100); }
.btn-sm { height: 32px; padding: 0 12px; font-size: 13px; }
.btn .ico { width: 16px; height: 16px; flex: 0 0 auto; }

:focus-visible { outline: 2px solid var(--blue-sky-500); outline-offset: 2px; }
.btn:focus-visible, .icon-btn:focus-visible, .tab:focus-visible,
.lang-seg-btn:focus-visible, .period-btn:focus-visible, .hala-pick:focus-visible {
  outline: 2px solid #fff;
  box-shadow: 0 0 0 4px var(--blue-sky-500);
}
.topbar :focus-visible, .lightbox :focus-visible { outline-color: #fff; }

/* ---------- Fields / inputs ---------- */
.field label,
.opening-bar .ob-field span,
.settings-card label { display: block; font-size: 13px; color: var(--gray-700); margin-bottom: 6px; }
.field input, .field select, .field textarea,
.form-grid input, .form-grid select, .form-grid textarea,
.opening-bar input,
.settings-card input, .settings-card select,
.period-custom input[type="date"] {
  width: 100%;
  height: 40px;
  border: 1px solid var(--gray-250);
  border-radius: 8px;
  padding: 0 12px;
  outline: none;
  background: var(--white);
  font: inherit;
}
.field textarea { height: auto; padding: 10px 12px; }
.field input:hover, .field select:hover,
.form-grid input:hover, .form-grid select:hover,
.opening-bar input:hover,
.settings-card input:hover, .settings-card select:hover { border-color: var(--gray-600); }
.field input:focus, .field select:focus, .field textarea:focus,
.form-grid input:focus, .form-grid select:focus,
.opening-bar input:focus,
.settings-card input:focus, .settings-card select:focus {
  outline: 2px solid var(--blue-sky-500);
  outline-offset: -2px;
  box-shadow: 0 0 0 4px var(--blue-sky-200);
  border-color: var(--gray-250);
}
.field .hint, .hint { font-size: 12px; color: var(--gray-500); margin-top: 4px; }
/* "key saved" text and its icon-only clear button on one centred line (settings) */
#geminiKeyHint { display: flex; align-items: center; gap: 8px; }
input[type="checkbox"], input[type="radio"] { accent-color: var(--blue-sky-600); width: 16px; height: 16px; }

/* ---------- Status tags ---------- */
.status-pill, .trend-badge, .kpi-delta {
  display: inline-flex;
  align-items: center;
  height: 20px;
  padding: 0 6px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
  background: var(--gray-200);
  color: var(--gray-700);
  line-height: 1;
  white-space: nowrap;
}
.status-ok, .status-pill.good, .trend-badge.good, .kpi-delta.good { background: var(--green-100); color: var(--green-700); }
.status-err, .status-bad, .status-pill.bad, .trend-badge.bad, .kpi-delta.bad { background: var(--red-100); color: var(--red-700); }
.status-warn, .status-pill.warn, .trend-badge.flat, .kpi-delta.flat { background: var(--apricot-100); color: var(--apricot-700); }

/* ---------- Login ---------- */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--gray-100);
  padding: 20px;
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--white);
  border: 1px solid var(--gray-250);
  border-radius: 16px;
  padding: 32px;
}
.login-title { text-align: center; font-size: 20px; font-weight: 600; margin: 0 0 4px; color: var(--gray-900); }
.login-sub { text-align: center; color: var(--gray-500); font-size: 13px; margin-bottom: 22px; }
.login-card .field { margin-bottom: 14px; }
.login-error {
  display: none;
  background: var(--red-100);
  color: var(--red-700);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 14px;
}
.login-error.show { display: block; }
.login-lang { display: flex; justify-content: center; margin-top: 18px; }

.login-card .btn-primary { width: 100%; justify-content: center; margin-top: 4px; }

/* ---------- Segmented control (lang switch, period tabs) ---------- */
.lang-seg, .seg {
  display: inline-flex;
  align-items: center;
  padding: 2px;
  background: var(--gray-100);
  border-radius: 9999px;
  gap: 2px;
}
.lang-seg-btn, .period-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 28px;
  padding: 0 12px;
  border: 0;
  background: none;
  border-radius: 9999px;
  font-size: 13px;
  font-weight: 500;
  color: var(--gray-600);
  cursor: pointer;
  white-space: nowrap;
}
.lang-seg-btn.active, .lang-seg-btn:hover.active { background: var(--gray-900); color: #fff; }
.mm-lang-btn.active { background: var(--gray-900); border-color: var(--gray-900); color: #fff; }

/* ---------- App shell ---------- */
.topbar {
  background: var(--white);
  border-bottom: 1px solid var(--gray-250);
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  padding: 0 24px;
  gap: 18px;
}
.brand { display: flex; align-items: baseline; gap: 10px; white-space: nowrap; min-width: 0; }
.brand #farmTitle { font-size: 17px; font-weight: 600; letter-spacing: -0.01em; color: var(--gray-900); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand-sub { font-size: 13px; color: var(--gray-400); }
.tabs { display: flex; flex-wrap: wrap; gap: 8px; padding: 8px 24px 12px; overflow: visible; }
.tab {
  display: inline-flex;
  align-items: center;
  height: 40px;
  background: var(--white);
  border: 1px solid var(--gray-250);
  border-radius: 8px;
  color: var(--gray-900);
  padding: 0 16px;
  cursor: pointer;
  font-weight: 600;
  font-size: 16px;
  white-space: nowrap;
}
.tab:hover { background: var(--gray-100); }
.tab.active { background: var(--blue-sky-600); border-color: var(--blue-sky-600); color: var(--white); box-shadow: none; }
.topbar-right { display: flex; align-items: center; gap: 14px; flex-shrink: 0; }
.user-label { font-size: 13px; color: var(--gray-500); white-space: nowrap; }

/* ---------- Mobile hamburger menu ---------- */
.mobile-menu-btn {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  padding: 0 12px;
  background: var(--white);
  color: var(--gray-900);
  border: 1px solid var(--gray-250);
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}
.mobile-menu-btn:hover { background: var(--gray-100); }
.mobile-menu-btn .ico { width: 20px; height: 20px; }
.burger-label { font-size: 13px; font-weight: 500; }
.mobile-menu { display: none; }
.mobile-menu-list { display: flex; flex-direction: column; }
.mobile-menu-item,
.mobile-menu-action {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  border-radius: 8px;
  padding: 12px;
  font-size: 15px;
  font-weight: 500;
  color: var(--gray-900);
  cursor: pointer;
}
.mobile-menu-item:hover,
.mobile-menu-action:hover { background: var(--gray-100); }
.mobile-menu-item.active { background: var(--blue-sky-100); color: var(--blue-sky-600); }
.mobile-menu-action { display: none; color: var(--blue-sky-600); }
.mobile-menu-action:hover { background: var(--blue-sky-100); }
.mobile-menu-lang { display: flex; gap: 8px; padding: 10px 12px 2px; }
.mm-lang-btn {
  flex: 1;
  border: 1px solid var(--gray-250);
  background: #fff;
  color: var(--gray-700);
  border-radius: 8px;
  padding: 8px 0;
  font-weight: 500;
  cursor: pointer;
}
.mobile-menu-user {
  padding: 10px 12px 2px;
  margin-top: 6px;
  border-top: 1px solid var(--gray-250);
  font-size: 13px;
  color: var(--gray-500);
}
.mobile-menu-logout {
  display: block;
  width: 100%;
  margin-top: 8px;
  background: var(--white);
  color: var(--gray-900);
  border: 1px solid var(--gray-250);
  border-radius: 8px;
  padding: 12px;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
}
.mobile-menu-logout:hover { background: var(--gray-100); }

main { padding: 0 24px 24px; }
.view { display: none; }
.view.active { display: block; }

.toolbar {
  display: flex;
  align-items: center;
  gap: var(--toolbar-gap);
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.icon-btn {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  border: 1px solid var(--gray-250);
  background: var(--white);
  cursor: pointer;
}
.icon-btn .ico { width: 16px; height: 16px; }
.icon-btn:hover { background: var(--gray-100); }
.toolbar .spacer { flex: 1; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.toolbar .actions { margin-left: auto; }

/* ---------- Page head ---------- */
/* Row 1, same on every tab: title · subtitle · actions (left, after the subtitle). Fixed
   min-height so the band is the same height whether or not a tab has actions/a subtitle. */
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 0 0 16px; min-height: 40px; }
.page-head-text { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.page-title { margin: 0; font-size: 20px; font-weight: 600; color: var(--gray-900); }
.page-sub { font-size: 13px; color: var(--gray-500); }

/* Sticky band: title row, then a period/help row, on every tab (same two rows even when a
   tab has no period — see PeriodBar.renderTail). */
.page-band {
  position: sticky;
  top: var(--topbar-h, 117px);
  z-index: 40;
  margin: 0 -24px 16px;
  padding: 12px 24px 10px;
  background: var(--white);
  border-bottom: 1px solid var(--gray-250);
}
.page-band .page-head { margin: 0; }
/* Row 2, fixed height regardless of content: the full period nav, or just the help link. */
.page-band .toolbar { margin: 10px 0 0; min-height: 32px; }

/* ---------- Tables ---------- */
.table-wrap {
  background: var(--white);
  border-radius: 8px;
  border: 1px solid var(--gray-250);
  overflow: auto;
  max-height: calc(100vh - var(--wrap-top, 260px) - 24px);
  min-height: 320px;
  position: relative;
}
table.grid {
  border-collapse: separate;
  border-spacing: 0;
  table-layout: auto;
  font-family: inherit;
  font-size: 14px;
  background: #fff;
  width: 100%;
}
table.grid th, table.grid td {
  border-right: var(--grid-line);
  border-bottom: var(--grid-line);
  border-top: none;
  border-left: none;
  padding: 6px 8px;
  text-align: center;
  vertical-align: middle;
  white-space: nowrap;
}
table.grid thead tr:nth-child(1) th { border-top: var(--grid-line-outer); }
table.grid td.sticky, table.grid th.sticky { border-left: var(--grid-line-outer); }
table.grid thead th {
  position: sticky;
  top: 0;
  z-index: 7;
  font-weight: 500;
  font-size: 13px;
  color: var(--gray-900);
  line-height: 1.2;
  white-space: normal;
  text-align: left;
  vertical-align: bottom;
}
table.grid thead tr:nth-child(2) th { top: var(--head2-top, 34px); z-index: 8; }
table.grid thead tr:nth-child(3) th { top: var(--head3-top, 62px); z-index: 7; }
table.grid thead tr:nth-child(1) th { z-index: 9; }
table.grid thead tr th.sticky, table.grid thead tr th.sticky-2 { z-index: 10; }
table.grid td.sticky, table.grid th.sticky,
table.grid td.sticky-2, table.grid th.sticky-2 {
  position: sticky;
  z-index: 6;
  box-shadow: 3px 0 8px -5px rgba(0, 0, 0, 0.35);
}
table.grid td.sticky, table.grid th.sticky { left: 0; }
table.grid td.sticky-2, table.grid th.sticky-2 { left: var(--sticky2-left, 88px); }
table.grid tbody tr.totals-row td {
  position: sticky;
  top: var(--totals-top, 0px);
  z-index: 8;
}
table.grid tbody tr.totals-row td.sticky,
table.grid tbody tr.totals-row td.sticky-2 { z-index: 9; }
table.grid .col-luna { width: 1%; min-width: 0; max-width: 48px; }
table.grid tbody td.col-luna { vertical-align: top; color: var(--gray-500); font-weight: 400; }
/* month/range label: vertical, large, like a rotated Excel header — keeps the narrow column narrow */
table.grid .luna-v {
  display: inline-block;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  white-space: nowrap;
  line-height: 1.1;
  font-size: 24px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--gray-700);
}
table.grid .col-day { width: 1%; min-width: 44px; }
table.grid .col-age { width: 1%; min-width: 52px; }
table.grid .col-m { width: 66px; min-width: 66px; }
table.grid .col-htotal { width: 74px; min-width: 74px; }
table.grid .col-sum { width: 76px; min-width: 76px; }
table.grid .col-pct { width: 62px; min-width: 62px; }
th.has-hint { cursor: help; }
th.has-hint > span { text-decoration: underline dotted; text-underline-offset: 3px; }

table.grid th .ro, table.grid th .ru { display: block; }
:root[lang="ro"] table.grid th:has(.ro) .ru { display: none; }
:root:not([lang="ro"]) table.grid th:has(.ru) .ro { display: none; }
table.grid .group-sub { display: block; font-weight: 700; font-size: 14px; }
table.grid .hl { font-weight: 700; }

/* Category cells. c-base = plain white (left columns). c-group = neutral group header
   ("Цех N" row, and the group header over a right-hand sums section). c-{gray,green,apricot,red,blue}
   carry --cat-head/--cat-z1/--cat-z2/--cat-tot/--cat-text/--cat-bar, values from the design artboard;
   raw hex here (no token match) comes straight from that artboard. */
table.grid .c-base { background: var(--white); }
table.grid th.c-group { background: var(--gray-100); color: var(--gray-700); font-size: 14px; font-weight: 700; }
table.grid .c-gray    { --cat-head: var(--gray-100);     --cat-z1: var(--white); --cat-z2: #FAFAFA; --cat-tot: #ECECEC; --cat-text: var(--gray-700);     --cat-bar: var(--gray-400); }
table.grid .c-green   { --cat-head: var(--green-50);     --cat-z1: #F7FCF9;      --cat-z2: #F1FAF5; --cat-tot: #DCF0E6; --cat-text: var(--green-700);    --cat-bar: var(--green-600); }
table.grid .c-apricot { --cat-head: var(--apricot-50);   --cat-z1: #FFFCF4;      --cat-z2: #FFF8EA; --cat-tot: #FDEFC9; --cat-text: var(--apricot-700);  --cat-bar: var(--apricot-500); }
table.grid .c-red     { --cat-head: var(--red-50);       --cat-z1: #FFF9F8;      --cat-z2: #FEF4F3; --cat-tot: #FDE3E1; --cat-text: var(--red-700);      --cat-bar: var(--red-600); }
table.grid .c-blue    { --cat-head: var(--blue-sky-100); --cat-z1: #F8FBFF;      --cat-z2: #F2F8FE; --cat-tot: #DCE9FA; --cat-text: var(--blue-sky-700); --cat-bar: var(--blue-sky-600); }
table.grid th.c-gray, table.grid th.c-green, table.grid th.c-apricot, table.grid th.c-red, table.grid th.c-blue {
  background: var(--cat-head);
  color: var(--cat-text);
  box-shadow: inset 0 3px 0 var(--cat-bar);
}
table.grid tbody tr:nth-child(odd) td.c-gray, table.grid tbody tr:nth-child(odd) td.c-green,
table.grid tbody tr:nth-child(odd) td.c-apricot, table.grid tbody tr:nth-child(odd) td.c-red,
table.grid tbody tr:nth-child(odd) td.c-blue { background: var(--cat-z1); }
table.grid tbody tr:nth-child(even) td.c-gray, table.grid tbody tr:nth-child(even) td.c-green,
table.grid tbody tr:nth-child(even) td.c-apricot, table.grid tbody tr:nth-child(even) td.c-red,
table.grid tbody tr:nth-child(even) td.c-blue { background: var(--cat-z2); }
table.grid tbody tr.totals-row td.c-gray, table.grid tbody tr.totals-row td.c-green,
table.grid tbody tr.totals-row td.c-apricot, table.grid tbody tr.totals-row td.c-red,
table.grid tbody tr.totals-row td.c-blue { background: var(--cat-tot); font-weight: 600; }
table.grid tbody tr.totals-row td.c-base { background: var(--gray-200); font-weight: 700; }
table.grid td.col-luna, table.grid th.col-luna,
table.grid td.col-day, table.grid th.col-day,
table.grid td.col-age, table.grid th.col-age { background: var(--white); }

table.grid tbody tr.month-start td { border-top: var(--grid-line-strong); }
table.grid th.hg-end, table.grid td.hg-end { border-right: var(--grid-line-group); }
table.grid tbody tr.today-row td.col-day { box-shadow: inset 0 0 0 2px var(--blue-sky-600); }
table.grid .muted { color: var(--gray-500); }
table.grid td.num { text-align: right; font-variant-numeric: tabular-nums; }
.water-reset { color: var(--red-600); font-weight: 700; }
.water-span { color: var(--apricot-700); font-weight: 700; }

table.grid td:has(> input.cell-input) { padding: 2px 4px; }
table.grid input.cell-input {
  width: 100%; height: 26px; padding: 0 6px; box-sizing: border-box;
  border: 1px solid var(--gray-300); border-radius: 6px; background: var(--white);
  font: inherit; font-weight: 600; color: var(--gray-900); text-align: inherit;
  font-variant-numeric: tabular-nums; outline: none; -moz-appearance: textfield;
}
table.grid input.cell-input:hover { border-color: var(--gray-600); }
table.grid input.cell-input:focus { border-color: var(--blue-sky-600); box-shadow: 0 0 0 2px var(--blue-sky-200); }
table.grid input.cell-input::placeholder { color: var(--gray-400); font-weight: 400; font-size: 12px; }
table.grid input.cell-input:focus::placeholder { color: transparent; }
table.grid input.cell-input.error { border-color: var(--red-600); background: var(--red-100); box-shadow: none; }
table.grid input.cell-input.warn  { border-color: var(--apricot-500); background: var(--apricot-100); box-shadow: none; }
@media (max-width: 900px) { table.grid input.cell-input::placeholder { color: transparent; } }
.field input.error, input.error { background: var(--red-100); box-shadow: inset 0 0 0 2px var(--red-600); }

/* ---------- Deliveries (Приходы) ---------- */
.delivery-sex { margin-bottom: 20px; }
.delivery-summary { display: flex; align-items: center; gap: 10px; margin: 10px 0 18px; font-size: 13px; color: var(--gray-700); }
.delivery-photos-wrap { margin-bottom: 16px; }
.delivery-photos { display: flex; flex-wrap: wrap; gap: 8px; }
.delivery-photos .recog-thumb img { width: 84px; height: 84px; object-fit: cover; border-radius: 8px; border: 1px solid var(--gray-300); display: block; }

.legend {
  margin-top: 12px;
  font-size: 13px;
  color: var(--gray-600);
  display: flex;
  gap: 8px 28px;
  flex-wrap: wrap;
}
.legend b { color: var(--gray-900); font-weight: 600; }

/* One card rule: same frame for every panel/card look in the app. */
.card, .dash-panel, .hala-filter, .opening-bar, .settings-card, .forms-card {
  background: var(--white);
  border: 1px solid var(--gray-250);
  border-radius: 8px;
  padding: 20px;
  margin-bottom: 16px;
  min-width: 0;
  max-width: 100%;
}
.card-title, .dash-panel h3 { margin: 0 0 16px; font-size: 16px; font-weight: 600; color: var(--gray-900); overflow-wrap: anywhere; }

/* ---------- Hala filter panel ---------- */
/* joins the grid card below it: no bottom radius/margin of its own */
.hala-filter {
  padding: 10px 16px;
  margin-bottom: 0;
  border-radius: 8px 8px 0 0;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}
.hala-filter + .table-wrap { border-top: 0; border-top-left-radius: 0; border-top-right-radius: 0; }
.hf-title { font-size: 14px; font-weight: 600; color: var(--gray-900); }
.hf-item { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; color: var(--gray-900); }
.hf-item input[type="checkbox"] { accent-color: var(--blue-sky-600); width: 16px; height: 16px; }
.hf-toggle.is-all { background: var(--blue-sky-100); color: var(--blue-sky-700); border-color: transparent; }
.hf-hint { margin-left: auto; max-width: 360px; font-size: 12px; color: var(--gray-500); }
@media (max-width: 900px) {
  .hf-hint { margin-left: 0; max-width: 100%; }
}

/* opening balance bar */
.opening-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  overflow-x: auto;
  padding: 16px 20px;
  font-size: 13px;
}
.opening-bar .ob-title { font-weight: 600; color: var(--gray-900); font-size: 14px; }
.opening-bar .ob-field { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; }
.opening-bar .ob-field input {
  width: 90px;
  height: 34px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.opening-bar .ob-field input[type="date"] { width: auto; text-align: left; }
.opening-bar .ob-hint { color: var(--gray-500); font-size: 12px; }
.opening-bar .start-grid thead th { position: static; background: var(--gray-100); color: var(--gray-600); }
.opening-bar .start-grid td { width: 84px; min-width: 84px; }
.opening-bar .start-grid input.cell-input { height: 32px; }
.opening-bar .start-grid input.cell-input:disabled { color: var(--gray-500); }


/* ---------- Dashboard ---------- */
.dash-head { display: flex; align-items: baseline; gap: 10px; margin: 0 0 12px; }
.dash-head .card-title { margin: 0; }
/* Period switcher */
.period-nav { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.period-label {
  font-size: 13px;
  color: var(--gray-500);
  margin-right: 2px;
}
/* 28px + .seg's 2px top/bottom padding = 32px pill, matching the row's date inputs/apply/month-nav */
.period-nav .period-btn { height: 28px; padding: 0 16px; }
.period-nav .period-btn.active { background: var(--gray-900); color: #fff; }
.period-custom { display: inline-flex; align-items: center; gap: 8px; margin-left: 8px; flex-wrap: wrap; max-width: 100%; }
.pb-month-nav { display: inline-flex; align-items: center; gap: 6px; }
.pb-month-label {
  font-weight: 500;
  font-size: 14px;
  min-width: 126px;
  text-align: center;
  text-transform: capitalize;
  user-select: none;
}
.period-custom input[type="date"] { width: auto; height: 32px; }
.period-dash { color: var(--gray-400); font-size: 14px; }
.period-custom #dashApply,
.period-custom .period-apply,
.period-apply { height: 32px; }
.help-link { background: none; border: 0; padding: 0; font: inherit; font-weight: 500; font-size: 13px; color: var(--blue-sky-600); text-decoration: none; cursor: pointer; }
.help-link:hover { text-decoration: underline; }
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(185px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.kpi-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--white);
  border: 1px solid var(--gray-250);
  border-radius: 8px;
  padding: 14px 16px;
  min-width: 0;
}
.kpi-ico { display: none; }
.kpi-body { min-width: 0; flex: 1; }
.kpi-value { font-size: 30px; font-weight: 600; line-height: 1.1; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.kpi-label { font-size: 13px; color: var(--gray-500); font-weight: 400; margin-top: 2px; }
.kpi-sub { font-size: 12.5px; color: var(--gray-500); margin-top: 2px; }
.kpi-grid-sm .kpi-value { font-size: 19px; }
.kpi-card.bad .kpi-value { color: var(--red-700); }
.kpi-card.warn .kpi-value { color: var(--apricot-700); }
.dash-row {
  display: grid;
  grid-template-columns: 1.25fr 1fr;
  gap: 16px;
  align-items: start;
  min-width: 0;
}
.dash-row > * { min-width: 0; }
.hala-bar {
  display: flex;
  height: 12px;
  border-radius: 6px;
  overflow: hidden;
  background: var(--gray-100);
  margin-bottom: 6px;
}
.hala-bar i { height: 100%; display: block; }
.hala-bar .h-inc { background: var(--blue-sky-600); }
.hala-bar .h-floor { background: var(--apricot-400); }
.hala-bar .h-nonconf { background: var(--red-600); }
.dash-empty {
  background: var(--white);
  border: 1px solid var(--gray-250);
  border-radius: 8px;
  padding: 60px 20px;
  text-align: center;
  color: var(--gray-500);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.dash-empty-text { font-size: 15px; }

/* dashboard v2 */
.panel-head {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.panel-head h3 { margin: 0; }
.panel-hint { margin-left: auto; font-size: 12px; color: var(--blue-sky-600); font-weight: 500; }
.kpi-value-row { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.kpi-delta { white-space: nowrap; flex: 0 0 auto; }

.records { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 14px; }
.record { border-radius: 8px; padding: 12px 14px; background: var(--white); border: 1px solid var(--gray-250); }
.record.weak { background: var(--white); border-color: var(--gray-250); }
.record-label { font-size: 13px; color: var(--gray-500); font-weight: 400; }
.record-value { font-size: 24px; font-weight: 600; font-variant-numeric: tabular-nums; margin: 2px 0; }
.record-date { font-size: 13px; color: var(--gray-700); }

.hala-share { font-size: 13px; font-weight: 500; color: var(--gray-700); }

/* Structure card: slim stacked bar + name/value/% rows + a total line (replaces the old donut). */
.dash-struct-bar { margin-bottom: 16px; }
.dash-struct-rows { display: flex; flex-direction: column; gap: 2px; }
.dash-struct-row { display: flex; align-items: center; gap: 8px; font-size: 14px; padding: 6px 0; }
.dash-struct-row .name { color: var(--gray-700); flex: 1; min-width: 0; overflow-wrap: anywhere; }
.dash-struct-row .val { font-weight: 600; font-variant-numeric: tabular-nums; }
.dash-struct-row .pct { color: var(--gray-500); font-variant-numeric: tabular-nums; width: 62px; text-align: right; }
.dash-struct-total {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-top: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--gray-250);
  font-size: 13px;
  color: var(--gray-500);
}
.dash-struct-total b { font-size: 17px; font-weight: 600; font-variant-numeric: tabular-nums; color: var(--gray-900); }

/* Hala table: sortable-looking summary with an inline share bar (replaces the hala-cards grid). */
.hala-table th.num, .hala-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.hala-table td.bar-cell { min-width: 140px; }
.hala-table td.bar-cell .hala-bar { margin-bottom: 0; }
.hala-table tbody tr.clickable { cursor: pointer; }
.hala-table tbody tr.clickable:hover { background: var(--gray-100); }
.hala-table tr.total-row td { font-weight: 600; border-top: 1px solid var(--gray-300); }

/* Phone (390px): each row as a 3-line grid instead of a scrolling table (owner: no sideways
   scroll). Scoped to screen so the headWithPrint print copy of this same table stays untouched. */
@media screen and (max-width: 640px) {
  #view-dashboard .hala-table { display: block; width: 100%; }
  #view-dashboard .hala-table thead { display: none; }
  #view-dashboard .hala-table tbody { display: block; width: 100%; }
  #view-dashboard .hala-table tr {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-areas: "hala hala total total" "s1 s2 s3 s4" "bar bar bar bar";
    column-gap: 8px;
    row-gap: 6px;
    padding: 12px 0;
    border-bottom: 1px solid #EFEFEF;
  }
  #view-dashboard .hala-table tr.total-row { border-bottom: 0; border-top: 1px solid var(--gray-300); }
  #view-dashboard .hala-table td { display: block; padding: 0; border: 0; font-size: 13px; }
  #view-dashboard .hala-table td:nth-child(1) { grid-area: hala; align-self: center; font-weight: 500; font-size: 15px; }
  #view-dashboard .hala-table td:nth-child(2) { grid-area: total; align-self: center; text-align: right; font-weight: 600; font-size: 17px; }
  #view-dashboard .hala-table td:nth-child(3) { grid-area: s1; }
  #view-dashboard .hala-table td:nth-child(4) { grid-area: s2; }
  #view-dashboard .hala-table td:nth-child(5) { grid-area: s3; }
  #view-dashboard .hala-table td:nth-child(6) { grid-area: s4; }
  #view-dashboard .hala-table td:nth-child(3), #view-dashboard .hala-table td:nth-child(4),
  #view-dashboard .hala-table td:nth-child(5), #view-dashboard .hala-table td:nth-child(6) { text-align: left; }
  #view-dashboard .hala-table td[data-label]::before {
    content: attr(data-label);
    display: block;
    font-size: 11px;
    font-weight: 400;
    color: var(--gray-500);
    margin-bottom: 2px;
  }
  #view-dashboard .hala-table td.bar-cell { grid-area: bar; min-width: 0; }
  #view-dashboard .hala-table td.bar-cell:empty { display: none; }
}

/* Section shells: the tab is split into Eggs / Birds / Feed & water / Warehouse,
   each with a colour mark, heading, one-line description and a link to its tab. */
.dash-section { margin-top: 40px; padding-top: 24px; border-top: 1px solid var(--gray-250); }
.dash-section:first-child { margin-top: 0; padding-top: 0; border-top: 0; }
.dash-sec-head { display: flex; align-items: stretch; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.dash-sec-mark { width: 4px; border-radius: 2px; flex: 0 0 auto; }
.dash-sec-mark-eggs { background: var(--blue-sky-600); }
.dash-sec-mark-birds { background: var(--red-600); }
.dash-sec-mark-feed { background: var(--apricot-600); }
.dash-sec-mark-warehouse { background: var(--green-700); }
.dash-sec-text { flex: 1; min-width: 200px; display: flex; flex-direction: column; justify-content: center; gap: 2px; }
.dash-sec-text h2 { margin: 0; font-size: 16px; font-weight: 600; color: var(--gray-900); }
.dash-sec-desc { font-size: 13px; color: var(--gray-500); }
.dash-sec-head .link-arrow { align-self: center; margin-left: auto; }
.dash-empty-sm { padding: 24px; font-size: 13px; }

/* print buttons */
.panel-head-spacer { flex: 1; }
.panel-print {
  height: 32px;
  padding: 0 12px;
  border: 1px solid var(--gray-250);
  background: #fff;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--gray-700);
  white-space: nowrap;
}
.panel-print:hover { background: var(--gray-100); }
.panel-print span { margin-left: 2px; }

@page chart { size: A4 landscape; margin: 8mm; }
.print-chart-page { page: chart; }
.print-chart-page .print-chart-box { margin-top: 14px; }
@media print {
  #print-root, #print-root * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
  .print-chart-page .cal-cell { min-height: 52px; }
}

@media (max-width: 1100px) {
  .dash-row { grid-template-columns: 1fr; }
}
.chart-legend {
  display: flex;
  gap: 16px;
  font-size: 13.5px;
  color: var(--gray-700);
  margin-top: 6px;
  flex-wrap: wrap;
}
.chart-legend .dot, .dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  margin-right: 5px;
  vertical-align: middle;
}
.hala-row { display: flex; align-items: center; gap: 10px; margin-bottom: 9px; }
.hala-row .name { width: 74px; font-weight: 500; font-size: 13px; color: var(--gray-900); }
.hala-row .track {
  flex: 1;
  background: var(--gray-100);
  border-radius: 6px;
  height: 22px;
  overflow: hidden;
  display: flex;
  min-width: 60px;
}
.hala-row .track i { height: 100%; display: block; }
.hala-row .track .hr-hens { background: var(--blue-sky-600); }
.hala-row .track .hr-roosters { background: var(--apricot-500); }
.hala-row .value { width: 130px; text-align: right; font-variant-numeric: tabular-nums; }
.hala-row .value b { display: block; font-size: 19px; font-weight: 600; }
.hala-row .value small { display: block; font-size: 13px; font-weight: 600; }
.c-hens { color: var(--blue-sky-600); }
.c-roosters { color: var(--apricot-700); }
.hala-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-left: auto; }
.hala-detail .kpi-grid { margin-top: 14px; }
.chart-empty { grid-column: 1 / -1; color: var(--gray-500); font-size: 13px; padding: 24px 0; text-align: center; }

/* Calendar cards: one continuous Mon..Sun grid for the whole period, every value written on the
   cell, no tooltips (owner decision 2026-09-14). Tone classes colour a cell by deviation from
   average (g1/g2 above, b1/b2 below) or flag an alarm (mortality spike / feed diff). */
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 3px; }
.cal-wh { font-size: 14px; font-weight: 600; color: var(--gray-500); text-align: center; padding-bottom: 4px; }
.cal-cell {
  position: relative;
  min-height: 60px;
  padding: 16px 1px 4px;
  border-radius: 6px;
  border: 1px solid var(--gray-250);
  background: var(--white);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 1px;
  min-width: 0;
}
.cal-cell.g1 { background: var(--green-100); border-color: var(--green-100); }
.cal-cell.g2 { background: var(--green-200); border-color: var(--green-200); }
.cal-cell.b1 { background: var(--red-100); border-color: var(--red-100); }
.cal-cell.b2 { background: var(--red-200); border-color: var(--red-200); }
.cal-cell.alarm { background: var(--red-100); border-color: var(--red-600); }
.cal-n { position: absolute; top: 3px; left: 5px; font-size: 11px; line-height: 1; color: var(--gray-500); }
.cal-v { font-size: 16px; font-weight: 700; line-height: 1.15; font-variant-numeric: tabular-nums; }
.cal-v.sm { font-size: 14px; }
@media (max-width: 600px) { .cal-v.xs { font-size: 12px; } }
.cal-s { font-size: 12px; font-weight: 600; line-height: 1.2; min-height: 14px; color: var(--gray-500); font-variant-numeric: tabular-nums; }
.cal-s.good { color: var(--green-700); }
.cal-s.bad { color: var(--red-700); }
.cal-s.apricot { color: var(--apricot-700); }
.cal-cap { grid-column: 1 / -1; font-size: 12px; font-weight: 600; color: var(--gray-500); margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--gray-250); }
.cal-avg { font-size: 15px; font-weight: 700; text-align: center; padding: 4px 0; font-variant-numeric: tabular-nums; }
.cal-avg.best { color: var(--green-700); }
.cal-avg.worst { color: var(--red-700); }

/* Week list: one row per Mon..Sun bucket (dash.byWeek). */
.wk-list { display: flex; flex-direction: column; }
.wk-row { display: grid; grid-template-columns: 84px minmax(0, 1fr) 64px; gap: 10px; align-items: center; padding: 7px 0; border-bottom: 1px solid var(--gray-100); }
.wk-row:last-child { border-bottom: 0; }
.wk-l { font-size: 13px; color: var(--gray-700); min-width: 0; }
.wk-l small { display: block; font-size: 11.5px; color: var(--gray-500); font-weight: 400; }
.wk-bar { height: 10px; border-radius: 4px; background: var(--gray-100); overflow: hidden; }
.wk-bar i { display: block; height: 100%; background: var(--blue-sky-600); border-radius: 4px; }
.wk-v { font-size: 16px; font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
.wk-v small { display: block; font-size: 12px; font-weight: 600; }
.wk-v small.good { color: var(--green-700); }
.wk-v small.bad { color: var(--red-700); }

/* Weekday bars: pure CSS columns, no SVG (dash.weekday). */
.wd-bars { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); align-items: end; gap: 6px; height: 176px; }
.wd-col { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 4px; min-width: 0; }
.wd-v { font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; }
.wd-v.best { color: var(--green-700); }
.wd-v.worst { color: var(--red-700); }
.wd-bar { width: 70%; min-height: 3px; border-radius: 3px 3px 0 0; background: var(--blue-sky-300); }
.wd-bar.best { background: var(--green-500); }
.wd-bar.worst { background: var(--red-400); }
.wd-l { font-size: 15px; font-weight: 600; color: var(--gray-700); }

@media (max-width: 900px) {
  .dash-section .dash-panel { padding: 14px; }
  .wk-row { grid-template-columns: 76px minmax(0, 1fr) 60px; gap: 8px; }
  .hala-row .value { width: 90px; }
}

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 18px;
}
.modal {
  background: var(--white);
  border-radius: 16px;
  box-shadow: var(--drop-shadow-400);
  width: 100%;
  max-width: 620px;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal.modal-wide { max-width: 980px; }
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--gray-250);
  font-weight: 600;
  font-size: 16px;
}
.modal-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  border-radius: 8px;
  font-size: 20px;
  cursor: pointer;
  color: var(--gray-500);
  line-height: 1;
}
.modal-close:hover { background: var(--gray-100); }
.modal-body { padding: 16px 18px; overflow: auto; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 12px 18px;
  border-top: 1px solid var(--gray-250);
  background: var(--gray-100);
}
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
.checkbox-row { display: flex; align-items: center; gap: 8px; margin: 6px 0; }
.checkbox-row input { width: 17px; height: 17px; }
.radio-row { display: flex; gap: 14px; flex-wrap: wrap; }
.radio-row label { display: flex; align-items: center; gap: 6px; font-weight: 500; font-size: 14px; }
.section-title { font-weight: 600; font-size: 16px; margin: 16px 0 0; padding-top: 16px; border-top: 1px solid var(--gray-250); color: var(--gray-900); }
.section-title:first-child { margin-top: 0; padding-top: 0; border-top: none; }

/* Upload */
.dropzone {
  border: 2px dashed var(--gray-300);
  border-radius: 8px;
  padding: 26px 16px;
  text-align: center;
  color: var(--gray-500);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.dropzone:hover, .dropzone.dragover { border-color: var(--blue-sky-600); background: var(--blue-sky-100); color: var(--blue-sky-600); }
.thumbs { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.thumb { position: relative; width: 92px; height: 92px; border-radius: 8px; overflow: hidden; border: 1px solid var(--gray-300); }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb .remove {
  position: absolute; top: 2px; right: 2px;
  background: rgba(0, 0, 0, 0.6); color: #fff;
  border: none; border-radius: 50%; width: 20px; height: 20px; cursor: pointer; font-size: 12px; line-height: 1;
}
.recog-card {
  border: 1px solid var(--gray-250);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 12px;
}
.recog-card .head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.recog-card .head img { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; border: 1px solid var(--gray-300); }
.recog-fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px; }
.recog-fields .field label { font-size: 11px; }
.recog-fields .field input, .recog-fields .field select { height: 32px; padding: 0 8px; font-size: 13px; }
.recog-fields.recog-fields-div { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--gray-250); }
.recog-target { background: var(--blue-sky-100); border: 1px solid var(--blue-sky-150); border-radius: 8px; padding: 8px 10px; font-size: 13px; margin-bottom: 10px; }
/* the blank's date against today: green today, apricot late, red future/unknown */
.recog-date { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.recog-date .status-pill { font-size: 14px; font-weight: 600; padding: 4px 10px; white-space: normal; }
.warn-note { background: var(--apricot-100); color: var(--apricot-700); border-radius: 8px; padding: 6px 10px; font-size: 13px; margin-bottom: 8px; }
.recog-card.is-saved { opacity: .75; }
.recog-dates { margin-right: auto; align-self: center; font-size: 13px; color: var(--gray-700); }
.recog-dates.warn { color: var(--apricot-700); font-weight: 600; }

/* Recognition progress */
.progress-wrap { margin: 6px 0 14px; }
.progress-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 14px; font-weight: 600; color: var(--gray-900); margin-bottom: 7px; }
.progress-count { font-weight: 500; color: var(--gray-700); font-variant-numeric: tabular-nums; }
.progress { height: 14px; background: var(--gray-200); border-radius: 999px; overflow: hidden; }
.progress-fill { height: 100%; width: 0%; border-radius: 999px; background: var(--blue-sky-600); transition: width 0.35s ease; }
.progress-hint { font-size: 12.5px; color: var(--gray-500); margin-top: 7px; }
.recog-failed-note {
  background: var(--red-100);
  color: var(--red-700);
  border: 1px solid var(--red-200);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 12px;
}
.recog-card.failed { border-color: var(--red-200); background: var(--red-50); }
.spinner {
  width: 16px; height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Toast */
#toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--gray-900);
  color: #fff;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 14px;
  opacity: 0;
  transition: transform 0.25s, opacity 0.25s;
  z-index: 600;
  pointer-events: none;
  max-width: 90vw;
}
#toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
#toast.error { background: var(--red-600); }

.settings-card + .settings-card { margin-top: 16px; }
.settings-card .row { display: flex; align-items: flex-end; gap: 10px; margin-bottom: 14px; }
.settings-card .row .field { flex: 1; margin: 0; }

/* ---------- Forms tab ---------- */
/* card left, 2-column blank previews right, stacked under the card on the phone */
.forms-layout { display: grid; grid-template-columns: minmax(320px, 520px) 1fr; gap: 16px; align-items: start; }
.forms-previews { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
@media (max-width: 900px) {
  .forms-layout { grid-template-columns: 1fr; }
}
.form-thumb-box { margin: 0; display: flex; flex-direction: column; gap: 6px; }
/* the button IS the clipped A4 box now — aspect-ratio sizes it, overflow hidden clips the
   unscaled 190mm x 277mm content a CSS transform never shrinks the layout box of. */
.form-thumb-box button {
  display: block;
  width: 100%;
  aspect-ratio: 190 / 277;
  overflow: hidden;
  padding: 0;
  border: 1px solid var(--gray-250);
  border-radius: 8px;
  background: var(--white);
  cursor: zoom-in;
}
.form-thumb-box button:hover { border-color: var(--gray-600); }
.form-thumb { width: 190mm; height: 277mm; transform-origin: 0 0; transform: scale(var(--k, .4)); pointer-events: none; }
.form-thumb-cap { margin: 0; font-size: 14px; font-weight: 600; color: var(--gray-900); text-align: left; }
.form-viewer { overflow: auto; max-height: 75vh; }
.form-viewer-page { width: calc(190mm * var(--k)); height: calc(277mm * var(--k)); margin: 0 auto; }
.forms-date { max-width: 220px; margin-bottom: 6px; }
.hala-picker { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.hala-pick {
  height: 36px;
  border: 1px solid transparent;
  background: var(--gray-100);
  color: var(--gray-900);
  border-radius: 9999px;
  padding: 0 16px;
  cursor: pointer;
  font-weight: 500;
}
.hala-pick:hover { background: var(--gray-200); }
.hala-pick.active { background: var(--blue-sky-100); border-color: var(--blue-sky-600); color: var(--blue-sky-700); }

/* ---------- Photo lightbox (upload review) ---------- */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: rgba(0, 0, 0, 0.86);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  cursor: zoom-out;
}
.lightbox img {
  max-width: 96vw;
  max-height: 88vh;
  object-fit: contain;
  border-radius: 6px;
  box-shadow: 0 10px 50px rgba(0, 0, 0, 0.6);
  background: #fff;
  cursor: default;
}
.lightbox-close {
  position: fixed;
  top: 18px;
  right: 22px;
  border: none;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  font-size: 28px;
  line-height: 1;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  cursor: pointer;
}
.lightbox-close:hover { background: rgba(255, 255, 255, 0.34); }
.lightbox-caption {
  position: fixed;
  bottom: 16px;
  left: 0;
  right: 0;
  text-align: center;
  color: #fff;
  font-size: 13px;
  opacity: 0.85;
  padding: 0 20px;
}
.recog-thumb { position: relative; flex: 0 0 auto; line-height: 0; }
.recog-thumb .thumb-zoom {
  position: absolute;
  left: 3px;
  right: 3px;
  bottom: 3px;
  border: none;
  background: rgba(0, 0, 0, 0.62);
  color: #fff;
  border-radius: 6px;
  padding: 3px 4px;
  font-size: 10px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.recog-thumb .thumb-zoom:hover { background: rgba(0, 0, 0, 0.85); }

/* ---------- Print ---------- */
#print-root { display: none; }

@media print {
  body.printing > *:not(#print-root) { display: none !important; }
  body.printing #print-root { display: block !important; }

  @page { size: A4 portrait; margin: 10mm; }
  @page report { size: A4 landscape; margin: 8mm; }

  /* The sheet takes the printable width the browser gives: Chrome honours the 10 mm margins
     (190 mm), Safari on iPhone keeps its own wider margins and ignores @page — a fixed 190 mm
     sheet was cut on the right and spilled onto a second page there. The body's screen
     overflow clip must not apply to paper either. */
  html, body { overflow: visible !important; background: #fff; }
  .print-page {
    width: auto;
    max-width: 190mm;
    height: auto;
    box-sizing: border-box;
    page-break-after: always;
    page-break-inside: avoid;
  }
  .print-page:last-child { page-break-after: auto; }
  .print-page.print-report {
    page: report;
    max-width: none;
  }
  .print-page.print-chart-page {
    page: chart;
    max-width: 281mm;
    page-break-after: auto;
  }
}

.print-page { font-family: var(--font); color: #000; }
.print-head { text-align: center; margin-bottom: 8px; }
.print-head .farm { font-size: 14px; font-weight: 600; }
.print-head h1 { font-size: 20px; margin: 6px 0 2px; }
.print-head .sub { font-size: 13px; color: #444; }
.print-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 10px;
  font-size: 14px;
  font-weight: 600;
  margin: 8px 0;
  border: 1px solid #000;
  border-radius: 6px;
  padding: 8px 12px;
}
.print-meta .date-box {
  display: inline-block;
  width: 34px;
  height: 26px;
  border: 1px dashed #999;
  border-radius: 4px;
  background: #fafafa;
  vertical-align: middle;
}
.print-meta .date-box.y { width: 60px; }
.print-table { width: 100%; border-collapse: collapse; margin-top: 6px; table-layout: fixed; }
.print-table th, .print-table td {
  border: 1px solid #000;
  padding: 7px 8px;
  font-size: 13px;
  text-align: left;
  vertical-align: middle;
}
.print-table th { background: #f0f0f0; text-align: center; font-weight: 700; }
.print-table td.value-cell { width: 200px; height: 60px; padding: 4px; text-align: center; }
.print-table td.value-cell .cell-box {
  display: block;
  position: relative;
  height: 50px;
  border: 1px dashed #999;
  border-radius: 4px;
  background: #fafafa;
}
.print-table td.value-cell .unit {
  position: absolute;
  right: 4px;
  bottom: 2px;
  font-size: 9px;
  font-weight: 400;
  color: #888;
  line-height: 1;
}
.print-table td.value-cell .cell-box { box-sizing: border-box; overflow: hidden; }
.print-table.initial th, .print-table.initial td { padding: 4px 3px; font-size: 10px; }
.print-table.initial:not(.opening) th:first-child { width: 36px; }
.print-table.opening th, .print-table.opening td { width: 50%; font-size: 11px; padding: 4px 6px; }
.print-table.opening td.value-cell { height: 54px; }
.print-table.opening td.value-cell .cell-box { height: 44px; }
.print-table.initial td.value-cell { width: auto; height: 56px; }
.print-table.initial td.value-cell .cell-box { height: 46px; }
.print-table.initial td.value-cell .unit { font-size: 8px; right: 3px; }
.print-table td.plan-cell { background: #f6f6f6; }
.print-table th, .print-table td { word-break: break-word; }
.print-table td.num { width: 40px; text-align: center; font-weight: 700; }
.print-note { font-size: 11px; color: #333; margin-top: 6px; }
.print-sign { margin-top: 20px; font-size: 12px; display: flex; justify-content: space-between; }
.print-sign .line { border-bottom: 1px solid #000; width: 220px; display: inline-block; }
.print-report h2 { font-size: 15px; margin: 16px 0 6px; }
.print-report table { width: 100%; border-collapse: collapse; font-size: 8px; }
.print-report th, .print-report td { border: 1px solid #666; padding: 2px 3px; text-align: center; white-space: nowrap; }
.print-report th { background: #eee; white-space: normal; }

@media (max-width: 900px) {
  main { padding: 0 16px 16px; }
  .topbar-row { padding: 0 16px; }
  .tabs { display: none; }
  .topbar-right { margin-left: auto; }
  .user-label { display: none; }
  .lang-seg, #logoutBtn { display: none; }
  .mobile-menu-btn { display: inline-flex; }
  .mobile-menu.open {
    display: block;
    position: fixed;
    top: calc(var(--topbar-h, 56px) + 6px);
    right: 8px;
    z-index: 80;
    width: min(300px, calc(100vw - 16px));
    max-height: calc(100vh - var(--topbar-h, 56px) - 20px);
    overflow-y: auto;
    background: #fff;
    border: 1px solid var(--gray-250);
    border-radius: 16px;
    box-shadow: var(--drop-shadow-400);
    padding: 8px;
  }
  .mobile-menu-action { display: flex; }
  .page-head { flex-direction: column; align-items: flex-start; }
  .page-band { position: static; margin: 0 -16px 12px; padding: 10px 16px; }
  .seg { overflow-x: auto; }
  .toolbar { gap: 8px; }
  /* two columns, no sideways swipe: nothing on Обзор scrolls sideways on the phone (owner) */
  .dash-section .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .dash-section .kpi-card { padding: 10px 12px; }
  .dash-section .kpi-value { font-size: 19px; }
  .dash-section .kpi-label { font-size: 12px; }
  .dash-section .kpi-sub { font-size: 11.5px; }
  .kpi-grid { grid-template-columns: 1fr; }
  .dash-row, .dash-row-2 { grid-template-columns: 1fr; }
  .records { grid-template-columns: 1fr; }
  .table-wrap { max-height: calc(100vh - var(--topbar-h, 56px) - 20px); max-height: calc(100dvh - var(--topbar-h, 56px) - 20px); }
  .opening-bar { padding: 8px 10px; }
  .opening-bar .ob-field input { width: 72px; }
  .modal { max-height: 94vh; }
  .modal-body { padding: 12px; }
  .form-grid { grid-template-columns: 1fr; }

  /* Mobile tables: pin ONLY the date (data/День) column.
     "Luna/Месяц" (.col-luna/.sticky) scrolls away with the rest. */
  table.grid td.sticky, table.grid th.sticky,
  table.grid td.col-luna, table.grid th.col-luna {
    position: static;
    left: auto;
    box-shadow: none;
  }
  table.grid td.sticky-2, table.grid th.sticky-2,
  table.grid td.col-day, table.grid th.col-day {
    position: sticky;
    left: 0 !important;
    z-index: 6;
    box-shadow: 3px 0 8px -5px rgba(0, 0, 0, 0.35);
  }
  table.grid thead tr th.sticky-2, table.grid thead tr th.col-day { z-index: 10; }
  table.grid tbody tr.totals-row td.sticky-2,
  table.grid tbody tr.totals-row td.col-day { z-index: 9; }
  table.grid .col-luna:not(.col-period) { width: 0; min-width: 0; padding: 0; border: 0; font-size: 0; }
  table.grid .col-luna:not(.col-period) * { display: none; }

  /* week/range rows have a single label cell (.col-period): keep it pinned like the day column */
  table.grid td.col-period, table.grid th.col-period {
    position: sticky;
    left: 0 !important;
    z-index: 6;
    box-shadow: 3px 0 8px -5px rgba(0, 0, 0, 0.35);
  }
  table.grid thead tr th.col-period { z-index: 10; }
}

/* ---------- History ---------- */
.hist-wrap { background: var(--white); border: 1px solid var(--gray-250); border-radius: 8px; max-height: none; overflow: auto; }
.card .hist-wrap { border: 0; border-radius: 0; }
table.hist-table { width: 100%; border-collapse: collapse; font-size: 13px; }
table.hist-table th, table.hist-table td { padding: 8px 10px; border-bottom: 1px solid #EFEFEF; text-align: left; white-space: nowrap; vertical-align: top; }
table.hist-table thead th { position: sticky; top: 0; background: var(--white); color: var(--gray-500); font-weight: 500; font-size: 12px; border-bottom: 1px solid var(--gray-250); z-index: 2; }
table.hist-table tbody tr:hover { background: var(--gray-100); }
table.hist-table td.hist-change { font-weight: 600; }
table.hist-table .hist-old { color: var(--red-700); }
table.hist-table .hist-new { color: var(--green-700); }
.hist-empty { padding: 44px 20px; text-align: center; color: var(--gray-500); font-size: 15px; }

@media (max-width: 600px) {
  .login-card { padding: 24px 18px; }
  .period-nav { gap: 6px; }
  .period-nav .period-btn { padding: 0 12px; font-size: 13px; height: 28px; }
  .period-custom { margin-left: 0; gap: 6px; }
  .period-custom input[type="date"] { padding: 0 8px; font-size: 13px; width: 132px; }
  .btn { padding: 0 12px; font-size: 13px; }
  .icon-btn { width: 30px; height: 30px; }
  .actions { width: 100%; }
  .actions .btn { flex: 1; justify-content: center; }
  .record-value { font-size: 20px; }
}

@media (max-width: 900px) {
  .opening-bar.start-panel { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .opening-bar.start-panel .btn { margin-top: 6px; }
}

@media (max-width: 900px) {
  #view-forms .btn { white-space: normal; max-width: 100%; text-align: left; }
}

/* ---------- Building blocks (simple tabs) ---------- */
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.card-head .card-title { margin: 0; }
.cards-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; margin-bottom: 16px; }
.cards-2 > .card, .cards-2 > .dash-panel { margin-bottom: 0; }
@media (max-width: 900px) {
  .cards-2 { grid-template-columns: 1fr; }
}

.table-plain { width: 100%; border-collapse: collapse; }
.table-plain th { font-size: 12px; font-weight: 500; color: var(--gray-600); text-align: left; padding: 8px 12px 8px 0; border-bottom: 1px solid var(--gray-250); }
.table-plain td { font-size: 14px; padding: 12px 12px 12px 0; border-bottom: 1px solid #EFEFEF; }
.table-plain td.num { text-align: right; font-variant-numeric: tabular-nums; }
/* the card is the frame: a plain table inside it gets no second border */
.table-wrap:has(> .table-plain) { border: 0; border-radius: 0; max-height: none; }

.big-value, .kpi-value.big-value { font-size: 48px; font-weight: 600; line-height: 1.1; }
.muted { font-size: 13px; color: var(--gray-500); }

.link-arrow {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: none;
  background: none;
  padding: 0;
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--blue-sky-600);
  text-decoration: none;
  cursor: pointer;
}
.link-arrow:hover { text-decoration: underline; }

.form-row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.form-row .field { margin-bottom: 0; }

.divider { border: 0; border-top: 1px solid var(--gray-250); margin: 20px 0; }
.divider + .section-title { border-top: 0; padding-top: 0; margin-top: 0; }
.btn-block { width: 100%; margin-top: 16px; }
.link-arrow { white-space: nowrap; }

/* a form bar placed inside a card is part of the card, not a card of its own */
.card .opening-bar { border: 0; padding: 0; margin: 0; background: none; }
.card .opening-bar .ob-field { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }

/* Manual: one column of cards, section titles are plain headings */
#view-manual .section-title { border-top: 0; padding-top: 0; margin: 24px 0 10px; }
.manual-goal { font-size: 14px; color: var(--gray-600); margin: 0 0 8px; }
.manual-card ol { margin: 0; padding-left: 20px; }
.manual-links { display: flex; flex-wrap: wrap; gap: 8px 16px; margin-top: 12px; }
/* tutorial videos are 1280×848: the app frame plus the caption band under it */
.manual-video, .guide-video {
  display: block;
  width: 100%;
  max-width: 640px;
  aspect-ratio: 1280 / 848;
  margin-top: 12px;
  border: 1px solid var(--gray-250);
  border-radius: 8px;
  background: var(--gray-900);
}
.guide-video { max-width: 100%; }
.manual-card ol.guide-chapters { list-style: none; padding: 0; margin-top: 12px; display: grid; gap: 4px; }
.guide-chapter {
  width: 100%;
  min-height: 40px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  border: 1px solid var(--gray-250);
  border-radius: 8px;
  background: var(--white);
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.guide-chapter:hover { background: var(--gray-100); }
.guide-chapter.active { border-color: var(--blue-sky-600); background: var(--blue-sky-100); }
#view-manual input[type="text"] {
  height: 40px;
  min-width: 260px;
  border: 1px solid var(--gray-250);
  border-radius: 8px;
  padding: 0 12px;
  font: inherit;
}
