/* Alonzo — тема: боковое меню, карточки, графики. Светлая и тёмная тема (авто по системе или вручную). */
/* Контраст проверен по WCAG AA: обычный текст ≥ 4.5:1, границы полей ≥ 3:1 (светлая и тёмная тема) */
:root {
  color-scheme: light;
  --bg: #f4f6fb; --card: #ffffff; --card-2: #f8f9fc; --text: #161b2e; --muted: #5f6679; --faint: #6b7288;
  --line: #e6e9f1; --line-2: #d8dce7; --field-border: #8c93a8;
  --accent: #4f46e5; --accent-2: #4338ca; --accent-soft: #eef0ff; --accent-text: #3730a3;
  --accent-fill: #4f46e5; --accent-fill-2: #4338ca;   /* заливка кнопок с белым текстом — одинаковая в обеих темах */
  --danger: #c81e1e; --danger-soft: #fdecec; --ok: #137333; --ok-soft: #e7f6ec; --warn: #b45309; --warn-soft: #fdf3e2;
  --violet-soft: #f1eafe; --violet: #7c3aed;
  --input: #ffffff; --side: #111629; --side-text: #aab2cc; --side-hover: rgba(255, 255, 255, .06);
  --side-on: rgba(129, 140, 248, .16); --side-title: #8a93b2;
  --ch1: #6366f1; --ch2: #14b8a6; --ch3: #f59e0b; --ch4: #f43f5e; --ch5: #0ea5e9; --ch6: #a855f7;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .06);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .14);
  --radius: 12px; --side-w: 236px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0e1220; --card: #161b2d; --card-2: #1b2136; --text: #e6e9f4; --muted: #98a0b8; --faint: #8a93ad;
    --line: #262d44; --line-2: #313a55; --field-border: #646e92;
    --accent: #818cf8; --accent-2: #a5b4fc; --accent-soft: #232a4d; --accent-text: #c7cdfc;
    --accent-fill: #4f46e5; --accent-fill-2: #4338ca;
    --danger: #f87171; --danger-soft: #3a1d24; --ok: #4ade80; --ok-soft: #16301f; --warn: #fbbf24; --warn-soft: #36290f;
    --violet-soft: #2c2146; --violet: #c4a5fb;
    --input: #121729; --side: #0a0e1a; --side-text: #9aa3bf; --side-title: #8a93b2;
    --ch1: #818cf8; --ch2: #2dd4bf; --ch3: #fbbf24; --ch4: #fb7185; --ch5: #38bdf8; --ch6: #c084fc;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3); --shadow-lg: 0 12px 32px rgba(0, 0, 0, .5);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0e1220; --card: #161b2d; --card-2: #1b2136; --text: #e6e9f4; --muted: #98a0b8; --faint: #8a93ad;
  --line: #262d44; --line-2: #313a55; --field-border: #646e92;
  --accent: #818cf8; --accent-2: #a5b4fc; --accent-soft: #232a4d; --accent-text: #c7cdfc;
  --accent-fill: #4f46e5; --accent-fill-2: #4338ca;
  --danger: #f87171; --danger-soft: #3a1d24; --ok: #4ade80; --ok-soft: #16301f; --warn: #fbbf24; --warn-soft: #36290f;
  --violet-soft: #2c2146; --violet: #c4a5fb;
  --input: #121729; --side: #0a0e1a; --side-text: #9aa3bf; --side-title: #8a93b2;
  --ch1: #818cf8; --ch2: #2dd4bf; --ch3: #fbbf24; --ch4: #fb7185; --ch5: #38bdf8; --ch6: #c084fc;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3); --shadow-lg: 0 12px 32px rgba(0, 0, 0, .5);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.5 "Segoe UI", "Inter", system-ui, -apple-system, Roboto, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.ico { flex: none; vertical-align: -3px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sidebar :focus-visible { outline-color: #a5b4fc; }
input:focus-visible, select:focus-visible, textarea:focus-visible, main:focus-visible { outline: none; }
.skip-link { position: absolute; left: 12px; top: -60px; z-index: 100; background: var(--accent-fill); color: #fff;
  padding: 8px 14px; border-radius: 8px; }
.skip-link:focus { top: 12px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- каркас: боковое меню + содержимое ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar { width: var(--side-w); background: var(--side); color: var(--side-text); position: sticky; top: 0;
  height: 100vh; overflow-y: auto; display: flex; flex-direction: column; flex: none; z-index: 40;
  color-scheme: dark; scrollbar-width: thin; scrollbar-color: #2a3150 transparent; }
/* Логотип (и крестик на телефоне) сверху, пользователь с «Тема/Выход» снизу — на месте; ссылки прокручиваются между ними */
.side-head { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; background: var(--side); padding-right: 10px; }
.side-brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; color: #fff; font-weight: 700;
  font-size: 17px; letter-spacing: .2px; }
.side-brand .logo { width: 32px; height: 32px; border-radius: 9px; background: linear-gradient(135deg, #6366f1, #a855f7);
  display: grid; place-items: center; color: #fff; font-size: 15px; }
.side-brand:hover { text-decoration: none; }
.side-group { padding: 6px 10px; }
.side-title { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--side-title);
  padding: 10px 10px 6px; }
.side-link { display: flex; align-items: center; gap: 11px; padding: 8px 10px; border-radius: 8px; color: var(--side-text);
  font-size: 14px; position: relative; }
.side-link:hover { background: var(--side-hover); color: #fff; text-decoration: none; }
.side-link.on { background: var(--side-on); color: #fff; }
.side-link.on::before { content: ""; position: absolute; left: -10px; top: 8px; bottom: 8px; width: 3px; border-radius: 0 3px 3px 0;
  background: #818cf8; }
.side-foot { margin-top: auto; padding: 12px 14px 16px; border-top: 1px solid rgba(255, 255, 255, .06);
  position: sticky; bottom: 0; background: var(--side); }
.side-user { display: flex; align-items: center; gap: 10px; color: #fff; font-size: 13px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: #2a3150; color: #c7cdfc; display: grid;
  place-items: center; font-weight: 600; font-size: 13px; flex: none; }
.side-user small { display: block; color: var(--side-text); font-size: 12px; }
.side-actions { display: flex; gap: 6px; margin-top: 10px; }
.side-actions button { flex: 1; background: var(--side-hover); border: 1px solid rgba(255, 255, 255, .08); color: var(--side-text);
  padding: 6px 8px; font-size: 12px; display: flex; align-items: center; justify-content: center; gap: 6px; }
.side-actions button:hover { color: #fff; border-color: rgba(255, 255, 255, .2); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: none; }
.wrap { width: 100%; max-width: 1320px; margin: 0 auto; padding: 24px 28px 60px; }
.auth-page .wrap { max-width: 420px; }

/* ---------- заголовки и сетки ---------- */
h1 { font-size: 24px; font-weight: 700; margin: 0 0 18px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  letter-spacing: -.2px; }
h1 .actions { margin-left: auto; display: flex; gap: 8px; font-size: 14px; font-weight: normal; flex-wrap: wrap; align-items: center; }
h2 { font-size: 16px; font-weight: 600; margin: 0 0 14px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px;
  margin-bottom: 18px; box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px 16px; }
.grid .wide { grid-column: span 2; }
@media (max-width: 480px) { .grid .wide { grid-column: 1 / -1; } }   /* одна колонка — без лишней узкой */
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.cols-3 { display: grid; grid-template-columns: 2fr 1fr; gap: 18px; }
.cols > .card, .cols-3 > .card { margin-bottom: 0; }
.cols > *, .cols-3 > *, .grid > * { min-width: 0; }   /* широкая таблица прокручивается внутри карточки, а не растягивает страницу */
.cols, .cols-3 { margin-bottom: 18px; }
@media (max-width: 1000px) { .cols, .cols-3 { grid-template-columns: 1fr; } }

/* ---------- формы и кнопки ---------- */
label { display: block; font-size: 12px; font-weight: 500; color: var(--muted); margin-bottom: 5px; }
input, select, textarea { width: 100%; padding: 8px 11px; border: 1px solid var(--field-border); border-radius: 8px;
  background: var(--input); color: var(--text); font: inherit; min-height: 38px; transition: border-color .15s, box-shadow .15s; }
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft); }
input[type=number] { text-align: right; }
input[type=checkbox] { width: auto; min-height: 0; accent-color: var(--accent); }
button, .btn { font: inherit; font-weight: 500; cursor: pointer; border-radius: 8px; padding: 8px 15px; min-height: 38px;
  border: 1px solid var(--line-2); background: var(--card); color: var(--text); display: inline-flex; align-items: center;
  justify-content: center; gap: 7px; white-space: nowrap; transition: background .15s, border-color .15s, color .15s; }
button:hover, .btn:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }
.primary, button.primary { background: var(--accent-fill); border-color: var(--accent-fill); color: #fff !important; }
.primary:hover { background: var(--accent-fill-2); border-color: var(--accent-fill-2); }
.danger { color: var(--danger); }
button.danger:hover, .btn.danger:hover { border-color: var(--danger); background: var(--danger-soft); color: var(--danger); }
.small, button.small, .btn.small { padding: 3px 10px; font-size: 12px; min-height: 28px; border-radius: 7px; }
.link, button.link { background: none; border: none; color: var(--accent); padding: 0; min-height: 0; }
.link.danger { color: var(--danger); }
.muted { color: var(--muted); }
.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.inline { display: inline; }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.hint.ok { color: var(--ok); }

/* ---------- таблицы ---------- */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; }
th { font-size: 12px; font-weight: 600; color: var(--muted); text-align: left; padding: 9px 10px; background: var(--card-2);
  border-bottom: 1px solid var(--line); white-space: nowrap; }
th:first-child { border-top-left-radius: 8px; } th:last-child { border-top-right-radius: 8px; }
td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr { transition: background .1s; }
tbody tr:hover { background: var(--card-2); }
tr.off td { opacity: .55; }
tr.off td:has(button, form, a.btn) { opacity: 1; }   /* кнопки «Изменить»/«Включить» у отключённых — не бледные */
tfoot td { font-weight: 600; border-bottom: none; background: var(--card-2); }

/* ---------- вкладки ---------- */
.tabs { display: inline-flex; gap: 4px; flex-wrap: wrap; margin-bottom: 16px; padding: 4px; background: var(--card);
  border: 1px solid var(--line); border-radius: 10px; }
.tabs a { padding: 6px 14px; border-radius: 7px; color: var(--muted); font-weight: 500; }
.tabs a.on { background: var(--accent-fill); color: #fff; }
.tabs a:hover:not(.on) { background: var(--card-2); color: var(--text); text-decoration: none; }
.seg { display: inline-flex; gap: 2px; padding: 3px; background: var(--card-2); border-radius: 8px; }
.seg button { min-height: 26px; padding: 2px 10px; font-size: 12px; border: none; background: none; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--text); box-shadow: var(--shadow); }

/* ---------- метки и сообщения ---------- */
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 600; padding: 2px 9px;
  border-radius: 20px; background: var(--accent-soft); color: var(--accent-text); white-space: nowrap; }
.badge.new { background: var(--warn-soft); color: var(--warn); }
.badge.done { background: var(--ok-soft); color: var(--ok); }
.badge.archive { background: var(--card-2); color: var(--muted); border: 1px solid var(--line); }
.badge.dealer { background: var(--violet-soft); color: var(--violet); }
.debt { color: var(--danger); font-weight: 600; }
.paid-full { color: var(--ok); }
.flash { padding: 11px 15px; border-radius: 10px; margin-bottom: 16px; border: 1px solid; display: flex; gap: 10px;
  align-items: flex-start; }
.flash.ok { background: var(--ok-soft); border-color: color-mix(in srgb, var(--ok) 35%, transparent); }
.flash.error { background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 35%, transparent); color: var(--danger); }

/* ---------- карточки-итоги ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 16px; margin-bottom: 18px; }
/* 5 карточек на средней ширине: 3 + 2 вместо «4 и одна внизу» */
@media (min-width: 901px) and (max-width: 1420px) {
  .stats:has(> .stat:nth-child(5):last-child) { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .stats:has(> .stat:nth-child(5):last-child) > .stat { grid-column: span 2; }
  .stats:has(> .stat:nth-child(5):last-child) > .stat:nth-child(n+4) { grid-column: span 3; }
}
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px;
  box-shadow: var(--shadow); position: relative; overflow: hidden; }
.stat .muted:first-child { font-size: 13px; }
.stat .v { font-size: 22px; font-weight: 700; margin-top: 6px; letter-spacing: -.3px; line-height: 1.35; }
.stat .v .muted { font-size: 12px; font-weight: 400; letter-spacing: 0; }
.stat-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.stat-ico { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; flex: none; }
.stat-ico.c1 { background: var(--accent-soft); color: var(--accent); }
.stat-ico.c2 { background: var(--ok-soft); color: var(--ok); }
.stat-ico.c3 { background: var(--warn-soft); color: var(--warn); }
.stat-ico.c4 { background: var(--danger-soft); color: var(--danger); }
.stat-ico.c5 { background: var(--violet-soft); color: var(--violet); }
.stat .spark { display: block; width: 100%; height: 34px; margin-top: 10px; }
.spark-cap { font-size: 11px; color: var(--muted); margin-top: 2px; }
.stat .amt { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; font-size: 18px; line-height: 1.45; }
.stat .amt small { font-size: 12px; font-weight: 500; color: var(--muted); white-space: nowrap; }
.amt { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
td .amt { justify-content: flex-end; }
.amt small { font-size: 11px; color: var(--muted); white-space: nowrap; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 8px 20px; }
.kv div:nth-child(odd) { color: var(--muted); }

/* ---------- графики ---------- */
.chart-box { position: relative; padding: 8px 0 24px 58px; }
.chart-plot { position: absolute; left: 58px; right: 4px; top: 8px; bottom: 24px; }
.chart-plot svg { width: 100%; height: 100%; display: block; overflow: visible; }
.chart-plot .gl { stroke: var(--line); stroke-width: 1; }
.chart-plot rect { transition: opacity .15s; }
.chart-plot rect:hover { opacity: .8; }
.chart-y { position: absolute; left: 0; width: 52px; top: 8px; bottom: 24px; }
.chart-x { position: absolute; left: 58px; right: 4px; bottom: 0; height: 20px; }
.chart-y .ya, .chart-x .xa { position: absolute; font-size: 11px; color: var(--muted); white-space: nowrap; line-height: 1; }
.chart-y .ya { right: 0; transform: translateY(-50%); }
.chart-x .xa { bottom: 2px; transform: translateX(-50%); }
.chart-x .xa[hidden] { display: none; }
.chart-empty { color: var(--muted); padding: 40px 0; text-align: center; font-size: 13px; }
.ch-1 { fill: var(--ch1); background: var(--ch1); } .ch-2 { fill: var(--ch2); background: var(--ch2); }
.ch-3 { fill: var(--ch3); background: var(--ch3); } .ch-4 { fill: var(--ch4); background: var(--ch4); }
.ch-5 { fill: var(--ch5); background: var(--ch5); } .ch-6 { fill: var(--ch6); background: var(--ch6); }
.ch-s1 { stroke: var(--ch1); } .ch-s2 { stroke: var(--ch2); } .ch-s3 { stroke: var(--ch3); }
.ch-s4 { stroke: var(--ch4); } .ch-s5 { stroke: var(--ch5); } .ch-s6 { stroke: var(--ch6); }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: 8px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend b { white-space: nowrap; }
.dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex: none; }
.donut { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.donut svg { width: 150px; height: 150px; flex: none; }
.donut .track { stroke: var(--card-2); }
.donut-v { fill: var(--text); font-size: 20px; font-weight: 700; }
.donut-s { fill: var(--muted); font-size: 11px; }
.donut ul { list-style: none; margin: 0; padding: 0; flex: 1; min-width: 160px; }
.donut li { display: grid; grid-template-columns: 14px 1fr auto auto; gap: 8px; align-items: center; padding: 5px 0;
  border-bottom: 1px dashed var(--line); font-size: 13px; }
.donut li:last-child { border-bottom: 0; }
.donut li b { font-weight: 600; } .donut li em { font-style: normal; color: var(--muted); font-size: 12px; min-width: 34px; text-align: right; }
.hbars { display: flex; flex-direction: column; gap: 12px; }
.hbar-top { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; margin-bottom: 5px; }
.hbar-top small { color: var(--muted); white-space: nowrap; }
.hbar-top b { font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }
.hbar-track { height: 8px; border-radius: 6px; background: var(--card-2); overflow: hidden; }
.hbar-fill { height: 100%; border-radius: 6px; }
.hbar-more { font-size: 12px; color: var(--muted); }
.crumb { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; margin-bottom: 6px; }
.presets { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 12px; font-size: 13px; }
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 3px 11px; border-radius: 20px; border: 1px solid var(--line-2);
  color: var(--text); background: var(--card); font-size: 12.5px; }
.chip:hover { text-decoration: none; border-color: var(--accent); }
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
tr.on td { background: var(--accent-soft); }
tr.row-link { cursor: pointer; }
tr.row-link:hover td { background: var(--card-2); }
/* табель и ведомость */
.ts-grid th, .ts-grid td { padding: 4px 2px; text-align: center; }
.ts-grid th small { font-size: 10px; color: var(--muted); font-weight: 400; }
.ts-grid .ts-name { text-align: left; white-space: nowrap; position: sticky; left: 0; background: var(--card); z-index: 1;
  padding-right: 8px; min-width: 110px; }
.ts-grid input { width: 34px; min-height: 30px; padding: 3px 1px; text-align: center; font-size: 13px; }
.ts-grid .ts-sum { font-weight: 600; padding: 4px 6px; white-space: nowrap; }
.ts-grid input.bad { border-color: var(--danger); box-shadow: 0 0 0 2px var(--danger-soft); }
.ts-grid .sun { background: var(--card-2); }
.pay-table td, .pay-table th { vertical-align: top; }
.pay-table input { min-height: 32px; padding: 5px 7px; }
tr.group td { background: var(--card-2); }
fieldset.pay-fields { border: 1px solid var(--line); border-radius: 10px; padding: 8px 14px 4px; margin: 6px 0 12px; }
fieldset.pay-fields legend { font-weight: 600; font-size: 13px; padding: 0 6px; }
.pay-table .pay-name { position: sticky; left: 0; z-index: 1; background: var(--card); white-space: nowrap;
  box-shadow: 1px 0 0 var(--line); }
.pay-table thead .pay-name, .pay-table tfoot .pay-name { background: var(--card-2); z-index: 2; }
.pay-table input.bad, .ts-grid input.bad { border-color: var(--danger); box-shadow: 0 0 0 2px var(--danger-soft); }
.month-nav { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.month-nav input { width: auto; }
/* «Новый заказ»: размеры двери под позицией ЭШИК */
.door-row > td { background: var(--card-2); padding: 10px 12px 14px; }
/* таблица позиций шире экрана — поля двери держим в видимой части (ширину задаёт скрипт формы) */
.door-row > td > .door-fields { position: sticky; left: 12px; width: var(--door-w, auto); }
.door-fields .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.door-preview { margin-top: 8px; }
/* «Отметки»: кнопки под статусом — таблица помещается в экран телефона */
.att-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.icon-btn { padding: 6px 9px; display: inline-flex; align-items: center; justify-content: center; }
.spark-line { fill: none !important; stroke-width: 2; }
.spark-line.ch-1 { stroke: var(--ch1); } .spark-line.ch-2 { stroke: var(--ch2); } .spark-line.ch-3 { stroke: var(--ch3); }
.spark-line.ch-4 { stroke: var(--ch4); }
.spark-area { opacity: .12; }
.chart-tabs [data-chart] { display: none; }
.chart-tabs [data-chart].on { display: block; }
.print-only { display: none; }
.chart-cap { font-size: 12px; font-weight: 600; color: var(--muted); margin: 10px 0 4px; }

/* ---------- вход ---------- */
.auth { max-width: 400px; margin: 8vh auto 0; padding: 28px; }
.auth h1 { justify-content: center; }
.auth .logo { width: 48px; height: 48px; border-radius: 14px; background: linear-gradient(135deg, #6366f1, #a855f7);
  color: #fff; display: grid; place-items: center; font-size: 22px; font-weight: 700; margin: 0 auto 10px; }

/* ---------- форма нового заказа ---------- */
.lines td { vertical-align: top; }
.lines input, .lines select { min-width: 70px; }
.lines .w-model { min-width: 170px; }
.lines .w-num { width: 90px; }
.lines .w-price { width: 110px; }
.lines .info { font-size: 12px; color: var(--muted); margin-top: 4px; }
.totals-box { display: grid; grid-template-columns: 1fr auto; gap: 8px 28px; max-width: 440px; margin-left: auto; }
.totals-box .big { font-size: 22px; font-weight: 700; }
.picker { position: relative; }
.picker-list { position: absolute; left: 0; right: 0; top: 100%; z-index: 30; background: var(--card); border: 1px solid var(--line-2);
  border-radius: 10px; box-shadow: var(--shadow-lg); max-height: 320px; overflow-y: auto; margin-top: 4px; }
.picker-item { padding: 9px 13px; cursor: pointer; border-bottom: 1px solid var(--line); }
.picker-item:last-child { border-bottom: 0; }
.picker-item.on, .picker-item:hover { background: var(--accent-soft); }
/* выбор модели в позиции заказа: список поверх таблицы (таблица прокручивается), с фото */
.mpick .mlist { position: fixed; right: auto; max-height: 380px; margin-top: 0; }
.mitem { display: flex; gap: 10px; align-items: center; padding: 6px 10px; }
.mitem img, .mitem .mnoimg { width: 52px; height: 52px; object-fit: cover; border-radius: 6px; flex: none; background: var(--card-2); }
.mitem .muted { font-size: 12px; }
.lines .mthumb { display: block; width: 84px; height: 84px; object-fit: cover; border-radius: 8px; margin-top: 6px; }
.lines .mthumb[hidden] { display: none; }
.model-photo img { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; vertical-align: middle; margin-right: 10px; }
.models-thumb { width: 44px; height: 44px; object-fit: cover; border-radius: 6px; display: block; }

/* ---------- окна ---------- */
dialog { border: 1px solid var(--line); border-radius: 14px; background: var(--card); color: var(--text); padding: 22px;
  width: min(520px, 94vw); box-shadow: var(--shadow-lg); }
dialog::backdrop { background: rgba(10, 14, 26, .5); backdrop-filter: blur(2px); }
dialog h2 { margin-bottom: 14px; }
dialog .row { justify-content: flex-end; margin-top: 18px; }
details > summary { cursor: pointer; }

/* ---------- телефон и планшет ---------- */
.bottom-nav, .side-close { display: none; }
@media (max-width: 900px) {
  /* Закрытое меню скрыто и для клавиатуры (Tab не уходит за край экрана) */
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; transform: translateX(-105%); visibility: hidden;
    transition: transform .22s ease, visibility 0s linear .22s; box-shadow: var(--shadow-lg); width: min(290px, 86vw); }
  .app.menu-open .sidebar { transform: none; visibility: visible; transition: transform .22s ease; }
  .app.menu-open::after { content: ""; position: fixed; inset: 0; background: rgba(10, 14, 26, .45); z-index: 35; }
  .side-close { display: inline-flex; margin-left: auto; background: none; border: none; color: var(--side-text); min-height: 0; padding: 4px; }
  .topbar { display: flex; align-items: center; gap: 10px; position: sticky; top: 0; z-index: 30; padding: 10px 14px;
    background: var(--card); border-bottom: 1px solid var(--line); }
  .topbar .brand { font-weight: 700; color: var(--text); font-size: 16px; }
  html { scroll-padding-top: 68px; }   /* якоря (#suggest и др.) не прячутся под прилипшей верхней панелью */
  .topbar button { min-height: 36px; padding: 6px 9px; }
  .topbar .who { margin-left: auto; }
  .wrap { padding: 16px 14px 96px; }
  h1 { font-size: 20px; }
  .card { padding: 14px; border-radius: 12px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat { padding: 12px 13px; }
  .stat .v, .stat .amt { font-size: 15px; }
  .bottom-nav { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: var(--card);
    border-top: 1px solid var(--line); padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); justify-content: space-around; }
  .bottom-nav a { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; color: var(--muted);
    padding: 4px 8px; border-radius: 10px; min-width: 56px; }
  .bottom-nav a.on { color: var(--accent); }
  .bottom-nav a:hover { text-decoration: none; }
  .bottom-nav a.fab { background: var(--accent-fill); color: #fff; width: 48px; height: 48px; border-radius: 50%; margin-top: -20px;
    justify-content: center; box-shadow: 0 6px 16px color-mix(in srgb, var(--accent) 45%, transparent); min-width: 0; }
  .bottom-nav .fab span { display: none; }
  .chart-box { height: 190px !important; }
}
@media (max-width: 520px) {
  .stats { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 420px) {
  .stats { grid-template-columns: 1fr; }   /* длинные суммы в сумах не переносятся */
  .stat .v, .stat .amt { font-size: 17px; }
  .month-nav { width: 100%; }   /* поле месяца — на всю ширину, под ним «‹ Показать ›» */
  .month-nav input { order: -1; flex: 1 0 100%; }
}
@media (max-width: 520px) {
  h1 .actions { width: 100%; margin-left: 0; }
  .kv { grid-template-columns: 1fr; gap: 2px; }
  .kv div:nth-child(even) { margin-bottom: 8px; }
}

@media print {
  /* Печать всегда в светлых цветах, даже если на экране тёмная тема */
  :root:root, :root:root[data-theme="dark"] {
    color-scheme: light; --bg: #fff; --card: #fff; --card-2: #f8f9fc; --text: #000; --muted: #444b5c; --faint: #555c6e;
    --line: #d8dce7; --line-2: #c5cad8; --accent: #3730a3; --accent-soft: #eef0ff; --accent-text: #3730a3;
    --danger: #b91c1c; --danger-soft: #fdecec; --ok: #137333; --ok-soft: #e7f6ec; --warn: #92400e; --warn-soft: #fdf3e2;
    --violet-soft: #f1eafe; --violet: #6d28d9; --input: #fff;
  }
  .sidebar, .topbar, .bottom-nav, .no-print, .tabs, .seg, .skip-link, .presets, .crumb, button, .btn { display: none !important; }
  .presets.print-filter { display: flex !important; }   /* на бумаге видно, по какому отбору посчитаны итоги */
  .print-filter .chip svg { display: none; }
  .chart-tabs [data-chart] { display: block; }   /* на бумаге — графики всех типов оплаты, каждый с подписью */
  .print-only { display: block; }
  body { background: #fff; color: #000; }
  a { color: inherit; }
  .card, .stat { border: none; padding: 0; box-shadow: none; }
  .wrap { padding: 0; }
}
