:root {
  --ink: #171c28;
  --muted: #6b7280;
  --line: #e3e6ec;
  --bg: #f5f6f8;
  --card: #ffffff;
  --accent: #1f3a93;
  --accent-ink: #ffffff;
  --danger: #b42318;
  --ok: #067647;
  --navy: #14203f;
  --accent-soft: #eef2fb;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 32, 63, .05), 0 12px 32px -20px rgba(20, 32, 63, .35);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.5 "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 24px; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 15px; margin: 0; }
h3 { font-size: 13px; margin: 0 0 8px; }
small { display: block; color: var(--muted); font-size: 12px; }
code { background: #eef0f4; padding: 1px 4px; border-radius: 4px; font-size: 12px; }

/* --- шапка --- */
.topbar {
  display: flex; align-items: center; gap: 24px;
  background: var(--card); border-bottom: 1px solid var(--line);
  padding: 0 24px; height: 56px; position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; color: var(--ink); }
.brand img { height: 26px; }
.topbar nav { display: flex; gap: 4px; margin-right: auto; }
.topbar nav a {
  padding: 7px 12px; border-radius: 8px; color: var(--muted); font-weight: 500;
}
.topbar nav a:hover { background: var(--bg); text-decoration: none; }
.topbar nav a.active { background: var(--bg); color: var(--ink); }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.who { font-size: 13px; text-align: right; line-height: 1.2; }
.who em { display: block; color: var(--muted); font-style: normal; font-size: 11px; }

/* --- раскладка --- */
.wrap { max-width: 1180px; margin: 0 auto; padding: 24px; }
.auth { display: grid; place-items: center; min-height: 100vh; padding: 24px; }
.auth-brand { display: none; }
@media (min-width: 900px) {
  .auth { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); grid-template-rows: auto 1fr; padding: 0; place-items: stretch; }
  .auth > .flash { grid-column: 2; grid-row: 1; width: 340px; margin: 32px auto 0; }
  .auth-card { grid-column: 2; grid-row: 2; align-self: center; justify-self: center; }
  .auth-brand {
    grid-column: 1; grid-row: 1 / -1; display: flex; align-items: center; padding: 48px;
    background: linear-gradient(160deg, var(--navy) 0%, #1d3270 55%, #274aa8 100%); color: #fff;
  }
  .auth-brand-inner { max-width: 420px; margin: 0 auto; }
  .brand-tile { display: inline-block; background: #fff; border-radius: 14px; padding: 14px 16px; margin-bottom: 28px; }
  .brand-tile img { height: 52px; display: block; }
  .auth-brand h2 { font-size: 28px; line-height: 1.25; letter-spacing: -.01em; margin: 0 0 20px; color: #fff; }
  .auth-brand ul { list-style: none; padding: 0; margin: 0; display: grid; gap: 12px; color: rgba(255, 255, 255, .82); font-size: 15px; }
  .auth-brand li { padding-left: 28px; position: relative; }
  .auth-brand li::before {
    content: "\2713"; position: absolute; left: 0; top: 1px; width: 18px; height: 18px; border-radius: 50%;
    background: rgba(255, 255, 255, .16); font-size: 11px; display: inline-flex; align-items: center; justify-content: center;
  }
}
.page-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; margin-bottom: 18px; flex-wrap: wrap;
}
.subtitle { margin: 4px 0 0; color: var(--muted); }
.head-actions { display: flex; align-items: center; gap: 10px; }
.columns { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 18px; align-items: start; }
.col-main, .col-side { display: flex; flex-direction: column; gap: 18px; min-width: 0; }
@media (max-width: 960px) { .columns { grid-template-columns: 1fr; } }

/* --- карточки --- */
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow);
}
/* Таблица занимает карточку целиком: заголовок на подложке, строки во всю ширину. */
.table-card { padding: 0; overflow: hidden; }
.table-card .grid th { padding: 12px 14px; background: #f8f9fc; }
.table-card .grid td { padding: 13px 14px; }
.table-card .grid th:first-child, .table-card .grid td:first-child { padding-left: 20px; }
.table-card .grid th:last-child, .table-card .grid td:last-child { padding-right: 20px; }
tr[data-href] { cursor: pointer; }
@media (hover: hover) { .table-card .grid tbody tr:hover td { background: #f7f9fc; } }

/* Сводные карточки главной. */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi {
  display: flex; flex-direction: column; gap: 2px; padding: 14px 18px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
}
.kpi-label { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.kpi-value { font-size: 28px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; line-height: 1.2; }
.kpi-note { font-size: 13px; color: var(--muted); }
.kpi-accent { background: linear-gradient(135deg, var(--accent) 0%, #2d55c8 100%); border-color: transparent; color: #fff; }
.kpi-accent .kpi-label, .kpi-accent .kpi-note { color: rgba(255, 255, 255, .8); }

/* Вкладки статусов со счётчиками. */
.status-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin: -4px 0 14px; }
.status-tabs a {
  display: inline-flex; align-items: center; gap: 7px; padding: 6px 12px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--card); color: var(--muted); font-size: 13px; font-weight: 500;
}
.status-tabs a:hover { text-decoration: none; border-color: #c9d0dc; color: var(--ink); }
.status-tabs a.active { background: var(--ink); border-color: var(--ink); color: #fff; }
.status-tabs .count {
  min-width: 20px; padding: 0 7px; border-radius: 999px; text-align: center;
  background: rgba(23, 28, 40, .06); font-size: 12px; font-variant-numeric: tabular-nums;
}
.status-tabs a.active .count { background: rgba(255, 255, 255, .22); }

/* Поиск со значком лупы. */
.search { position: relative; display: block; flex: 1; min-width: 220px; margin: 0; }
.search svg { position: absolute; left: 12px; top: 50%; width: 18px; height: 18px; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search input[type=search] { width: 100%; margin: 0; padding-left: 38px; }

/* Ссылка на готовый PDF — заметная плашка. */
.pdf-link {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 8px;
  background: var(--accent-soft); color: var(--accent); font-weight: 500; font-size: 13px; white-space: nowrap;
}
.pdf-link svg { width: 15px; height: 15px; }
.pdf-link:hover { text-decoration: none; background: #e1e8fa; }

/* Шкала статуса заказа: пройдено / сейчас / впереди. */
.stepper { display: flex; gap: 8px; list-style: none; padding: 0; margin: 0 0 18px; counter-reset: step; }
.stepper li {
  flex: 1; display: flex; align-items: center; gap: 9px; padding: 10px 12px; border-radius: 10px;
  background: var(--card); border: 1px solid var(--line); color: var(--muted); font-size: 13px; font-weight: 500;
}
.stepper li::before {
  counter-increment: step; content: counter(step); flex: 0 0 auto;
  width: 22px; height: 22px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  background: #eef0f4; font-size: 12px;
}
.stepper li.done { color: var(--ok); border-color: #cfe8da; background: #f3faf6; }
.stepper li.done::before { content: "\2713"; background: var(--ok); color: #fff; }
.stepper li.current { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); box-shadow: 0 0 0 3px rgba(31, 58, 147, .12); }
.stepper li.current::before { background: var(--accent); color: #fff; }

.with-icon svg { width: 18px; height: 18px; vertical-align: -4px; margin-right: 6px; }

/* Документ на странице заказа — как первая страница PDF. */
.doc-tools { display: flex; justify-content: flex-end; margin-bottom: 10px; }
.doc-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 16px;
  padding-bottom: 14px; margin-bottom: 6px; border-bottom: 2px solid var(--ink);
}
.doc-logo { height: 60px; max-width: 200px; object-fit: contain; }
.doc-title { text-align: right; }
.doc-title h2 { font-size: 20px; margin-bottom: 4px; }
.doc-meta { font-size: 13px; }
.doc-meta-main { font-size: 18px; font-weight: 700; color: var(--ink); }
.doc-section {
  margin: 20px 0 10px; padding-bottom: 6px; border-bottom: 1px solid var(--line);
  font-size: 12px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--ink);
}
.doc-params { display: grid; grid-template-columns: 200px 1fr; gap: 6px 16px; margin: 0; font-size: 14px; }
.doc-params dt { color: var(--muted); }
.doc-params dd { margin: 0; }
/* Правка общих параметров в документе: кнопка как у чертежей, форма «название — значение». */
.params-edit { margin: 10px 0 4px; }
.params-edit summary {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; min-height: 32px; list-style: none;
  border: 1px solid var(--line); border-radius: 8px; background: var(--bg);
  font-size: 13px; font-weight: 500; color: var(--accent); cursor: pointer;
}
.params-edit summary::-webkit-details-marker { display: none; }
.params-edit summary::after { content: " \25BE"; color: var(--muted); }
.params-edit[open] summary { border-color: var(--accent); background: #fff; }
.params-form { margin-top: 10px; }
.params-grid { display: grid; grid-template-columns: 2fr 3fr; gap: 6px 8px; align-items: center; }
.params-grid input[type=text] { margin: 0; }
.outdated { margin: 0 0 12px; font-size: 14px; }
.outdated form { margin-top: 8px; }
.client-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 8px; }
.client-grid .client-address { grid-column: 1 / -1; }
@media (max-width: 720px) {
  .client-grid { grid-template-columns: 1fr; }
  .params-edit summary, .doc-card .drawing-upload summary { min-height: 44px; }
}
.doc-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px; }
.doc-card { margin: 0; padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.doc-card img, .doc-nodrawing { display: block; width: 100%; height: 190px; object-fit: contain; }
.doc-nodrawing { display: flex; align-items: center; justify-content: center; background: var(--bg); border-radius: 8px; }
.doc-card figcaption { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-top: 10px; font-size: 15px; }
.doc-card figcaption span { font-weight: 700; white-space: nowrap; }
.composition { border-top: 1px solid var(--line); margin-top: 18px; padding-top: 8px; }
/* Кнопка наценки под итогом и свёрнутый расчёт для менеджера. */
/* Наценка: кнопка «+N%» и рядом поле для своего процента — две формы в одном ряду. */
.markup-row { display: flex; align-items: center; gap: 8px 10px; margin: 0 0 12px; flex-wrap: wrap; }
.markup-form { display: flex; align-items: center; gap: 10px; margin: 0; flex-wrap: wrap; }
.markup-custom { gap: 8px; }
.markup-custom input[type=text] { width: 92px; margin: 0; padding: 7px 10px; text-align: right; }
.markup-button { background: var(--ok); border-color: var(--ok); color: #fff; font-weight: 700; font-size: 15px; padding: 8px 16px; }
.markup-button:hover { background: #05613a; }
.markup-form .link { font-size: 13px; }
/* Быстрые услуги в итогах: «Монтаж», «Подоконник» — сумму вписывает менеджер. */
.quick-services { display: grid; gap: 8px; margin: 0 0 12px; padding-top: 10px; border-top: 1px dashed var(--line); }
/* Сетка 2×2: название и «Убрать» в первой строке, поле суммы и кнопка — во второй:
   панель итогов узкая (~300 px), в одну строку всё не помещается. */
.quick-service { display: grid; grid-template-columns: 1fr auto; gap: 6px 8px; align-items: center; }
.quick-service label { grid-column: 1; margin: 0; font-size: 14px; font-weight: 600; color: var(--ink); }
.quick-service.is-set label::after {
  content: ""; display: inline-block; width: 7px; height: 7px; margin-left: 6px;
  border-radius: 50%; background: var(--ok); vertical-align: middle;
}
/* Свой чертёж конструкции: свёрнутая форма загрузки в строке таблицы. */
.drawing-upload { margin-top: 4px; text-align: left; }
.drawing-upload summary { font-size: 13px; color: var(--accent); cursor: pointer; list-style: none; white-space: nowrap; }
.drawing-upload summary::-webkit-details-marker { display: none; }
.drawing-upload summary::after { content: " \25BE"; color: var(--muted); }
.drawing-upload[open] summary::after { content: " \25B4"; }
.drawing-form { display: flex; flex-direction: column; gap: 6px; margin: 6px 0; }
.drawing-form input[type=file] { font-size: 13px; max-width: 190px; }
.drawing-upload .link { font-size: 13px; }
/* В карточке документа — заметная кнопка с иконкой (серую ссылку владелец не нашёл),
   а сам чертёж — подпись к полю файла: нажатие открывает выбор файла. */
.doc-card .drawing-upload { margin-top: 8px; }
.doc-card .drawing-upload summary {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; min-height: 32px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--bg);
  font-size: 13px; font-weight: 500; color: var(--accent);
}
.doc-card .drawing-upload summary svg { width: 15px; height: 15px; flex: none; }
.doc-card .drawing-upload summary:hover, .doc-card .drawing-upload[open] summary { border-color: var(--accent); background: #fff; }
.doc-card .drawing-form input[type=file] { max-width: 100%; }
.doc-drawing { display: block; position: relative; margin: 0; cursor: pointer; border-radius: 8px; overflow: hidden; }
.doc-drawing::after {
  content: "Заменить чертёж"; position: absolute; left: 0; right: 0; bottom: 0; padding: 5px 8px;
  text-align: center; font-size: 12px; color: #fff; background: rgba(31, 58, 147, .85);
  opacity: 0; transition: opacity .15s;
}
.doc-drawing.empty::after { content: "Добавить чертёж"; }
.doc-drawing:hover::after { opacity: 1; }
.doc-drawing.empty .doc-nodrawing { border: 1px dashed var(--line); text-align: center; padding: 0 12px; }
/* Страница «Чертежи из файла»: пронумерованные чертежи и выбор для каждой конструкции. */
.pick-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-top: 12px; }
.pick-card { margin: 0; padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: #fff; text-align: center; }
.pick-card img { display: block; width: 100%; height: 130px; object-fit: contain; }
.pick-card figcaption { margin-top: 6px; font-size: 13px; font-weight: 600; }
.assign-actions { display: flex; gap: 10px; align-items: center; }
.assign-actions .button { display: inline-flex; align-items: center; }
.quick-service label .muted { font-weight: 400; margin-left: 4px; }
.total-override { margin: 2px 0 12px; }
.quick-service .hint { grid-column: 1 / -1; font-size: 12px; color: var(--muted); line-height: 1.3; }
.quick-service .quick-links { grid-row: 1; grid-column: 2; justify-self: end; display: flex; gap: 10px; }
.quick-service input[type=text] { grid-column: 1; min-width: 0; margin: 0; padding: 7px 10px; text-align: right; }
.quick-service button { grid-column: 2; white-space: nowrap; }
.quick-service .link { grid-row: 1; justify-self: end; font-size: 13px; }
.totals .breakdown { margin-top: 4px; }
.totals .breakdown .total-row { font-size: 13px; padding: 4px 0; }
.totals .breakdown summary { font-size: 12px; color: var(--muted); }
.composition summary { list-style: none; cursor: pointer; padding: 6px 0; font-size: 13px; font-weight: 600; color: var(--accent); user-select: none; }
.composition summary::-webkit-details-marker { display: none; }
.composition summary::after { content: " \25BE"; color: var(--muted); }
.composition[open] summary::after { content: " \25B4"; }
.card-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 12px; margin-bottom: 12px;
}
.auth-card { width: 340px; display: flex; flex-direction: column; gap: 12px; }
.auth-card h1 { font-size: 18px; text-align: center; }
.auth-logo { height: 56px; object-fit: contain; margin: 0 auto 4px; }
.empty { text-align: center; padding: 48px 24px; }
.empty p { color: var(--muted); max-width: 520px; margin: 8px auto 18px; }
.hint ol { margin: 0; padding-left: 20px; color: var(--muted); }
.hint li { margin-bottom: 6px; }
.warn { border-color: #f3c99b; background: #fffaf2; }
.warn ul { margin: 0; padding-left: 20px; }
.warn li { margin-bottom: 4px; }

/* --- формы --- */
label { display: block; font-size: 13px; color: var(--muted); }
input[type=text], input[type=email], input[type=password], input[type=search],
select, textarea {
  width: 100%; margin-top: 4px; padding: 8px 10px;
  border: 1px solid var(--line); border-radius: 8px;
  font: inherit; color: var(--ink); background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #c7d2f0; border-color: var(--accent); }
textarea { resize: vertical; }
/* Поле пароля с кнопкой «Показать» (кнопку включает скрипт в base.html). */
.password-field { position: relative; display: block; margin-top: 4px; }
.password-field input[type=password], .password-field input[type=text] { margin-top: 0; padding-right: 92px; }
.password-field .reveal {
  position: absolute; top: 0; bottom: 0; right: 0; min-height: 0; padding: 0 12px;
  border: none; background: transparent; color: var(--accent); font-size: 13px; font-weight: 500;
}
.password-field .reveal:hover { background: transparent; text-decoration: underline; }
.flash small { display: block; margin-top: 4px; font-size: 12px; opacity: 0.85; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.check { display: flex; align-items: center; gap: 8px; color: var(--ink); }
.check input { width: auto; margin: 0; }
.border-top { border-top: 1px solid var(--line); padding-top: 16px; margin-top: 16px; }
.inline { display: inline; }

button, .button {
  font: inherit; padding: 8px 14px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--line); background: #fff; color: var(--ink);
}
button:hover, .button:hover { background: var(--bg); text-decoration: none; }
.primary {
  background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 500;
  box-shadow: 0 8px 18px -10px rgba(31, 58, 147, .7);
}
.primary:hover { background: #172f7d; }
.danger { background: #fff; border-color: #e6b0aa; color: var(--danger); }
.danger:hover { background: #fdf3f2; }
.wide { width: 100%; margin-top: 12px; }
.link { border: none; background: none; color: var(--accent); padding: 0; cursor: pointer; }
.link:hover { background: none; text-decoration: underline; }
.link-button { padding: 8px 12px; border-radius: 8px; color: var(--muted); }
.link-button:hover { background: var(--card); text-decoration: none; }
.button.mini { padding: 4px 10px; font-size: 13px; }
.doc-links { display: flex; gap: 8px; flex-wrap: wrap; }
/* Значки разделов и вкладка «Загрузить» нужны только нижней панели телефона. */
.nav-icon { display: none; width: 24px; height: 24px; }
.nav-upload { display: none; }
/* Без серой вспышки при касании и без задержки двойного тапа. */
a, button, summary { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }

.filters { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.filters input[type=search] { flex: 1; min-width: 220px; margin: 0; }
.filters select { width: auto; margin: 0; }

.dropzone {
  position: relative; display: block; border: 2px dashed var(--line); border-radius: var(--radius);
  padding: 26px 20px; text-align: center; cursor: pointer; margin-bottom: 14px;
}
.dropzone:hover, .dropzone:focus-within { border-color: var(--accent); background: #fbfcfe; }
.dropzone.has-file { border-style: solid; border-color: var(--ok); background: #f3faf6; }
/* Системный элемент выбора файла прячем, но оставляем в потоке: клик по любой части
   зоны открывает выбор, а клавиатура и экранный диктор до него всё равно доходят. */
.dropzone input[type=file] { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; }
.dropzone-button {
  display: inline-block; padding: 10px 18px; border-radius: 8px; font-weight: 500;
  background: var(--accent); color: var(--accent-ink);
}
.dropzone-name { display: block; margin: 12px 0 6px; color: var(--ink); font-weight: 600; overflow-wrap: anywhere; }
.dropzone-hint { display: block; color: var(--muted); font-size: 13px; }
/* Ход загрузки и разбора PDF: спиннер, полоса и оставшееся время. */
.progress-panel { margin-top: 16px; padding: 14px 16px; border: 1px solid #c7d2f0; border-radius: 10px; background: var(--accent-soft); }
.progress-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; font-weight: 600; flex-wrap: wrap; }
.progress-eta { margin-left: auto; font-weight: 500; font-variant-numeric: tabular-nums; }
.progress-track { height: 8px; border-radius: 999px; background: #d9e0f2; overflow: hidden; }
.progress-fill { height: 100%; width: 2%; border-radius: 999px; background: linear-gradient(90deg, var(--accent), #2d55c8); transition: width .25s ease; }
.progress-panel p { margin: 10px 0 0; }
.spinner {
  display: inline-block; width: 18px; height: 18px; border-radius: 50%; flex: 0 0 auto;
  border: 3px solid #c7d2f0; border-top-color: var(--accent); animation: spin .8s linear infinite;
}
.spinner-light { width: 15px; height: 15px; vertical-align: -3px; border-color: rgba(255, 255, 255, .35); border-top-color: #fff; }
@keyframes spin { to { transform: rotate(360deg); } }
#upload-error { margin-top: 14px; }

/* --- таблицы --- */
.grid { width: 100%; border-collapse: collapse; }
.grid th {
  text-align: left; font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em;
  padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
.grid td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.grid tbody tr:last-child td { border-bottom: none; }
.grid.compact td, .grid.compact th { padding: 7px 8px; }
.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
/* Габариты изделия не должны переноситься, а тип конструкции пусть жмётся. */
.cell-item { min-width: 168px; }
.cell-type { max-width: 150px; font-size: 13px; }
/* Широкие таблицы из произвольных PDF прокручиваются, а не ломают вёрстку. */
.scroll-x { overflow-x: auto; }
/* Таблица-форма правки разбора: поля вплотную, без лишних отступов. */
.edit-grid td { padding: 4px 6px; vertical-align: middle; }
.edit-grid input, .edit-grid select { margin: 0; padding: 5px 7px; font-size: 13px; }
.edit-grid td input[inputmode] { text-align: right; }
.edit-grid select { min-width: 96px; }

/* Статус меняется явной кнопкой, а не автоотправкой при выборе. */
.status-form { display: flex; gap: 6px; align-items: center; }
.status-form select { margin: 0; width: auto; }

/* Подтверждение опасных действий встроено в страницу: браузерные диалоги
   confirm() во встроенных браузерах гасятся, и форма молча не уходит. */
.confirm { border: 1px solid var(--line); border-radius: 8px; margin-top: 10px; }
.confirm summary {
  list-style: none; cursor: pointer; padding: 9px 14px;
  color: var(--danger); font-weight: 500; user-select: none;
}
.confirm summary::-webkit-details-marker { display: none; }
.confirm summary::after { content: "\25BE"; float: right; color: var(--muted); }
.confirm[open] summary::after { content: "\25B4"; }
.confirm[open] { border-color: #e6b0aa; background: #fdf3f2; }
.confirm .body { padding: 0 14px 12px; }
.confirm .body p { margin: 0 0 10px; }
.strong { font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.danger { color: var(--danger); }
.row-excluded { opacity: .5; }
.row-excluded .strong { text-decoration: line-through; }
.group-title { margin-top: 14px; color: var(--muted); text-transform: uppercase; font-size: 11px; letter-spacing: .04em; }

.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px 2px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 500; background: #eef0f4; color: #414958; white-space: nowrap;
}
.chip::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; opacity: .75; }
.chip-quoted { background: #e7f0ff; color: #1f3a93; }
.chip-approved { background: #e6f6ee; color: var(--ok); }
.chip-production { background: #fff3da; color: #8a5a00; }
.chip-warn { background: #fff3da; color: #8a5a00; margin-left: 6px; vertical-align: middle; }
.subhead { margin: 0 0 8px; font-size: 15px; }
.issue-list { list-style: none; padding: 0; margin: 0; font-size: 14px; }
.issue-list li { display: flex; flex-wrap: wrap; gap: 4px 10px; padding: 6px 0; border-top: 1px solid var(--line); }
.issue-list li:first-child { border-top: none; }
.chip-done { background: #e6f6ee; color: var(--ok); }
.chip-cancelled { background: #fdecea; color: var(--danger); }

.pager { display: flex; gap: 16px; align-items: center; justify-content: center; margin-top: 18px; color: var(--muted); }

/* --- итоги и предпросмотр --- */
.total-row { display: flex; justify-content: space-between; gap: 12px; padding: 5px 0; }
.total-row.muted-row { color: var(--muted); font-size: 13px; }
.total-row.grand {
  font-size: 18px; margin: 8px 0 12px; padding: 12px 14px; border-radius: 10px;
  background: var(--accent-soft); color: var(--accent); align-items: center;
}
.totals hr { border: none; border-top: 1px solid var(--line); margin: 8px 0; }
.preview { width: 100%; border: 1px solid var(--line); border-radius: 6px; display: block; }
.versions { list-style: none; padding: 0; margin: 12px 0 0; font-size: 13px; }
.versions li { display: flex; gap: 8px; align-items: baseline; padding: 5px 0; border-top: 1px solid var(--line); }
.versions li .muted { flex: 1; font-size: 12px; }
.facts { display: grid; grid-template-columns: 90px 1fr; gap: 6px 12px; margin: 0; font-size: 13px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }
.log { list-style: none; padding: 0; margin: 0; font-size: 13px; }
.log li { padding: 5px 0; border-top: 1px solid var(--line); }
.log li:first-child { border-top: none; }
.log em { font-style: normal; color: var(--muted); }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; background: #e6f6ee; color: var(--ok); }
.flash-error { background: #fdecea; color: var(--danger); }
.flash-warn { background: #fff3da; color: #8a5a00; }

/* --- телефон --- */
.m-only { display: none; }

@media (max-width: 720px) {
  /* Шапка: только бренд и выход; в установленном приложении отступ под строку состояния. */
  .topbar { height: auto; padding: 6px 12px; padding-top: calc(6px + env(safe-area-inset-top)); gap: 8px; }
  .brand { min-height: 44px; }
  .brand span { display: none; }
  .brand img { height: 30px; }
  .topbar-right { margin-left: auto; gap: 8px; }
  .who { font-size: 13px; max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .who em { display: none; }
  .topbar-right .link {
    min-height: 44px; padding: 8px 14px; border: 1px solid var(--line); border-radius: 10px;
    color: var(--ink); background: var(--card); font-size: 15px;
  }

  /* Разделы — нижняя панель под большим пальцем, как в системных приложениях:
     кнопки во всю высоту панели, со значком и подписью. */
  .topbar nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; margin: 0;
    display: flex; gap: 0; background: var(--card); border-top: 1px solid var(--line);
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
  }
  .topbar nav a {
    flex: 1 1 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 3px; min-height: 56px; padding: 4px 2px; border-radius: 12px;
    font-size: 12px; font-weight: 500; color: var(--muted); white-space: nowrap;
  }
  .topbar nav a.active { background: #eef2fb; color: var(--accent); }
  .topbar nav a:active { background: var(--bg); }
  .nav-icon { display: block; }
  .nav-upload { display: flex; }

  /* Снизу запас под панель, чтобы последняя карточка не пряталась за ней. */
  .wrap { padding: 14px; padding-bottom: calc(96px + env(safe-area-inset-bottom)); }

  /* Крупные зоны нажатия — не меньше 44–48 px; шрифт чуть больше, чем на компьютере. */
  body { font-size: 15px; }
  label { font-size: 14px; }
  .check { min-height: 44px; gap: 12px; }
  input[type=checkbox] { width: 24px; height: 24px; flex: 0 0 auto; }
  .page-head .link-button, .head-actions .link-button {
    display: flex; align-items: center; justify-content: center; text-align: center;
    border: 1px solid var(--line); background: var(--card); color: var(--ink);
  }
  .head-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .status-form { grid-column: 1 / -1; gap: 8px; }
  .status-form button { white-space: nowrap; }
  .card-head { flex-wrap: wrap; }
  .button.mini { min-height: 44px; padding: 10px 14px; font-size: 15px; }
  .confirm summary { padding: 14px 16px; font-size: 16px; }
  .confirm .body button { width: 100%; }
  .versions li { padding: 8px 0; font-size: 14px; flex-wrap: wrap; align-items: center; }
  .versions li a { display: inline-flex; align-items: center; min-height: 40px; padding: 0 14px; border: 1px solid var(--line); border-radius: 10px; }
  .pager { gap: 12px; }
  .pager a { display: inline-flex; align-items: center; min-height: 44px; padding: 0 16px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); }
  button:active, .button:active { transform: scale(0.985); }
  .card { padding: 14px; }
  .page-head { flex-direction: column; align-items: stretch; margin-bottom: 14px; }
  .page-head .button { text-align: center; }
  .head-actions { flex-wrap: wrap; }
  .status-form { flex: 1 1 100%; }
  .status-form select { flex: 1; }
  .row { grid-template-columns: 1fr; }
  .auth { min-height: 100svh; }
  .auth-card { width: 100%; max-width: 340px; }
  h1 { font-size: 20px; overflow-wrap: anywhere; }

  /* Поля не меньше 16px — иначе iPhone приближает страницу при фокусе. */
  input[type=text], input[type=email], input[type=password], input[type=search],
  select, textarea { font-size: 16px; padding: 10px 12px; }
  button, .button, .link-button { min-height: 48px; padding: 10px 16px; font-size: 16px; border-radius: 10px; }
  .link { min-height: 0; padding: 0; font-size: inherit; }
  /* Фильтры: поиск на всю ширину, статус и кнопка — под ним в один ряд. */
  .filters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .filters input[type=search] { grid-column: 1 / -1; min-width: 0; width: 100%; }
  .filters select, .filters button { width: 100%; }
  .filters .link-button { grid-column: 1 / -1; text-align: center; }
  .upload .primary { width: 100%; }

  .grid td { padding: 8px 6px; }
  .grid th { padding: 6px; }
  .cell-item { min-width: 120px; }
  .facts { grid-template-columns: 80px 1fr; }
  .edit-grid input, .edit-grid select { min-width: 76px; font-size: 16px; padding: 8px; }
  .edit-grid td:first-child { min-width: 28px; }
  .total-row.grand { font-size: 18px; }
  .m-only { display: inline; }
  .m-hide { display: none !important; }

  /* Страница заказа: итоги и готовый документ — первыми, состав — ниже. */
  .columns.side-first .col-side { order: -1; }

  /* Таблицы-списки превращаются в карточки: каждая строка — блок,
     подпись колонки берётся из data-label ячейки. */
  .grid.cards, .grid.cards tbody, .grid.cards tr, .grid.cards td { display: block; width: 100%; }
  .grid.cards thead { display: none; }
  .grid.cards tr {
    position: relative; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card);
    padding: 10px 14px; margin-bottom: 10px;
  }
  .grid.cards td {
    display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
    padding: 7px 0; border-bottom: 1px dashed var(--line); text-align: right;
  }
  .grid.cards td:last-child { border-bottom: none; }
  .grid.cards td[data-label]::before {
    content: attr(data-label); color: var(--muted); font-size: 13px; text-align: left; flex: 0 0 auto;
  }
  .grid.cards td.card-title { display: block; text-align: left; font-size: 17px; padding: 6px 28px 8px 0; }
  /* Вся карточка — одна большая кнопка: ссылка заголовка растягивается на карточку (стрелка
     справа это подсказывает), а прочие ссылки и кнопки внутри остаются нажимаемыми поверх неё. */
  .grid.cards .card-link::after { content: ""; position: absolute; inset: 0; border-radius: inherit; }
  .grid.cards .card-link::before {
    content: "\203A"; position: absolute; right: 14px; top: 8px;
    font-size: 30px; line-height: 1; color: #b3b9c6;
  }
  .card .grid.cards .card-link::before { right: 2px; }
  .grid.cards td a:not(.card-link), .grid.cards td form, .grid.cards td button { position: relative; z-index: 1; }
  .grid.cards td.card-actions { display: block; text-align: left; padding: 8px 0 2px; }
  .grid.cards td.card-actions .link {
    display: inline-flex; align-items: center; min-height: 44px; padding: 0 16px;
    border: 1px solid var(--line); border-radius: 10px; font-size: 15px;
  }
  .card .grid.cards tr { border: none; border-top: 1px solid var(--line); border-radius: 0; padding: 8px 0; margin: 0; }
  .card .grid.cards tr:first-child { border-top: none; }

  /* Правка разбора: каждая конструкция — карточка с подписанными полями,
     без горизонтальной прокрутки. */
  .edit-grid.cards td { align-items: center; border-bottom: none; padding: 4px 0; }
  .edit-grid.cards td[data-label]::before { flex: 0 0 44%; font-size: 13px; }
  .edit-grid.cards td input, .edit-grid.cards td select { flex: 1; min-width: 0; width: auto; margin: 0; }
  .edit-grid.cards td.card-title { font-size: 13px; color: var(--muted); padding: 0 0 6px; }
  .card .edit-grid.cards tr { padding: 10px 0; }

  /* Главная на телефоне: сводка в два столбца, вкладки статусов — прокручиваемая строка,
     таблица-карточка прозрачна, чтобы карточки заказов остались отдельными. */
  .kpis { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi { padding: 12px 14px; }
  .kpi-value { font-size: 22px; }
  .status-tabs {
    flex-wrap: nowrap; overflow-x: auto; margin: 0 -14px 12px; padding: 0 14px 6px; scrollbar-width: none;
  }
  .status-tabs::-webkit-scrollbar { display: none; }
  .status-tabs a { flex: 0 0 auto; min-height: 40px; }
  .filters .search { grid-column: 1 / -1; }
  .filters button { grid-column: 1 / -1; }
  .filters .link-button { grid-column: 1 / -1; }
  .table-card { background: transparent; border: none; box-shadow: none; padding: 0; overflow: visible; }
  .table-card .grid.cards tr {
    border: 1px solid var(--line); border-radius: var(--radius); background: var(--card);
    padding: 10px 14px; margin-bottom: 10px; box-shadow: var(--shadow);
  }
  .table-card .grid.cards .card-link::before { right: 14px; }
  .table-card .grid td, .table-card .grid td:first-child, .table-card .grid td:last-child { padding: 7px 0; }
  .stepper { display: none; }
  .with-icon svg { display: none; }
  .doc-head { flex-direction: column; }
  .doc-title { text-align: left; }
  .doc-params { grid-template-columns: 1fr; gap: 2px; }
  .doc-params dt { margin-top: 6px; font-size: 12px; }
  .doc-cards { grid-template-columns: 1fr 1fr; gap: 10px; }
  .doc-card { padding: 8px; }
  .doc-card img, .doc-nodrawing { height: 150px; }
  .doc-card figcaption { flex-direction: column; gap: 0; font-size: 14px; }
}

/* Кнопка «Отправить» появляется только там, где телефон умеет делиться файлами. */
.share-button { display: none; }
.share-button.ready { display: inline-block; }

/* --- компьютер: боковая панель --- */
@media (min-width: 1024px) {
  :root { --sidebar: 240px; }
  .topbar {
    position: fixed; top: 0; bottom: 0; left: 0; width: var(--sidebar); height: auto;
    flex-direction: column; align-items: stretch; gap: 20px; padding: 18px 14px;
    background: linear-gradient(180deg, var(--navy) 0%, #1a2b5c 100%); border-bottom: none; color: #fff;
  }
  .brand {
    flex-direction: column; align-items: flex-start; gap: 8px; padding: 12px 14px;
    background: #fff; border-radius: 12px; color: var(--ink);
  }
  .brand img { height: 34px; }
  .brand span { font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
  .topbar nav { flex-direction: column; gap: 4px; margin: 0; }
  .topbar nav a {
    display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px;
    color: rgba(255, 255, 255, .72); font-size: 14px;
  }
  .topbar nav a:hover { background: rgba(255, 255, 255, .08); color: #fff; }
  .topbar nav a.active { background: rgba(255, 255, 255, .14); color: #fff; }
  .nav-icon { display: block; width: 20px; height: 20px; }
  .topbar-right {
    margin-top: auto; flex-direction: column; align-items: stretch; gap: 10px;
    padding-top: 14px; border-top: 1px solid rgba(255, 255, 255, .12);
  }
  .who { text-align: left; color: #fff; font-size: 13px; }
  .who em { color: rgba(255, 255, 255, .6); }
  .topbar-right form { display: block; }
  .topbar-right .link {
    width: 100%; text-align: left; padding: 8px 12px; border-radius: 10px;
    color: rgba(255, 255, 255, .85); border: 1px solid rgba(255, 255, 255, .18);
  }
  .topbar-right .link:hover { background: rgba(255, 255, 255, .08); color: #fff; text-decoration: none; }
  /* Содержимое центрируется в оставшейся части экрана. */
  .topbar ~ main { margin-left: max(var(--sidebar), calc((100% + var(--sidebar) - 1240px) / 2)); margin-right: 0; max-width: 1240px; padding: 30px 36px; }
}
