/* Тёмная тема интерфейса.

   Печатные формы к этим стилям не подключены: документы уходят клиенту
   и печатаются на бумаге, там своя светлая вёрстка. */
:root {
  --bg: #0a1017;           /* фон страницы */
  --panel: #111a24;        /* карточки */
  --panel-2: #0d151d;      /* боковое меню */
  --panel-hi: #16202c;     /* подсветка строк и наведение */
  --line: #1e2a37;         /* границы */
  --line-soft: #17212c;

  --ink: #e8eef4;          /* основной текст */
  --ink-dim: #c3cedb;      /* текст в таблицах */
  --muted: #8593a4;        /* подписи и второстепенное */

  --accent: #2dd4bf;       /* бирюзовый акцент */
  --accent-ink: #04262b;   /* текст на бирюзовом */
  --accent-soft: rgba(45, 212, 191, 0.13);
  --accent-line: rgba(45, 212, 191, 0.35);

  --ok: #34d399;
  --warn: #fbbf24;
  --danger: #f87171;
  --violet: #a78bfa;

  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Fira Sans Condensed", "Inter", -apple-system, "Segoe UI", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

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

::selection { background: var(--accent-soft); }

/* ---------- каркас ---------- */
.layout { display: flex; min-height: 100vh; }

.side {
  width: 252px;
  flex: 0 0 252px;
  background: var(--panel-2);
  border-right: 1px solid var(--line);
  padding: 16px 0;
  display: flex;
  flex-direction: column;
}
.side .brand {
  font-weight: 700;
  font-size: 17px;
  letter-spacing: 0.02em;
  padding: 0 18px 14px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 10px;
  color: var(--ink);
}
.side .brand::before {
  content: "";
  display: inline-block;
  width: 8px; height: 8px;
  margin-right: 9px;
  border-radius: 2px;
  background: linear-gradient(135deg, var(--accent), var(--ok));
  vertical-align: middle;
}
.side nav > a {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 8px 18px;
  color: var(--ink-dim);
  border-left: 3px solid transparent;
}
.side nav > a:hover { background: var(--panel-hi); color: var(--ink); text-decoration: none; }
.side nav > a.on {
  border-left-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}
.ic { width: 17px; height: 17px; flex: 0 0 17px; opacity: 0.85; }

/* ---------- цепочка документов в меню ---------- */
.flow {
  margin: 8px 12px;
  padding: 6px 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(45, 212, 191, 0.04);
}
.flow .step {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 11px;
  padding: 7px 12px;
  color: var(--ink-dim);
}
.flow .step:hover { color: var(--ink); text-decoration: none; }
.flow .step .num {
  position: relative;
  z-index: 1;
  flex: 0 0 22px;
  width: 22px; height: 22px;
  margin-top: 1px;
  border-radius: 50%;
  border: 1.5px solid var(--accent-line);
  background: var(--panel-2);
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
/* соединительная линия между шагами */
.flow .step:not(.last)::before {
  content: "";
  position: absolute;
  left: 22px;
  top: 26px;
  bottom: -4px;
  width: 1.5px;
  background: var(--accent-line);
}
.flow .step .txt { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.flow .step .txt b { font-weight: 600; font-size: 14px; white-space: nowrap; }
.flow .step .txt i {
  font-style: normal;
  font-size: 11.5px;
  color: var(--muted);
  margin-top: 1px;
}
.flow .step.on { color: var(--accent); }
.flow .step.on .num { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.flow .step.on .txt b { color: var(--accent); }

.flow .step-row { display: flex; align-items: flex-start; }
.flow .step-row .step { flex: 1; min-width: 0; }
.flow .chev {
  flex: 0 0 30px;
  margin: 9px 8px 0 0;
  padding: 2px;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  border-radius: 6px;
}
.flow .chev:hover { color: var(--ink); background: var(--panel-hi); }
.flow .chev .ic { transition: transform 0.15s; }
.flow.cn-open .chev .ic { transform: rotate(180deg); }

.flow .substep {
  display: none;
  align-items: center;
  gap: 10px;
  padding: 6px 12px 8px 45px;
  font-size: 13.5px;
  color: var(--muted);
}
.flow.cn-open .substep { display: flex; }
.flow .substep:hover { color: var(--ink); text-decoration: none; }
.flow .substep.on { color: var(--accent); font-weight: 600; }
.flow .substep .ic { width: 15px; height: 15px; flex: 0 0 15px; }

/* ---------- раскрывающийся раздел меню ---------- */
.group-head {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  padding: 8px 18px;
  border: 0;
  border-left: 3px solid transparent;
  background: transparent;
  color: var(--ink-dim);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.group-head span { flex: 1; }
.group-head:hover { background: var(--panel-hi); color: var(--ink); }
.group-head.on {
  border-left-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}
.group-head .ic:last-child { transition: transform 0.15s; opacity: 0.6; }
.group.open .group-head .ic:last-child { transform: rotate(180deg); }

/* Цепочка документов живёт внутри раздела «Продажи» и прячется вместе с ним */
.group .flow { display: none; }
.group.open .flow { display: block; }

.group .subitem {
  display: none;
  align-items: center;
  gap: 10px;
  padding: 6px 18px 6px 42px;
  font-size: 13.5px;
  color: var(--muted);
}
.group.open .subitem { display: flex; }
.group .subitem:hover { color: var(--ink); text-decoration: none; background: var(--panel-hi); }
.group .subitem.on { color: var(--accent); font-weight: 600; }
.group .subitem .ic { width: 15px; height: 15px; flex: 0 0 15px; }

.side .sep { height: 1px; background: var(--line); margin: 10px 14px; }
.side .foot { margin-top: auto; padding: 12px 18px; font-size: 13px; color: var(--muted); }

.main { flex: 1; padding: 22px 26px 60px; min-width: 0; }

.head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 16px; margin-bottom: 16px;
}
h1 { font-size: 23px; margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h2 { font-size: 16px; margin: 22px 0 10px; font-weight: 600; }

/* ---------- элементы ---------- */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 16px;
  /* Широкая таблица прокручивается внутри карточки, а не растягивает
     страницу: у упаковочного листа одиннадцать колонок. */
  overflow-x: auto;
}

table { border-collapse: collapse; width: 100%; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--line-soft); }
th {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
td { color: var(--ink-dim); }
td.r, th.r { text-align: right; }
td.c, th.c { text-align: center; }
tbody tr:hover { background: var(--panel-hi); }
tfoot th { border-top: 1px solid var(--line); color: var(--ink); font-size: 13px; }
.nums { font-variant-numeric: tabular-nums; white-space: nowrap; }

input, select, textarea {
  font: inherit;
  color: var(--ink);
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #0c141d;
  width: 100%;
}
input::placeholder, textarea::placeholder { color: #5b6878; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent-line);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
input:disabled, select:disabled { color: var(--muted); background: #0a1119; }
textarea { min-height: 62px; resize: vertical; }
input[type="checkbox"], input[type="radio"] { accent-color: var(--accent); }
input[type="date"]::-webkit-calendar-picker-indicator { filter: invert(0.7); }
select option { background: var(--panel); color: var(--ink); }

label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.field { margin-bottom: 12px; }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: 1fr 1fr; }
.g3 { grid-template-columns: 1fr 1fr 1fr; }
.g4 { grid-template-columns: repeat(4, 1fr); }

.btn {
  display: inline-block;
  padding: 7px 14px;
  border-radius: 7px;
  border: 1px solid var(--line);
  background: #131d28;
  color: var(--ink);
  cursor: pointer;
  font: inherit;
}
.btn:hover { background: var(--panel-hi); border-color: #2a3949; text-decoration: none; }
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}
.btn.primary:hover { filter: brightness(1.1); }
.btn.danger { color: var(--danger); border-color: rgba(248, 113, 113, 0.35); }
.btn.danger:hover { background: rgba(248, 113, 113, 0.1); }
.btn.sm { padding: 3px 9px; font-size: 13px; }
.row-actions { display: flex; gap: 8px; align-items: center; }

.tag {
  display: inline-block; padding: 1px 9px; border-radius: 20px;
  font-size: 12px; background: var(--panel-hi);
  border: 1px solid var(--line); color: var(--ink-dim);
}
.tag.draft { color: var(--muted); }
.tag.issued, .tag.sent {
  color: #67e8f9; border-color: rgba(103, 232, 249, 0.3); background: rgba(103, 232, 249, 0.1);
}
.tag.partial { color: var(--warn); border-color: rgba(251, 191, 36, 0.3); background: rgba(251, 191, 36, 0.1); }
.tag.paid, .tag.accepted {
  color: var(--ok); border-color: rgba(52, 211, 153, 0.3); background: rgba(52, 211, 153, 0.1);
}
.tag.shipped { color: var(--violet); border-color: rgba(167, 139, 250, 0.32); background: rgba(167, 139, 250, 0.1); }
.tag.cancelled, .tag.rejected, .tag.expired {
  color: var(--danger); border-color: rgba(248, 113, 113, 0.3); background: rgba(248, 113, 113, 0.1);
}

.muted { color: var(--muted); }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; line-height: 1.4; }
.err {
  background: rgba(248, 113, 113, 0.1);
  border: 1px solid rgba(248, 113, 113, 0.35);
  color: #fca5a5;
  padding: 9px 12px; border-radius: 7px; margin-bottom: 14px;
}
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar input, .toolbar select { width: auto; min-width: 160px; }

/* ---------- итоги документа ---------- */
.totals { margin-left: auto; width: 360px; }
.totals td { border: none; padding: 5px 0; color: var(--muted); }
.totals td.r { font-variant-numeric: tabular-nums; color: var(--ink-dim); }
.totals tr.grand td {
  font-weight: 700; color: var(--ink);
  border-top: 1px solid var(--line); padding-top: 9px;
}

/* ---------- вход ---------- */
.login-wrap { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-box { width: 340px; }

/* ---------- проверка пароля ---------- */
.pwlist {
  list-style: none;
  margin: 7px 0 0;
  padding: 0;
  font-size: 12px;
  color: var(--muted);
}
.pwlist li { display: flex; gap: 8px; align-items: baseline; line-height: 1.8; }
.pwlist li::before {
  content: "○";
  width: 12px;
  flex: 0 0 12px;
  color: #4a5866;
}
.pwlist li.ok { color: var(--ok); }
.pwlist li.ok::before { content: "✓"; color: var(--ok); font-weight: 700; }
.pwlist .title { color: var(--muted); margin-bottom: 2px; }
.pwlist .title::before { content: ""; width: 0; flex: 0; }
.pwlist.collapsed { display: none; }

/* ---------- предпросмотр печатной формы ---------- */
/* Кадр внутри — шириной с лист (210 мм), поэтому колонке нужен min-width: 0.
   Без него сетка растягивается под ширину кадра и карточка расползается. */
.pv-cols > * { min-width: 0; }
.pv-view {
  position: relative;
  width: 80%;                       /* лист чуть меньше колонки… */
  margin-left: auto;                /* …и прижат к правому краю формы */
  aspect-ratio: 210 / 297;          /* окно той же формы, что лист А4 */
  overflow-y: auto;                 /* подпись и печать — прокруткой */
  overflow-x: hidden;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.pv-stage { position: relative; width: 100%; }
.pv-view iframe {
  position: absolute;
  top: 0;
  left: 0;
  border: 0;
  background: #fff;
  transform-origin: 0 0;            /* масштаб задаётся скриптом по ширине окна */
}
.pv-group { margin-top: 18px; }
.pv-group:first-of-type { margin-top: 0; }
.pv-group > h2 { margin-top: 0; }
.pv-num { max-width: 96px; }

/* ---------- список с флажками (упаковочные листы у инвойса) ---------- */
.checklist { list-style: none; margin: 0; padding: 0; }
.checklist li { padding: 4px 0; }
.checklist label { display: flex; gap: 8px; align-items: baseline; cursor: pointer; }
.checklist input { width: auto; margin: 0; }

/* ---------- узкие экраны ---------- */
/* Адаптивности «по умолчанию» не бывает: сетки, боковое меню и таблицы
   заданы в пикселях и колонках, поэтому на планшете и телефоне их надо
   перестраивать явно. */
.menu-toggle { display: none; }

@media (max-width: 1180px) {
  .g4 { grid-template-columns: 1fr 1fr; }
  .pv-view { width: 100%; }        /* предпросмотр печати во всю колонку */
}

@media (max-width: 980px) {
  .g3 { grid-template-columns: 1fr 1fr; }
  .pv-cols { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .layout { flex-direction: column; }

  .menu-toggle {
    display: flex;
    align-items: center;
    gap: 9px;
    width: 100%;
    padding: 12px 16px;
    border: 0;
    border-bottom: 1px solid var(--line);
    background: var(--panel-2);
    color: var(--ink);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
  }

  /* Меню занимает всю ширину и по умолчанию свёрнуто */
  .side {
    width: auto;
    flex: none;
    display: none;
    padding: 10px 0;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .side.open { display: flex; }
  .side .brand { display: none; }
  .side .foot { margin-top: 12px; }

  .main { padding: 14px 12px 40px; }
  .head { flex-direction: column; align-items: stretch; gap: 10px; }
  .head .row-actions { flex-wrap: wrap; }
  .card { padding: 13px 13px; }

  .grid, .g2, .g3, .g4 { grid-template-columns: 1fr; }

  .card table { min-width: 640px; }

  h1 { font-size: 20px; }
}

/* ---------- очереди в реестре фапьяо ---------- */
.queue {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-hi);
  color: var(--ink-dim);
}
.queue:hover { border-color: var(--accent-line); text-decoration: none; color: var(--ink); }
.queue b { font-size: 22px; font-weight: 600; color: var(--ink); }
.queue span { font-size: 12.5px; color: var(--muted); }
/* Очередь, которая требует действия, подсвечивается только когда в ней есть строки */
.queue.hot { border-color: rgba(248, 113, 113, 0.45); }
.queue.hot b { color: var(--danger); }

/* ---------- переключатель списков ---------- */
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0 0 14px;
}
.tab {
  padding: 6px 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink-dim);
  font-size: 13.5px;
  white-space: nowrap;
}
.tab:hover { background: var(--panel-hi); color: var(--ink); text-decoration: none; }
.tab.on {
  border-color: var(--accent-line);
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}
