:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --ink: #1c2330;
  --muted: #6b7280;
  --line: #e2e5ea;
  --brand: #1f5fbf;
  --ok: #1a9d54;
  --bad: #d23b3b;
  --opt: #b7bcc6;
  --warn-bg: #fff6e0;
  --warn-line: #e6b800;
  --radius: 10px;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.45 -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; }
.small { font-size: 13px; }
.muted { color: var(--muted); }
.center { text-align: center; }
.mt { margin-top: 10px; display: block; }

/* Topbar */
.topbar {
  display: flex; align-items: center; gap: 14px;
  background: var(--card); border-bottom: 1px solid var(--line);
  padding: 10px 18px; position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; font-size: 19px; color: var(--ink); }
.topbar-search { flex: 1; }
.topbar-search input {
  width: 100%; max-width: 460px; padding: 8px 12px;
  border: 1px solid var(--line); border-radius: 20px; background: #fff;
}
.logout { display: flex; align-items: center; gap: 10px; }
.who { color: var(--muted); font-size: 13px; }
.fx-rate { font-size: 11px; line-height: 1.3; color: var(--muted);
  white-space: nowrap; cursor: default; text-align: right; }
.fx-rate b { color: var(--ink); font-variant-numeric: tabular-nums; }
.fx-upd { font-size: 10px; color: var(--muted); opacity: .8; }
.quick-tasks-open {
  position: relative; padding: 7px 12px; white-space: nowrap;
  border-color: #c8d6ea; background: #f7fbff; color: var(--brand);
}
.quick-tasks-open span {
  position: absolute; right: -6px; top: -7px; min-width: 18px; height: 18px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 999px; background: var(--bad); color: #fff;
  font-size: 11px; font-weight: 800; padding: 0 5px;
}

/* Layout */
.container { max-width: 1160px; margin: 20px auto; padding: 0 16px; }

/* Двухколоночная карточка: слева поля, справа документы */
.deal-cols { display: grid; grid-template-columns: 1fr; gap: 20px; align-items: start; }
@media (min-width: 900px) { .deal-cols { grid-template-columns: 1.05fr 0.95fr; } }
.col { min-width: 0; }
.doc-toolbar { display: flex; justify-content: space-between; align-items: center;
  gap: 12px; flex-wrap: wrap; }
.doc-toolbar h2 { margin: 0; }
.check-result { margin: 10px 0; padding: 10px 14px; border-radius: 8px; font-size: 14px; }
.check-result.ok { background: #e7f6ec; color: #14612f; border: 1px solid #9dd6b0; }
.check-result.bad { background: #fdecec; color: #8a1f1f; border: 1px solid #eab3b3; }
.check-result ul { margin: 4px 0 0; padding-left: 20px; }
.card { background: var(--card); border: 1px solid var(--line);
        border-radius: var(--radius); padding: 20px; }
.page-head, .deal-head { display: flex; justify-content: space-between;
  align-items: flex-start; gap: 16px; margin-bottom: 16px; }
h1 { font-size: 22px; margin: 4px 0; }
h2 { font-size: 17px; margin: 22px 0 10px; }
.count { color: var(--muted); font-weight: 400; font-size: 14px; }
.back { font-size: 13px; }
.head-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.head-actions form { margin: 0; }

/* Buttons */
button, .btn {
  font: inherit; cursor: pointer; border: 1px solid var(--line);
  background: #fff; color: var(--ink); padding: 8px 14px;
  border-radius: 8px; display: inline-block;
}
button:hover, .btn:hover { border-color: #c3c8d0; text-decoration: none; }
button.primary, .btn.primary {
  background: var(--brand); color: #fff; border-color: var(--brand);
}
.form-actions { position: sticky; bottom: 0; padding: 12px 0;
  display: flex; gap: 10px; align-items: center;
  background: linear-gradient(transparent, var(--bg) 40%); }

/* Flash */
.flashes { max-width: 1000px; margin: 12px auto 0; padding: 0 16px; }
.flash { padding: 9px 14px; border-radius: 8px; margin-bottom: 8px; }
.flash-info { background: #e7f0fb; color: #17457f; }
.flash-error { background: #fde7e7; color: #8a1f1f; }

/* Tables list */
table.deals { width: 100%; border-collapse: collapse; background: var(--card);
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.deals th, .deals td { padding: 9px 12px; border-bottom: 1px solid var(--line);
  text-align: left; }
.deals th { background: #fafbfc; font-size: 12px; text-transform: uppercase;
  letter-spacing: .03em; color: var(--muted); }
.sort-th {
  border: 0; background: transparent; padding: 0; margin: 0;
  color: inherit; font: inherit; text-transform: inherit; letter-spacing: inherit;
  cursor: pointer;
}
.sort-th:hover { color: var(--brand); text-decoration: none; border: 0; }
.sort-th::after { content: "↕"; margin-left: 5px; opacity: .45; }
.sort-th.asc::after { content: "↑"; opacity: .9; }
.sort-th.desc::after { content: "↓"; opacity: .9; }
.deals tbody tr { cursor: pointer; }
.deals tbody tr:hover { background: #f7f9fc; }
.deals input[type="checkbox"] { width: auto; margin: 0; }
.deals .select-all-cell, .deals .select-cell {
  width: 38px; text-align: center; padding-left: 10px; padding-right: 10px;
}
.deals .select-all-cell input { vertical-align: middle; }
.vin-cell { white-space: nowrap; }
.vin-copy { display: inline-flex; align-items: center; justify-content: center;
  width: 1.5em; height: 1.5em; margin-left: 5px; padding: 0; vertical-align: middle;
  border: 1px solid var(--line); border-radius: 4px; background: #fff;
  color: var(--muted); cursor: pointer; }
.vin-copy:hover { border-color: var(--brand); color: var(--brand); }
.vin-copy.copied { color: var(--ok); border-color: var(--ok); }
.vin-copy svg { display: block; }

.stage-badge { background: #eef1f6; border-radius: 20px; padding: 2px 10px;
  font-size: 12px; white-space: nowrap; }
.stage-badge.big { font-size: 14px; padding: 4px 14px; }
.dot { font-size: 14px; }
.dot-ok { color: var(--ok); }
.dot-bad { color: var(--bad); }
.docs-cell { line-height: 1; max-width: 190px; }
.docs-cell .dot { font-size: 12px; margin: 0 1px; cursor: default; }
.docs-done { color: var(--ok); font-size: 18px; font-weight: 700; cursor: default; }
.docs-missing-count { color: var(--bad); font-size: 18px; font-weight: 800;
  font-variant-numeric: tabular-nums; cursor: default; }
.dot-opt { color: var(--opt); }
.work-tasks-cell { text-align: center; white-space: nowrap; }
.client-calc-cell {
  white-space: nowrap; font-variant-numeric: tabular-nums;
}
.client-refund { color: var(--ok); font-weight: 800; font-variant-numeric: tabular-nums; }
.work-task-alert {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 24px; height: 24px; padding: 0 7px;
  border-radius: 999px; background: #fde7e7; color: #9b1c1c;
  border: 1px solid #eab3b3; font-weight: 700; font-size: 12px;
}
.work-task-ok { color: var(--ok); font-size: 18px; font-weight: 700; }
.work-summary-open {
  border-color: #c8d6ea; background: #f7fbff; color: var(--brand);
}
.work-summary-box { width: min(860px, 96vw); }
.work-summary-body {
  text-align: left; max-height: 76vh; padding: 8px;
}
.work-summary-table {
  width: 100%; border-collapse: collapse; background: #fff;
  border: 1px solid var(--line); border-radius: 8px; overflow: hidden;
  font-size: 13px;
}
.work-summary-table th,
.work-summary-table td {
  text-align: left; vertical-align: top; padding: 5px 7px;
  border-bottom: 1px solid var(--line);
}
.work-summary-table th {
  background: #fafbfc; color: var(--muted); font-size: 11px;
  text-transform: uppercase; letter-spacing: .03em;
}
.work-summary-table tr:last-child td { border-bottom: 0; }
.work-summary-vin { width: 245px; border-right: 1px solid var(--line); }
.work-summary-manager { width: 150px; border-right: 1px solid var(--line); }
.work-summary-car { display: block; font-weight: 700; margin-bottom: 1px; }
.work-summary-vin .mono { white-space: nowrap; }
.work-summary-manager b,
.work-summary-manager span { display: block; }
.work-summary-manager span { color: var(--muted); font-size: 12px; margin-top: 1px; }
.work-summary-task { white-space: pre-wrap; }
.work-summary-empty { margin: 8px 0; text-align: left; padding: 0 4px; }
.quick-tasks-box { width: min(920px, 96vw); }
.quick-tasks-body {
  text-align: left; display: grid; gap: 12px; max-height: 82vh; padding: 12px;
}
.quick-task-block {
  background: #fff; border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px;
}
.quick-task-block h2 { margin: 0 0 8px; }
.quick-task-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.quick-task-actions { display: flex; align-items: center; gap: 8px; }
.quick-task-list { display: flex; flex-direction: column; gap: 6px; }
.quick-task-row {
  display: grid; grid-template-columns: 1fr 30px; gap: 6px; align-items: start;
}
.quick-task-text {
  margin: 0; min-height: 34px; resize: none; overflow: hidden;
  line-height: 1.35; font-size: 13px; padding: 7px 9px;
}
.quick-task-save { padding: 6px 10px; font-size: 13px; }
.quick-task-auto-table { margin-top: 2px; }
.quick-task-status, .quick-task-empty { margin: 6px 0 0; }
.manager-cell { min-width: 120px; }
.manager-list-name { display: block; font-weight: 700; color: var(--ink); }
.manager-list-phone { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
.closed-head { color: var(--muted); }

/* Deal card */
.deal-sub { color: var(--muted); margin-top: 4px; }
.manager-badge {
  display: inline-flex; align-items: center; vertical-align: middle;
  margin-left: 8px; padding: 3px 10px; border-radius: 999px;
  background: var(--brand); color: #fff; font-size: 12px; font-weight: 700;
}
.deal-head-actions { display: flex; flex-direction: column; gap: 8px; align-items: flex-end; }
.warnings { background: var(--warn-bg); border: 1px solid var(--warn-line);
  border-radius: var(--radius); padding: 12px 16px; margin-bottom: 16px; }
.warnings ul { margin: 6px 0 0; padding-left: 20px; }
.docs-summary { border-radius: var(--radius); padding: 12px 16px; margin-bottom: 12px;
  font-size: 14px; border: 1px solid var(--line); }
.docs-summary.ok { background: #e7f6ec; color: #14612f; border-color: #9dd6b0; }
.docs-summary.missing { background: #fdecec; color: #8a1f1f; border-color: #eab3b3; }
.docs-summary ul { margin: 6px 0 0; padding-left: 20px;
  display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 2px 18px; }

.deal-form { background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px; }
.deal-form details { border-top: 1px solid var(--line); padding: 12px 0; }
.deal-form summary { cursor: pointer; font-weight: 600; font-size: 15px;
  padding: 4px 0; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 10px; }
input, select { font: inherit; width: 100%; padding: 8px 10px; margin-top: 3px;
  border: 1px solid var(--line); border-radius: 7px; background: #fff; color: var(--ink); }
textarea { font: inherit; width: 100%; padding: 8px 10px; margin-top: 3px;
  border: 1px solid var(--line); border-radius: 7px; background: #fff; color: var(--ink);
  resize: vertical; }
input.vin { text-transform: uppercase; letter-spacing: .05em; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }

/* Line tables */
table.lines { width: 100%; border-collapse: collapse; margin: 6px 0; }
.lines th { text-align: left; font-size: 12px; color: var(--muted); padding: 4px 6px; }
.lines td { padding: 3px 6px; }
.lines input { margin: 0; }
.lines .delta { white-space: nowrap; font-variant-numeric: tabular-nums; }
.lines .cur { width: 70px; text-transform: uppercase; }
.del-line, .del-file { border: none; background: none; color: var(--bad);
  padding: 2px 6px; }
.add-line { margin-top: 4px; }
.delta.plus { color: var(--bad); }
.delta.minus { color: var(--ok); }

.translit { border: 1px solid var(--line); border-radius: 8px; padding: 12px;
  margin-top: 12px; }
.translit legend { font-size: 12px; color: var(--muted); padding: 0 6px; }
.translit .fill { margin-top: 4px; font-size: 12px; padding: 4px 10px; }
.freeze { display: flex; align-items: center; gap: 8px; }
.freeze input { width: auto; margin: 0; }
.fill-translit { margin-bottom: 10px; }

/* Режим просмотра / редактирования */
.deal-fields, .profit-fields { border: 0; margin: 0; padding: 0; min-width: 0; }
.deal-fields input:disabled,
.deal-fields select:disabled,
.deal-fields textarea:disabled,
.profit-fields input:disabled,
.profit-fields select:disabled,
.profit-fields textarea:disabled {
  background: #f4f6f9; color: var(--ink); opacity: 1;
  -webkit-text-fill-color: var(--ink); cursor: default;
}
input[readonly] { background: #f0f2f6; }

/* Блок расчёта: узкие поля, порядок справа налево */
.calc-date { max-width: 220px; }
.calc-grid { display: flex; flex-wrap: wrap; gap: 12px; direction: rtl; margin: 6px 0 12px; }
.calc-field { direction: ltr; display: flex; flex-direction: column; width: 120px; }
.calc-field span { font-size: 11px; color: var(--muted); min-height: 26px; }
.calc-input { width: 100%; max-width: 120px; margin-top: 2px; }
.calc-field.total span { color: var(--ink); font-weight: 600; }
.calc-field.total .calc-input { font-weight: 700; background: #eef6f0; }

.translit-actions { display: flex; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.translit-actions button { font-size: 13px; padding: 6px 12px; }

/* Прибыль / профили */
.profit-fields { margin-top: 18px; }
.profit-section { background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 16px; }
.profit-section .lines { table-layout: auto; }
.profit-cats { font-size: 13px; color: var(--muted); margin: 8px 0; }
.profit-cats b { color: var(--ink); font-variant-numeric: tabular-nums; }
#profit-table td, #recipients td { font-variant-numeric: tabular-nums; }
.profit-share, .overpay-share { display: inline-block; min-width: 82px; }
.profit-adjust { display: inline-flex; align-items: center; gap: 4px; margin-left: 8px; }
.profit-adjust select.manual-kind {
  width: 58px; margin: 0; padding: 5px 6px; font-size: 13px;
}
.profit-adjust input.manual-value {
  width: 86px; margin: 0; padding: 5px 7px; font-size: 13px;
}
.sum-row td { font-weight: 600; color: var(--muted); }
.bad-sum { color: var(--bad); }
table.lines .pct { width: 100px; }
.add-rcp { margin-top: 6px; }
.profit-final { margin: 10px 0 0; padding: 8px 12px; background: #eef6f0;
  border-radius: 8px; font-size: 15px; }
.profit-final b { font-variant-numeric: tabular-nums; }
#recipients input[type="radio"] { width: auto; margin: 0; }
.balance { margin-top: 10px; font-size: 13px; color: var(--muted); }
.balance b { color: var(--ink); font-variant-numeric: tabular-nums; }
.bl-third-line { margin-top: 4px; }
.pay-third { display: flex; align-items: center; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.pay-third input[type="radio"] { width: auto; margin: 0; }
.chk { display: flex; align-items: center; gap: 8px; margin: 6px 0 10px; }
.chk input { width: auto; margin: 0; }
.customs-res { font-size: 13px; }
.customs-res.ok { color: var(--ok); }
.customs-res.bad { color: var(--bad); }
.customs-block { margin-top: 24px; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px; }
.customs-block h2 { margin: 0 0 12px; }
.customs-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px; }
.customs-form label { margin: 0; }
.customs-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 14px; }
.customs-total-wrap { font-size: 16px; }
.customs-total-wrap b { font-variant-numeric: tabular-nums; }

/* Главная */
.home-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px; margin-top: 16px; }
.home-card { display: flex; flex-direction: column; gap: 6px; background: var(--card);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.home-card:hover { border-color: var(--brand); text-decoration: none;
  box-shadow: 0 4px 16px rgba(0,0,0,.06); }
.home-ico { font-size: 30px; }
.home-title { font-weight: 700; font-size: 17px; color: var(--ink); }
.home-desc { color: var(--muted); font-size: 13px; }

/* Быстрая навигация */
.quick-nav { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }

/* Предварительный расчёт (таблица) */
.calc-toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.calc-status { color: var(--muted); font-size: 13px; }
/* Таблица во всю ширину экрана (выходит за пределы .container), чтобы влезала без прокрутки */
.sheet-wrap { width: 100vw; margin-left: calc(50% - 50vw); padding: 0 14px;
  overflow-x: auto; }
table.sheet { border-collapse: collapse; font-size: 14px; margin: 0 auto;
  background: var(--card); border: 1px solid var(--line); }
table.sheet th, table.sheet td { border: 1px solid var(--line); padding: 0; }
table.sheet th { background: #fafbfc; padding: 5px 4px; text-align: center; }
.col-letter { font-weight: 700; color: var(--muted); font-size: 13px; }
.col-label { font-size: 12px; color: var(--muted); white-space: nowrap; }
.rownum, .rownum-h { background: #fafbfc; color: var(--muted); text-align: center;
  padding: 6px 8px; font-size: 14px; font-variant-numeric: tabular-nums; }
.rownum { cursor: pointer; user-select: none; }
tr.row-selected .rownum { background: var(--brand); color: #fff; }
tr.row-selected input.cell { background: #eaf1fc; }
tr.row-selected input.cell.computed { background: #dcecdf; }
table.sheet input.cell { width: 92px; border: 0; padding: 8px 7px; margin: 0;
  border-radius: 0; background: transparent; text-align: right;
  font-variant-numeric: tabular-nums; font-size: 14px; }
table.sheet input.cell.cell-text { width: 150px; text-align: left; }
table.sheet input.cell:focus { outline: 2px solid var(--brand); outline-offset: -2px;
  background: #fff; text-align: left; }
table.sheet input.cell.computed { background: #eef6f0; font-weight: 600; }
.to-deal-btn { border: 1px solid var(--brand); color: var(--brand); background: #fff;
  border-radius: 6px; padding: 4px 7px; font-size: 11px; white-space: nowrap; margin: 2px; }
.to-deal-btn:hover { background: var(--brand); color: #fff; }
.act, .act-h { background: #fafbfc; }
.view-note { background: #eef1f6; color: var(--muted); border-radius: 8px;
  padding: 8px 14px; margin-bottom: 12px; font-size: 13px; }
.hint { color: var(--muted); font-size: 12px; margin: 8px 0 0; }

/* Documents */
.client-calcs { background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px; margin-bottom: 18px; }
.client-calcs-head { display: flex; justify-content: space-between; align-items: center;
  gap: 10px; margin-bottom: 8px; }
.client-calcs-head h2 { margin: 0; }
.client-calc-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.client-calc-grid label { margin-bottom: 0; }
.client-calc-errors { background: #fdecec; border: 1px solid #eab3b3; color: #8a1f1f;
  border-radius: 8px; padding: 8px 10px; margin: 8px 0; font-size: 13px; }
.work-tasks { background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px; margin-bottom: 18px; }
.work-tasks-toolbar { display: flex; justify-content: space-between; align-items: center;
  gap: 10px; margin-bottom: 10px; }
.work-tasks-toolbar h2 { margin: 0; }
.work-tasks-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.add-work-task { width: 34px; height: 34px; padding: 0; border-radius: 999px;
  font-size: 22px; line-height: 1; }
.save-work-tasks { padding: 6px 12px; font-size: 13px; }
.work-tasks-list { display: flex; flex-direction: column; gap: 8px; }
.work-task-row { display: grid; grid-template-columns: 24px 1fr; gap: 8px;
  align-items: center; }
.work-task-check { margin: 0; display: flex; align-items: center; justify-content: center; }
.work-task-check input { width: auto; margin: 0; }
.work-task-row textarea {
  margin: 0; min-height: 38px; overflow: hidden; resize: none; line-height: 1.45;
}
.work-task-row.done textarea {
  text-decoration: line-through; color: var(--muted); background: #f4f6f9;
}
.work-task-row.done textarea:disabled {
  -webkit-text-fill-color: var(--muted);
}
.work-tasks-empty, .work-tasks-status { margin: 6px 0 0; }
.documents { margin-top: 22px; }
.work-tasks + .documents { margin-top: 0; }
.doc-slot { background: var(--card); border: 1px solid var(--line);
  border-left: 4px solid var(--opt); border-radius: var(--radius);
  padding: 12px 14px; margin-bottom: 10px; }
.doc-slot.ok { border-left-color: var(--ok); }
.doc-slot.required { border-left-color: var(--bad); }
.doc-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.doc-name { font-weight: 600; }
.custom-documents { margin-top: 10px; }
.custom-doc-slot { border-left-color: var(--opt); }
.custom-doc-head { align-items: center; }
.custom-doc-title { flex: 1 1 220px; min-width: 180px; margin: 0; font-weight: 600; }
.custom-doc-tag { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; color: var(--muted); }
.custom-doc-tag input { width: auto; margin: 0; }
.custom-doc-delete { margin-left: auto; }
.custom-doc-add { display: block; width: 100%; margin: 4px 0 0; padding: 7px; border: 1px dashed var(--brand);
  background: transparent; color: var(--brand); font-size: 22px; line-height: 1; border-radius: 8px; cursor: pointer; }
.custom-doc-add:hover { background: #f0f6ff; }
.doc-stub { display: flex; align-items: center; gap: 8px; margin: 6px 0 2px;
  font-size: 13px; color: var(--muted); }
.doc-stub input { width: auto; margin: 0; }
.tag { font-size: 11px; padding: 1px 8px; border-radius: 20px; background: #eef1f6; }
.tag.req { background: #fde7e7; color: #8a1f1f; }
.tag.brk { background: #e7f0fb; color: #17457f; }
.tag.mult { background: #eef7ec; color: #1a6b3c; }
/* Документы — компактные иконки (предпросмотр в модалке по клику) */
.doc-chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.doc-chip { display: inline-flex; align-items: center; gap: 6px; cursor: pointer;
  background: #fff; border: 1px solid var(--line); border-radius: 8px;
  padding: 5px 8px; max-width: 100%; }
.doc-chip:hover { border-color: var(--brand); background: #f4f9ff; }
.doc-ico { font-size: 18px; line-height: 1; }
.doc-chip-name { font-size: 12px; max-width: 150px; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; }
.doc-chip .del-file { border: none; background: none; color: var(--bad);
  padding: 0 2px; font-size: 13px; }

/* Модальный предпросмотр */
body.modal-open { overflow: hidden; }
.modal { position: fixed; inset: 0; z-index: 100; display: flex;
  align-items: center; justify-content: center; padding: 24px; }
.modal[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(15,20,30,.6); }
.modal-box { position: relative; background: var(--card); border-radius: 12px;
  width: min(900px, 96vw); max-height: 92vh; display: flex; flex-direction: column;
  overflow: hidden; box-shadow: 0 10px 40px rgba(0,0,0,.3); }
.modal-head { display: flex; align-items: center; gap: 12px; padding: 10px 14px;
  border-bottom: 1px solid var(--line); }
.modal-title { flex: 1; font-weight: 600; word-break: break-all; }
.modal-head-actions { display: flex; gap: 8px; }
.modal-body { padding: 12px; overflow: auto; background: #f4f5f7; text-align: center; }
.modal-img { max-width: 100%; max-height: 78vh; }
.modal-pdf { width: 100%; height: 78vh; border: 0; }
.dropzone { margin-top: 8px; border: 2px dashed var(--line); border-radius: 8px;
  padding: 12px; text-align: center; color: var(--muted); font-size: 13px;
  display: flex; align-items: center; justify-content: center; gap: 12px; flex-wrap: wrap; }
.dropzone.drag { border-color: var(--brand); background: #f0f6ff; }
.extras-fields { margin: 12px 0 0; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; }
.extras-fields legend { padding: 0 6px; font-weight: 600; }
.extras-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.extras-grid > div { display: grid; gap: 6px; }
.extras-grid strong { font-size: 13px; }
.extras-grid label { display: grid; grid-template-columns: 22px minmax(0, 1fr); align-items: center; gap: 6px; margin: 0; }
.extra-manual { width: 92px; min-width: 72px; }
.extras-head { min-width: 170px; }
.extras-remaining { display: block; margin-top: 3px; font-size: 11px; font-weight: 400; color: var(--muted); white-space: nowrap; }
.final-extra-errors { margin: 8px 0; }
@media (max-width: 700px) { .extras-grid { grid-template-columns: 1fr; } }
.file-pick { display: inline-block; color: var(--brand); cursor: pointer;
  margin: 0; border: 1px solid var(--brand); border-radius: 7px; padding: 5px 12px; }
.file-pick input { display: none; }
.up-progress { width: 140px; height: 8px; }
.merge-btn { font-size: 13px; }
.missing-list { color: #8a1f1f; }
.custom-doc-print-source { display: none; }
.custom-doc-print-page { break-before: page; page-break-before: always; min-height: 95vh; }
.custom-doc-print-page h3 { margin: 0 0 12px; font-size: 14px; }
.custom-doc-print-page img { display: block; width: 100%; max-height: 94vh; object-fit: contain; }

/* Управление сделкой: архив / удаление */
.deal-manage { display: flex; gap: 10px; flex-wrap: wrap;
  margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); }
.deal-manage form { margin: 0; }
.btn.danger { color: var(--bad); border-color: #eab3b3; }
.btn.danger:hover { background: #fdecec; border-color: var(--bad); }

/* Кнопки действий в строке списка */
.row-actions { white-space: nowrap; text-align: right; }
.row-actions form { display: inline-block; margin: 0; }
.icon-btn { padding: 4px 8px; font-size: 14px; line-height: 1; border-radius: 6px; }
.icon-btn.danger { color: var(--bad); border-color: #eab3b3; }
.icon-btn.danger:hover { background: #fdecec; border-color: var(--bad); }

/* Login */
.login-page { display: flex; align-items: center; justify-content: center;
  min-height: 100vh; background: var(--bg); }
.login-card { background: var(--card); border: 1px solid var(--line);
  border-radius: 14px; padding: 28px; width: 340px; box-shadow: 0 6px 30px rgba(0,0,0,.06); }
.login-card h1 { text-align: center; margin: 0; }
.login-card .sub { text-align: center; color: var(--muted); margin: 4px 0 18px; }
.login-card button { width: 100%; margin-top: 8px; }
.search-form { display: flex; gap: 10px; margin-bottom: 14px; }
.search-form input { flex: 1; }
.page-head.embedded { margin-bottom: 10px; align-items: center; }
.page-head.embedded h2 { margin: 0; }
.managers-section { margin: 16px 0 22px; }
.inline-actions { position: static; background: transparent; padding: 10px 0 0; }

/* Итоговые расчёты */
.final-session { background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px; margin: 18px 0; }
.final-page-head { margin-bottom: 0; }
.final-actions-island {
  position: sticky; top: 76px; z-index: 9;
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  background: var(--card);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 16px; margin: 18px 0;
  box-shadow: 0 6px 18px rgba(0,0,0,.08);
  backdrop-filter: blur(4px);
}
.final-actions-island .head-actions:last-child { margin-left: auto; }
.final-session + .final-session { border-top: 4px solid var(--line); padding-top: 20px; }
.final-session.legacy { opacity: .95; }
.final-session.calc-archive { margin-top: 34px; border-top: 6px solid #c7ccd5;
  background: #fafbfc; }
.final-session-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.final-session-head h2 { margin: 0; }
.print-pick { display: inline-flex; align-items: center; gap: 5px; margin: 0 4px 0 0;
  color: var(--muted); font-size: 12px; font-weight: 400; }
.print-pick input { width: auto; margin: 0; }
.summary-print-cols { display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin-top: 10px; padding: 8px 10px; background: #f7f9fc; border-radius: 8px; }
.summary-print-cols label { display: inline-flex; align-items: center; gap: 5px;
  margin: 0; color: var(--ink); font-size: 12px; }
.summary-print-cols input { width: auto; margin: 0; }
.print-output { display: none; }
.summary-receipt-print {
  width: 18px; height: 18px; padding: 0; margin-left: 5px;
  display: inline-flex; align-items: center; justify-content: center;
  vertical-align: text-bottom; border-radius: 4px; font-size: 11px; line-height: 1;
  border: 1px solid var(--line); color: var(--ink); background: #fff;
  text-decoration: none;
}
.summary-receipt-print:hover { border-color: var(--brand); text-decoration: none; }
.final-deal-card { border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; margin-top: 14px; background: #fff; }
.final-deal-head { display: flex; justify-content: space-between; align-items: baseline;
  gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.final-deal-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.final-deal-actions form { margin: 0; }
.final-deal-actions button { padding: 5px 10px; font-size: 13px; }
.final-car { font-weight: 700; }
.final-profit-table { table-layout: fixed; font-size: 14px; }
.final-profit-table th, .final-profit-table td { vertical-align: top; overflow-wrap: anywhere; }
.final-profit-table th:first-child, .final-profit-table td:first-child { width: 20%; }
.final-profit-table td { font-variant-numeric: tabular-nums; }
.final-settled { display: inline-flex; align-items: center; gap: 6px; margin: 0 6px 0 0;
  color: var(--ink); font-size: 14px; }
.final-settled input { width: auto; margin: 0; }
.final-summary { background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px; margin: 20px 0 28px;
  width: 100%; max-width: 100%; }
.final-summary-wrap { overflow-x: auto; margin-top: 12px; }
.final-summary-table { width: max-content; table-layout: auto; font-size: 13px; }
.final-summary-table th, .final-summary-table td {
  vertical-align: top; font-variant-numeric: tabular-nums;
}
.final-summary-table th, .final-summary-table td { white-space: nowrap; overflow-wrap: normal; }
.final-summary-table th:first-child, .final-summary-table td:first-child {
  min-width: 190px; max-width: 260px; white-space: normal; overflow-wrap: anywhere;
}
.final-summary-table th:nth-child(2), .final-summary-table td:nth-child(2) {
  min-width: 165px; white-space: nowrap; overflow-wrap: normal;
}
.final-summary-table th:not(:first-child):not(:nth-child(2)),
.final-summary-table td:not(:first-child):not(:nth-child(2)) {
  width: 1%; text-align: left;
}
.final-summary-table .participant-start {
  border-left: 2px solid #cfd5de; min-width: 96px;
}
.final-summary-table .participant-start + th,
.final-summary-table .participant-start + td,
.final-summary-table .net-col + th,
.final-summary-table .net-col + td {
  min-width: 74px;
}
.final-summary-table thead .participant-start,
.final-summary-table thead .net-col {
  background: #f7f9fc; position: relative; padding-top: 18px;
}
.final-summary-table thead .participant-start::before,
.final-summary-table thead .net-col::before {
  content: attr(data-participant-name);
  position: absolute; left: 6px; top: 2px; max-width: 158px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 12px; color: var(--muted);
}
.final-summary-table .net-col {
  border-left: 3px solid var(--brand);
  background: #f7fbff;
  font-weight: 700; min-width: 112px;
}
.summary-paid-row td { background: #fbfcff; }
.summary-paid-row input {
  width: 92px; min-width: 92px; margin: 0; padding: 5px 7px;
  font-size: 12px; font-variant-numeric: tabular-nums;
}
.summary-paid-row select {
  width: 118px; min-width: 118px; margin: 0; padding: 5px 7px;
  font-size: 12px;
}
.summary-paid-row .summary-paid-date {
  width: 76px; min-width: 76px;
}
.summary-paid-row .summary-paid-rate {
  width: 72px; min-width: 72px;
}
.summary-paid-row .summary-paid-note {
  display: block; width: 100%; min-width: 150px; margin-top: 5px;
}
.summary-note-print {
  display: none; color: var(--muted); font-size: 11px; margin-top: 2px;
}
.summary-paid-meta {
  display: flex; align-items: center; gap: 5px;
}
.summary-paid-row.locked input[readonly],
.summary-paid-row.locked select {
  background: #f0f2f6; border-color: transparent; cursor: default;
  pointer-events: none;
}
.summary-paid-actions {
  display: inline-flex; align-items: center; gap: 4px; margin-right: 7px;
  vertical-align: middle;
}
.summary-paid-actions .icon-btn {
  width: 26px; height: 26px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
}
.summary-rest-row td {
  border-top: 1px solid var(--line);
}
.summary-paid-print { display: none; }

@media (max-width: 680px) {
  .row2, .row3 { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; }
  .deal-head { flex-direction: column; }
  .deal-head-actions { align-items: flex-start; }
  .final-actions-island { align-items: flex-start; flex-direction: column; }
  .final-actions-island .head-actions:last-child { margin-left: 0; }
}

@media print {
  @page { margin: 8mm; }

  body.print-selected-blocks .topbar,
  body.print-selected-blocks .quick-nav,
  body.print-selected-blocks .page-head,
  body.print-selected-blocks .flashes,
  body.print-selected-blocks .container > :not(.print-output) {
    display: none !important;
  }
  body.print-selected-blocks .container {
    max-width: 1160px; margin: 0 auto; padding: 0 12px;
  }
  body.print-selected-blocks .print-output {
    display: block !important;
    font-size: 10px;
    zoom: .78;
  }
  body.print-selected-blocks .print-output h2 { font-size: 13px; margin: 6px 0; }
  body.print-selected-blocks .print-output .profit-cats { font-size: 9px; margin: 4px 0; }
  body.print-selected-blocks .print-output table.lines { font-size: 9px; }
  body.print-selected-blocks .print-output .final-extra-value { display: inline; }
  body.print-selected-blocks .print-output .lines th,
  body.print-selected-blocks .print-output .lines td { padding: 1px 3px; }
  body.print-selected-blocks .print-output .final-session,
  body.print-selected-blocks .print-output .final-summary,
  body.print-selected-blocks .print-output .final-deal-card {
    break-inside: avoid; page-break-inside: avoid;
    box-shadow: none; margin: 0 0 8px; border-color: #cfd5de;
    padding: 8px 10px;
  }
  body.print-selected-blocks .print-output a {
    color: inherit; text-decoration: none;
  }
  body.print-selected-blocks .print-output .final-summary-wrap {
    overflow: visible;
  }
  body.print-selected-blocks .print-output .summary-paid-print {
    display: inline;
  }
  body.print-selected-blocks .print-output .summary-note-print {
    display: block;
  }
}
