/* Мини-CRM корреспонденции РСУ-Э — дизайн-система «Minimalism & Swiss» (ui-ux-pro-max):
   строгий navy, один синий акцент, плотная раскладка для реестра, Inter с кириллицей. */
@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap");

:root {
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --bg: #f6f8fb; --surface: #ffffff; --surface-2: #f1f5f9; --hover: #f8fafc;
  --ink: #0f172a; --ink-2: #334155; --muted: #64748b; --line: #e2e8f0; --line-strong: #cbd5e1;
  --primary: #0f172a; --accent: #0369a1; --accent-hover: #075985; --accent-soft: #e0f2fe; --accent-ink: #075985;
  --red: #dc2626; --red-soft: #fef2f2; --red-ink: #b91c1c;
  --amber: #b45309; --amber-soft: #fffbeb; --green: #15803d; --green-soft: #f0fdf4;
  --violet: #6d28d9; --violet-soft: #f5f3ff; --teal: #0f766e; --teal-soft: #f0fdfa;
  --ring: 0 0 0 3px rgba(3, 105, 161, .25);
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .05);
  --shadow: 0 1px 3px rgba(15, 23, 42, .06), 0 8px 24px rgba(15, 23, 42, .06);
  --shadow-lg: 0 24px 64px rgba(15, 23, 42, .22);
  --radius: 12px; --radius-sm: 8px;
  --fast: 150ms; --base: 220ms; --ease: cubic-bezier(.2, .8, .2, 1);
  /* совместимость с прежними именами */
  --canvas: var(--bg); --blue: var(--accent); --blue-soft: var(--accent-soft); --navy: var(--primary);
  --yellow: var(--amber); --yellow-soft: var(--amber-soft);
}
html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b1220; --surface: #111a2b; --surface-2: #17223a; --hover: #16213a;
  --ink: #e6ebf2; --ink-2: #c3ccd9; --muted: #94a3b8; --line: #23304a; --line-strong: #31405f;
  --primary: #e6ebf2; --accent: #38bdf8; --accent-hover: #7dd3fc; --accent-soft: #0c2a40; --accent-ink: #7dd3fc;
  --red: #f87171; --red-soft: #3a1518; --red-ink: #fca5a5;
  --amber: #fbbf24; --amber-soft: #33270c; --green: #4ade80; --green-soft: #0f2a1b;
  --violet: #c4b5fd; --violet-soft: #241b3d; --teal: #5eead4; --teal-soft: #0c2a28;
  --ring: 0 0 0 3px rgba(56, 189, 248, .35);
  --shadow-sm: none; --shadow: 0 1px 0 rgba(255, 255, 255, .03); --shadow-lg: 0 24px 64px rgba(0, 0, 0, .5);
}
html.in-telegram { --bg: var(--tg-secondary, var(--bg)); }

* { box-sizing: border-box; }
html { color-scheme: light; -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 400 14px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
button, a, summary, label.file-upload, [role="button"] { cursor: pointer; -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.icon { flex: 0 0 auto; display: block; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }

/* ── Каркас ───────────────────────────────────────────────────────── */
.app-shell { min-height: 100vh; display: grid; grid-template-columns: 248px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 20px 14px; display: flex; flex-direction: column; gap: 6px; background: var(--surface); border-right: 1px solid var(--line); z-index: 30; }
.brand { display: flex; align-items: center; gap: 11px; padding: 4px 10px 22px; color: var(--ink); text-decoration: none; }
.brand-mark { width: 38px; height: 38px; flex: 0 0 auto; display: grid; place-items: center; border-radius: 50%; background: #fff; border: 1px solid var(--line); font-weight: 700; font-size: 18px; letter-spacing: -.02em; }
.brand-mark img { display: block; width: 26px; height: 26px; }
html[data-theme="dark"] .brand-mark { background: #fff; border-color: transparent; }
.brand b { display: block; font-size: 16px; font-weight: 700; letter-spacing: -.01em; }
.brand small { display: block; color: var(--muted); font-size: 12px; }
.nav { display: grid; gap: 2px; }
.nav-item { width: 100%; min-height: 40px; display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--ink-2); font-size: 14px; font-weight: 500; text-align: left; text-decoration: none; transition: background var(--fast) var(--ease), color var(--fast) var(--ease); }
.nav-item > span:not(.nav-icon) { flex: 1; }
.nav-item:hover { background: var(--surface-2); color: var(--ink); }
.nav-item.active { background: var(--accent-soft); color: var(--accent-ink); }
.nav-item.active .nav-icon { color: var(--accent); }
.nav-icon { width: 20px; display: grid; place-items: center; color: var(--muted); }
.nav-item b { min-width: 24px; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); font-size: 12px; font-weight: 600; text-align: center; }
.nav-item.active b { background: var(--surface); color: var(--accent-ink); }
.nav-item b.alert { background: var(--red); color: #fff; }
.sidebar-bottom { margin-top: auto; display: grid; gap: 4px; padding-top: 12px; border-top: 1px solid var(--line); }
.system-state { display: flex; align-items: center; gap: 8px; padding: 8px 10px 0; color: var(--muted); font-size: 12px; }
.system-state i { width: 8px; height: 8px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 3px var(--green-soft); }

.main { min-width: 0; }
.topbar { position: sticky; top: 0; z-index: 20; min-height: 72px; padding: 14px 32px; display: flex; align-items: center; justify-content: space-between; gap: 16px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(12px); border-bottom: 1px solid var(--line); }
.eyebrow { margin: 0 0 2px; color: var(--muted); font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; }
.topbar h1 { margin: 0; font-size: 22px; font-weight: 700; letter-spacing: -.02em; }
.top-actions { display: flex; align-items: center; gap: 12px; }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 4px 12px 4px 4px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); }
.user-chip b, .user-chip small { display: block; line-height: 1.25; }
.user-chip b { font-size: 13px; font-weight: 600; }
.user-chip small { color: var(--muted); font-size: 12px; }
.avatar { width: 34px; height: 34px; flex: 0 0 auto; display: grid; place-items: center; border-radius: 50%; background: var(--accent-soft); color: var(--accent-ink); font-size: 12px; font-weight: 700; }
.content { max-width: 1480px; margin: 0 auto; padding: 24px 32px 64px; }

/* ── Кнопки и поля ───────────────────────────────────────────────── */
.button { min-height: 38px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 0 14px; border: 1px solid transparent; border-radius: var(--radius-sm); font-size: 14px; font-weight: 600; white-space: nowrap; transition: background var(--fast) var(--ease), border-color var(--fast) var(--ease), box-shadow var(--fast) var(--ease); }
.button-primary { background: var(--accent); color: #fff; box-shadow: var(--shadow-sm); }
.button-primary:hover { background: var(--accent-hover); }
html[data-theme="dark"] .button-primary { color: #04121f; }
.button-soft { background: var(--surface); border-color: var(--line); color: var(--ink-2); }
.button-soft:hover { background: var(--surface-2); border-color: var(--line-strong); color: var(--ink); }
.button:disabled { opacity: .5; cursor: not-allowed; }
.button.small { min-height: 32px; padding: 0 10px; font-size: 13px; }
.icon-button { width: 38px; height: 38px; display: inline-grid; place-items: center; padding: 0; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); color: var(--ink-2); transition: background var(--fast); }
.icon-button:hover { background: var(--surface-2); color: var(--ink); }
.icon-button.small { width: 32px; height: 32px; }
.link-button { padding: 0; border: 0; background: none; color: var(--accent); font-size: 13px; font-weight: 600; }
.link-button:hover { text-decoration: underline; }

input, select, textarea { width: 100%; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--surface); color: var(--ink); outline: none; transition: border-color var(--fast), box-shadow var(--fast); }
input, select { height: 40px; padding: 0 12px; }
textarea { padding: 10px 12px; resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: var(--ring); }
input::placeholder, textarea::placeholder { color: var(--muted); }
input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); }
input:disabled, select:disabled, textarea:disabled { background: var(--surface-2); color: var(--muted); cursor: not-allowed; }

/* ── Баннер и сводка ─────────────────────────────────────────────── */
.demo-banner { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; padding: 12px 16px; border: 1px solid color-mix(in srgb, var(--accent) 25%, var(--line)); border-radius: var(--radius); background: var(--accent-soft); color: var(--ink-2); font-size: 13px; }
.demo-banner > span:first-child { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; background: var(--surface); color: var(--accent-ink); font-size: 12px; font-weight: 700; white-space: nowrap; }
.demo-banner p { margin: 0; }
.demo-banner select { margin-left: auto; width: auto; max-width: 340px; height: 34px; font-size: 13px; }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat-card { position: relative; display: flex; align-items: center; gap: 14px; padding: 16px 18px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); text-align: left; box-shadow: var(--shadow-sm); transition: border-color var(--base) var(--ease), box-shadow var(--base) var(--ease); }
.stat-card:hover { border-color: var(--line-strong); box-shadow: var(--shadow); }
.stat-icon { width: 40px; height: 40px; flex: 0 0 auto; display: grid; place-items: center; border-radius: 10px; }
.stat-card small { display: block; color: var(--muted); font-size: 13px; font-weight: 500; }
.stat-card b { display: block; margin-top: 2px; font-size: 26px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat-new .stat-icon { background: var(--accent-soft); color: var(--accent); }
.stat-work .stat-icon { background: var(--amber-soft); color: var(--amber); }
.stat-approval .stat-icon { background: var(--teal-soft); color: var(--teal); }
.stat-overdue .stat-icon { background: var(--red-soft); color: var(--red); }

/* ── Реестр ──────────────────────────────────────────────────────── */
.panel { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow-sm); overflow: hidden; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 20px 14px; }
.panel-heading h2 { margin: 0; font-size: 18px; font-weight: 700; letter-spacing: -.01em; }
.result-count { padding: 3px 10px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }
.filters { display: grid; grid-template-columns: minmax(260px, 1fr) 200px 220px auto; gap: 10px; padding: 0 20px 16px; }
.filters-extra { grid-template-columns: repeat(3, minmax(0, 1fr)) 160px 160px auto; align-items: end; }
.filters-extra label { display: grid; gap: 4px; }
.filter-label { color: var(--muted); font-size: 12px; font-weight: 600; }
.search-field { position: relative; }
.search-field > span { position: absolute; left: 12px; top: 11px; color: var(--muted); pointer-events: none; }
.search-field input { padding-left: 38px; }

.registry-head, .letter-row { display: grid; grid-template-columns: minmax(300px, 2.4fr) minmax(170px, 1.2fr) minmax(150px, 1fr) 120px 140px; gap: 16px; align-items: center; }
.registry-head { min-height: 38px; padding: 0 20px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); background: var(--surface-2); color: var(--muted); font-size: 12px; font-weight: 600; letter-spacing: .03em; text-transform: uppercase; }
.letter-row { position: relative; width: 100%; padding: 14px 20px; border: 0; border-bottom: 1px solid var(--line); background: var(--surface); text-align: left; transition: background var(--fast) var(--ease); }
.letter-row:last-child { border-bottom: 0; }
.letter-row:hover { background: var(--hover); }
.letter-row.urgent-row::before { content: ""; position: absolute; left: 0; top: 10px; bottom: 10px; width: 3px; border-radius: 0 3px 3px 0; background: var(--red); }
.letter-row.annulled-row { opacity: .55; }
.letter-row.annulled-row strong { text-decoration: line-through; }
.letter-main, .sender, .letter-meta { min-width: 0; }
.letter-meta { display: flex; align-items: center; gap: 8px; }
.letter-meta b { color: var(--accent-ink); font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; }
.letter-meta small { margin-left: auto; color: var(--muted); font-size: 12px; white-space: nowrap; }
.letter-main strong, .letter-main > small, .sender strong, .sender small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.letter-main strong { margin: 3px 0 2px; font-size: 14px; font-weight: 600; }
.letter-main > small, .sender small { color: var(--muted); font-size: 12px; }
.sender strong { font-size: 13px; font-weight: 600; }
.person { display: flex; align-items: center; gap: 8px; font-size: 13px; min-width: 0; }
.person i { width: 26px; height: 26px; flex: 0 0 auto; display: grid; place-items: center; border-radius: 50%; background: var(--surface-2); color: var(--ink-2); font-size: 11px; font-style: normal; font-weight: 700; }
.letter-row .muted { font-size: 13px; }
.urgent-pill { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; background: var(--red-soft); color: var(--red-ink); font-size: 11px; font-weight: 700; letter-spacing: .02em; text-transform: uppercase; white-space: nowrap; }

.deadline { font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }
.deadline small { display: block; margin-top: 1px; font-size: 12px; font-weight: 500; color: inherit; opacity: .9; }
.deadline.ok { color: var(--green); }
.deadline.soon { color: var(--amber); }
.deadline.overdue { color: var(--red); }
.deadline.done, .deadline.none { color: var(--muted); }

.status-badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); font-size: 12px; font-weight: 600; white-space: nowrap; }
.status-badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .8; }
.status-new { background: var(--accent-soft); color: var(--accent-ink); }
.status-assigned { background: var(--violet-soft); color: var(--violet); }
.status-in_progress { background: var(--amber-soft); color: var(--amber); }
.status-on_approval { background: var(--teal-soft); color: var(--teal); }
.status-response_sent { background: var(--teal-soft); color: var(--teal); }
.status-completed, .status-closed_no_reply { background: var(--green-soft); color: var(--green); }
.status-annulled { background: var(--surface-2); color: var(--muted); }

.empty-state { padding: 56px 20px; text-align: center; color: var(--muted); }
.empty-state div { width: 48px; height: 48px; margin: 0 auto 12px; display: grid; place-items: center; border-radius: 50%; background: var(--green-soft); color: var(--green); }
.empty-state h3 { margin: 0 0 6px; color: var(--ink); font-size: 16px; }
.empty-state p { margin: 0; }
.skeleton-row { height: 68px; margin: 0 20px; border-bottom: 1px solid var(--line); background: linear-gradient(90deg, var(--surface), var(--surface-2), var(--surface)); background-size: 220% 100%; animation: shimmer 1.4s infinite; }
.letter-list.loading { opacity: .6; transition: opacity var(--fast); }
.load-error { padding: 28px 20px; color: var(--red); }
.pager { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 14px; border-top: 1px solid var(--line); color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }

/* ── Карточка письма (выезжающая панель) ─────────────────────────── */
.drawer-backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(15, 23, 42, .35); backdrop-filter: blur(2px); animation: fade var(--base) var(--ease); }
.drawer { position: fixed; top: 0; right: 0; z-index: 50; width: min(760px, 100%); height: 100vh; overflow: auto; background: var(--bg); box-shadow: var(--shadow-lg); transform: translateX(104%); transition: transform 280ms var(--ease); }
.drawer.open { transform: translateX(0); }
.drawer-header { position: sticky; top: 0; z-index: 2; min-height: 72px; padding: 14px 24px; display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 14px; background: var(--surface); border-bottom: 1px solid var(--line); }
.drawer-header h2 { margin: 0; font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.drawer-body { padding: 20px 24px 40px; }
body.drawer-open { overflow: hidden; }

.letter-hero { padding: 22px 24px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow-sm); }
.letter-hero.urgent { border-color: color-mix(in srgb, var(--red) 35%, var(--line)); background: linear-gradient(180deg, var(--red-soft), var(--surface) 70%); }
.letter-hero h3 { margin: 10px 0 8px; font-size: 20px; font-weight: 700; line-height: 1.3; letter-spacing: -.01em; }
.letter-hero > .urgent-pill + h3 { margin-top: 12px; }
.letter-hero p { margin: 0; color: var(--ink-2); line-height: 1.6; }
.hero-meta { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.hero-meta span { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); font-size: 12px; font-weight: 600; }
.hero-meta .deadline.ok { background: var(--green-soft); color: var(--green); }
.hero-meta .deadline.soon { background: var(--amber-soft); color: var(--amber); }
.hero-meta .deadline.overdue { background: var(--red-soft); color: var(--red); }

.detail-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 14px 0; }
.detail-item { min-height: 76px; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); }
.detail-item small, .detail-item b, .detail-item span { display: block; }
.detail-item small { color: var(--muted); font-size: 12px; font-weight: 500; }
.detail-item b { margin-top: 4px; font-size: 14px; font-weight: 600; overflow-wrap: anywhere; }
.detail-item span { margin-top: 2px; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.detail-section { margin-top: 14px; padding: 18px 20px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow-sm); }
.detail-section h3 { margin: 0 0 12px; font-size: 15px; font-weight: 700; }
.detail-section h3 small, .section-title small { color: var(--muted); font-weight: 600; }
.section-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.section-title h3 { margin-bottom: 12px; }
.letter-text { max-height: 300px; overflow: auto; color: var(--ink-2); font-size: 14px; line-height: 1.65; white-space: pre-wrap; overflow-wrap: anywhere; }
.files { display: grid; gap: 8px; }
.file-card { display: grid; grid-template-columns: 36px 1fr auto; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); color: var(--ink); text-decoration: none; font-size: 13px; transition: border-color var(--fast), background var(--fast); }
.file-card:hover { border-color: var(--accent); background: var(--hover); }
.file-card > span { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 8px; background: var(--accent-soft); color: var(--accent); }
.file-card b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.file-card small { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.file-upload { display: inline-flex; align-items: center; gap: 6px; color: var(--accent); font-size: 13px; font-weight: 600; }
.file-upload input { display: none; }
.mini-empty { padding: 14px; border: 1px dashed var(--line-strong); border-radius: var(--radius-sm); color: var(--muted); font-size: 13px; text-align: center; }

.extraction-review { border-color: color-mix(in srgb, var(--amber) 40%, var(--line)); background: var(--amber-soft); }
.extraction-review .section-title > span { padding: 3px 10px; border-radius: 999px; background: var(--surface); color: var(--amber); font-size: 12px; font-weight: 700; }
.extraction-review .eyebrow { margin-bottom: 2px; }
.assignment-form, .form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.assignment-form label, .form-grid label { display: grid; gap: 6px; color: var(--ink-2); font-size: 13px; font-weight: 600; }
.assignment-form label > small { color: var(--muted); font-weight: 500; }
.span-2 { grid-column: span 2; }
.resolution { margin: 0 0 14px; padding: 10px 14px; border-left: 3px solid var(--accent); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; background: var(--accent-soft); color: var(--ink); }
.collaborators { min-width: 0; margin: 0; padding: 10px 12px 12px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); }
.collaborators legend { padding: 0 6px; color: var(--ink-2); font-size: 13px; font-weight: 600; }
.check-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 14px; }
.assignment-form .check { display: flex; align-items: center; gap: 8px; color: var(--ink); font-size: 13px; font-weight: 500; }
.status-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.status-actions .button-success { border-color: color-mix(in srgb, var(--green) 30%, var(--line)); background: var(--green-soft); color: var(--green); }
.status-actions .button-warning { border-color: color-mix(in srgb, var(--amber) 30%, var(--line)); background: var(--amber-soft); color: var(--amber); }
.status-actions .button-danger { border-color: color-mix(in srgb, var(--red) 30%, var(--line)); background: var(--red-soft); color: var(--red-ink); }

.comments { display: grid; gap: 14px; }
.comment { display: grid; grid-template-columns: auto 1fr; gap: 10px; }
.comment header { display: flex; align-items: center; gap: 8px; }
.comment header b { font-size: 13px; font-weight: 600; }
.comment time { margin-left: auto; color: var(--muted); font-size: 12px; white-space: nowrap; }
.comment p { margin: 4px 0 0; color: var(--ink-2); font-size: 14px; line-height: 1.55; white-space: pre-wrap; overflow-wrap: anywhere; }
.comment-email > div { padding: 10px 12px; border: 1px solid color-mix(in srgb, var(--accent) 20%, var(--line)); border-radius: var(--radius-sm); background: var(--accent-soft); }
.comment-system p { color: var(--muted); }
.source-tag { padding: 1px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-size: 11px; font-weight: 600; white-space: nowrap; }
.comment-file { display: inline-flex; align-items: center; gap: 6px; margin-top: 6px; color: var(--accent); font-size: 13px; font-weight: 600; text-decoration: none; }
.comment-form { display: grid; gap: 8px; margin-top: 16px; }
.comment-form .button { justify-self: end; }
.related { display: grid; gap: 8px; }
.related-item { display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: center; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); color: var(--ink); font-size: 13px; text-align: left; }
.related-item small { color: var(--muted); font-size: 12px; }
details summary { list-style: none; display: flex; align-items: center; gap: 8px; }
details summary::-webkit-details-marker { display: none; }
details summary h3 { margin: 0 !important; }
details summary::after { content: ""; width: 8px; height: 8px; margin-left: 4px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg) translateY(-2px); transition: transform var(--fast); }
details[open] summary::after { transform: rotate(-135deg) translateY(-2px); }
.audit-list { list-style: none; margin: 14px 0 0; padding: 0; display: grid; gap: 0; }
.audit-list li { position: relative; display: grid; grid-template-columns: 120px 1fr; gap: 2px 14px; padding: 8px 0 8px 0; border-top: 1px solid var(--line); font-size: 13px; }
.audit-list time { grid-row: span 2; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.audit-list b { font-weight: 600; }
.audit-list span { color: var(--muted); font-size: 12px; }

/* ── Модальные окна, тосты ───────────────────────────────────────── */
.modal { width: min(680px, calc(100% - 24px)); padding: 0; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); color: var(--ink); box-shadow: var(--shadow-lg); }
.modal-small { width: min(460px, calc(100% - 24px)); }
.modal::backdrop { background: rgba(15, 23, 42, .45); backdrop-filter: blur(3px); }
.modal[open] { animation: pop var(--base) var(--ease); }
.modal-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 22px; border-bottom: 1px solid var(--line); }
.modal-header h2 { margin: 0; font-size: 18px; font-weight: 700; }
.modal .form-grid { padding: 20px 22px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 22px 18px; border-top: 1px solid var(--line); background: var(--surface-2); border-radius: 0 0 16px 16px; }
.toast { position: fixed; left: 50%; bottom: 24px; z-index: 100; max-width: calc(100% - 32px); padding: 11px 16px; border-radius: 10px; background: var(--primary); color: var(--surface); font-size: 14px; font-weight: 500; box-shadow: var(--shadow-lg); opacity: 0; pointer-events: none; transform: translate(-50%, 16px); transition: opacity var(--base) var(--ease), transform var(--base) var(--ease); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--red); color: #fff; }
.auth-screen { max-width: 520px; margin: 64px auto; padding: 36px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); color: var(--ink-2); text-align: center; line-height: 1.6; box-shadow: var(--shadow); }
.auth-screen .brand-mark { margin: 0 auto 16px; }
.auth-screen h2 { margin: 0 0 10px; color: var(--ink); font-size: 20px; }

/* ── Админка ─────────────────────────────────────────────────────── */
.admin-panel { padding-bottom: 6px; }
.hint-box { display: flex; gap: 10px; margin: 0 20px 14px; padding: 12px 14px; border-radius: var(--radius-sm); background: var(--accent-soft); color: var(--ink-2); font-size: 13px; line-height: 1.5; }
.admin-user-list { display: grid; }
.admin-user { display: grid; grid-template-columns: auto minmax(200px, 1.4fr) 170px minmax(200px, 1fr) auto; align-items: center; gap: 14px; padding: 12px 20px; border-top: 1px solid var(--line); transition: background var(--fast); }
.admin-user:hover { background: var(--hover); }
.admin-user.blocked { opacity: .55; }
.admin-user-name b, .admin-user-name small, .admin-user-contact b, .admin-user-contact small { display: block; }
.admin-user-name b, .admin-user-contact b { font-size: 14px; font-weight: 600; }
.admin-user-name small, .admin-user-contact small { margin-top: 2px; color: var(--muted); font-size: 12px; }
.invite-pending { color: var(--amber) !important; }
.role-pill { display: inline-flex; padding: 3px 10px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); font-size: 12px; font-weight: 600; }
.role-head { background: var(--violet-soft); color: var(--violet); }
.role-clerk { background: var(--accent-soft); color: var(--accent-ink); }
.role-admin { background: var(--red-soft); color: var(--red-ink); }
.role-observer { background: var(--surface-2); color: var(--muted); }
.admin-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
.toggle { width: 44px; height: 26px; padding: 3px; border: 0; border-radius: 999px; background: var(--line-strong); transition: background var(--base) var(--ease); }
.toggle i { display: block; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, .2); transition: transform var(--base) var(--ease); }
.toggle.on { background: var(--green); }
.toggle.on i { transform: translateX(18px); }
.mailbox-card { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 14px; padding: 16px 20px; border-top: 1px solid var(--line); }
.mailbox-card b, .mailbox-card small { display: block; }
.mailbox-card b { font-size: 14px; font-weight: 600; }
.mailbox-card small { margin-top: 3px; color: var(--muted); font-size: 12px; }
.mailbox-icon { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 10px; background: var(--accent-soft); color: var(--accent); }
.connection-state { padding: 4px 10px; border-radius: 999px; background: var(--amber-soft); color: var(--amber); font-size: 12px; font-weight: 600; white-space: nowrap; }
.connection-state.connected { background: var(--green-soft); color: var(--green); }
.connection-state.error { background: var(--red-soft); color: var(--red-ink); }
.error-text { color: var(--red) !important; }
.number-preview { margin: 0 20px 16px; padding: 18px 20px; border-radius: var(--radius); background: var(--primary); color: var(--surface); }
html[data-theme="dark"] .number-preview { background: var(--surface-2); color: var(--ink); }
.number-preview small, .number-preview span { display: block; opacity: .75; font-size: 13px; }
.number-preview b { display: block; margin: 4px 0; font-size: 32px; font-weight: 700; letter-spacing: -.01em; font-variant-numeric: tabular-nums; }
.simple-table { width: calc(100% - 40px); margin: 0 20px 16px; border-collapse: collapse; font-size: 13px; }
.simple-table th, .simple-table td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: left; }
.simple-table th { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.numbering-form { padding: 0 20px 20px; }

body:not(.is-manager) .manager-only { display: none !important; }
body:not(.can-manage-users) .user-admin-only { display: none !important; }
.mobile-only { display: none; }

@keyframes shimmer { to { background-position: -120% 0; } }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; scroll-behavior: auto !important; }
}

/* ── Адаптив ─────────────────────────────────────────────────────── */
@media (max-width: 1100px) {
  .app-shell { grid-template-columns: 220px minmax(0, 1fr); }
  .registry-head, .letter-row { grid-template-columns: minmax(260px, 2fr) minmax(150px, 1fr) 120px 130px; }
  .registry-head span:nth-child(3), .letter-row > span:nth-child(3) { display: none; }
  .filters { grid-template-columns: minmax(220px, 1fr) 180px 190px auto; }
  .filters-extra { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .admin-user { grid-template-columns: auto 1fr auto auto; }
  .admin-user-contact { display: none; }
}
@media (max-width: 760px) {
  body { font-size: 15px; }
  .app-shell { display: block; }
  .sidebar { position: fixed; left: 0; width: 272px; transform: translateX(-104%); transition: transform var(--base) var(--ease); box-shadow: var(--shadow-lg); }
  .sidebar.mobile-open { transform: translateX(0); }
  .mobile-only { display: inline-grid; }
  .desktop-only { display: none; }
  .topbar { min-height: 60px; padding: 10px 14px; justify-content: flex-start; }
  .topbar h1 { font-size: 19px; }
  .topbar .eyebrow, .user-chip { display: none; }
  .top-actions { margin-left: auto; }
  .top-actions .button { width: 42px; padding: 0; }
  .top-actions .button .button-label { display: none; }
  .content { padding: 14px 12px 40px; }
  .demo-banner { flex-wrap: wrap; align-items: flex-start; }
  .demo-banner select { width: 100%; max-width: none; margin-left: 0; }
  .stats { gap: 10px; }
  .stat-card { padding: 12px; gap: 10px; }
  .stat-icon { width: 34px; height: 34px; }
  .stat-card b { font-size: 21px; }
  .panel-heading { padding: 16px 14px 12px; }
  .filters, .filters-extra { grid-template-columns: 1fr 1fr; padding: 0 14px 12px; }
  .search-field, .filters #more-filters, .filters-extra label:nth-child(-n+3) { grid-column: span 2; }
  .filters > label:nth-child(3) { display: none; }
  .letter-row { grid-template-columns: 1fr auto; gap: 6px 10px; padding: 14px; }
  .letter-row > span:nth-child(2), .letter-row > span:nth-child(3) { display: none; }
  .letter-row > span:nth-child(4) { grid-column: 1; }
  .letter-row > span:nth-child(4) small { display: inline; margin-left: 6px; }
  .letter-row > span:nth-child(5) { grid-column: 2; grid-row: 2; }
  .letter-meta small { margin-left: 0; }
  .drawer-header { padding: 10px 12px; min-height: 60px; }
  .drawer-body { padding: 12px 12px 32px; }
  .letter-hero { padding: 18px; }
  .letter-hero h3 { font-size: 18px; }
  .detail-grid { grid-template-columns: repeat(2, 1fr); }
  .assignment-form, .form-grid, .check-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: span 1; }
  .audit-list li { grid-template-columns: 1fr; }
  .audit-list time { grid-row: auto; }
  .admin-user { grid-template-columns: auto 1fr auto; padding: 12px 14px; }
  .admin-user > span:nth-child(3) { display: none; }
  .hint-box { margin: 0 14px 12px; }
  .number-preview, .simple-table { width: auto; margin-left: 14px; margin-right: 14px; }
  .numbering-form { padding: 0 14px 18px; }
  #add-user-button { width: 42px; padding: 0; }
  .add-user-label { display: none; }
  input, select, textarea { font-size: 16px; } /* iOS не масштабирует поле при фокусе */
}

/* Компактная карточка */
.extraction-review .section-title h3 { font-size: 14px; font-weight: 500; color: var(--ink-2); margin: 0; line-height: 1.6; }
.extraction-review .section-title h3 b { font-weight: 700; color: var(--ink); }
.extraction-form { display: block; }
.extraction-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }
.extraction-actions { display: flex; gap: 8px; margin-top: 12px; }
.assignment-summary { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 16px; margin-bottom: 12px; }
.assignment-summary small { display: block; color: var(--muted); font-size: 12px; }
.assignment-summary b { display: block; margin-top: 2px; font-size: 14px; font-weight: 600; }
.assignment-form.hidden + .assignment-summary { margin-bottom: 0; }
@media (max-width: 760px) { .extraction-fields { grid-template-columns: 1fr; } }

/* Страница помощи */
.help { max-width: 860px; }
.help-block { padding: 22px 24px; margin-bottom: 14px; }
.help-block h2 { margin: 0 0 12px; font-size: 17px; font-weight: 700; }
.help-block p { margin: 8px 0 0; color: var(--ink-2); line-height: 1.6; }
.help-steps { margin: 0; padding-left: 22px; display: grid; gap: 10px; color: var(--ink-2); line-height: 1.55; }
.help-steps li::marker { color: var(--accent); font-weight: 700; }
.help-legend { display: flex; flex-wrap: wrap; gap: 10px 18px; margin-bottom: 6px; font-size: 14px; }
.help-table { width: 100%; margin: 0; }
.help-table td { vertical-align: top; }
.help-table td:first-child { white-space: nowrap; width: 1%; padding-right: 18px; }
.help-list { margin: 0; padding-left: 20px; display: grid; gap: 8px; color: var(--ink-2); line-height: 1.55; }
code { padding: 1px 6px; border-radius: 6px; background: var(--surface-2); font-size: 13px; }

/* Рассылки, отложенные до решения делопроизводителя */
.screened-item { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 16px; align-items: start; padding: 14px 20px; border-top: 1px solid var(--line); }
.screened-item:hover { background: var(--hover); }
.screened-main b { display: block; font-size: 14px; font-weight: 600; }
.screened-main small { display: block; margin-top: 3px; color: var(--muted); font-size: 12px; }
.screened-main p { margin: 6px 0 8px; color: var(--ink-2); font-size: 13px; line-height: 1.5; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.screened-reason { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 999px; background: var(--amber-soft); color: var(--amber); font-size: 12px; font-weight: 600; }
.screened-filter { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; font-weight: 500; }
.screened-filter input { width: 16px; height: 16px; }
@media (max-width: 760px) { .screened-item { grid-template-columns: 1fr; } .screened-item .admin-actions { justify-content: flex-start; flex-wrap: wrap; } }
