:root {
  --background: #f5f4ee;
  --foreground: #16221f;
  --card: #fbfaf6;
  --primary: #152825;
  --muted: #5b6663;
  --border: #d9dbd5;
  --mint: #167962;
  --mint-soft: #dcebe5;
  --clay: #d85e34;
  --clay-soft: #fce7df;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--background); color: var(--foreground); font: 15px/1.5 Inter, "Segoe UI", sans-serif; }
a { color: var(--mint); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; }
button, .button { display: inline-flex; align-items: center; justify-content: center; padding: 9px 15px; background: var(--card); border: 1px solid var(--border); border-radius: 8px; color: var(--primary); cursor: pointer; white-space: nowrap; }
button:hover, .button:hover { border-color: var(--mint); text-decoration: none; }
button.primary { background: var(--clay); color: #fff8f3; border-color: var(--clay); }
button.primary:hover { background: #a8411f; }
button:disabled { opacity: .65; cursor: wait; }
button[aria-pressed="true"] { background: var(--mint-soft); border-color: var(--mint); }
input, select, textarea { min-width: 0; padding: 8px 11px; border: 1px solid var(--border); border-radius: 7px; background: var(--card); color: var(--foreground); }
:focus-visible { outline: 2px solid var(--mint); outline-offset: 3px; }
label { display: flex; align-items: center; gap: 9px; }
h1, h2, h3 { line-height: 1.2; letter-spacing: -.025em; }
h1 { margin: 0 0 24px; font-size: 32px; font-weight: 650; }
h2 { margin: 0 0 15px; font-size: 21px; font-weight: 600; }
h3 { margin: 22px 0 8px; font-size: 16px; }
p { margin: 10px 0; }
small { display: block; font-size: 12px; color: var(--muted); }
.muted { color: var(--muted); }
.sidebar { position: fixed; inset: 0 auto 0 0; width: 245px; padding: 26px 18px; background: var(--card); border-right: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 19px; margin: 0 9px 36px; color: var(--primary); }
.brand:hover { text-decoration: none; }
.brand img { display: block; object-fit: contain; }
.brand span { font-size: 21px; font-weight: 650; }
nav { display: grid; gap: 6px; }
nav a { padding: 11px 13px; color: var(--primary); border-radius: 8px; }
nav a:hover { background: #e6ece8; text-decoration: none; }
nav a.active { background: var(--primary); color: #f8f6ef; }
.source-link { display: block; margin: 28px 13px; color: var(--muted); font-size: 13px; }
.workspace { margin-left: 245px; min-width: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 66px; padding: 16px 32px; border-bottom: 1px solid var(--border); font-size: 13px; }
.topbar > span { font-weight: 600; }
.status { color: var(--muted); }
main { padding: 30px 32px 50px; max-width: 1800px; margin: auto; }
.grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 18px; margin-bottom: 20px; }
.metrics { grid-template-columns: repeat(4,minmax(0,1fr)); }
.panel { min-width: 0; margin-bottom: 20px; padding: 22px; border: 1px solid var(--border); border-radius: 13px; background: var(--card); }
.grid .panel { margin-bottom: 0; }
.module-card { color: var(--foreground); min-height: 180px; }
.module-card:hover { text-decoration: none; border-color: var(--mint); }
.module-card h2 { margin-top: 22px; }
.module-card p { color: var(--muted); }
.badge { display: inline-block; padding: 3px 9px; border-radius: 6px; background: #e9e9e3; color: var(--muted); font-size: 12px; }
.badge.ready { background: var(--mint-soft); color: var(--mint); }
.metrics strong { display: block; margin: 12px 0 8px; font-size: clamp(19px,1.8vw,27px); font-weight: 650; white-space: nowrap; }
.page-heading, .section-heading, .version { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 14px; margin-bottom: 18px; }
.page-heading h1, .section-heading h2 { margin: 0; }
.date-range, .filters, .diagram-controls, .version form { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; }
.date-range { padding: 17px 22px; }
.date-range .muted { font-size: 12px; }
.version { font-size: 12px; }
.source-dates { margin-bottom: 20px; color: var(--muted); font-size: 12px; }
.version select { max-width: 250px; }
.notice { padding: 15px 18px; margin-bottom: 20px; border: 1px solid var(--border); border-radius: 9px; background: #e6ece8; }
.notice.warning { background: var(--clay-soft); border-color: #ebc3b2; }
.notice.error { background: #fce7df; border-color: #b9382f; }
.notice.success { background: var(--mint-soft); border-color: #90b8aa; }
summary { cursor: pointer; font-weight: 600; }
.notice ul { margin-bottom: 0; padding-left: 22px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; text-align: left; font-size: 13px; }
th { color: var(--muted); font-weight: 500; }
th, td { padding: 13px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
td small { margin-top: 5px; }
.number { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.filters { margin: 18px 0; }
.filters input[name="q"] { flex: 1; min-width: 220px; }
.pagination { display: flex; gap: 20px; align-items: center; margin-top: 16px; color: var(--muted); font-size: 12px; }
.operation-value { font-size: 32px; font-weight: 650; }
.decision { display: grid; gap: 17px; max-width: 650px; }
.decision label { display: grid; gap: 6px; }
.decision button { justify-self: start; }
.sankey-scroll { width: 100%; overflow-x: auto; }
.sankey-scroll svg { display: block; }
.sankey-label { font-size: 14px; fill: var(--foreground); font-weight: 500; }
.sankey-amount { font-size: 12px; fill: var(--muted); }
.sankey-node.clickable { cursor: pointer; }
.sankey-node:focus { outline: none; }
.sankey-node:focus rect, .sankey-node[aria-pressed="true"] rect { stroke: var(--clay); stroke-width: 3; }
.sankey-ribbon:hover { fill-opacity: .75; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); border: 0; }
@media (max-width: 1200px) { .metrics { grid-template-columns: repeat(2,minmax(0,1fr)); } }
@media (max-width: 760px) {
  .sidebar { position: static; width: auto; padding: 16px; border-right: 0; border-bottom: 1px solid var(--border); }
  .brand { margin: 0 0 16px; }
  .brand img { width: 55px; height: 48px; }
  nav { display: flex; gap: 6px; overflow-x: auto; }
  nav a { white-space: nowrap; font-size: 13px; }
  .source-link { margin: 15px 0 0; }
  .workspace { margin-left: 0; }
  .topbar { padding: 13px 18px; }
  main { padding: 24px 16px; }
  h1 { font-size: 27px; }
  .panel { padding: 17px; }
  .modules { grid-template-columns: 1fr; }
  .date-range label { flex: 1; }
  .date-range input { width: 100%; }
  .metrics strong { font-size: 19px; white-space: normal; overflow-wrap: anywhere; }
  .diagram-controls { gap: 6px; }
  .diagram-controls button { padding: 8px; font-size: 12px; }
}

.operation-tabs { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
.operation-tabs .active { background: var(--mint-soft); border-color: var(--mint); }
.operation-tabs .active.review { background: var(--clay-soft); border-color: var(--clay); }
.review-reason { color: #934a30; }
.date-range select { max-width: min(420px, 100%); }
.date-range label { flex-wrap: wrap; }
@media (max-width: 760px) {
  .date-range label, .date-range input[name="q"] { width: 100%; flex-basis: 100%; }
  .date-range select { width: 100%; }
}

/* Экран входа использует ту же палитру и логотип, без навигации к закрытым данным. */
.workspace.auth-workspace { margin-left: 0; }
.auth-workspace main { min-height: 100vh; display: grid; place-items: center; }
.login-panel { width: 100%; max-width: 440px; }
.login-panel h1 { font-size: 27px; }
.user-session { display: flex; align-items: center; gap: 14px; }
.user-session form { margin: 0; }
/* Сохраняем переносы исходных сообщений при просмотре отчётных свидетельств. */
.message-text { white-space: pre-wrap; min-width: 15rem; }

.direction-picker { display: flex; flex-wrap: wrap; gap: 12px; }
.direction-picker [hidden] { display: none; }
.decision .direction-picker { display: grid; }

/* Дашборд выводит проблемы, а расшифровки открываются отдельным выбором. */
.control-dashboard { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; margin: 20px 0; }
.control-card { margin: 0; display: flex; flex-direction: column; gap: 9px; color: var(--foreground); text-decoration: none; }
.control-card h2 { margin: 0 0 8px; }
.control-card strong, .control-total { display: block; font-size: 26px; font-weight: 700; }
.control-card small { display: block; line-height: 1.5; }
.control-card > a { color: inherit; text-decoration: none; }
.control-card:hover { border-color: var(--mint); }
.source-gap { display: block; text-decoration: none; }
.aging-chart { display: grid; gap: 12px; margin: 12px 0; }
.aging-row { display: grid; grid-template-columns: 100px minmax(12px, 1fr) 85px; gap: 8px; align-items: center; font-size: 12px; }
.aging-track { height: 9px; border-radius: 4px; background: #e9efed; overflow: hidden; }
.aging-track > div { height: 100%; border-radius: 4px; background: var(--mint); }
@media (max-width: 1200px) { .control-dashboard { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 760px) { .control-dashboard { grid-template-columns: 1fr; } }
