/* Светлая тема — единственная: интерфейс не подстраивается под систему.
   color-scheme: light фиксирует и системные элементы (поля ввода, списки,
   полосы прокрутки), иначе при тёмной теме Windows они уезжали бы в тёмное. */
:root {
  color-scheme: light;
  --bg: #eef1f5;
  --surface: #ffffff;
  --surface-2: #f6f8fb;
  --line: #e1e6ec;
  --line-strong: #ccd4de;
  --text: #1a2028;
  --muted: #67707b;
  --accent: #3b6fe0;
  --accent-soft: #e7eefc;
  --good: #1f9d63;
  --good-soft: #e4f4ec;
  --warn: #c9871a;
  --warn-soft: #fbf0dc;
  --crit: #d0473f;
  --crit-soft: #fbe6e4;
  --shadow: 0 1px 2px rgba(20,30,45,.05), 0 6px 20px rgba(20,30,45,.05);
  --radius: 12px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
/* nowrap: разряды отбиты пробелом, без него «4 320 000» рвётся на две строки. */
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
td.r, th.r { white-space: nowrap; }
.muted { color: var(--muted); }

/* ===================== Боковое меню =====================
   Девять разделов в верхней полосе не помещались и переносились; сбоку они
   стоят столбцом, разбиты на смысловые группы, а рабочая область — шире. */
body.app { display: grid; grid-template-columns: 244px minmax(0, 1fr); min-height: 100vh; }

.side {
  position: sticky; top: 0; align-self: start;
  height: 100vh; overflow-y: auto;
  display: flex; flex-direction: column; gap: 2px;
  background: var(--surface); border-right: 1px solid var(--line);
  padding: 16px 12px 12px;
}
.brand {
  display: flex; align-items: center; gap: 9px;
  font-weight: 680; font-size: 15.5px; letter-spacing: -.01em; color: var(--text);
  padding: 2px 10px 16px;
}
.brand:hover { text-decoration: none; }
.brand .logo { font-size: 19px; line-height: 1; }

.side-nav { display: flex; flex-direction: column; gap: 2px; }
.side-nav a {
  display: flex; align-items: center; gap: 10px;
  color: var(--muted); font-size: 14px; padding: 8px 10px; border-radius: 9px;
}
.side-nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.side-nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.side-nav .ic { width: 19px; height: 19px; flex: none; }
.side-nav .grp {
  font-size: 10.5px; letter-spacing: .08em; text-transform: uppercase;
  color: var(--muted); opacity: .8; padding: 15px 10px 5px;
}

.side-user {
  margin-top: auto; padding: 10px 10px 2px; border-top: 1px solid var(--line);
  display: flex; align-items: center; gap: 10px;
}
.side-user .su-body { min-width: 0; flex: 1; }
.side-user .who { font-weight: 600; font-size: 13.5px; }
.side-user .role { font-size: 12px; color: var(--muted); }
.side-user .logout { font-size: 12.5px; color: var(--muted); white-space: nowrap; }

/* Узкий экран: меню возвращается наверх горизонтальной полосой. */
@media (max-width: 900px) {
  body.app { grid-template-columns: 1fr; }
  .side {
    position: static; height: auto; flex-direction: row; align-items: center;
    gap: 14px; border-right: 0; border-bottom: 1px solid var(--line); padding: 10px 16px;
  }
  .brand { padding: 0; }
  .brand-text { display: none; }
  .side-nav { flex-direction: row; overflow-x: auto; flex: 1; scrollbar-width: none; }
  .side-nav::-webkit-scrollbar { display: none; }
  .side-nav a { white-space: nowrap; }
  .side-nav .grp { display: none; }
  .side-user { margin-top: 0; padding: 0; border-top: 0; }
  .side-user .role { display: none; }
}

/* min-width: 0 — иначе колонка грида не сжимается уже своего содержимого,
   и широкие таблицы (календарь молока) распирают страницу вместо
   прокрутки внутри собственной обёртки. */
/* width + min-width: 0 — грид-элемент с margin:auto иначе не сжимается до
   своей колонки, и содержимое (широкий календарь) распирает страницу. */
main { width: 100%; max-width: 1080px; margin: 22px auto; padding: 0 22px 56px; min-width: 0; }
main.wide { max-width: 2100px; }
main.wide-plan { max-width: 1890px; }
h1 { font-size: 21px; margin: 0 0 16px; letter-spacing: -.01em; }
h2 { font-size: 15px; margin: 0; }

/* Toolbar: период + фильтр по складу */
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.segmented {
  display: inline-flex; background: var(--surface); border: 1px solid var(--line);
  border-radius: 999px; padding: 3px; box-shadow: var(--shadow);
}
.segmented a {
  color: var(--muted); font-size: 13px; padding: 5px 14px; border-radius: 999px;
}
.segmented a:hover { text-decoration: none; color: var(--text); }
.segmented a.active { background: var(--accent); color: #fff; }
.wh-filter { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.wh-filter label { display: flex; align-items: center; gap: 8px; }

/* Молоко сегодня — карточка на дашборде */
.milk-today {
  display: flex; align-items: center; gap: 16px; margin-bottom: 16px;
  background: linear-gradient(180deg, var(--accent-soft), var(--surface) 70%);
  border: 1px solid var(--accent); border-radius: var(--radius);
  padding: 16px 22px; box-shadow: var(--shadow);
}
.milk-today .mt-icon { font-size: 34px; line-height: 1; }
.milk-today .mt-body { flex: 1; }
.milk-today .mt-label { font-size: 15px; font-weight: 640; }
.milk-today .mt-sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.milk-today .mt-value { font-size: 34px; font-weight: 720; letter-spacing: -.02em; color: var(--accent); }
.milk-today .mt-value small { font-size: 17px; font-weight: 600; color: var(--muted); }

/* KPI row */
/* auto-fit + minmax(0,…): колонки сжимаются и переносятся, а не держат
   ширину по содержимому — иначе ряд карточек распирал страницу. */
.kpis {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(min(210px, 100%), 1fr));
  gap: 14px; margin-bottom: 14px;
}
.kpi {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 15px 16px 12px; box-shadow: var(--shadow); position: relative; overflow: hidden;
}
.kpi .label { font-size: 11px; letter-spacing: .07em; text-transform: uppercase; color: var(--muted); }
.kpi .value {
  font-size: 26px; font-weight: 680; letter-spacing: -.02em; margin: 6px 0 2px;
  font-variant-numeric: tabular-nums;
}
.kpi .value small { font-size: 15px; font-weight: 600; color: var(--muted); margin-left: 2px; }
.kpi .sub { font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.kpi .spark { position: absolute; right: 14px; top: 16px; width: 74px; height: 30px; }
.kpi.alert { border-color: var(--warn); background: linear-gradient(180deg, var(--warn-soft), var(--surface) 60%); }
.kpi.alert .value { color: var(--warn); }
.kpi .prod-list { margin-top: 8px; display: flex; flex-direction: column; gap: 6px; }
/* На узком экране строка «название — значение — %» не влезала, и процент
   срезался краем карточки; wrap переносит его вместо обрезки. */
.kpi .prod-list > div { display: flex; align-items: baseline; justify-content: space-between; gap: 4px 10px; flex-wrap: wrap; }
.kpi .prod-list span { font-size: 13px; color: var(--muted); }
.kpi .prod-list b { font-size: 16px; font-weight: 680; white-space: nowrap; }
.kpi.alert.zero { border-color: var(--line); background: var(--surface); }
.kpi.alert.zero .value { color: var(--good); }

/* Chain flow strip */
.chain {
  display: flex; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 4px; margin: 14px 0 22px; overflow-x: auto;
}
.node { flex: 1 1 0; min-width: 138px; padding: 12px 14px; position: relative; }
.node + .node::before {
  content: "→"; position: absolute; left: -9px; top: 50%; transform: translateY(-50%);
  color: var(--line-strong); font-size: 15px;
}
.node .n-label { font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.node .n-val { font-size: 17px; font-weight: 660; margin-top: 3px; letter-spacing: -.01em; }
.node .n-val small { font-size: 12px; font-weight: 600; color: var(--muted); }

/* Panels + tables */
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.panel > header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 13px 16px; border-bottom: 1px solid var(--line);
}
.panel > header .count { font-size: 12px; color: var(--muted); }
.panel.ledger { margin-top: 16px; }

/* Цифры во всех таблицах — моноширинные по разрядам, иначе колонки «пляшут». */
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: 10px 16px; text-align: left; }
th {
  font-size: 11px; letter-spacing: .05em; text-transform: uppercase; color: var(--muted);
  font-weight: 600; border-bottom: 1px solid var(--line);
}
td { border-bottom: 1px solid var(--line); font-size: 14px; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--surface-2); }
td.r, th.r { text-align: right; }
.item-name { font-weight: 560; }
.bar-cell { width: 120px; }

.sbar { position: relative; height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.sbar > span { position: absolute; inset: 0 auto 0 0; border-radius: 3px; background: var(--good); }
.sbar .min-mark { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--muted); opacity: .55; }
tr.row-warn .sbar > span { background: var(--warn); }
tr.row-crit .sbar > span { background: var(--crit); }
/* Цвет полосы по степени выполнения плана: статусные цвета, не серии. */
.sbar.good > span { background: var(--good); }
.sbar.warn > span { background: var(--warn); }
.sbar.crit > span { background: var(--crit); }

/* --- Сводка на дашборде --- */
.attention {
  background: var(--warn-soft); border: 1px solid var(--warn);
  border-radius: var(--radius); padding: 12px 16px 13px; margin-bottom: 16px;
}
.attention .att-title { font-weight: 640; font-size: 13.5px; margin-bottom: 3px; }
.attention ul { margin: 0; padding-left: 19px; }
.attention li { font-size: 13.5px; margin: 3px 0; }
.attention a { color: var(--text); text-decoration: underline; text-decoration-color: var(--line-strong); text-underline-offset: 2px; }

.kpi .sbar { margin: 9px 0 7px; }
.kpi .prod-row { display: flex; flex-direction: column; align-items: stretch; gap: 5px; }
.kpi .pr-head { display: flex; align-items: baseline; justify-content: space-between; gap: 4px 10px; flex-wrap: wrap; }

.milk-graph .bd { padding: 14px 16px 16px; }
.chart-wrap { overflow-x: auto; }
.daybars { display: block; width: 100%; height: auto; min-width: 520px; }
.daybars .track { fill: var(--surface-2); }
.daybars .bar { fill: var(--accent); }
.daybars .tick { font-size: 9px; fill: var(--muted); text-anchor: middle; font-variant-numeric: tabular-nums; }
.daybars .avg { stroke: var(--line-strong); stroke-width: 1.4; stroke-dasharray: 5 5; }

.chip {
  display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 600;
  padding: 2px 9px; border-radius: 999px; white-space: nowrap;
}
.chip::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.chip.ok { color: var(--good); background: var(--good-soft); }
.chip.warn { color: var(--warn); background: var(--warn-soft); }
.chip.crit { color: var(--crit); background: var(--crit-soft); }

.op { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; }
.op .dot { width: 8px; height: 8px; border-radius: 2px; flex: none; }
.op.purchase .dot { background: var(--accent); }
.op.production_out .dot { background: var(--good); }
.op.production_consume .dot { background: var(--warn); }
.op.sale .dot { background: #8a5cd6; }
.op.transfer_in .dot, .op.transfer_out .dot { background: var(--line-strong); }
.op.opening .dot { background: var(--accent); }
.qty.pos { color: var(--good); font-weight: 600; }
.qty.neg { color: var(--crit); font-weight: 600; }
.when { color: var(--muted); font-size: 12.5px; }

/* Forms */
.btn {
  background: var(--accent); color: #fff; border: none; border-radius: 8px;
  padding: 9px 16px; font-size: 14px; cursor: pointer;
}
.btn:hover { opacity: .92; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.danger { background: var(--crit); }
.btn[disabled] { opacity: .5; cursor: default; }

/* План продаж */
.plan-head { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.monthnav {
  display: inline-flex; align-items: center; gap: 2px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 999px; padding: 3px; box-shadow: var(--shadow);
}
.monthnav a {
  display: inline-flex; width: 30px; height: 30px; align-items: center; justify-content: center;
  border-radius: 999px; color: var(--muted); font-size: 20px; line-height: 1;
}
.monthnav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.monthnav .lbl { font-weight: 640; min-width: 140px; text-align: center; font-size: 14px; }

.kpi.kpi-hero .progress {
  margin-top: 8px; height: 8px; border-radius: 4px; background: var(--line); overflow: hidden;
}
.kpi.kpi-hero .progress > span { display: block; height: 100%; border-radius: 4px; transition: width .3s; }

.addbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 16px; margin: 16px 0; box-shadow: var(--shadow);
}

.plan-table td, .plan-table th { padding: 11px 12px; }
/* Названия клиентов длинные: без минимума колонка сжимается и имя рвётся
   на три строки. Отступы выше ужаты, чтобы таблица осталась без скролла. */
.plan-table .item-name { font-size: 14px; min-width: 150px; }
.plan-table input.pin { padding: 8px 10px; font-size: 14px; }
.plan-table th.grp { text-align: center; border-bottom: 0; color: var(--muted);
  font-size: 10.5px; letter-spacing: .06em; padding-bottom: 2px; }
.plan-table thead th { background: var(--surface-2); }
.plan-table tbody tr:hover { background: var(--surface-2); }
.plan-table input.pin {
  text-align: right; background: var(--surface-2); border: 1px solid var(--line);
  padding: 7px 9px;
}
.plan-table input.pin:focus { background: var(--surface); outline: 2px solid var(--accent); outline-offset: 0; }
.plan-table tfoot td { border-top: 2px solid var(--line-strong); background: var(--surface-2); }

.cell-bar { display: flex; align-items: center; gap: 8px; justify-content: flex-end; }
.cell-bar .sbar { width: 56px; flex: none; }

.iconbtn {
  border: 1px solid var(--line); background: var(--surface); color: var(--muted);
  width: 28px; height: 28px; border-radius: 8px; cursor: pointer; font-size: 13px; line-height: 1;
}
.iconbtn:hover { border-color: var(--crit); color: var(--crit); background: var(--crit-soft); }

/* Календарь поступления молока */
table.cal { table-layout: fixed; width: 100%; min-width: 1040px; border-collapse: separate; border-spacing: 0; }
table.cal th {
  background: var(--surface-2); text-align: center; padding: 11px 10px; font-size: 13px;
  color: var(--muted); border-bottom: 1px solid var(--line);
}
table.cal th.we { color: var(--accent); }
table.cal th.wk { width: 150px; }
table.cal td {
  vertical-align: top; height: 156px; padding: 12px 14px; border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line); position: relative;
}
table.cal td:first-child { border-left: 1px solid var(--line); }
table.cal td.out { background: var(--surface-2); }
table.cal td.we { background: rgba(59, 111, 224, 0.05); }
table.cal td.today { box-shadow: inset 0 0 0 2px var(--accent); border-radius: 4px; }
table.cal td.clickable { cursor: pointer; }
table.cal td.clickable:hover { background: var(--accent-soft); }
table.cal td.wk { background: var(--surface-2); text-align: right; vertical-align: middle; }
.cal td.wk b { display: block; font-size: 14px; }
.cal td.wk .muted { font-size: 12px; }

.cal .daynum { font-weight: 700; font-size: 15px; color: var(--muted); text-align: right; }
.cal td.today .daynum { color: var(--accent); }
.cal .mlist { margin-top: 8px; display: flex; flex-direction: column; gap: 5px; }
.cal .mrow {
  display: flex; align-items: center; gap: 8px; font-size: 14.5px;
  background: var(--surface-2); border-radius: 8px; padding: 6px 11px;
}
.cal td.we .mrow { background: var(--surface); }
.cal .fdot { width: 11px; height: 11px; border-radius: 50%; flex: none; }
.cal .mrow .farm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal .mrow .vol { font-weight: 700; white-space: nowrap; font-variant-numeric: tabular-nums; }
.cal .mrow .vol::after { content: " кг"; font-weight: 400; color: var(--muted); }
.cal .xmini {
  border: 0; background: transparent; color: var(--line-strong); cursor: pointer;
  font-size: 11px; padding: 0; line-height: 1; opacity: 0; transition: opacity .12s;
}
.cal .mrow:hover .xmini { opacity: 1; }
.cal .xmini:hover { color: var(--crit); }
.cal .dtot { margin-top: 10px; font-size: 15px; color: var(--text); font-weight: 680; text-align: right; }
.cal .intensity {
  position: absolute; left: 12px; right: 12px; bottom: 8px; height: 5px;
  border-radius: 3px; background: var(--line); overflow: hidden;
}
.cal .intensity > span { display: block; height: 100%; border-radius: 2px; background: var(--accent); }
table.cal tfoot td { background: var(--surface-2); border-top: 2px solid var(--line-strong); padding: 12px; }
.cal tfoot td.wk b { display: inline; }
.cal tfoot td.wk span { margin-left: 8px; color: var(--muted); }

/* Палитра хозяйств (стабильный цвет по id, читается в обеих темах) */
.fdot.c0 { background: #3b6fe0; } .fdot.c1 { background: #1f9d63; }
.fdot.c2 { background: #d9911f; } .fdot.c3 { background: #d0473f; }
.fdot.c4 { background: #8a5cd6; } .fdot.c5 { background: #0f9bb0; }
.fdot.c6 { background: #c2568f; } .fdot.c7 { background: #6d8a2e; }
input, select {
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px;
  font-size: 14px; background: var(--surface); color: var(--text);
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.row-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 12px 0 20px; }
.stack-form {
  /* Две колонки на широком экране, одна на узком: шесть полей в столбик
     растягивали форму вниз узкой лентой на фоне пустого экрана. */
  display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px 16px; max-width: 620px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow);
}
.stack-form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.stack-form input, .stack-form select { font-size: 15px; }
.stack-form .wide { grid-column: 1 / -1; }          /* поле на всю ширину формы */
.stack-form > button { grid-column: 1 / -1; justify-self: start; padding-inline: 22px; }

.banner {
  background: var(--warn-soft); border: 1px solid var(--warn);
  border-radius: var(--radius); padding: 14px 18px; margin-bottom: 16px;
}

/* Login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: 100%; max-width: 340px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 16px; box-shadow: var(--shadow); padding: 28px;
}
.login-card .brand { font-size: 18px; margin-bottom: 4px; }
.login-card .hint { color: var(--muted); font-size: 13px; margin-bottom: 20px; }
.login-card form { display: flex; flex-direction: column; gap: 12px; }
.login-card .err { color: var(--crit); font-size: 13px; }

@media (max-width: 820px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .grid2 { grid-template-columns: 1fr; }
}
@media (max-width: 460px) {
  .kpis { grid-template-columns: 1fr; }
  .kpi .spark { display: none; }
}
