/* Reson Документы — стили на семантических токенах портфеля (tokens.css). */
:root { color-scheme: light dark; --tabbar-h: 64px; --ease: cubic-bezier(.2,.8,.2,1); }
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--surface-canvas); color: var(--text-primary);
  font: 400 15px/1.5 var(--font-sans); font-variant-numeric: tabular-nums; }
a { color: var(--accent-primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: var(--text-xl); line-height: 1.25; margin: 0; text-wrap: balance; }
h2 { font-size: 16px; margin: 0 0 var(--space-3); }
p { margin: 0 0 var(--space-2); }
.muted { color: var(--text-secondary); }
.small { font-size: 13px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.num { font-family: var(--font-mono); font-size: 13px; }
:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; border-radius: 4px; }

/* шапка */
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: var(--space-6);
  padding: 10px max(16px, env(safe-area-inset-left)); background: color-mix(in srgb, var(--surface-card) 92%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--border-default); }
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 650; color: var(--text-primary); }
.brand:hover { text-decoration: none; }
.brand-mark { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 8px;
  background: var(--accent-primary); color: #fff; font-size: 15px; }
.brand-lg { font-size: 20px; margin-bottom: var(--space-2); }
.topnav { display: flex; gap: 4px; flex: 1; }
.topnav a { padding: 8px 12px; border-radius: var(--radius-control); color: var(--text-secondary); font-weight: 500; }
.topnav a:hover { background: var(--surface-muted); text-decoration: none; }
.topnav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent-primary); }
.logout { margin: 0; }

.page { max-width: 1120px; margin: 0 auto; padding: var(--space-6) 16px 48px; display: grid; gap: var(--space-4); }
.page-head { display: flex; flex-wrap: wrap; gap: var(--space-3); justify-content: space-between; align-items: flex-end; }
.page-head > div:first-child { min-width: 0; }
.eyebrow { font-size: 13px; color: var(--text-secondary); margin: 0 0 4px; }
.actions { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.lead { font-size: 16px; font-weight: 600; }

/* карточки и сетки */
.card { background: var(--surface-card); border: 1px solid var(--border-default); border-radius: var(--radius-card);
  padding: var(--space-4); box-shadow: var(--shadow); min-width: 0; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: var(--space-2); }
.grid-2, .grid-3 { display: grid; gap: var(--space-4); }
@media (min-width: 768px) { .grid-2 { grid-template-columns: 1fr 1fr; } .grid-3 { grid-template-columns: repeat(3, 1fr); } }
.kpi { display: grid; gap: 4px; align-content: start; }
.kpi-link { color: inherit; transition: border-color .12s var(--ease); }
.kpi-link:hover { text-decoration: none; border-color: var(--border-strong); }
.kpi-label { color: var(--text-secondary); font-size: 13px; }
.kpi-value { font-size: 28px; font-weight: 650; letter-spacing: -.01em; }
.kpi-sub { color: var(--text-secondary); font-size: 13px; }
.kpi-warning { border-color: var(--status-warning); }
.kpi-critical { border-color: var(--status-danger); }
meter { width: 100%; height: 8px; }
.empty { text-align: left; }
.empty-line { color: var(--text-secondary); margin: 0; padding: var(--space-2) 0; }
.steps { margin: 0; padding-left: 20px; display: grid; gap: 6px; }

/* списки-строки (вместо широких таблиц на телефоне) */
.rows { list-style: none; margin: 0 calc(-1 * var(--space-2)); padding: 0; }
.row { display: flex; align-items: center; gap: var(--space-3); padding: 10px var(--space-2); border-radius: var(--radius-control);
  color: inherit; min-height: 44px; }
a.row:hover, label.row:hover { background: var(--surface-muted); text-decoration: none; }
.rows li + li .row { border-top: 1px solid var(--border-default); border-radius: 0; }
.row-main { display: grid; min-width: 0; flex: 1; }
.row-title { font-weight: 550; color: var(--text-primary); overflow-wrap: anywhere; }
.row-sub { color: var(--text-secondary); font-size: 13px; }
.row-amount { font-weight: 600; white-space: nowrap; }
.row-end { display: grid; justify-items: end; gap: 4px; }
.row-nested { padding-left: var(--space-6); }
.row-check { cursor: pointer; }
.row-check input { width: 20px; height: 20px; flex: none; }
.chev { color: var(--text-disabled); font-size: 20px; }
.warn-text { color: var(--status-warning); font-weight: 600; }
.total-line { text-align: right; margin: var(--space-3) 0 0; }

.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap;
  border: 1px solid currentColor; }
.pill-success { color: var(--status-success); }
.pill-warning { color: var(--status-warning); }
.pill-danger { color: var(--status-danger); }
.pill-info { color: var(--status-info); }
.pill-muted { color: var(--text-secondary); }

.facts dl { margin: 0; display: grid; gap: var(--space-2); }
@media (min-width: 768px) { .facts dl { grid-template-columns: 1fr 1fr; } }
.facts dt { color: var(--text-secondary); font-size: 13px; }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.note { white-space: pre-wrap; background: var(--surface-muted); padding: var(--space-3); border-radius: var(--radius-control); margin-top: var(--space-3); }

/* уведомления */
.flashes { display: grid; gap: var(--space-2); }
.flash, .notice { margin: 0; padding: 12px var(--space-4); border-radius: var(--radius-control); border: 1px solid var(--border-default);
  background: var(--surface-card); border-left-width: 4px; }
.flash-success { border-left-color: var(--status-success); }
.flash-danger, .notice-danger { border-left-color: var(--status-danger); }
.notice-warning { border-left-color: var(--status-warning); display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; }
.notice-info { border-left-color: var(--status-info); }

/* кнопки */
.btn, .btn-ghost { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 0 16px;
  border-radius: var(--radius-control); border: 1px solid var(--border-strong); background: var(--surface-card); color: var(--text-primary);
  font: 600 14px/1 var(--font-sans); cursor: pointer; transition: background .12s var(--ease), border-color .12s var(--ease); }
.btn:hover, .btn-ghost:hover { background: var(--surface-muted); text-decoration: none; }
.btn-ghost { border-color: transparent; background: transparent; color: var(--accent-primary); }
.btn-primary { background: var(--accent-primary); border-color: var(--accent-primary); color: #fff; }
.btn-primary:hover { background: color-mix(in srgb, var(--accent-primary) 88%, #000); }
.btn-danger { background: var(--status-danger); border-color: var(--status-danger); color: #fff; }
.btn-small { min-height: 36px; padding: 0 12px; font-size: 13px; }
.btn-block { width: 100%; }
.btn-current { background: var(--accent-soft); border-color: var(--accent-primary); color: var(--accent-primary); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn { width: 36px; height: 36px; border: 0; background: transparent; color: var(--text-secondary); font-size: 22px; border-radius: 8px; cursor: pointer; }
.icon-btn:hover { background: var(--surface-muted); color: var(--status-danger); }
.file-buttons, .status-buttons { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-bottom: var(--space-2); }

/* формы */
.form { display: grid; gap: var(--space-4); }
.form h2 { margin: var(--space-2) 0 0; }
.form-grid { display: grid; gap: var(--space-3) var(--space-4); }
@media (min-width: 768px) { .form-grid { grid-template-columns: repeat(3, 1fr); } .field-wide { grid-column: 1 / -1; } }
.field { display: grid; gap: 4px; margin: 0; min-width: 0; }
.field-label { font-size: 13px; font-weight: 600; color: var(--text-secondary); }
.field-hint { font-size: 12px; color: var(--text-secondary); }
.req { color: var(--status-danger); }
input, select, textarea { width: 100%; min-height: 44px; padding: 10px 12px; border: 1px solid var(--border-strong); border-radius: var(--radius-control);
  background: var(--surface-card); color: var(--text-primary); font: 400 15px/1.3 var(--font-sans); }
textarea { min-height: 88px; resize: vertical; }
input[type="checkbox"], input[type="radio"] { width: auto; min-height: 0; accent-color: var(--accent-primary); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--focus-ring); outline-offset: 0; border-color: var(--focus-ring); }
.form-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.inline-form { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: flex-end; }
.stack { display: grid; gap: var(--space-3); }
.check { display: flex; gap: 8px; align-items: flex-start; }
.search { display: flex; gap: var(--space-2); }
.segmented { display: flex; flex-wrap: wrap; gap: 6px; border: 0; padding: 0; margin: 0; }
.segmented legend { font-size: 13px; font-weight: 600; color: var(--text-secondary); margin-bottom: 6px; padding: 0; }
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; }
.segmented span { display: inline-flex; align-items: center; min-height: 40px; padding: 0 14px; border: 1px solid var(--border-strong);
  border-radius: 999px; font-weight: 600; font-size: 14px; cursor: pointer; }
.segmented input:checked + span { background: var(--accent-soft); border-color: var(--accent-primary); color: var(--accent-primary); }
.segmented input:focus-visible + span { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
details.more summary, details.danger-zone summary { cursor: pointer; font-weight: 600; color: var(--text-secondary); min-height: 32px; }
details.danger-zone { padding: var(--space-3) var(--space-4); border: 1px dashed var(--border-strong); border-radius: var(--radius-card); }
details.danger-zone form { display: grid; gap: var(--space-3); margin-top: var(--space-3); }
[data-client-form] .only-org, [data-client-form] .only-ip { display: contents; }
[data-kind="ip"] .only-org:not(.only-ip), [data-kind="person"] .only-org, [data-kind="person"] .only-ip { display: none; }
.chips { display: flex; gap: 6px; overflow-x: auto; }
.chips a { padding: 8px 14px; border-radius: 999px; border: 1px solid var(--border-default); color: var(--text-secondary); white-space: nowrap; font-weight: 600; font-size: 14px; }
.chips a[aria-current="page"] { background: var(--accent-soft); color: var(--accent-primary); border-color: var(--accent-primary); }

/* строки услуг */
.lines { border: 1px solid var(--border-default); border-radius: var(--radius-card); padding: var(--space-3); margin: 0; display: grid; gap: var(--space-2); }
.lines legend { font-weight: 650; padding: 0 6px; }
.lines-head { display: none; }
.line { display: grid; gap: 8px; grid-template-columns: .8fr 1.1fr 1.2fr; padding: var(--space-3) 0; border-top: 1px solid var(--border-default); position: relative; }
.line:first-child { border-top: 0; }
.line-name { grid-column: 1 / -1; padding-right: 40px; }
.line label { display: grid; gap: 2px; }
.m-label { font-size: 12px; color: var(--text-secondary); }
.line-sum { grid-column: 1 / -1; text-align: right; font-weight: 600; }
.line .icon-btn { position: absolute; top: 12px; right: 0; }
.lines-foot { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: var(--space-2); }
.lines-total { margin: 0; font-size: 16px; }
@media (min-width: 768px) {
  .lines-head { display: grid; grid-template-columns: minmax(0, 1fr) 90px 110px 130px 120px 36px; gap: 8px; font-size: 12px; color: var(--text-secondary); font-weight: 600; }
  .line { grid-template-columns: minmax(0, 1fr) 90px 110px 130px 120px 36px; align-items: center; padding: 4px 0; border: 0; }
  .line-name { grid-column: auto; padding-right: 0; }
  .line-sum { grid-column: auto; }
  .m-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .line .icon-btn { position: static; }
}

/* вход */
.page-login { min-height: 100vh; place-content: center; }
.login-card { width: min(380px, 100%); margin: 0 auto; background: var(--surface-card); border: 1px solid var(--border-default);
  border-radius: var(--radius-panel); padding: var(--space-6); box-shadow: var(--shadow-lg); display: grid; gap: var(--space-3); }

/* нижняя панель на телефоне */
.tabbar { display: none; }
@media (max-width: 767px) {
  .topnav, .logout { display: none; }
  .topbar { justify-content: center; }
  .page { padding-bottom: calc(var(--tabbar-h) + 32px + env(safe-area-inset-bottom)); }
  .tabbar { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); background: var(--surface-card); border-top: 1px solid var(--border-default); }
  .tabbar a { display: grid; justify-items: center; gap: 2px; font-size: 11px; font-weight: 600; color: var(--text-secondary); min-height: 48px; padding-top: 4px; }
  .tabbar a:hover { text-decoration: none; }
  .tabbar a[aria-current="page"] { color: var(--accent-primary); }
  .tab-primary .ti { background: var(--accent-primary); color: #fff; border-radius: 10px; }
  .page-head .actions { width: 100%; }
  .page-head .actions .btn { flex: 1; }
  .kpi-value { font-size: 24px; }
}
.ti { display: inline-grid; place-items: center; width: 28px; height: 24px; font-size: 18px; line-height: 1; }
.ti-home::before { content: "⌂"; } .ti-people::before { content: "☺"; } .ti-plus::before { content: "+"; font-weight: 700; }
.ti-doc::before { content: "≡"; } .ti-check::before { content: "✓"; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* поиск контрагента */
.combo { position: relative; display: grid; gap: 6px; }
.combo-box { position: relative; }
.combo-box input { padding-left: 38px; padding-right: 40px; font-size: 16px; min-height: 48px; }
.combo-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-secondary); font-size: 18px; }
.combo-spinner { position: absolute; right: 14px; top: 50%; width: 16px; height: 16px; margin-top: -8px; border-radius: 50%;
  border: 2px solid var(--border-strong); border-top-color: var(--accent-primary); animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.combo-list { position: absolute; z-index: 30; left: 0; right: 0; top: calc(100% - 22px); max-height: min(60vh, 460px); overflow-y: auto;
  background: var(--surface-card); border: 1px solid var(--border-strong); border-radius: var(--radius-card); box-shadow: var(--shadow-lg); padding: 6px; }
.combo-group { font-size: 12px; font-weight: 700; color: var(--text-secondary); text-transform: uppercase; letter-spacing: .04em; padding: 8px 10px 4px; }
.combo-option { display: flex; gap: 10px; align-items: center; justify-content: space-between; padding: 10px; border-radius: var(--radius-control); cursor: pointer; min-height: 44px; }
.combo-option.active, .combo-option:hover { background: var(--accent-soft); }
.combo-option.inactive .co-main b { color: var(--text-secondary); text-decoration: line-through; }
.co-main { display: grid; gap: 2px; min-width: 0; }
.co-main b { font-weight: 600; overflow-wrap: anywhere; }
.co-sub { font-size: 13px; color: var(--text-secondary); overflow-wrap: anywhere; }
.co-tag { flex: none; font-size: 12px; font-weight: 600; color: var(--text-secondary); border: 1px solid var(--border-default); border-radius: 999px; padding: 2px 8px; }
.co-new { color: var(--accent-primary); border-color: var(--accent-primary); }
.co-bad { color: var(--status-danger); border-color: var(--status-danger); }
.co-action b { color: var(--accent-primary); }
.quick-picks { display: grid; gap: 6px; margin-top: var(--space-3); }
.inn-field { display: grid; gap: 6px; align-content: start; }
.inn-field .btn { justify-self: start; }
input.filled { background: color-mix(in srgb, var(--status-success) 7%, var(--surface-card)); border-color: color-mix(in srgb, var(--status-success) 45%, var(--border-strong)); }
@media (max-width: 767px) { .combo-list { position: static; max-height: none; margin-top: 4px; } }
