:root {
  --bg: #f6f6f4; --card: #ffffff; --fg: #1c1b19; --muted: #6f6b66; --line: #e4e2de;
  --accent: #1f5fbf; --accent-fg: #ffffff; --ok-bg: #e8f5ec; --ok-fg: #1d6b3a;
  --err-bg: #fdecea; --err-fg: #a12a1f; --warn: #9a5b00; --chip: #efeeeb;
  color-scheme: light;
}
/* Оформление выбирает пользователь (data-theme на <html>): без атрибута —
   как в системе, light — светлое, dark — темное, classic — классическое. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #171615; --card: #22201f; --fg: #f1efec; --muted: #a39e98; --line: #3a3734;
    --accent: #7fb0ff; --accent-fg: #10161f; --ok-bg: #16301f; --ok-fg: #8fd6a5;
    --err-bg: #3a1a17; --err-fg: #ffb3aa; --warn: #f2b84b; --chip: #2e2b29;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #171615; --card: #22201f; --fg: #f1efec; --muted: #a39e98; --line: #3a3734;
  --accent: #7fb0ff; --accent-fg: #10161f; --ok-bg: #16301f; --ok-fg: #8fd6a5;
  --err-bg: #3a1a17; --err-fg: #ffb3aa; --warn: #f2b84b; --chip: #2e2b29;
  color-scheme: dark;
}
:root[data-theme="classic"] {
  --bg: #f7f2e6; --card: #fefbf1; --fg: #1b1a14; --muted: #6e6a58; --line: #cbc6af;
  --accent: #2a4fc4; --accent-fg: #ffffff; --ok-bg: #e7f1dc; --ok-fg: #2f5d1a;
  --err-bg: #fbe3dc; --err-fg: #a12a1f; --warn: #8a5a00; --chip: #ece8d6;
  --grid: #b2ac8a; --band: #e9e5d9; --sel: #3f5fcc;
  color-scheme: light;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 15px/1.5 -apple-system, "Segoe UI", Roboto, Arial, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 24px; margin: 0 0 4px; }
h2 { font-size: 18px; margin: 28px 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
nav.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin: 14px 0 20px; border-bottom: 1px solid var(--line); }
nav.tabs a { padding: 8px 12px; border-radius: 8px 8px 0 0; color: var(--muted); }
nav.tabs a.active { color: var(--fg); background: var(--card); border: 1px solid var(--line); border-bottom-color: var(--card); margin-bottom: -1px; font-weight: 600; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 16px; margin-bottom: 16px; }
.scroll { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: 10px; }
.scroll td.text { min-width: 16rem; }
.scroll td.who { min-width: 10rem; }
table { border-collapse: collapse; width: 100%; }
th, td { padding: 8px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { font-size: 12px; font-weight: 600; color: var(--muted); white-space: nowrap; }
th.center { text-align: center; }
tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
th.wrap { white-space: normal; min-width: 5.5rem; }
tr.total td { font-weight: 700; border-top: 2px solid var(--line); }
.notice { background: var(--ok-bg); color: var(--ok-fg); padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; }
.error { background: var(--err-bg); color: var(--err-fg); padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; white-space: pre-wrap; }
.warn { color: var(--warn); margin: 6px 0; }
.chip { display: inline-block; padding: 1px 8px; border-radius: 999px; background: var(--chip); font-size: 12px; }
.chip.posted { background: var(--ok-bg); color: var(--ok-fg); }
.chip.cancelled { background: var(--err-bg); color: var(--err-fg); }
form .grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px 16px; }
form .grid > .end { align-self: end; }
label { display: block; font-size: 13px; color: var(--muted); }
input, select, textarea { width: 100%; font: inherit; color: var(--fg); background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 7px 9px; margin-top: 3px; }
input.amount { text-align: right; font-variant-numeric: tabular-nums; }
table input, table select { margin: 0; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; align-items: center; }
button, .button { font: inherit; padding: 8px 16px; border-radius: 6px; border: 1px solid var(--line); background: var(--card); color: var(--fg); cursor: pointer; display: inline-block; }
button.primary, .button.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
button.danger { color: var(--err-fg); }
.inline { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; }
.inline > div { min-width: 160px; }
.big { font-size: 20px; font-weight: 700; }
.mb { margin-bottom: 16px; }
.mt { margin-top: 12px; }
.mt0 { margin-top: 0; }
.full { flex-basis: 100%; margin: 0; }
code { background: var(--chip); padding: 1px 5px; border-radius: 4px; }
nav.tabs .group { padding: 8px 4px 8px 14px; font-size: 12px; color: var(--muted); border-left: 1px solid var(--line); }
tr.archived td { color: var(--muted); }
.check { display: flex; gap: 8px; align-items: center; color: var(--fg); font-size: 14px; }
.check input { width: auto; margin: 0; }
.chip.error { background: var(--err-bg); color: var(--err-fg); }
.chip.pending { background: var(--chip); }
.chip.done { background: var(--ok-bg); color: var(--ok-fg); }
.chip.abc-A { background: var(--ok-bg); color: var(--ok-fg); }
.sections { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; margin-bottom: 8px; }
.sections .card { margin-bottom: 0; }
td.links { white-space: nowrap; }
.orgline { margin: 0 0 16px; }
.filterinfo { margin: 0 0 10px; }

/* Раскладка: боковая панель на всю высоту слева (сворачивается в узкую
   полосу со значками), справа от нее меню, содержимое и колонка фильтров. */
.shell { display: flex; min-height: 100vh; }
.workspace { flex: 1; min-width: 0; container-type: inline-size; }

.sidebar { position: sticky; top: 0; height: 100vh; height: 100dvh; width: 264px; flex: none; display: flex; flex-direction: column;
  background: var(--card); border-right: 1px solid var(--line); }
.sidebar-head { height: 57px; flex: none; display: flex; align-items: center; gap: 8px; padding: 0 10px 0 18px; border-bottom: 1px solid var(--line); }
.sidebar .brand { display: block; flex: 1; min-width: 0; font-weight: 700; color: var(--fg); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-toggle { flex: none; display: grid; place-items: center; width: 34px; height: 34px; padding: 0; border: 0; border-radius: 8px;
  background: transparent; color: var(--muted); }
.sidebar-toggle:hover { background: var(--bg); color: var(--fg); }
.sidebar nav.orgs { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; padding: 14px 10px; }
.sidebar nav.orgs h3 { font-size: 13px; color: var(--muted); margin: 0 8px 6px; font-weight: 600; }
.sidebar nav.orgs p { margin: 0 8px 6px; }
.sidebar nav.orgs a { display: flex; gap: 10px; align-items: flex-start; padding: 7px 8px; border-radius: 8px; color: var(--fg); }
.sidebar nav.orgs a:hover { background: var(--bg); text-decoration: none; }
.sidebar nav.orgs a.active { background: var(--accent); color: var(--accent-fg); }
.sidebar nav.orgs a.add { align-items: center; color: var(--accent); margin-top: 4px; }
.sidebar .txt { display: flex; flex-direction: column; min-width: 0; }
.sidebar .name { line-height: 1.3; overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
.sidebar .meta { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar nav.orgs a.active .meta { color: var(--accent-fg); opacity: 0.8; }
.avatar { flex: none; width: 32px; height: 32px; border-radius: 8px; display: grid; place-items: center; font-size: 13px; font-weight: 700;
  line-height: 1; color: #fff; background: var(--muted); }
.avatar.tone0 { background: #2a64c4; } .avatar.tone1 { background: #2b7a4b; } .avatar.tone2 { background: #6a43b8; }
.avatar.tone3 { background: #b45a1b; } .avatar.tone4 { background: #17727b; } .avatar.tone5 { background: #b8325f; }
.sidebar a.add .avatar { background: transparent; color: var(--accent); border: 1px dashed var(--line); font-size: 18px; font-weight: 400; }
.sidebar .user { flex: none; display: flex; gap: 10px; align-items: center; padding: 12px 18px; border-top: 1px solid var(--line); cursor: default; }
.sidebar .user .avatar { border-radius: 50%; background: var(--chip); color: var(--muted); }
.sidebar .user .name { font-weight: 600; }

/* Свернутая панель: только значки, полные названия — во всплывающей подсказке. */
.shell.collapsed .sidebar { width: 64px; }
.shell.collapsed .sidebar .txt { display: none; }
.shell.collapsed .sidebar-head { justify-content: center; padding: 0; }
.shell.collapsed .sidebar-toggle svg { transform: rotate(180deg); }
.shell.collapsed .sidebar nav.orgs { padding: 14px 8px; }
.shell.collapsed .sidebar nav.orgs a { justify-content: center; padding: 6px 0; }
.shell.collapsed .sidebar .user { justify-content: center; padding: 12px 0; }

header.top { background: var(--card); border-bottom: 1px solid var(--line); }
nav.areas { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; min-height: 56px; padding: 8px 24px; }
nav.areas a { padding: 6px 12px; border-radius: 8px; color: var(--fg); font-weight: 600; }
nav.areas a:hover { background: var(--bg); text-decoration: none; }
nav.areas a.active { background: var(--accent); color: var(--accent-fg); }
nav.subnav { display: flex; gap: 4px; flex-wrap: wrap; padding: 6px 24px; border-top: 1px solid var(--line); }
nav.subnav a { padding: 5px 12px; border-radius: 6px; color: var(--muted); }
nav.subnav a.active { color: var(--fg); background: var(--bg); font-weight: 600; }

.layout { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 24px; padding: 20px 24px 48px; align-items: start; max-width: 1480px; }
aside.filters { width: 250px; position: sticky; top: 12px; }
aside.filters:not(:has(section)) { display: none; }
aside.filters .block { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin-bottom: 12px; }
aside.filters h3 { font-size: 13px; color: var(--muted); margin: 0 0 8px; font-weight: 600; }
aside.filters form label { margin-bottom: 8px; }
aside.filters form .check { margin-bottom: 8px; }
aside.filters .actions { margin-top: 8px; }

/* Мало места справа от панели — фильтры над списком, поля в несколько колонок. */
@container (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); padding: 16px 16px 40px; }
  aside.filters { width: auto; position: static; order: -1; }
  aside.filters form { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 8px 12px; align-items: end; }
  aside.filters form label, aside.filters form .check, aside.filters .actions { margin: 0; }
  nav.areas, nav.subnav { padding-left: 16px; padding-right: 16px; }
}
/* Узкий экран (телефон): панель всегда узкая, со значками. */
@media (max-width: 720px) {
  .shell .sidebar { width: 64px; }
  .shell .sidebar .txt, .sidebar-toggle { display: none; }
  .shell .sidebar-head { justify-content: center; padding: 0; }
  .shell .sidebar nav.orgs { padding: 14px 8px; }
  .shell .sidebar nav.orgs a { justify-content: center; padding: 6px 0; }
  .shell .sidebar .user { justify-content: center; padding: 12px 0; }
}

/* Воронка сделок: колонки стадий с карточками. */
.board { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin-bottom: 16px; }
.board .column { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px; }
.board h3 { font-size: 14px; margin: 0 0 8px; }
.dealcard { display: flex; flex-direction: column; gap: 2px; padding: 8px; margin-bottom: 8px; border: 1px solid var(--line);
  border-radius: 8px; background: var(--bg); color: var(--fg); }
.dealcard:hover { border-color: var(--accent); text-decoration: none; }

/* Вход и пользователи */
.bare { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.bare main.card { width: 100%; max-width: 380px; }
.bare .brand-line { margin: 0 0 8px; color: var(--muted); }
form.stack label { display: block; margin-bottom: 12px; }
.sidebar .user a.avatar { text-decoration: none; }
.sidebar .user a.name { color: var(--fg); text-decoration: none; }
.sidebar .user .txt { min-width: 0; display: flex; flex-direction: column; }
.sidebar .user .meta { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar .user form.logout { margin-left: auto; }
button.linklike { border: 0; background: none; padding: 0; color: var(--accent); font-size: 13px; }
.exportbar { display: flex; gap: 16px; align-items: center; margin: 0 0 12px; font-size: 13px; }
.shell.collapsed .sidebar .user form.logout { display: none; }
.temp-password { border-color: var(--warn); }
code.big { font-size: 18px; letter-spacing: 1px; user-select: all; }
fieldset { border: 1px solid var(--line); border-radius: 6px; padding: 8px 12px; }
fieldset .check { margin: 4px 0; }
.nowrap { white-space: nowrap; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

/* Сторно в журнале и карточке счета */
tr.storno td { color: var(--err-fg); }

/* Сводка организации */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { display: flex; flex-direction: column; gap: 4px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); color: var(--fg); text-decoration: none; }
.kpi:hover { border-color: var(--accent); }
.kpi .label { color: var(--muted); font-size: 13px; }
.kpi .value { font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; }
.kpi .hint { color: var(--muted); font-size: 12px; }
.kpi.bad .value { color: var(--err-fg); }

/* Печать отчетов: без меню, фильтров и кнопок */
.print-title h1 { font-size: 18px; }
table.kudir tr.cols td { text-align: center; color: var(--muted); font-size: 12px; }
@media print {
  .sidebar, header.top, aside.filters, .actions, .noprint, .orgline { display: none !important; }
  .shell, .workspace, .layout, main { display: block !important; margin: 0 !important; padding: 0 !important; }
  body { background: #fff; color: #000; }
  table { font-size: 11px; }
  a { color: inherit; text-decoration: none; }
}
/* Кнопка «Печать» с выпадающим списком печатных форм. */
.docbar { display: flex; gap: 8px; align-items: center; margin: 0 0 12px; }
.printmenu { position: relative; display: inline-block; }
.printmenu > summary { list-style: none; padding: 4px 12px; font-size: 13px; user-select: none; }
.printmenu > summary::-webkit-details-marker { display: none; }
.printmenu > summary::after { content: " ▾"; color: var(--muted); }
.printmenu[open] > summary { border-color: var(--accent); }
.printmenu .menu { position: absolute; z-index: 30; top: calc(100% + 4px); left: 0; min-width: 240px; padding: 4px 0;
  background: var(--card); border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 6px 20px rgba(0, 0, 0, .14);
  display: flex; flex-direction: column; font-size: 14px; }
.printmenu .menu-forms { display: flex; flex-direction: column; }
.printmenu .menu a, .printmenu .menu button { display: block; padding: 7px 14px; text-align: left; white-space: nowrap;
  color: var(--fg); text-decoration: none; border: 0; border-radius: 0; background: none; font-size: 14px; }
.printmenu .menu a:hover, .printmenu .menu button:hover { background: var(--chip); }
.printmenu .menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }
.printmenu .menu-note { margin: 0; padding: 7px 14px; color: var(--muted); font-size: 13px; }
.printmenu .menu-group { margin: 0; padding: 6px 14px 2px; color: var(--muted); font-size: 12px; text-transform: uppercase;
  letter-spacing: .03em; }
.createmenu > summary { font-size: 14px; padding: 6px 14px; }
.createmenu > summary::after { color: inherit; opacity: .8; }
.printmenu .menu-note[hidden] { display: none; }
tr[data-row] { cursor: default; }
tr[data-row].selected > td { background: color-mix(in srgb, var(--accent) 14%, transparent); }
@media print { tr[data-row].selected > td { background: none; } }

/* Выбор оформления: внизу боковой панели и на странице профиля. */
.sidebar .themebar { flex: none; padding: 8px 18px; border-top: 1px solid var(--line); }
.sidebar .themebar label { font-size: 12px; }
.sidebar .themebar select { padding: 3px 6px; font-size: 13px; }
.themes { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.themecard { display: flex; flex-direction: column; gap: 6px; padding: 10px; border: 1px solid var(--line); border-radius: 8px;
  color: var(--fg); font-size: 14px; cursor: pointer; }
.themecard:has(input:checked) { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.themecard input { width: auto; margin: 0; }
.preview { position: relative; display: block; height: 64px; border: 1px solid var(--pv-line); border-radius: 6px; overflow: hidden;
  background: var(--pv-bg); }
.preview i { position: absolute; display: block; left: 30%; right: 8px; height: 7px; background: var(--pv-line); }
.preview i:nth-child(1) { left: 0; right: auto; top: 0; bottom: 0; width: 22%; height: auto; background: var(--pv-side);
  border-right: 1px solid var(--pv-line); }
.preview i:nth-child(2) { top: 9px; height: 9px; background: var(--pv-accent); right: 40%; }
.preview i:nth-child(3) { top: 27px; }
.preview i:nth-child(4) { top: 42px; }
.preview-light { --pv-bg: #f6f6f4; --pv-side: #ffffff; --pv-line: #dedbd6; --pv-accent: #1f5fbf; }
.preview-dark { --pv-bg: #171615; --pv-side: #22201f; --pv-line: #3a3734; --pv-accent: #7fb0ff; }
.preview-system { --pv-side: transparent; --pv-line: #8d8984; --pv-accent: #4f87df;
  --pv-bg: linear-gradient(135deg, #f6f6f4 50%, #171615 50%); }
.preview-classic { --pv-bg: #fefbf1; --pv-side: #e9e5d9; --pv-line: #b2ac8a; --pv-accent: #3f5fcc; border-radius: 0; }
.preview-classic i:nth-child(3), .preview-classic i:nth-child(4) { background: #fff; border: 1px solid #b2ac8a; height: 9px; }

/* Классическое оформление: мелкий шрифт, плотные таблицы с полной сеткой,
   объемные кнопки и закладки, подчеркнутые ссылки, синее выделение. */
[data-theme="classic"] body { font: 13px/1.4 Tahoma, Verdana, "Segoe UI", Arial, sans-serif; }
[data-theme="classic"] main :where(a:not(.button, .kpi, .dealcard)) { text-decoration: underline; }
[data-theme="classic"] h1 { font-size: 22px; font-weight: 400; color: #8a8463; }
[data-theme="classic"] h2 { font-size: 13px; font-weight: 700; color: var(--muted); background: var(--band); padding: 3px 8px; margin: 18px 0 8px; }
[data-theme="classic"] .small { font-size: 12px; }
[data-theme="classic"] .card, [data-theme="classic"] .scroll, [data-theme="classic"] aside.filters .block,
[data-theme="classic"] .board .column, [data-theme="classic"] .kpi, [data-theme="classic"] .dealcard,
[data-theme="classic"] fieldset, [data-theme="classic"] .themecard { border-radius: 0; border-color: var(--grid); }
[data-theme="classic"] .card { padding: 10px 12px; margin-bottom: 12px; }
[data-theme="classic"] .scroll { background: #fff; }
[data-theme="classic"] th, [data-theme="classic"] td { padding: 2px 6px; border: 1px solid #d6d1bb; }
[data-theme="classic"] th { font-size: 12px; font-weight: 400; color: var(--fg); background: linear-gradient(#fbf9ef, #ebe7d3);
  border-color: var(--grid); }
[data-theme="classic"] tr:last-child td { border-bottom: 1px solid #d6d1bb; }
[data-theme="classic"] tr.total td { border-top: 2px solid var(--grid); background: var(--band); }
[data-theme="classic"] tbody tr:hover > td, [data-theme="classic"] tr[data-row]:hover > td { background: #fbf6d9; }
[data-theme="classic"] tr[data-row].selected > td { background: var(--sel); color: #fff; }
[data-theme="classic"] tr[data-row].selected > td a, [data-theme="classic"] tr[data-row].selected > td .chip { color: #fff; }
[data-theme="classic"] tr[data-row].selected > td .chip { background: rgba(255, 255, 255, .2); }
[data-theme="classic"] input, [data-theme="classic"] select, [data-theme="classic"] textarea {
  background: #fff; border-color: #a8a387; border-radius: 0; padding: 3px 5px; }
[data-theme="classic"] input:focus, [data-theme="classic"] select:focus, [data-theme="classic"] textarea:focus {
  outline: 1px solid var(--sel); outline-offset: 0; border-color: var(--sel); }
[data-theme="classic"] label { font-size: 12px; }
[data-theme="classic"] button, [data-theme="classic"] .button { padding: 3px 12px; border-radius: 2px; border-color: #a8a387; color: var(--fg);
  background: linear-gradient(#fefdf8, #e6e2d0); }
[data-theme="classic"] button:hover, [data-theme="classic"] .button:hover { background: linear-gradient(#fffbe6, #f2e3a6); text-decoration: none; }
[data-theme="classic"] button.primary, [data-theme="classic"] .button.primary { font-weight: 700; color: var(--fg); border-color: #7a7458;
  background: linear-gradient(#fefdf8, #e6e2d0); }
[data-theme="classic"] button.danger { color: var(--err-fg); }
[data-theme="classic"] button.linklike { background: none; border: 0; padding: 0; color: var(--accent); text-decoration: underline; }
[data-theme="classic"] .actions { margin-top: 10px; gap: 6px; }
[data-theme="classic"] .sidebar-toggle { background: transparent; border: 0; border-radius: 2px; }
[data-theme="classic"] .sidebar-toggle:hover { background: #f5f1de; }
[data-theme="classic"] table input, [data-theme="classic"] table select { border-color: transparent; background: transparent; }
[data-theme="classic"] table input:hover, [data-theme="classic"] table select:hover { border-color: #c9c3a6; }
[data-theme="classic"] .notice, [data-theme="classic"] .error { border-radius: 0; padding: 6px 10px; border: 1px solid currentColor; }
[data-theme="classic"] .chip { border-radius: 2px; }
[data-theme="classic"] code { border-radius: 0; }
[data-theme="classic"] .avatar { border-radius: 2px; }
[data-theme="classic"] .sidebar { background: var(--band); border-right-color: var(--grid); }
[data-theme="classic"] .sidebar-head { border-bottom-color: var(--grid); }
[data-theme="classic"] .sidebar nav.orgs a { border-radius: 0; }
[data-theme="classic"] .sidebar nav.orgs a:hover { background: #f5f1de; }
[data-theme="classic"] .sidebar nav.orgs a.active { background: var(--sel); color: #fff; }
[data-theme="classic"] .sidebar .user, [data-theme="classic"] .sidebar .themebar { border-top-color: var(--grid); }
[data-theme="classic"] header.top { background: var(--band); border-bottom-color: var(--grid); }
[data-theme="classic"] nav.areas { gap: 2px; min-height: 0; padding: 6px 24px 0; align-items: flex-end; }
[data-theme="classic"] nav.areas a { padding: 3px 12px; border: 1px solid #c0bb9f; border-bottom: 0; border-radius: 3px 3px 0 0;
  font-weight: 400; color: var(--fg); background: linear-gradient(#f8f6ea, #e3dfc8); }
[data-theme="classic"] nav.areas a:hover { background: linear-gradient(#fffbe6, #f2e3a6); }
[data-theme="classic"] nav.areas a.active { background: var(--card); color: var(--fg); border-color: var(--grid); padding-bottom: 5px;
  margin-bottom: -1px; position: relative; }
[data-theme="classic"] nav.subnav { background: var(--card); border-top-color: var(--grid); padding: 4px 24px; gap: 2px 14px; }
[data-theme="classic"] nav.subnav a { padding: 1px 0; border-radius: 0; color: var(--accent); text-decoration: underline; }
[data-theme="classic"] nav.subnav a.active { background: none; color: var(--fg); text-decoration: none; font-weight: 700; }
[data-theme="classic"] nav.tabs { gap: 2px; margin: 10px 0 14px; border-bottom-color: var(--grid); }
[data-theme="classic"] nav.tabs a { padding: 3px 12px; border: 1px solid #c0bb9f; border-bottom: 0; border-radius: 3px 3px 0 0;
  color: var(--fg); background: linear-gradient(#f8f6ea, #e3dfc8); text-decoration: none; }
[data-theme="classic"] nav.tabs a.active { background: var(--card); border-color: var(--grid); font-weight: 400; }
[data-theme="classic"] nav.tabs .group { padding: 3px 4px 3px 12px; border-left-color: var(--grid); }
[data-theme="classic"] .layout { gap: 16px; padding: 14px 20px 40px; }
[data-theme="classic"] .printmenu .menu { border-radius: 0; border-color: var(--grid); box-shadow: 2px 2px 4px rgba(0, 0, 0, .2); background: #fff; }
[data-theme="classic"] .printmenu .menu a, [data-theme="classic"] .printmenu .menu button { padding: 4px 14px; font-size: 13px;
  background: none; border: 0; text-decoration: none; font-weight: 400; }
[data-theme="classic"] .printmenu .menu a:hover, [data-theme="classic"] .printmenu .menu button:hover { background: var(--sel); color: #fff; }
[data-theme="classic"] .exportbar { font-size: 12px; }
[data-theme="classic"] .exportbar a { text-decoration: underline; }
/* Печать — всегда светлая, в каком бы оформлении ни работал пользователь. */
@media print {
  :root:not([data-theme]), :root[data-theme] {
    --bg: #ffffff; --card: #ffffff; --fg: #000000; --muted: #555555; --line: #cccccc; --grid: #999999; --band: #eeeeee;
    --accent: #000000; --chip: #eeeeee; --ok-bg: #ffffff; --ok-fg: #000000; --err-bg: #ffffff; --err-fg: #000000;
    color-scheme: light;
  }
  [data-theme] th { background: none; }
}

/* Штрихкоды в карточке номенклатуры. */
.barcodes { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 8px; }
.barcodes figure { margin: 0; padding: 6px; background: #fff; border: 1px solid var(--line); border-radius: 6px; }
.barcodes svg { display: block; width: 200px; height: 70px; }

/* Поле сканера в документе: первая кнопка формы — «Добавить по штрихкоду»,
   чтобы Enter сканера не проводил документ; на экране ее не видно. */
.defaultsubmit { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }
.scanbar { display: flex; gap: 8px; align-items: end; max-width: 640px; margin-bottom: 4px; }
.scanbar label { flex: 1; }
/* Розница: рабочее место кассира (pos.js), документы розницы. */
.grid-info { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px 16px; }
.posbar { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: center; margin-bottom: 14px; }
.posbar h2 { margin: 0; }
.postitle { display: flex; flex-direction: column; }
.posbar .grow { flex: 1; }
.posmsg { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; background: var(--ok-bg); color: var(--ok-fg); white-space: pre-wrap; }
.posmsg.error { background: var(--err-bg); color: var(--err-fg); }
.posmsg.big { font-size: 20px; font-weight: 600; }
.posgrid { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 16px; align-items: start; }
@container (max-width: 860px) { .posgrid { grid-template-columns: minmax(0, 1fr); } }
.poscart, .pospay { margin-bottom: 0; }
.posscan input { font-size: 17px; padding: 10px 12px; }
.posfound { list-style: none; margin: 6px 0 10px; padding: 4px 0; border: 1px solid var(--line); border-radius: 8px; background: var(--card); max-height: 320px; overflow-y: auto; }
.posfound li button { display: flex; width: 100%; gap: 12px; justify-content: space-between; border: 0; border-radius: 0; background: none; text-align: left; padding: 8px 12px; }
.posfound li button:hover, .posfound li button:focus { background: var(--chip); }
.posfound .muted { white-space: nowrap; }
.postable { margin-top: 10px; }
.postable td { vertical-align: middle; }
.postable input { width: 7rem; padding: 5px 7px; }
.postable input.posqty { width: 5.5rem; }
.postable input.posdisc { width: 4.5rem; }
.postable button.posdel { padding: 2px 9px; color: var(--err-fg); }
.postable tr.noprice input.posprice { border-color: var(--err-fg); }
.postotal { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 12px; }
.postotal b { font-size: 32px; font-variant-numeric: tabular-nums; }
.pospay label { margin-bottom: 10px; }
.pospay input { font-size: 17px; }
.poschange { margin: 2px 0 14px; font-size: 17px; }
.poschange b { font-variant-numeric: tabular-nums; }
.posbuttons { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
button.posbig { width: 100%; padding: 14px 10px; font-size: 17px; font-weight: 600; }
.posmixed { margin-top: 12px; }
.posmixed summary { cursor: pointer; color: var(--accent); font-size: 14px; margin-bottom: 8px; }
.posrefund { border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; margin: 0 0 12px; }
.posrefund legend { font-size: 13px; color: var(--muted); padding: 0 4px; }
.posrefund .check { margin: 4px 0; }
.posreceipts { margin-top: 8px; }
.posfind summary { cursor: pointer; }
.pos.busy button { opacity: .6; pointer-events: none; }
.chip.new { background: var(--err-bg); color: var(--err-fg); }
.chip.failed { background: var(--chip); color: var(--muted); }
.chip.draft { background: var(--chip); }
/* Узкий экран (телефон): строка чека — название сверху, поля под ним. */
@container (max-width: 640px) {
  #pos-cart thead { display: none; }
  #pos-cart tr { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.5fr) minmax(0, 1fr) auto; gap: 4px 8px; padding: 8px 10px; border-bottom: 1px solid var(--line); }
  #pos-cart td { padding: 0; border: 0; }
  #pos-cart td:first-child { grid-column: 1 / -1; }
  #pos-cart td[data-label]::before { content: attr(data-label); display: block; font-size: 11px; color: var(--muted); text-align: left; }
  #pos-cart td.num { text-align: left; }
  #pos-cart input { width: 100%; }
  #pos-cart td:last-child { align-self: end; }
  #pos-cart td.possum { grid-column: 1 / 4; font-weight: 600; }
}

/* Терминал склада (/orgs/{org}/m): страницы для телефона и терминала сбора
   данных — крупные кнопки и поля, без меню и боковой панели. */
.m-shell { max-width: 640px; margin: 0 auto; min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
.m-top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 6px; min-height: 56px; padding: 6px 12px;
  background: var(--card); border-bottom: 1px solid var(--line); }
.m-back { display: grid; place-items: center; width: 40px; height: 40px; margin-left: -6px; border-radius: 8px; color: var(--accent); }
.m-title { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
.m-title b { font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.m-title span { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.m-home { padding: 8px 10px; font-weight: 600; }
#m-main { flex: 1; padding: 14px 16px 24px; }
#m-main h2 { margin: 20px 0 8px; }
.m-foot { display: flex; gap: 14px; flex-wrap: wrap; align-items: center; padding: 12px 16px; font-size: 13px; color: var(--muted);
  border-top: 1px solid var(--line); }
.m-foot form { margin-left: auto; }
.m-whpick select { font-size: 17px; padding: 10px; }
.m-tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 16px 0; }
.m-tile { display: flex; flex-direction: column; gap: 4px; min-height: 104px; padding: 16px 14px; border-radius: 12px; background: var(--card);
  border: 1px solid var(--line); color: var(--fg); }
.m-tile:hover { text-decoration: none; border-color: var(--accent); }
.m-tile b { font-size: 18px; color: var(--accent); }
.m-tile span { font-size: 13px; color: var(--muted); }
.m-wide { display: block; text-align: center; padding: 14px; font-size: 17px; margin-bottom: 8px; }
.m-scan { margin-bottom: 14px; }
.m-scanrow { display: flex; gap: 8px; align-items: stretch; }
.m-scanrow input { flex: 1; min-width: 0; margin: 0; font-size: 18px; padding: 12px; }
.m-scanrow button { min-width: 52px; min-height: 52px; font-size: 16px; }
.m-cambtn { display: grid; place-items: center; padding: 0; color: var(--accent); }
.m-cambtn[hidden] { display: none; }
.m-cambtn.active { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.m-full { margin-bottom: 10px; }
.m-qty, .m-more, .m-left { margin-top: 10px; }
.m-qty summary, .m-more summary, .m-left summary, .m-fix summary { color: var(--accent); cursor: pointer; font-size: 14px; padding: 4px 0; }
.m-qty input { font-size: 17px; max-width: 12rem; }
.m-left ul { margin: 6px 0 0; padding-left: 20px; }
.m-cards { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.m-cards a { display: flex; flex-direction: column; gap: 2px; padding: 14px; border-radius: 10px; background: var(--card); border: 1px solid var(--line); color: var(--fg); }
.m-cards a:hover { text-decoration: none; border-color: var(--accent); }
.m-cards a b { color: var(--accent); }
.m-overdue { color: var(--err-fg); }
.m-lines { list-style: none; margin: 0; padding: 0; background: var(--card); border: 1px solid var(--line); border-radius: 10px; }
.m-lines li { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 12px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.m-lines li:last-child { border-bottom: 0; }
.m-lines li.last { background: var(--ok-bg); }
.m-lines li.done .m-name, .m-lines li.done .m-q { color: var(--muted); }
.m-lines li.done .m-q b::before { content: "✓ "; color: var(--ok-fg); }
.m-name { display: flex; flex-direction: column; min-width: 0; overflow-wrap: anywhere; }
.m-q { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.m-q b { font-size: 18px; }
.m-fix { grid-column: 1 / -1; }
.m-fixform { display: flex; gap: 8px; margin-top: 4px; }
.m-fixform input { margin: 0; max-width: 9rem; font-size: 17px; }
.m-choices form { margin-top: 8px; }
.m-choice { width: 100%; text-align: left; padding: 12px; }
.m-head { margin: 0 0 4px; }
.m-figures { display: flex; gap: 20px; flex-wrap: wrap; }
.m-figures div { display: flex; flex-direction: column; }
.m-figures b { font-size: 22px; }
.m-prefilled { padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; }
.m-cam { position: sticky; top: 56px; z-index: 4; background: #000; }
.m-cam[hidden] { display: none; }
.m-cam video { display: block; width: 100%; height: 34vh; object-fit: cover; }
.m-cam-bar { display: flex; gap: 10px; align-items: center; justify-content: space-between; padding: 6px 12px; color: #fff; font-size: 13px; }
.m-cam-bar button { padding: 6px 12px; }
