:root {
    color-scheme: light;
    --bg: #f4efe4;
    --panel: rgba(255, 252, 247, 0.88);
    --panel-border: rgba(56, 41, 24, 0.14);
    --text: #1f1a16;
    --muted: #6f6253;
    --accent: #b04f2d;
    --accent-dark: #7d2f16;
    --success: #21633c;
    --error: #a12e24;
    --shadow: 0 24px 60px rgba(63, 43, 23, 0.12);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
    color: var(--text);
    background:
        radial-gradient(circle at top left, rgba(176, 79, 45, 0.2), transparent 32%),
        linear-gradient(180deg, #efe7d6 0%, var(--bg) 45%, #efe8dc 100%);
}

h1,
h2,
h3 {
    font-family: Georgia, "Times New Roman", serif;
}

code,
pre {
    font-family: "Courier New", Courier, monospace;
}

button,
select,
textarea,
input {
    font-family: inherit;
}

.shell {
    width: min(1400px, calc(100% - 2.5rem));
    margin: 0 auto;
    padding: 1.25rem 0 1.75rem;
}

.shell-detail {
    width: min(1560px, calc(100% - 2.5rem));
}

.hero {
    padding: 0.25rem 0 0.9rem;
}

.hero-detail {
    padding-bottom: 1rem;
}

.hero-home {
    padding-bottom: 0.9rem;
}

.detail-topline {
    display: flex;
    align-items: center;
    gap: 1.25rem;
    margin-bottom: 0.7rem;
}

.back-link,
.invoice-link {
    color: var(--accent-dark);
    text-decoration: none;
}

.back-link:hover,
.back-link:focus-visible,
.invoice-link:hover,
.invoice-link:focus-visible {
    text-decoration: underline;
}

.eyebrow {
    margin: 0 0 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.18em;
    font-size: 0.72rem;
    color: var(--accent-dark);
}

.hero h1 {
    margin: 0;
    font-size: clamp(2.15rem, 4.6vw, 3.8rem);
    line-height: 0.96;
    font-weight: 600;
}

.hero-home h1 {
    font-size: clamp(1.75rem, 3.2vw, 2.7rem);
}

.lede {
    max-width: 44rem;
    margin: 0.5rem 0 0;
    font-size: 0.92rem;
    line-height: 1.45;
    color: var(--muted);
}

.status-strip {
    display: inline-flex;
    align-items: center;
    gap: 0.9rem;
    margin-top: 1rem;
    padding: 0.7rem 0.9rem;
    border: 1px solid var(--panel-border);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.5);
}

.hero-link-row {
    display: flex;
    align-items: center;
    gap: 1.25rem;
    margin: 0.8rem 0 0;
}

.status-label {
    font-size: 0.9rem;
    color: var(--muted);
}

.health-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
}

.health-badge::before {
    content: "";
    width: 0.7rem;
    height: 0.7rem;
    border-radius: 999px;
    background: currentColor;
}

.health-badge.loading {
    color: var(--muted);
}

.health-badge.ok {
    color: var(--success);
}

.health-badge.error {
    color: var(--error);
}

.panel {
    background: var(--panel);
    backdrop-filter: blur(8px);
    border: 1px solid var(--panel-border);
    border-radius: 16px;
    box-shadow: var(--shadow);
    padding: 0.85rem;
}

.panel-upload {
    margin-bottom: 0.85rem;
}

.panel-list {
    margin-top: 0.85rem;
}

.panel-head h2 {
    margin: 0;
    font-size: 1.18rem;
}

.panel-head-row {
    display: flex;
    justify-content: space-between;
    gap: 0.85rem;
    align-items: flex-start;
}

.detail-panel-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: flex-end;
}

.list-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    align-items: center;
    padding: 0.6rem 0 0.2rem;
}

.list-actions-sep {
    display: block;
    width: 1px;
    height: 1.4rem;
    background: rgba(56, 41, 24, 0.15);
    margin: 0 0.15rem;
}

.table-action:disabled {
    opacity: 0.38;
    cursor: not-allowed;
}

.panel-head p {
    margin: 0.25rem 0 0;
    font-size: 0.92rem;
    color: var(--muted);
}

.upload-form {
    margin-top: 1rem;
}

.dropzone {
    display: block;
    border: 1.5px dashed rgba(125, 47, 22, 0.35);
    border-radius: 16px;
    padding: 1rem;
    background: rgba(255, 255, 255, 0.55);
    cursor: pointer;
    transition: transform 160ms ease, border-color 160ms ease, background 160ms ease, box-shadow 160ms ease;
}

.dropzone input {
    display: none;
}

.dropzone.drag-active {
    transform: translateY(-2px) scale(1.01);
    border-color: var(--accent-dark);
    background: rgba(255, 247, 240, 0.95);
    box-shadow: 0 18px 32px rgba(125, 47, 22, 0.14);
}

.dropzone.busy {
    opacity: 0.8;
}

.dropzone-copy {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.dropzone-copy strong {
    font-size: 1rem;
}

#file-name {
    color: var(--muted);
}

.actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
    margin-top: 0.85rem;
}

button {
    border: 0;
    border-radius: 999px;
    padding: 0.78rem 1.1rem;
    font-size: 0.9rem;
    color: #fff8f2;
    background: linear-gradient(135deg, var(--accent-dark), var(--accent));
    cursor: pointer;
}

button:disabled {
    cursor: wait;
    opacity: 0.7;
}

a:focus-visible,
button:focus-visible,
input:focus-visible,
summary:focus-visible,
.dropzone:focus-within {
    outline: 2px solid rgba(125, 47, 22, 0.72);
    outline-offset: 3px;
}

.form-message {
    margin: 0;
    min-height: 1.25rem;
    color: var(--muted);
}

.form-message.error {
    color: var(--error);
}

.form-message.success {
    color: var(--success);
}

.progress-shell {
    position: relative;
    width: min(24rem, 100%);
    height: 0.55rem;
    margin-top: 0.55rem;
    overflow: hidden;
    border-radius: 999px;
    background: rgba(125, 47, 22, 0.12);
}

.progress-bar {
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--accent-dark), var(--accent));
}

.progress-bar-indeterminate {
    width: 45%;
    animation: progress-slide 1.15s ease-in-out infinite;
}

@keyframes progress-slide {
    0% {
        transform: translateX(-120%);
    }
    50% {
        transform: translateX(75%);
    }
    100% {
        transform: translateX(250%);
    }
}

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

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.85rem;
    margin-bottom: 0.85rem;
}

.detail-kpi-grid {
    margin-bottom: 1rem;
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.kpi-label,
.kpi-meta {
    margin: 0;
}

.kpi-label {
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
}

.kpi-value {
    margin: 0.45rem 0 0;
    font-size: clamp(1.5rem, 2.4vw, 2.2rem);
    line-height: 1.08;
    color: var(--accent-dark);
}

.kpi-value-small {
    font-size: clamp(1.2rem, 1.8vw, 1.65rem);
}

.kpi-meta {
    margin-top: 0.35rem;
    color: var(--muted);
    font-size: 0.86rem;
    line-height: 1.3;
}

.analytics-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.85rem;
    margin-bottom: 0.85rem;
}

.analytics-detail-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    margin-bottom: 0.85rem;
}

.panel-span-full {
    grid-column: 1 / -1;
}

.analytics-total,
.analytics-company {
    margin: 0.65rem 0 0;
    font-size: clamp(1.35rem, 2.8vw, 2rem);
    line-height: 1.1;
    color: var(--accent-dark);
}

.analytics-subcopy {
    margin: 0.25rem 0 0;
    font-size: 0.92rem;
    color: var(--muted);
}

.analytics-link {
    color: var(--accent-dark);
    text-decoration: none;
    border-bottom: 1px solid rgba(154, 94, 53, 0.28);
}

.analytics-link:hover,
.analytics-link:focus-visible {
    color: var(--accent);
    border-bottom-color: rgba(154, 94, 53, 0.7);
}

.analytics-link-hero {
    border-bottom-width: 2px;
}

.analytics-disclosure {
    display: block;
}

.analytics-summary {
    display: block;
    list-style: none;
    cursor: pointer;
}

.analytics-summary::-webkit-details-marker {
    display: none;
}

.analytics-summary .panel-head {
    position: relative;
    padding-right: 1.75rem;
}

.analytics-summary .panel-head::after {
    content: "▾";
    position: absolute;
    top: 0.05rem;
    right: 0;
    font-size: 1rem;
    color: var(--muted);
    transition: transform 160ms ease;
}

.analytics-disclosure:not([open]) .panel-head::after {
    transform: rotate(-90deg);
}

.analytics-disclosure > .invoice-list,
.analytics-disclosure > .empty-copy,
.analytics-disclosure > .detail-list,
.analytics-disclosure > .status-banner {
    margin-top: 0.7rem;
}

.analytics-table td:last-child,
.analytics-table th:last-child {
    text-align: left;
}

.active-filters {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin: 0 0 0.75rem;
    padding: 0.65rem 0.8rem;
    border-radius: 16px;
    background: rgba(255, 248, 238, 0.85);
    border: 1px solid rgba(154, 94, 53, 0.14);
}

.filter-form {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr 1fr 1fr 1fr auto;
    gap: 0.7rem;
    margin: 0.85rem 0 0.75rem;
    padding: 0.75rem;
    border-radius: 16px;
    background: rgba(255, 248, 238, 0.72);
    border: 1px solid rgba(154, 94, 53, 0.12);
}

.filter-field {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.filter-field-search {
    /* naturally gets the 2fr column, no span needed */
}

.filter-field span {
    font-size: 0.76rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
}

.filter-field input {
    width: 100%;
    min-height: 2.35rem;
    padding: 0.55rem 0.75rem;
    border: 1px solid rgba(56, 41, 24, 0.12);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.85);
    color: var(--text);
    font-size: 0.92rem;
}

.filter-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: end;
    gap: 0.5rem;
}

.active-filters-copy {
    margin: 0;
    font-size: 0.92rem;
    color: var(--muted);
}

.filter-chip {
    display: inline-flex;
    align-items: center;
    margin-left: 0.45rem;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    background: rgba(154, 94, 53, 0.1);
    color: var(--accent-dark);
    font-size: 0.92rem;
}

.detail-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
    margin-bottom: 1rem;
}

.detail-layout {
    display: grid;
    grid-template-columns: minmax(0, 1.12fr) minmax(20rem, 0.88fr);
    gap: 1rem;
    align-items: start;
    margin-bottom: 1rem;
}

.detail-main-column {
    min-width: 0;
}

.detail-preview-column {
    position: sticky;
    top: 0.75rem;
}

.panel-pdf-preview {
    padding-bottom: 0.9rem;
}

.pdf-frame-shell {
    margin-top: 0.85rem;
    overflow: hidden;
    border-radius: 16px;
    border: 1px solid rgba(56, 41, 24, 0.1);
    background: rgba(255, 255, 255, 0.68);
}

.pdf-frame {
    display: block;
    width: 100%;
    height: min(74vh, 66rem);
    border: 0;
    background: white;
}

.summary-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
    margin: 0.95rem 0 0;
}

.summary-list.empty {
    grid-template-columns: 1fr;
}

.summary-list div {
    padding: 0.75rem 0.85rem;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.65);
    border: 1px solid rgba(56, 41, 24, 0.08);
}

.summary-list dt {
    margin: 0;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
}

.summary-list dd {
    margin: 0.35rem 0 0;
    font-size: 0.96rem;
    word-break: break-word;
}

.detail-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
    margin: 0.95rem 0 0;
}

.detail-list div {
    padding: 0.75rem 0.85rem;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.65);
    border: 1px solid rgba(56, 41, 24, 0.08);
}

.detail-list dt {
    margin: 0;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
}

.detail-list dd {
    margin: 0.35rem 0 0;
    font-size: 0.96rem;
}

.amount-emphasis {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--accent-dark);
}

.raw-response {
    margin: 0.95rem 0 0;
    min-height: 18rem;
    padding: 0.85rem;
    overflow: auto;
    border-radius: 16px;
    background: #1e1d1a;
    color: #f3eee7;
    font-size: 0.92rem;
    line-height: 1.5;
}

.invoice-list {
    margin-top: 0.7rem;
    overflow-x: auto;
}

.invoice-list.empty {
    display: block;
    color: var(--muted);
}

.invoice-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
    background: rgba(255, 255, 255, 0.58);
    border-radius: 12px;
    overflow: hidden;
}

.invoice-table th,
.invoice-table td {
    padding: 0.55rem 0.65rem;
    text-align: left;
    border-bottom: 1px solid rgba(56, 41, 24, 0.08);
    vertical-align: middle;
}

.invoice-table th {
    font-size: 0.74rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
    background: rgba(244, 239, 228, 0.95);
}

.table-subcopy {
    display: inline-block;
    margin-top: 0.2rem;
    color: var(--muted);
    font-size: 0.82rem;
    line-height: 1.35;
}

.table-nowrap {
    white-space: nowrap;
}

.matter-description-cell {
    min-width: 24rem;
    white-space: normal;
}

.sortable-link {
    color: inherit;
    text-decoration: none;
}

.sortable-link:hover,
.sortable-link.active {
    color: var(--accent-dark);
    text-decoration: underline;
}

.sortable-link:focus-visible {
    color: var(--accent-dark);
    text-decoration: underline;
}

.sortable-link.active::after {
    content: " ↑";
    font-size: 0.75em;
    opacity: 0.65;
    text-decoration: none;
    display: inline-block;
}

.sortable-link.active.sort-desc::after {
    content: " ↓";
}

.invoice-table tbody tr:last-child td {
    border-bottom: 0;
}

.invoice-table tbody tr[data-href] {
    cursor: pointer;
    transition: background 120ms ease;
}

.invoice-table tbody tr[data-href]:hover {
    background: rgba(176, 79, 45, 0.06);
}

.invoice-select-cell {
    width: 1%;
    text-align: center;
}

.invoice-select-checkbox {
    width: 1rem;
    height: 1rem;
    accent-color: var(--accent-dark);
    cursor: pointer;
}

.invoice-detail-table td {
    vertical-align: top;
}

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

.action-menu {
    position: relative;
    display: inline-block;
}

.action-menu-trigger {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    list-style: none;
    cursor: pointer;
}

.action-menu-trigger::-webkit-details-marker {
    display: none;
}

.action-menu-trigger::after {
    content: "▾";
    font-size: 0.7rem;
}

.action-menu-panel {
    position: absolute;
    top: calc(100% + 0.35rem);
    right: 0;
    z-index: 10;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    min-width: 8.5rem;
    padding: 0.55rem;
    border: 1px solid var(--panel-border);
    border-radius: 14px;
    background: rgba(255, 252, 247, 0.98);
    box-shadow: 0 18px 32px rgba(63, 43, 23, 0.14);
}

.action-menu:not([open]) .action-menu-panel {
    display: none;
}

.table-action {
    padding: 0.38rem 0.68rem;
    font-size: 0.75rem;
}

.table-action-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    color: #fff8f2;
    background: linear-gradient(135deg, var(--accent-dark), var(--accent));
    text-decoration: none;
}

.table-action-secondary {
    color: var(--accent-dark);
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid rgba(125, 47, 22, 0.16);
}

.table-action-danger {
    background: linear-gradient(135deg, #7f1d1d, #b91c1c);
}

.detail-upload-form {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
    margin-top: 0.85rem;
}

.detail-upload-form input[type="file"] {
    max-width: 100%;
}

.detail-dropzone {
    width: min(32rem, 100%);
}

.attached-files {
    margin-top: 1rem;
}

.attached-files h3 {
    margin: 0 0 0.75rem;
    font-size: 1rem;
}

.attached-file-list {
    margin: 0;
    padding: 0;
    list-style: none;
}

.attached-file-list li {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.75rem 0;
    border-top: 1px solid rgba(56, 41, 24, 0.08);
}

.attached-file-list li:first-child {
    border-top: 0;
}

.panel-detail-table {
    margin-top: 1rem;
}

.detail-break {
    word-break: break-word;
}

.narrative-cell {
    max-width: 32rem;
    min-width: 10rem;
}

.narrative-text {
    display: -webkit-box;
    -webkit-line-clamp: 4;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.kpi-value-ok {
    color: var(--success);
}

.kpi-value-error {
    color: var(--error);
}

.kpi-value-neutral {
    color: var(--muted);
}

/* ── Reports page ── */
.reports-kpi-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.pct-change {
    font-size: 0.83rem;
    font-weight: 600;
    white-space: nowrap;
}

.pct-up {
    color: var(--error);
}

.pct-down {
    color: var(--success);
}

.active-dot {
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--success);
    margin-left: 5px;
    vertical-align: middle;
    flex-shrink: 0;
}

.active-matter-legend {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
}

.empty-copy {
    margin: 0.85rem 0 0;
    color: var(--muted);
}

.table-total-line {
    margin: 0.5rem 0 0;
    text-align: right;
    font-size: 0.88rem;
    color: var(--muted);
}

.table-total-line strong {
    color: var(--accent-dark);
}

.check-ok {
    color: var(--success);
}

.check-error {
    color: var(--error);
}

.check-dot {
    display: inline-block;
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 50%;
    vertical-align: middle;
    margin-left: 0.3rem;
    flex-shrink: 0;
}

.check-dot-ok { background: var(--success); }
.check-dot-error { background: var(--error); }
.check-dot-neutral { background: var(--muted); opacity: 0.45; }

.status-banner {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1rem;
    align-items: center;
    margin-top: 1rem;
    padding: 0.85rem 1rem;
    border-radius: 14px;
    border: 1px solid rgba(56, 41, 24, 0.08);
}

.status-banner-ok {
    background: rgba(33, 99, 60, 0.08);
    color: var(--success);
}

.status-banner-error {
    background: rgba(161, 46, 36, 0.08);
    color: var(--error);
}

.status-banner-neutral {
    background: rgba(111, 98, 83, 0.08);
    color: var(--muted);
}

.status-pill {
    display: inline-flex;
    align-items: center;
    min-height: 2rem;
    padding: 0.2rem 0.7rem;
    border-radius: 999px;
    font-size: 0.9rem;
    font-weight: 700;
}

.status-pill-ok {
    background: rgba(33, 99, 60, 0.12);
    color: var(--success);
}

.status-pill-error {
    background: rgba(161, 46, 36, 0.12);
    color: var(--error);
}

.status-pill-neutral {
    background: rgba(111, 98, 83, 0.12);
    color: var(--muted);
}

@media (max-width: 1180px) {
    .analytics-detail-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .filter-form {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .filter-field-search {
        grid-column: 1 / -1;
    }

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

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

    .detail-preview-column {
        position: static;
    }

    .pdf-frame {
        height: 68vh;
    }
}

/* ── Filter toggle (mobile only) ───────────────────────────────── */
.filter-toggle-btn {
    display: none;
}

/* ── Compact layout ≤ 960px (half-screen MacBook and below) ─────── */
@media (max-width: 960px) {
    .shell {
        width: min(100% - 1rem, 1080px);
        padding-top: 1rem;
    }

    /* Grids collapse to single column */
    .kpi-grid,
    .results-grid,
    .analytics-grid,
    .analytics-detail-grid,
    .summary-list,
    .detail-grid,
    .detail-list {
        grid-template-columns: 1fr;
    }

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

    .table-total-line {
        text-align: left;
    }

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

    .detail-preview-column {
        position: static;
    }

    .pdf-frame {
        height: 70vh;
    }

    .attached-file-list li {
        flex-direction: column;
    }

    .status-strip,
    .actions {
        align-items: flex-start;
    }

    /* ── Panel head row: keep horizontal but wrap tightly ── */
    .panel-head-row {
        flex-wrap: wrap;
        gap: 0.6rem;
    }

    .panel-head-row > div {
        flex: 1 1 auto;
    }

    /* ── Active filters ── */
    .active-filters {
        align-items: flex-start;
        flex-direction: column;
    }

    /* ── Filter toggle button ── */
    .filter-toggle-btn {
        display: flex;
        align-items: center;
        width: 100%;
        margin: 0.75rem 0 0;
        padding: 0.6rem 0.85rem;
        border-radius: 12px;
        font-size: 0.88rem;
        font-weight: 500;
        color: var(--accent-dark);
        background: rgba(255, 248, 238, 0.85);
        border: 1px solid rgba(154, 94, 53, 0.18);
        cursor: pointer;
        text-align: left;
        gap: 0.4rem;
    }

    .filter-toggle-btn::after {
        content: "▾";
        margin-left: auto;
        opacity: 0.55;
        transition: transform 200ms ease;
        font-size: 0.85em;
    }

    .filter-toggle-btn.active::after {
        transform: rotate(180deg);
    }

    /* ── Filter form: hidden on mobile until toggled ── */
    .filter-form:not(.filter-open) {
        display: none;
    }

    .filter-form {
        grid-template-columns: 1fr;
        margin-top: 0.5rem;
    }

    .filter-field-search {
        grid-column: auto;
    }

    .filter-actions {
        align-items: stretch;
    }

    .filter-actions .table-action,
    .filter-actions .table-action-link {
        width: 100%;
    }


    /* ── Analytics tables: generic label:value card layout ── */
    .analytics-table,
    .analytics-table thead,
    .analytics-table tbody,
    .analytics-table tr,
    .analytics-table th,
    .analytics-table td {
        display: block;
    }

    .analytics-table thead {
        display: none;
    }

    .analytics-table tbody {
        display: grid;
        gap: 0.5rem;
    }

    .analytics-table tr {
        border: 1px solid rgba(56, 41, 24, 0.07);
        border-radius: 10px;
        background: rgba(255, 255, 255, 0.6);
        overflow: hidden;
    }

    .analytics-table td {
        display: flex;
        justify-content: space-between;
        gap: 1rem;
        padding: 0.55rem 0.75rem;
        text-align: right;
        border-bottom: 1px solid rgba(56, 41, 24, 0.07);
    }

    .analytics-table td::before {
        content: attr(data-label);
        flex: 0 0 5.5rem;
        text-align: left;
        font-size: 0.74rem;
        text-transform: uppercase;
        letter-spacing: 0.06em;
        color: var(--muted);
    }

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

    .matter-description-cell {
        min-width: 0;
    }

    /* ── Invoice detail tables: label:value card layout ── */
    .invoice-detail-table,
    .invoice-detail-table thead,
    .invoice-detail-table tbody,
    .invoice-detail-table tr,
    .invoice-detail-table th,
    .invoice-detail-table td {
        display: block;
    }

    .invoice-detail-table thead {
        display: none;
    }

    .invoice-detail-table tbody {
        display: grid;
        gap: 0.5rem;
    }

    .invoice-detail-table tr {
        border: 1px solid rgba(56, 41, 24, 0.08);
        border-radius: 12px;
        background: rgba(255, 255, 255, 0.65);
        overflow: hidden;
    }

    .invoice-detail-table td {
        display: flex;
        justify-content: space-between;
        gap: 1rem;
        padding: 0.6rem 0.8rem;
        text-align: right;
        border-bottom: 1px solid rgba(56, 41, 24, 0.07);
    }

    .invoice-detail-table td::before {
        content: attr(data-label);
        flex: 0 0 6rem;
        text-align: left;
        font-size: 0.74rem;
        text-transform: uppercase;
        letter-spacing: 0.06em;
        color: var(--muted);
    }

    .invoice-detail-table tr td:last-child {
        border-bottom: 0;
    }

    /* ── Invoice list table: compact 2-row cards ── */
    .invoice-list-table,
    .invoice-list-table thead,
    .invoice-list-table tbody,
    .invoice-list-table tr,
    .invoice-list-table th,
    .invoice-list-table td {
        display: block;
    }

    .invoice-list-table thead {
        display: none;
    }

    .invoice-list-table tbody {
        display: grid;
        gap: 0.5rem;
    }

    .invoice-list-table tr {
        display: grid;
        grid-template-columns: 1.25rem 1fr auto;
        grid-template-rows: auto auto;
        column-gap: 0.65rem;
        row-gap: 0.15rem;
        padding: 0.75rem 0.9rem;
        border: 1px solid rgba(56, 41, 24, 0.08);
        border-radius: 14px;
        background: rgba(255, 255, 255, 0.72);
        cursor: pointer;
        transition: background 120ms ease;
    }

    .invoice-list-table tr:hover,
    .invoice-list-table tr:active {
        background: rgba(176, 79, 45, 0.07);
    }

    .invoice-list-table td {
        display: block;
        padding: 0;
        border: none;
        text-align: left;
    }

    .invoice-list-table td::before {
        display: none;
    }

    /* Col 1 (checkbox) — left, spans both rows */
    .invoice-list-table .invoice-select-cell {
        grid-column: 1;
        grid-row: 1 / span 2;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Col 2 (Company) — row 1, center */
    .invoice-list-table td:nth-child(2) {
        grid-column: 2;
        grid-row: 1;
        font-weight: 600;
        font-size: 0.9rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* Col 3 (Matter) — row 2, center */
    .invoice-list-table td:nth-child(3) {
        grid-column: 2;
        grid-row: 2;
        font-size: 0.78rem;
        color: var(--muted);
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .invoice-list-table td:nth-child(3) br,
    .invoice-list-table td:nth-child(3) .table-subcopy {
        display: none;
    }

    /* Col 4 (Date) — row 2, right */
    .invoice-list-table td:nth-child(4) {
        grid-column: 3;
        grid-row: 2;
        font-size: 0.78rem;
        color: var(--muted);
        text-align: right;
        white-space: nowrap;
    }

    /* Col 5 (Invoice #) — hidden; row click navigates */
    .invoice-list-table td:nth-child(5) {
        display: none;
    }

    /* Col 6 (Amount) — row 1, right */
    .invoice-list-table td:nth-child(6) {
        grid-column: 3;
        grid-row: 1;
        text-align: right;
        font-weight: 600;
        font-size: 0.9rem;
        white-space: nowrap;
    }

    .invoice-list-table td:nth-child(6) br,
    .invoice-list-table td:nth-child(6) .table-subcopy {
        display: none;
    }
}
