/* ============================================================
   Legal Operations — Compact Design System
   ============================================================ */

/* 1. TOKENS */
:root {
  --bg: #f5f6f7;
  --panel: #ffffff;
  --border: #e1e4e8;
  --border-strong: #c9cdd2;
  --text: #1a1a1a;
  --text-muted: #6b7280;
  --text-faint: #9ca3af;
  --brand: #0f766e;
  --brand-dark: #0a5a54;
  --brand-bg: #f0fdf9;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --warning: #d97706;
  --warning-bg: #fffbeb;
  --success: #059669;
  --success-bg: #f0fdf4;
  --radius: 4px;
  --fs: 13px;
  --container: 1280px;
}

/* 2. RESET + BASE */
*, *::before, *::after { box-sizing: border-box; }

html {
  font-size: var(--fs);
  color-scheme: light;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  line-height: 1.4;
  min-width: 320px;
}

a { color: inherit; text-decoration: none; }
a:hover { color: var(--brand); }
img { max-width: 100%; }
button, input, select, textarea { font: inherit; }
button { border: 0; cursor: pointer; }
p { margin: 0; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; }

/* 3. LAYOUT */
.page-wrap {
  max-width: var(--container);
  margin: 0 auto;
  padding: 12px 16px 32px;
}

.page-wrap--auth {
  max-width: 100%;
  padding: 0;
}

/* 4. TOPBAR */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  height: 40px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.topbar__inner {
  max-width: var(--container);
  margin: 0 auto;
  padding: 0 16px;
  height: 100%;
  display: flex;
  align-items: center;
  gap: 16px;
}

.topbar__brand {
  font-weight: 700;
  font-size: 13px;
  color: var(--brand);
  white-space: nowrap;
  letter-spacing: -0.01em;
}

.topbar__nav {
  display: flex;
  align-items: center;
  gap: 2px;
}

.topbar__spacer { flex: 1; }

.topbar__link {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: var(--radius);
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  transition: background 0.1s, color 0.1s;
}

.topbar__link:hover {
  background: var(--bg);
  color: var(--text);
}

.topbar__link--active {
  background: var(--brand-bg);
  color: var(--brand);
}

.topbar__user {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  padding: 0 6px;
}

/* 5. ALERTS */
.alert {
  padding: 8px 12px;
  border-radius: var(--radius);
  font-size: 12px;
  border: 1px solid transparent;
  margin-bottom: 10px;
}

.alert--success {
  background: var(--success-bg);
  border-color: #a7f3d0;
  color: #065f46;
}

.alert--error {
  background: var(--danger-bg);
  border-color: #fecaca;
  color: #991b1b;
}

.alert--warning {
  background: var(--warning-bg);
  border-color: #fde68a;
  color: #92400e;
}

.customer-edit-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(320px, 0.9fr);
  gap: 16px;
  align-items: start;
}

.customer-edit-layout__main,
.customer-edit-layout__side {
  min-width: 0;
}

.customer-edit-layout__side {
  display: grid;
  gap: 12px;
}

.customer-side-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
}

.customer-contact-list {
  display: grid;
  gap: 8px;
}

.customer-contact-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  background: #fcfcfd;
}

.customer-contact-card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}

.customer-contact-card__actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.customer-contact-card__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  color: var(--text-muted);
  font-size: 12px;
}

.customer-checkbox {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
}

.customer-checkbox input {
  margin: 0;
}

.text-muted {
  color: var(--text-muted);
}

/* 6. TOOLBAR */
.toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.toolbar__spacer { flex: 1; }

.toolbar__title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

/* 7. BUTTONS */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  height: 28px;
  padding: 0 12px;
  font-size: 12px;
  font-weight: 500;
  border-radius: var(--radius);
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.1s, border-color 0.1s, opacity 0.1s;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  text-decoration: none;
}

.btn:hover {
  background: var(--bg);
  color: var(--text);
}

.btn--primary {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

.btn--primary:hover {
  background: var(--brand-dark);
  border-color: var(--brand-dark);
  color: #fff;
}

.btn--danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.btn--danger:hover {
  background: #b91c1c;
  border-color: #b91c1c;
  color: #fff;
}

.btn--ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text-muted);
}

.btn--ghost:hover {
  background: var(--bg);
  color: var(--text);
}

.btn--sm {
  height: 24px;
  padding: 0 8px;
  font-size: 11px;
}

.btn--full { width: 100%; }

/* 8. PILLS / BADGES */
.pill {
  display: inline-block;
  padding: 1px 7px;
  font-size: 11px;
  font-weight: 500;
  border-radius: 999px;
  white-space: nowrap;
  line-height: 18px;
}

/* Status pills */
.pill--new      { background: #f3f4f6; color: #374151; border: 1px solid #d1d5db; }
.pill--taken    { background: #eff6ff; color: #1d4ed8; border: 1px solid #bfdbfe; }
.pill--in_work  { background: var(--brand-bg); color: var(--brand); border: 1px solid #99f6e4; }
.pill--returned { background: var(--warning-bg); color: var(--warning); border: 1px solid #fde68a; }
.pill--closed   { background: #f9fafb; color: var(--text-faint); border: 1px solid var(--border); }

/* Priority pills */
.pill--high   { background: var(--danger-bg); color: var(--danger); border: 1px solid #fecaca; }
.pill--medium { background: var(--warning-bg); color: var(--warning); border: 1px solid #fde68a; }
.pill--low    { background: #f9fafb; color: var(--text-faint); border: 1px solid var(--border); }

/* Deadline pills */
.pill--danger  { background: var(--danger-bg); color: var(--danger); border: 1px solid #fecaca; }
.pill--warning { background: var(--warning-bg); color: var(--warning); border: 1px solid #fde68a; }
.pill--success { background: var(--success-bg); color: var(--success); border: 1px solid #a7f3d0; }
.pill--muted   { background: #f3f4f6; color: var(--text-muted); border: 1px solid var(--border); }

/* 9. STAT CHIPS */
.stat-chips {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 12px;
  color: var(--text-muted);
  flex-wrap: wrap;
}

.stat-chip strong {
  color: var(--text);
  font-weight: 600;
}

.stat-chip--danger strong { color: var(--danger); }
.stat-chip--warning strong { color: var(--warning); }

/* 10. QUICK FILTERS */
.qfilters {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.qfilter {
  display: inline-flex;
  align-items: center;
  height: 24px;
  padding: 0 10px;
  font-size: 11px;
  font-weight: 500;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text-muted);
  cursor: pointer;
  text-decoration: none;
  transition: background 0.1s, color 0.1s, border-color 0.1s;
  white-space: nowrap;
}

.qfilter:hover {
  background: var(--bg);
  color: var(--text);
}

.qfilter--active {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

.qfilter--active:hover {
  background: var(--brand-dark);
  color: #fff;
}

/* 11. FILTER ROW */
.filter-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 10px;
}

.filter-row input,
.filter-row select {
  height: 28px;
  padding: 0 8px;
  font-size: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  outline: none;
}

.filter-row input:focus,
.filter-row select:focus {
  border-color: var(--brand);
}

.filter-row input { min-width: 180px; }
.filter-row select { min-width: 120px; }

/* 12. ATTENTION BAR */
.attention-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  padding: 6px 10px;
  background: var(--warning-bg);
  border: 1px solid #fde68a;
  border-radius: var(--radius);
  font-size: 12px;
  margin-bottom: 10px;
}

.attention-bar__label {
  color: var(--warning);
  font-weight: 600;
  white-space: nowrap;
}

.attention-tag {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
  text-decoration: none;
  transition: opacity 0.1s;
}

.attention-tag:hover { opacity: 0.8; }
.attention-tag--danger  { background: var(--danger-bg); color: var(--danger); border: 1px solid #fecaca; }
.attention-tag--warning { background: var(--warning-bg); color: var(--warning); border: 1px solid #fde68a; }
.attention-tag--muted   { background: #f3f4f6; color: var(--text-muted); border: 1px solid var(--border); }

/* 13. CASES TABLE */
.cases-table-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--panel);
}

.cases-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.cases-table th {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
  background: #fafbfc;
  text-align: left;
  white-space: nowrap;
}

.cases-table td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.cases-table tbody tr:last-child td { border-bottom: none; }

.cases-table tbody tr:hover td { background: #f9fafb; }

.cases-table tbody tr { transition: background 0.08s; }

/* Deadline row highlights */
.cases-table__row--overdue td:first-child { border-left: 3px solid var(--danger); }
.cases-table__row--today   td:first-child { border-left: 3px solid var(--warning); }
.cases-table__row--soon    td:first-child { border-left: 3px solid #fbbf24; }

.cases-table__num {
  font-family: "Courier New", monospace;
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
}

.cases-table__title-link {
  font-weight: 500;
  color: var(--text);
  display: block;
}

.cases-table__title-link:hover { color: var(--brand); }

.cases-table__sub {
  font-size: 11px;
  color: var(--text-faint);
}

.cases-table td.text-danger { color: var(--danger); font-weight: 500; }
.cases-table td.text-warning { color: var(--warning); }

/* 14. COMPACT CASE CARDS (юрист — свободные дела) */
.case-cards { display: flex; flex-direction: column; gap: 4px; }

.case-card {
  display: block;
  padding: 8px 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text);
  transition: border-color 0.1s, box-shadow 0.1s;
}

.case-card:hover {
  border-color: var(--brand);
  color: var(--text);
}

.case-card--overdue { border-left: 3px solid var(--danger); }
.case-card--today   { border-left: 3px solid var(--warning); }
.case-card--soon    { border-left: 3px solid #fbbf24; }

.case-card__header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 2px;
}

.case-card__num {
  font-family: "Courier New", monospace;
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.case-card__title {
  font-weight: 500;
  font-size: 13px;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.case-card__badges {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.case-card__meta {
  font-size: 11px;
  color: var(--text-muted);
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

/* 15. SECTION DIVIDER */
.section-divider {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 14px 0 8px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.section-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* 16. SPLIT LAYOUT (карточка дела) */
.case-breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 0 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0;
  font-size: 12px;
  color: var(--text-muted);
  flex-wrap: wrap;
}

.case-breadcrumb__title {
  font-weight: 600;
  color: var(--text);
  font-size: 13px;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.case-breadcrumb__sep { color: var(--border-strong); }

.split-layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 0;
  height: calc(100vh - 40px - 43px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--panel);
  margin-top: 8px;
}

.split-layout__aside {
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 12px;
  background: #fafbfc;
}

.split-layout__main {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--panel);
}

.split-layout__tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  padding: 0 12px;
  flex-shrink: 0;
  background: #fafbfc;
}

.split-layout__tab-content {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}

.split-layout__tab-content--docs {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.split-layout__footer {
  border-top: 1px solid var(--border);
  padding: 8px 12px;
  flex-shrink: 0;
  background: var(--panel);
}

/* 17. TABS */
.tab-link {
  display: inline-block;
  padding: 8px 12px;
  font-size: 12px;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  white-space: nowrap;
  transition: color 0.1s;
  text-decoration: none;
}

.tab-link:hover { color: var(--text); }

.tab-link--active {
  color: var(--brand);
  border-bottom-color: var(--brand);
  font-weight: 500;
}

/* 18. META DL (левая панель) */
.section-title {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  margin: 12px 0 6px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
}

.section-title:first-child { margin-top: 0; }

.meta-dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 5px 10px;
  font-size: 12px;
  align-items: baseline;
}

.meta-dl dt {
  color: var(--text-muted);
  white-space: nowrap;
  font-weight: 400;
}

.meta-dl dd {
  margin: 0;
  font-weight: 500;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
}

.aside-description {
  font-size: 12px;
  line-height: 1.55;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
  margin-bottom: 10px;
}

/* 19. ASIDE ACTION FORMS */
.aside-form { margin-top: 8px; }

.aside-form + .aside-form { margin-top: 6px; }

.aside-select-row {
  display: flex;
  gap: 4px;
  align-items: center;
}

.aside-select-row select {
  flex: 1;
  height: 28px;
  padding: 0 6px;
  font-size: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  outline: none;
}

.aside-select-row select:focus { border-color: var(--brand); }

.aside-actions {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 6px;
}

.aside-form--stack {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.aside-select,
.aside-input,
.aside-textarea,
.aside-multiselect {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  font-size: 12px;
  outline: none;
}

.aside-select,
.aside-input {
  height: 28px;
  padding: 0 6px;
}

.aside-textarea,
.aside-multiselect {
  padding: 6px;
}

.aside-multiselect {
  min-height: 90px;
}

.aside-select:focus,
.aside-input:focus,
.aside-textarea:focus,
.aside-multiselect:focus {
  border-color: var(--brand);
}

.aside-note {
  font-size: 11px;
  line-height: 1.45;
  color: var(--text-muted);
}

body.modal-open {
  overflow: hidden;
}

.confirm-modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.confirm-modal[hidden] {
  display: none !important;
}

.confirm-modal__dialog {
  width: min(640px, 100%);
  max-height: calc(100vh - 40px);
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 6px);
  box-shadow: 0 24px 64px rgba(15, 23, 42, 0.22);
  padding: 18px;
}

.confirm-modal__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.confirm-modal__header .section-title {
  margin-bottom: 0;
}

.confirm-modal__eyebrow {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.confirm-modal__close {
  width: 28px;
  height: 28px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
}

.confirm-modal__close:hover {
  background: var(--panel);
  color: var(--text);
}

.confirm-modal__text {
  margin-top: 12px;
  font-size: 13px;
  color: var(--text);
  line-height: 1.5;
}

.confirm-summary {
  margin-top: 16px;
  display: grid;
  grid-template-columns: 140px minmax(0, 1fr);
  gap: 10px 14px;
  align-items: start;
}

.confirm-summary dt {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.confirm-summary dd {
  margin: 0;
  font-size: 13px;
  color: var(--text);
  line-height: 1.5;
  word-break: break-word;
}

.confirm-summary__message {
  white-space: pre-wrap;
}

.confirm-summary__attachments {
  margin: 0;
  padding-left: 18px;
  display: grid;
  gap: 4px;
}

.confirm-modal__actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}

/* 20. TIMELINE */
.timeline { padding: 0; margin: 0; }

.timeline-item {
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  line-height: 1.5;
}

.timeline-item:last-child { border-bottom: none; }

.timeline-item__meta {
  color: var(--text-muted);
  font-size: 11px;
  margin-bottom: 2px;
}

/* 21. DOCUMENT LIST */
.doc-upload-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.doc-upload-row select {
  height: 28px;
  padding: 0 8px;
  font-size: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  min-width: 140px;
}

.doc-upload-row input[type="file"] {
  font-size: 12px;
  flex: 1;
  min-width: 0;
}

.docs-workspace {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
}

.docs-workspace--with-preview {
  display: flex;
  flex-direction: column;
}

.docs-workspace__list,
.docs-workspace__preview {
  min-width: 0;
}

.docs-workspace--with-preview .docs-workspace__list {
  max-height: none;
  overflow: visible;
  padding-right: 0;
}

.doc-groups { display: flex; flex-direction: column; gap: 12px; }

.doc-group__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 0;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}

.doc-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.doc-archive {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.doc-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 12px;
  background: var(--panel);
}

.doc-row--active { border-color: var(--brand); background: var(--brand-bg); }

.doc-row__name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
}

.doc-row__meta {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
}

.doc-row--archived {
  background: #f8fafb;
  border-color: #e5e7eb;
}

.doc-row__tag {
  display: inline-flex;
  align-items: center;
  margin-left: 8px;
  padding: 1px 6px;
  border-radius: 999px;
  background: #eef2f7;
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 600;
  white-space: nowrap;
}

.doc-row__actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.doc-type-form {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.doc-type-form select {
  height: 24px;
  padding: 0 4px;
  font-size: 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  max-width: 120px;
}

.doc-preview-wrap {
  margin-top: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--panel);
}

.docs-workspace--with-preview .doc-preview-wrap {
  margin-top: 12px;
  position: static;
}

.doc-preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  background: #fafbfc;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}

.doc-preview-header__name {
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.doc-preview-header__actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.doc-preview {
  width: 100%;
  height: clamp(960px, 138vh, 1500px);
  border: none;
  display: block;
  background: #fff;
}

.doc-preview--image {
  height: clamp(960px, 138vh, 1500px);
  max-height: none;
  object-fit: contain;
  background: #f6f7f8;
}

/* 22. FORMS */
.form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.form-grid {
  display: grid;
  gap: 12px;
}

.form-grid--two {
  grid-template-columns: 1fr 1fr;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
}

.field input,
.field select {
  height: 28px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  font-size: 13px;
  outline: none;
  width: 100%;
}

.field textarea {
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  font-size: 13px;
  outline: none;
  resize: vertical;
  min-height: 80px;
  width: 100%;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--brand);
}

.form-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}

/* 23. AUTH PAGE */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 340px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 28px 28px 24px;
}

.auth-card__logo {
  font-weight: 700;
  font-size: 15px;
  color: var(--brand);
  margin-bottom: 20px;
  display: block;
}

.auth-card__title {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--text);
}

.auth-card__hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.auth-card__link {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 12px;
  text-align: center;
}

.auth-card__link:hover { color: var(--brand); }

.auth-error {
  padding: 7px 10px;
  background: var(--danger-bg);
  border: 1px solid #fecaca;
  border-radius: var(--radius);
  font-size: 12px;
  color: #991b1b;
  margin-bottom: 12px;
}

/* 24. ADMIN TABLE */
.admin-table-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--panel);
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.admin-table th {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
  background: #fafbfc;
  text-align: left;
  white-space: nowrap;
}

.admin-table td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  font-size: 12px;
}

.admin-table tbody tr:last-child td { border-bottom: none; }
.admin-table tbody tr:hover td { background: #f9fafb; }

.admin-table__actions {
  display: flex;
  gap: 4px;
  align-items: center;
}

/* 25. EMPTY STATE */
.empty {
  text-align: center;
  color: var(--text-muted);
  padding: 28px 16px;
  font-size: 12px;
}

/* 26. PAGE HEADER (для форм) */
.page-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.page-header__title {
  font-size: 14px;
  font-weight: 600;
}

.form-wrap {
  max-width: 660px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.maintenance-panel {
  margin-bottom: 16px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.admin-tabs {
  display: flex;
  gap: 4px;
  padding: 0 0 10px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.maintenance-panel__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.maintenance-panel__title {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 4px;
}

.maintenance-panel__hint {
  font-size: 12px;
  color: var(--text-muted);
  max-width: 720px;
}

.maintenance-status {
  display: inline-flex;
  align-items: center;
  height: 24px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.maintenance-status--enabled {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid #fecaca;
}

.maintenance-status--disabled {
  background: var(--success-bg);
  color: var(--success);
  border: 1px solid #a7f3d0;
}

.maintenance-panel__actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.maintenance-panel__disable-form {
  margin-top: 8px;
}

/* 27. USER STATUS */
.user-status--active   { color: var(--success); font-weight: 500; font-size: 12px; }
.user-status--blocked  { color: var(--text-faint); font-weight: 500; font-size: 12px; }

/* 28. RESPONSIVE */

/* Desktop/tablet utility classes */
.desktop-only { display: block; }
.mobile-only  { display: none !important; }

/* ── 900px: планшет горизонтально ── */
@media (max-width: 900px) {
  .split-layout {
    grid-template-columns: 1fr;
    height: auto;
    overflow: visible;
  }

  .split-layout__aside {
    border-right: none;
    border-bottom: 1px solid var(--border);
    overflow-y: visible;
  }

  .split-layout__main {
    overflow: visible;
  }

  .split-layout__tab-content {
    overflow: visible;
  }

  .docs-workspace--with-preview {
    grid-template-columns: 1fr;
  }

  .docs-workspace--with-preview .docs-workspace__list {
    max-height: none;
    overflow: visible;
    padding-right: 0;
  }

  .docs-workspace--with-preview .doc-preview-wrap {
    position: static;
  }

  .doc-preview,
  .doc-preview--image {
    height: 72vh;
    min-height: 520px;
  }

  .split-layout__footer {
    position: sticky;
    bottom: 0;
    background: var(--panel);
    z-index: 10;
    border-top: 1px solid var(--border);
  }

  .form-grid--two {
    grid-template-columns: 1fr;
  }

  .customer-edit-layout {
    grid-template-columns: 1fr;
  }
}

/* ── 640px: планшет вертикально / большой телефон ── */
@media (max-width: 640px) {
  /* Топбар */
  .topbar { height: auto; min-height: 40px; }
  .topbar__inner { flex-wrap: wrap; gap: 4px; padding: 4px 12px; }

  /* Таблица дел — скрыть, показать карточки */
  .desktop-only { display: none !important; }
  .mobile-only  { display: block !important; }

  /* Таблица — оставить только самое важное если всё же показана */
  .cases-table th:nth-child(3),
  .cases-table td:nth-child(3) { display: none; }
  .cases-table th:nth-child(4),
  .cases-table td:nth-child(4) { display: none; }
  .cases-table th:nth-child(6),
  .cases-table td:nth-child(6) { display: none; }

  /* Кнопки — touch-friendly */
  .btn     { height: 40px; padding: 0 14px; font-size: 13px; }
  .btn--sm { height: 32px; padding: 0 10px; font-size: 12px; }
  .qfilter { height: 32px; padding: 0 12px; font-size: 12px; line-height: 32px; }

  /* Фильтры */
  .filter-row { flex-direction: column; align-items: stretch; gap: 8px; }
  .filter-row input,
  .filter-row select { width: 100%; min-width: unset; }
  .filter-row .btn { width: 100%; justify-content: center; }

  /* Фильтры — collapsible */
  .filter-collapsible { display: none; }
  .filter-toggle-cb:checked ~ .filter-collapsible { display: block; }

  /* Admin таблица — скрыть email и телефон */
  .admin-table th:nth-child(2),
  .admin-table td:nth-child(2),
  .admin-table th:nth-child(3),
  .admin-table td:nth-child(3) { display: none; }

  .admin-table__actions { flex-wrap: wrap; gap: 6px; }
  .admin-table__actions > form { width: 100%; }
  .admin-table__actions input[type="text"] { width: 100% !important; }

  /* Stat chips — уменьшить gap */
  .stat-chips { gap: 10px; }

  /* Page wrap */
  .page-wrap { padding: 8px 12px 24px; }

  /* Breadcrumb */
  .case-breadcrumb { flex-wrap: wrap; gap: 4px; }

  .doc-preview-header {
    flex-wrap: wrap;
    gap: 8px;
  }

  .doc-preview-header__actions {
    width: 100%;
    justify-content: flex-start;
  }

  .doc-preview,
  .doc-preview--image {
    height: 68vh;
    min-height: 420px;
  }

  .maintenance-panel__header,
  .maintenance-panel__actions { flex-direction: column; align-items: stretch; }
}

/* ── 480px: телефон ── */
@media (max-width: 480px) {
  /* Скрыть имя пользователя в топбаре */
  .topbar__user { display: none; }

  /* Auth карточка */
  .auth-card { padding: 20px 16px; }

  /* Документы — перенос кнопок */
  .doc-row { flex-wrap: wrap; gap: 6px; }
  .doc-row__name { width: 100%; margin-bottom: 2px; }
  .doc-row__meta { width: 100%; }
  .doc-row__actions { width: 100%; justify-content: flex-start; }
  .doc-type-form { width: 100%; }
  .doc-type-form form { display: flex; gap: 4px; width: 100%; }
  .doc-type-form select { flex: 1; }

  /* Breadcrumb — компактнее */
  .case-breadcrumb__title { font-size: 12px; }

  /* Внимание-бар */
  .attention-bar { flex-direction: column; align-items: flex-start; }

  /* Aside actions — полная ширина */
  .aside-actions .btn { width: 100%; justify-content: center; }
  .aside-select-row select { font-size: 13px; }
  .confirm-summary {
    grid-template-columns: 1fr;
    gap: 6px;
  }
  .confirm-modal__actions {
    flex-direction: column-reverse;
  }
  .confirm-modal__actions .btn {
    width: 100%;
  }
}

/* ── Скрытый чекбокс для toggle фильтров ── */
.filter-toggle-cb { display: none; }
