/* ==========================================================================
   ОФОРМЛЕНИЕ ВЕБ-КАБИНЕТА
   Цвета и размеры — в переменных ниже: поменяйте значение здесь, и оно
   изменится на всех страницах. Фиолетовый — цвет «печати»: им отмечено
   подписанное и главные кнопки.
   ========================================================================== */

:root {
  --ground: #E6E9EE;      /* фон вокруг рабочего листа */
  --sheet: #FFFFFF;       /* рабочий лист */
  --ink: #1B2233;         /* основной текст */
  --ink-2: #3A4254;       /* второстепенный текст */
  --muted: #5B6475;       /* подписи */
  --line: #E4E7EC;        /* линии таблиц */
  --line-2: #CFD5DE;      /* линии заголовков, рамки полей */
  --soft: #F3F4F7;        /* плашки */
  --seal: #4B3FA8;        /* цвет печати: подписано, главные кнопки */
  --seal-dark: #3C3190;
  --late: #B3261E;        /* просрочено, ошибки */
  --wait: #8A5A00;        /* ждём: отправлено, на приёмке */
  --paid: #2F6B4F;        /* оплачено */
  --radius: 8px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--ground); color: var(--ink);
  font-family: "Golos Text", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px; line-height: 1.45; font-variant-numeric: tabular-nums;
}
a { color: var(--seal); text-decoration: none; }
a:hover { color: var(--seal-dark); text-decoration: underline; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: 28px; font-weight: 600; letter-spacing: -0.01em; line-height: 1.2; }
h2 { font-size: 18px; font-weight: 600; }
h3 { font-size: 15px; font-weight: 600; }
:focus-visible { outline: 2px solid var(--seal); outline-offset: 2px; }

/* ---------- каркас: меню слева, рабочий лист справа ---------- */
.layout { display: flex; min-height: 100vh; }
.side {
  width: 248px; flex-shrink: 0; padding: 22px 16px; display: flex; flex-direction: column; gap: 22px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 0 8px; color: var(--ink); }
.brand:hover { text-decoration: none; color: var(--ink); }
.seal {
  width: 40px; height: 40px; border-radius: 50%; border: 2px solid var(--seal);
  box-shadow: inset 0 0 0 3px var(--ground), inset 0 0 0 4px var(--seal);
  display: flex; align-items: center; justify-content: center; color: var(--seal);
  font-weight: 700; font-size: 13px; transform: rotate(-8deg); flex-shrink: 0;
}
.brand b { display: block; font-size: 15px; }
.brand small { display: block; font-size: 12px; color: var(--muted); }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-title { font-size: 12px; color: var(--muted); padding: 10px 12px 4px; }
.nav a {
  display: flex; align-items: center; justify-content: space-between; min-height: 38px; padding: 0 12px;
  border-radius: var(--radius); color: var(--ink-2); font-size: 15px;
}
.nav a:hover { background: #DADEE5; color: var(--ink); text-decoration: none; }
.nav a.on { background: var(--sheet); color: var(--ink); font-weight: 600; }
.nav .n { font-size: 12px; font-weight: 600; color: #fff; background: var(--seal); border-radius: 10px; padding: 1px 8px; }
.side-foot { margin-top: auto; padding: 0 8px; font-size: 13px; color: var(--muted); display: flex; flex-direction: column; gap: 4px; }
.side-foot b { color: var(--ink); font-weight: 500; }
.linkbtn { background: none; border: 0; padding: 0; font: inherit; color: var(--seal); cursor: pointer; text-align: left; }
.linkbtn:hover { text-decoration: underline; }

.sheet {
  flex-grow: 1; min-width: 0; margin: 12px 12px 12px 0; background: var(--sheet); border-radius: 14px;
  padding: 30px 40px 48px; display: flex; flex-direction: column; gap: 26px;
}
.head { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; flex-wrap: wrap; }
.head-text { display: flex; flex-direction: column; gap: 8px; max-width: 760px; }
.lead { font-size: 16px; color: var(--ink-2); }
.page-hint { font-size: 14px; color: var(--muted); max-width: 760px; }
.crumbs { font-size: 14px; color: var(--muted); margin-bottom: -14px; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* ---------- сообщения после действий ---------- */
.flash { border-radius: 10px; padding: 14px 18px; background: #EEF6F1; border: 1px solid #CFE3D7; display: flex; flex-direction: column; gap: 6px; }
.flash.error { background: #FBEDEC; border-color: #F0CFCC; }
.flash b { font-weight: 600; }
.flash ul { margin: 0; padding-left: 20px; }
.flash .hint { color: var(--ink-2); font-size: 14px; }
.error-box { border-radius: 10px; padding: 12px 16px; background: #FBEDEC; border: 1px solid #F0CFCC; color: #7A1A14; }

/* ---------- таблицы ---------- */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th {
  font-size: 13px; font-weight: 500; color: var(--muted); text-align: left; padding: 0 12px 9px;
  border-bottom: 1px solid var(--line-2); white-space: nowrap;
}
td { font-size: 14px; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
tbody tr:hover td { background: #F7F8FA; }
tr.total td { font-weight: 600; border-bottom: none; }
.r { text-align: right; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.dim { color: var(--muted); }
.sub { display: block; font-size: 13px; color: var(--muted); margin-top: 2px; }
.doc { font-weight: 600; color: var(--ink); }
a.doc:hover { color: var(--seal); }
.empty { color: var(--muted); font-size: 14px; padding: 6px 0; }

/* ---------- статусы: «печать» для подписанного, точка для остальных ---------- */
.stamp {
  display: inline-block; padding: 1px 9px; border: 1.5px solid var(--seal); border-radius: 5px; color: var(--seal);
  font-weight: 600; font-size: 13px; transform: rotate(-2.5deg); background: #fff; white-space: nowrap;
  box-shadow: inset 0 0 0 2px #fff, inset 0 0 0 3px rgba(75, 63, 168, .4);
}
.st { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; white-space: nowrap; }
.st::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.s-prep { color: var(--muted); } .s-sent { color: var(--wait); } .s-rej { color: var(--late); }
.late { color: var(--late); font-weight: 600; } .paid { color: var(--paid); } .sent { color: var(--wait); }

/* ---------- кнопки и поля ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px; padding: 0 16px;
  border-radius: var(--radius); border: 1px solid #C3CAD4; background: #fff; font: inherit; font-size: 14px;
  font-weight: 500; color: var(--ink); cursor: pointer; white-space: nowrap;
}
.btn:hover { background: #F1F3F6; text-decoration: none; color: var(--ink); }
.btn.p { background: var(--seal); border-color: var(--seal); color: #fff; }
.btn.p:hover { background: var(--seal-dark); color: #fff; }
.btn.s { min-height: 32px; padding: 0 12px; font-size: 13px; }
.btn.danger { color: var(--late); }
.btn[disabled] { opacity: .6; cursor: progress; }
.file { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 6px; border: 1px solid #C3CAD4; border-radius: 4px; color: var(--ink-2); margin: 0 4px 4px 0; }
.file:hover { border-color: var(--seal); color: var(--seal); text-decoration: none; }

.form { display: flex; flex-direction: column; gap: 16px; max-width: 720px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 20px; }
.form-grid .wide { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label, .label { font-size: 13px; font-weight: 500; color: var(--ink-2); }
.field .help { font-size: 12px; color: var(--muted); }
.req::after { content: " *"; color: var(--late); }
input, select, textarea {
  font: inherit; font-size: 14px; min-height: 40px; padding: 8px 12px; border: 1px solid #C3CAD4;
  border-radius: var(--radius); background: #fff; color: var(--ink); width: 100%;
}
textarea { min-height: 96px; resize: vertical; line-height: 1.45; }
input[type=checkbox] { width: 18px; min-height: 18px; height: 18px; accent-color: var(--seal); }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.filters input, .filters select { width: auto; }
.filters input[type=search] { min-width: 260px; }

.seg { display: inline-flex; flex-wrap: wrap; background: #EEF0F3; border-radius: 9px; padding: 3px; gap: 2px; }
.seg a { display: inline-flex; align-items: center; gap: 6px; min-height: 34px; padding: 0 14px; border-radius: 7px; font-size: 14px; color: var(--ink-2); }
.seg a:hover { text-decoration: none; color: var(--ink); background: #E2E5EA; }
.seg a.on { background: #fff; color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(27, 34, 51, .12); }
.seg small { font-size: 12px; color: var(--muted); font-weight: 500; }

/* ---------- блоки страниц ---------- */
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 36px; }
.section { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.section-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.section-head a { font-size: 14px; }
.panel { border: 1px solid #E0E4EA; border-radius: 10px; }
.panel-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 13px 16px; border-bottom: 1px solid var(--line); }
.panel-row:last-child { border-bottom: none; }
.note { padding: 14px 18px; background: var(--soft); border-radius: 10px; font-size: 15px; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 8px 20px; font-size: 14px; }
.facts dt { color: var(--muted); } .facts dd { margin: 0; }
.tree { display: flex; flex-direction: column; gap: 12px; padding-left: 18px; border-left: 2px solid #E0E4EA; }
.card-row { display: flex; gap: 36px; align-items: flex-start; }
.card-row > .main { flex-grow: 1; min-width: 0; display: flex; flex-direction: column; gap: 22px; }
.card-row > aside { width: 320px; flex-shrink: 0; display: flex; flex-direction: column; gap: 22px; }
.code-chip { font-size: 13px; font-weight: 600; color: var(--seal); border: 1.5px solid var(--seal); border-radius: 5px; padding: 1px 7px; }

/* полоса «из чего складываются деньги» на странице задолженности */
.bar { display: flex; height: 26px; border-radius: 6px; overflow: hidden; gap: 3px; background: var(--soft); }
.bar div { min-width: 4px; }
.bar .b-late { background: var(--late); }
.bar .b-debt { background: var(--ink-2); }
.bar .b-pending { background: repeating-linear-gradient(135deg, var(--seal) 0 6px, #7C72C9 6px 12px); }
.bar .b-exp { background: #fff; border: 1.5px dashed var(--muted); }
.legend { display: flex; gap: 24px; flex-wrap: wrap; font-size: 14px; }
.legend span { display: inline-flex; align-items: center; gap: 8px; }
.legend i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }

/* черновик — как лист бумаги */
.paper { border: 1px solid #D5DAE1; border-radius: 10px; padding: 26px 30px; box-shadow: 0 8px 24px -12px rgba(27, 34, 51, .18); max-width: 860px; }
.paper pre { margin: 0; white-space: pre-wrap; font: inherit; font-size: 14px; line-height: 1.6; }
.draft-badge { font-size: 13px; font-weight: 600; color: var(--wait); background: #FBF1DC; border-radius: 6px; padding: 3px 9px; }

/* чат с ИИ */
.chat { display: flex; flex-direction: column; gap: 14px; max-width: 860px; }
.msg { padding: 12px 16px; border-radius: 12px; white-space: pre-wrap; font-size: 15px; max-width: 88%; }
.msg.user { align-self: flex-end; background: #ECEAF8; }
.msg.assistant { align-self: flex-start; background: var(--soft); }
.msg.note { align-self: center; background: none; color: var(--muted); font-size: 13px; padding: 2px 8px; }
.chat-form { display: flex; flex-direction: column; gap: 10px; max-width: 860px; position: sticky; bottom: 0; background: var(--sheet); padding: 12px 0 4px; }
.thinking { display: none; color: var(--muted); font-size: 14px; }
form.busy .thinking { display: inline; }

/* ---------- узкие экраны: меню сверху, всё в одну колонку ---------- */
@media (max-width: 980px) {
  .layout { flex-direction: column; }
  .side { width: auto; height: auto; position: static; padding: 14px 16px; gap: 12px; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .nav-title { display: none; }
  .side-foot { flex-direction: row; gap: 14px; margin-top: 0; }
  .sheet { margin: 0; border-radius: 0; padding: 22px 16px 40px; }
  .grid2, .form-grid { grid-template-columns: minmax(0, 1fr); }
  .card-row { flex-direction: column; }
  .card-row > aside { width: auto; }
  .filters input[type=search] { min-width: 0; width: 100%; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
