/* CourtLetters UI — на базе CourtWatcher, с улучшениями:
 * - семейство продуктов (navy sidebar + primary blue)
 * - акцент teal для «входящей» линии продукта
 * - шрифт Manrope (не дефолтный Inter/Roboto)
 * - hero, KPI, motion, mobile drawer
 */
@import url("https://fonts.googleapis.com/css2?family=Manrope:wght@450;500;600;700;800&display=swap");

:root {
  --bg: #f1f4f9;
  --panel: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --muted: #64748b;
  --primary: #2c5aa0;
  --primary-dark: #1f4287;
  --primary-soft: #eff6ff;
  --teal: #0f766e;
  --teal-soft: #f0fdfa;
  --green: #16a34a;
  --warn: #b45309;
  --danger: #b91c1c;
  --sidebar-from: #1a253c;
  --sidebar-to: #22314e;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 1px 2px rgba(15, 23, 42, .04);
  --shadow-lg: 0 12px 32px rgba(26, 37, 60, .16);
  --radius: 12px;
  --sidebar-w: 248px;
  --ease: cubic-bezier(.22, 1, .36, 1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  font-family: "Manrope", "Segoe UI", sans-serif;
  background:
    radial-gradient(900px 420px at 88% -8%, rgba(44, 90, 160, .08), transparent 55%),
    radial-gradient(700px 380px at 0% 0%, rgba(15, 118, 110, .06), transparent 50%),
    var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
  min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.layout { display: flex; min-height: 100vh; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: linear-gradient(180deg, var(--sidebar-to) 0%, var(--sidebar-from) 100%);
  color: #d7e0ee;
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 40;
  box-shadow: 4px 0 24px rgba(15, 23, 42, .12);
}

.logo {
  display: flex; align-items: center; gap: 12px;
  padding: 6px 8px 18px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.logo-mark {
  width: 38px; height: 38px; border-radius: 11px;
  display: grid; place-items: center;
  font-weight: 800; font-size: 15px; letter-spacing: -.02em;
  color: #fff;
  background: linear-gradient(135deg, var(--primary) 0%, var(--teal) 100%);
  box-shadow: 0 6px 16px rgba(44, 90, 160, .35);
}
.logo-title { font-size: 17px; font-weight: 800; color: #fff; letter-spacing: -.01em; }
.logo-sub { font-size: 11px; color: #8fa0bd; margin-top: 1px; }
.logo-family {
  margin-top: 8px; padding: 0 8px;
  font-size: 10px; letter-spacing: .08em; text-transform: uppercase; color: #7d8eaa;
}

.menu { margin-top: 16px; display: flex; flex-direction: column; gap: 3px; flex: 1; }
.menu-label {
  margin: 12px 12px 6px; font-size: 10px; letter-spacing: .08em;
  text-transform: uppercase; color: #7d8eaa; font-weight: 700;
}
.menu-item {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px; border-radius: 9px;
  color: #c3cede; text-decoration: none; font-weight: 600;
  transition: background .18s var(--ease), color .18s var(--ease), transform .18s var(--ease);
}
.menu-item:hover { background: rgba(255,255,255,.08); color: #fff; text-decoration: none; }
.menu-item.active {
  background: linear-gradient(90deg, var(--primary), #3a6bb8);
  color: #fff;
  box-shadow: 0 6px 16px rgba(44, 90, 160, .35);
}
.menu-item.active-soft {
  background: rgba(255,255,255,.06);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.12);
  color: #e8eef8;
}
.menu-ico {
  width: 28px; height: 28px; border-radius: 8px;
  display: grid; place-items: center;
  background: rgba(255,255,255,.06);
  font-size: 11px; font-weight: 800; letter-spacing: .02em;
  flex-shrink: 0;
}
.menu-item.active .menu-ico { background: rgba(255,255,255,.18); }
.menu-text { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.menu-text strong { font-size: 13px; font-weight: 700; }
.menu-text span { font-size: 11px; font-weight: 500; opacity: .72; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.sidebar-footer {
  margin-top: auto; padding: 14px 8px 4px;
  border-top: 1px solid rgba(255,255,255,.08);
}
.user-chip {
  display: flex; align-items: center; gap: 10px;
  padding: 8px; border-radius: 10px;
  background: rgba(255,255,255,.05);
}
.user-avatar {
  width: 34px; height: 34px; border-radius: 50%;
  display: grid; place-items: center;
  background: linear-gradient(135deg, #3a6bb8, var(--teal));
  color: #fff; font-weight: 800; font-size: 12px;
}
.user-meta { min-width: 0; flex: 1; }
.user-name { color: #fff; font-weight: 700; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { color: #9fb0cc; font-size: 11px; }
.logout-form { margin-top: 8px; }
.logout-form .btn { width: 100%; justify-content: center; }

/* ---------- Content ---------- */
.content {
  flex: 1; min-width: 0;
  padding: 24px 28px 40px;
  animation: fade-in .35s var(--ease);
}
@keyframes fade-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.top-mobile {
  display: none;
  align-items: center; justify-content: space-between;
  margin: -8px 0 16px; gap: 10px;
}
.burger {
  width: 40px; height: 40px; border-radius: 10px;
  border: 1px solid var(--border); background: #fff;
  display: grid; place-items: center; cursor: pointer;
  box-shadow: var(--shadow);
}
.burger span {
  display: block; width: 16px; height: 2px; background: var(--text); position: relative;
}
.burger span::before, .burger span::after {
  content: ""; position: absolute; left: 0; width: 16px; height: 2px; background: var(--text);
}
.burger span::before { top: -5px; }
.burger span::after { top: 5px; }

.sidebar-backdrop {
  display: none; position: fixed; inset: 0;
  background: rgba(15, 23, 42, .45); z-index: 35;
}
body.nav-open .sidebar-backdrop { display: block; }

/* ---------- Page head / hero ---------- */
.page-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  margin-bottom: 18px; flex-wrap: wrap; gap: 12px;
}
.page-head h1 { font-size: 24px; font-weight: 800; letter-spacing: -.02em; color: var(--text); }
.page-head .sub { color: var(--muted); font-size: 13px; margin-top: 4px; max-width: 560px; }
.page-head-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.hero {
  display: flex; justify-content: space-between; gap: 20px; flex-wrap: wrap;
  margin-bottom: 18px; padding: 22px 24px;
  background: linear-gradient(135deg, #1a253c 0%, #2c5aa0 68%, #0f766e 100%);
  border-radius: 16px; color: #eef4ff;
  box-shadow: var(--shadow-lg);
  position: relative; overflow: hidden;
}
.hero::after {
  content: ""; position: absolute; right: -40px; top: -40px;
  width: 180px; height: 180px; border-radius: 50%;
  background: rgba(255,255,255,.08);
  pointer-events: none;
}
.hero-kicker {
  font-size: 11px; letter-spacing: .1em; text-transform: uppercase;
  opacity: .75; margin-bottom: 6px; font-weight: 700;
}
.hero h1 { font-size: 26px; font-weight: 800; color: #fff; letter-spacing: -.02em; }
.hero-lead { margin-top: 6px; font-size: 13px; opacity: .88; max-width: 520px; line-height: 1.5; }
.hero-aside {
  display: flex; align-items: flex-end; justify-content: flex-end; gap: 10px;
  flex-wrap: wrap; margin-left: auto; position: relative; z-index: 1;
}
.hero-live {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 12px; font-weight: 600;
  background: rgba(255,255,255,.12); padding: 8px 12px; border-radius: 999px;
  border: 1px solid rgba(255,255,255,.16);
}
.hero-dot {
  width: 8px; height: 8px; border-radius: 50%; background: #4ade80;
  box-shadow: 0 0 0 3px rgba(74, 222, 128, .25);
  animation: pulse 1.8s ease infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 3px rgba(74, 222, 128, .25); }
  50% { box-shadow: 0 0 0 6px rgba(74, 222, 128, .08); }
}

/* ---------- KPI / cards ---------- */
.kpi {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px 10px; margin-bottom: 14px;
}
@media (max-width: 1300px) { .kpi { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 700px) { .kpi { grid-template-columns: repeat(2, 1fr); } }

.kpi-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 12px; box-shadow: var(--shadow);
  transition: transform .2s var(--ease), box-shadow .2s var(--ease);
}
.kpi-card:hover { transform: translateY(-2px); box-shadow: 0 8px 20px rgba(15, 23, 42, .08); }
.kpi-card.primary { border-color: #bfdbfe; background: linear-gradient(180deg, #f8fbff, #fff); }
.kpi-card.teal { border-color: #99f6e4; background: linear-gradient(180deg, #f0fdfa, #fff); }
.kpi-card.warn { border-color: #fcd34d; background: linear-gradient(180deg, #fffbeb, #fff); }
.kpi-label {
  font-size: 10px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); font-weight: 700;
}
.kpi-value { font-size: 20px; font-weight: 800; margin-top: 3px; color: var(--text); line-height: 1.1; }
.kpi-card.primary .kpi-value { color: var(--primary); }
.kpi-card.teal .kpi-value { color: var(--teal); }
.kpi-card.warn .kpi-value { color: var(--warn); }
.kpi-hint { margin-top: 4px; font-size: 10px; color: var(--muted); }

/* ---------- Panels ---------- */
.panel {
  background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow);
  border: 1px solid var(--border); padding: 14px 16px; margin-bottom: 14px;
}
.panel-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 10px; flex-wrap: wrap; margin-bottom: 14px;
}
.panel h2, .panel-head h2 {
  font-size: 15px; color: var(--text); font-weight: 700; margin: 0;
}
.panel-hint { font-size: 12px; color: var(--muted); }

/* ---------- Case card tabs ---------- */
.case-tabs {
  display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px;
}
.case-tab {
  appearance: none; border: 1px solid var(--border); background: var(--panel);
  color: var(--text); font-size: 13px; font-weight: 600; padding: 8px 14px;
  border-radius: 8px; cursor: pointer;
}
.case-tab:hover { background: #f1f5f9; }
.case-tab.active { background: #05231a; color: #fff; border-color: #05231a; }
.case-tab-panel { display: none; }
.case-tab-panel.active { display: block; }

.grid-2 { display: grid; grid-template-columns: 1.35fr 1fr; gap: 16px; }
.grid-2 > .panel { margin-bottom: 0; }
@media (max-width: 960px) { .grid-2 { grid-template-columns: 1fr; } }

.section-title {
  font-size: 12px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase;
  color: var(--muted); margin: 4px 0 10px;
}

/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; margin: 0 -4px; }
table { width: 100%; border-collapse: collapse; }
th, td {
  text-align: left; padding: 10px 12px;
  border-bottom: 1px solid var(--border); vertical-align: top;
}
th {
  background: #f8fafc; color: var(--muted); font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .04em; white-space: nowrap;
}
tbody tr { transition: background .12s; }
tbody tr:hover { background: #f8fafc; }
td.num { font-weight: 700; color: var(--primary); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.link-strong { color: var(--primary); font-weight: 700; text-decoration: none; }
.link-strong:hover { text-decoration: underline; }

/* ---------- Badges / pills ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px; border-radius: 999px;
  font-size: 11px; font-weight: 700; background: #e2e8f0; color: #475569;
  white-space: nowrap;
}
.badge.new, .badge.staging { background: #fef3c7; color: #b45309; }
.badge.classified, .badge.validated, .badge.processing {
  background: #dbeafe; color: #1d4ed8;
}
.badge.done, .badge.linked, .badge.merged, .badge.forwarded, .badge.completed {
  background: #dcfce7; color: #15803d;
}
.badge.rejected, .badge.failed, .badge.error { background: #fee2e2; color: #b91c1c; }
.badge.stale, .badge.archived { background: #e2e8f0; color: #475569; }
/* Результаты обработки задачи — зелёные (завершено), «не читается» — серый */
.badge.pid_found_attached, .badge.pid_new_attached, .badge.not_pid_return, .badge.case_clarification {
  background: #dcfce7; color: #15803d;
}
.badge.unreadable { background: #e2e8f0; color: #475569; }

/* Раздел «Логи» (admin) — подсветка строк по уровню */
.log-row-error td { background: #fef2f2; }
.log-row-warn td { background: #fffbeb; }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 11px; border-radius: 999px; font-size: 12px; font-weight: 700;
}
.pill.on { background: #dcfce7; color: #15803d; }
.pill.off { background: #fee2e2; color: #b91c1c; }

/* ---------- Forms / filters ---------- */
.toolbar {
  display: flex; gap: 10px; flex-wrap: wrap; align-items: end;
  margin-bottom: 14px;
  padding: 14px 16px;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.field { display: flex; flex-direction: column; gap: 5px; min-width: 160px; }
.field span, label.field-label {
  font-size: 11px; color: var(--muted); text-transform: uppercase;
  letter-spacing: .03em; font-weight: 700;
}
.field input, .field select, .field textarea,
input, select, textarea {
  padding: 9px 12px; border: 1px solid var(--border); border-radius: 9px;
  font-size: 14px; background: #fff; color: var(--text); font-family: inherit;
}
.field input:focus, .field select:focus, .field textarea:focus,
input:focus, select:focus, textarea:focus {
  outline: 2px solid #bfdbfe; border-color: var(--primary);
}
.form-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px; margin-bottom: 14px;
}
.form-group label {
  display: block; font-size: 12px; color: var(--muted);
  margin-bottom: 6px; font-weight: 600;
}
.form-group input, .form-group select, .form-group textarea { width: 100%; }
.form-group textarea { min-height: 88px; resize: vertical; }
.form-hint { font-size: 12px; color: var(--muted); margin-top: 5px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ---------- Buttons ---------- */
.btn, button.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 16px; border-radius: 9px; border: 1px solid var(--border);
  background: #fff; color: var(--text); font-size: 13px; font-weight: 700;
  cursor: pointer; transition: all .15s var(--ease); font-family: inherit;
  text-decoration: none; line-height: 1;
}
.btn:hover, button.btn:hover { background: #f1f5f9; text-decoration: none; }
.btn.primary, button.btn.primary {
  background: var(--primary); border-color: var(--primary); color: #fff;
}
.btn.primary:hover, button.btn.primary:hover { background: var(--primary-dark); }
.btn.teal {
  background: var(--teal); border-color: var(--teal); color: #fff;
}
/* Инверсия цветов при наведении: тёмная подложка + светлый текст (фикс «белое на белом») */
.btn.teal:hover { background: #05231a; border-color: #05231a; color: var(--teal); }
.btn.danger, button.btn.danger {
  background: var(--danger); border-color: var(--danger); color: #fff;
}
.btn.danger:hover { background: #991b1b; }
.btn.ghost {
  background: transparent; border-color: rgba(255,255,255,.28); color: #fff;
}
.btn.ghost:hover { background: rgba(255,255,255,.14); }
.btn.soft { background: var(--primary-soft); border-color: #bfdbfe; color: var(--primary-dark); }
.btn.small { padding: 6px 11px; font-size: 12px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* sidebar logout uses light ghost on dark */
.sidebar .btn {
  background: rgba(255,255,255,.06); border-color: rgba(255,255,255,.14); color: #d7e0ee;
}
.sidebar .btn:hover { background: rgba(255,255,255,.12); color: #fff; }

/* ---------- Alerts / empty ---------- */
.messages { list-style: none; margin: 0 0 14px; padding: 0; }
.messages li, .alert {
  padding: 12px 14px; border-radius: 10px; margin-bottom: 8px; font-size: 13px; font-weight: 600;
  border: 1px solid transparent;
}
.messages li, .alert.success { background: #f0fdf4; color: #15803d; border-color: #bbf7d0; }
.messages li.error, .alert.error { background: #fef2f2; color: #b91c1c; border-color: #fecaca; }
.messages li.warning, .alert.warn { background: #fefce8; color: #a16207; border-color: #fde047; }
.alert.info { background: #eff6ff; color: #1d4ed8; border-color: #bfdbfe; }

.empty {
  text-align: center; padding: 36px 16px; color: var(--muted);
  border: 1px dashed var(--border); border-radius: 12px; background: #fafbfc;
}
.empty strong { display: block; color: var(--text); font-size: 15px; margin-bottom: 4px; }

.meta dt { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; margin-top: 12px; }
.meta dd { margin: 3px 0 0; color: var(--text); font-weight: 600; }
.meta dd:first-of-type { margin-top: 0; }

.detail-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; }
@media (max-width: 960px) { .detail-grid { grid-template-columns: 1fr; } }

.payload-box, .body-box {
  margin-top: 10px; padding: 12px 14px; border-radius: 10px;
  background: #f8fafc; border: 1px solid var(--border);
  white-space: pre-wrap; font-size: 12px; line-height: 1.5;
  max-height: 320px; overflow: auto; font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
}

.htmx-indicator { display: none; color: var(--muted); font-size: 12px; font-weight: 600; }
.htmx-request .htmx-indicator, .htmx-indicator.htmx-request { display: inline; }

/* ---------- Login ---------- */
.login-page {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background:
    radial-gradient(800px 400px at 20% 0%, rgba(44,90,160,.18), transparent 55%),
    radial-gradient(700px 360px at 90% 100%, rgba(15,118,110,.16), transparent 50%),
    linear-gradient(160deg, #1a253c 0%, #243552 45%, #1a253c 100%);
}
.login-card {
  width: min(440px, 100%);
  background: rgba(255,255,255,.96);
  border-radius: 18px; padding: 28px 26px;
  box-shadow: 0 24px 60px rgba(0,0,0,.28);
  border: 1px solid rgba(255,255,255,.5);
  animation: fade-in .4s var(--ease);
}
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.login-brand .logo-mark { width: 44px; height: 44px; font-size: 16px; }
.login-card h1 { font-size: 22px; font-weight: 800; letter-spacing: -.02em; }
.login-card .lead { color: var(--muted); margin: 6px 0 18px; line-height: 1.5; }
.login-actions { display: flex; flex-direction: column; gap: 8px; }

/* ---------- Мастер импорта ---------- */
.iw-progress {
  margin: 14px 0 8px;
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--primary-soft);
  border: 1px solid #dbe7f8;
}
.iw-progress-meta {
  display: flex; justify-content: space-between; gap: 12px;
  font-size: 13px; font-weight: 600; margin-bottom: 8px;
}
.iw-progress-track {
  height: 8px; border-radius: 999px; background: #d7e4f5; overflow: hidden;
}
.iw-progress-bar {
  height: 100%; width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--primary), var(--teal));
  transition: width .25s var(--ease);
}
.iw-detect { margin: 12px 0; }
.iw-detect-card {
  padding: 12px 14px; border-radius: 10px;
  background: var(--teal-soft); border: 1px solid #cce8e4;
  line-height: 1.45;
}
.import-wizard select[data-iw-col] { min-width: 220px; width: 100%; }

.doc-list { list-style: none; padding: 0; margin: 0 0 8px; }
.doc-list li {
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px;
  margin-bottom: 6px; background: #f8fafc;
}
.btn.small { padding: 4px 10px; font-size: 12px; }

/* ---------- Суммы (как CourtWatcher finance) ---------- */
.finance-block { overflow: hidden; }
.finance-table-wrap { overflow-x: auto; }
.finance-table .finance-input {
  width: 100%; min-width: 88px; padding: 6px 8px;
  border: 1px solid var(--border); border-radius: 6px; font-size: 13px;
  font-variant-numeric: tabular-nums; text-align: right;
  background: #fff;
}
.finance-table .finance-input:focus {
  outline: 2px solid #bfdbfe; border-color: var(--primary);
}
.finance-table-matrix th.finance-row-label {
  text-align: left; white-space: normal; min-width: 140px; max-width: 200px;
  font-weight: 600; color: var(--muted); background: #f8fafc;
  position: sticky; left: 0; z-index: 1;
}
.finance-table-matrix .finance-total-row td,
.finance-table-matrix .finance-total-row th { background: #f1f5f9; }
.finance-table .finance-total {
  font-weight: 600; color: var(--text);
  font-variant-numeric: tabular-nums; text-align: right;
  padding: 8px 10px;
}
.money-input {
  font-variant-numeric: tabular-nums; text-align: right;
}

/* ---------- Role dashboards ---------- */
.dash-filters {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end;
}
.dash-filters label {
  display: flex; flex-direction: column; gap: 4px; font-size: 11px; color: #fff;
}
/* Текст выбранного периода — как подписи «Период / С / По» (белый), не muted */
.dash-filters .period-value { color: #fff; font-size: 11px; }
.dash-filters select {
  min-width: 120px; padding: 8px 10px; border: 1px solid var(--border);
  border-radius: 8px; background: #fff; color: var(--text); font: inherit;
}
.inline-rebuild { display: inline-flex; }
.dash-grid {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-top: 14px;
}
@media (max-width: 1300px) { .dash-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 700px) { .dash-grid { grid-template-columns: 1fr; } }
.dash-grid .panel { margin: 0; }
.dash-grid canvas { max-height: 190px; }
.tech-grid {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px;
}
@media (max-width: 900px) {
  .tech-grid { grid-template-columns: repeat(2, 1fr); }
}
.tech-item {
  border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px;
  background: linear-gradient(180deg, #f8fafc, #fff);
  display: flex; flex-direction: column; gap: 4px;
}
.tech-item span { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.tech-item strong { font-size: 20px; font-weight: 800; color: var(--text); }

/* ---------- Chart legend as table (dashboard) ---------- */
.chart-legend-table {
  margin-top: 10px;
  overflow-x: auto;
}
.chart-legend-table table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.chart-legend-table th,
.chart-legend-table td {
  padding: 6px 8px;
  border-top: 1px solid var(--border);
  text-align: left;
}
.chart-legend-table thead th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .03em;
  color: var(--muted);
  border-top: none;
}
.chart-legend-table tfoot td {
  border-top: 2px solid var(--border);
  background: #f8fafc;
}
.chart-legend-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.chart-swatch {
  display: inline-block;
  width: 12px; height: 12px;
  border-radius: 3px;
  vertical-align: middle;
}

/* ---------- Task workspace: документ (слева) + дело (справа) ---------- */
.task-workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(340px, 1.2fr);
  gap: 16px;
  align-items: start;
}
@media (max-width: 1100px) {
  .task-workspace { grid-template-columns: 1fr; }
}
.task-col-doc, .task-col-case { display: flex; flex-direction: column; gap: 16px; min-width: 0; }

/* Блок с документом растягивается на высоту блока «Дело и действия» слева.
   Grid-строка одна — при align-items: stretch (по умолчанию) обе колонки
   одинаковой высоты; панель документа занимает всё оставшееся место,
   окно со сканом — всю свободную высоту, плашка OCR+LLM прижата к низу. */
.task-workspace { align-items: stretch; }
.task-col-doc .task-viewer-panel {
  flex: 1 1 auto; display: flex; flex-direction: column; min-height: 0; margin-bottom: 0;
}
/* Окно со сканом растягивается на всю доступную высоту блока.
   ВАЖНО: .doc-list-panel — flex-колонка, иначе её высота = сумме содержимого
   (список + тулбар + stage 360px) и она сама диктует высоту правой колонки. */
.task-viewer-panel .doc-list-panel { display: flex; flex-direction: column; min-height: 0; }
.task-viewer-panel .doc-viewer-inline { flex: 1 1 auto; display: flex; flex-direction: column; min-height: 0; }
.task-viewer-panel .doc-viewer-inline .doc-viewer-stage {
  flex: 1 1 auto; min-height: 360px; max-height: none; overflow: hidden;
}
/* Плашка OCR + LLM прижата к низу блока.
   Кнопка не растягивается по ширине — плашка занимает только своё содержимое,
   поэтому её высота (а с ней и весь блок) не превышает левую колонку. */
.task-viewer-panel .ocr-stub { margin-top: auto; align-items: flex-start; }
.task-viewer-panel .ocr-stub > button { flex: 0 0 auto; }

/* Сведения о задаче — свёрнуты по умолчанию (details/summary) */
.task-meta-panel details { margin: 0; }
.task-meta-summary { cursor: pointer; list-style: none; user-select: none; }
.task-meta-summary::-webkit-details-marker { display: none; }
.task-meta-summary::before { content: "▸ "; color: var(--muted); }
details[open] > .task-meta-summary::before { content: "▾ "; }
.task-meta-summary h2 { display: inline; font-size: 15px; color: var(--text); font-weight: 700; margin: 0; }

.doc-tab-kind {
  display: inline-block; margin-right: 6px; padding: 1px 6px;
  border-radius: 999px; background: #e2e8f0; color: var(--muted);
  font-size: 10px; text-transform: uppercase; letter-spacing: .04em;
}

.doc-file-list {
  list-style: none; margin: 0; padding: 0;
  display: flex; flex-direction: column; gap: 8px;
}
.doc-file-item {
  display: flex; flex-wrap: wrap; gap: 10px 14px;
  align-items: center; justify-content: space-between;
  padding: 12px 14px; border: 1px solid var(--border); border-radius: 10px;
  background: linear-gradient(180deg, #f8fafc, #fff);
  transition: border-color .15s var(--ease), box-shadow .15s var(--ease);
}
.doc-file-item:hover { border-color: #bfdbfe; }
.doc-file-item.is-active {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(44, 90, 160, .12);
}
.doc-file-meta {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 8px;
  min-width: 0; flex: 1;
}
.doc-file-name { font-size: 14px; word-break: break-word; }
.doc-file-actions { display: flex; flex-wrap: wrap; gap: 6px; }

/* Модальное окно просмотра S3 */
body.doc-modal-open { overflow: hidden; }
.doc-modal[hidden] { display: none !important; }
.doc-modal {
  position: fixed; inset: 0; z-index: 80;
  display: flex; align-items: stretch; justify-content: center;
  padding: 18px;
  animation: fade-in .2s var(--ease);
}
.doc-modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(15, 23, 42, .62);
  backdrop-filter: blur(2px);
}
.doc-modal-dialog {
  position: relative; z-index: 1;
  width: min(1180px, 100%);
  max-height: calc(100vh - 36px);
  display: flex; flex-direction: column;
  background: #fff; border-radius: 14px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: fade-in .28s var(--ease);
}
.doc-modal-head {
  display: flex; flex-wrap: wrap; gap: 10px 16px;
  align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #f8fafc, #fff);
}
.doc-modal-head h2 {
  font-size: 16px; font-weight: 800; letter-spacing: -.01em;
  max-width: min(560px, 70vw); word-break: break-word;
}
.doc-modal-actions { display: flex; flex-wrap: wrap; gap: 6px; }

/* Панель листания многостраничных сканов (PDF / TIFF) */
.doc-pager {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  padding: 8px 14px; border-bottom: 1px solid var(--border);
  background: #f1f5f9;
}
.doc-pager[hidden] { display: none !important; }
.doc-pager-label, .doc-pager-zoom {
  font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums;
  min-width: 5.5em; text-align: center;
}
.doc-pager-sep {
  width: 1px; height: 22px; background: var(--border); margin: 0 4px;
}
.doc-pager-hint { margin-left: auto; }

.doc-viewer {
  border: 1px solid var(--border); border-radius: 12px; overflow: hidden;
  background: #0f172a;
}
.doc-viewer-modal {
  border: 0; border-radius: 0; flex: 1; min-height: 0;
  display: flex; flex-direction: column;
}
.doc-viewer-stage {
  min-height: 420px; max-height: min(70vh, 760px);
  background: #111827; display: flex; flex-direction: column;
}
.doc-viewer-modal .doc-viewer-stage {
  min-height: 0; max-height: none; flex: 1;
  height: calc(100vh - 180px);
}
/* Встроенный (inline) просмотрщик скана в карточке задачи */
.doc-viewer-inline { margin-top: 12px; }
.doc-viewer-inline .doc-viewer-stage { min-height: 360px; max-height: 70vh; }
.doc-toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 10px; }
.doc-viewer-empty {
  margin: auto; padding: 28px 18px; text-align: center; color: #cbd5e1; line-height: 1.5;
}
.doc-viewer-empty strong { display: block; color: #f8fafc; margin-bottom: 6px; }
.doc-frame {
  width: 100%; height: min(70vh, 760px); border: 0; background: #525659;
}
.doc-viewer-modal .doc-frame {
  height: 100%; min-height: 420px;
}
.doc-page-scroll {
  flex: 1; overflow: auto; min-height: 0;
  display: flex; justify-content: center; padding: 12px;
  background: #111827;
}
.doc-page-host {
  display: flex; justify-content: center; align-items: flex-start;
}
/* PDF.js: canvas + поверх текстовый слой (выделение/копирование) */
.doc-pdf-page {
  position: relative;
  box-shadow: 0 8px 24px rgba(0,0,0,.35);
  background: #fff;
}
.doc-pdf-canvas { display: block; }
.doc-pdf-textlayer {
  position: absolute; inset: 0; overflow: hidden;
  opacity: 0.25; line-height: 1;
  pointer-events: auto;
}
.doc-pdf-textlayer span,
.doc-pdf-textlayer br {
  color: transparent; position: absolute; white-space: pre;
  cursor: text; transform-origin: 0% 0%;
}
.doc-pdf-textlayer ::selection { background: rgba(0, 100, 255, 0.35); }

.doc-image-wrap {
  overflow: auto; flex: 1; display: flex; flex-direction: column;
  align-items: center; padding: 12px; gap: 8px;
}
.doc-image, .doc-tiff-canvas {
  max-width: 100%; height: auto; border-radius: 4px;
  box-shadow: 0 8px 24px rgba(0,0,0,.35); background: #fff;
}

.ocr-stub {
  margin-top: 12px; padding: 12px 14px; border-radius: 10px;
  border: 1px dashed #cbd5e1; background: #f8fafc;
  display: flex; gap: 12px; align-items: center; justify-content: space-between;
  flex-wrap: wrap;
}
.ocr-stub-on { border-color: #99f6e4; background: var(--teal-soft); }
.ocr-stub-text { display: flex; flex-direction: column; gap: 2px; min-width: 200px; flex: 1; }
.ocr-stub-text strong { font-size: 13px; }
.ocr-stub-text span { color: var(--muted); font-size: 12px; line-height: 1.45; }

.create-case-box {
  margin-top: 4px; padding: 12px 14px; border-radius: 12px;
  border: 1px solid var(--border); background: #fafbfc;
}
.create-case-box-hl {
  border-color: #fcd34d; background: #fffbeb;
  box-shadow: 0 0 0 3px rgba(251, 191, 36, .18);
}

.task-meta-details summary { font-weight: 700; }

/* ---------- Mobile ---------- */
@media (max-width: 900px) {
  .sidebar {
    position: fixed; left: 0; top: 0;
    transform: translateX(-105%);
    transition: transform .28s var(--ease);
  }
  body.nav-open .sidebar { transform: none; }
  .top-mobile { display: flex; }
  .content { padding: 16px 14px 32px; }
  .hero h1 { font-size: 22px; }
  .doc-modal { padding: 8px; }
  .doc-modal-dialog { max-height: calc(100vh - 16px); }
  .doc-viewer-modal .doc-viewer-stage { height: calc(100vh - 160px); }
  .doc-viewer-stage, .doc-frame { min-height: 240px; }
  .doc-file-actions { width: 100%; }
  .doc-file-actions .btn { flex: 1; }
}
