/* Astra — оболочка по образцу rnp: те же переменные темы, шапка, вкладки, карточки, таблицы.
   Тёмная тема — :root[data-theme="dark"]. Узкий экран — до 899px (телефон в книжной и альбомной), как в rnp после v1.9.
   Inline-стилей в приложении нет (CSP: style-src 'self'). */
:root {
  --bg: #f4f5f2; --card: #ffffff; --ink: #151a17; --ink-2: #5c645c; --rule: #d3d8cc;
  --accent: #0f6b5c; --accent-ink: #ffffff; --warn: #b4562a; --hot: #b3261e; --ok: #1f7a3d;
  --shade: rgba(21, 26, 23, .45);
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
:root[data-theme="dark"] {
  --bg: #141b21; --card: #1e272f; --ink: #e6ebee; --ink-2: #9aa7b0; --rule: #2e3a44;
  --accent: #5fd3b8; --accent-ink: #0c1a17; --warn: #d08a3e; --hot: #ff6b6b; --ok: #6fcf8e;
  --shade: rgba(0, 0, 0, .6);
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.45 var(--sans); }
body { min-height: 100vh; display: flex; flex-direction: column; }
[hidden] { display: none !important; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; }
.muted { color: var(--ink-2); }
.small { font-size: 12px; }
.stack { display: grid; gap: 2px; justify-items: start; }
.card > .actions { margin-top: 10px; }
.mono { font-family: var(--mono); }
.nowrap { white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.data-cabinet h3 { font-size: 15px; margin: 16px 0 6px; }
.data-cabinet p { margin: 4px 0; }
details.fold { margin-top: 6px; }
details.fold summary { cursor: pointer; padding: 4px 0; color: var(--ink-2); }
.warn { color: var(--warn); }
.error { color: var(--hot); }

/* ── шапка ── */
.top { display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 10px 16px; border-bottom: 1px solid var(--rule); background: var(--card); }
.brand { display: flex; align-items: center; gap: 8px; font-family: var(--mono); font-weight: 600; letter-spacing: .04em; }
.brand img { width: 24px; height: 24px; border-radius: 50%; }
.controls { display: flex; align-items: center; gap: 10px; min-width: 0; }
.controls select { max-width: 280px; }
.user-box { display: flex; align-items: center; gap: 8px; padding-left: 10px; border-left: 1px solid var(--rule); white-space: nowrap; }
.user-box .who { max-width: 180px; overflow: hidden; text-overflow: ellipsis; }

select, button, input, textarea { font: inherit; color: var(--ink); background: var(--bg);
  border: 1px solid var(--rule); border-radius: 6px; padding: 5px 8px; }
textarea { width: 100%; min-height: 96px; resize: vertical; font-family: var(--mono); font-size: 12px; }
button { cursor: pointer; }
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.danger { color: var(--hot); border-color: var(--hot); }
button.link { border: 0; background: none; padding: 0; color: var(--accent); text-decoration: underline; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input.invalid, select.invalid, textarea.invalid { border-color: var(--hot); }

/* ── полоса состояния: вход администратора, требования к учётной записи ── */
.banner { padding: 8px 16px; font-size: 13px; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  background: color-mix(in srgb, var(--warn) 18%, var(--card)); border-bottom: 1px solid var(--rule); }

/* ── «Состояние системы»: полоса под шапкой (красная — нужно действие, жёлтая — предупреждение) ── */
.hb { font-size: 13px; }
.hb.red { background: #b3261e; color: #fff; }
.hb.yellow { background: #f2c94c; color: #2b2100; }
.hb .hb-sum { all: unset; cursor: pointer; display: block; width: 100%; box-sizing: border-box; padding: 6px 16px; font-weight: 600; }
.hb .hb-sum:focus-visible { outline: 2px solid currentColor; outline-offset: -2px; }
.hb .hb-more { font-weight: 400; text-decoration: underline; margin-left: 6px; }
.hb .hb-det { padding: 0 16px 10px; }
.hb .hb-item { padding: 6px 0; border-top: 1px solid rgba(0, 0, 0, .18); }
.hb .hb-hint { opacity: .9; font-style: italic; }
ul.problems { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
ul.problems li { padding: 6px 10px; border-left: 4px solid var(--warn); border-radius: 4px; background: var(--bg); }
ul.problems li.red { border-color: var(--hot); }

/* ── разделы: строка над вкладками («Склад», «Настройки»); выбранный раздел соединён с полосой вкладок ── */
nav.sections { display: flex; gap: 4px; padding: 8px 16px 0; background: var(--card); border-bottom: 2px solid var(--accent); overflow-x: auto; scrollbar-width: thin; }
nav.sections a { padding: 6px 14px; border-radius: 6px 6px 0 0; color: var(--ink-2); font-weight: 600; text-decoration: none; white-space: nowrap; }
nav.sections a:hover { color: var(--ink); }
nav.sections a.active { color: var(--accent-ink); background: var(--accent); }
a.who { color: var(--ink); text-decoration: none; }
a.who:hover, a.who.active { color: var(--accent); text-decoration: underline; }
/* индикатор актуальности данных площадок в заголовке складского экрана */
a.fresh { text-decoration: none; }
a.fresh:hover { text-decoration: underline; }
/* переключатель видов внутри вкладки и строка отбора над таблицей */
.subnav { display: flex; gap: 6px; flex-wrap: wrap; }
.subnav a { padding: 3px 10px; border: 1px solid var(--rule); border-radius: 14px; color: var(--ink-2); text-decoration: none; white-space: nowrap; }
.subnav a.active { color: var(--ink); border-color: var(--accent); }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; margin-bottom: 10px; }
.toolbar input[type=search] { flex: 1 1 220px; min-width: 0; max-width: 360px; }
.toolbar-search { display: flex; gap: 6px; flex: 1 1 260px; min-width: 0; max-width: 460px; }
.toolbar-search input { flex: 1 1 auto; min-width: 0; }
.toolbar label.check { display: flex; align-items: center; gap: 6px; }
.toolbar select { max-width: 260px; }
.pick { display: grid; gap: 4px; max-height: 320px; overflow: auto; }
.pick button { text-align: left; }
.pick button b { font-family: var(--mono); font-weight: 600; }

/* складские документы и остатки: пометка о скрытой стоимости, строки документа с полями ввода, остаток по местам */
.note { margin: 0 0 10px; padding: 6px 10px; border-left: 4px solid var(--warn); border-radius: 4px; background: var(--bg); font-size: 13px; }
.card h3 { font-size: 15px; margin: 14px 0 8px; }
.card .kv { margin-bottom: 10px; }
.small { font-size: 12px; }
.stack { display: grid; gap: 2px; justify-items: start; }
.lines td { vertical-align: middle; }
.lines input.short { width: 96px; }
.lines input.money { width: 116px; text-align: right; }
.lines .line-product { margin-right: 8px; overflow-wrap: anywhere; }
.lines .actions { margin-top: 8px; }
input.short { width: 96px; }
ul.places li { display: flex; justify-content: space-between; gap: 12px; max-width: 340px; }
ul.places li b { font-weight: 600; white-space: nowrap; }
td.row-actions a { white-space: nowrap; }
dialog.wide { width: min(980px, calc(100vw - 24px)); }
.import-report { display: grid; gap: 8px; }
.import-report .table-wrap { max-height: 46vh; overflow: auto; }
.import-report p { margin: 0; }

/* ── вкладки ── */
nav.tabs { display: flex; gap: 2px; padding: 0 16px; border-bottom: 1px solid var(--rule); background: var(--card); overflow-x: auto; scrollbar-width: thin; }
nav.tabs a { padding: 10px 14px; color: var(--ink-2); text-decoration: none; border-bottom: 2px solid transparent; white-space: nowrap; }
nav.tabs a:hover { color: var(--ink); }
nav.tabs a.active { color: var(--ink); border-bottom-color: var(--accent); }
nav.tabs .spacer { flex: 1; }

main { flex: 1; width: 100%; max-width: 1400px; margin: 0 auto; padding: 16px; }
.foot { padding: 8px 16px; border-top: 1px solid var(--rule); font-size: 12px; display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

/* ── карточки и заголовки разделов ── */
section { margin-bottom: 20px; }
.card { padding: 14px 16px; border: 1px solid var(--rule); border-radius: 8px; background: var(--card); }
.sect-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.sect-head h2 { font-size: 17px; }
.sect-head h3 { font-size: 15px; margin-top: 12px; }
.sect-head .grow { flex: 1; }
.stub { padding: 28px; border: 1px dashed var(--rule); border-radius: 8px; background: var(--card); text-align: center; }
.crumbs { margin-bottom: 12px; font-size: 13px; }
.kv { display: grid; grid-template-columns: 180px 1fr; gap: 4px 14px; margin: 0; }
.kv dt { color: var(--ink-2); }
.kv dd { margin: 0; overflow-wrap: anywhere; }

/* ── таблицы ── */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th, td { padding: 7px 8px; border-bottom: 1px solid var(--rule); text-align: left; vertical-align: top; }
th { color: var(--ink-2); font-weight: 500; font-size: 12px; white-space: nowrap; }
tr.inactive td { color: var(--ink-2); }
/* ячейка с кнопками строки (не путать с блоком .actions под формами) */
td.row-actions { text-align: right; min-width: 200px; }
td.row-actions button { padding: 2px 8px; margin: 0 0 4px 4px; }
td.wide { min-width: 220px; overflow-wrap: anywhere; }

/* ── метки состояния ── */
.badge { display: inline-block; width: fit-content; justify-self: start; padding: 1px 8px; border-radius: 9px; font-size: 12px; white-space: nowrap;
  border: 1px solid var(--rule); color: var(--ink-2); }
.badge.ok { color: var(--ok); border-color: var(--ok); }
.badge.warn { color: var(--warn); border-color: var(--warn); }
.badge.bad { color: var(--hot); border-color: var(--hot); }

/* ── формы ── */
.form { display: grid; gap: 12px; }
.form .grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px 14px; }
.form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--ink-2); }
.form label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--ink); }
.form input:not([type=checkbox]):not([type=radio]), .form select { width: 100%; }
.form input[type=checkbox], .form input[type=radio] { width: 16px; height: 16px; margin: 0; padding: 0; accent-color: var(--accent); }
.form .hint { font-size: 12px; color: var(--ink-2); margin: 0; }
.form fieldset { margin: 0; padding: 10px 12px; border: 1px solid var(--rule); border-radius: 6px; display: grid; gap: 6px; }
.form legend { padding: 0 6px; font-size: 13px; color: var(--ink-2); }
.actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.status { font-size: 13px; min-height: 1.4em; margin: 0; }

/* ── диалог ── */
dialog { width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 24px); padding: 0; overflow: auto;
  color: var(--ink); background: var(--card); border: 1px solid var(--rule); border-radius: 10px; }
dialog::backdrop { background: var(--shade); }
dialog .dlg-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--rule); }
dialog .dlg-head h2 { font-size: 16px; }
dialog .dlg-body { padding: 14px 16px 16px; display: grid; gap: 12px; }
dialog .dlg-close { border: 0; background: none; font-size: 20px; line-height: 1; padding: 0 4px; color: var(--ink-2); }

/* ── секрет, который показывается один раз (выданный пароль, резервные коды) ── */
.secret { margin: 0; padding: 10px 12px; font: 15px/1.6 var(--mono); text-align: center; white-space: pre-wrap; overflow-wrap: anywhere;
  background: var(--bg); border: 1px dashed var(--accent); border-radius: 8px; user-select: all; }
img.qr { width: 220px; height: 220px; justify-self: center; border-radius: 8px; background: #fff; }

/* ── история «было / стало» ── */
.diff { display: grid; grid-template-columns: minmax(120px, auto) minmax(0, 1fr) minmax(0, 1fr); gap: 2px 12px; font-size: 12px; margin: 0; }
.diff .field { color: var(--ink-2); }
.diff .was { color: var(--ink-2); text-decoration: line-through; overflow-wrap: anywhere; }
.diff .now { overflow-wrap: anywhere; }
/* метки области доступа */
.marks { display: flex; flex-wrap: wrap; gap: 4px; }
.mark { padding: 1px 8px; border: 1px solid var(--rule); border-radius: 10px; font-size: 12px; white-space: nowrap; }
.mark.cabinet { border-style: dashed; }

/* область доступа деревом: юрлицо и его кабинеты */
.scope-tree { display: grid; gap: 10px; margin-top: 4px; }
.scope-entity { display: grid; gap: 4px; }
.scope-cabinets { display: grid; gap: 4px; padding-left: 24px; border-left: 2px solid var(--rule); margin-left: 7px; }

/* матрица прав роли */
table.perm-matrix th, table.perm-matrix td { padding: 5px 6px; }
table.perm-matrix .pm-act { text-align: center; width: 84px; }
table.perm-matrix input:disabled { opacity: .35; }
table.perm-matrix th .short { display: none; }
button.link { text-align: left; }

/* отбор журнала */
.filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 14px; margin-bottom: 12px; }
.filters label, .filters .field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--ink-2); }
.filters .pair { display: flex; gap: 6px; }
.filters input.short { width: 76px; }
.filters select { max-width: 260px; }

/* страница приглашения */
.login-card.invite-card { max-width: 420px; }
.invite-card .kv { grid-template-columns: 110px 1fr; }
.invite-card fieldset.mode { margin: 0; padding: 10px 12px; border: 1px solid var(--rule); border-radius: 6px; display: grid; gap: 6px; }
.invite-card fieldset.mode legend { padding: 0 6px; font-size: 13px; color: var(--ink-2); }
.invite-card label.check { display: flex; align-items: center; gap: 8px; }
a.button { display: inline-block; padding: 9px 12px; border-radius: 6px; text-align: center; text-decoration: none; }
a.button.primary { background: var(--accent); color: var(--accent-ink); }

ul.plain { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }

/* ── страница входа и одиночные формы ── */
body.center { display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; padding: 24px; display: grid; gap: 14px; }
.login-card img { justify-self: center; width: 72px; height: 72px; border-radius: 50%; }
.login-card h1 { font-size: 22px; text-align: center; }
.login-card input:not([type=checkbox]) { padding: 9px 10px; }
.login-card button { padding: 9px 12px; }

.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 100; max-width: calc(100vw - 24px);
  padding: 8px 14px; border-radius: 8px; background: var(--ink); color: var(--bg); font-size: 13px; }

/* ── Узкий экран < 900px: телефон в книжной и альбомной ─────────────────────────────────────────────
   Шапка в две строки, вкладки прокручиваются, таблицы превращаются в карточки (подпись колонки — слева),
   формы в одну колонку, диалог — почти на весь экран. Десктоп ≥ 900px не меняется. */
@media (max-width: 899px) {
  .top { flex-wrap: wrap; gap: 8px; padding: 8px; }
  .controls { flex: 1 1 100%; flex-wrap: wrap; gap: 8px; }
  .controls select { flex: 1 1 160px; max-width: none; min-width: 0; }
  .user-box { border-left: 0; padding-left: 0; }
  nav.sections { padding: 8px 8px 0; }
  nav.sections a { padding: 6px 12px; }
  .toolbar-search { max-width: none; flex-basis: 100%; }
  .toolbar select { max-width: none; flex: 1 1 140px; }
  nav.tabs { padding: 0 8px; }
  nav.tabs a { padding: 10px; }
  main { padding: 8px; }
  .banner { padding: 8px; }
  .hb .hb-sum { padding: 6px 8px; }
  .hb .hb-det { padding: 0 8px 8px; }
  .card { padding: 10px; }
  .kv { grid-template-columns: 1fr; gap: 0; }
  .kv dd { margin-bottom: 6px; }
  .form .grid { grid-template-columns: 1fr; }
  .sect-head button { flex: 1 1 auto; }
  dialog { width: calc(100vw - 12px); max-height: calc(100vh - 12px); }
  dialog .actions button { flex: 1 1 auto; }

  table.cards thead { display: none; }
  table.cards, table.cards tbody, table.cards tr, table.cards td { display: block; width: 100%; }
  table.cards tr { padding: 8px 0; border-bottom: 1px solid var(--rule); }
  table.cards td { display: grid; grid-template-columns: 110px 1fr; gap: 8px; padding: 2px 0; border: 0; text-align: left; min-width: 0; }
  table.cards td::before { content: attr(data-label); color: var(--ink-2); font-size: 12px; }
  table.cards td:empty { display: none; }
  table.cards td.row-actions { display: flex; flex-wrap: wrap; gap: 6px; padding-top: 6px; min-width: 0; }
  table.cards td.row-actions::before { content: none; }

  /* «Данные»: строки-карточки в две колонки, первая ячейка — заголовок карточки */
  .data-cabinet table.cards tr { display: grid; grid-template-columns: 1fr 1fr; column-gap: 12px; }
  .data-cabinet table.cards td { grid-template-columns: 1fr auto; }
  .data-cabinet table.cards td:first-child { grid-column: 1 / -1; grid-template-columns: 1fr; font-weight: 600; }
  .data-cabinet table.cards td:first-child::before { content: none; }
  .data-cabinet table.cards td.num { text-align: right; }
  .data-cabinet table.cards td.wide { grid-column: 1 / -1; grid-template-columns: 130px 1fr; white-space: normal; }
  table.cards td.row-actions button { flex: 1 1 auto; margin: 0; padding: 6px 8px; }
  .lines input.short, .lines input.money, .lines select { width: 100%; text-align: left; }
  ul.places li { max-width: none; }
  dialog.wide { width: calc(100vw - 12px); }
  .filters label, .filters .field { flex: 1 1 100%; }
  .filters .pair > * { flex: 1 1 0; min-width: 0; }
  .filters .pair input.short { flex: 0 0 76px; }
  .filters select { max-width: none; width: 100%; }
  .filters > button { flex: 1 1 100%; }
  table.perm-matrix { table-layout: fixed; }
  table.perm-matrix th:first-child { width: 38%; }
  table.perm-matrix .pm-act { width: auto; padding: 5px 2px; }
  table.perm-matrix th .full { display: none; }
  table.perm-matrix th .short { display: inline; }
  table.cards td button.link { justify-self: start; }
  .invite-card .kv { grid-template-columns: 110px 1fr; gap: 4px 14px; }
  .diff { grid-template-columns: 1fr; gap: 0; }
  .diff .field { margin-top: 4px; }
  .diff span:empty { display: none; }
}
