:root {
    --bg: #f6f7fb;
    --surface: #ffffff;
    --surface-soft: #f8fafc;
    --surface-muted: #f1f5f9;
    --text: #111827;
    --text-soft: #334155;
    --secondary: #334155;
    --muted: #64748b;
    --line: #e2e8f0;
    --line-strong: #cbd5e1;
    --brand: #2563eb;
    --brand-strong: #1d4ed8;
    --brand-soft: #eff6ff;
    --nav: #0f172a;
    --nav-soft: #1e293b;
    --danger: #dc2626;
    --danger-soft: #fef2f2;
    --success: #16a34a;
    --success-soft: #f0fdf4;
    --warning: #d97706;
    --warning-soft: #fffbeb;
    --radius: 10px;
    --radius-sm: 8px;
    --shadow: 0 16px 40px rgba(15, 23, 42, .06);
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, .08);
}

* {
    box-sizing: border-box;
}

html,
body {
    min-height: 100%;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
    letter-spacing: 0;
}

a {
    color: var(--brand);
    text-decoration: none;
}

a:hover {
    color: var(--brand-strong);
}

h1,
h2,
h3,
p {
    margin-top: 0;
}

h1 {
    margin-bottom: 6px;
    font-size: 24px;
    line-height: 1.18;
    letter-spacing: 0;
}

h2 {
    margin-bottom: 6px;
    font-size: 18px;
    line-height: 1.25;
    letter-spacing: 0;
}

h3 {
    margin-bottom: 0;
    font-size: 16px;
    line-height: 1.3;
    letter-spacing: 0;
}

p,
small,
.muted {
    color: var(--muted);
}

button,
.button {
    min-height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: 1px solid var(--brand);
    border-radius: var(--radius-sm);
    padding: 8px 14px;
    background: var(--brand);
    color: #fff;
    cursor: pointer;
    font: inherit;
    font-weight: 750;
    line-height: 1.1;
    white-space: nowrap;
    box-shadow: var(--shadow-sm);
}

button:hover,
.button:hover {
    background: var(--brand-strong);
    border-color: var(--brand-strong);
    color: #fff;
}

button:focus-visible,
.button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
a:focus-visible {
    outline: 3px solid rgba(37, 99, 235, .18);
    outline-offset: 2px;
}

.button.secondary {
    background: #fff;
    border-color: var(--line-strong);
    color: var(--text-soft);
    box-shadow: none;
}

.button.secondary:hover {
    background: var(--surface-soft);
    border-color: #94a3b8;
    color: var(--text);
}

.small-button {
    min-height: 32px;
    padding: 6px 10px;
    font-size: 13px;
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    padding: 10px 11px;
    background: #fff;
    color: var(--text);
    font: inherit;
}

textarea {
    resize: vertical;
}

label {
    display: grid;
    gap: 6px;
    min-width: 0;
    margin: 0;
    color: #475569;
    font-size: 12px;
    font-weight: 800;
}

.ui-kicker,
.eyebrow,
.section-label {
    display: inline-flex;
    color: var(--muted);
    font-size: 11px;
    font-weight: 850;
    letter-spacing: .04em;
    text-transform: uppercase;
}

.app-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 248px minmax(0, 1fr);
}

.app-sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    gap: 18px;
    padding: 18px 14px;
    background: var(--nav);
    color: #fff;
}

.sidebar-brand {
    min-height: 50px;
    display: grid;
    grid-template-columns: 42px minmax(0, 1fr);
    gap: 12px;
    align-items: center;
    color: #fff;
}

.sidebar-brand:hover {
    color: #fff;
}

.brand-mark {
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    border-radius: var(--radius-sm);
    background: var(--brand);
    color: #fff;
    font-weight: 900;
}

.brand-copy {
    min-width: 0;
    display: grid;
    gap: 2px;
}

.brand-copy strong {
    overflow: hidden;
    font-size: 15px;
    line-height: 1.15;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.brand-copy small {
    color: #94a3b8;
}

.sidebar-nav {
    display: grid;
    gap: 6px;
}

.sidebar-nav a {
    min-height: 42px;
    display: flex;
    align-items: center;
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    color: #cbd5e1;
    font-weight: 780;
}

.sidebar-nav a:hover {
    background: var(--nav-soft);
    color: #fff;
}

.sidebar-nav a.active {
    background: #fff;
    color: var(--text);
}

.sidebar-metric {
    display: grid;
    gap: 4px;
    border: 1px solid rgba(255, 255, 255, .12);
    border-radius: var(--radius);
    padding: 14px;
    background: rgba(255, 255, 255, .05);
}

.sidebar-metric span {
    color: #94a3b8;
    font-size: 11px;
    font-weight: 850;
    text-transform: uppercase;
}

.sidebar-metric strong {
    font-size: 30px;
    line-height: 1;
}

.sidebar-metric small {
    color: #cbd5e1;
}

.sidebar-logout {
    min-height: 40px;
    display: flex;
    align-items: center;
    margin-top: auto;
    border-radius: var(--radius-sm);
    padding: 9px 12px;
    color: #cbd5e1;
    font-weight: 780;
}

.sidebar-logout:hover {
    background: var(--nav-soft);
    color: #fff;
}

.app-workspace {
    min-width: 0;
}

.app-topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    min-height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    border-bottom: 1px solid var(--line);
    padding: 0 28px;
    background: rgba(255, 255, 255, .92);
    backdrop-filter: blur(12px);
}

.app-topbar strong {
    display: block;
    font-size: 18px;
    line-height: 1.2;
}

.top-user {
    display: grid;
    justify-items: end;
    line-height: 1.2;
}

.top-user span {
    font-weight: 820;
}

.top-user small {
    color: var(--muted);
}

.page {
    width: 100%;
    max-width: 1600px;
    margin: 0 auto;
    padding: 24px 28px 36px;
}

.surface,
.panel {
    min-width: 0;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow);
}

.surface,
.panel {
    padding: 18px;
}

.dashboard-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 16px;
}

.dashboard-header p {
    max-width: 680px;
    margin-bottom: 0;
}

.dashboard-total {
    min-width: 140px;
    display: grid;
    gap: 3px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 13px 16px;
    background: #fff;
    box-shadow: var(--shadow-sm);
}

.dashboard-total span {
    color: var(--muted);
    font-size: 11px;
    font-weight: 850;
    text-transform: uppercase;
}

.dashboard-total strong {
    font-size: 30px;
    line-height: 1;
}

.status-overview {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(154px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.status-metric {
    min-height: 86px;
    display: grid;
    align-content: space-between;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 13px 14px;
    background: #fff;
    box-shadow: var(--shadow-sm);
    position: relative;
    overflow: hidden;
}

.status-metric::before {
    content: "";
    position: absolute;
    inset: 0 auto 0 0;
    width: 4px;
    background: #94a3b8;
}

.status-metric span {
    color: #475569;
    font-size: 11px;
    font-weight: 850;
    line-height: 1.2;
    text-transform: uppercase;
}

.status-metric strong {
    color: #0f172a;
    font-size: 29px;
    line-height: 1;
}

.metric-registered::before { background: #0ea5e9; }
.metric-sent_department::before { background: #f97316; }
.metric-in_progress::before { background: #10b981; }
.metric-refused::before { background: #eab308; }
.metric-completed::before { background: #22c55e; }
.metric-error::before { background: #f43f5e; }
.metric-withdrawn::before { background: #fb923c; }
.metric-returned::before { background: #a855f7; }
.metric-consultation::before { background: #94a3b8; }

.registry-panel {
    margin-bottom: 22px;
}

.surface-head,
.title {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 16px;
}

.head-pill {
    min-height: 28px;
    display: inline-flex;
    align-items: center;
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 4px 10px;
    background: var(--surface-soft);
    color: var(--text-soft);
    font-size: 12px;
    font-weight: 800;
    white-space: nowrap;
}

.surface-head p,
.title p {
    margin-bottom: 0;
}

.title-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 10px;
    align-items: flex-start;
}

.assign-mo-form {
    display: grid;
    grid-template-columns: minmax(230px, 320px) auto;
    gap: 8px;
    align-items: end;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 10px;
    background: var(--surface-soft);
}

.assign-mo-form label {
    gap: 4px;
}

.assign-mo-form label span {
    color: var(--muted);
    font-size: 11px;
    text-transform: uppercase;
}

.registry-head {
    align-items: center;
    border-bottom: 1px solid var(--line);
    padding-bottom: 14px;
}

.registry-head > div:last-child,
.registry-head .button,
.registry-head form {
    display: inline-flex;
    gap: 8px;
    align-items: center;
}

.filters {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 12px;
    align-items: end;
    margin-bottom: 14px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 13px;
    background: var(--surface-soft);
}

.report-filter {
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
}

.filter-actions {
    display: flex;
    min-width: 0;
    flex-wrap: wrap;
    gap: 8px;
    align-items: end;
    align-self: end;
}

.filter-actions button,
.filter-actions .button {
    white-space: nowrap;
}

.status-tabs {
    display: flex;
    gap: 8px;
    max-width: 100%;
    min-width: 0;
    margin-bottom: 14px;
    padding-bottom: 2px;
    overflow-x: auto;
}

.status-tabs button,
.status-tabs a {
    min-height: 34px;
    flex: 0 0 auto;
    display: inline-flex;
    gap: 8px;
    align-items: center;
    justify-content: center;
    border-color: var(--line);
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 6px 10px 6px 12px;
    background: #fff;
    color: var(--text-soft);
    font-size: 13px;
    font-weight: 760;
    box-shadow: none;
}

.status-tabs button:hover,
.status-tabs a:hover {
    border-color: #bfdbfe;
    background: var(--brand-soft);
    color: var(--brand-strong);
}

.status-tabs button.active,
.status-tabs a.active {
    border-color: var(--brand);
    background: var(--brand);
    color: #fff;
}

.status-tabs span {
    min-width: 22px;
    min-height: 20px;
    display: inline-grid;
    place-items: center;
    border-radius: 999px;
    padding: 0 6px;
    background: rgba(15, 23, 42, .08);
    font-size: 12px;
}

.status-tabs button.active span,
.status-tabs a.active span {
    background: rgba(255, 255, 255, .22);
}

.table-wrap {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
}

table {
    width: 100%;
    min-width: 1180px;
    border-collapse: collapse;
}

th,
td {
    border-bottom: 1px solid var(--line);
    padding: 11px 13px;
    text-align: left;
    vertical-align: middle;
}

tr:last-child td {
    border-bottom: 0;
}

tbody tr:hover {
    background: #f8fbff;
}

th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: #f8fafc;
    color: #64748b;
    font-size: 11px;
    font-weight: 850;
    text-transform: uppercase;
}

.case-number,
.stacked-cell {
    min-width: 0;
}

.case-number > a,
.case-number > small,
.stacked-cell > span,
.stacked-cell > small {
    display: block;
    min-width: 0;
}

.case-number > :not(:first-child),
.stacked-cell > :not(:first-child) {
    margin-top: 2px;
}

.case-number small,
.stacked-cell small {
    color: var(--muted);
}

.stacked-cell > span,
.stacked-cell > small {
    overflow-wrap: anywhere;
}

.mo-cell .muted {
    color: var(--muted);
    font-weight: 700;
    white-space: nowrap;
}

.table-wrap th:nth-child(5),
.table-wrap td:nth-child(5) {
    min-width: 170px;
}

.table-wrap th:nth-child(6),
.table-wrap td:nth-child(6) {
    min-width: 210px;
}

.reg-link {
    color: var(--brand-strong);
    font-weight: 850;
}

.status,
.source,
.age {
    min-height: 25px;
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 4px 9px;
    font-size: 12px;
    font-weight: 800;
    white-space: nowrap;
}

.status-registered { background: #f0f9ff; color: #0369a1; }
.status-sent { background: #fff7ed; color: #9a3412; }
.status-work { background: #ecfdf5; color: #047857; }
.status-refused { background: #fffbeb; color: #92400e; }
.status-completed { background: #f0fdf4; color: #166534; }
.status-error { background: #fff1f2; color: #be123c; }
.status-withdrawn { background: #fff7ed; color: #a75700; }
.status-returned { background: #f5f3ff; color: #6d28d9; }
.status-consultation { background: #f1f5f9; color: #475569; }
.source-telegram { background: #eff6ff; color: #1d4ed8; }
.source-max { background: #f5f3ff; color: #6d28d9; }
.source-manual { background: #f1f5f9; color: #475569; }
.age-normal { background: #eff6ff; color: #1d4ed8; }
.age-warn { background: var(--warning-soft); color: var(--warning); }
.age-hot { background: var(--danger-soft); color: var(--danger); }
.age-done { background: var(--success-soft); color: var(--success); }

.analytics-section {
    display: grid;
    gap: 12px;
}

.section-heading {
    display: flex;
    justify-content: space-between;
    gap: 18px;
}

.analytics-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
    align-items: start;
}

.analytics-card {
    min-height: 270px;
    display: grid;
    align-content: start;
    gap: 12px;
}

.analytics-wide {
    grid-column: 1 / -1;
    min-height: 0;
}

.queue-list {
    display: grid;
    gap: 9px;
}

.queue-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 116px;
    gap: 14px;
    align-items: center;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 11px 13px;
    background: var(--surface-soft);
    color: var(--text);
    position: relative;
}

.queue-row::before {
    content: "";
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: #94a3b8;
    position: absolute;
    left: 13px;
    top: 17px;
}

.queue-row[data-status-filter="registered"]::before { background: #0ea5e9; }
.queue-row[data-status-filter="sent_department"]::before { background: #f97316; }
.queue-row[data-status-filter="in_progress"]::before { background: #10b981; }
.queue-row[data-status-filter="returned"]::before { background: #a855f7; }
.queue-row[data-status-filter="error"]::before { background: #f43f5e; }

.queue-row:hover,
.queue-row.active {
    border-color: #bfdbfe;
    background: var(--brand-soft);
    color: var(--text);
}

.queue-row > div:first-child {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 12px;
    align-items: center;
    padding-left: 18px;
}

.queue-row span {
    overflow: hidden;
    color: #334155;
    font-weight: 800;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.queue-row strong {
    color: #0f172a;
    font-size: 20px;
    line-height: 1;
}

.queue-bar,
.bar {
    height: 8px;
    overflow: hidden;
    border-radius: 999px;
    background: #e2e8f0;
}

.queue-bar i,
.bar i {
    display: block;
    height: 100%;
    border-radius: 999px;
}

.queue-bar i.status-registered { background: #0ea5e9; }
.queue-bar i.status-sent { background: #f97316; }
.queue-bar i.status-work { background: #10b981; }
.queue-bar i.status-refused { background: #eab308; }
.queue-bar i.status-completed { background: #22c55e; }
.queue-bar i.status-error { background: #f43f5e; }
.queue-bar i.status-withdrawn { background: #fb923c; }
.queue-bar i.status-returned { background: #a855f7; }
.queue-bar i.status-consultation { background: #94a3b8; }

.chart {
    height: 196px;
    display: flex;
    align-items: flex-end;
    gap: 7px;
    max-width: 100%;
    min-width: 0;
    overflow-x: auto;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 14px 8px 30px;
    background:
        linear-gradient(to top, rgba(15, 23, 42, .06) 1px, transparent 1px) 0 0 / 100% 34px,
        #fff;
}

.chart-col {
    min-width: 26px;
    height: 138px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    position: relative;
}

.chart-col i {
    width: 19px;
    display: block;
    border-radius: 6px 6px 0 0;
    background: var(--brand);
}

.chart-col.is-empty i {
    background: #e2e8f0;
}

.chart-value {
    min-height: 11px;
    margin-bottom: 4px;
    color: var(--text-soft);
    font-size: 11px;
    line-height: 1;
}

.chart-col b {
    position: absolute;
    left: 50%;
    bottom: -28px;
    transform: translateX(-50%) rotate(-45deg);
    color: var(--muted);
    font-size: 11px;
    font-weight: 650;
    white-space: nowrap;
}

.chart-col b.is-hidden {
    opacity: 0;
}

.split-lists {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
}

.compact-list {
    display: grid;
    align-content: start;
    gap: 6px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 14px;
    background: var(--surface-soft);
}

.compact-list h3 {
    margin-bottom: 6px;
    color: #334155;
    font-size: 14px;
    font-weight: 850;
}

.compact-row {
    min-height: 34px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 12px;
    align-items: center;
    border-bottom: 1px solid var(--line);
    padding: 7px 0;
}

.compact-row:last-child {
    border-bottom: 0;
}

.compact-row span {
    overflow-wrap: anywhere;
    color: #475569;
}

.compact-row strong {
    color: #0f172a;
}

.metrics,
.summary,
.report-grid,
.refs-grid {
    display: grid;
    gap: 14px;
}

.metrics {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    margin-bottom: 16px;
}

.metrics div,
.summary div {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 14px;
    background: var(--surface-soft);
}

.metrics strong {
    display: block;
    color: #0f172a;
    font-size: 29px;
    line-height: 1;
}

.metrics span,
.summary span {
    color: var(--muted);
    font-size: 11px;
    font-weight: 850;
    text-transform: uppercase;
}

.summary {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    margin-bottom: 16px;
}

.summary strong {
    display: block;
    overflow-wrap: anywhere;
}

.next-step {
    margin-bottom: 16px;
    border: 1px solid #bfdbfe;
    border-radius: var(--radius);
    padding: 12px 14px;
    background: var(--brand-soft);
    color: #1e3a8a;
}

.layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 360px;
    gap: 18px;
    align-items: start;
}

.detail-side {
    display: grid;
    gap: 14px;
    min-width: 0;
}

.text,
.edit,
.compact-meta,
.report-card,
.reference-card,
.reference-item {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface-soft);
}

.text {
    padding: 16px;
    font-size: 15px;
    line-height: 1.65;
}

.attachments-block {
    margin-top: 18px;
}

.attachment-missing-notice {
    margin-top: 14px;
    padding: 14px 16px;
    border: 1px solid #fcd34d;
    border-radius: var(--radius-sm);
    background: var(--warning-soft);
    color: #92400e;
}

.attachment-missing-notice p {
    margin: 8px 0 12px;
}

.attachment-missing-notice .inline-form {
    margin: 0;
}

.attachments-block h2 {
    margin-bottom: 10px;
}

.attachment-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 12px;
}

.attachment-item {
    min-width: 0;
    display: grid;
    gap: 8px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: 10px;
    background: #fff;
    color: var(--text);
    box-shadow: var(--shadow-sm);
}

.attachment-item:hover {
    border-color: var(--brand);
    color: var(--text);
}

.attachment-item img {
    width: 100%;
    aspect-ratio: 4 / 3;
    border-radius: 6px;
    object-fit: cover;
    background: var(--surface-muted);
}

.attachment-item strong {
    overflow: hidden;
    font-size: 13px;
    line-height: 1.25;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.attachment-item small {
    font-size: 12px;
}

.file-icon {
    min-height: 96px;
    display: grid;
    place-items: center;
    border-radius: 6px;
    background: var(--surface-muted);
    color: var(--muted);
    font-weight: 850;
}

.compact-meta {
    margin: 14px 0 18px;
    padding: 14px;
}

.meta {
    display: grid;
    grid-template-columns: 130px 1fr;
    gap: 7px 12px;
}

.meta dt {
    color: var(--muted);
    font-weight: 800;
}

.meta dd {
    min-width: 0;
    margin: 0;
    overflow-wrap: anywhere;
}

.edit {
    position: sticky;
    top: 84px;
    padding: 16px;
    background: #fff;
}

.return-form {
    padding: 16px;
    background: #fff;
    border: 1px solid #e9d5ff;
    border-radius: var(--radius);
    box-shadow: var(--shadow-soft);
}

.return-form h2 {
    margin: 0 0 8px;
}

.return-form label {
    margin-top: 12px;
}

.return-form button {
    margin-top: 12px;
}

.edit h2 {
    margin-top: 0;
}

.status-options {
    display: grid;
    gap: 8px;
    margin-bottom: 14px;
}

.status-choice {
    min-height: 42px;
    display: flex;
    align-items: center;
    gap: 9px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: 9px 10px;
    background: var(--surface-soft);
    color: var(--text);
    font-size: 14px;
}

.status-choice input {
    width: auto;
}

.status-choice:has(input:checked) {
    border-color: #bfdbfe;
    background: var(--brand-soft);
    color: #1e3a8a;
    font-weight: 820;
}

.report-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    margin: 16px 0;
}

.report-card,
.reference-card {
    padding: 15px;
}

.report-card h2,
.reference-card h2 {
    margin-top: 0;
}

.report-row {
    display: grid;
    gap: 6px;
    margin: 10px 0;
}

.report-row div:first-child {
    display: flex;
    justify-content: space-between;
    gap: 10px;
}

.bar i {
    background: var(--brand);
}

.refs-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.reference-tabs {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    margin: 16px 0;
}

.reference-tabs a {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    min-height: 52px;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fff;
    color: var(--secondary);
    text-decoration: none;
    font-weight: 800;
}

.reference-tabs a:hover {
    border-color: var(--line-strong);
    background: var(--surface-soft);
}

.reference-tabs a.active {
    border-color: rgba(37, 99, 235, .36);
    background: #eff6ff;
    color: var(--brand);
}

.reference-tabs strong {
    min-width: 34px;
    padding: 4px 8px;
    border-radius: 999px;
    background: var(--surface-soft);
    color: var(--muted);
    text-align: center;
}

.reference-tabs a.active strong {
    background: #dbeafe;
    color: #1d4ed8;
}

.reference-scope {
    display: grid;
    grid-template-columns: minmax(260px, 420px) minmax(0, 1fr);
    gap: 12px;
    align-items: end;
    margin-bottom: 14px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--surface-soft);
}

.reference-card-wide {
    max-width: 1040px;
}

.reference-card-head {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: start;
    margin-bottom: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--line);
}

.reference-card-head h2 {
    margin-bottom: 4px;
}

.reference-card-head p {
    margin: 0;
    color: var(--muted);
}

.reference-add {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
    gap: 8px;
    align-items: end;
    margin-bottom: 12px;
}

.reference-add:not(.is-subcategory) {
    grid-template-columns: minmax(240px, 520px) auto;
}

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

.reference-item {
    min-height: 42px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 9px 11px;
    background: #fff;
}

.reference-item span {
    overflow-wrap: anywhere;
}

.reference-rename {
    display: flex;
    flex: 1 1 auto;
    min-width: 0;
    align-items: center;
    gap: 8px;
}

.reference-rename input {
    min-width: 0;
    flex: 1 1 auto;
}

.reference-actions {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    gap: 6px;
}

.icon-button {
    min-width: 32px;
    min-height: 30px;
    padding: 4px 8px;
    border-color: var(--line);
    background: #fff;
    color: var(--secondary);
    font-size: 15px;
    line-height: 1;
}

.icon-button:hover:not(:disabled) {
    border-color: var(--line-strong);
    background: var(--surface-soft);
}

.cabinet-page {
    display: grid;
    gap: 16px;
}

.cabinet-stats {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
}

.cabinet-stats div {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 14px;
    background: var(--surface-soft);
}

.cabinet-stats span {
    display: block;
    margin-bottom: 7px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 850;
    text-transform: uppercase;
}

.cabinet-stats strong {
    color: #0f172a;
    font-size: 28px;
    line-height: 1;
}

.cabinet-layout {
    display: grid;
    grid-template-columns: minmax(300px, 380px) minmax(0, 1fr);
    gap: 16px;
    align-items: start;
}

.cabinet-form,
.cabinet-list {
    min-width: 0;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 16px;
    background: var(--surface-soft);
}

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

.cabinet-form h2 {
    margin-bottom: 2px;
}

.cabinet-form p {
    margin: 0;
}

.cabinet-list {
    display: grid;
    gap: 12px;
}

.cabinet-list-head {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: flex-start;
}

.cabinet-table {
    min-width: 860px;
}

.cabinet-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 6px;
}

.cabinet-actions form {
    margin: 0;
}

.uncovered-mo {
    display: grid;
    gap: 10px;
    border: 1px dashed var(--line-strong);
    border-radius: var(--radius);
    padding: 13px;
    background: #fff;
}

.uncovered-mo > div {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
}

.uncovered-mo span:not(.ui-kicker) {
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 5px 9px;
    background: var(--surface-soft);
    color: var(--text-soft);
    font-size: 12px;
    font-weight: 760;
}

.policy-layout {
    display: grid;
    grid-template-columns: minmax(0, .9fr) minmax(0, 1.1fr);
    gap: 18px;
    align-items: start;
}

.policy-upload,
.policy-current {
    min-width: 0;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 16px;
    background: var(--surface-soft);
}

.policy-upload {
    display: grid;
    gap: 12px;
}

.policy-upload p {
    margin-bottom: 0;
}

.policy-upload input[type="file"] {
    padding: 9px;
    background: #fff;
}

.policy-current {
    display: grid;
    gap: 12px;
}

.policy-current strong {
    overflow-wrap: anywhere;
    font-size: 17px;
}

.file-meta {
    display: grid;
    grid-template-columns: 110px minmax(0, 1fr);
    gap: 8px 12px;
    margin: 0;
}

.file-meta dt {
    color: var(--muted);
    font-weight: 800;
}

.file-meta dd {
    min-width: 0;
    margin: 0;
    overflow-wrap: anywhere;
}

.policy-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.danger-button {
    min-height: 30px;
    border-color: #fecdd3;
    padding: 5px 9px;
    background: #fff;
    color: var(--danger);
    font-size: 13px;
}

.danger-button:hover {
    border-color: #fecdd3;
    background: var(--danger-soft);
    color: var(--danger);
}

.empty {
    padding: 22px;
    color: var(--muted);
    text-align: center;
}

.empty.slim {
    padding: 14px 0;
    text-align: left;
}

.flash {
    margin-bottom: 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 10px 12px;
    background: #fff;
}

.flash.error {
    border-color: #fecdd3;
    background: var(--danger-soft);
    color: #991b1b;
}

.flash.success {
    border-color: #bbf7d0;
    background: var(--success-soft);
    color: #166534;
}

.login-page {
    min-height: 100vh;
    overflow: hidden;
    background:
        linear-gradient(90deg, rgba(37, 99, 235, .10) 0 1px, transparent 1px 100%),
        linear-gradient(180deg, rgba(15, 23, 42, .06) 0 1px, transparent 1px 100%),
        linear-gradient(135deg, #f8fafc 0%, #eef2f7 48%, #f8fafc 100%);
    background-size: 44px 44px, 44px 44px, auto;
}

.login-page::before {
    content: "";
    position: fixed;
    inset: 0 auto 0 0;
    width: 42vw;
    max-width: 620px;
    background:
        linear-gradient(180deg, rgba(15, 23, 42, .96), rgba(30, 41, 59, .96)),
        repeating-linear-gradient(135deg, rgba(255, 255, 255, .08) 0 1px, transparent 1px 18px);
    clip-path: polygon(0 0, 86% 0, 100% 100%, 0 100%);
    pointer-events: none;
}

.login-shell {
    position: relative;
    z-index: 1;
    min-height: 100vh;
    width: min(1120px, 100%);
    margin: 0 auto;
    display: grid;
    grid-template-columns: minmax(340px, 430px) minmax(320px, 1fr);
    align-items: center;
    gap: 72px;
    padding: 42px;
}

.login-card {
    min-width: 0;
    border: 1px solid rgba(203, 213, 225, .9);
    border-radius: 12px;
    padding: 28px;
    background: rgba(255, 255, 255, .94);
    box-shadow: 0 24px 70px rgba(15, 23, 42, .16);
    backdrop-filter: blur(12px);
}

.login-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 34px;
}

.login-mark {
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    border-radius: 10px;
    background: var(--brand);
    color: #fff;
    font-weight: 900;
}

.login-brand div {
    display: grid;
    gap: 2px;
    line-height: 1.2;
}

.login-brand span:not(.login-mark) {
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
}

.login-brand strong {
    color: var(--text);
    font-size: 15px;
}

.login-heading {
    margin-bottom: 18px;
}

.login-heading h1 {
    margin: 4px 0 0;
    font-size: 28px;
    line-height: 1.12;
}

.login-form {
    display: grid;
    gap: 14px;
}

.login-form label {
    gap: 7px;
}

.login-form label span {
    color: #334155;
}

.login-form input {
    height: 44px;
    border-color: #cbd5e1;
    background: #f8fafc;
    font-size: 15px;
    transition: border-color .16s ease, box-shadow .16s ease, background .16s ease;
}

.login-form input:hover {
    border-color: #94a3b8;
    background: #fff;
}

.login-form input:focus {
    border-color: var(--brand);
    background: #fff;
    box-shadow: 0 0 0 4px rgba(37, 99, 235, .12);
    outline: none;
}

.login-submit {
    width: 100%;
    min-height: 46px;
    margin-top: 4px;
    font-size: 15px;
}

.login-context {
    min-height: 440px;
    display: grid;
    align-content: center;
    gap: 22px;
    color: #fff;
}

.context-card {
    width: min(420px, 100%);
    border: 1px solid rgba(255, 255, 255, .16);
    border-radius: 12px;
    padding: 30px;
    background: rgba(15, 23, 42, .72);
    box-shadow: 0 24px 70px rgba(15, 23, 42, .22);
}

.context-card span,
.context-card small {
    color: #cbd5e1;
    font-weight: 750;
}

.context-card span {
    display: block;
    margin-bottom: 10px;
    font-size: 12px;
    letter-spacing: .04em;
    text-transform: uppercase;
}

.context-card strong {
    display: block;
    max-width: 320px;
    margin-bottom: 12px;
    font-size: 34px;
    line-height: 1.05;
    letter-spacing: 0;
}

.context-strip {
    width: min(420px, 100%);
    display: grid;
    grid-template-columns: 1.2fr .8fr 1fr .6fr;
    gap: 8px;
}

.context-strip i {
    height: 7px;
    border-radius: 999px;
    background: rgba(255, 255, 255, .28);
}

.context-strip i:nth-child(2) {
    background: rgba(37, 99, 235, .86);
}

.context-strip i:nth-child(3) {
    background: rgba(22, 163, 74, .78);
}

code {
    border-radius: 4px;
    padding: 2px 5px;
    background: #e2e8f0;
}

@media (max-width: 1180px) {
    .login-shell {
        gap: 42px;
        padding: 32px;
    }

    .app-shell {
        grid-template-columns: 220px minmax(0, 1fr);
    }

    .page {
        padding: 20px;
    }

    .filters,
    .report-filter {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .filter-actions {
        grid-column: 1 / -1;
    }
}

@media (max-width: 980px) {
    .login-page {
        overflow: auto;
    }

    .login-page::before {
        width: 100%;
        max-width: none;
        height: 36vh;
        clip-path: none;
    }

    .login-shell {
        width: min(520px, 100%);
        grid-template-columns: 1fr;
        gap: 22px;
        padding: 28px 18px;
    }

    .login-context {
        min-height: 0;
        order: -1;
    }

    .context-card {
        padding: 18px;
    }

    .context-card strong {
        font-size: 24px;
    }

    .analytics-grid,
    .split-lists,
    .policy-layout,
    .cabinet-layout,
    .cabinet-stats,
    .metrics,
    .summary,
    .layout,
    .report-grid,
    .refs-grid,
    .reference-tabs,
    .reference-scope {
        grid-template-columns: 1fr;
    }

    .analytics-wide {
        grid-column: auto;
    }

    .edit {
        position: static;
    }
}

@media (max-width: 760px) {
    .login-page::before,
    .login-context {
        display: none;
    }

    .login-shell {
        min-height: 100svh;
        width: 100%;
        padding: 16px;
    }

    .login-card {
        padding: 22px;
        box-shadow: 0 18px 48px rgba(15, 23, 42, .12);
    }

    .login-brand {
        margin-bottom: 26px;
    }

    .login-heading h1 {
        font-size: 25px;
    }

    .app-shell {
        display: block;
    }

    .app-sidebar {
        position: static;
        height: auto;
        gap: 12px;
        padding: 14px;
    }

    .sidebar-brand {
        grid-template-columns: 38px minmax(0, 1fr);
    }

    .brand-mark {
        width: 38px;
        height: 38px;
    }

    .sidebar-nav {
        grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
    }

    .sidebar-nav a {
        justify-content: center;
        min-height: 38px;
        padding: 8px;
        text-align: center;
    }

    .sidebar-metric {
        display: none;
    }

    .sidebar-logout {
        justify-content: center;
        margin-top: 0;
    }

    .app-topbar {
        position: static;
        min-height: 58px;
        padding: 12px 14px;
    }

    .top-user {
        display: none;
    }

    .page {
        padding: 14px 10px 22px;
    }

    .dashboard-header {
        display: grid;
    }

    .dashboard-total {
        min-width: 0;
    }

    .status-overview {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .surface,
    .panel {
        padding: 14px;
    }

    .filters,
    .report-filter,
    .assign-mo-form,
    .reference-add,
    .reference-add:not(.is-subcategory) {
        grid-template-columns: 1fr;
    }

    .filter-actions {
        display: grid;
        grid-template-columns: 1fr;
    }

    .surface-head,
    .title {
        display: block;
    }

    .title-actions {
        justify-content: flex-start;
        margin-top: 10px;
    }

    .queue-row {
        grid-template-columns: 1fr;
    }

    table {
        min-width: 760px;
    }
}

.edit > label {
    margin-top: 12px;
}

.edit > button {
    margin-top: 14px;
}

.notify-check {
    display: flex;
    align-items: center;
    gap: 9px;
    margin: 12px 0 0;
    color: var(--text);
    font-size: 13px;
    font-weight: 700;
}

.notify-check input {
    width: auto;
    margin: 0;
}

.notify-check.is-disabled {
    opacity: .58;
}
