/* Дополнения к стилям recoru (static/recoru/ui.css, nav.css) — только то,
   чего там нет: знак этого приложения и разметка страниц на askama.
   Цвета — только через токены recoru (--surface, --text-primary и т. д.). */

/* Знак приложения в левом меню вместо знака-часов recoru. */
.brand.app-brand {
  align-items: center;
  padding: 0 16px;
  gap: 12px;
}

.app-mark {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 2px solid var(--logo-disc-stroke);
  background: var(--logo-disc);
  color: var(--logo-ink);
  font-weight: 700;
  font-size: 18px;
}

.app-name {
  font-weight: 700;
  font-size: 15.5px;
  white-space: nowrap;
  transition: opacity .28s cubic-bezier(.4, 0, .2, 1);
}

html[data-nav=collapsed] .app-name {
  opacity: 0;
}

.mobile-menu .app-mark {
  width: 32px;
  height: 32px;
  font-size: 15px;
}

/* Содержимое страницы внутри .business-page. */
.page-content {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 24px 0 32px;
}

/* Таблицы — в свою высоту; длинная прокручивается внутри, заголовок закреплён
   (правило recoru `flex: 1` делило высоту поровну между таблицами отчёта). */
.page-content > .table-scroll {
  flex: none;
  min-height: 0;
  max-height: calc(100dvh - 120px);
}

/* Основной список страницы — до низа окна: фильтры и заголовок таблицы
   остаются на месте, прокручиваются только строки. */
.page-content:has(> .table-fill) {
  flex: 1 1 auto;
  min-height: 0;
}

.page-content > .table-fill {
  flex: 0 1 auto;
  min-height: 0;
  max-height: none;
}

/* Минимальная высота — только у длинного списка: у короткого рамка
   заканчивается вместе со строками. */
.page-content > .table-fill:has(tbody tr:nth-child(6)) {
  min-height: 240px;
}

/* Закреплённые колонки, как sticky-action / sticky-date в recoru: в списке —
   кнопки строки и следующая за ними колонка, в отчёте — первая колонка.
   Ширину колонки кнопок (1–2 кнопки) ставит app.js в --actions-w. */
.table-scroll table:has(td.row-actions) tr > :first-child {
  position: sticky;
  left: 0;
  z-index: 1;
}

.table-scroll table:has(td.row-actions) tr > :nth-child(2),
.table-scroll table:not(:has(td.row-actions)) tr > :first-child {
  position: sticky;
  left: var(--actions-w, 0px);
  z-index: 1;
  border-right: 1px solid var(--border-subtle);
}

.table-scroll table:not(:has(td.row-actions)) tr > :first-child {
  left: 0;
}

/* Заголовок и итоги — над закреплёнными ячейками строк (та же структура
   селектора, иначе правило выше перебивает z-index). */
.table-scroll table:has(td.row-actions) :is(thead, tfoot) tr > :is(:first-child, :nth-child(2)),
.table-scroll table:not(:has(td.row-actions)) :is(thead, tfoot) tr > :first-child {
  z-index: 4;
}

/* Меню гостя (вход, ошибки): единственная группа — сверху, а не внизу. */
.nav-body .nav-group:only-child {
  margin-top: 0;
}

/* Меню: группа «設定» не прилипает к низу — на невысоком экране она
   закрывала пункты «マスタ», в том числе открытый раздел. */
.nav-body .nav-group:last-child {
  position: static;
  box-shadow: none;
}

.nav-body .nav-links {
  overflow-x: hidden;
}

/* Поле с ошибкой: recoru выделяет только <input>, а у нас ошибка бывает
   и в выборе из списка, календаре и многострочном поле. */
:is(select, textarea, .picker-trigger)[aria-invalid="true"] {
  border-color: var(--danger-fg);
}

/* Уже 960px recoru обрезает страницу (`overflow: hidden`) — у него списки
   прокручиваются внутри таблицы. У нас отчёты и формы длиннее экрана:
   прокручивается вся страница. */
@media (max-width: 959px) {
  .pages > .business-page {
    overflow: visible;
  }
}

.page-lead {
  margin: 0;
  color: var(--text-secondary);
}

.card {
  padding: 16px 20px;
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
}

.page-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
}

/* Таблицы-списки: без широкой минимальной ширины таблиц recoru. */
.list-table table {
  min-width: 0;
  table-layout: auto;
}

.list-table td,
.list-table th {
  white-space: nowrap;
}

.row-inactive td,
.row-inactive th {
  color: var(--text-muted);
}

/* Форма действий карточки (роль, отключение, сброс пароля). */
.form-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 8px 12px;
}

.form-actions .field {
  min-width: 200px;
}

/* Меню учётной записи. */
.account-dialog-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.account-dialog-actions form {
  margin: 0;
}

/* Поиск в списках справочников. */
.search-form {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 8px;
  flex: 1 1 320px;
}

.search-form .field {
  flex: 1 1 180px;
}

.page-actions + .table-scroll,
.page-actions + .card {
  margin-top: 16px;
}

/* Карточка документа: поля в строку, перенос на узком экране. */
.details-list {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 8px 16px;
  margin: 0 0 16px;
}

.details-list dt {
  color: var(--text-muted);
}

.details-list dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.pre-line {
  white-space: pre-line;
}

.doc-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.doc-header,
.doc-line-fields {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px 16px;
}

.doc-header {
  align-items: flex-start;
}

.doc-header .field {
  flex: 1 1 200px;
}

.doc-header .doc-note {
  flex-basis: 100%;
}

.doc-line {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.doc-line legend {
  font-weight: 600;
  padding: 0 4px;
}

.doc-product {
  flex: 2 1 240px;
}

.doc-qty {
  flex: 0 1 110px;
}

.doc-cost {
  flex: 1 1 160px;
}

.doc-line-fields[hidden] {
  display: none;
}

.doc-section-title {
  margin: 24px 0 12px;
}

.doc-pieces input {
  min-width: 96px;
}

.notice + .doc-form,
.notice + .page-actions,
.notice + .details-list {
  margin-top: 16px;
}

/* Кнопка по умолчанию для Enter: невидима и вне порядка табуляции. */
.default-submit {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
  padding: 0;
}

/* Убыток: прибыль строки продажи меньше нуля. */
.loss {
  color: var(--danger-fg);
}

.line-preview {
  margin: 0;
  padding-top: 8px;
  border-top: 1px solid var(--border-subtle);
}

/* Поиск в списке: подсказка («チャネル・顧客・商品名・品番・備考») видна целиком. */
.query-filters input[type="search"] {
  width: 320px;
  max-width: 100%;
}

/* Число с единицей после поля («日»). */
.input-unit {
  display: flex;
  align-items: center;
  gap: 8px;
}

.input-unit input {
  flex: 1;
  min-width: 0;
}

/* `.field` у recoru — flex, он перекрывает атрибут hidden. */
.field[hidden] {
  display: none;
}

/* Поле файла импорта: кнопка, имя файла, рамка для перетаскивания. */
.field-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

.file-drop {
  position: relative;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px;
  border: 1px dashed var(--border-control);
  border-radius: var(--radius-md);
  background: var(--canvas);
  cursor: pointer;
}

.file-drop:hover,
.file-drop.dragging {
  border-color: var(--primary);
  background: var(--surface-hover);
}

.file-drop:focus-within {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

/* Сам <input type=file> скрыт, но остаётся в порядке Tab и в форме. */
.file-drop .file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.file-drop .button {
  flex: none;
  pointer-events: none;
}

.file-drop-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.file-name {
  overflow-wrap: anywhere;
}

.file-name.empty {
  color: var(--text-secondary);
}

/* Ячейки строки файла с заголовками колонок. */
.import-row-table {
  overflow-x: auto;
}

.import-row-table table {
  border-collapse: collapse;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.import-row-table th {
  font-size: 12px;
  font-weight: 400;
  color: var(--text-secondary);
  text-align: left;
  padding: 0 24px 4px 0;
  white-space: nowrap;
}

.import-row-table td {
  padding: 0 24px 0 0;
  white-space: nowrap;
}

/* Предпросмотр импорта. */
.import-cells {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  color: var(--text-secondary);
  font-size: 13px;
}

.import-problem {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border-subtle);
}

.import-problem.undecided > p {
  color: var(--warning-fg);
}

details.card > summary {
  cursor: pointer;
  min-height: 32px;
}

/* Атрибут hidden сильнее display из стилей recoru (.notice и др.). */
[hidden] {
  display: none !important;
}

/* Отчёты. */
.report-filter {
  align-items: flex-end;
}

.report-filter .field {
  flex: 0 1 180px;
}

.report-chart {
  height: 320px;
  margin: 16px 0;
  padding: 8px;
}

/* Кнопка учётной записи с именем — как в recoru (crates/ui/style/entity-picker.css):
   без этого имя шире кнопки 44 px и накрывает переключатель темы. */
.header-actions .account-button {
  width: auto;
  flex: 0 1 auto;
  min-width: 44px;
  max-width: 260px;
}

.account-button .account-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-button > svg {
  flex-shrink: 0;
}

/* У fieldset минимальная ширина — по содержимому: длинные пункты списка
   товаров растягивали карточку строки за край экрана телефона. */
.doc-line {
  min-width: 0;
}

.doc-line select {
  max-width: 100%;
}

/* Главная: показатели месяца и склада. */
.figures {
  display: grid;
  /* auto-fit: карточки растягиваются на всю ширину, как блоки под ними. */
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin: 0 0 12px;
}

.figure dt {
  color: var(--text-secondary);
  font-size: 13px;
}

.figure dd {
  margin: 4px 0 0;
  font-size: 20px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.figure .figure-compare {
  margin-top: 4px;
  font-size: 12px;
  font-weight: 400;
  color: var(--text-secondary);
}

/* Главная: «要確認» — что посмотреть и кнопка к отчёту. */
.home-checks {
  list-style: none;
  margin: 0 0 12px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.home-checks > .notice {
  align-items: center;
  margin: 0;
}

.home-checks > .notice > div {
  flex: 1;
}

.home-checks p {
  margin: 0;
}

.home-shortcuts {
  margin-bottom: 8px;
}

/* Образец цвета канала в списке. */
svg.swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-right: 6px;
  vertical-align: -1px;
}

/* Поле значения у проблемы импорта: подпись в одну строку. */
.import-value {
  flex: 0 1 180px;
}

.import-value label {
  white-space: nowrap;
}

/* Блок «移行期間» на странице импорта: те же отступы, что у карточек форм. */
.card.transition {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card.transition .doc-section-title {
  margin: 0;
}

/* Панель (ТЗ, п. 5.6): форма или содержимое занимает всю высоту панели,
   кнопки действий — внизу, как у Drawer в recoru. */
.drawer-frame > form,
.drawer-frame > .drawer-content {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

/* Строка списка, открытая в панели. Полосы строк recoru заданы правилом
   с высокой специфичностью — выделение должно быть видно поверх них. */
.table-scroll tbody > tr.row-selected > :is(th, td) {
  background: var(--selected-bg) !important;
  color: var(--selected-fg);
}

/* Кнопки строки: просмотр и правка рядом. */
.row-actions {
  width: 1%;
  padding-block: 0;
}

.row-actions .icon-button + .icon-button {
  margin-left: 2px;
}

/* Содержимое панели: разделы, строки документа, вещи. */
.panel-section {
  font-size: 15px;
  margin: 8px 0 0;
}

.panel-items {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  border-top: 1px solid var(--border-subtle);
}

.panel-items > li {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border-subtle);
  overflow-wrap: anywhere;
}

.panel-item-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.panel-item-meta {
  font-size: 13px;
  color: var(--text-secondary);
}

/* Суммы строки в панели: ровная сетка в три колонки, подпись над значением. */
.panel-figures {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px 16px;
  margin: 6px 0 0;
}

.panel-figures > div {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.panel-figures dt {
  font-size: 12px;
  color: var(--text-secondary);
}

.panel-figures dd {
  margin: 0;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

/* Поштучные лоты одного товара — компактной таблицей. */
.lot-table {
  width: 100%;
  margin-top: 6px;
  border-collapse: collapse;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.lot-table th {
  font-size: 12px;
  font-weight: 400;
  color: var(--text-secondary);
  text-align: left;
  padding: 4px 16px 4px 0;
  border-bottom: 1px solid var(--border-subtle);
}

.lot-table td {
  padding: 4px 16px 4px 0;
  border-bottom: 1px solid var(--border-subtle);
}

.lot-table tr:last-child td {
  border-bottom: 0;
}

.lot-table :is(th, td):last-child {
  padding-right: 0;
}

.lot-table .numeric {
  text-align: right;
}

.lot-group > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  cursor: pointer;
}

.lot-group > summary .panel-item-meta {
  margin-left: auto;
  white-space: nowrap;
}

.lot-group > summary::-webkit-details-marker {
  display: none;
}

/* Стрелка раскрытия: вниз — свёрнуто, вверх — раскрыто. */
.lot-group > summary::after {
  content: "";
  flex: none;
  width: 7px;
  height: 7px;
  margin: 0 4px 4px 4px;
  border-right: 2px solid var(--text-secondary);
  border-bottom: 2px solid var(--text-secondary);
  transform: rotate(45deg);
}

.lot-group[open] > summary::after {
  margin-bottom: 0;
  margin-top: 4px;
  transform: rotate(-135deg);
}

/* Несвёрнутая группа — то же место под стрелку, чтобы края сводок совпадали. */
.lot-head::after {
  content: "";
  flex: none;
  width: 9px;
  margin: 0 4px;
}

.lot-head .panel-item-meta {
  margin-left: auto;
}

.lot-group > summary:hover strong {
  text-decoration: underline;
}

/* Цвет канала: палитра браузера и флажок «色を付けない». */
.color-field {
  display: flex;
  align-items: center;
  gap: 16px;
}

.color-field input[type="color"] {
  flex: none;
  width: 56px;
  height: 36px;
  padding: 2px;
  border: 1px solid var(--border-control);
  border-radius: var(--radius-md);
  background: var(--surface);
  cursor: pointer;
}

.check-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 400;
  white-space: nowrap;
  cursor: pointer;
}

/* Общие стили полей recoru дают любому <input> размер 52×40 — флажку свой. */
.check-label input[type="checkbox"] {
  flex: none;
  width: 16px;
  height: 16px;
  min-width: 0;
  min-height: 0;
  margin: 0;
  padding: 0;
  accent-color: var(--primary);
}

.swatch-only {
  display: inline-flex;
  vertical-align: middle;
}

/* Рамка, чтобы тёмный цвет был виден на тёмной теме, светлый — на светлой. */
.swatch rect {
  stroke: var(--border-control);
  stroke-width: 1.5;
}

/* Разбор импорта: действия всегда видны внизу экрана; отмена — справа,
   отдельно от «登録する». */
.import-actions {
  position: sticky;
  bottom: 0;
  z-index: 5;
  margin: 0;
  padding: 12px 0;
  background: var(--canvas);
  border-top: 1px solid var(--border-subtle);
}

.import-actions .actions-end {
  margin-left: auto;
}

/* Разбивка лота: вещи сеткой — подписи колонок один раз, строка на вещь. */
.split-pieces {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.split-head,
.split-row {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) minmax(0, 0.7fr) minmax(0, 1fr) minmax(0, 1.6fr);
  gap: 6px;
  align-items: center;
}

.split-head {
  font-size: 12px;
  color: var(--text-secondary);
}

.split-number {
  font-size: 13px;
  color: var(--text-secondary);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.split-row .field {
  min-width: 0;
}

.split-row input {
  min-width: 0;
  padding-inline: 8px;
}

.split-row .picker-trigger {
  padding-inline: 8px;
}

/* Подвал формы: вспомогательное действие («計算») слева, キャンセル и
   подтверждение — справа (как в recoru). */
.dialog-footer .footer-start {
  margin-right: auto;
}

/* Итог после возвратов в карточке продажи. */
.details-list .figure-total {
  font-weight: 600;
}

/* Способ учёта товара в строке закупки. */
.mode-badge {
  flex: none;
  font-size: 12px;
  color: var(--text-secondary);
  background: var(--surface-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  padding: 1px 8px;
  white-space: nowrap;
}

.panel-line {
  display: flex;
  flex-direction: column;
  gap: 12px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 12px;
}

.panel-line .new-product {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.panel-line .new-product[hidden] {
  display: none;
}

.panel-pair {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.panel-piece {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 12px;
  padding-top: 8px;
  border-top: 1px dashed var(--border-subtle);
}

.panel-piece-number,
.panel-piece-wide {
  grid-column: 1 / -1;
}

.panel-piece-number {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}

.panel-line-remove {
  align-self: flex-start;
}

.query-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
}

.query-filters .field {
  min-width: 200px;
}

/* Кнопка добавления — справа в той же строке (как в recoru): при нехватке
   места переносятся поля фильтров внутри своего блока, а не кнопка. */
@media (min-width: 960px) {
  .business-page .query-toolbar:has(> .query-filters) {
    flex-wrap: nowrap;
  }

  .query-toolbar > .query-filters {
    flex: 0 1 auto;
    min-width: 0;
  }

  .query-toolbar > .button {
    flex: none;
  }
}

/* Справка: .help-layout сама задаёт отступы, как в recoru, где она лежит
   прямо в .pages; отступы .business-page и .page-content не добавляются. */
.business-page[data-page="help"] {
  padding: 0;
}

.business-page[data-page="help"] > .page-content {
  padding: 0;
}

/* Сводка «集計» по элементу справочника (ТЗ, п. 8.1): блок в панели и
   широкий диалог. Диалог из панели — по центру окна, как справка. */
.panel-summary {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--border-subtle);
}

.panel-summary > .button {
  align-self: flex-start;
}

.summary-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.summary-head select {
  width: auto;
}

.drawer dialog.dialog-wide {
  margin: auto;
}

.summary-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Прокручивается тело диалога, а не сжимаются график и таблицы. */
.summary-body > * {
  flex: none;
}

.summary-body .report-chart {
  height: 280px;
  margin: 0;
}

.summary-body .summary-head {
  justify-content: flex-start;
  align-items: flex-end;
}

.summary-body .summary-head .hint {
  margin: 0 0 8px;
}

.summary-figures {
  grid-template-columns: repeat(6, minmax(0, 1fr));
}

@media (max-width: 767px) {
  .summary-figures {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}
