/* ============================================================================
   Платформа обращений — стили интерфейса на токенах дизайн-системы.
   Компоненты перенесены из bundle.css дизайн-системы (Button, Badge, Tabs,
   Select, Search, Avatar, StatCard, ListRow, Panel) и дополнены формами,
   таблицами, таймлайном и раскладкой страниц.
   ============================================================================ */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 20px;
  color: var(--ink-900);
  background: var(--surface-canvas);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
a { color: var(--brand-600); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
img { max-width: 100%; display: block; }
h1, h2, h3, h4, p { margin: 0; }
ul { margin: 0; padding: 0; list-style: none; }
:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------------------------------------------------------------- Typography */
.t-display-xl { font-size: 34px; line-height: 40px; font-weight: 700; letter-spacing: -0.02em; }
.t-display-md { font-size: 26px; line-height: 32px; font-weight: 700; letter-spacing: -0.01em; }
.t-heading-lg { font-size: 18px; line-height: 24px; font-weight: 700; }
.t-heading-md { font-size: 15px; line-height: 20px; font-weight: 600; }
.t-body-md { font-size: 14px; line-height: 20px; font-weight: 400; }
.t-body-sm { font-size: 13px; line-height: 18px; font-weight: 400; }
.t-label-sm { font-size: 12px; line-height: 16px; font-weight: 600; }
.t-label-xs { font-size: 11px; line-height: 14px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; }
.t-amount-xl { font-family: var(--font-numeric); font-variant-numeric: tabular-nums; font-size: 28px; line-height: 34px; font-weight: 700; letter-spacing: -0.01em; }
.t-amount-lg { font-family: var(--font-numeric); font-variant-numeric: tabular-nums; font-size: 20px; line-height: 26px; font-weight: 700; }
.t-amount-md { font-family: var(--font-numeric); font-variant-numeric: tabular-nums; font-size: 15px; line-height: 20px; font-weight: 700; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-400); }
.ink-600 { color: var(--ink-600); }
.danger-text { color: var(--danger-600); }
.success-text { color: var(--success-600); }
.nowrap { white-space: nowrap; }

/* ---------------------------------------------------------------- Layout */
.shell { max-width: 1280px; margin: 0 auto; padding: 0 var(--space-8) var(--space-10); }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--space-4); margin: var(--space-8) 0 var(--space-6); flex-wrap: wrap; }
.page-head__sub { margin-top: var(--space-1); color: var(--ink-600); }
.page-head__actions { display: flex; gap: var(--space-2); align-items: center; flex-wrap: wrap; }
.section { margin-top: var(--space-6); }
.section + .section { margin-top: var(--space-6); }
.stack { display: flex; flex-direction: column; gap: var(--space-4); }
.stack--sm { gap: var(--space-2); }
.cluster { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; }
.cluster--between { justify-content: space-between; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-4); }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--space-4); }
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--space-4); }
.detail { display: grid; grid-template-columns: minmax(0, 7fr) minmax(320px, 4fr); gap: var(--space-4); align-items: start; }
.sticky { position: sticky; top: var(--space-4); }
.divider { height: 1px; background: var(--border-subtle); margin: var(--space-4) 0; }

/* ---------------------------------------------------------------- Topbar */
.topbar {
  display: flex; align-items: center; gap: var(--space-4);
  margin-top: var(--space-4);
  padding: 8px 8px 8px 20px;
  background: var(--surface-inverse); color: var(--ink-on-inverse);
  border-radius: var(--radius-full);
}
.topbar__brand { display: flex; flex-direction: column; line-height: 1.1; min-width: 0; margin-right: var(--space-2); }
.topbar__brand-name { font-weight: 800; font-size: 14px; letter-spacing: -0.01em; white-space: nowrap; }
.topbar__brand-sub { font-size: 11px; color: var(--ink-on-inverse-muted); white-space: nowrap; }
.topbar__nav { display: flex; gap: 4px; flex: 1 1 0; min-width: 0; overflow-x: auto; scrollbar-width: none; padding: 2px; }
.topbar__nav::-webkit-scrollbar { display: none; }
.topbar__right { display: flex; align-items: center; gap: var(--space-2); margin-left: auto; flex: none; }
.topbar__user { display: flex; align-items: center; gap: var(--space-2); padding: 4px 6px 4px 4px; border-radius: var(--radius-full); color: var(--ink-on-inverse); }
.topbar__user:hover { background: rgba(255,255,255,.08); text-decoration: none; }
.topbar__user-name { font-size: 13px; font-weight: 600; white-space: nowrap; }
.topbar__user-role { font-size: 11px; color: var(--ink-on-inverse-muted); white-space: nowrap; }
.navpill {
  display: inline-flex; align-items: center; gap: var(--space-2);
  padding: 8px 16px; border-radius: var(--radius-full);
  font-size: 13px; line-height: 18px; font-weight: 600; white-space: nowrap;
  color: var(--ink-on-inverse-muted); background: transparent;
}
.navpill:hover { color: var(--ink-on-inverse); text-decoration: none; }
.navpill.is-active { background: var(--brand-500); color: var(--ink-on-inverse); }
.navpill__count { min-width: 18px; height: 18px; padding: 0 5px; border-radius: var(--radius-full); background: rgba(255,255,255,.22); display: inline-flex; align-items: center; justify-content: center; font-size: 11px; }
.bell { position: relative; }
.bell--new { animation: bell-shake 0.6s ease 0s 3; }
@keyframes bell-shake {
  0%, 100% { transform: rotate(0); }
  20% { transform: rotate(-12deg); }
  40% { transform: rotate(10deg); }
  60% { transform: rotate(-6deg); }
  80% { transform: rotate(4deg); }
}
@media (prefers-reduced-motion: reduce) { .bell--new { animation: none; } }
.bell__dot { position: absolute; top: 6px; right: 6px; min-width: 16px; height: 16px; padding: 0 4px; border-radius: var(--radius-full); background: var(--danger-500); color: #fff; font-size: 10px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; line-height: 1; }

/* ---------------------------------------------------------------- Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  border: 1px solid transparent; border-radius: var(--radius-full);
  font-size: 14px; line-height: 20px; font-weight: 600; cursor: pointer;
  padding: 10px 18px; text-decoration: none; white-space: nowrap;
  transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease;
}
.btn:hover { text-decoration: none; }
.btn--sm { padding: 7px 14px; font-size: 13px; line-height: 18px; }
.btn--lg { padding: 13px 24px; font-size: 15px; line-height: 22px; }
.btn--block { width: 100%; }
.btn:disabled, .btn.is-disabled { opacity: var(--opacity-disabled); cursor: not-allowed; pointer-events: none; }
.btn svg { width: 16px; height: 16px; flex: none; }
.btn--primary { background: var(--brand-500); color: var(--ink-on-inverse); box-shadow: var(--shadow-brand); }
.btn--primary:hover { background: var(--brand-600); }
.btn--primary:active { background: var(--brand-700); }
.btn--secondary { background: var(--surface-card); color: var(--ink-900); border-color: var(--border-strong); }
.btn--secondary:hover { background: var(--surface-sunken); }
.btn--ghost { background: transparent; color: var(--ink-600); }
.btn--ghost:hover { background: var(--surface-sunken); color: var(--ink-900); }
.btn--inverse { background: var(--surface-card); color: var(--ink-900); }
.btn--inverse:hover { background: var(--surface-sunken); }
.btn--danger { background: var(--danger-100); color: var(--danger-600); }
.btn--danger:hover { background: #fbd9d5; }
.btn--success { background: var(--success-500); color: #fff; }
.btn--success:hover { background: #1ba74f; }
.btn--whatsapp { background: #25d366; color: #0b2e1a; box-shadow: 0 6px 18px rgba(37, 211, 102, 0.3); }
.btn--whatsapp:hover { background: #1fc65b; }

.iconbtn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; border-radius: var(--radius-md);
  border: 1px solid transparent; background: transparent; color: var(--ink-600); cursor: pointer;
}
.iconbtn svg { width: 18px; height: 18px; }
.iconbtn--sm { width: 30px; height: 30px; border-radius: var(--radius-sm); }
.iconbtn--ghost:hover { background: var(--surface-sunken); color: var(--ink-900); }
.iconbtn--outline { border-color: var(--border-strong); background: var(--surface-card); }
.iconbtn--inverse { background: rgba(255,255,255,.08); color: var(--ink-on-inverse); border-radius: var(--radius-full); }
.iconbtn--inverse:hover { background: rgba(255,255,255,.16); }

/* ---------------------------------------------------------------- Badge */
.badge {
  display: inline-flex; align-items: center; gap: var(--space-1);
  padding: 4px 10px; border-radius: var(--radius-sm);
  font-size: 12px; line-height: 16px; font-weight: 600; white-space: nowrap;
}
.badge--neutral { background: var(--surface-sunken); color: var(--ink-600); }
.badge--brand { background: var(--brand-100); color: var(--on-brand-soft); }
.badge--success { background: var(--success-100); color: var(--success-600); }
.badge--danger { background: var(--danger-100); color: var(--danger-600); }
.badge--warning { background: var(--warning-100); color: var(--warning-600); }
.badge--inverse { background: rgba(255,255,255,.1); color: var(--ink-on-inverse); }
.badge--outline { background: transparent; border: 1px solid var(--border-subtle); color: var(--ink-600); }

/* ---------------------------------------------------------------- Segmented tabs */
.tabs { display: inline-flex; align-items: center; gap: 4px; padding: 5px; border-radius: var(--radius-full); max-width: 100%; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs--light { background: var(--surface-sunken); }
.tabs--inverse { background: var(--surface-inverse); }
.tabs--card { background: var(--surface-card); box-shadow: var(--shadow-card); }
.tab {
  display: inline-flex; align-items: center; gap: var(--space-2);
  border: 0; background: transparent; border-radius: var(--radius-full);
  padding: 8px 16px; font-size: 13px; line-height: 18px; font-weight: 600; cursor: pointer;
  color: var(--ink-600); white-space: nowrap; text-decoration: none;
}
.tab:hover { color: var(--ink-900); text-decoration: none; }
.tabs--inverse .tab { color: var(--ink-on-inverse-muted); }
.tabs--inverse .tab:hover { color: var(--ink-on-inverse); }
.tab.is-active { background: var(--brand-500); color: var(--ink-on-inverse); }
.tab__count { min-width: 18px; height: 18px; padding: 0 5px; border-radius: var(--radius-full); background: rgba(255,255,255,.22); display: inline-flex; align-items: center; justify-content: center; font-size: 11px; }
.tab:not(.is-active) .tab__count { background: var(--surface-card); color: var(--ink-600); }
.tabs--card .tab:not(.is-active) .tab__count { background: var(--surface-sunken); }
.tab.is-danger:not(.is-active) { color: var(--danger-600); }

/* ---------------------------------------------------------------- Forms */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field__label { font-size: 12px; line-height: 16px; font-weight: 600; color: var(--ink-400); }
.field__label--strong { font-size: 13px; color: var(--ink-900); }
.field__hint { font-size: 12px; line-height: 16px; color: var(--ink-400); }
.field__error { font-size: 12px; line-height: 16px; color: var(--danger-600); font-weight: 600; }
.field.has-error .input, .field.has-error .textarea, .field.has-error .select__control { border-color: var(--danger-500); }
.req { color: var(--danger-500); }
.input, .textarea, .select__control {
  width: 100%; max-width: 100%; min-width: 0;
  border: 1px solid var(--border-strong); border-radius: var(--radius-md);
  background: var(--surface-card); color: var(--ink-900);
  padding: 0 14px; height: 44px; font-size: 14px;
}
/* Safari на iOS даёт input[type=date] собственную ширину и не даёт ей сжиматься —
   поле вылезает за карточку. Снимаем нативное оформление и разрешаем сжатие. */
input[type="date"] {
  -webkit-appearance: none;
  appearance: none;
  min-width: 0;
  max-width: 100%;
}
input[type="date"]::-webkit-date-and-time-value { text-align: left; }
input[type="date"]::-webkit-calendar-picker-indicator { margin-left: auto; opacity: .6; }
.field > * { min-width: 0; max-width: 100%; }
.input::placeholder, .textarea::placeholder { color: var(--ink-400); }
.input:focus, .textarea:focus { outline: 2px solid var(--focus-ring); outline-offset: 1px; border-color: transparent; }
.textarea { height: auto; min-height: 120px; padding: 12px 14px; line-height: 20px; resize: vertical; }
.input--sm { height: 40px; font-size: 13px; }
.select { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.select__control { position: relative; display: flex; align-items: center; padding: 0; height: 44px; }
.select__control--sm { height: 40px; }
.select__input {
  appearance: none; -webkit-appearance: none; border: 0; background: transparent;
  width: 100%; height: 100%; padding: 0 36px 0 14px; font-size: 14px; font-weight: 500; color: inherit; cursor: pointer;
  border-radius: var(--radius-md);
}
.select__control--sm .select__input { font-size: 13px; font-weight: 600; }
.select__input:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 1px; }
.select__chevron { position: absolute; right: 12px; color: var(--ink-400); pointer-events: none; display: inline-flex; }
.select__chevron svg { width: 16px; height: 16px; }
.search { display: inline-flex; align-items: center; gap: var(--space-2); height: 40px; padding: 0 14px; border: 1px solid var(--border-strong); border-radius: var(--radius-md); background: var(--surface-card); min-width: 220px; }
.search:focus-within { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
.search svg { width: 16px; height: 16px; color: var(--ink-400); flex: none; }
.search__input { border: 0; background: transparent; outline: none; width: 100%; font-size: 13px; color: var(--ink-900); }
.search__input::placeholder { color: var(--ink-400); }
.check { display: flex; align-items: flex-start; gap: var(--space-3); cursor: pointer; }
.check input { width: 20px; height: 20px; margin: 0; flex: none; accent-color: var(--brand-500); }
.filters { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; }
.filters .select { min-width: 160px; flex: 1 1 160px; }
.filters .search { flex: 1 1 220px; max-width: 320px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-4); }
.form-grid .span-2 { grid-column: span 2; }
.form-actions { display: flex; gap: var(--space-2); align-items: center; flex-wrap: wrap; margin-top: var(--space-2); }
.errorlist { margin: 0; padding: 0; list-style: none; color: var(--danger-600); font-size: 12px; font-weight: 600; }
.help-block { font-size: 12px; color: var(--ink-400); }

/* ---------------------------------------------------------------- Avatar */
.avatar { display: inline-flex; align-items: center; justify-content: center; border-radius: var(--radius-full); overflow: hidden; background: var(--brand-100); color: var(--on-brand-soft); font-weight: 700; flex: none; }
.avatar--sm { width: 28px; height: 28px; font-size: 11px; }
.avatar--md { width: 36px; height: 36px; font-size: 13px; }
.avatar--lg { width: 48px; height: 48px; font-size: 16px; }
.avatar--inverse { background: rgba(255,255,255,.14); color: var(--ink-on-inverse); }
.avatar--neutral { background: var(--surface-sunken); color: var(--ink-600); }

/* ---------------------------------------------------------------- Stat card */
.stat { display: flex; flex-direction: column; gap: var(--space-2); padding: var(--space-5); background: var(--surface-card); border-radius: var(--radius-lg); box-shadow: var(--shadow-card); min-width: 0; text-decoration: none; color: inherit; }
a.stat:hover { text-decoration: none; box-shadow: var(--shadow-popover); }
.stat__head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.stat__label { font-size: 15px; line-height: 20px; font-weight: 600; color: var(--ink-900); }
.stat__icon { display: inline-flex; color: var(--ink-400); }
.stat__icon svg { width: 18px; height: 18px; }
.stat__icon--danger { color: var(--danger-500); }
.stat__icon--success { color: var(--success-500); }
.stat__value { font-family: var(--font-numeric); font-variant-numeric: tabular-nums; font-size: 28px; line-height: 34px; font-weight: 700; letter-spacing: -0.01em; color: var(--ink-900); }
.stat__unit { font-size: 15px; font-weight: 600; margin-left: 6px; color: var(--ink-600); }
.stat__delta { font-size: 12px; line-height: 16px; font-weight: 600; color: var(--ink-400); }
.stat__delta--bad { color: var(--danger-600); }
.stat__delta--good { color: var(--success-600); }
.stat--danger .stat__value { color: var(--danger-600); }

/* ---------------------------------------------------------------- Panel */
.panel { border-radius: var(--radius-xl); padding: var(--space-6); display: flex; flex-direction: column; gap: var(--space-4); min-width: 0; }
.panel--light { background: var(--surface-card); color: var(--ink-900); box-shadow: var(--shadow-card); }
.panel--inverse { background: var(--surface-inverse); color: var(--ink-on-inverse); }
.panel--brand { background: var(--brand-500); color: var(--ink-on-inverse); box-shadow: var(--shadow-brand); }
.panel--sunken { background: var(--surface-sunken); }
.panel--compact { padding: var(--space-5); gap: var(--space-3); }
.panel__head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-4); flex-wrap: wrap; }
.panel__title { font-size: 18px; line-height: 24px; font-weight: 700; }
.panel__sub { font-size: 13px; color: var(--ink-400); margin-top: 2px; }
.panel--inverse .panel__sub, .panel--brand .panel__sub { color: var(--ink-on-inverse-muted); }
.panel--brand .panel__sub { color: rgba(255,255,255,.8); }
.panel__actions { display: inline-flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.panel__body { display: flex; flex-direction: column; gap: var(--space-2); }
.panel--inverse a { color: var(--ink-on-inverse); }

/* ---------------------------------------------------------------- List rows */
.rows { display: flex; flex-direction: column; }
.rows > * + * { border-top: 1px solid var(--border-subtle); }
.panel--inverse .rows > * + * { border-top-color: rgba(255,255,255,.08); }
.row { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3) var(--space-4); border-radius: var(--radius-lg); color: var(--ink-900); text-decoration: none; width: 100%; min-width: 0; }
.row:hover { background: var(--surface-sunken); text-decoration: none; }
.panel--inverse .row { color: var(--ink-on-inverse); }
.panel--inverse .row:hover { background: rgba(255,255,255,.06); }
.row__main { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.row__title { font-size: 14px; line-height: 20px; font-weight: 600; display: flex; gap: var(--space-2); align-items: center; flex-wrap: wrap; }
.row__meta { font-size: 13px; line-height: 18px; color: var(--ink-400); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.panel--inverse .row__meta { color: var(--ink-on-inverse-muted); }
.row__text { font-size: 13px; line-height: 18px; color: var(--ink-600); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.panel--inverse .row__text { color: var(--ink-on-inverse-muted); }
.row__side { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex: none; text-align: right; }
.row__amount { font-family: var(--font-numeric); font-variant-numeric: tabular-nums; font-size: 15px; line-height: 20px; font-weight: 700; }
.row__sub { font-size: 12px; color: var(--ink-400); }
.panel--inverse .row__sub { color: var(--ink-on-inverse-muted); }
.row__sub--danger { color: var(--danger-500); font-weight: 600; }

/* ---------------------------------------------------------------- Table */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th { text-align: left; font-size: 11px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--ink-400); padding: 8px 12px; border-bottom: 1px solid var(--border-subtle); white-space: nowrap; }
.table td { padding: 12px; border-bottom: 1px solid var(--border-subtle); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.panel--inverse .table th { color: var(--ink-on-inverse-muted); border-bottom-color: rgba(255,255,255,.1); }
.panel--inverse .table td { border-bottom-color: rgba(255,255,255,.08); }
.table .cell-user { display: flex; align-items: center; gap: var(--space-2); white-space: nowrap; }
.bar { height: 6px; border-radius: var(--radius-full); background: var(--chart-bar-muted); overflow: hidden; min-width: 80px; }
.bar > i { display: block; height: 100%; background: var(--chart-bar); border-radius: var(--radius-full); }
.panel--inverse .bar { background: rgba(255,255,255,.12); }

/* ---------------------------------------------------------------- Timeline / history */
.timeline { display: flex; flex-direction: column; gap: 0; position: relative; }
.tl { display: grid; grid-template-columns: 20px 1fr; gap: var(--space-3); padding: 6px 0; position: relative; }
.tl__dot { width: 10px; height: 10px; border-radius: var(--radius-full); background: var(--brand-300); margin: 5px auto 0; position: relative; z-index: 1; }
.tl__dot--brand { background: var(--brand-500); }
.tl__dot--success { background: var(--success-500); }
.tl__dot--danger { background: var(--danger-500); }
.tl__dot--muted { background: var(--border-subtle); }
.tl::before { content: ""; position: absolute; left: 9px; top: 0; bottom: 0; width: 2px; background: var(--border-subtle); }
.tl:first-child::before { top: 12px; }
.tl:last-child::before { bottom: calc(100% - 12px); }
.tl__body { min-width: 0; }
.tl__title { font-size: 13px; font-weight: 600; }
.tl__meta { font-size: 12px; color: var(--ink-400); }
.tl__text { font-size: 13px; color: var(--ink-600); margin-top: 2px; white-space: pre-wrap; word-break: break-word; }

/* Милстоуны на брендовой панели карточки */
.milestones { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-3); }
.ms { background: rgba(255,255,255,.14); border-radius: var(--radius-md); padding: var(--space-3) var(--space-4); min-width: 0; }
.ms__label { font-size: 11px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; opacity: .85; }
.ms__value { font-family: var(--font-numeric); font-variant-numeric: tabular-nums; font-size: 15px; font-weight: 700; margin-top: 4px; white-space: nowrap; }
.ms__sub { font-size: 12px; opacity: .85; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ms--empty { background: rgba(255,255,255,.07); border: 1px dashed rgba(255,255,255,.4); }

/* ---------------------------------------------------------------- Definition list */
.dl { display: grid; grid-template-columns: 140px 1fr; gap: 6px var(--space-4); font-size: 14px; }
.dl dt { color: var(--ink-400); font-size: 13px; }
.dl dd { margin: 0; min-width: 0; word-break: break-word; }
.prose { white-space: pre-wrap; word-break: break-word; line-height: 22px; }
.quote { background: var(--surface-sunken); border-radius: var(--radius-md); padding: var(--space-4); }

/* ---------------------------------------------------------------- Files */
.files { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: var(--space-3); }
.file { display: flex; flex-direction: column; gap: 6px; text-decoration: none; color: inherit; min-width: 0; }
.file:hover { text-decoration: none; }
.file__thumb { aspect-ratio: 4 / 3; border-radius: var(--radius-md); background: var(--surface-sunken); overflow: hidden; display: flex; align-items: center; justify-content: center; color: var(--ink-400); border: 1px solid var(--border-subtle); }
.file__thumb img { width: 100%; height: 100%; object-fit: cover; }
.file__thumb svg { width: 28px; height: 28px; }
.file__name { font-size: 12px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file__meta { font-size: 11px; color: var(--ink-400); display: flex; justify-content: space-between; gap: 6px; }
.file__remove { border: 0; background: transparent; color: var(--danger-600); font-size: 11px; font-weight: 600; cursor: pointer; padding: 0; }
.dropzone { border: 1px dashed var(--border-strong); border-radius: var(--radius-md); padding: var(--space-4); background: var(--surface-sunken); display: flex; align-items: center; gap: var(--space-3); cursor: pointer; }
.dropzone:hover { background: var(--brand-100); border-color: var(--brand-500); }
.dropzone svg { width: 22px; height: 22px; color: var(--brand-600); flex: none; }
.dropzone__text { font-size: 13px; font-weight: 600; }
.dropzone__hint { font-size: 12px; color: var(--ink-400); }
.dropzone input { display: none; }
.filelist { display: flex; flex-direction: column; gap: 6px; }
.filelist__item { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); font-size: 13px; padding: 8px 12px; background: var(--surface-card); border: 1px solid var(--border-subtle); border-radius: var(--radius-sm); }
.filelist__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------------------------------------------------------------- Alerts / toasts */
.alert { border-radius: var(--radius-md); padding: var(--space-3) var(--space-4); font-size: 13px; font-weight: 600; display: flex; gap: var(--space-2); align-items: flex-start; }
.alert--danger { background: var(--danger-100); color: var(--danger-600); }
.alert--warning { background: var(--warning-100); color: var(--warning-600); }
.alert--success { background: var(--success-100); color: var(--success-600); }
.alert--brand { background: var(--brand-100); color: var(--on-brand-soft); }
.alert ul { margin: 4px 0 0; padding-left: 18px; list-style: disc; font-weight: 500; }
.toasts { position: fixed; top: var(--space-4); right: var(--space-4); display: flex; flex-direction: column; gap: var(--space-2); z-index: 100; max-width: 360px; }
.toast { background: var(--surface-inverse); color: var(--ink-on-inverse); padding: 12px 16px; border-radius: var(--radius-md); box-shadow: var(--shadow-popover); font-size: 13px; font-weight: 600; display: flex; gap: var(--space-2); align-items: center; }
.toast--success { border-left: 3px solid var(--success-500); }
.toast--error { border-left: 3px solid var(--danger-500); }
.toast__close { margin-left: auto; background: transparent; border: 0; color: var(--ink-on-inverse-muted); cursor: pointer; font-size: 16px; line-height: 1; }

/* ---------------------------------------------------------------- Pagination */
.pager { display: flex; align-items: center; gap: var(--space-2); justify-content: space-between; flex-wrap: wrap; }
.pager__info { font-size: 13px; color: var(--ink-400); }

/* ---------------------------------------------------------------- Empty state */
.empty { padding: var(--space-8) var(--space-4); text-align: center; color: var(--ink-400); font-size: 14px; }
.empty strong { display: block; color: var(--ink-900); font-size: 15px; margin-bottom: 4px; }

/* ---------------------------------------------------------------- Chart boxes */
.chart-box { position: relative; height: 240px; }
.chart-box--tall { height: 300px; }
.legend { display: flex; gap: var(--space-4); font-size: 12px; color: var(--ink-400); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: middle; }

/* ---------------------------------------------------------------- Details/disclosure */
details.disclosure > summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: var(--space-2); font-weight: 600; font-size: 13px; color: var(--brand-600); }
details.disclosure > summary::-webkit-details-marker { display: none; }
details.disclosure[open] > summary { margin-bottom: var(--space-3); }

/* ============================================================================
   Публичная форма пациента (mobile first)
   ============================================================================ */
.pub { max-width: 600px; margin: 0 auto; padding: var(--space-4) var(--space-4) 120px; }
.pub__top { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); padding: var(--space-2) 0 var(--space-4); }
.pub__org { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.pub__org-name { font-weight: 800; font-size: 14px; letter-spacing: -0.01em; }
.pub__org-sub { font-size: 12px; color: var(--ink-400); }
.pub__title { margin-top: var(--space-2); }
.pub__sub { color: var(--ink-600); margin-top: var(--space-1); }
.pub-card { background: var(--surface-card); border-radius: var(--radius-xl); box-shadow: var(--shadow-card); padding: var(--space-5); margin-top: var(--space-5); display: flex; flex-direction: column; gap: var(--space-5); }
.steps { display: flex; gap: 6px; margin-top: var(--space-5); }
.steps__item { flex: 1; display: flex; flex-direction: column; gap: 6px; font-size: 12px; font-weight: 600; color: var(--ink-400); }
.steps__bar { height: 6px; border-radius: var(--radius-full); background: var(--border-subtle); }
.steps__item.is-active { color: var(--ink-900); }
.steps__item.is-active .steps__bar, .steps__item.is-done .steps__bar { background: var(--brand-500); }
.steps__item.is-done { color: var(--brand-600); }
.step { display: none; flex-direction: column; gap: var(--space-5); }
.step.is-active { display: flex; }
.step__title { font-size: 18px; line-height: 24px; font-weight: 700; }
.step__num { font-size: 12px; font-weight: 600; color: var(--ink-400); text-transform: uppercase; letter-spacing: 0.04em; }
.pub .input, .pub .select__control, .pub .textarea { height: 52px; font-size: 16px; border-radius: var(--radius-md); }
.pub .textarea { height: auto; min-height: 160px; }
.pub .select__input { font-size: 16px; }
.pub .field__label { font-size: 13px; color: var(--ink-900); font-weight: 600; }
.kinds { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-2); }
.kind { position: relative; }
.kind input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.kind__tile { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 14px 8px; border-radius: var(--radius-md); border: 1px solid var(--border-strong); background: var(--surface-card); font-size: 13px; font-weight: 600; cursor: pointer; text-align: center; color: var(--ink-600); }
.kind__tile svg { width: 22px; height: 22px; }
.kind input:checked + .kind__tile { background: var(--brand-500); color: var(--ink-on-inverse); border-color: var(--brand-500); box-shadow: var(--shadow-brand); }
.kind input:focus-visible + .kind__tile { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
.pub-actions { position: fixed; left: 0; right: 0; bottom: 0; padding: var(--space-3) var(--space-4) calc(var(--space-3) + env(safe-area-inset-bottom)); background: rgba(244,243,251,.92); backdrop-filter: blur(10px); border-top: 1px solid var(--border-subtle); z-index: 20; }
.pub-actions__inner { max-width: 600px; margin: 0 auto; display: flex; gap: var(--space-2); }
.pub-actions__inner .btn { flex: 1; height: 52px; font-size: 15px; }
.pub-actions__inner .btn--ghost { flex: 0 0 auto; padding-inline: 18px; }
.lang { display: inline-flex; gap: 2px; padding: 3px; background: var(--surface-card); border-radius: var(--radius-full); box-shadow: var(--shadow-card); flex: none; }
.lang a { padding: 6px 12px; border-radius: var(--radius-full); font-size: 12px; font-weight: 700; color: var(--ink-600); }
.lang a.is-active { background: var(--brand-500); color: #fff; }
.lang a:hover { text-decoration: none; }
.pub-success { text-align: center; display: flex; flex-direction: column; align-items: center; gap: var(--space-4); padding: var(--space-8) var(--space-5); }
.pub-success__icon { width: 64px; height: 64px; border-radius: var(--radius-full); background: var(--success-100); color: var(--success-600); display: flex; align-items: center; justify-content: center; }
.pub-success__icon svg { width: 30px; height: 30px; }
.pub-success__number { font-family: var(--font-numeric); font-variant-numeric: tabular-nums; font-size: 40px; line-height: 44px; font-weight: 800; letter-spacing: -0.02em; color: var(--brand-600); }
.consent-text { font-size: 12px; line-height: 18px; color: var(--ink-600); background: var(--surface-sunken); border-radius: var(--radius-md); padding: var(--space-3) var(--space-4); }

/* ============================================================================
   Страница входа
   ============================================================================ */
.auth { min-height: 100vh; display: grid; place-items: center; padding: var(--space-4); }
.auth__card { width: 100%; max-width: 400px; background: var(--surface-card); border-radius: var(--radius-xl); box-shadow: var(--shadow-card); padding: var(--space-8); display: flex; flex-direction: column; gap: var(--space-5); }
.auth__brand { display: flex; align-items: center; gap: var(--space-3); }
.auth__mark { width: 40px; height: 40px; border-radius: var(--radius-md); background: var(--brand-500); box-shadow: var(--shadow-brand); display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 800; }

/* ============================================================================
   Responsive
   ============================================================================ */
@media (max-width: 1024px) {
  .detail { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sticky { position: static; }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
  .shell { padding: 0 var(--space-4) var(--space-8); }
  .topbar { border-radius: var(--radius-xl); flex-wrap: wrap; padding: 10px 12px; gap: var(--space-2); }
  .topbar__brand { order: 1; flex: 1 1 0; min-width: 0; }
  .topbar__brand-name, .topbar__brand-sub { white-space: normal; }
  .topbar__right { order: 2; margin-left: auto; }
  .topbar__nav { order: 3; flex: 1 1 100%; }
  .stats { grid-template-columns: 1fr; }
  .topbar__user-name, .topbar__user-role { display: none; }
  .page-head { margin-top: var(--space-5); }
  .t-display-xl { font-size: 26px; line-height: 32px; }
  .grid-2, .grid-3, .form-grid { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: auto; }
  .panel { padding: var(--space-4); border-radius: var(--radius-lg); }
  .dl { grid-template-columns: 1fr; gap: 2px; }
  .dl dt { margin-top: var(--space-2); }
  .milestones { grid-template-columns: 1fr; }
  .row { padding: var(--space-3); flex-wrap: wrap; }
  .row__side { align-items: flex-start; text-align: left; width: 100%; flex-direction: row; gap: var(--space-2); }
  .row__meta, .row__text { white-space: normal; }
  .filters .search { max-width: none; }
  .toasts { left: var(--space-4); right: var(--space-4); max-width: none; }
  .kinds { grid-template-columns: 1fr; }
  .kind__tile { flex-direction: row; justify-content: flex-start; padding: 12px 14px; }
  .chart-box { height: 200px; }
}
