:root {
    --bg: #f5f6f4;
    --surface: #ffffff;
    --surface-2: #eef2ef;
    --text: #1b1f22;
    --muted: #657077;
    --line: #dce2de;
    --brand: #1b6f6a;
    --brand-strong: #14524f;
    --accent: #b44b2b;
    --blue: #2e5f9e;
    --green: #24764d;
    --amber: #9a6a12;
    --red: #aa3131;
    --shadow: 0 18px 40px rgba(25, 33, 38, .08);
}

/* Secondo cervello: Wiki legale, revisioni e grafo nativo. */
.second-brain-hero {
    border-left: 4px solid var(--brand);
}

.second-brain-metrics {
    margin: 18px 0;
}

.second-brain-query-layout {
    align-items: start;
}

.wiki-query-list,
.wiki-citations,
.wiki-review-actions {
    display: grid;
    gap: 14px;
}

.wiki-query-card,
.wiki-change-set,
.wiki-change-item,
.wiki-page {
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-2);
}

.wiki-query-card header,
.wiki-change-set > summary,
.wiki-change-item > summary,
.wiki-page > summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
}

.wiki-change-set > summary,
.wiki-change-item > summary,
.wiki-page > summary {
    cursor: pointer;
    font-weight: 800;
}

.wiki-markdown-answer,
.wiki-change-item pre,
.wiki-page pre {
    margin: 14px 0;
    padding: 14px;
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 7px;
    color: var(--text);
    background: var(--surface);
    font: inherit;
    line-height: 1.55;
    white-space: pre-wrap;
}

.wiki-citations {
    padding-left: 28px;
}

.wiki-citations blockquote {
    margin: 6px 0 0;
    padding: 8px 12px;
    border-left: 3px solid var(--brand);
    color: var(--muted);
    background: var(--surface);
}

.wiki-review-actions {
    grid-template-columns: auto minmax(280px, 1fr);
    align-items: end;
    margin-top: 14px;
}

.wiki-review-actions form:last-child {
    display: flex;
    align-items: end;
    gap: 10px;
}

.wiki-review-actions label {
    flex: 1;
}

.wiki-graph {
    position: relative;
    min-height: 680px;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 9px;
    background:
        radial-gradient(circle at center, rgba(54, 132, 116, .09), transparent 45%),
        var(--surface-2);
}

.wiki-graph-controls {
    display: grid;
    grid-template-columns: minmax(210px, 2fr) repeat(5, minmax(120px, 1fr));
    gap: 10px;
    align-items: end;
    margin-bottom: 12px;
}

.wiki-graph-controls label {
    margin: 0;
}

.wiki-graph-zoom { display: flex; gap: 4px; }
.wiki-graph-timeline { display: grid; grid-template-columns: auto minmax(260px, 1fr) minmax(170px, auto) auto; gap: 12px; align-items: center; margin: 0 0 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface-2); }
.wiki-graph-timeline label { display: grid; grid-template-columns: auto minmax(180px, 1fr); gap: 10px; align-items: center; margin: 0; }
.wiki-graph-timeline input[type="range"] { width: 100%; accent-color: var(--brand-strong); }
.wiki-graph-timeline strong { color: var(--brand-strong); font-size: 13px; white-space: nowrap; }
.wiki-graph-legend { display: flex; flex-wrap: wrap; gap: 16px; margin: 0 0 12px; color: var(--muted); font-size: 12px; }
.wiki-graph-legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend-dot { width: 12px; height: 12px; border: 2px solid var(--brand-strong); border-radius: 50%; background: #d9eee8; }
.legend-dot.source { border-color: #9a6728; background: #f3dfbd; }
.legend-dot.proposed { border-color: #7356a8; border-style: dashed; background: #eee7fa; }
.legend-line { width: 24px; border-top: 3px solid var(--brand); }
.legend-line.contradicts { border-color: #b94b57; border-top-style: dashed; }
.legend-line.links-to { border-color: #3978b8; }
.legend-line.derived-from { border-color: #c47a25; }
.legend-line.proposed { border-color: #7356a8; border-top-style: dashed; }
.wiki-graph-shell { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 14px; align-items: stretch; }

.wiki-graph-status {
    position: absolute;
    z-index: 2;
    top: 10px;
    left: 12px;
    margin: 0;
    padding: 5px 8px;
    border-radius: 5px;
    color: var(--muted);
    background: rgba(255, 255, 255, .88);
    font-size: 12px;
}

.wiki-graph-status.is-error {
    color: var(--red);
}

.wiki-graph svg {
    display: block;
    width: 100%;
    min-width: 760px;
    height: 720px;
}

.wiki-graph-detail { min-height: 680px; padding: 20px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface-2); }
.wiki-graph-detail h3 { margin: 6px 0 8px; font-size: 20px; }
.wiki-graph-detail ul { padding-left: 18px; color: var(--muted); font-size: 13px; line-height: 1.5; }
.wiki-graph-detail .button { margin-top: 18px; }

.wiki-graph-edge {
    stroke: #557d73;
    stroke-width: 2.4;
    opacity: .9;
    marker-end: none;
    transition: opacity .16s ease;
}

.wiki-graph-edge-contradicts {
    stroke: #b94b57;
    stroke-dasharray: 6 4;
}

.wiki-graph-edge-supports,
.wiki-graph-edge-cites {
    stroke: var(--brand);
}

.wiki-graph-edge-links_to { stroke: #3978b8; }
.wiki-graph-edge-derived_from { stroke: #c47a25; }
.wiki-graph-edge-mentions { stroke: #7356a8; }
.wiki-graph-edge-layer-proposed { stroke-dasharray: 7 5; opacity: .78; }

.wiki-graph-arrow {
    fill: #557d73;
}

.wiki-graph-node {
    cursor: grab;
    outline: none;
    transition: opacity .16s ease;
}
.wiki-graph-node:active { cursor: grabbing; }

.wiki-graph-node circle {
    fill: #d9eee8;
    stroke: var(--brand-strong);
    stroke-width: 2;
}

.wiki-graph-node:hover circle { filter: drop-shadow(0 3px 5px rgba(25, 61, 53, .28)); }

.wiki-graph-node-source circle {
    fill: #f3dfbd;
    stroke: #9a6728;
}

.wiki-graph-node-layer-proposed circle {
    fill: #eee7fa;
    stroke: #7356a8;
    stroke-dasharray: 5 3;
}

.wiki-graph-node-index circle {
    fill: var(--brand-strong);
    stroke: #ffffff;
    stroke-width: 3;
}

.wiki-graph-node-contradiction circle {
    fill: #f4cbd0;
    stroke: #a33c48;
}

.wiki-graph-node text {
    fill: var(--text);
    font-size: 11px;
    font-weight: 700;
    paint-order: stroke;
    stroke: var(--surface-2);
    stroke-width: 3px;
    stroke-linejoin: round;
}

.wiki-graph-node:focus circle {
    stroke-width: 5;
}

.wiki-graph-node.is-selected circle {
    stroke: #172f2a;
    stroke-width: 5;
}

.wiki-graph .is-filtered {
    display: none;
}

.wiki-graph .is-muted {
    opacity: .12;
}

.wiki-accessible-graph {
    margin-top: 12px;
}

@media (max-width: 760px) {
    .wiki-graph-controls {
        grid-template-columns: 1fr;
    }
    .wiki-graph-shell { grid-template-columns: 1fr; }
    .wiki-graph-timeline { grid-template-columns: auto 1fr; }
    .wiki-graph-timeline strong { grid-column: 1 / -1; }
    .wiki-graph-detail { min-height: 0; }
    .wiki-review-actions {
        grid-template-columns: 1fr;
    }

    .wiki-review-actions form:last-child,
    .wiki-query-card header,
    .wiki-change-set > summary,
    .wiki-change-item > summary,
    .wiki-page > summary {
        align-items: stretch;
        flex-direction: column;
    }

    .wiki-graph {
        overflow-x: auto;
    }
}

/* PEC inbox, importazione e configurazione account */
.pec-hero .muted,
.pec-inbox-head .muted,
.pec-account-panel .panel-head .muted,
.pec-config-panel .panel-head .muted {
    max-width: 720px;
    margin: 7px 0 0;
    line-height: 1.5;
}

.pec-receipt-metrics .metric {
    text-decoration: none;
}

.pec-receipt-metrics .metric:hover {
    border-color: var(--accent);
}

.pec-import-panel {
    border-color: #b8d8cd;
    background: linear-gradient(145deg, #ffffff 0%, #f3faf7 100%);
}

.pec-import-form {
    margin-top: 18px;
}

.pec-file-field {
    padding: 14px;
    border: 1px dashed #8fb9aa;
    border-radius: 8px;
    background: rgba(255, 255, 255, .78);
}

.pec-file-field input {
    margin-top: 7px;
    background: var(--surface);
}

.pec-file-field small,
.pec-manual-panel label small,
.pec-config-form label small {
    display: block;
    margin-top: 6px;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.45;
}

.pec-import-form .form-actions .hint {
    max-width: 520px;
    margin: 0;
}

.pec-manual-panel {
    margin-bottom: 18px;
    padding: 0;
    overflow: hidden;
}

.pec-manual-panel details > summary {
    list-style-position: inside;
}

.pec-panel-summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    padding: 18px;
    cursor: pointer;
}

.pec-panel-summary:hover {
    background: var(--surface-2);
}

.pec-panel-summary > span:first-child {
    display: grid;
}

.pec-panel-summary .eyebrow {
    margin-bottom: 5px;
}

.pec-panel-summary > .muted {
    max-width: 380px;
    text-align: right;
    font-size: 13px;
}

.pec-manual-panel details[open] .pec-panel-summary {
    border-bottom: 1px solid var(--line);
}

.pec-manual-content {
    padding: 18px;
}

.pec-manual-content > .alert {
    margin: 0 0 18px;
}

.pec-inbox-panel {
    padding: 0;
    overflow: hidden;
}

.pec-inbox-head {
    padding: 18px 18px 0;
}

.pec-inbox-filters {
    display: grid;
    grid-template-columns: minmax(260px, 1fr) minmax(150px, .35fr) minmax(190px, .55fr) auto;
    gap: 12px;
    align-items: end;
    padding: 18px;
    border-bottom: 1px solid var(--line);
}

.pec-filter-actions,
.pec-account-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    flex-wrap: wrap;
}

.pec-inbox-panel td .muted,
.pec-inbox-panel td .pec-download-link,
.pec-inbox-panel td .pec-error-detail {
    display: block;
    margin-top: 4px;
    font-size: 12px;
    line-height: 1.4;
}

.pec-download-link {
    color: var(--brand-strong);
    font-weight: 700;
}

.pec-error-detail,
.pec-account-error {
    color: #8b301f;
}

.pec-row-error td {
    background: #fff9f5;
}

.pec-pagination {
    margin-top: 18px;
}

.pec-account-list {
    display: grid;
    gap: 12px;
    margin-top: 16px;
}

.pec-account-card {
    display: grid;
    gap: 14px;
    padding: 15px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-2);
}

.pec-account-card.has-error {
    border-color: #e1b4a7;
    background: #fff9f5;
}

.pec-account-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.pec-account-heading > div {
    display: grid;
    gap: 4px;
    min-width: 0;
}

.pec-account-heading strong {
    overflow-wrap: anywhere;
}

.pec-account-details {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin: 0;
}

.pec-account-details div {
    display: grid;
    gap: 3px;
    min-width: 0;
}

.pec-account-details dt {
    color: var(--muted);
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
}

.pec-account-details dd {
    margin: 0;
    overflow-wrap: anywhere;
    font-size: 13px;
}

.pec-account-error {
    margin: 0;
    padding: 10px;
    border-radius: 7px;
    background: #fff0ea;
    font-size: 12px;
    line-height: 1.45;
}

.pec-account-empty {
    display: grid;
    justify-items: start;
    gap: 8px;
    padding: 20px;
    border: 1px dashed var(--line);
    border-radius: 8px;
}

.pec-config-panel {
    max-width: 900px;
}

.pec-security-note {
    margin: 18px 0;
}

.pec-config-form {
    gap: 18px;
}

.pec-fieldset {
    display: grid;
    gap: 14px;
    padding: 16px;
}

.pec-connection-summary {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
}

.pec-connection-summary span {
    display: grid;
    gap: 3px;
    padding: 10px;
    border-radius: 7px;
    background: var(--surface-2);
    color: var(--muted);
    font-size: 12px;
}

.pec-connection-summary strong {
    color: var(--text);
}

.pec-config-form code {
    padding: 1px 4px;
    border-radius: 4px;
    background: var(--surface-2);
}

.pec-config-form button:disabled {
    cursor: not-allowed;
    opacity: .55;
}

.pec-matter-fieldset {
    min-width: 0;
    margin: 0;
    padding: 0;
    border: 0;
}

.pec-matter-fieldset legend {
    margin-bottom: 7px;
    font-weight: 700;
}

.pec-matter-checklist {
    display: grid;
    gap: 2px;
    max-height: 260px;
    overflow: auto;
    padding: 6px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--surface);
}

.pec-matter-checklist label {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 9px;
    align-items: start;
    padding: 8px;
    border-radius: 7px;
    cursor: pointer;
    line-height: 1.35;
}

.pec-matter-checklist label:hover {
    background: var(--surface-2);
}

.pec-matter-checklist label.is-disabled {
    opacity: .5;
    cursor: not-allowed;
}

@media (max-width: 900px) {
    .pec-receipt-metrics {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .pec-inbox-filters,
    .pec-connection-summary {
        grid-template-columns: 1fr;
    }

    .pec-filter-actions {
        justify-content: flex-start;
    }
}

@media (max-width: 680px) {
    .pec-panel-summary,
    .pec-account-heading,
    .pec-config-actions {
        align-items: stretch;
        flex-direction: column;
    }

    .pec-panel-summary > .muted {
        text-align: left;
    }

    .pec-account-details,
    .pec-receipt-metrics {
        grid-template-columns: 1fr;
    }

    .pec-account-actions,
    .pec-account-actions form,
    .pec-account-actions .button {
        width: 100%;
    }
}

* {
    box-sizing: border-box;
}

html {
    min-width: 320px;
}

body {
    margin: 0;
    min-height: 100vh;
    color: var(--text);
    background: var(--bg);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    letter-spacing: 0;
}

a {
    color: inherit;
    text-decoration: none;
}

.skip-link {
    position: fixed;
    top: 10px;
    left: 10px;
    z-index: 100;
    padding: 10px 14px;
    border-radius: 8px;
    color: #ffffff;
    background: var(--brand-strong);
    font-weight: 800;
    transform: translateY(-160%);
    transition: transform .15s ease;
}

.skip-link:focus {
    transform: translateY(0);
}

button,
input,
select,
textarea {
    font: inherit;
    letter-spacing: 0;
}

:where(a, button, summary, input, select, textarea, [tabindex]):focus-visible {
    outline: 3px solid rgba(27, 111, 106, .42);
    outline-offset: 3px;
}

.sidebar :where(a, button):focus-visible {
    outline-color: #a8eee5;
}

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

.sidebar {
    display: flex;
    flex-direction: column;
    gap: 22px;
    padding: 24px 18px;
    color: #f8fbf9;
    background: #193330;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

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

.brand strong,
.brand small {
    display: block;
}

.brand small {
    margin-top: 2px;
    color: rgba(255, 255, 255, .66);
    font-size: 12px;
}

.sidebar-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    gap: 7px;
    min-width: 44px;
    min-height: 44px;
    padding: 8px 11px;
    border: 1px solid rgba(255, 255, 255, .35);
    border-radius: 8px;
    color: #ffffff;
    background: rgba(255, 255, 255, .08);
    font-weight: 800;
    cursor: pointer;
}

.sidebar-panel {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 24px;
    min-height: 0;
}

.nav {
    display: grid;
    gap: 18px;
    min-height: 0;
}

.nav-group {
    display: grid;
    gap: 5px;
}

.nav-group-title {
    margin: 0 10px;
    color: rgba(255, 255, 255, .52);
    font-size: 10px;
    font-weight: 900;
    letter-spacing: .09em;
    text-transform: uppercase;
}

.nav-group-links {
    display: grid;
    gap: 3px;
}

.nav a {
    min-height: 40px;
    padding: 10px 12px;
    border-radius: 8px;
    color: rgba(255, 255, 255, .74);
}

.nav a:hover,
.nav a.active {
    color: #ffffff;
    background: rgba(255, 255, 255, .12);
}

.nav a.active {
    box-shadow: inset 3px 0 0 #78d2c8;
}

.sidebar-footer {
    display: grid;
    gap: 10px;
    margin-top: auto;
    color: rgba(255, 255, 255, .72);
    font-size: 13px;
}

.sidebar-user strong,
.sidebar-user small {
    display: block;
}

.sidebar-user small {
    margin-top: 2px;
    color: rgba(255, 255, 255, .56);
    font-size: 11px;
    text-transform: capitalize;
}

.sidebar .button.ghost {
    border-color: rgba(255, 255, 255, .38);
    color: #ffffff;
    background: rgba(255, 255, 255, .06);
}

.sidebar .button.ghost:hover {
    border-color: rgba(255, 255, 255, .65);
    background: rgba(255, 255, 255, .14);
}

.main {
    min-width: 0;
    padding: 30px;
}

.topbar,
.panel-head,
.toolbar,
.form-actions,
.actions,
.provider-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
}

.actions,
.action-stack,
.form-actions {
    flex-wrap: wrap;
}

.topbar {
    margin-bottom: 24px;
}

.quickbar {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    min-width: min(100%, 520px);
}

.quick-search {
    display: flex;
    align-items: center;
    gap: 8px;
    width: min(100%, 360px);
}

.quick-search-field {
    position: relative;
    flex: 1;
    min-width: 0;
}

.quick-search input {
    min-height: 34px;
    padding-right: 76px;
}

.search-shortcut {
    position: absolute;
    top: 50%;
    right: 8px;
    padding: 2px 5px;
    border: 1px solid var(--line);
    border-bottom-width: 2px;
    border-radius: 5px;
    color: var(--muted);
    background: var(--surface-2);
    font-family: inherit;
    font-size: 10px;
    line-height: 1.35;
    pointer-events: none;
    transform: translateY(-50%);
}

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

h1 {
    margin-bottom: 0;
    font-size: clamp(28px, 3vw, 40px);
    line-height: 1.08;
}

h2 {
    margin-bottom: 0;
    font-size: 21px;
    line-height: 1.2;
}

.eyebrow {
    margin-bottom: 7px;
    color: var(--accent);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
}

.muted,
.hint,
.empty {
    color: var(--muted);
}

.hint {
    margin: 18px 0 0;
    font-size: 13px;
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 38px;
    padding: 9px 14px;
    border: 1px solid var(--brand);
    border-radius: 8px;
    color: #ffffff;
    background: var(--brand);
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
}

.button:hover {
    background: var(--brand-strong);
}

.button.secondary {
    border-color: #cbd6d1;
    color: var(--brand-strong);
    background: #eaf2ef;
}

.button.ghost {
    border-color: var(--line);
    color: var(--text);
    background: transparent;
}

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

.button.full {
    width: 100%;
}

.alert {
    margin-bottom: 16px;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.alert.success {
    border-color: #bcdac9;
    color: #145b38;
    background: #eaf7f0;
}

.alert.danger {
    border-color: #e4b9b9;
    color: #8f2323;
    background: #fff0f0;
}

.alert.warning {
    border-color: #e4cf8d;
    color: #765100;
    background: #fff7dd;
}

.conflict-alert ul {
    margin: 8px 0 0;
    padding-left: 20px;
}

.mini-checklist {
    margin: 8px 0 0;
    padding-left: 16px;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.4;
}

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

.metrics-grid.compact-metrics {
    grid-template-columns: repeat(8, minmax(120px, 1fr));
}

.metric,
.panel,
.auth-panel {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.metric {
    display: grid;
    gap: 10px;
    min-height: 112px;
    padding: 18px;
}

.metric span {
    color: var(--muted);
    font-weight: 700;
}

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

.metric.urgent {
    border-color: #e2c58d;
    background: #fff8e9;
}

.content-grid,
.split {
    display: grid;
    grid-template-columns: minmax(0, 1.35fr) minmax(320px, .75fr);
    gap: 18px;
    margin-bottom: 18px;
}

.process-hero,
.matter-command {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 18px;
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.process-hero h2,
.matter-command h2 {
    margin-bottom: 0;
}

.matter-command p {
    margin: 8px 0 0;
}

.matter-command-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
}

.score {
    display: inline-grid;
    place-items: center;
    min-width: 58px;
    min-height: 58px;
    border-radius: 999px;
    color: #155b3a;
    background: #dff1e8;
    font-weight: 900;
}

.score.warning {
    color: #76500b;
    background: #fff1cf;
}

.score.danger {
    color: #8b2424;
    background: #ffe2e2;
}

.panel {
    min-width: 0;
    padding: 18px;
}

.narrow {
    max-width: 760px;
}

.list {
    display: grid;
    gap: 10px;
    margin-top: 16px;
}

.list.compact {
    gap: 6px;
}

.list-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 0;
    border-top: 1px solid var(--line);
}

.list-row:first-child {
    border-top: 0;
}

.list-row strong,
.list-row span {
    display: block;
}

.list-row span,
.list-row time,
td {
    color: var(--muted);
}

.link-row:hover {
    color: var(--brand-strong);
}

.row-right {
    display: grid;
    justify-items: end;
    gap: 6px;
}

.status-bars {
    display: grid;
    gap: 10px;
    margin-top: 18px;
}

.status-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
    margin-top: 16px;
}

.status-grid div {
    min-height: 86px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-2);
}

.status-grid span {
    display: block;
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
}

.status-grid strong {
    display: block;
    margin-top: 8px;
    font-size: 24px;
    line-height: 1.1;
    overflow-wrap: anywhere;
}

.status-line {
    display: flex;
    justify-content: space-between;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-2);
}

.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

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

th {
    color: #3d474c;
    font-size: 12px;
    text-transform: uppercase;
}

td strong,
td a {
    color: var(--text);
}

.actions-cell {
    width: 1%;
    white-space: nowrap;
}

.action-stack {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
}

.inline-form {
    display: flex;
    align-items: center;
    gap: 8px;
}

.inline-form input {
    width: 180px;
    min-height: 32px;
    padding: 6px 8px;
    font-size: 13px;
}

.badge {
    display: inline-flex;
    align-items: center;
    min-height: 25px;
    padding: 4px 8px;
    border-radius: 999px;
    color: #485158;
    background: #e7ece9;
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
}

.badge.success {
    color: #155b3a;
    background: #dff1e8;
}

.badge.warning {
    color: #76500b;
    background: #fff1cf;
}

.badge.danger {
    color: #8b2424;
    background: #ffe2e2;
}

.toolbar {
    margin-bottom: 16px;
}

.search {
    display: flex;
    align-items: center;
    gap: 10px;
    width: min(100%, 680px);
}

.search.multi {
    width: min(100%, 860px);
}

.search-page-form {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 12px;
    align-items: end;
}

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

.form {
    width: 100%;
}

.form.stack {
    display: grid;
    gap: 14px;
}

.form-gap {
    margin-top: 18px;
}

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

.grid-form.embedded {
    width: 100%;
}

.span-2 {
    grid-column: span 2;
}

label {
    display: grid;
    gap: 7px;
    color: #445057;
    font-size: 13px;
    font-weight: 800;
}

.check-line {
    display: flex;
    align-items: center;
    gap: 10px;
}

.check-line input {
    width: 18px;
    min-height: 18px;
}

.checks {
    display: grid;
    gap: 8px;
}

.checks label {
    display: flex;
    align-items: center;
    gap: 10px;
}

.checks input {
    width: 18px;
    min-height: 18px;
}

.wizard-section {
    display: grid;
    grid-template-columns: minmax(180px, 240px) minmax(0, 1fr);
    gap: 18px;
    padding: 18px 0;
    border-top: 1px solid var(--line);
}

.wizard-section:first-of-type {
    border-top: 0;
    padding-top: 0;
}

.wizard-section h3 {
    margin: 8px 0 0;
    font-size: 18px;
}

.step-index {
    display: inline-grid;
    place-items: center;
    width: 30px;
    height: 30px;
    border-radius: 999px;
    color: #ffffff;
    background: var(--brand);
    font-weight: 900;
}

.step-list {
    display: grid;
    gap: 12px;
    margin: 18px 0 0;
    padding: 0;
    list-style: none;
}

.step-list li {
    display: grid;
    grid-template-columns: 30px minmax(0, 1fr);
    gap: 10px;
    align-items: start;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-2);
}

.step-list li > span {
    display: inline-grid;
    place-items: center;
    width: 26px;
    height: 26px;
    border-radius: 999px;
    color: #ffffff;
    background: var(--brand);
    font-size: 12px;
    font-weight: 900;
}

.step-list strong,
.step-list small {
    display: block;
}

.step-list small {
    margin-top: 4px;
    color: var(--muted);
}

fieldset {
    min-width: 0;
    margin: 0;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
}

legend {
    padding: 0 6px;
    color: #445057;
    font-size: 13px;
    font-weight: 800;
}

input,
select,
textarea {
    width: 100%;
    min-height: 40px;
    padding: 9px 11px;
    border: 1px solid #cbd6d1;
    border-radius: 8px;
    color: var(--text);
    background: #ffffff;
}

textarea {
    resize: vertical;
}

.prose {
    line-height: 1.65;
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 3px solid rgba(27, 111, 106, .16);
    border-color: var(--brand);
}

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

.details div {
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-2);
}

.details dt {
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
}

.details dd {
    margin: 5px 0 0;
    overflow-wrap: anywhere;
}

.callout {
    margin-top: 16px;
    padding: 14px;
    border-left: 4px solid var(--brand);
    border-radius: 6px;
    background: var(--surface-2);
}

.callout p {
    margin: 6px 0 0;
}

.check-list {
    display: grid;
    gap: 10px;
    margin: 16px 0 0;
    padding: 0;
    list-style: none;
}

.check-list li {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: start;
    gap: 10px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-2);
}

.check-list strong,
.check-list .muted {
    display: block;
}

.form-disclosure > summary {
    cursor: pointer;
    font-weight: 800;
}

.form-disclosure[open] > summary {
    margin-bottom: 14px;
}

.form-disclosure > .panel {
    padding: 0;
    border: 0;
    box-shadow: none;
}

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

.provider-box {
    display: grid;
    gap: 12px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-2);
}

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

.provider-test {
    padding-top: 12px;
    border-top: 1px solid var(--line);
}

.queue-summary {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 14px;
}

.queue-summary .metric-card {
    min-height: auto;
    text-decoration: none;
}

.auth-body {
    display: grid;
    place-items: center;
    min-height: 100vh;
    padding: 24px;
    background:
        linear-gradient(135deg, rgba(27, 111, 106, .16), rgba(180, 75, 43, .10)),
        var(--bg);
}

.auth-wrap {
    width: min(100%, 430px);
}

.auth-panel {
    padding: 28px;
}

.auth-brand {
    margin-bottom: 28px;
    color: var(--text);
}

.auth-brand small {
    color: var(--muted);
}

.auth-panel h1 {
    font-size: 30px;
}

.debug {
    overflow: auto;
    max-height: 360px;
    padding: 14px;
    border-radius: 8px;
    background: #121616;
    color: #e8f3ee;
    font-size: 12px;
}

.timeline {
    display: grid;
    gap: 0;
    margin-top: 16px;
}

.timeline-item {
    display: grid;
    grid-template-columns: 110px minmax(0, 1fr);
    gap: 12px;
    padding: 12px 0;
    border-top: 1px solid var(--line);
}

.timeline-item:first-child {
    border-top: 0;
}

.timeline-item strong,
.timeline-item span {
    display: block;
}

.timeline-item div span {
    margin-top: 4px;
    color: var(--muted);
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.classification-toolbar > div,
.classification-document-heading,
.classification-review-actions,
.bulk-review-actions,
.queue-pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.queue-total {
    margin-left: 12px;
    color: var(--muted);
}

.queue-total strong {
    color: var(--text);
}

.classification-migration-warning {
    display: grid;
    gap: 6px;
    margin: 0;
}

.queue-filter-panel {
    margin-bottom: 18px;
}

.classification-filters {
    display: grid;
    grid-template-columns: minmax(240px, 1fr) minmax(150px, .35fr) minmax(170px, .4fr) auto;
    gap: 12px;
    align-items: end;
}

.classification-filter-actions {
    display: flex;
    gap: 8px;
}

.classification-layout {
    display: grid;
    grid-template-columns: minmax(340px, .55fr) minmax(520px, 1fr);
    gap: 18px;
    align-items: start;
}

.classification-queue-panel {
    padding: 0;
    overflow: hidden;
}

.classification-queue-head {
    padding: 18px;
    border-bottom: 1px solid var(--line);
}

.classification-queue-head p,
.classification-document-heading p {
    margin: 6px 0 0;
    font-size: 13px;
}

.compact-check {
    display: inline-flex;
    font-size: 12px;
    white-space: nowrap;
}

.compact-check input,
.queue-checkbox input,
.check-card input {
    width: 18px;
    min-height: 18px;
    margin: 0;
}

.bulk-review {
    margin: 14px;
    border: 1px solid #d6deda;
    border-radius: 8px;
    background: var(--surface-2);
}

.bulk-review summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 12px;
    color: var(--brand-strong);
    font-weight: 800;
    cursor: pointer;
}

.bulk-review[open] summary {
    border-bottom: 1px solid var(--line);
}

.bulk-review > .hint {
    margin: 12px 12px 0;
}

.bulk-review-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    padding: 12px;
}

.bulk-review-grid label {
    min-width: 0;
}

.bulk-subtype-field .check-line {
    min-height: 20px;
}

.bulk-review-actions {
    padding: 0 12px 12px;
    justify-content: flex-end;
}

.option-filter {
    min-height: 31px;
    padding: 5px 9px;
    font-size: 12px;
}

.classification-queue-list {
    border-top: 1px solid var(--line);
}

.classification-queue-item {
    position: relative;
    display: grid;
    grid-template-columns: 34px minmax(0, 1fr);
    min-width: 0;
    border-bottom: 1px solid var(--line);
    background: var(--surface);
}

.classification-queue-item:hover,
.classification-queue-item.active {
    background: #eef6f3;
}

.classification-queue-item.active {
    box-shadow: inset 4px 0 0 var(--brand);
}

.queue-checkbox {
    display: grid;
    place-items: start center;
    padding: 17px 0 0 8px;
}

.queue-item-link {
    display: grid;
    gap: 7px;
    min-width: 0;
    padding: 14px 14px 14px 6px;
}

.queue-item-link strong,
.queue-item-link small {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.queue-item-link small {
    color: var(--muted);
    font-size: 12px;
}

.queue-item-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
}

.queue-empty,
.queue-selection-empty,
.preview-empty {
    padding: 32px 18px;
    text-align: center;
}

.queue-pagination {
    padding: 14px 18px;
    color: var(--muted);
    font-size: 13px;
}

.classification-review-column {
    display: grid;
    gap: 18px;
    min-width: 0;
}

.classification-document-heading {
    align-items: flex-start;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--line);
}

.classification-document-heading h2 {
    overflow-wrap: anywhere;
}

.classification-evidence {
    margin: 18px 0;
}

.classification-evidence h3 {
    margin-bottom: 10px;
    font-size: 15px;
}

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

.evidence-grid div {
    min-width: 0;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-2);
}

.evidence-grid span,
.evidence-grid strong {
    display: block;
}

.evidence-grid span {
    margin-bottom: 4px;
    color: var(--muted);
    font-size: 10px;
    font-weight: 800;
    text-transform: uppercase;
}

.evidence-grid strong {
    overflow: hidden;
    font-size: 12px;
    line-height: 1.45;
    text-overflow: ellipsis;
}

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

.classification-fields {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.classification-fields.three-columns {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.classification-fields select[multiple] {
    min-height: 132px;
}

.classification-review-form fieldset > .hint {
    margin-top: 12px;
}

.check-card {
    display: flex;
    align-items: center;
    align-self: end;
    min-height: 64px;
    padding: 10px;
    border: 1px solid #cbd6d1;
    border-radius: 8px;
    background: var(--surface-2);
}

.check-card span,
.check-card strong,
.check-card small {
    display: block;
}

.check-card small {
    margin-top: 3px;
    color: var(--muted);
    font-weight: 500;
}

.classification-review-actions {
    align-items: stretch;
}

.classification-review-actions > div {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.markdown-preview-panel .panel-head {
    align-items: flex-start;
}

.source-path {
    max-width: 640px;
    margin: 7px 0 0;
    overflow: hidden;
    color: var(--muted);
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 11px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.markdown-preview {
    overflow: auto;
    max-height: 680px;
    margin: 16px 0 0;
    padding: 16px;
    border: 1px solid #27302e;
    border-radius: 8px;
    color: #eaf3ef;
    background: #17201e;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 12px;
    line-height: 1.55;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

@media (min-width: 1001px) {
    .sidebar {
        position: sticky;
        top: 0;
        height: 100vh;
    }

    .sidebar-panel {
        overflow: hidden;
    }

    .nav {
        padding-right: 4px;
        overflow-y: auto;
        overscroll-behavior: contain;
        scrollbar-gutter: stable;
    }
}

@media (max-width: 1200px) {
    .classification-layout {
        grid-template-columns: 1fr;
    }

    .classification-queue-list {
        max-height: 520px;
        overflow-y: auto;
    }
}

@media (max-width: 1000px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: sticky;
        top: 0;
        z-index: 10;
        display: block;
        padding: 14px;
        box-shadow: 0 8px 24px rgba(17, 38, 35, .18);
    }

    .sidebar-toggle {
        display: inline-flex;
    }

    .sidebar-panel {
        gap: 18px;
        max-height: calc(100vh - 76px);
        padding: 14px 2px 4px;
        overflow: hidden;
        border-top: 1px solid rgba(255, 255, 255, .16);
    }

    .sidebar.js-enabled:not(.nav-open) .sidebar-panel {
        display: none;
    }

    .nav {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 16px;
        padding-right: 4px;
        overflow-y: auto;
        overscroll-behavior: contain;
    }

    .nav a {
        min-height: 44px;
    }

    .sidebar-footer {
        display: grid;
        margin-top: 0;
        padding-top: 16px;
        border-top: 1px solid rgba(255, 255, 255, .16);
    }

    .main {
        padding: 20px;
    }

    .metrics-grid,
    .content-grid,
    .split,
    .provider-grid,
    .metrics-grid.compact-metrics,
    .status-grid,
    .wizard-section {
        grid-template-columns: 1fr;
    }

    .process-hero,
    .matter-command {
        align-items: stretch;
        flex-direction: column;
    }

    .matter-command-actions {
        justify-content: flex-start;
    }
}

@media (max-width: 680px) {
    .nav {
        grid-template-columns: 1fr;
    }

    .toolbar,
    .search,
    .topbar,
    .quickbar,
    .quick-search,
    .panel-head,
    .form-actions,
    .action-stack,
    .inline-form,
    .search-page-form,
    .process-hero .actions {
        align-items: stretch;
        flex-direction: column;
    }

    .inline-form input {
        width: 100%;
    }

    .quickbar,
    .quick-search {
        width: 100%;
    }

    .quick-search-field {
        width: 100%;
    }

    .grid-form,
    .details,
    .search-page-form,
    .search-results {
        grid-template-columns: 1fr;
    }

    .span-2 {
        grid-column: span 1;
    }

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

    .timeline-item {
        grid-template-columns: 1fr;
    }

    .classification-filters,
    .bulk-review-grid,
    .classification-fields,
    .classification-fields.three-columns,
    .evidence-grid {
        grid-template-columns: 1fr;
    }

    .classification-toolbar > div,
    .classification-review-actions,
    .classification-review-actions > div,
    .bulk-review-actions,
    .queue-pagination {
        align-items: stretch;
        flex-direction: column;
    }

    .queue-total {
        margin: 0;
    }
}

@media (pointer: coarse) {
    button,
    .button,
    .nav a,
    .sidebar-toggle {
        min-height: 44px;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        transition-duration: .01ms !important;
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
    }
}

/* Analytics */
.analytics-page {
    display: grid;
    gap: 18px;
}

.metrics-grid.analytics-kpis {
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    margin-bottom: 0;
}

.analytics-kpis .metric {
    min-width: 0;
}

.analytics-kpis .metric strong {
    font-size: clamp(25px, 2.6vw, 34px);
    overflow-wrap: anywhere;
}

.analytics-kpis .metric small {
    line-height: 1.4;
}

.analytics-method-note,
.analytics-access-note {
    margin: 0;
}

.analytics-access-note {
    box-shadow: none;
}

.analytics-panel {
    display: grid;
    gap: 18px;
}

.analytics-panel-head {
    align-items: flex-start;
}

.analytics-heading-copy {
    min-width: 0;
}

.analytics-heading-copy p {
    max-width: 760px;
    margin: 7px 0 0;
    line-height: 1.5;
}

.analytics-export-actions {
    flex-shrink: 0;
    justify-content: flex-end;
}

.analytics-query-form {
    display: grid;
    gap: 16px;
}

.analytics-fieldset {
    padding: 16px;
    background: var(--surface-2);
}

.analytics-axis-grid,
.analytics-filter-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
}

.analytics-filter-hint {
    margin-top: 12px;
}

.analytics-form-actions {
    justify-content: flex-start;
}

.analytics-query-context {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px 14px;
    padding: 12px 16px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
}

.analytics-query-context p {
    margin: 0;
}

.analytics-filter-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.analytics-filter-chips li {
    padding: 5px 9px;
    border: 1px solid #cbd6d1;
    border-radius: 999px;
    color: var(--brand-strong);
    background: #eaf2ef;
    font-size: 12px;
    font-weight: 800;
}

.analytics-grand-total {
    display: grid;
    flex-shrink: 0;
    justify-items: end;
    gap: 4px;
    margin: 0;
}

.analytics-grand-total span {
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
}

.analytics-grand-total strong {
    color: var(--brand-strong);
    font-size: 24px;
}

.analytics-table-wrap {
    max-height: min(70vh, 720px);
    border: 1px solid var(--line);
    border-radius: 8px;
    overscroll-behavior: contain;
}

.analytics-pivot-table {
    min-width: 720px;
}

.analytics-pivot-table th,
.analytics-pivot-table td {
    min-width: 145px;
    background: var(--surface);
}

.analytics-pivot-table thead th {
    position: sticky;
    top: 0;
    z-index: 3;
    border-bottom-color: #cbd6d1;
    background: var(--surface-2);
}

.analytics-pivot-table tfoot th,
.analytics-pivot-table tfoot td {
    position: sticky;
    bottom: 0;
    z-index: 3;
}

.analytics-pivot-table .analytics-sticky-column {
    position: sticky;
    left: 0;
    z-index: 2;
    min-width: 190px;
    max-width: 270px;
    box-shadow: 1px 0 0 var(--line);
}

.analytics-pivot-table thead .analytics-sticky-column {
    z-index: 5;
    background: var(--surface-2);
}

.analytics-pivot-table tfoot .analytics-sticky-column {
    z-index: 5;
}

.analytics-number-heading,
.analytics-number-cell {
    text-align: right;
}

.analytics-cell-button {
    display: grid;
    justify-items: end;
    gap: 4px;
    width: 100%;
    min-height: 48px;
    padding: 7px 9px;
    border: 1px solid transparent;
    border-radius: 7px;
    color: var(--text);
    background: transparent;
    cursor: pointer;
}

.analytics-cell-button:hover {
    border-color: #b8d2cc;
    color: var(--brand-strong);
    background: #edf7f4;
}

.analytics-cell-button strong,
.analytics-cell-button small {
    display: block;
}

.analytics-cell-button small {
    color: var(--muted);
    font-size: 11px;
}

.analytics-zero {
    display: block;
    padding: 7px 9px;
    color: #889298;
}

.analytics-total-cell {
    color: var(--text);
    background: #f0f4f2 !important;
}

.analytics-grand-total-cell {
    color: #ffffff;
    background: var(--brand-strong) !important;
}

.analytics-grand-total-cell strong {
    color: #ffffff;
}

.analytics-empty-cell {
    padding: 30px 18px;
    text-align: center;
}

body.analytics-dialog-open {
    overflow: hidden;
}

.analytics-dialog {
    position: fixed;
    inset: 0;
    z-index: 50;
    width: min(1120px, calc(100% - 32px));
    max-width: none;
    max-height: calc(100vh - 32px);
    margin: auto;
    padding: 0;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 10px;
    color: var(--text);
    background: var(--surface);
    box-shadow: 0 28px 80px rgba(17, 38, 35, .30);
}

.analytics-dialog:not([open]) {
    display: none;
}

.analytics-dialog[open] {
    display: block;
}

.analytics-dialog::backdrop {
    background: rgba(17, 27, 28, .62);
}

.analytics-dialog-card {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    max-height: calc(100vh - 34px);
}

.analytics-dialog-header,
.analytics-dialog-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 16px 18px;
}

.analytics-dialog-header {
    align-items: flex-start;
    border-bottom: 1px solid var(--line);
}

.analytics-dialog-header h2,
.analytics-dialog-header p,
.analytics-dialog-footer p {
    margin: 0;
}

.analytics-dialog-header p {
    margin-top: 5px;
}

.analytics-dialog-body {
    min-height: 190px;
    padding: 16px 18px;
    overflow: auto;
}

.analytics-dialog-status {
    margin: 0;
    color: var(--muted);
}

.analytics-dialog-status.is-error {
    color: var(--red);
    font-weight: 800;
}

.analytics-retry {
    margin-top: 12px;
}

.analytics-drilldown-table-wrap {
    margin-top: 2px;
}

.analytics-drilldown-table {
    min-width: 780px;
}

.analytics-drilldown-table a {
    color: var(--brand-strong);
    font-weight: 800;
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 3px;
}

.analytics-dialog-footer {
    border-top: 1px solid var(--line);
    background: var(--surface-2);
}

.analytics-dialog-footer .actions {
    justify-content: flex-end;
}

@media (max-width: 1000px) {
    .metrics-grid.analytics-kpis,
    .analytics-axis-grid,
    .analytics-filter-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 680px) {
    .metrics-grid.analytics-kpis,
    .analytics-axis-grid,
    .analytics-filter-grid {
        grid-template-columns: 1fr;
    }

    .analytics-export-actions,
    .analytics-form-actions,
    .analytics-dialog-header,
    .analytics-dialog-footer {
        align-items: stretch;
        flex-direction: column;
    }

    .analytics-export-actions .button,
    .analytics-form-actions .button {
        width: 100%;
    }

    .analytics-query-context {
        align-items: flex-start;
        flex-direction: column;
    }

    .analytics-filter-chips {
        width: 100%;
    }

    .analytics-grand-total {
        justify-items: start;
    }

    .analytics-dialog {
        width: calc(100% - 16px);
        max-height: calc(100vh - 16px);
    }

    .analytics-dialog-card {
        max-height: calc(100vh - 18px);
    }

    .analytics-dialog-header,
    .analytics-dialog-body,
    .analytics-dialog-footer {
        padding: 14px;
    }

    .analytics-dialog-footer .actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
        width: 100%;
    }
}

/* Document processing: visible progress without technical vocabulary. */
.brain-progress progress { width: 100%; height: 1rem; accent-color: var(--primary, #2563eb); }
.brain-progress-lead { font-size: 1.3rem; font-weight: 650; }
.brain-counts { margin: 1rem 0; }
.brain-story { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; margin: 1.25rem 0; }
.brain-story article { padding: 1rem; border: 1px solid var(--border, #dce2ea); border-radius: .75rem; overflow-wrap: anywhere; }
.brain-story h3 { margin-top: 0; font-size: 1rem; }
.brain-steps { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1rem; padding-left: 1.5rem; margin: 1.5rem 0; }
.brain-steps li { padding: .5rem; }
.brain-steps strong { display: block; margin-top: .5rem; }
.brain-progress details { margin-top: 1.25rem; }
.brain-progress summary, #profilo-esecuzione > summary { cursor: pointer; font-weight: 650; padding: .5rem 0; }
.brain-document-filters { display: flex; flex-wrap: wrap; gap: 1rem; margin: 1rem 0; }
.brain-document-filters label { flex: 1; min-width: 12rem; }
.brain-document-scroll { max-height: 32rem; overflow: auto; }
.brain-document-table { width: 100%; border-collapse: collapse; text-align: left; }
.brain-document-table th, .brain-document-table td { padding: .8rem; border-bottom: 1px solid var(--border, #dce2ea); vertical-align: top; overflow-wrap: anywhere; }
.brain-document-table td:first-child { min-width: 12rem; }
.brain-document-table [data-document-state="errors"] { color: #a12424; font-weight: 650; }
.brain-document-table [data-document-state="working"] { font-weight: 700; }
.brain-progress [hidden] { display: none !important; }
@media (max-width: 760px) {
    .brain-story, .brain-steps { grid-template-columns: 1fr; }
    .brain-document-table th, .brain-document-table td { padding: .5rem; }
}
