/* =====================================================================
   Debt Minder for Sage Pastel - DEMO stylesheet (v2)
   Refreshed palette, contrast, transitions, and animations
   ===================================================================== */

:root {
    --bg-darkest:   #0a1f1b;
    --bg-dark:      #0d2622;
    --bg-mid:       #0f2e29;
    --surface:      #162e28;          /* cards, panels, table rows */
    --surface-2:    #1a3830;          /* hover / nested surface */
    --accent:       #2dd4a0;          /* primary action / highlight */
    --accent-soft:  rgba(45, 212, 160, 0.12);
    --accent-mid:   rgba(45, 212, 160, 0.22);
    --accent-line:  rgba(45, 212, 160, 0.35);
    --text:         #e8eeec;          /* WCAG AA on dark bg */
    --text-muted:   rgba(232, 238, 236, 0.62);
    --text-dim:     rgba(232, 238, 236, 0.35);
    --border:       rgba(255, 255, 255, 0.10);
    --border-strong:rgba(255, 255, 255, 0.18);
    --danger:       #f87171;
    --warning:      #fbbf24;
    --darkest:      #0a1f1b;          /* legacy alias */
    --dark:         var(--surface);   /* legacy alias for button bg */
    --sidebar:      #0b211d;
    --sidebar-head: #081915;
    --row:          rgba(255, 255, 255, 0.02);
    --highlight:    rgba(45, 212, 160, 0.12);
}

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

html, body { margin: 0; padding: 0; height: 100%; }
html { scroll-behavior: smooth; }
html, body { scrollbar-color: var(--accent) var(--bg-dark); scrollbar-width: thin; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-track { background: var(--bg-dark); }
*::-webkit-scrollbar-thumb { background: var(--accent); border-radius: 4px; }

body {
    background: var(--bg-darkest);
    background: radial-gradient(circle at 30% 20%, #15413a 0%, #0d2622 45%, #0a1f1b 100%);
    background-repeat: no-repeat;
    background-attachment: fixed;
    background-size: cover;
    color: var(--text);
    font-family: "Segoe UI", "Inter", system-ui, -apple-system, sans-serif;
    font-size: 15px;
    line-height: 1.6;
    min-height: 100vh;
    padding: 20px;
    transition: background-color 200ms ease, color 200ms ease;
}

/* =====================================================================
   LIGHT THEME — variable overrides only.
   Activated by setting `data-theme="light"` on <html>.
   ===================================================================== */
:root[data-theme="light"] {
    --bg-darkest:   #f6faf8;
    --bg-dark:      #eef3f0;
    --bg-mid:       #ffffff;
    --surface:      #ffffff;
    --surface-2:    #f1f6f3;
    --accent:       #16a07a;          /* slightly darker accent for AA on white */
    --accent-soft:  rgba(22, 160, 122, 0.10);
    --accent-mid:   rgba(22, 160, 122, 0.20);
    --accent-line:  rgba(22, 160, 122, 0.35);
    --text:         #0f1f1b;
    --text-muted:   rgba(15, 31, 27, 0.65);
    --text-dim:     rgba(15, 31, 27, 0.45);
    --border:       rgba(15, 31, 27, 0.10);
    --border-strong:rgba(15, 31, 27, 0.18);
    --sidebar:      #ffffff;
    --sidebar-head: #f1f6f3;
    --row:          rgba(0, 0, 0, 0.02);
    --highlight:    rgba(22, 160, 122, 0.14);
}
:root[data-theme="light"] body {
    background: var(--bg-darkest);
    background: radial-gradient(circle at 30% 20%, #d8efe5 0%, #ecf3ef 45%, #f6faf8 100%);
}

/* Light-theme small corrections (things that can't be expressed as variables) */
:root[data-theme="light"] .table tbody tr:nth-child(even) td,
:root[data-theme="light"] .feedback-table tbody tr:nth-child(even) td,
:root[data-theme="light"] .doc-table tbody tr:nth-child(even) td {
    background: #f6faf8;
}
:root[data-theme="light"] .table tbody tr:hover td,
:root[data-theme="light"] .feedback-table tbody tr:hover td,
:root[data-theme="light"] .doc-table tbody tr:hover td {
    background: rgba(22, 160, 122, 0.06);
}

/* Status icon "discs" use a white inset on the dark theme — invert for light */
:root[data-theme="light"] td .fa-circle-exclamation { background: transparent; color: #dc2626; }
:root[data-theme="light"] td .fa-circle-info        { background: transparent; color: #1d4ed8; }

/* Chips: re-tint text so it reads on light tints */
:root[data-theme="light"] .chip--pdf   { background: rgba(220, 38, 38, 0.10);  color: #b91c1c; }
:root[data-theme="light"] .chip--word  { background: rgba(37, 99, 235, 0.10);  color: #1d4ed8; }
:root[data-theme="light"] .chip--excel { background: rgba(22, 163, 74, 0.10);  color: #15803d; }
:root[data-theme="light"] .chip--call  { background: rgba(13, 148, 136, 0.10); color: #0f766e; }
:root[data-theme="light"] .chip--sms   { background: rgba(126, 34, 206, 0.10); color: #7e22ce; }
:root[data-theme="light"] .chip--email { background: rgba(37, 99, 235, 0.10);  color: #1d4ed8; }

/* Pills: dark backgrounds work on light too, but soften them a touch */
:root[data-theme="light"] .pill--none {
    background: transparent;
    border-color: rgba(15, 31, 27, 0.18);
    color: var(--text-muted);
}

/* Filter header overlay tone */
:root[data-theme="light"] .filter-header   { background: rgba(22, 160, 122, 0.06); }
:root[data-theme="light"] .filter-header:hover { background: rgba(22, 160, 122, 0.12); }
:root[data-theme="light"] .filter-content,
:root[data-theme="light"] .filter-content2,
:root[data-theme="light"] .panel-content {
    background: #ffffff;
}

/* Drawer overlay: lighter on light theme */
:root[data-theme="light"] .drawer-overlay { background: rgba(0, 0, 0, 0.30); }

/* Demo-note hint legibility on light bg */
:root[data-theme="light"] .demo-note {
    color: rgba(0, 0, 0, 0.55);
    border-top-color: rgba(0, 0, 0, 0.08);
}

/* Soft drop shadow on cards in light theme for layering */
:root[data-theme="light"] .table td,
:root[data-theme="light"] .feedback-table td,
:root[data-theme="light"] .doc-table td,
:root[data-theme="light"] .table-header-bar .col,
:root[data-theme="light"] .feedback-table-header-bar .col,
:root[data-theme="light"] .attachment-table-header-bar .col,
:root[data-theme="light"] .allocations-table-header-bar .col,
:root[data-theme="light"] .switch-group,
:root[data-theme="light"] .filter-panel,
:root[data-theme="light"] .panel-header,
:root[data-theme="light"] .search-container form {
    box-shadow: 0 1px 2px rgba(15, 31, 27, 0.05);
}

/* Brand DM badge: invert against white */
:root[data-theme="light"] .brand .badge-dm {
    background: var(--accent);
    color: #ffffff;
    border-color: var(--accent);
}

/* Theme toggle button */
.theme-toggle {
    background: transparent;
    border: 1px solid var(--border-strong);
    color: var(--text);
    width: 40px; height: 40px; border-radius: 10px;
    cursor: pointer;
    display: inline-grid; place-items: center;
    font-size: 16px;
    margin-left: 8px;
}
.theme-toggle:hover { background: var(--surface-2); }
.theme-toggle .icon-light { display: none; }
:root[data-theme="light"] .theme-toggle .icon-dark  { display: none; }
:root[data-theme="light"] .theme-toggle .icon-light { display: inline; }

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

/* numeric alignment for currency cells */
.num, td.num, .amt { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }

/* Global interactive transitions */
button, a, .row, input, select, .table tbody tr, .feedback-table tbody tr, .doc-table tbody tr,
.pill, .chip, .toolbox button, .switch .slider, .switch .slider:before {
    transition: background-color 180ms ease, box-shadow 180ms ease, opacity 180ms ease,
                color 180ms ease, border-color 180ms ease, transform 120ms ease;
}

/* Focus rings — only suppress for mouse users; show clearly on keyboard nav */
*:focus { outline: none; }
*:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
    border-radius: 4px;
}
/* Extra contrast on dark backgrounds for round controls */
.customer-checkbox:focus-visible,
.select-checkbox:focus-visible,
.history-checkbox:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
}
.switch input:focus-visible + .slider {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
    border-radius: 50px;
}

/* Page-entry animation */
@keyframes dm-page-in {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}
body > .top-section,
body > .filter-panel,
body > .table-header-bar,
body > .table-container2,
body > .panel,
body > header,
body > .bottom-section,
body > .demo-note,
body > a.btn-primary2 {
    animation: dm-page-in 280ms ease-out both;
}
body > .filter-panel    { animation-delay: 40ms; }
body > .table-header-bar{ animation-delay: 80ms; }
body > .table-container2{ animation-delay: 120ms; }
body > .panel           { animation-delay: 60ms; }
body > .bottom-section  { animation-delay: 160ms; }

/* Pulse animation for warning icons */
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50%      { opacity: 0.5; }
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes dm-tooltip-in {
    from { opacity: 0; transform: translateY(4px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ---------------- TOP SECTION ---------------- */
.top-section {                                                         /* M1: sticky */
    padding: 14px 20px 16px;
    border-bottom: 1px solid rgba(45, 212, 160, 0.20);
    display: flex; justify-content: space-between; align-items: center;
    width: 100%; flex-wrap: wrap; gap: 12px;
    position: sticky; top: 0; z-index: 10;
    background: var(--bg-dark);
    margin: -20px -20px 0;          /* extend to body padding edges */
    padding-left: 20px; padding-right: 20px;
}
.button-group { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.brand {
    display: flex; align-items: center; gap: 12px;
    font-size: 20px; font-weight: 700; color: var(--text);
}
.brand .badge-dm {
    background: var(--bg-dark);
    color: var(--accent);
    border: 2px solid var(--accent);
    width: 36px; height: 36px; border-radius: 10px;
    display: grid; place-items: center; font-weight: 800;
    letter-spacing: 0.5px;
}
.brand .badge-dm:hover,
.brand:hover .badge-dm {
    box-shadow: 0 0 10px rgba(45, 212, 160, 0.4);
}

/* ---------------- BUTTONS ---------------- */
.btn-primary2 {
    overflow: hidden; border-radius: 20px; padding: 10px 18px; text-align: center; /* H3: ~44px tap target */
    background: var(--accent-soft);
    color: var(--text);
    border: 1px solid var(--accent-line);
    cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    font-size: 14px; font-weight: 500;
    min-height: 40px;
}
.btn-primary2:hover {
    background: var(--accent-mid);
    box-shadow: 0 0 0 3px var(--accent-soft);
}
.btn-primary2:active { transform: translateY(1px); }
.btn-primary2.sm {
    padding: 10px 18px;          /* H3: was 6px 16px; now meets WCAG 2.5.5 */
    border-radius: 20px; font-size: 13.5px;
    min-height: 40px;
}

/* M2: Primary-action variant — promote the main CTA */
.btn-primary2.primary-action {
    background: var(--accent);
    color: var(--bg-darkest);
    border-color: var(--accent);
    font-weight: 600;
}
.btn-primary2.primary-action:hover {
    background: #22c98e;
    box-shadow: 0 0 0 3px var(--accent-soft);
}
:root[data-theme="light"] .btn-primary2.primary-action {
    color: #ffffff;
}

/* Primary filled */
.btn-primary {
    background: var(--accent); color: var(--bg-darkest);
    border: 1px solid var(--accent); font-weight: 600;
    border-radius: 8px; padding: 9px 18px; cursor: pointer;
    display: inline-flex; align-items: center; gap: 8px;
}
.btn-primary:hover { background: #22c990; box-shadow: 0 4px 14px rgba(45, 212, 160, 0.35); }

/* Ghost (secondary) — H4: meets WCAG 2.5.5 (44x44) */
.btn-ghost {
    background: transparent; color: var(--text);
    border: 1px solid var(--border-strong); border-radius: 8px;
    padding: 10px 16px; cursor: pointer;
    min-height: 44px;
    display: inline-flex; align-items: center; gap: 8px;
}
.btn-ghost:hover { background: rgba(255, 255, 255, 0.05); border-color: var(--text); }

/* Danger ghost — H4: same tap-target rule */
.btn-danger {
    background: transparent; color: var(--danger);
    border: 1px solid var(--danger); border-radius: 8px;
    padding: 10px 16px; cursor: pointer;
    min-height: 44px;
    display: inline-flex; align-items: center; gap: 8px;
}
.btn-danger:hover { background: rgba(248, 113, 113, 0.08); }

/* Spinner inside button while generating */
.btn-primary2.is-loading,
.btn-primary.is-loading { pointer-events: none; opacity: 0.85; }
.btn-primary2.is-loading::before,
.btn-primary.is-loading::before {
    content: ""; width: 12px; height: 12px;
    border: 2px solid transparent; border-top-color: currentColor;
    border-radius: 50%; animation: spin 600ms linear infinite;
    margin-right: 8px;
}

.hamburger {
    background: transparent; border: none; color: var(--text);
    font-size: 1.4rem; cursor: pointer; line-height: 1;
    padding: 6px 10px; border-radius: 8px;
}
.hamburger:hover { background: rgba(255, 255, 255, 0.06); }

/* ---------------- TOGGLE SWITCHES ---------------- */
.switch-group { border-radius: 14px; padding: 6px 14px; background: var(--surface); border: 1px solid var(--border); }
.switch-group-line { display: flex; align-items: center; margin: 2px 0; }
.switch-group-text { color: var(--text); font-size: 14px; }

.switch { font-size: 8px; position: relative; display: inline-block; width: 3.5em; height: 2em; margin-right: 8px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
    position: absolute; cursor: pointer; inset: 0;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.20);
    border-radius: 50px;
    transition: background-color 280ms ease, border-color 280ms ease;
}
.slider:before {
    position: absolute; content: ""; height: 1.6em; width: 1.6em;
    top: 50%; left: 0.2em; transform: translateY(-50%);
    background: #fff; border-radius: 50px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4);
    transition: transform 280ms cubic-bezier(.175, .885, .32, 1.275);
}
.switch input:checked + .slider { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .slider:before { transform: translate(1.65em, -50%); }

/* ---------------- SEARCH ---------------- */
.search-container { display: flex; align-items: center; }
.search-container form {
    background: var(--surface); width: 300px; height: 42px;
    border-radius: 10px; border: 1px solid var(--border);
    display: flex; align-items: center;
}
.search-container form:focus-within {
    outline: 2px solid var(--accent); outline-offset: 2px;
    border-color: var(--accent);
}
.search-container input { all: unset; font: 15px system-ui; color: var(--text); height: 100%; width: 100%; padding: 8px 14px; }
.search-container input::placeholder { color: var(--text-muted); }
.search-container button { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 16px; padding-right: 14px; }
.search-container form:focus-within button { color: var(--accent); }

/* ---------------- FILTER PANEL ---------------- */
.filter-panel {
    width: 100%; margin-top: 14px; border-radius: 12px; overflow: hidden;
    border: 1px solid var(--border);
    border-left: 2px solid var(--accent);
}
.filter-header {
    padding: 12px 18px; font-size: 16px; font-weight: 600; color: var(--text); cursor: pointer;
    display: flex; justify-content: space-between; align-items: center;
    background: rgba(45, 212, 160, 0.07);
}
.filter-header:hover { background: rgba(45, 212, 160, 0.12); }
.filter-right { display: flex; align-items: center; gap: 14px; }
.filter-right .btn-primary2.clear-filters {           /* L4: specificity instead of !important */
    font-size: 13px; padding: 10px 14px; border-radius: 16px;
    background: transparent; border: 1px solid var(--border-strong); color: var(--text-muted);
    min-height: 40px;
}
.filter-right .btn-primary2.clear-filters:hover {
    border-color: var(--danger); color: var(--danger);
    background: transparent; box-shadow: none;
}
.filter-arrow { transition: transform 250ms ease; color: var(--accent); display: inline-block; }
.filter-content {
    max-height: 0; overflow: hidden; transition: max-height 350ms ease-in-out;
    padding-left: 20px; padding-right: 20px; background: rgba(13, 38, 34, 0.5);
}
.filter-grid {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 18px;
    padding: 20px 0;
}
.filter-item { position: relative; }
.filter-item label { color: var(--text-muted); font-size: 13px; margin-bottom: 6px; display: block; }
.filter-item input, .filter-item select {
    width: 100%; height: 38px; padding: 8px 12px;
    border-radius: 6px;
    color: var(--text);
    background: var(--bg-mid);
    border: 1px solid var(--border-strong);
    outline: none;
}
.filter-item input:focus, .filter-item select:focus {
    border-color: var(--accent);
    outline: 2px solid var(--accent); outline-offset: 1px;
}

.filter-panel2 { width: 100%; border-radius: 8px; overflow: hidden; border: 1px solid var(--border); }
.filter-header2 {
    padding: 9px 14px; font-size: 14px; color: var(--text); cursor: pointer;
    display: flex; justify-content: space-between; align-items: center;
    background: var(--surface);
}
.filter-header2:hover { background: var(--surface-2); }
.filter-content2 {
    max-height: 0; overflow: hidden; transition: max-height 220ms ease;
    padding: 0 18px; background: rgba(13, 38, 34, 0.5);
}
.filter-arrow2 { transition: transform 250ms ease; color: var(--accent); display: inline-block; }
.switch-group2 { display: flex; flex-direction: column; margin: 12px 0; gap: 6px; }
.switch-group-line2 { display: flex; align-items: center; }

/* ---------------- TABLE HEADER BARS ---------------- */
.table-header-bar, .feedback-table-header-bar, .attachment-table-header-bar, .allocations-table-header-bar {
    margin-top: 14px; display: grid; width: 100%; letter-spacing: 0.08em; gap: 0;
}
.table-header-bar {                                                       /* M1: sticky header */
    position: sticky; top: 92px; z-index: 9;
    background: var(--bg-dark);
    padding: 4px 0;
}
.table-header-bar {
    grid-template-columns: 9.1% 9% 27.1% 9.9% 9.9% 5.8% 6% 5.6% 8.6% 9%;
}
.feedback-table-header-bar { grid-template-columns: 11% 11% 12% 13.5% 14% 14% 13.5% 11%; }
.attachment-table-header-bar { grid-template-columns: 9.5% 11.5% 12% 29.5% 14% 12% 11.5%; }
.allocations-table-header-bar { grid-template-columns: repeat(8, 1fr) 1fr; }

.table-header-bar .col, .feedback-table-header-bar .col,
.attachment-table-header-bar .col, .allocations-table-header-bar .col {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 11px 12px; color: var(--text); /* H4: was --text-muted; meets AA on --surface */
    font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em;
    display: flex; align-items: center; font-size: 0.72rem;
    white-space: nowrap;
}

/* Cleaner select-all header cell */
.col.select-cell { gap: 8px; cursor: pointer; }
.col.select-cell:hover { background: var(--surface-2); }
.col.select-cell .select-count { margin-left: auto; color: var(--text-muted); font-weight: 500; } /* H4: was --text-dim */

/* ---------------- TABLES ---------------- */
.table-container2 { width: 100%; position: relative; padding: 6px 0; overflow-y: auto; }

.table, .feedback-table, .doc-table {
    width: 100%; font-size: 14px;
    border-collapse: separate !important; border-spacing: 0 4px !important;
    table-layout: fixed;   /* <colgroup> widths become authoritative -> aligns with grid header */
}
.table td, .feedback-table td, .doc-table td {
    overflow: hidden; text-overflow: ellipsis;
}
.table td, .feedback-table td, .doc-table td {
    background: var(--surface);
    border: none !important; padding: 11px 14px;
    color: var(--text); vertical-align: middle;
    border-top: 1px solid transparent; border-bottom: 1px solid transparent;
}
.table tbody tr, .feedback-table tbody tr, .doc-table tbody tr {
    cursor: pointer;
}
/* alternating row tint */
.table tbody tr:nth-child(even) td,
.feedback-table tbody tr:nth-child(even) td,
.doc-table tbody tr:nth-child(even) td {
    background: #142e28;
}
.table tbody tr:hover td,
.feedback-table tbody tr:hover td,
.doc-table tbody tr:hover td {
    background: rgba(45, 212, 160, 0.06);
}
.table tbody tr td:first-child,
.feedback-table tbody tr td:first-child,
.doc-table tbody tr td:first-child {
    border-top-left-radius: 8px; border-bottom-left-radius: 8px;
}
.table tbody tr td:last-child,
.feedback-table tbody tr td:last-child,
.doc-table tbody tr td:last-child {
    border-top-right-radius: 8px; border-bottom-right-radius: 8px;
}

/* Selected (highlighted) rows */
.highlight-row td {
    background: rgba(45, 212, 160, 0.12) !important;
    color: var(--text) !important;
}
.highlight-row td:first-child {
    box-shadow: inset 2px 0 0 var(--accent);
}

/* Discrepancy: amber left border on Total Due / Doc Total cells when amounts differ */
.row-discrepancy td:nth-child(4),
.row-discrepancy td:nth-child(5) {
    box-shadow: inset 2px 0 0 var(--warning);
}

/* Column widths for main customer table */
.main-table tbody tr td:nth-child(1){ width: 7.5%; }
.main-table tbody tr td:nth-child(2){ width: 7.8%; font-variant-numeric: tabular-nums; }
.main-table tbody tr td:nth-child(3){
    width: 24.4%; min-width: 180px; max-width: 280px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.main-table tbody tr td:nth-child(4),
.main-table tbody tr td:nth-child(5){
    width: 8.9%; font-variant-numeric: tabular-nums; text-align: right;
}
.main-table tbody tr td:nth-child(6){ width: 5.4%; text-align: center; }
.main-table tbody tr td:nth-child(7),
.main-table tbody tr td:nth-child(8){ width: 5.4%; text-align: center; }
.main-table tbody tr td:nth-child(9){ width: 7.1%; }
.main-table tbody tr td:nth-child(10){ width: 8%; }

/* Docs / Email icons — rendered as <button> for keyboard access (H2) */
.cell-icon {
    color: var(--text-muted);
    font-size: 16px;
    display: inline-flex; align-items: center; justify-content: center;
    width: 36px; height: 36px; border-radius: 8px;
    background: none; border: none;
    cursor: pointer;
}
.cell-icon:hover { color: var(--accent); transform: scale(1.2); background: var(--accent-soft); }
.cell-icon:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------------- CIRCLE CHECKBOXES ---------------- */
.select-checkbox, .customer-checkbox, .history-checkbox {
    appearance: none; -webkit-appearance: none; width: 18px; height: 18px;
    border-radius: 50%;
    border: 2px solid var(--accent); cursor: pointer; position: relative; outline: none;
    background: transparent; vertical-align: middle; margin-right: 6px;
    flex-shrink: 0;
}
.select-checkbox::after, .customer-checkbox::after, .history-checkbox::after {
    content: ""; position: absolute; top: 3px; left: 5px; width: 4px; height: 8px;
    border: solid var(--bg-darkest); border-width: 0 2px 2px 0; transform: rotate(45deg);
    opacity: 0;
}
.select-checkbox:hover, .customer-checkbox:hover, .history-checkbox:hover {
    box-shadow: 0 0 0 4px rgba(45, 212, 160, 0.15);
}
.select-checkbox:checked, .customer-checkbox:checked, .history-checkbox:checked {
    background: var(--accent); border-color: var(--accent);
}
.select-checkbox:checked::after, .customer-checkbox:checked::after, .history-checkbox:checked::after { opacity: 1; }

/* ---------------- STATUS ICONS / TOOLTIPS ---------------- */
.icon-tooltip { position: relative; display: inline-flex; align-items: center; }
td .fa-circle-exclamation {
    margin-left: 4px; border-radius: 10px; background: #fff; color: #ef4444;
    animation: pulse 2s ease-in-out infinite;
}
td .fa-circle-info {
    margin-left: 4px; border-radius: 10px; background: #fff; color: #2f7cef;
}
.floating-tooltip {
    position: fixed; background: var(--surface);
    color: var(--text); padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 6px; font-size: 12px; z-index: 9999; pointer-events: none; white-space: nowrap;
    opacity: 0; transition: opacity 150ms ease, transform 150ms ease; transform: translateY(4px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
}
.floating-tooltip.show { opacity: 1; transform: translateY(0); }

/* ---------------- SIDEBAR DRAWER ---------------- */
.drawer-overlay {
    position: fixed; inset: 0; background: rgba(0, 0, 0, 0.5);
    opacity: 0; visibility: hidden;
    transition: opacity 240ms ease, visibility 240ms ease;
    z-index: 1040;
}
.drawer-overlay.open { opacity: 1; visibility: visible; }
.drawer {
    position: fixed; top: 0; left: 0; height: 100%; width: 264px;
    background: var(--sidebar);
    border-right: 1px solid var(--border);
    transform: translateX(-100%);
    transition: transform 240ms ease-out;
    z-index: 1050;
    display: flex; flex-direction: column;
}
.drawer.open { transform: translateX(0); }
.drawer-header {
    padding: 18px 16px; background: var(--sidebar-head);
    border-bottom: 1px solid var(--border);
    display: flex; justify-content: space-between; align-items: center;
}
.drawer-header h2, .drawer-header h5 { color: var(--text); font-size: 18px; font-weight: 600; margin: 0; }
.drawer-header .close-x {
    background: none; border: none; color: var(--text);
    font-size: 22px; cursor: pointer; line-height: 1;
    min-width: 32px; min-height: 32px; border-radius: 50%;
    display: inline-grid; place-items: center;
}
.drawer-header .close-x:hover { background: rgba(255, 255, 255, 0.1); }
.drawer-body { padding: 14px 10px; flex: 1; display: flex; flex-direction: column; }
.drawer-body a {
    display: flex; align-items: center; color: var(--text);
    padding: 10px 14px; border-radius: 8px; margin-bottom: 4px;
    transition: padding-left 150ms ease, background-color 180ms ease, color 180ms ease;
    border-left: 3px solid transparent;
    font-size: 14px;
}
.drawer-body a:hover {
    background: rgba(255, 255, 255, 0.06);
    padding-left: 18px;
}
.drawer-body a.active {
    background: rgba(45, 212, 160, 0.10);
    border-left: 3px solid var(--accent);
    color: var(--text);
    font-weight: 600;
}
.drawer-body a.logout {
    margin-top: auto;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 0;
    padding-top: 14px; padding-bottom: 14px;
    color: var(--danger);
}
.drawer-body a.logout:hover { background: rgba(248, 113, 113, 0.10); padding-left: 14px; }

/* ---------------- PAGE HEADER / PANELS ---------------- */
.document-header {
    color: var(--text); margin-bottom: 22px;
    font-size: 1.6rem; font-weight: 700;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--accent);
    display: inline-block;
}
.panel { border: none; border-radius: 8px; margin-bottom: 16px; overflow: hidden; }
.panel-header {
    padding: 12px 16px; font-size: 15px; font-weight: 600;
    display: flex; align-items: center; justify-content: space-between; cursor: pointer;
    background: var(--surface);
    border-left: 3px solid var(--accent);
    color: var(--text);
}
.panel-header:hover { background: var(--surface-2); }
.panel-arrow { transition: transform 250ms ease; color: var(--accent); display: inline-block; }
.panel-content {
    overflow: hidden;
    transition: max-height 320ms ease-in-out;
    background: rgba(13, 38, 34, 0.6);
}

.form-grid { display: grid; gap: 18px; padding: 20px; }
.form-grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.form-grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
.field label { display: block; color: var(--text-muted); font-size: 13px; margin-bottom: 6px; }
.field input, .field select, .field textarea {
    width: 100%; height: 38px; padding: 8px 12px;
    border-radius: 6px;
    background: var(--bg-mid); color: var(--text);
    border: 1px solid var(--border-strong); outline: none;
}
.field textarea { height: auto; min-height: 100px; padding: 10px 12px; line-height: 1.5; }
.field input:focus, .field select:focus, .field textarea:focus {
    border-color: var(--accent);
    outline: 2px solid var(--accent); outline-offset: 1px;
}

/* Read-only info tile (for Outstanding / PTP amounts in feedback capture) */
.field input.info-tile {
    background: rgba(45, 212, 160, 0.06);
    border: 1px solid var(--accent-line);
    cursor: default;
    font-variant-numeric: tabular-nums;
}
.field input.info-tile:focus { outline: none; box-shadow: none; }

/* Date input with calendar icon hint */
.field .date-wrap { position: relative; }
.field .date-wrap input { padding-right: 36px; }
.field .date-wrap::after {
    content: "\f133"; /* fa calendar */
    font-family: "Font Awesome 6 Free"; font-weight: 400;
    position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
    color: var(--text-muted); pointer-events: none;
}

.action-buttons1 { display: flex; justify-content: flex-end; gap: 10px; padding: 0 20px 20px; }

/* Notes editor toolbar (feedback manager) */
.toolbox {
    padding: 8px; background: var(--surface);
    border: 1px solid var(--border);
    border-top-left-radius: 6px; border-top-right-radius: 6px;
    display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
    border-bottom: none;
}
.toolbox button {
    background: var(--surface-2);
    border: 1px solid rgba(255, 255, 255, 0.10);
    border-radius: 4px; padding: 4px 8px; min-width: 28px;
    color: var(--text); cursor: pointer;
    font-size: 13px;
}
.toolbox button:hover { background: rgba(45, 212, 160, 0.15); border-color: var(--accent-line); }
.editor-box {
    background: var(--bg-mid);
    border: 1px solid var(--border);
    border-top: none;
    border-bottom-left-radius: 6px; border-bottom-right-radius: 6px;
    padding: 12px; min-height: 120px;
    overflow-y: auto; line-height: 1.6; color: var(--text);
}
.editor-box:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }

/* ---------------- DROPZONE (document manager) ---------------- */
.dropzone {
    border: 2px dashed rgba(45, 212, 160, 0.4);
    border-radius: 8px; padding: 24px;
    text-align: center; color: var(--text-muted);
    cursor: pointer;
    background: rgba(45, 212, 160, 0.03);
    display: flex; flex-direction: column; align-items: center; gap: 8px;
}
.dropzone:hover, .dropzone.dragging {
    border-color: var(--accent);
    background: rgba(45, 212, 160, 0.08);
    color: var(--text);
}
.dropzone i { font-size: 24px; color: var(--accent); }
.dropzone .dz-file { color: var(--accent); font-weight: 600; }
.dropzone input[type=file] { display: none; }

/* ---------------- BOTTOM SECTION (details / allocations) ---------------- */
.bottom-section {
    display: flex; justify-content: space-between; align-items: flex-end;
    margin-top: 24px; gap: 20px; flex-wrap: wrap;
}
.right-btn-group { display: flex; gap: 10px; flex-wrap: wrap; }
.bottom-left-header { display: flex; gap: 16px; padding-bottom: 10px; }
.bottom-left-header .col, .bottom-left-label .col, .totals-table td {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 8px; padding: 7px 12px; color: var(--text);
    text-transform: capitalize; letter-spacing: 0.04em;
    display: flex; align-items: center;
    font-variant-numeric: tabular-nums;
}
.bottom-left-content { display: flex; align-items: flex-start; gap: 12px; }
.bottom-left-label { display: flex; flex-direction: column; gap: 5px; padding-top: 4px; }
.totals-table { border-collapse: separate; border-spacing: 0 5px; }
.totals-table td { justify-content: center; min-width: 120px; }
.col1 { margin-left: 8px; }

.amount-input {
    background: none !important; border: none !important; outline: none !important;
    color: inherit; width: 90px; -moz-appearance: textfield;
    text-align: center; font: inherit;
    font-variant-numeric: tabular-nums;
}
.amount-input::-webkit-outer-spin-button, .amount-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

/* Centered details table */
.center-table td { text-align: center; }
.center-table td.num, .center-table td.amt { text-align: right; }
.center-table td.neg { color: var(--danger); }
.center-table tfoot td {
    background: var(--surface);
    border-top: 2px solid rgba(45, 212, 160, 0.3) !important;
    font-weight: 700;
}

/* ---------------- PILLS / STATUS BADGES ---------------- */
.pill {
    padding: 4px 12px; border-radius: 999px;            /* M5: was 3px 12px */
    font-size: 12px; font-weight: 600;                   /* M5: was 11.5px */
    letter-spacing: 0.04em;
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-muted);
    white-space: nowrap;
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    border: 1px solid transparent;
    min-width: 88px;                                     /* M5: consistent column width */
    text-align: center;
}
.pill--none      { background: transparent; border-color: rgba(255, 255, 255, 0.15); color: var(--text-muted); }
.pill--followup  { background: #0d9488; color: #99f6e4; }
.pill--escalated { background: #b45309; color: #fde68a; }
.pill--resolved  { background: #166534; color: #bbf7d0; }
.pill--pending   { background: #334155; color: #cbd5e1; }
.pill--ptp       { background: #3730a3; color: #c7d2fe; }

/* Doc Type chips (document manager) */
.chip {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 3px 10px; border-radius: 999px;
    font-size: 11.5px; font-weight: 600; letter-spacing: 0.03em;
}
.chip::before { content: ""; display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.chip--pdf   { background: rgba(248, 113, 113, 0.15); color: #fca5a5; }
.chip--word  { background: rgba(96, 165, 250, 0.15); color: #93c5fd; }
.chip--excel { background: rgba(34, 197, 94, 0.15);  color: #86efac; }

/* Feedback type chips */
.chip--call  { background: rgba(45, 212, 160, 0.15); color: #99f6e4; }
.chip--sms   { background: rgba(192, 132, 252, 0.15); color: #d8b4fe; }
.chip--email { background: rgba(96, 165, 250, 0.15); color: #93c5fd; }

/* Truncated file paths */
.filename { font-family: ui-monospace, "Cascadia Mono", Menlo, monospace; font-size: 13px; }

/* PTP amount column emphasis */
.ptp-amt { color: var(--accent); font-variant-numeric: tabular-nums; }
.amt-right { text-align: right; font-variant-numeric: tabular-nums; }
.amt-neg   { color: var(--danger); font-variant-numeric: tabular-nums; }

/* Footer hint text
   H5: 0.55 opacity (~2.8:1) — intentional supplementary-chrome trade-off; full 4.5:1
   would make this footer note too visually loud. */
.demo-note {
    margin-top: 24px;
    padding: 12px 0;
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.55);
    text-align: center;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
}
.demo-note em { color: var(--accent); font-style: normal; }

/* ---------------- CUSTOMIZE / EDIT MODE (customer.html) ---------------- */
.customize-toggle {
    background: transparent; border: 1px solid var(--border-strong); color: var(--text);
    height: 40px; padding: 0 14px; border-radius: 10px; cursor: pointer;
    display: inline-flex; align-items: center; gap: 8px; font-size: 14px;
}
.customize-toggle:hover { background: var(--surface-2); }
.customize-toggle.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

.dm-customize-banner {
    display: none;
    margin: 14px 0;
    padding: 10px 16px;
    border-radius: 10px;
    background: var(--accent-soft);
    border: 1px solid var(--accent-line);
    color: var(--text);
    font-size: 13.5px;
    align-items: center; justify-content: space-between; gap: 10px;
}
body.editing .dm-customize-banner { display: flex; }
.dm-customize-banner-actions { display: flex; gap: 8px; }

/* H2: visually-hidden thead keeps screen-reader semantics while the styled
   .table-header-bar div above provides the visual header. */
table thead.sr-only-head,
table caption.visually-hidden { /* alias the existing utility for table elements */
    position: absolute;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap; border: 0;
}

/* Section panel — used for both demo and live customer.html */
.section-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    margin-bottom: 14px;
    overflow: hidden;
    transition: opacity .18s ease, transform .18s ease, box-shadow .18s ease;
}
.section-card.hidden-by-user { display: none; }
.section-card[data-hidden="1"] { opacity: 0.5; }
body.editing .section-card { box-shadow: 0 0 0 1px var(--accent-line); }
body.editing .section-card:hover { box-shadow: 0 0 0 1px var(--accent); }

.section-header {
    padding: 12px 16px;
    background: #4a6360;                /* H1: AA-safe mid-tone in both themes */
    border-bottom: 1px solid var(--border);
    border-left: 3px solid var(--accent);
    display: flex; align-items: center; gap: 10px;
}
:root[data-theme="light"] .section-header { background: #4a6360; }
.section-header h2, .section-header h3 {  /* M1: h2 added — see Medium pass */
    margin: 0; font-size: 15px; font-weight: 600;
    color: #ffffff;                     /* H1: explicit white -> 6.3:1 on #4a6360 */
    flex: 1;
}

.section-controls { display: none; align-items: center; gap: 4px; }
body.editing .section-controls { display: inline-flex; }

.section-controls button {
    background: transparent;
    border: 1px solid var(--border-strong);
    color: var(--text-muted);
    border-radius: 8px; cursor: pointer;
    width: 32px; height: 32px;
    display: inline-grid; place-items: center;
    transition: background-color 150ms ease, color 150ms ease, border-color 150ms ease;
}
.section-controls button:hover:not(:disabled) { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-line); }
.section-controls button:disabled { opacity: 0.35; cursor: not-allowed; }
.section-controls button.visibility-toggle.is-off {
    background: rgba(248, 113, 113, 0.10);
    border-color: rgba(248, 113, 113, 0.30);
    color: var(--danger);
}

.section-body { padding: 16px; }

/* KV grid (legacy summary) — kept for any callers that still use it */
.kv-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; }
.kv-grid .kv label { display: block; font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 4px; }
.kv-grid .kv span {
    font-size: 15px; color: var(--text);
    display: block;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    max-width: 100%;
}
.kv-grid .kv .amt { font-variant-numeric: tabular-nums; font-weight: 600; }

/* KPI tile row — key-metrics, customer-info, aging */
.kpi-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
    padding: 16px;
}
.kpi-row.compact .kpi-tile .kpi-value { font-size: 18px; }
.kpi-tile {
    background: var(--bg-mid);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px 16px;
    display: flex; flex-direction: column;
    transition: opacity .15s ease;
}
.kpi-tile[data-hidden="1"] { display: none; }
.kpi-tile .kpi-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    display: block;
    margin-bottom: 6px;
}
.kpi-tile .kpi-value {
    font-size: 22px;
    font-weight: 600;
    color: var(--text);
    font-variant-numeric: tabular-nums;
    display: block;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    max-width: 100%;
}
.kpi-tile .kpi-sub {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
    display: block;
}
.kpi-tile.is-warning .kpi-value { color: var(--warning); }
.kpi-tile.is-danger  .kpi-value { color: var(--danger); }

/* Aging stacked bar mini-chart inside its tile */
.aging-bar {
    height: 4px; background: rgba(255,255,255,0.08); border-radius: 999px;
    margin-top: 8px; overflow: hidden;
}
.aging-bar > span { display: block; height: 100%; border-radius: 999px; background: var(--accent); }
.aging-tile.b-current  .aging-bar > span { background: #10b981; }
.aging-tile.b-30       .aging-bar > span { background: #2dd4a0; }
.aging-tile.b-60       .aging-bar > span { background: #fbbf24; }
.aging-tile.b-90       .aging-bar > span { background: #f59e0b; }
.aging-tile.b-120      .aging-bar > span { background: #ef4444; }
:root[data-theme="light"] .aging-bar { background: rgba(0,0,0,0.06); }

/* ===================  LAYOUT PANEL (right slide-in)  =================== */
.layout-panel-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.45);
    opacity: 0; visibility: hidden;
    transition: opacity 220ms ease, visibility 220ms ease;
    z-index: 1045;
}
.layout-panel-overlay.open { opacity: 1; visibility: visible; }
:root[data-theme="light"] .layout-panel-overlay { background: rgba(0,0,0,0.30); }

.layout-panel {
    position: fixed; top: 0; right: 0; height: 100%; width: 360px; max-width: 92vw;
    background: var(--surface);
    border-left: 1px solid var(--border);
    transform: translateX(100%);
    transition: transform 260ms ease-out;
    z-index: 1050;
    display: flex; flex-direction: column;
    box-shadow: -10px 0 24px rgba(0,0,0,0.35);
}
.layout-panel.open { transform: translateX(0); }
.layout-panel-header {
    padding: 16px 18px;
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
}
.layout-panel-header h2 { margin: 0; font-size: 16px; font-weight: 600; color: var(--text); }
.layout-panel-header .close-x {
    background: none; border: none; color: var(--text);
    font-size: 22px; cursor: pointer; line-height: 1;
    min-width: 32px; min-height: 32px; border-radius: 50%;
    display: inline-grid; place-items: center;
}
.layout-panel-header .close-x:hover { background: rgba(255,255,255,0.10); }
:root[data-theme="light"] .layout-panel-header .close-x:hover { background: rgba(0,0,0,0.06); }

.layout-panel-body {
    padding: 14px; flex: 1; overflow-y: auto;
    display: flex; flex-direction: column; gap: 10px;
}
.layout-panel-footer {
    padding: 12px 14px; border-top: 1px solid var(--border);
    background: var(--surface-2);
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
}

.layout-row {
    background: var(--bg-mid);
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
}
.layout-row.hidden { opacity: 0.55; }
.layout-row-head {
    display: grid;
    grid-template-columns: 1fr auto auto auto auto;
    align-items: center; gap: 8px;
    padding: 10px 12px;
}
.layout-row-head .layout-row-label {
    font-size: 14px; font-weight: 500; color: var(--text);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    cursor: pointer;
}
.layout-row-head button {
    background: transparent; border: 1px solid var(--border-strong);
    color: var(--text-muted);
    width: 32px; height: 32px; border-radius: 8px;
    cursor: pointer;
    display: inline-grid; place-items: center;
    transition: background-color 150ms ease, color 150ms ease, border-color 150ms ease;
}
.layout-row-head button:hover:not(:disabled) {
    background: var(--accent-soft); color: var(--accent); border-color: var(--accent-line);
}
.layout-row-head button:disabled { opacity: 0.35; cursor: not-allowed; }
.layout-row-head button.visibility-toggle.is-off {
    background: rgba(248, 113, 113, 0.10);
    border-color: rgba(248, 113, 113, 0.30);
    color: var(--danger);
}
.layout-row-head .layout-row-expand[aria-expanded="true"] i { transform: rotate(180deg); }
.layout-row-head .layout-row-expand i { transition: transform 200ms ease; }

.layout-row-items {
    border-top: 1px solid var(--border);
    padding: 8px 12px 12px;
    display: none;
    flex-direction: column; gap: 6px;
    background: rgba(0,0,0,0.10);
}
.layout-row.expanded .layout-row-items { display: flex; }
:root[data-theme="light"] .layout-row-items { background: rgba(0,0,0,0.025); }

.layout-item {
    display: flex; align-items: center; justify-content: space-between;
    gap: 8px; padding: 6px 4px;
    font-size: 13.5px; color: var(--text);
}
.layout-item .layout-item-toggle {
    background: transparent; border: 1px solid var(--border-strong); color: var(--text-muted);
    width: 28px; height: 28px; border-radius: 6px;
    cursor: pointer; display: inline-grid; place-items: center;
}
.layout-item .layout-item-toggle:hover { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-line); }
.layout-item .layout-item-toggle.is-off {
    background: rgba(248, 113, 113, 0.10); color: var(--danger); border-color: rgba(248, 113, 113, 0.30);
}

/* All-hidden fallback */
.all-hidden-msg {
    display: none;
    padding: 24px;
    text-align: center;
    color: var(--text-muted);
    background: var(--surface);
    border: 1px dashed var(--border-strong);
    border-radius: 12px;
}
body.all-hidden .all-hidden-msg { display: block; }

/* =====================================================================
   CHAT MODE — feedback-manager.html
   ===================================================================== */

/* Mode toggle pills */
.mode-switch {
    display: inline-flex; gap: 4px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 4px;
    margin: 12px 0 18px;
}
.mode-switch button {
    background: transparent; border: none;
    color: var(--text-muted);
    padding: 8px 18px;
    border-radius: 999px;
    cursor: pointer;
    font-size: 13.5px; font-weight: 500;
    display: inline-flex; align-items: center; gap: 8px;
    transition: background-color 180ms ease, color 180ms ease;
}
.mode-switch button:hover { color: var(--text); }
.mode-switch button.active {
    background: var(--accent);
    color: var(--darkest, #0a1f1b);
    font-weight: 600;
}
:root[data-theme="light"] .mode-switch button.active { color: #ffffff; }
.mode-pane[hidden] { display: none; }

/* Notification bell */
.dm-bell {
    position: relative;
    background: transparent; border: 1px solid var(--border-strong); color: var(--text);
    width: 40px; height: 40px; border-radius: 10px; cursor: pointer;
    display: inline-grid; place-items: center; font-size: 16px;
}
.dm-bell:hover { background: var(--surface-2, var(--dark)); }
.dm-bell-badge {
    position: absolute; top: -4px; right: -4px;
    background: var(--danger);
    color: #fff;
    font-size: 10px; font-weight: 700;
    min-width: 18px; height: 18px;
    border-radius: 999px;
    padding: 0 5px;
    display: grid; place-items: center;
    border: 2px solid var(--bg-dark);
}
.dm-bell-badge[data-empty="1"] { display: none; }

/* Notification dropdown */
.notif-pop {
    position: absolute; right: 0; top: 48px;
    width: 360px; max-width: 95vw;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.4);
    z-index: 1060;
    overflow: hidden;
    display: none;
}
.notif-pop.open { display: block; }
.notif-pop-head {
    padding: 12px 16px; border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
    background: var(--surface-2, var(--dark));
}
.notif-pop-head h3 { margin: 0; font-size: 14px; font-weight: 600; color: var(--text); }
.notif-pop-head button { background: transparent; border: none; color: var(--text-muted); cursor: pointer; font-size: 12px; }
.notif-pop-head button:hover { color: var(--accent); }
.notif-pop-body { max-height: 420px; overflow-y: auto; }
.notif-item {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    display: flex; gap: 12px; align-items: flex-start;
    transition: background-color 150ms ease;
}
.notif-item:last-child { border-bottom: none; }
.notif-item:hover { background: var(--surface-2, var(--dark)); }
.notif-item.unread { background: rgba(45, 212, 160, 0.06); }
.notif-item .avatar {
    width: 32px; height: 32px; border-radius: 50%;
    display: grid; place-items: center;
    color: #0a1f1b; font-weight: 700; font-size: 13px;
    flex-shrink: 0;
}
.notif-item .meta { flex: 1; min-width: 0; }
.notif-item .meta .line1 { font-size: 13px; color: var(--text); }
.notif-item .meta .line1 strong { font-weight: 600; }
.notif-item .meta .line2 {
    font-size: 12px; color: var(--text-muted);
    margin-top: 3px;
    overflow: hidden; text-overflow: ellipsis;
    display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical;
}
.notif-item .meta .when { font-size: 11px; color: var(--text-dim); margin-top: 4px; }
.notif-empty {
    padding: 24px 16px; text-align: center; color: var(--text-muted); font-size: 13px;
}

/* Chat shell — two-pane grid */
.chat-shell {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 14px;
    min-height: 580px;
    height: calc(100vh - 250px);
    margin-bottom: 16px;
}

/* Thread list (left) */
.thread-list {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    display: flex; flex-direction: column;
}
.thread-list-head {
    padding: 12px 14px;
    background: rgba(45, 212, 160, 0.07);
    border-bottom: 1px solid var(--border);
    display: flex; flex-direction: column; gap: 10px;
}
.thread-list-head h3 { margin: 0; font-size: 14px; font-weight: 600; color: var(--text); }
.thread-list-head .head-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.thread-search {
    width: 100%; height: 36px; padding: 6px 12px;
    background: var(--bg-mid); color: var(--text);
    border: 1px solid var(--border-strong); border-radius: 8px;
    font-size: 13px;
}
.thread-search:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }
.thread-list-body { flex: 1; overflow-y: auto; }

.thread-item {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    display: flex; gap: 10px; align-items: flex-start;
    transition: background-color 150ms ease;
}
.thread-item:hover { background: var(--surface-2, var(--dark)); }
.thread-item.active { background: rgba(45, 212, 160, 0.12); border-left: 3px solid var(--accent); padding-left: 11px; }
.thread-item .ti-avatar {
    width: 36px; height: 36px; border-radius: 50%;
    display: grid; place-items: center;
    color: #0a1f1b; font-weight: 700; font-size: 13px;
    flex-shrink: 0;
}
.thread-item .ti-body { flex: 1; min-width: 0; }
.thread-item .ti-subject { font-size: 14px; font-weight: 600; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread-item .ti-preview { font-size: 12px; color: var(--text-muted); margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread-item .ti-meta { font-size: 11px; color: var(--text-dim); margin-top: 4px; display: flex; align-items: center; gap: 6px; }
.thread-item .ti-unread {
    background: var(--accent); color: #0a1f1b;
    font-size: 10.5px; font-weight: 700;
    min-width: 18px; height: 18px;
    border-radius: 999px; padding: 0 6px;
    display: grid; place-items: center;
    margin-left: auto;
}

/* Conversation (right) */
.conv {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    display: flex; flex-direction: column;
}
.conv-empty {
    flex: 1; display: flex; align-items: center; justify-content: center;
    color: var(--text-muted); font-size: 14px; padding: 40px;
    text-align: center;
}
.conv-head {
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
    background: rgba(45, 212, 160, 0.05);
}
.conv-subject { font-size: 16px; font-weight: 600; color: var(--text); margin: 0; }
.conv-participants { font-size: 12px; color: var(--text-muted); margin-top: 4px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.conv-participants .part-chip {
    background: var(--bg-mid); padding: 3px 10px; border-radius: 999px;
    font-size: 11.5px; color: var(--text); border: 1px solid var(--border);
}
.conv-body {
    flex: 1; overflow-y: auto;
    padding: 16px 18px;
    display: flex; flex-direction: column; gap: 4px;
    background: var(--bg-darkest);
}
:root[data-theme="light"] .conv-body { background: #f1f6f3; }

.date-divider {
    text-align: center; color: var(--text-muted);
    font-size: 11px; font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.08em;
    margin: 12px 0;
}
.date-divider span {
    background: var(--surface); padding: 4px 12px;
    border-radius: 999px; border: 1px solid var(--border);
}

/* Message */
.msg {
    display: flex; gap: 8px;
    margin: 6px 0;
    max-width: 75%;
}
.msg.theirs { align-self: flex-start; }
.msg.mine   { align-self: flex-end; flex-direction: row-reverse; }

.msg .avatar {
    width: 30px; height: 30px; border-radius: 50%;
    display: grid; place-items: center;
    color: #0a1f1b; font-weight: 700; font-size: 12px;
    flex-shrink: 0;
}
.msg.mine .avatar { display: none; }

.msg .bubble {
    background: var(--surface);
    color: var(--text);
    border-radius: 14px;
    padding: 9px 14px 7px;
    font-size: 14px; line-height: 1.4;
    border: 1px solid var(--border);
    position: relative;
    word-wrap: break-word;
    box-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);
}
.msg.theirs .bubble { border-top-left-radius: 4px; }
.msg.mine   .bubble {
    background: var(--accent);
    color: #0a1f1b;
    border-color: var(--accent);
    border-top-right-radius: 4px;
}
:root[data-theme="light"] .msg.mine .bubble { color: #ffffff; }

.msg .author {
    font-size: 11.5px; font-weight: 700; color: var(--accent);
    margin-bottom: 2px;
}
.msg.mine .author { display: none; }
.msg .text { white-space: pre-wrap; }
.msg.mine .text .mention { background: rgba(255,255,255,0.30); color: inherit; }
.msg .text .mention {
    background: rgba(45, 212, 160, 0.20);
    color: var(--accent);
    padding: 1px 6px; border-radius: 4px;
    font-weight: 600;
}
:root[data-theme="light"] .msg .text .mention { background: rgba(22, 160, 122, 0.15); color: #0f766e; }

/* Document reference chip — distinct from @mention */
.msg .text .doc-ref {
    background: rgba(96, 165, 250, 0.20);
    color: #93c5fd;
    padding: 1px 7px 1px 5px;
    border-radius: 4px;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex; align-items: center; gap: 4px;
    text-decoration: none;
}
.msg .text .doc-ref:hover { background: rgba(96, 165, 250, 0.35); }
.msg .text .doc-ref i { font-size: 11px; }
.msg.mine .text .doc-ref { background: rgba(255,255,255,0.32); color: inherit; }
:root[data-theme="light"] .msg .text .doc-ref { background: rgba(37, 99, 235, 0.12); color: #1d4ed8; }

/* Credit-note variant — amber to flag that it reduces the balance */
.msg .text .doc-ref--credit {
    background: rgba(251, 191, 36, 0.18);
    color: #fde68a;
}
.msg .text .doc-ref--credit:hover { background: rgba(251, 191, 36, 0.32); }
.msg.mine .text .doc-ref--credit { background: rgba(255, 255, 255, 0.32); color: inherit; }
:root[data-theme="light"] .msg .text .doc-ref--credit { background: rgba(180, 83, 9, 0.12); color: #b45309; }

/* Picker rows for credit notes get the amber avatar */
.mention-pop-item.doc[data-id^="CRN"] .mp-avatar i { color: #fbbf24; }
:root[data-theme="light"] .mention-pop-item.doc[data-id^="CRN"] .mp-avatar i { color: #b45309; }

/* Mention popup also reused for #doc — slight visual tweak for doc rows */
.mention-pop-item.doc .mp-avatar {
    background: rgba(96, 165, 250, 0.20) !important;
    color: #93c5fd !important;
}
:root[data-theme="light"] .mention-pop-item.doc .mp-avatar { color: #1d4ed8 !important; }
.mention-pop-item .mp-sub {
    font-size: 11px; color: var(--text-muted);
    margin-top: 2px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.msg .meta {
    font-size: 10.5px; color: var(--text-dim);
    margin-top: 4px;
    display: flex; align-items: center; gap: 4px;
    justify-content: flex-end;
}
.msg.mine .meta { color: rgba(10, 31, 27, 0.55); }
:root[data-theme="light"] .msg.mine .meta { color: rgba(255, 255, 255, 0.75); }
.msg .meta .checks { letter-spacing: -2px; }
.msg .meta .checks.read { color: #4ec1ff; }

/* Composer */
.composer {
    border-top: 1px solid var(--border);
    background: var(--surface);
    padding: 10px 14px;
    display: flex; align-items: flex-end; gap: 10px;
    position: relative;
}
.composer textarea {
    flex: 1; min-height: 40px; max-height: 140px;
    padding: 9px 12px;
    background: var(--bg-mid); color: var(--text);
    border: 1px solid var(--border-strong); border-radius: 10px;
    resize: none; font: inherit; font-size: 14px; line-height: 1.4;
    outline: none;
}
.composer textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }
.composer .send-btn {
    background: var(--accent); color: #0a1f1b;
    border: none; border-radius: 10px;
    width: 40px; height: 40px;
    display: grid; place-items: center;
    cursor: pointer; font-size: 16px;
    flex-shrink: 0;
}
.composer .send-btn:hover { background: #22c98e; box-shadow: 0 0 0 3px var(--accent-soft); }
.composer .send-btn:disabled { background: var(--border-strong); color: var(--text-muted); cursor: not-allowed; }

/* @mention autocomplete popup */
.mention-pop {
    position: absolute; bottom: 60px; left: 14px;
    width: 260px; max-height: 220px; overflow-y: auto;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    z-index: 100;
    display: none;
}
.mention-pop.open { display: block; }
.mention-pop-item {
    padding: 8px 12px; display: flex; align-items: center; gap: 10px;
    cursor: pointer; font-size: 13.5px;
}
.mention-pop-item:hover, .mention-pop-item.focused { background: rgba(45, 212, 160, 0.10); }
.mention-pop-item .mp-avatar {
    width: 28px; height: 28px; border-radius: 50%;
    display: grid; place-items: center;
    color: #0a1f1b; font-weight: 700; font-size: 11.5px;
    flex-shrink: 0;
}
.mention-pop-item .mp-name { color: var(--text); font-weight: 500; }
.mention-pop-item .mp-handle { color: var(--text-muted); margin-left: auto; font-size: 12px; }

@media (max-width: 760px) {
    .chat-shell { grid-template-columns: 1fr; height: auto; min-height: 0; }
    .thread-list { max-height: 280px; }
}

/* H8: SR-only utility */
.visually-hidden {
    position: absolute;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

@media (max-width: 900px) {
    .form-grid.cols-3, .form-grid.cols-4 { grid-template-columns: 1fr 1fr; }
}

/* M3: tablet & narrow desktops */
@media (max-width: 768px) {
    body { padding: 12px; }
    .top-section {
        flex-wrap: wrap;
        gap: 8px;
        padding: 10px 12px 12px;
        margin: -12px -12px 0;
    }
    .button-group { flex-wrap: wrap; gap: 6px; }
    .search-container { width: 100%; }
    .search-container form { width: 100%; min-width: 200px; }
    .table-container2 {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    /* Hide less-critical columns on small screens */
    .main-table tbody tr td:nth-child(6),  /* Docs # */
    .main-table tbody tr td:nth-child(8),  /* Email icon */
    .table-header-bar .col:nth-child(6),
    .table-header-bar .col:nth-child(8) {
        display: none;
    }
    /* The sticky header offset shrinks when toolbar wraps */
    .table-header-bar { top: 120px; }
    .form-grid.cols-3, .form-grid.cols-4 { grid-template-columns: 1fr; }
    .bottom-section { flex-direction: column; align-items: stretch; }
    .right-btn-group { justify-content: flex-end; }
}
