/* Кадры — единый набор токенов (docs/09-DESIGN.md), визуальная система «Олимпа». */
@font-face {
  font-family: "Manrope";
  src: url("../fonts/Manrope.946beb949095.ttf") format("truetype");
  font-weight: 200 800;
  font-display: swap;
}

:root {
  --bg: #f3f6fb;
  --surface: #ffffff;
  --surface-muted: #f9fafc;
  --surface-sunken: #f0f3f8;
  --ink: #182b49;
  --ink-soft: #334155;
  --ink-muted: #526176;
  --line: #e1e7ef;
  --line-soft: #edf1f6;
  --line-strong: #c8d2df;
  --accent: #365bd6;
  --accent-hover: #2948b3;
  --accent-soft: #edf1ff;
  --accent-ink: #2d4db8;
  --ok: #065f46;
  --ok-soft: #e7f1ec;
  --ok-line: #b9d6c9;
  --warn: #92400e;
  --warn-soft: #fbf1de;
  --warn-line: #e0c9a0;
  --err: #b91c1c;
  --err-soft: #fbeae8;
  --err-line: #f0c9c4;
  --radius-card: 16px;
  --radius-ctl: 10px;
  --shadow-card: 0 1px 2px rgba(24, 43, 73, 0.05);
  --shadow-raised: 0 4px 16px rgba(24, 43, 73, 0.10);
  --sidebar: 248px;
  font-family: "Manrope", "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); }
body { min-height: 100vh; font-variant-numeric: tabular-nums; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.2; color: var(--ink); }
h1 { font-size: 28px; font-weight: 750; letter-spacing: -0.01em; }
h2 { font-size: 20px; font-weight: 700; }
h3 { font-size: 16px; font-weight: 700; }
p { margin: 0 0 8px; }
small, .small { font-size: 13px; }
.muted { color: var(--ink-muted); }
.icon { flex: none; vertical-align: middle; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
:focus-visible { outline: 3px solid rgba(54, 91, 214, 0.45); outline-offset: 2px; border-radius: 6px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- каркас ---------- */
.layout { display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  background: var(--surface); border-right: 1px solid var(--line); padding: 20px 14px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; gap: 4px;
}
.brand { display: flex; gap: 12px; align-items: center; padding: 4px 8px 18px; color: var(--ink); }
.brand:hover { text-decoration: none; color: var(--ink); }
.brand-mark {
  width: 44px; height: 44px; border-radius: 12px; background: var(--accent); color: #fff;
  display: grid; place-items: center; flex: none;
}
.brand-name { font-weight: 800; font-size: 19px; line-height: 1.1; }
.brand-sub { font-size: 12.5px; color: var(--ink-muted); line-height: 1.2; }
.nav-group { font-size: 11.5px; font-weight: 700; letter-spacing: .06em; color: var(--ink-muted);
  text-transform: uppercase; padding: 14px 10px 6px; }
.nav a {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px; color: var(--ink-soft);
  font-weight: 550; min-height: 44px;
}
.nav a:hover { background: var(--surface-sunken); text-decoration: none; color: var(--ink); }
.nav a.active { background: var(--accent-soft); color: var(--accent-ink); font-weight: 700; }
.nav .count { margin-left: auto; background: #f3c969; color: #4a2c00; border-radius: 999px; font-size: 12px;
  font-weight: 800; padding: 1px 8px; }
.sidebar-foot { margin-top: auto; padding: 16px 10px 0; font-size: 12.5px; color: var(--ink-muted); display: flex; gap: 10px; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 12px 32px; border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, .85); backdrop-filter: blur(6px); position: sticky; top: 0; z-index: 20;
}
.topbar form.search { flex: 1; max-width: 520px; position: relative; }
.topbar form.search input { padding-left: 38px; }
.topbar form.search .icon { position: absolute; left: 12px; top: 12px; color: var(--ink-muted); }
.asof { display: flex; align-items: center; gap: 6px; }
.asof input[type=date] { width: 150px; }
.user-menu { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--surface-sunken); display: grid;
  place-items: center; font-weight: 700; color: var(--ink-soft); }
.menu-toggle { display: none; }
.content { padding: 28px 36px 48px; max-width: 1480px; width: 100%; }
.page-head { display: flex; gap: 16px; align-items: flex-start; justify-content: space-between; margin-bottom: 20px;
  flex-wrap: wrap; }
.page-head .sub { color: var(--ink-muted); margin-top: 4px; }
.page-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.breadcrumbs { font-size: 13px; color: var(--ink-muted); margin-bottom: 6px; }
.breadcrumbs a { color: var(--ink-muted); }

.mode-banner { padding: 10px 36px; font-weight: 600; font-size: 14px; display: flex; gap: 10px; align-items: center; }
.mode-banner.future { background: var(--accent-soft); color: var(--accent-ink); }
.mode-banner.past { background: var(--warn-soft); color: var(--warn); }

/* ---------- карточки ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-card);
  box-shadow: var(--shadow-card); padding: 22px 24px; }
.card + .card { margin-top: 16px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; }
.card.attention { border-left: 5px solid #e7a52b; border-color: #f0d9a6; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-main { grid-template-columns: minmax(0, 1fr) 360px; align-items: start; }
.stat { display: block; color: var(--ink); }
.stat:hover { text-decoration: none; box-shadow: var(--shadow-raised); }
.stat .label { color: var(--ink-muted); font-weight: 600; font-size: 14px; }
.stat .value { font-size: 32px; font-weight: 800; letter-spacing: -0.02em; margin: 6px 0 2px; line-height: 1.1; }
.stat .value.money { font-size: 26px; }
.stat .hint { color: var(--ink-muted); font-size: 13.5px; }
.stack > * + * { margin-top: 12px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.sticky { position: sticky; top: 84px; }
hr { border: none; border-top: 1px solid var(--line); margin: 16px 0; }
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; margin: 0; }
dl.kv dt { color: var(--ink-muted); }
dl.kv dd { margin: 0; font-weight: 600; }

/* ---------- кнопки и поля ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 18px;
  border-radius: var(--radius-ctl); border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
  font: inherit; font-weight: 650; cursor: pointer; white-space: nowrap;
}
.btn:hover { text-decoration: none; background: var(--surface-sunken); color: var(--ink); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); color: #fff; }
.btn-outline { border-color: var(--accent); color: var(--accent); }
.btn-danger { border-color: var(--err); color: var(--err); }
.btn-danger:hover { background: var(--err-soft); color: var(--err); }
.btn-lg { min-height: 48px; font-size: 16px; }
.btn-sm { min-height: 36px; padding: 0 12px; font-size: 14px; }
.btn-link { border: none; background: none; color: var(--accent); padding: 0; min-height: auto; font-weight: 650; }
.btn[disabled], .btn.disabled { opacity: .55; cursor: not-allowed; }
label { font-weight: 600; font-size: 14px; display: block; margin-bottom: 6px; }
input[type=text], input[type=search], input[type=password], input[type=number], input[type=date], input[type=email],
input[type=file], select, textarea {
  width: 100%; min-height: 44px; padding: 9px 12px; border: 1px solid var(--line-strong); border-radius: var(--radius-ctl);
  font: inherit; color: var(--ink); background: #fff;
}
textarea { min-height: 88px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: 3px solid rgba(54,91,214,.18); }
.field { margin-bottom: 16px; }
.field .help { font-size: 13px; color: var(--ink-muted); margin-top: 4px; }
.field .error, .errorlist { color: var(--err); font-size: 13.5px; margin-top: 4px; list-style: none; padding: 0; }
.field.has-error input, .field.has-error select, .field.has-error textarea { border-color: var(--err); background: #fffafa; }
.field.flag input, .field.flag select { background: #fff8e6; border-color: #e0c9a0; }
.checkbox { display: flex; gap: 10px; align-items: flex-start; font-weight: 500; }
.checkbox input { width: 20px; height: 20px; margin-top: 2px; flex: none; }
.choice-cards { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.choice-card { border: 1px solid var(--line-strong); border-radius: 12px; padding: 14px 16px; cursor: pointer;
  display: flex; gap: 10px; align-items: flex-start; font-weight: 500; margin: 0; }
.choice-card:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.choice-card input { margin-top: 3px; }
.choice-card b { display: block; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 18px; }
.form-grid .span-2 { grid-column: span 2; }

/* ---------- таблицы ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
table.data { width: 100%; border-collapse: collapse; font-size: 14.5px; }
table.data th { text-align: left; font-weight: 650; color: var(--ink-muted); font-size: 13px; background: var(--surface-muted);
  padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; position: sticky; top: 0; }
table.data td { padding: 11px 12px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
table.data tr:last-child td { border-bottom: none; }
table.data tr:hover td { background: #fbfcff; }
table.data .num, table.data th.num { text-align: right; white-space: nowrap; }
table.data td.sticky-col, table.data th.sticky-col { position: sticky; left: 0; background: #fff; z-index: 1; min-width: 210px; }
table.data th.sticky-col { background: var(--surface-muted); z-index: 2; }
table.data tr.group td { background: var(--surface-sunken); font-weight: 700; }
table.data tr.excluded td { color: var(--ink-muted); text-decoration: line-through; }
.table-foot { padding: 10px 12px; color: var(--ink-muted); font-size: 13px; }

/* ---------- метки состояний ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; font-weight: 700; border-radius: 999px;
  padding: 2px 10px; border: 1px solid transparent; white-space: nowrap; }
.badge-ok { background: var(--ok-soft); color: var(--ok); border-color: var(--ok-line); }
.badge-warn { background: var(--warn-soft); color: var(--warn); border-color: var(--warn-line); }
.badge-err { background: var(--err-soft); color: var(--err); border-color: var(--err-line); }
.badge-info { background: var(--accent-soft); color: var(--accent-ink); border-color: #cfd9fb; }
.badge-muted { background: var(--surface-sunken); color: var(--ink-muted); border-color: var(--line); }
.alert { border-radius: 12px; padding: 12px 16px; display: flex; gap: 12px; align-items: flex-start; border: 1px solid; }
.alert + .alert { margin-top: 10px; }
.alert-ok { background: var(--ok-soft); color: var(--ok); border-color: var(--ok-line); }
.alert-warn { background: var(--warn-soft); color: var(--warn); border-color: var(--warn-line); }
.alert-err { background: var(--err-soft); color: var(--err); border-color: var(--err-line); }
.alert-info { background: var(--accent-soft); color: var(--accent-ink); border-color: #cfd9fb; }
.alert .title { font-weight: 700; }
.alert ul { margin: 4px 0 0; padding-left: 18px; }
.messages { margin-bottom: 16px; }
.empty { text-align: center; padding: 36px 16px; color: var(--ink-muted); }
.empty .icon { color: var(--line-strong); margin-bottom: 8px; }
.money-label { font-size: 12px; color: var(--ink-muted); font-weight: 600; margin-left: 4px; }
.unknown { color: var(--warn); font-weight: 650; }

/* ---------- вкладки, шаги, списки дел ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; overflow-x: auto; }
.tabs a { padding: 12px 16px; color: var(--ink-muted); font-weight: 650; border-bottom: 3px solid transparent;
  white-space: nowrap; }
.tabs a:hover { color: var(--ink); text-decoration: none; }
.tabs a.active { color: var(--accent-ink); border-color: var(--accent); }
.steps { display: flex; gap: 6px; margin-bottom: 18px; flex-wrap: wrap; counter-reset: step; }
.steps a, .steps span { flex: 1; min-width: 140px; padding: 10px 12px; border-radius: 10px; background: var(--surface);
  border: 1px solid var(--line); color: var(--ink-muted); font-weight: 650; font-size: 14px; }
.steps .done { color: var(--ok); border-color: var(--ok-line); background: var(--ok-soft); }
.steps .current { color: var(--accent-ink); border-color: var(--accent); background: var(--accent-soft); }
.todo { display: flex; gap: 14px; align-items: center; padding: 14px 16px; border: 1px solid var(--line);
  border-radius: 12px; background: #fff; }
.todo + .todo { margin-top: 10px; }
.todo .todo-icon { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; flex: none; }
.todo .todo-icon.warn { background: var(--warn-soft); color: var(--warn); }
.todo .todo-icon.err { background: var(--err-soft); color: var(--err); }
.todo .todo-icon.info { background: var(--accent-soft); color: var(--accent); }
.todo .t-title { font-weight: 700; }
.todo .t-sub { color: var(--ink-muted); font-size: 13.5px; }
.todo .t-action { margin-left: auto; font-weight: 700; white-space: nowrap; }
.date-chip { width: 72px; flex: none; border-radius: 12px; background: var(--accent-soft); color: var(--accent-ink);
  text-align: center; padding: 8px 4px; font-weight: 800; line-height: 1.2; }
.date-chip small { display: block; font-weight: 600; }
.timeline { list-style: none; margin: 0; padding: 0; border-left: 2px solid var(--line); }
.timeline li { position: relative; padding: 0 0 18px 20px; }
.timeline li::before { content: ""; position: absolute; left: -7px; top: 6px; width: 12px; height: 12px; border-radius: 50%;
  background: #fff; border: 2px solid var(--accent); }
.timeline .when { font-size: 13px; color: var(--ink-muted); }
.segment-bar { display: flex; height: 12px; border-radius: 999px; overflow: hidden; background: var(--surface-sunken); }
.segment-bar span { display: block; height: 100%; }
.seg-a { background: #365bd6; } .seg-w { background: #7c97f0; } .seg-r { background: #e7a52b; }
.seg-u { background: repeating-linear-gradient(45deg, #b91c1c 0 4px, #f0c9c4 4px 8px); } .seg-free { background: #cfe8dc; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--ink-muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; }
.formula { font-family: "Manrope", monospace; background: var(--surface-muted); border: 1px dashed var(--line-strong);
  border-radius: 8px; padding: 6px 10px; font-size: 13.5px; }
details.explain summary { cursor: pointer; color: var(--accent); font-weight: 650; }
.doc-preview { width: 100%; height: 720px; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 420px; }
.progress { height: 8px; background: var(--surface-sunken); border-radius: 999px; overflow: hidden; }
.progress span { display: block; height: 100%; background: var(--accent); }
.dropzone { border: 2px dashed var(--line-strong); border-radius: 16px; padding: 28px; text-align: center; background: #fff; }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.source-text { white-space: pre-wrap; font-size: 13.5px; max-height: 620px; overflow: auto; background: var(--surface-muted);
  border: 1px solid var(--line); border-radius: 10px; padding: 12px; }
mark { background: #fde68a; padding: 0 2px; border-radius: 3px; }
.htmx-indicator { opacity: 0; transition: opacity .2s; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { opacity: 1; }

@media print {
  .sidebar, .topbar, .page-actions, .no-print { display: none !important; }
  .layout { display: block; }
  .content { padding: 0; }
  .card { box-shadow: none; border: none; padding: 0; }
}

@media (max-width: 1200px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-main { grid-template-columns: 1fr; }
  .sticky { position: static; }
}
@media (max-width: 1024px) {
  :root { --sidebar: 76px; }
  .brand-text, .nav-group, .nav a span.label, .sidebar-foot span, .nav .count { display: none; }
  .nav a { justify-content: center; padding: 10px; }
  .content { padding: 22px 20px 40px; }
  .topbar { padding: 10px 20px; }
  .grid-3 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 720px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 50; left: 0; top: 0; width: 272px; transform: translateX(-100%);
    transition: transform .2s; box-shadow: var(--shadow-raised); }
  .sidebar.open { transform: none; }
  .sidebar.open .brand-text, .sidebar.open .nav-group, .sidebar.open .nav a span.label, .sidebar.open .nav .count { display: initial; }
  .sidebar.open .nav a { justify-content: flex-start; }
  .menu-toggle { display: inline-flex; }
  .topbar { flex-wrap: wrap; padding: 10px 16px; }
  .topbar form.search { order: 5; flex-basis: 100%; max-width: none; }
  .asof input[type=date] { width: 138px; }
  .content { padding: 18px 16px 36px; }
  .grid-2, .grid-3, .grid-4, .form-grid, .split { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: auto; }
  h1 { font-size: 24px; }
  .stat .value { font-size: 26px; }
  .card { padding: 18px 16px; }
  .todo { flex-wrap: wrap; }
  .todo .t-action { margin-left: 54px; }
  .hide-sm { display: none; }
  .mode-banner { padding: 10px 16px; }
}
