/* Доброжелательный минимализм: тёплая нейтральная шкала, мягкие скругления, один спокойный акцент,
   цвет — только по смыслу. */

:root {
  --bg: #ffffff;
  --surface: #f7f6f3;          /* боковая панель, фон страницы входа */
  --hover: #efede8;
  --text: #1f2125;
  --muted: #6e6f73;
  --rule: #ebe9e4;
  --rule-strong: #d5d2cb;
  --accent: #3f5bd8;
  --accent-soft: #e9edfc;
  --ring: 0 0 0 3px rgba(63, 91, 216, .18);
  --ok: #1d7a43;
  --warn: #9a5a00;
  --bad: #c0392b;
  --bad-soft: #fdeeec;

  --radius: 10px;
  --radius-sm: 6px;

  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --fs: 14px;
  --fs-small: 12px;

  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }

html { font-size: var(--fs); }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 1rem/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }

h1 { margin: 0; font-size: 22px; font-weight: 600; letter-spacing: -.01em; }

h2 {
  margin: 36px 0 8px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

p { margin: 0; }

small { font-size: var(--fs-small); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* Каркас */

.layout {
  display: grid;
  grid-template-columns: 184px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  padding: 20px 12px;
  background: var(--surface);
  border-right: 1px solid var(--rule);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 8px 20px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 18px;
  height: 18px;
  border-radius: 6px;
  background: linear-gradient(135deg, var(--accent), #7b8ff0);
}

.sidebar ul { margin: 0; padding: 0; list-style: none; }
.sidebar li a {
  display: block;
  padding: 5px 8px;
  border-radius: var(--radius-sm);
  color: var(--muted);
}
.sidebar li a:hover { background: var(--hover); color: var(--text); text-decoration: none; }
.sidebar li a[aria-current="page"] { background: var(--bg); color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgba(0, 0, 0, .06); }

.sign-out { margin: auto 8px 0; padding-top: 16px; }
.sign-out .link { color: var(--muted); font-size: var(--fs); }
.sign-out .link:hover { color: var(--text); }

.content { max-width: 1200px; padding: 24px 36px 72px; }

/* Шапка страницы */

.crumbs { margin-bottom: 4px; font-size: var(--fs-small); }
.crumbs a { color: var(--muted); }

.page-head { display: flex; align-items: center; gap: 16px; }

.meta { margin-top: 4px; color: var(--muted); }
.meta .sep { margin: 0 2px; }

.comment { margin-top: 8px; }

.notice { margin-top: 12px; }

/* Итоги */

.totals {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 48px;
  margin: 20px 0 0;
  padding: 14px 20px;
  border-radius: var(--radius);
  background: var(--surface);
}
.totals dt { font-size: var(--fs-small); color: var(--muted); }
.totals dd { margin: 2px 0 0; font-size: 19px; font-weight: 500; font-variant-numeric: tabular-nums; }

/* Таблицы */

.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
table.compact { width: auto; min-width: 420px; }

th, td {
  padding: 6px 14px 6px 0;
  border-bottom: 1px solid var(--rule);
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
}
th:last-child, td:last-child { padding-right: 0; }
th { font-size: var(--fs-small); font-weight: 500; color: var(--muted); }
tfoot td { border-bottom: 0; padding-top: 10px; }

.num { text-align: right; }
.mono { font-family: var(--mono); font-size: 13px; }

/* Поля и кнопки */

select, input, button { font: inherit; color: inherit; }

.cell-form { display: inline-flex; align-items: center; gap: 8px; margin: 0; }

/* Правка в ячейке — «тихое» поле: тёплая подложка и тонкая рамка; при вводе — белое, с обводкой, как в формах.
   Ниже полей форм (30px), чтобы строки таблиц не разрастались. */
.cell-input,
.cell-select,
.status-select,
.field-input,
.add-form select {
  height: 30px;
  padding: 0 8px;
  border: 1px solid var(--rule);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  transition: border-color .12s, background-color .12s;
}
.cell-input, .field-input { width: 11ch; text-align: right; font-variant-numeric: tabular-nums; }
/* Ширина по выбранному значению, а не по самому длинному варианту (где поддерживается). */
.cell-select, .status-select { field-sizing: content; padding-right: 4px; }
.cell-select { max-width: 340px; }
.status-select { font-weight: 600; }
.cell-input:hover, .cell-select:hover, .status-select:hover, .field-input:hover, .add-form select:hover { border-color: var(--rule-strong); }
.cell-input:focus, .cell-select:focus, .status-select:focus, .field-input:focus, .add-form select:focus {
  border-color: var(--accent);
  background: var(--bg);
  outline: none;
  box-shadow: var(--ring);
}

.add-form { display: flex; align-items: center; gap: 8px; }

td.wrap { white-space: normal; min-width: 20ch; max-width: 48ch; }

.button {
  height: 30px;
  padding: 0 14px;
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius-sm);
  background: var(--bg);
  cursor: pointer;
  transition: background-color .12s, border-color .12s;
}
.button:hover { background: var(--surface); border-color: var(--muted); }
.button.primary { border-color: var(--accent); background: var(--accent); color: #fff; font-weight: 500; }
.button.primary:hover { background: #3550c4; border-color: #3550c4; }

.link {
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent);
  font-size: var(--fs-small);
  cursor: pointer;
}
.link:hover { text-decoration: underline; }

/* Маленькая кнопка в строке таблицы. danger — удаление: красная при наведении. */
.button-small {
  height: 26px;
  padding: 0 10px;
  border: 1px solid var(--rule);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  font-size: var(--fs-small);
  cursor: pointer;
  transition: color .12s, background-color .12s, border-color .12s;
}
.button-small:hover { border-color: var(--rule-strong); color: var(--text); }
.mark + .button-small { margin-left: 6px; }
a.button-small { display: inline-flex; align-items: center; margin-right: 6px; text-decoration: none; }
.button-small.danger:hover { border-color: transparent; background: var(--bad-soft); color: var(--bad); }

.mark { font-size: var(--fs-small); color: var(--muted); }

/* История */

.history { margin: 0; padding: 0; list-style: none; }
.history li {
  display: grid;
  grid-template-columns: 128px 72px 1fr;
  gap: 12px;
  padding: 6px 0;
  border-bottom: 1px solid var(--rule);
}
.history time { font-variant-numeric: tabular-nums; }
/* История у партнёра: время и событие — без колонки источника. */
.history.events li { grid-template-columns: 128px 1fr; }

/* Смысловые тона */

.muted, .tone-muted { color: var(--muted); }
.tone-ok { color: var(--ok); }
.tone-warn { color: var(--warn); }
.tone-bad { color: var(--bad); }

/* Запрос HTMX в процессе */

.htmx-request { opacity: .5; }

/* Узкие экраны */

@media (max-width: 760px) {
  .layout { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; }
  .sidebar {
    position: static;
    height: auto;
    padding: 12px;
    border-right: 0;
    border-bottom: 1px solid var(--rule);
  }
  .brand { margin-bottom: 8px; }
  .sidebar ul { display: flex; flex-wrap: wrap; gap: 2px 4px; }
  .sign-out { margin: 8px 8px 0; padding-top: 0; }
  .content { padding: 16px 16px 48px; }
  .totals { gap: 12px 32px; }
  .history li, .history.events li { grid-template-columns: 1fr; gap: 0; }
  table.compact { min-width: 0; }
}

/* Фильтры списков — компактная карточка: подписи над полями, поля .field */

.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px 14px;
  width: fit-content;
  max-width: 100%;
  margin-top: 16px;
  padding: 14px 18px;
  border: 1px solid var(--rule);
  border-radius: 14px;
  background: var(--bg);
}
.filters label { display: grid; gap: 5px; color: var(--muted); }
.filters .w-date { flex: 0 0 160px; }
.filters .w-m { flex: 0 0 200px; }
.filters .w-l { flex: 0 0 260px; }
.filters .check { display: inline-flex; align-items: center; gap: 6px; height: 36px; color: var(--text); }

.pager { display: flex; gap: 16px; margin-top: 12px; }

/* Выбор заказов и массовые действия */

th.select, td.select { width: 1%; padding-right: 12px; }
td.status-cell { white-space: normal; min-width: 9ch; max-width: 15ch; }

/* Панель выбранных заказов — плавающая карточка у нижнего края: итоги и массовые действия */

.selection-bar:not(:empty) {
  position: sticky;
  bottom: 12px;
  margin-top: 16px;
  padding: 14px 18px 16px;
  border: 1px solid var(--rule);
  border-radius: 14px;
  background: var(--bg);
  box-shadow: 0 8px 28px rgba(31, 33, 37, .10);
}
.totals.totals-compact { margin: 0; padding: 0 0 12px; border-radius: 0; background: none; border-bottom: 1px solid var(--rule); gap: 8px 32px; }
.totals-compact dd { font-size: 15px; }
.bulk-actions { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px 24px; margin-top: 12px; }
.bulk-action { display: grid; gap: 5px; margin: 0; }
.bulk-label { color: var(--muted); }
.bulk-note { height: 36px; display: flex; align-items: center; }
/* Поле и кнопка вплотную: одно действие */
.field-group { display: flex; }
.field-group .field { width: auto; border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.field-group select.field { field-sizing: content; min-width: 16ch; max-width: 440px; }
.field-group input.field { width: 11ch; }
.field-group .field:focus { position: relative; z-index: 1; }
.field-group .button { height: 36px; margin-left: -1px; border-radius: 0 var(--radius-sm) var(--radius-sm) 0; white-space: nowrap; }
.empty { margin-top: 16px; }

/* Карточка исполнителя */

.stat-line + .stat-line { margin-top: 4px; }
/* a:where(...) весит как `a`: перебивает синий цвет ссылок, но уступает классам .tone-*. */
a:where(.stat-link) { color: var(--text); }
.stat-link { text-decoration: underline; text-decoration-color: var(--rule-strong); text-underline-offset: 3px; }
.stat-link:hover { text-decoration-color: currentColor; }
.cell-input.cell-text { width: 32ch; }
table.profile th { padding-right: 32px; font-size: var(--fs); font-weight: 400; color: var(--muted); }
table.profile .cell-input { text-align: left; }
.more { margin-top: 8px; color: var(--muted); }

/* Ставки */

.default-rate { margin-top: 16px; }
.default-rate label { color: var(--muted); }
details.city { border-bottom: 1px solid var(--rule); padding: 8px 0; }
details.city summary { cursor: pointer; }
details.city table { margin: 6px 0 2px 18px; }
/* Одинаковые колонки в базовых и городских ставках — цифры стоят ровным столбцом. */
table.rate-cells { min-width: 0; }
table.rate-cells td:first-child { width: 220px; }
table.rate-cells td.num { width: 110px; }
details.city td { border-bottom: 0; padding-top: 3px; padding-bottom: 3px; }

/* Выгрузка */

.result-actions { margin: 12px 0 6px; font-size: var(--fs-small); color: var(--muted); }

/* Итоговая строка таблиц */

tr.totals-row td { border-top: 1px solid var(--rule-strong); border-bottom: 0; font-weight: 600; padding-top: 8px; }

/* Карточка партии */

.totals .cell-input.totals-input { height: 32px; font-size: 18px; width: 10ch; margin-top: 2px; text-align: left; background: var(--bg); }

/* Отчёт о прибылях и убытках */

table.pnl { width: auto; min-width: min(560px, 100%); }
table.pnl td:first-child { padding-right: clamp(16px, 5vw, 48px); }
table.pnl tr.pnl-result td { font-weight: 600; border-top: 1px solid var(--rule-strong); }
table.pnl tr.pnl-sub td:first-child { padding-left: 16px; color: var(--muted); }
table.pnl tr.pnl-count td { color: var(--muted); }
.breakdowns { display: flex; flex-wrap: wrap; gap: 0 48px; }

/* Сводка */

table.attention { width: auto; }
table.attention td:first-child { padding-right: 32px; }
tr.current td { font-weight: 600; }
.more a.quiet { color: var(--muted); text-decoration: underline; text-decoration-color: var(--rule-strong); }

/* Карточка партнёра */

details.inline-edit { display: inline; }
details.inline-edit summary { display: inline; cursor: pointer; color: var(--muted); list-style: none; }
details.inline-edit summary::-webkit-details-marker { display: none; }
details.inline-edit[open] summary { display: none; }
details.inline-edit form { display: inline-flex; }
table.tariffs .cell-input { width: 14ch; }
div.meta { margin-bottom: 16px; }

/* Расходы */

table.expenses .cell-text { width: 32ch; text-align: left; }

/* Оклады */

.salary-due { flex: 1 1 260px; min-height: 36px; display: flex; flex-wrap: wrap; align-items: center; gap: 0 4px; }
.salary-due b { font-weight: 600; font-variant-numeric: tabular-nums; }
table.payroll-accruals .cell-text { width: 28ch; text-align: left; }

/* Справочники */

table.reference { width: auto; min-width: min(560px, 100%); }
table.reference .name-input { width: 24ch; text-align: left; }

/* Настройки */

.issued-key { margin: 12px 0 16px; padding: 14px 18px; border-radius: var(--radius); background: var(--accent-soft); }
.issued-key p { margin: 0 0 6px; }
.issued-key .secret { font-size: 14px; word-break: break-all; user-select: all; }
.settings-info div { display: flex; gap: 16px; padding: 4px 0; }
.settings-info dt { width: 14ch; color: var(--muted); }
.settings-info dd { margin: 0; }

/* Партия: ручное списание, новая партия */

table.candidates td:first-child { width: 1%; }

/* Каталог: единица товара и размер фасовки */

.unit-form { display: flex; align-items: baseline; gap: 6px; }
.unit-input { width: 5ch; text-align: left; }
.allocation { margin-top: 2px; font-size: 13px; }

/* Вход */

.login {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px 16px;
  background: var(--surface);
}
.login-card {
  display: grid;
  gap: 14px;
  width: min(360px, 100%);
  padding: 32px 28px 28px;
  border: 1px solid var(--rule);
  border-radius: 14px;
  background: var(--bg);
  box-shadow: 0 8px 28px rgba(31, 33, 37, .06);
}
.login-card .brand { margin: 0 0 8px; }
.login-card h1 { font-size: 20px; }
.login-card > .muted { margin-top: -10px; }
.login-card label { display: grid; gap: 6px; color: var(--muted); }
.login-card .button { height: 40px; margin-top: 6px; }
.login-error { padding: 8px 12px; border-radius: var(--radius-sm); background: var(--bad-soft); color: var(--bad); }

/* Формы-карточки: поле, группы, ряды */

.field {
  width: 100%;
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
}
.field:focus { border-color: var(--accent); outline: none; box-shadow: var(--ring); }
.field.num { text-align: right; font-variant-numeric: tabular-nums; }
select.field { padding-right: 6px; }
.login-card .field { height: 40px; }

.form-card {
  max-width: 720px;
  margin: 16px 0 0;
  padding: 4px 24px 20px;
  border: 1px solid var(--rule);
  border-radius: 14px;
  background: var(--bg);
  box-shadow: 0 4px 18px rgba(31, 33, 37, .05);
}
.form-section {
  margin: 0;
  padding: 18px 0 16px;
  border: 0;
  border-bottom: 1px solid var(--rule);
  min-width: 0;
}
.form-section legend {
  float: left;
  width: 100%;
  margin-bottom: 10px;
  padding: 0;
  font-weight: 600;
}
.form-row {
  clear: both;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px 16px;
}
.form-row label { display: grid; gap: 5px; align-content: start; color: var(--muted); }
.form-row label small { color: var(--muted); }
.form-row .span-2 { grid-column: span 2; }
.form-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  padding-top: 18px;
}
.form-actions .button { height: 36px; padding: 0 18px; }
.form-actions p { flex-basis: 100%; font-size: var(--fs-small); }
.button-link { color: var(--muted); }
.button-link:hover { color: var(--text); }

/* Компактная карточка: форма добавления под таблицей — одной строкой */

.form-card.compact { max-width: 760px; margin-top: 16px; padding: 14px 18px 16px; box-shadow: none; }
.form-title { margin-bottom: 10px; font-weight: 600; }
.form-line { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px 14px; }
.form-line label { display: grid; gap: 5px; color: var(--muted); }
.form-line .w-s { flex: 0 1 120px; }
.form-line .w-date { flex: 0 1 160px; }
.form-line .w-m { flex: 1 1 170px; max-width: 240px; }
.form-line .w-l { flex: 2 1 220px; }
.form-line .button { height: 36px; padding: 0 18px; }
.form-hint { margin-top: 12px; font-size: var(--fs-small); color: var(--muted); }

@media (max-width: 760px) {
  .form-card { padding: 4px 16px 16px; }
  .form-card.compact { padding: 12px 14px 14px; }
  .form-line label { flex-basis: 100%; max-width: none; }
  .filters { width: auto; padding: 12px 14px; }
  .filters .w-m, .filters .w-l { flex: 1 1 100%; }
  .filters .w-date { flex: 1 1 40%; }
  .form-row { grid-template-columns: minmax(0, 1fr); }
  .form-row .span-2 { grid-column: auto; }
}
