:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --ink: #1a2233;
  --muted: #6b7688;
  --line: #e3e7ee;
  --brand: #1f4e79;
  --brand-ink: #16324e;
  --accent: #2e7d5b;
  --danger: #c0392b;
  --amber: #b7791f;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16,32,60,.06), 0 6px 20px rgba(16,32,60,.06);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 15px/1.5 -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- topbar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 0 24px; height: 60px;
  background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--brand-ink); font-size: 16px; }
.brand:hover { text-decoration: none; }
.brand-mark {
  display: grid; place-items: center; width: 30px; height: 30px;
  background: var(--brand); color: #fff; border-radius: 8px; font-size: 18px; font-weight: 700;
}
.nav { display: flex; align-items: center; gap: 20px; }
.nav a { color: var(--muted); font-weight: 500; }
.nav a:hover { color: var(--ink); text-decoration: none; }

/* ---------- layout ---------- */
.wrap { max-width: 1000px; margin: 28px auto; padding: 0 24px; }
.page-head { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.page-head h1 { font-size: 24px; margin: 0; }
.sub { color: var(--muted); margin: 4px 0 0; }
.footer { text-align: center; color: var(--muted); padding: 30px; font-size: 13px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 16px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font: inherit; font-weight: 600;
  cursor: pointer; transition: .15s;
}
.btn:hover { text-decoration: none; border-color: #cdd4de; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-ink); }
.btn-ghost { background: transparent; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-lg { padding: 13px 26px; font-size: 16px; }

/* ---------- cards / panels ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.section { padding: 22px 24px; }
.section + .section { border-top: 1px solid var(--line); }
.section h2 { font-size: 14px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0 0 16px; }

/* ---------- form ---------- */
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: 1fr 1fr; }
.g3 { grid-template-columns: 1fr 1fr 1fr; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field.wide { grid-column: 1 / -1; }
label { font-size: 13px; font-weight: 600; color: #3d4757; }
input, select, textarea {
  font: inherit; padding: 9px 11px; border: 1px solid var(--line);
  border-radius: 8px; background: #fff; color: var(--ink); width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(31,78,121,.12); }
textarea { resize: vertical; min-height: 76px; }
.hint { font-size: 12px; color: var(--muted); }

.two-parties { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.party-title { font-weight: 700; color: var(--brand-ink); margin: 0 0 12px; padding-bottom: 8px; border-bottom: 2px solid var(--line); }

/* ---------- items table ---------- */
table.items { width: 100%; border-collapse: collapse; }
table.items th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); padding: 6px 8px; }
table.items td { padding: 4px 6px; vertical-align: top; }
table.items input { padding: 7px 9px; }
.col-num { width: 34px; color: var(--muted); text-align: center; padding-top: 14px !important; }
.col-x { width: 40px; }
.icon-btn { border: none; background: none; color: var(--muted); cursor: pointer; font-size: 18px; padding: 8px; border-radius: 6px; }
.icon-btn:hover { color: var(--danger); background: #fbe9e7; }

.form-actions { display: flex; align-items: center; gap: 14px; padding: 20px 24px; background: #fafbfc; border-top: 1px solid var(--line); border-radius: 0 0 var(--radius) var(--radius); }
.form-actions .spacer { flex: 1; }
.check { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 14px; }
.check input { width: auto; }

/* ---------- stats ---------- */
.stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 14px; margin-bottom: 18px; }
.stat {
  display: flex; flex-direction: column; gap: 4px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow); color: var(--ink); transition: .15s;
}
a.stat:hover { text-decoration: none; border-color: #cdd4de; transform: translateY(-1px); }
.stat-num { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--brand-ink); }
.stat-lbl { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.stat-money .stat-num { color: var(--accent); font-size: 20px; }

/* ---------- filters ---------- */
.filters { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.filters .filter-search { flex: 1; min-width: 240px; }
.filters select { width: auto; min-width: 150px; }

/* ---------- list ---------- */
.right { text-align: right; }
.empty-row { text-align: center; color: var(--muted); padding: 40px !important; }
.table-wrap { overflow-x: auto; }
table.list { width: 100%; border-collapse: collapse; background: var(--surface); }
table.list th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); padding: 12px 16px; border-bottom: 1px solid var(--line); }
table.list td { padding: 14px 16px; border-bottom: 1px solid var(--line); }
table.list tr:last-child td { border-bottom: none; }
table.list tr:hover td { background: #fafbfd; }
.mono { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 13px; }

/* ---------- badges ---------- */
.badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge.draft { background: #eef1f5; color: #55627a; }
.badge.generated { background: #e6f4ec; color: var(--accent); }
.badge.on_review { background: #fff4e0; color: #a86616; }
.badge.approved { background: #e3f0fb; color: #1d6fb8; }
.badge.rejected { background: #fbe4e2; color: var(--danger); }
.badge.signed { background: #e7effa; color: var(--brand); }
.badge.archived { background: #f3eee2; color: var(--amber); }

/* ---------- auth ---------- */
.user-chip { display: inline-flex; flex-direction: column; line-height: 1.15; margin-left: 8px; }
.user-name { font-size: 13px; font-weight: 600; color: var(--ink); }
.user-role { font-size: 11px; color: var(--muted); }
.logout { color: var(--muted); font-size: 13px; }
.login-wrap { max-width: 440px; margin: 6vh auto 0; }
.login-card .section:first-child { text-align: center; }
.login-brand { display: inline-flex; align-items: center; gap: 10px; font-size: 20px; font-weight: 700; color: var(--brand-ink); }
.login-brand .brand-mark { width: 34px; height: 34px; font-size: 20px; }
.login-card .field { text-align: left; }
.login-card button { width: 100%; justify-content: center; }
.login-demo { background: #fafbfc; }
.demo-list { list-style: none; margin: 10px 0 0; padding: 0; }
.demo-list li { padding: 5px 0; font-size: 14px; color: #3d4757; }

/* ---------- approval ---------- */
.approval-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.approval-form { display: flex; gap: 8px; align-items: center; }
.approval-form input[type=text] { width: 260px; }
.timeline { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--line); }
.tl-item { display: flex; gap: 12px; padding-bottom: 14px; }
.tl-item:last-child { padding-bottom: 0; }
.tl-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--brand); margin-top: 5px; flex-shrink: 0; position: relative; }
.tl-item:not(:last-child) .tl-dot::after { content: ""; position: absolute; left: 50%; top: 12px; width: 2px; height: calc(100% + 6px); background: var(--line); transform: translateX(-50%); }
.tl-body { font-size: 14px; }
.tl-comment { color: var(--danger); font-style: italic; margin: 3px 0; }

/* ---------- signature ---------- */
.sign-box { background: #f4faf6; border: 1px solid #cfe8d8; border-radius: var(--radius); padding: 18px; }
.sign-badge { display: inline-block; background: var(--accent); color: #fff; font-weight: 600; font-size: 13px; padding: 4px 12px; border-radius: 20px; }
.sign-hashes { margin-top: 12px; padding-top: 12px; border-top: 1px solid #cfe8d8; }
.hash-row { display: flex; flex-direction: column; gap: 2px; padding: 6px 0; }
.hash-row > span:first-child { font-weight: 600; font-size: 13px; }
.hash-row .hash { font-size: 11px; color: var(--muted); word-break: break-all; }

/* ---------- detail ---------- */
.kv { display: grid; grid-template-columns: 200px 1fr; gap: 8px 16px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.doc-row { display: flex; align-items: center; justify-content: space-between; padding: 12px 0; border-bottom: 1px solid var(--line); }
.doc-row:last-child { border-bottom: none; }
.doc-name { display: flex; align-items: center; gap: 10px; }
.file-ico { width: 30px; height: 30px; border-radius: 6px; display: grid; place-items: center; font-size: 11px; font-weight: 700; color: #fff; }
.file-ico.docx { background: #2b579a; }
.file-ico.pdf { background: #c0392b; }
.dl-group { display: flex; gap: 8px; }

/* ---------- template library ---------- */
.tpl-card { margin-bottom: 16px; }
.tpl-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.tpl-title { font-weight: 700; color: var(--ink); }
.tpl-ver { text-align: right; white-space: nowrap; }
.tpl-note { margin: 12px 0 0; color: #3d4757; font-size: 14px; }
.tpl-block { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.tpl-label { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
.clickable { cursor: pointer; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip { font-family: ui-monospace, "SF Mono", Consolas, monospace; font-size: 12px; background: #eef2f7; color: var(--brand-ink); padding: 3px 9px; border-radius: 6px; }
.history { list-style: none; margin: 10px 0 0; padding: 0; }
.history li { padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 14px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.history li:last-child { border-bottom: none; }
.hist-dl { margin-left: auto; }
.tpl-upload { display: flex; gap: 10px; align-items: center; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.tpl-upload input[type=text] { flex: 1; min-width: 200px; }
.tpl-upload input[type=file] { width: auto; padding: 6px; font-size: 13px; }

/* ---------- empty ---------- */
.empty { text-align: center; padding: 60px 20px; }
.empty .big { font-size: 40px; margin-bottom: 10px; }
.empty p { color: var(--muted); }

/* ---------- ИНН автозаполнение ---------- */
.inn-row { display: flex; gap: 6px; }
.inn-row input { flex: 1; }
.inn-btn { white-space: nowrap; flex-shrink: 0; }

/* ---------- admin users ---------- */
.edit-row > td { background: #fafbfc; padding: 18px 16px !important; }
.user-form-actions { display: flex; gap: 10px; margin-top: 14px; }

/* ---------- конструктор видов ---------- */
.doc-build-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.doc-build-row .doc-num { width: 22px; text-align: center; color: var(--muted); font-weight: 700; flex-shrink: 0; }
.doc-build-row input[type=file] { width: auto; padding: 6px; font-size: 13px; }

.banner { padding: 14px 18px; border-radius: 8px; margin-bottom: 20px; font-weight: 500; }
.banner.err { background: #fbe9e7; color: var(--danger); border: 1px solid #f3c9c2; }
.banner.ok { background: #e6f4ec; color: var(--accent); border: 1px solid #c3e6d1; }

@media (max-width: 760px) {
  .g2, .g3, .two-parties { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; gap: 2px 0; }
  .kv dt { margin-top: 10px; }
  /* компактная шапка: логотип-значок + меню в одну прокручиваемую строку */
  .topbar { height: auto; padding: 10px 16px; gap: 10px; flex-wrap: wrap; }
  .brand span:not(.brand-mark) { display: none; }
  .nav { gap: 14px; flex-wrap: wrap; row-gap: 8px; }
  .user-chip { margin-left: 0; }
  .page-head { flex-wrap: wrap; }
  .page-head > .btn-primary { display: none; }  /* дублирующая «Новая заявка» — в шапке уже есть */
  .stats { grid-template-columns: repeat(2, 1fr); }
  .stat-money { grid-column: 1 / -1; }
}
