/* ============================================================
   Atriella УТ — оформление «Реестр»
   Светлая тема по умолчанию; тёмная включается через
   <html data-theme="dark"> (переключатель в полосе состояния).
   ============================================================ */

:root {
  /* поверхности */
  --bg: #f6f8f7;
  --sidebar: #f0f3f1;
  --surface: #ffffff;
  --surface-2: #fafbfa;
  --surface-3: #eef2f0;
  --zebra: #fafbfa;
  --hover: rgba(20, 33, 27, .05);
  --select: #e7f2ec;

  /* линии */
  --line: #e2e7e4;
  --line-strong: #cdd6d1;

  /* текст */
  --ink: #14211b;
  --ink-2: #3d4b45;
  --muted: #6f7f78;

  /* фирменный акцент */
  --brand: #1f6f4f;
  --brand-ink: #17573e;
  --brand-on: #ffffff;
  --brand-soft: #e7f2ec;
  --brand-soft-2: #d5e8de;
  --link: #1f6f4f;

  /* состояния */
  --ok: #15803d;     --ok-soft: #e8f5ec;
  --warn: #b45309;   --warn-soft: #fdf3e3;
  --danger: #b91c1c; --danger-soft: #fdecec;

  --shadow-pop: 0 10px 28px rgba(20, 33, 27, .14);
  --radius: 6px;
  --radius-sm: 4px;
  --ribbon-h: 44px;

  /* совместимость с прежними именами токенов */
  --card: var(--surface);
  --text: var(--ink);
  --accent: var(--brand);
  --accent2: var(--link);
  --border: var(--line);

  color-scheme: light;
}

[data-theme="dark"] {
  --bg: #0f1419;
  --sidebar: #151b22;
  --surface: #1a222c;
  --surface-2: #1f2731;
  --surface-3: #232c37;
  --zebra: rgba(255, 255, 255, .02);
  --hover: rgba(255, 255, 255, .06);
  --select: rgba(110, 231, 183, .14);

  --line: rgba(255, 255, 255, .10);
  --line-strong: rgba(255, 255, 255, .22);

  --ink: #e8eef4;
  --ink-2: #c3ced9;
  --muted: #8b9aab;

  --brand: #6ee7b7;
  --brand-ink: #9df0cd;
  --brand-on: #10231c;
  --brand-soft: rgba(110, 231, 183, .14);
  --brand-soft-2: rgba(110, 231, 183, .22);
  --link: #93c5fd;

  --ok: #6ee7b7;     --ok-soft: rgba(110, 231, 183, .14);
  --warn: #fbbf24;   --warn-soft: rgba(251, 191, 36, .14);
  --danger: #f87171; --danger-soft: rgba(248, 113, 113, .14);

  --shadow-pop: 0 10px 28px rgba(0, 0, 0, .5);

  color-scheme: dark;
}

* { box-sizing: border-box; }
html { font-size: 14px; }
body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }

/* --- числовые и кодовые форматы --- */
.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.code, .mono {
  font-family: ui-monospace, "Cascadia Mono", "SF Mono", Consolas, "Liberation Mono", monospace;
  font-size: .84rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.01em;
}

/* ============================================================
   Каркас: полоса состояния + сайдбар + рабочая область
   ============================================================ */
.shell { display: flex; flex-direction: column; min-height: 100vh; }

.ribbon {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  min-height: var(--ribbon-h);
  padding: .35rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.ribbon__id { display: flex; align-items: baseline; gap: .6rem; min-width: 0; }
.ribbon__brand {
  font-size: .72rem; font-weight: 700; letter-spacing: .12em;
  text-transform: uppercase; color: var(--brand);
}
.ribbon__path {
  font-size: .82rem; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ribbon__path b { color: var(--ink); font-weight: 600; }
.ribbon__metrics {
  display: flex; align-items: center; gap: 1.35rem;
  margin-left: auto; flex-wrap: wrap;
}
.metric { display: flex; align-items: baseline; gap: .45rem; white-space: nowrap; }
.metric__label {
  font-size: .7rem; letter-spacing: .06em; text-transform: uppercase; color: var(--muted);
}
.metric__value { font-size: .9rem; font-weight: 650; font-variant-numeric: tabular-nums; }
.metric__value.is-danger { color: var(--danger); }
.metric__value.is-ok { color: var(--ok); }
.metric__value.is-muted { color: var(--muted); font-weight: 500; }
a.metric { text-decoration: none; }
a.metric:hover .metric__value { color: var(--brand); }
a.metric:hover .metric__label { color: var(--ink-2); }

.theme-toggle {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .28rem .6rem; border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong); background: var(--surface);
  color: var(--ink-2); font: inherit; font-size: .76rem; cursor: pointer;
}
.theme-toggle::before { content: '◐'; font-size: .85rem; line-height: 1; }
.theme-toggle:hover { border-color: var(--brand); color: var(--brand); }

/* Иконки в полосе состояния: почта и уведомления со счётчиком. */
.ribbon__icons { display: inline-flex; align-items: center; gap: .3rem; }
.icon-btn {
  position: relative;
  display: inline-flex; align-items: center; justify-content: center;
  width: 1.95rem; height: 1.95rem;
  border-radius: var(--radius-sm); border: 1px solid transparent;
  color: var(--ink-2); text-decoration: none;
}
.icon-btn:hover {
  background: var(--hover); border-color: var(--line);
  color: var(--brand); text-decoration: none;
}
.icon-btn svg { width: 18px; height: 18px; display: block; }
.icon-btn__count {
  position: absolute; top: -.15rem; right: -.15rem;
  min-width: 1.05rem; height: 1.05rem; padding: 0 .25rem;
  border-radius: 999px; background: var(--danger); color: #fff;
  font-size: .68rem; font-weight: 700; line-height: 1.05rem; text-align: center;
  border: 2px solid var(--surface); box-sizing: content-box;
}

.app { display: grid; grid-template-columns: 264px minmax(0, 1fr); flex: 1 1 auto; }

.sidebar {
  background: var(--sidebar);
  border-right: 1px solid var(--line);
  padding: .7rem .55rem 1rem;
  position: sticky; top: var(--ribbon-h);
  height: calc(100vh - var(--ribbon-h));
  /* Прокручивается только список разделов, подвал с пользователем закреплён */
  overflow: hidden;
  display: flex; flex-direction: column;
}
.brand {
  flex: 0 0 auto;
  display: flex; align-items: center; gap: .55rem;
  color: var(--ink); font-weight: 650; font-size: .95rem;
  padding: .3rem .5rem .7rem; text-decoration: none;
}
.brand:hover { text-decoration: none; }

/* --- дерево объектов --- */
.nav-tree {
  display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0;
  /* Свой скролл: длинный список не вылезает на блок пользователя */
  overflow-y: auto; overflow-x: hidden;
  scrollbar-width: thin;
}
.nav-search { margin-bottom: .45rem; }
.nav-search input { font-size: .8rem; padding: .35rem .5rem; }

.nav-group { border: 0; }
.nav-group + .nav-group { margin-top: .3rem; border-top: 1px solid var(--line); padding-top: .3rem; }
.nav-group__title {
  display: flex; align-items: center; gap: .35rem;
  margin: 0; padding: .35rem .5rem;
  font-size: .68rem; font-weight: 700; letter-spacing: .09em; text-transform: uppercase;
  color: var(--muted); cursor: pointer; list-style: none; user-select: none;
  border-radius: var(--radius-sm);
}
.nav-group__title::-webkit-details-marker { display: none; }
.nav-group__title::before {
  content: '▸'; font-size: .68rem; transition: transform .15s ease;
}
.nav-group[open] > .nav-group__title::before { transform: rotate(90deg); }
.nav-group__title:hover { color: var(--ink-2); background: var(--hover); }

.nav-item {
  display: block;
  padding: .34rem .5rem .34rem 1.1rem; margin: .05rem 0;
  border-radius: var(--radius-sm); border-left: 2px solid transparent;
  color: var(--ink-2); font-size: .84rem; text-decoration: none;
}
.nav-item:hover { background: var(--hover); color: var(--ink); text-decoration: none; }
.nav-item.is-active {
  background: var(--brand-soft); border-left-color: var(--brand);
  color: var(--brand); font-weight: 600;
}
.nav-empty { padding: .5rem .5rem; font-size: .8rem; color: var(--muted); }
.nav-section {
  margin: .8rem .5rem .3rem; font-size: .68rem; letter-spacing: .09em;
  text-transform: uppercase; color: var(--muted);
}

.sidebar-user {
  flex: 0 0 auto;
  position: relative; z-index: 1;
  background: var(--sidebar);
  margin-top: .7rem; padding: .7rem .5rem .2rem;
  border-top: 1px solid var(--line); font-size: .84rem;
}
.sidebar-user__name { font-weight: 600; margin-bottom: .15rem; }
.sidebar-user__meta, .sidebar-user__roles { font-size: .76rem; line-height: 1.35; }
.sidebar-user__roles { margin-top: .2rem; }
.sidebar-user__logout { display: inline-block; margin-top: .5rem; font-size: .8rem; }

/* --- рабочая область --- */
.main { --thead-top: var(--ribbon-h); padding: 1rem 1.25rem 2.5rem; min-width: 0; }
.top { display: flex; align-items: baseline; gap: .7rem; flex-wrap: wrap; margin: 0 0 .8rem; }
.top h1 { margin: 0; font-size: 1.15rem; font-weight: 650; letter-spacing: -.01em; }
.content { min-width: 0; }

.flash {
  margin: 0 0 .85rem; padding: .65rem .85rem; border-radius: var(--radius);
  background: var(--ok-soft); border: 1px solid var(--ok); color: var(--ok);
  line-height: 1.45; font-size: .86rem; max-width: none;
}
.flash-notice { white-space: normal; word-break: break-word; }

/* ============================================================
   Панели, показатели, кнопки, инструменты
   ============================================================ */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: .8rem .95rem; margin-bottom: .8rem;
}
.card > h3 { font-weight: 650; letter-spacing: -.01em; }

/* список документов с собственной прокруткой и липкой шапкой */
.card--scroll {
  overflow: auto; max-height: calc(100vh - 13rem); --thead-top: 0;
}

/* Прокручиваемая обёртка вокруг таблицы. Внутри неё шапка липнет к самой
   обёртке, поэтому отступ липкости нужно обнулить: иначе он берётся из
   .main (высота верхней панели) и шапка накрывает первую строку. */
.table-scroll { overflow: auto; --thead-top: 0; }

/* Строка кода, который правится не здесь (GTIN ведёт раздел «Маркировка»):
   приглушённый фон подсказывает, что полей для правки в ней нет. */
.code-row--marking > td { background: var(--surface-2); }

/* Письмо: разметка почищена, но чужие стили всё равно могут ломать вид,
   поэтому показываем её в собственных границах. */
.mail-body {
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: .8rem .9rem; background: var(--surface); overflow: auto;
  max-height: 60vh; font-size: .9rem; line-height: 1.5;
}
.mail-body img { max-width: 100%; height: auto; }
.mail-body table { width: auto; max-width: 100%; border-collapse: collapse; font-size: inherit; }
.mail-body table th, .mail-body table td { border: 0; padding: .25rem .4rem; vertical-align: top; }
.mail-body a { color: var(--link); }
.mail-body h1, .mail-body h2, .mail-body h3 { font-size: 1.05rem; margin: .6rem 0 .35rem; }
.mail-body p { margin: .5rem 0; }

.mail-body__plain {
  white-space: pre-wrap; word-break: break-word; font: inherit; margin: 0;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: .8rem .9rem; background: var(--surface-2); max-height: 60vh; overflow: auto;
}

/* Пометка «маркировка» у кода, которым управляет раздел «Маркировка» */
.mark-badge {
  display: inline-block; margin-top: .15rem; padding: .05rem .35rem;
  border: 1px solid var(--line-strong); border-radius: .35rem;
  font-size: .68rem; color: var(--muted); background: var(--surface); white-space: nowrap;
}

.kpi-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(185px, 1fr));
  gap: .7rem; margin-bottom: .8rem;
}
.kpi {
  background: var(--surface); border: 1px solid var(--line);
  border-left: 3px solid var(--line-strong);
  border-radius: var(--radius); padding: .7rem .85rem;
}
.kpi--brand { border-left-color: var(--brand); }
.kpi--ok { border-left-color: var(--ok); }
.kpi--danger { border-left-color: var(--danger); }
.kpi__label {
  font-size: .68rem; letter-spacing: .07em; text-transform: uppercase; color: var(--muted);
}
.kpi__value {
  font-size: 1.35rem; font-weight: 650; letter-spacing: -.01em;
  font-variant-numeric: tabular-nums; margin: .25rem 0 .3rem;
}
.kpi__hint { font-size: .76rem; color: var(--muted); }
.kpi__hint a { color: var(--link); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: .7rem; }
.stats > .card { margin-bottom: 0; }
.stat {
  font-size: 1.35rem; font-weight: 650; letter-spacing: -.01em;
  font-variant-numeric: tabular-nums; margin: .2rem 0 .35rem;
}

.facts { display: flex; flex-wrap: wrap; gap: .35rem .45rem; }
.fact {
  display: inline-flex; align-items: baseline; gap: .4rem;
  padding: .28rem .6rem; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--surface-2);
  color: var(--ink-2); font-size: .82rem; text-decoration: none;
}
.fact:hover { border-color: var(--brand); color: var(--brand); text-decoration: none; }
.fact__value { font-weight: 650; font-variant-numeric: tabular-nums; color: var(--ink); }
.fact:hover .fact__value { color: var(--brand); }

.toolbar { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: .8rem; align-items: center; }

.btn {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .4rem .8rem; border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong); background: var(--surface);
  color: var(--ink); cursor: pointer; font: inherit; font-size: .84rem; text-decoration: none;
}
.btn:hover { border-color: var(--brand); color: var(--brand); text-decoration: none; }
.btn-primary {
  background: var(--brand); border-color: var(--brand);
  color: var(--brand-on); font-weight: 600;
}
.btn-primary:hover { background: var(--brand-ink); border-color: var(--brand-ink); color: var(--brand-on); }
.btn-danger { color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); color: var(--danger); border-color: var(--danger); }
.btn-sm { padding: .22rem .5rem; font-size: .78rem; }
.btn-copy {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 1.9rem; padding: .3rem .5rem; font-size: .92rem; line-height: 1;
  border-radius: var(--radius-sm); border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--link); cursor: pointer; text-decoration: none;
}
.btn-copy:hover { border-color: var(--brand); color: var(--brand); text-decoration: none; }
.btn-link {
  display: inline; background: none; border: 0; padding: 0 .1rem;
  color: var(--link); cursor: pointer; font: inherit; font-size: .9rem; line-height: 1;
}
.btn-link:hover { color: var(--brand-ink); text-decoration: underline; }

/* ============================================================
   Таблицы — основной носитель данных
   ============================================================ */
table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: .86rem; }
th, td { text-align: left; padding: .42rem .55rem; vertical-align: top; }
thead th {
  position: sticky; top: var(--thead-top, 0); z-index: 3;
  background: var(--surface-2); color: var(--muted);
  font-size: .72rem; font-weight: 650; letter-spacing: .02em;
  border-bottom: 1px solid var(--line-strong); white-space: nowrap;
}
tbody td { border-bottom: 1px solid var(--line); }
tbody tr:nth-child(even) > td { background: var(--zebra); }
tbody tr:hover > td { background: var(--hover); }
tbody tr:last-child > td { border-bottom: 0; }
.table.compact td, .table.compact th { padding: .3rem .5rem; font-size: .82rem; }

tr.totals > td, tfoot > tr > td, tfoot > tr > th {
  border-top: 2px solid var(--line-strong); border-bottom: 0;
  background: var(--surface-2); font-weight: 650;
}
.row-warn td { color: var(--warn); }

/* ============================================================
   Статусы
   ============================================================ */
.dot {
  display: inline-flex; align-items: center; gap: .4rem;
  font-size: .8rem; white-space: nowrap; color: var(--ink-2);
}
.dot::before {
  content: ''; flex: 0 0 auto; width: 7px; height: 7px;
  border-radius: 50%; background: currentColor;
}
.dot--ok { color: var(--ok); }
.dot--warn { color: var(--warn); }
.dot--danger { color: var(--danger); }
.dot--muted { color: var(--muted); }

.badge {
  display: inline-block; padding: .08rem .48rem; border-radius: 999px;
  background: var(--surface-3); border: 1px solid var(--line);
  color: var(--ink-2); font-size: .74rem; font-weight: 600; white-space: nowrap;
}
.badge--ok { background: var(--ok-soft); border-color: var(--ok); color: var(--ok); }
.badge--warn { background: var(--warn-soft); border-color: var(--warn); color: var(--warn); }
.badge--danger { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }

/* ============================================================
   Формы
   ============================================================ */
label { display: block; font-size: .78rem; color: var(--muted); margin-bottom: .25rem; }
input, select, textarea {
  width: 100%; padding: .4rem .55rem; border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong); background: var(--surface);
  color: var(--ink); font: inherit; font-size: .86rem;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft);
}
textarea { min-height: 90px; resize: vertical; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .75rem .9rem; }
.form-grid .full { grid-column: 1 / -1; }
.checks { display: flex; flex-wrap: wrap; gap: .7rem 1.1rem; }
.checks label { display: flex; align-items: center; gap: .4rem; color: var(--ink); font-size: .86rem; margin: 0; }
.checks input { width: auto; }
.muted { color: var(--muted); }
.help { font-size: .78rem; color: var(--muted); margin-top: .25rem; }

/* ============================================================
   Сообщения и состояния
   ============================================================ */
.blocker {
  padding: .7rem .9rem; border-radius: var(--radius);
  margin-bottom: .8rem; border: 1px solid var(--line); background: var(--surface);
}
.blocker-danger { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }
.blocker-warn { background: var(--warn-soft); border-color: var(--warn); color: var(--warn); }
.blocker-ok { background: var(--ok-soft); border-color: var(--ok); color: var(--ok); }
.blocker-muted { background: var(--surface-3); border-color: var(--line); color: var(--muted); }
.stage-list { list-style: none; padding: 0; margin: 0; font-size: .86rem; }
.stage-list li { padding: .18rem 0; }
.stage-list li.ok { color: var(--ok); }
.stage-list li.no { color: var(--muted); }

/* ============================================================
   Пакеты документов, загрузка файлов, галерея
   ============================================================ */
.doc-package {
  margin-top: .7rem; border: 1px solid var(--line);
  border-radius: var(--radius); background: var(--surface-2);
}
.doc-package:first-of-type { margin-top: .45rem; }
.doc-package__title {
  display: flex; align-items: center; gap: .35rem; flex-wrap: wrap;
  margin: 0; padding: .5rem .7rem; font-size: .86rem; font-weight: 650;
  cursor: pointer; list-style: none; user-select: none;
}
.doc-package__title::-webkit-details-marker { display: none; }
.doc-package__title::before {
  content: '▸'; flex: 0 0 auto; font-size: .75rem; color: var(--muted);
  transition: transform .15s ease;
}
.doc-package[open] > .doc-package__title::before { transform: rotate(90deg); }
.doc-package__title:hover { background: var(--hover); }
.doc-package__title .muted { font-weight: 400; font-size: .8rem; }
.doc-package__body { padding: 0 .6rem .6rem; }
.doc-package .table { margin-bottom: 0; }

.doc-dropzone {
  border: 2px dashed var(--brand); border-radius: var(--radius);
  padding: 1.75rem 1.1rem; text-align: center; cursor: pointer;
  transition: border-color .15s, background .15s;
  background: var(--brand-soft);
}
.doc-dropzone:hover, .doc-dropzone.is-dragover {
  border-color: var(--brand-ink); background: var(--brand-soft-2);
}
.doc-dropzone.is-loading { opacity: .7; pointer-events: none; }
.doc-dropzone__icon { font-size: 1.9rem; line-height: 1; margin-bottom: .45rem; }
.doc-dropzone__title { font-weight: 650; margin-bottom: .3rem; }
.doc-dropzone__hint { margin: 0 0 .7rem; font-size: .84rem; }
.doc-dropzone__pick {
  margin: 0; display: flex; align-items: center; justify-content: center;
  gap: .5rem; flex-wrap: wrap;
}
.doc-dropzone__link {
  background: none; border: none; color: var(--link); cursor: pointer;
  font: inherit; padding: 0; text-decoration: underline;
}
.doc-dropzone__link:hover { color: var(--brand-ink); }
.doc-dropzone__status { margin: .7rem 0 0; font-size: .82rem; }
.doc-upload-form { margin-bottom: .85rem; }

.thumb { width: 40px; height: 40px; object-fit: cover; border-radius: var(--radius-sm); background: var(--surface-3); }
.list-thumb { width: 42px; height: 42px; object-fit: cover; border-radius: var(--radius-sm); background: var(--surface-3); display: block; }
.list-thumb--empty {
  display: inline-flex; align-items: center; justify-content: center;
  width: 42px; height: 42px; border-radius: var(--radius-sm);
  border: 1px dashed var(--line-strong); color: var(--muted); font-size: .82rem;
}
.gallery-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: .7rem;
}
.gallery-item {
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
  background: var(--surface-2); position: relative;
}
.gallery-item.is-dragging { opacity: .55; }
.gallery-drag-handle {
  position: absolute; top: .3rem; left: .3rem; z-index: 3;
  display: inline-flex; align-items: center; justify-content: center;
  width: 1.55rem; height: 1.55rem; border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong); background: var(--surface);
  color: var(--muted); cursor: grab; font-size: .72rem; line-height: 1;
  user-select: none; touch-action: none;
}
.gallery-drag-handle:active { cursor: grabbing; color: var(--brand); }
.gallery-item.is-drop-before { box-shadow: inset 3px 0 0 var(--brand); }
.gallery-item.is-drop-after { box-shadow: inset -3px 0 0 var(--brand); }
.gallery-item.is-pending { border-style: dashed; opacity: .95; }
.gallery-item.is-pending .gallery-item__link { cursor: default; }
.gallery-item__primary {
  display: inline-flex; align-items: center; gap: .3rem; margin: 0;
  cursor: pointer; font-size: .76rem; color: var(--ink);
}
.gallery-item__primary input { width: auto; margin: 0; }
.gallery-item.is-primary { border-color: var(--brand); box-shadow: inset 0 0 0 1px var(--brand-soft-2); }
.gallery-item__link { display: block; aspect-ratio: 1; background: var(--surface-3); }
.gallery-item__link img { width: 100%; height: 100%; object-fit: cover; display: block; }
.gallery-item__meta {
  display: flex; align-items: center; justify-content: space-between; gap: .35rem;
  padding: .4rem .45rem; border-top: 1px solid var(--line);
}
.gallery-item__meta form { margin: 0; }
.gallery-item__name {
  padding: 0 .45rem .4rem; font-size: .74rem; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ============================================================
   Строки документов: поиск поверх таблицы
   ============================================================ */
.doc-lines { overflow: visible; position: relative; }
.doc-lines table { position: relative; overflow: visible; }
.doc-lines td, .doc-lines th { overflow: visible; }
.doc-lines tr.is-searching { position: relative; z-index: 80; background: var(--surface); }
.doc-lines tr.is-searching td { background: var(--surface); }
.line-name-wrap {
  position: relative; display: flex; align-items: center; gap: .35rem;
  min-width: 12rem; z-index: 1;
}
tr.is-searching .line-name-wrap { z-index: 90; }
.line-name-text { flex: 1; min-width: 0; }
.line-edit { flex: 0 0 auto; font-size: .95rem; line-height: 1; padding: 0 .15rem; opacity: .7; }
.line-edit:hover { opacity: 1; }
.line-name-search { width: 100%; min-width: 12rem; font: inherit; }
.po-search-results {
  position: absolute; z-index: 100; left: 0; right: 0;
  top: calc(100% + 2px);
  background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm); max-height: 240px; overflow: auto;
  min-width: 18rem; box-shadow: var(--shadow-pop);
}
.po-search-item {
  display: block; width: 100%; text-align: left;
  padding: .5rem .7rem; border: 0; border-bottom: 1px solid var(--line);
  background: transparent; color: var(--ink); cursor: pointer;
  font: inherit; line-height: 1.35;
}
.po-search-item:last-child { border-bottom: 0; }
.po-search-item:hover, .po-search-item:focus-visible { background: var(--hover); outline: none; }

/* ============================================================
   Диалог печати
   ============================================================ */
.print-menu-wrap { display: inline-flex; align-items: center; }
.print-dialog {
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  padding: 0; width: min(560px, calc(100vw - 2rem)); max-width: 560px;
  background: var(--surface); color: var(--ink); box-shadow: var(--shadow-pop);
}
.print-dialog::backdrop { background: rgba(20, 33, 27, .38); }
.print-dialog__form { display: flex; flex-direction: column; gap: 0; }
.print-dialog__title { margin: 0; padding: .9rem 1.1rem .7rem; font-size: 1rem; font-weight: 650; }
.print-dialog__hint { margin: 0; padding: 0 1.1rem .7rem; font-size: .86rem; }
.print-dialog__table { width: 100%; border-collapse: collapse; font-size: .86rem; }
.print-dialog__table thead th {
  position: static; text-align: left; padding: .45rem 1rem;
  border-bottom: 1px solid var(--line-strong); background: var(--surface-2); font-weight: 650;
}
.print-dialog__table tbody td { padding: .4rem 1rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
.print-dialog__table tbody tr:last-child td { border-bottom: none; }
.print-dialog__table tbody tr:hover td { background: var(--hover); }
.print-dialog__check { width: 72px; text-align: center; vertical-align: middle; }
.print-dialog__check input { width: 16px; height: 16px; cursor: pointer; }
.print-dialog__actions {
  display: flex; gap: .5rem; justify-content: flex-end;
  padding: .7rem 1.1rem .9rem; border-top: 1px solid var(--line);
}

/* ============================================================
   Адаптив
   ============================================================ */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: relative; top: 0; height: auto; overflow: visible; }
  .nav-tree { overflow: visible; }
  .form-grid { grid-template-columns: 1fr; }
  .ribbon { gap: .5rem; padding: .4rem .8rem; }
  .ribbon__metrics { margin-left: 0; gap: 1rem; }
  .main { --thead-top: 0; padding: .85rem .8rem 2rem; }
  .card--scroll { max-height: none; }
}

/* Переписка: каждое письмо — сворачиваемый блок. */
.mail-thread__item > summary {
  cursor: pointer; display: flex; gap: .8rem; align-items: baseline; flex-wrap: wrap;
  font-size: .92rem; margin: -.2rem 0;
}
.mail-thread__item > summary::marker { color: var(--muted); }
.mail-thread__item[open] > summary { margin-bottom: .4rem; }
.mail-thread__who { font-weight: 650; }

/* Ответ: исходное письмо — отдельным свёрнутым блоком, под формой.
   В отправляемый текст оно не подставляется, поэтому длинное письмо
   при раскрытии прокручивается внутри блока, а не растягивает страницу. */
.mail-original { margin-top: .8rem; }
.mail-original > summary {
  cursor: pointer; display: flex; gap: .8rem; align-items: baseline; flex-wrap: wrap;
  font-size: .92rem; margin: -.2rem 0;
}
.mail-original > summary::marker { color: var(--muted); }
.mail-original[open] > summary { margin-bottom: .4rem; }
.mail-original[open] { max-height: 32rem; overflow: auto; }

/* --- отчёты --- */
.report-group td {
  background: var(--surface-2);
  font-weight: 600;
  padding-top: .5rem;
}
.report-total td {
  background: var(--surface-2);
  font-weight: 600;
  border-top: 1px solid var(--line);
}
.report-total td.num, td.num { text-align: right; }

/* Сроки годности партий */
.batch-soon td { background: #fff7ed; }
.batch-expired td { background: #fef2f2; color: #991b1b; }
