/* Контора — интерфейс. Палитра и шрифты общие с документами. */
:root {
  --paper: #F4F6F3;
  --sheet: #FFFFFF;
  --ink: #1B2026;
  --ink-2: #505962;
  --ink-3: #8A939B;
  --rule: #D3D9D2;
  --rule-2: #E6EAE5;
  --accent: #245C63;
  --accent-deep: #1A474D;
  --accent-soft: #E1EDED;
  --accent-tint: #5A9298;
  --mark: #FFEB9C;
  --mark-soft: #FFF6D2;
  --mark-line: #E3C453;
  --mark-ink: #3A3000;
  --danger: #A63A2B;
  --serif: "Source Serif 4", Georgia, "Times New Roman", serif;
  --sans: "IBM Plex Sans", "Helvetica Neue", Arial, sans-serif;
  --mono: "IBM Plex Mono", Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html { color-scheme: light; }
body { margin: 0; background: var(--paper); color: var(--ink); font-family: var(--sans); font-size: 15px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
a { color: var(--accent); }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.2; margin: 0; text-wrap: balance; }
h1 { font-size: 30px; }
h2 { font-size: 22px; }
.muted { color: var(--ink-2); }
.small { font-size: 13px; }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: 13.5px; }
.nowrap { white-space: nowrap; }
.inline { display: inline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; } }

/* ---------- шапка ---------- */
.top { display: flex; align-items: baseline; justify-content: space-between; gap: 24px; padding: 18px 32px 14px; border-bottom: 1px solid var(--rule); background: var(--paper); }
.wordmark { font-family: var(--serif); font-style: italic; font-weight: 600; font-size: 24px; color: var(--ink); text-decoration: none; letter-spacing: 0.005em; }
.wordmark .studio { font-style: normal; font-family: var(--sans); font-weight: 500; font-size: 13px; color: var(--ink-2); margin-left: 12px; letter-spacing: 0.06em; text-transform: uppercase; }
.wordmark.big { font-size: 36px; }
.menu { display: flex; gap: 22px; align-items: baseline; }
.menu a { font-size: 14px; font-weight: 500; text-decoration: none; color: var(--ink-2); padding-bottom: 2px; border-bottom: 2px solid transparent; }
.menu a.on { color: var(--ink); border-color: var(--accent); }
.menu a:hover { color: var(--ink); }
.link { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); cursor: pointer; font-size: 14px; }
.link.danger { color: var(--danger); }

/* ---------- страницы ---------- */
.page { max-width: 1180px; margin: 0 auto; padding: 36px 32px 80px; }
.page.narrow { max-width: 820px; }
.empty { color: var(--ink-2); padding: 28px 0; border-top: 1px dashed var(--rule); border-bottom: 1px dashed var(--rule); margin: 8px 0 0; }
.flash { margin: 0 0 18px; padding: 10px 14px; background: var(--accent-soft); color: var(--accent-deep); border-left: 3px solid var(--accent); font-size: 14px; }
.flash.error { background: #F6E4E0; color: #6E2418; border-color: var(--danger); }
.chip { display: inline-block; font-size: 12px; font-weight: 500; letter-spacing: 0.04em; text-transform: uppercase; color: var(--accent-deep); background: var(--accent-soft); padding: 2px 8px; border-radius: 2px; }

/* кнопки и поля */
.btn { display: inline-block; font: 500 14px/1 var(--sans); padding: 10px 16px; border: 1px solid var(--rule); border-radius: 3px; background: var(--sheet); color: var(--ink); text-decoration: none; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--ink-3); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-deep); }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn.danger { color: var(--danger); }
label { display: block; font-size: 13px; color: var(--ink-2); }
input[type="text"], input[type="password"], input[type="date"], input:not([type]), select, textarea {
  display: block; width: 100%; margin-top: 4px; font: 400 15px/1.35 var(--sans); color: var(--ink);
  padding: 8px 10px; border: 1px solid var(--rule); border-radius: 3px; background: var(--sheet);
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
.error { color: var(--danger); font-size: 14px; margin: 8px 0 0; }

/* ---------- вход ---------- */
.login-page { display: grid; place-items: center; min-height: 100vh; }
.login-card { width: min(380px, 92vw); background: var(--sheet); border: 1px solid var(--rule); padding: 32px 32px 28px; display: grid; gap: 14px; }
.login-card .wordmark { margin-bottom: 6px; }

/* ---------- договоры: список ---------- */
.new-contract h1 { margin-bottom: 18px; }
.templates { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 20px; }
.tpl { margin: 0; }
.tpl-card { display: grid; grid-template-columns: 116px 1fr; gap: 18px; align-items: start; width: 100%; text-align: left; padding: 18px; background: var(--sheet); border: 1px solid var(--rule); border-radius: 4px; cursor: pointer; font: inherit; color: inherit; transition: border-color .15s, transform .15s; }
.tpl-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.tpl-card:hover .thumb { box-shadow: 0 6px 18px rgba(27,32,38,.10); }
.thumb { display: block; aspect-ratio: 1 / 1.35; background: #fff; border: 1px solid var(--rule); padding: 12px 10px; box-shadow: 0 2px 8px rgba(27,32,38,.06); transition: box-shadow .15s; }
.t-title { display: block; font-family: var(--serif); font-weight: 600; font-size: 7.5px; line-height: 1.15; margin-bottom: 8px; color: var(--ink); }
.t-line { display: block; height: 3px; margin: 3px 0; background: var(--rule-2); border-radius: 1px; }
.t-line.mk { background: var(--mark); }
.w40 { width: 40%; } .w55 { width: 55%; } .w70 { width: 70%; } .w75 { width: 75%; } .w85 { width: 85%; } .w90 { width: 90%; }
.tpl-name { display: block; font-family: var(--serif); font-size: 22px; font-weight: 600; }
.tpl-who { display: block; color: var(--ink-2); margin: 2px 0 10px; font-size: 14px; }
.tpl-lines { display: grid; gap: 3px; font-size: 13px; color: var(--ink-2); }
.tpl-lines span::before { content: "·"; color: var(--accent); margin-right: 7px; }
.saved { margin-top: 44px; }
.saved h2 { margin-bottom: 12px; }
.saved h2 .count { font-family: var(--mono); font-weight: 400; font-size: 14px; color: var(--ink-3); margin-left: 6px; vertical-align: middle; }
table.list { width: 100%; border-collapse: collapse; background: var(--sheet); border: 1px solid var(--rule); }
table.list th { text-align: left; font-size: 12px; letter-spacing: 0.04em; text-transform: uppercase; color: var(--ink-2); font-weight: 500; padding: 10px 14px; border-bottom: 1px solid var(--rule); }
table.list td { padding: 12px 14px; border-bottom: 1px solid var(--rule-2); vertical-align: middle; }
table.list tr:last-child td { border-bottom: 0; }
.row-title { font-family: var(--serif); font-size: 17px; color: var(--ink); text-decoration: none; }
.row-title:hover { color: var(--accent); }
.bar { display: inline-block; width: 64px; height: 6px; background: var(--rule-2); border-radius: 3px; margin-right: 10px; vertical-align: middle; position: relative; overflow: hidden; }
.bar::after { content: ""; position: absolute; inset: 0; width: var(--p); background: var(--accent); }
.actions { text-align: right; white-space: nowrap; }
.actions .btn + form { margin-left: 6px; }

/* ---------- редактор договора ---------- */
.editor-page { background: var(--paper); }
.editor { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 28px; max-width: 1180px; margin: 0 auto; padding: 24px 32px 80px; align-items: start; }
.editor-hint { font-size: 13px; color: var(--ink-2); margin: 0 0 12px; }
.editor .sheet { background: var(--sheet); border: 1px solid var(--rule); padding: 56px 64px 64px; font-family: var(--serif); font-size: 16px; line-height: 1.55; }
.editor .sheet .cl p, .editor .sheet .preamble { max-width: none; }
.fld { display: inline; min-width: 3ch; padding: 0 4px; background: var(--mark); color: var(--mark-ink); border-bottom: 1.5px solid var(--mark-line); border-radius: 2px; font-family: var(--serif); font-size: 0.96em; line-height: 1.3; cursor: text; box-decoration-break: clone; -webkit-box-decoration-break: clone; transition: background .12s; }
.fld:empty::before { content: attr(data-hint); color: #8A7420; font-style: italic; }
.fld.filled { background: var(--mark-soft); border-bottom-color: var(--mark-line); }
.fld:focus { outline: none; background: #FFF3B8; border-bottom-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.fld.hl { background: #FFE27A; }
.fld br { display: none; }
.side { position: sticky; top: 16px; max-height: calc(100vh - 32px); overflow: auto; background: var(--sheet); border: 1px solid var(--rule); padding: 16px 18px 18px; display: grid; gap: 14px; align-content: start; }
.side-head { display: flex; justify-content: space-between; align-items: center; }
.back { font-size: 14px; text-decoration: none; }
.title-field input { font-family: var(--serif); font-size: 16px; }
.progress-bar { height: 6px; background: var(--rule-2); border-radius: 3px; position: relative; overflow: hidden; }
.progress-bar::after { content: ""; position: absolute; inset: 0; width: var(--p); background: var(--accent); transition: width .2s; }
.progress-text { font-size: 13px; color: var(--ink-2); margin-top: 6px; }
.side-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.save-status { font-size: 12px; color: var(--ink-3); font-family: var(--mono); }
.save-status.dirty { color: #8A6D00; }
.save-status.err { color: var(--danger); }
.groups { display: grid; gap: 4px; border-top: 1px solid var(--rule); padding-top: 8px; }
.group summary { cursor: pointer; font-weight: 500; font-size: 14px; padding: 8px 0; list-style: none; display: flex; align-items: center; gap: 8px; }
.group summary::before { content: ""; width: 6px; height: 6px; border-right: 1.5px solid var(--ink-2); border-bottom: 1.5px solid var(--ink-2); transform: rotate(-45deg); transition: transform .12s; }
.group[open] summary::before { transform: rotate(45deg); }
.group summary::-webkit-details-marker { display: none; }
.group-fields { display: grid; gap: 8px; padding: 2px 0 12px; }
.sf span { display: block; font-size: 12px; color: var(--ink-2); }
.sf input, .sf textarea { font-size: 14px; padding: 6px 8px; margin-top: 2px; }
.side-delete { border-top: 1px solid var(--rule); padding-top: 12px; }
@media (max-width: 900px) {
  .editor { grid-template-columns: 1fr; padding: 16px; }
  .editor .sheet { padding: 28px 20px; }
  .side { position: static; max-height: none; }
}

/* ---------- печать ---------- */
.print-page { background: var(--paper); }
.print-bar { display: flex; gap: 14px; align-items: center; justify-content: space-between; padding: 12px 24px; background: var(--sheet); border-bottom: 1px solid var(--rule); position: sticky; top: 0; z-index: 2; }
.print-note { font-size: 13px; color: var(--ink-2); }
.print-page .wrap { max-width: 820px; margin: 0 auto; padding: 32px 16px 64px; }
.print-page .sheet { background: var(--sheet); border: 1px solid var(--rule); padding: 56px 64px 64px; font-family: var(--serif); font-size: 16px; line-height: 1.55; }
.val { white-space: pre-line; }
@media print {
  .screen-only { display: none !important; }
  body { background: #fff; }
  .print-page .wrap { max-width: none; padding: 0; }
  .print-page .sheet { border: 0; padding: 0; }
}

/* ---------- расходы ---------- */
.ledger-head { display: grid; grid-template-columns: auto auto 1fr; gap: 20px 28px; align-items: center; margin-bottom: 22px; }
.period { display: flex; align-items: center; gap: 10px; }
.period h1 { font-size: 30px; min-width: 6ch; }
.nav-arrow { font-family: var(--serif); font-size: 30px; line-height: 1; text-decoration: none; color: var(--ink-2); padding: 0 6px; }
.nav-arrow:hover { color: var(--accent); }
.modes { display: flex; gap: 2px; border: 1px solid var(--rule); border-radius: 3px; overflow: hidden; background: var(--sheet); }
.modes a { padding: 7px 12px; font-size: 13px; font-weight: 500; text-decoration: none; color: var(--ink-2); }
.modes a.on { background: var(--accent); color: #fff; }
.filters { display: flex; gap: 8px; align-items: center; justify-self: end; flex-wrap: wrap; }
.filters select { width: auto; margin: 0; padding: 7px 28px 7px 10px; font-size: 13px; }
.filters .btn { padding: 7px 14px; font-size: 13px; line-height: 1.35; }
.add { background: var(--sheet); border: 1px solid var(--rule); margin-bottom: 22px; }
.add summary { cursor: pointer; padding: 12px 16px; font-weight: 500; list-style: none; display: flex; align-items: center; gap: 10px; }
.add summary::-webkit-details-marker { display: none; }
.plus { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: var(--accent); color: #fff; font-size: 16px; line-height: 1; }
.add-form { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 10px 12px; padding: 4px 16px 16px; align-items: end; border-top: 1px solid var(--rule-2); }
.add-form label { font-size: 12px; min-width: 0; }
.add-form input, .add-form select { margin-top: 3px; padding: 7px 9px; font-size: 14px; }
.add-form .grow { grid-column: span 3; }
.add-form .file { position: relative; grid-column: span 2; }
.add-form .file input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.add-form .btn { grid-column: span 1; justify-self: stretch; text-align: center; }
.file-label { display: block; margin-top: 3px; padding: 7px 10px; border: 1px dashed var(--ink-3); border-radius: 3px; font-size: 13px; color: var(--ink-2); cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file:focus-within .file-label, .file-label:hover { border-color: var(--accent); color: var(--accent-deep); }
.file.has .file-label { border-style: solid; background: var(--mark-soft); color: var(--mark-ink); }
@media (max-width: 900px) { .add-form { grid-template-columns: repeat(3, minmax(0, 1fr)); } .add-form .grow { grid-column: span 3; } .add-form .file { grid-column: span 2; } }
@media (max-width: 560px) { .add-form { grid-template-columns: repeat(2, minmax(0, 1fr)); } .add-form .grow, .add-form .file, .add-form .btn { grid-column: span 2; } }
.summary { display: grid; grid-template-columns: 1.1fr 1fr 1fr; gap: 28px; padding: 18px 0 22px; border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule); }
.stat-label { font-size: 12px; letter-spacing: 0.05em; text-transform: uppercase; color: var(--ink-2); font-weight: 500; margin-bottom: 8px; }
.stat-value { font-family: var(--mono); font-size: 34px; font-weight: 500; letter-spacing: -0.01em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat-sub { font-size: 13px; color: var(--ink-2); margin-top: 6px; }
.bd-row { display: grid; grid-template-columns: minmax(0, 1.5fr) 1fr auto; gap: 10px; align-items: center; font-size: 13.5px; padding: 3px 0; }
.bd-name { overflow-wrap: anywhere; line-height: 1.25; }
.summary .breakdown:first-of-type .bd-name { white-space: normal; }
.bd-bar { height: 8px; background: var(--rule-2); border-radius: 2px; overflow: hidden; }
.bd-bar i { display: block; height: 100%; width: var(--w); background: var(--accent); border-radius: 2px; }
.bd-val { font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: 13px; }
.chart { padding: 18px 0 6px; border-bottom: 1px solid var(--rule); position: relative; }
.chart-head { display: flex; justify-content: space-between; align-items: baseline; font-size: 13px; }
.bars { width: 100%; height: auto; display: block; }
.bars .grid { stroke: var(--rule-2); stroke-width: 1; }
.bars .ylab { fill: var(--ink-3); font: 11px var(--mono); text-anchor: end; }
.bars .xlab { fill: var(--ink-2); font: 11px var(--mono); text-anchor: middle; }
.bars .vlab { fill: var(--ink); font: 11px var(--mono); text-anchor: middle; }
.bars .bar path { fill: var(--accent-tint); transition: fill .12s; }
.bars .bar.in path { fill: var(--accent); }
.bars .bar:hover path { fill: var(--accent-deep); }
.bars .hit { fill: transparent; }
.tip { position: absolute; pointer-events: none; background: var(--ink); color: #fff; font: 12px var(--sans); padding: 6px 9px; border-radius: 3px; white-space: nowrap; transform: translate(-50%, -100%); z-index: 3; }
.tip b { font-family: var(--mono); font-weight: 500; margin-left: 6px; }
table.rows { width: 100%; border-collapse: collapse; margin-top: 8px; }
table.rows th { text-align: left; font-size: 12px; letter-spacing: 0.04em; text-transform: uppercase; color: var(--ink-2); font-weight: 500; padding: 12px 10px 8px; border-bottom: 1px solid var(--rule); }
table.rows th.num { text-align: right; }
table.rows td { padding: 10px; border-bottom: 1px solid var(--rule-2); vertical-align: middle; font-size: 14px; }
table.rows td.amount { text-align: right; font-size: 14.5px; }
table.rows tfoot td { border-bottom: 0; border-top: 1px solid var(--rule); font-weight: 500; padding-top: 12px; }
.desc { font-size: 14.5px; }
.proj { font-size: 12px; color: var(--accent-deep); }
.receipt img { width: 40px; height: 40px; object-fit: cover; border: 1px solid var(--rule); border-radius: 2px; display: block; }
.receipt .pdf { display: inline-block; font: 500 11px var(--mono); padding: 3px 6px; border: 1px solid var(--rule); border-radius: 2px; color: var(--ink-2); }
table.rows .actions .link { font-size: 18px; line-height: 1; color: var(--ink-3); }
table.rows .actions .link:hover { color: var(--danger); }
@media (max-width: 900px) {
  .ledger-head { grid-template-columns: 1fr; }
  .filters { justify-self: start; }
  .summary { grid-template-columns: 1fr; gap: 18px; }
  .page { padding: 20px 16px 60px; }
  .top { padding: 14px 16px 10px; }
}

/* ---------- настройки ---------- */
.settings { display: grid; gap: 22px; margin-top: 18px; }
.settings fieldset { border: 1px solid var(--rule); background: var(--sheet); padding: 16px 20px 20px; margin: 0; }
.settings legend { font-family: var(--serif); font-size: 18px; font-weight: 600; padding: 0 8px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.grid2 .span2 { grid-column: span 2; }
.projects { display: grid; gap: 8px; }
.form-actions { display: flex; gap: 10px; }
@media (max-width: 640px) { .grid2 { grid-template-columns: 1fr; } .grid2 .span2 { grid-column: auto; } }

/* ---------- пользователи ---------- */
.menu .who { font-size: 14px; color: var(--ink-2); }
.crumbs { font-size: 13px; color: var(--ink-2); margin: 0 0 8px; }
.crumbs a { text-decoration: none; }
.mt { margin-top: 32px; margin-bottom: 12px; }
.pw-form { display: inline-flex; gap: 6px; align-items: center; }
.pw-form input { width: 150px; margin: 0; padding: 5px 8px; font-size: 13px; }
table.users td.actions { white-space: normal; }
.add-user { display: grid; grid-template-columns: 1.4fr 1fr 1.6fr auto; gap: 12px; align-items: end; background: var(--sheet); border: 1px solid var(--rule); padding: 16px 20px 20px; }
.pw-wrap { display: flex; gap: 6px; align-items: center; margin-top: 4px; }
.pw-wrap input { margin: 0; }
@media (max-width: 720px) { .add-user { grid-template-columns: 1fr; } }

.user-rows { display: grid; gap: 12px; }
.user-row { background: var(--sheet); border: 1px solid var(--rule); padding: 14px 18px 16px; display: grid; gap: 10px; }
.user-main { display: grid; grid-template-columns: 1.6fr 1fr auto 1fr; gap: 12px; align-items: end; }
.user-main .user-meta { align-self: center; justify-self: end; }
.user-pw label { max-width: 520px; }
.user-del { justify-self: end; }
@media (max-width: 720px) { .user-main { grid-template-columns: 1fr 1fr; } .user-main .user-meta { justify-self: start; } }
