/* =================================================================
   IOP Manager — Modern, calm UI
   Restrained visual hierarchy: most actions outlined or ghost, only
   the single primary action filled. Brand blue for confirm, red for
   destructive/send. Minimal uppercase, subtle elevation.
   ================================================================= */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
    --bg:            #f5f6f8;
    --surface:       #ffffff;
    --surface-2:     #f7f8fa;
    --surface-3:     #eef0f4;
    --border:        #e3e6ec;
    --border-strong: #c8cdd6;
    --text:          #1a1d23;
    --text-soft:     #4b5563;
    --muted:         #6b7280;
    --soft:          #9aa0a6;

    /* Brand colours */
    --brand:         #2563eb;
    --brand-hover:   #1d4ed8;
    --brand-soft:    rgba(37,99,235,0.10);

    /* Backward-compat aliases (templates still reference --primary / --accent) */
    --primary:       var(--brand);
    --primary-hover: var(--brand-hover);
    --accent:        var(--brand);
    --accent-hover:  var(--brand-hover);

    /* Semantic */
    --danger:        #dc2626;
    --danger-hover:  #b91c1c;
    --danger-soft:   rgba(220,38,38,0.10);
    --success:       #15803d;
    --success-soft:  rgba(21,128,61,0.12);
    --warn:          #d97706;
    --warn-soft:     rgba(217,119,6,0.12);

    --shadow-sm:     0 1px 2px rgba(15,23,42,0.04);
    --shadow:        0 1px 3px rgba(15,23,42,0.06), 0 1px 2px rgba(15,23,42,0.04);
    --shadow-lg:     0 8px 24px rgba(15,23,42,0.08), 0 2px 6px rgba(15,23,42,0.04);
    --radius:        10px;
    --radius-sm:     7px;
    --radius-xs:     6px;
    --radius-pill:   999px;
    --transition:    140ms cubic-bezier(.4,0,.2,1);
}

* { box-sizing: border-box; }
html, body {
    margin: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}
h1, h2, h3, h4 { font-weight: 600; letter-spacing: -0.01em; margin: 0; color: var(--text); }
h1 { font-size: 1.4rem; }
h2 { font-size: 1rem; }
h3 { font-size: 0.92rem; }
a { color: var(--brand); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--brand-hover); text-decoration: underline; }
code {
    background: var(--surface-2);
    padding: 2px 6px;
    border-radius: var(--radius-xs);
    font-size: 0.85em;
    font-family: "SF Mono", "JetBrains Mono", monospace;
    color: var(--text-soft);
}

/* ------------ TOP BAR ----------------------------------------- */
.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0.6rem 1.5rem;
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 1.5rem;
    position: sticky;
    top: 0;
    z-index: 50;
    box-shadow: var(--shadow-sm);
}
.topbar-left   { display: flex; align-items: center; }
.topbar-center { display: flex; align-items: center; justify-content: center; }
.topbar-right  { display: flex; align-items: center; gap: 0.6rem; justify-content: flex-end; }

.topbar .brand {
    color: var(--text);
    font-weight: 600;
    font-size: 0.95rem;
    letter-spacing: 0;
    text-decoration: none;
}
.topbar .brand:hover { color: var(--brand); text-decoration: none; }
.topbar .nav-links { display: flex; gap: 0.25rem; }
.topbar .nav-links a {
    color: var(--text-soft);
    font-size: 0.86rem;
    font-weight: 500;
    padding: 6px 12px;
    border-radius: var(--radius-xs);
    transition: background var(--transition), color var(--transition);
    text-decoration: none;
}
.topbar .nav-links a:hover { color: var(--text); background: var(--surface-2); text-decoration: none; }
.topbar .nav-links a.active { color: var(--brand); background: var(--brand-soft); }

.topbar .nav-user {
    display: flex;
    gap: 0.6rem;
    align-items: center;
    color: var(--text-soft);
    font-size: 0.85rem;
    font-weight: 500;
}
.topbar .nav-user a { color: var(--text-soft); text-decoration: none; }
.topbar .nav-user a:hover { color: var(--text); }
.topbar .nav-user .nav-user-name { white-space: nowrap; color: var(--text); }

/* "+ New import" button in the topbar */
.topbar .btn-import {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 6px 12px;
    font-size: 0.82rem;
    font-weight: 600;
    white-space: nowrap;
    border-radius: var(--radius-sm);
}
.topbar .btn-import svg { display: block; }

/* Header search bar */
.header-search {
    position: relative;
    display: flex;
    align-items: center;
    width: 240px;
    max-width: 36vw;
}
.header-search-icon {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--muted);
    pointer-events: none;
}
.header-search-input {
    width: 100%;
    padding: 6px 10px 6px 32px;
    font: inherit;
    font-size: 0.85rem;
    color: var(--text);
    background: var(--surface-2);
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    transition: background var(--transition), border-color var(--transition);
}
.header-search-input:focus {
    outline: none;
    background: var(--surface);
    border-color: var(--brand);
    box-shadow: 0 0 0 3px var(--brand-soft);
}
.header-search-input::-webkit-search-cancel-button { -webkit-appearance: none; }

.header-search-dropdown {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    max-height: 60vh;
    overflow-y: auto;
    z-index: 60;
    padding: 4px 0;
    min-width: 320px;
}
.header-search-item {
    display: block;
    padding: 8px 12px;
    text-decoration: none;
    color: var(--text);
    border-radius: 0;
    border-bottom: 1px solid var(--border);
}
.header-search-item:last-child { border-bottom: 0; }
.header-search-item:hover,
.header-search-item.selected { background: var(--brand-soft); text-decoration: none; }
.header-search-item-name { font-weight: 600; font-size: 0.88rem; }
.header-search-item-name mark { background: #fef08a; color: inherit; padding: 0 1px; border-radius: 2px; }
.header-search-item-meta {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin-top: 2px;
    font-size: 0.76rem;
}
.header-search-empty {
    padding: 10px 14px;
    color: var(--muted);
    font-size: 0.85rem;
}

/* ------------ LAYOUT ------------------------------------------ */
.content {
    max-width: 1500px;
    margin: 0 auto;
    padding: 1.5rem 1.75rem 3rem;
}
.footer {
    text-align: center;
    padding: 1.5rem;
    color: var(--soft);
    font-size: 0.78rem;
}

.page-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
    gap: 1rem;
}
.page-meta { color: var(--text-soft); font-size: 0.88rem; }

/* ------------ CARD / SURFACE ---------------------------------- */
.card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 1.25rem 1.5rem;
    margin-bottom: 1rem;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
}
.card h2 { font-size: 1rem; font-weight: 600; margin-bottom: 1rem; }

/* ------------ STATS ------------------------------------------- */
.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 0.85rem;
    margin-bottom: 1.5rem;
}
.stat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.1rem 1.25rem;
    box-shadow: var(--shadow-sm);
    transition: border-color var(--transition);
}
.stat:hover { border-color: var(--border-strong); }
.stat-label {
    color: var(--soft);
    font-size: 0.7rem;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    font-weight: 600;
}
.stat-value {
    font-size: 1.5rem;
    font-weight: 600;
    margin-top: 0.3rem;
    letter-spacing: -0.02em;
    font-variant-numeric: tabular-nums;
}

/* ------------ FILTERS ----------------------------------------- */
.filters {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(168px, 1fr));
    gap: 0.6rem;
    align-items: center;
    margin-bottom: 1rem;
    background: var(--surface);
    padding: 0.85rem 1rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}
.filters input,
.filters select,
.filters .dropdown-multi,
.filters .dropdown-multi-trigger {
    width: 100%;
    box-sizing: border-box;
}
.filters input,
.filters select {
    min-height: 36px;
    padding: 6px 10px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-xs);
    font-size: 0.85rem;
    background: var(--surface);
    color: var(--text);
    font-family: inherit;
    transition: border var(--transition), box-shadow var(--transition);
}
.filters .dropdown-multi-trigger { min-height: 36px; }
.filters .dropdown-multi-trigger .dropdown-multi-caret { margin-left: auto; }
.filters input:focus,
.filters select:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px var(--brand-soft);
}
.filters .btn { padding: 6px 12px; }

/* ------------ BUTTONS -----------------------------------------
 * Hierarchy:
 *   .btn            = outlined, calm default (most actions)
 *   .btn.primary    = filled brand-blue, the ONE primary action per scope
 *   .btn.danger     = filled red, destructive/send (rare)
 *   .btn.ghost      = no border, only text — lowest weight
 *   .btn-link       = inline text link
 * Avoid using more than one filled button per screen scope.
 * --------------------------------------------------------------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 7px 14px;
    border: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--text);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    font-family: inherit;
    line-height: 1.2;
    text-decoration: none;
    white-space: nowrap;
    transition: background var(--transition), border-color var(--transition), color var(--transition);
}
.btn:hover {
    background: var(--surface-2);
    border-color: var(--text-soft);
    color: var(--text);
    text-decoration: none;
}
.btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px var(--brand-soft);
    border-color: var(--brand);
}
.btn:disabled, .btn[disabled] {
    opacity: 0.55;
    cursor: not-allowed;
}
.btn svg { width: 14px; height: 14px; flex: 0 0 auto; }

.btn.primary {
    background: var(--brand);
    color: #fff;
    border-color: var(--brand);
    font-weight: 600;
    padding: 8px 16px;
}
.btn.primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); color: #fff; }
.btn.primary:focus-visible { box-shadow: 0 0 0 3px rgba(37,99,235,0.30); }

.btn.danger {
    background: var(--danger);
    color: #fff;
    border-color: var(--danger);
    font-weight: 600;
    padding: 8px 16px;
}
.btn.danger:hover { background: var(--danger-hover); border-color: var(--danger-hover); color: #fff; }
.btn.danger:focus-visible { box-shadow: 0 0 0 3px rgba(220,38,38,0.30); }

.btn.ghost {
    background: transparent;
    border-color: transparent;
    color: var(--text-soft);
}
.btn.ghost:hover { background: var(--surface-2); color: var(--text); border-color: transparent; }

/* Subtle exit/cancel — text-soft, hovers red */
.btn.ghost.danger { color: var(--soft); }
.btn.ghost.danger:hover { color: var(--danger); background: transparent; }

.btn.small { padding: 5px 10px; font-size: 0.78rem; }
.btn.small.primary, .btn.small.danger { padding: 6px 12px; }

.btn-link {
    background: none;
    border: none;
    color: var(--brand);
    cursor: pointer;
    padding: 0;
    font-size: 0.85rem;
    font-weight: 500;
    font-family: inherit;
    transition: color var(--transition);
    text-decoration: none;
}
.btn-link:hover { color: var(--brand-hover); text-decoration: underline; }
.btn-link.danger { color: var(--danger); }
.btn-link.danger:hover { color: var(--danger-hover); }
.btn-link.muted { color: var(--muted); }
.btn-link.muted:hover { color: var(--text); }
.btn-link.small { font-size: 0.78rem; }

/* ------------ TABLES ------------------------------------------ */
.data-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
}
.data-table th,
.data-table td {
    padding: 10px 14px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    font-size: 0.86rem;
}
.data-table thead th {
    background: var(--surface-2);
    color: var(--soft);
    font-weight: 600;
    font-size: 0.7rem;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table .center { text-align: center; }
.data-table tbody tr {
    transition: background var(--transition);
}
.data-table tbody tr:hover { background: var(--surface-2); }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table .row-toggle {
    background: transparent;
    border: 1px solid var(--border-strong);
    width: 22px;
    height: 22px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 0.85rem;
    line-height: 0;
    color: var(--text-soft);
    transition: all var(--transition);
}
.data-table .row-toggle:hover { background: var(--brand); color: #fff; border-color: var(--brand); }

/* Sortable column headers */
.data-table thead th a.sort-header {
    color: inherit;
    text-decoration: none;
    display: inline-block;
    width: 100%;
    cursor: pointer;
    user-select: none;
    transition: color var(--transition);
}
.data-table thead th a.sort-header:hover { color: var(--text); text-decoration: none; }
.data-table thead th a.sort-header.sort-active { color: var(--brand); font-weight: 700; }
.data-table thead th.num a.sort-header { text-align: right; }

.invoices-cell { background: var(--surface-2); padding: 0 !important; }
.invoices-cell table { width: 100%; }
.invoices-cell th, .invoices-cell td { font-size: 0.8rem; padding: 8px 14px; }

/* ------------ BADGES ------------------------------------------ */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: var(--radius-pill);
    background: var(--surface-3);
    color: var(--text-soft);
    font-size: 0.7rem;
    font-weight: 500;
    letter-spacing: 0;
    text-transform: none;
    border: 1px solid transparent;
    line-height: 1.55;
}
/* Status badges intentionally share a single neutral look — visual hierarchy
   should come from layout and primary actions, not from a rainbow of statuses. */
.badge.status-active,
.badge.status-under_review,
.badge.status-rac_partner,
.badge.status-enforcement,
.badge.status-write_off,
.badge.status-vip,
.badge[class*="status-"] {
    background: var(--surface-3);
    color: var(--text-soft);
    border: 1px solid var(--border);
}

/* ------------ DIFF -------------------------------------------- */
.diff { font-weight: 600; font-size: 0.85rem; }
.diff.new       { color: var(--primary); }
.diff.increased { color: var(--danger); }
.diff.decreased { color: var(--success); }
.diff.unchanged { color: var(--muted); }
.diff.cleared   { color: var(--success); }
.diff small { font-weight: 400; color: var(--muted); display: block; font-size: 0.75rem; margin-top: 2px; }

/* ------------ FLASH ------------------------------------------- */
.flash {
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    margin-bottom: 1rem;
    font-size: 0.88rem;
    border: 1px solid;
    background: var(--surface);
}
.flash-success { background: #ecfdf5; border-color: rgba(21,128,61,0.25); color: #065f46; }
.flash-error   { background: #fef2f2; border-color: rgba(220,38,38,0.25); color: #991b1b; }
.flash-info    { background: #eff6ff; border-color: rgba(37,99,235,0.25); color: #1e3a8a; }

/* ------------ AUTH CARD --------------------------------------- */
.auth-card {
    max-width: 420px;
    margin: 5rem auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2rem;
    box-shadow: var(--shadow-lg);
}
.auth-card h1 { font-size: 1.3rem; margin-bottom: 1rem; }
.auth-card label { display: block; margin-bottom: 1rem; font-size: 0.85rem; color: var(--text-soft); }
.auth-card label input,
.auth-card label select {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    font-size: 0.92rem;
    margin-top: 0.3rem;
    font-family: inherit;
    color: var(--text);
    background: var(--surface);
    transition: border var(--transition), box-shadow var(--transition);
}
.auth-card label input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.auth-card .btn { width: 100%; padding: 10px; font-size: 0.9rem; }

/* ------------ MISC -------------------------------------------- */
.muted     { color: var(--muted); }
.small     { font-size: 0.82rem; }
.center    { text-align: center; }
.row       { display: flex; gap: 0.85rem; align-items: center; }
.stack     { display: flex; flex-direction: column; gap: 0.75rem; }
.stack label {
    display: flex; flex-direction: column;
    font-size: 0.78rem;
    color: var(--text-soft);
    gap: 0.3rem;
    font-weight: 500;
}
.stack label input,
.stack label select,
.stack label textarea {
    padding: 7px 10px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-xs);
    font-size: 0.88rem;
    color: var(--text);
    font-family: inherit;
    background: var(--surface);
    transition: border var(--transition), box-shadow var(--transition);
}
.stack label input:focus,
.stack label select:focus,
.stack label textarea:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px var(--brand-soft);
}
.stack label.row { flex-direction: row; align-items: center; }
.inline { display: inline; }

details { margin-top: 0.6rem; }
details summary {
    cursor: pointer;
    color: var(--brand);
    font-size: 0.85rem;
    font-weight: 500;
    list-style: none;
    padding: 0.35rem 0;
}
details summary:hover { color: var(--brand-hover); }
details summary::-webkit-details-marker { display: none; }
details summary::before {
    content: '+';
    margin-right: 0.4rem;
    font-weight: 400;
    color: var(--muted);
    transition: transform var(--transition);
    display: inline-block;
}
details[open] summary::before { content: '−'; }

.grid { display: grid; gap: 1.25rem; }
.grid-2 { grid-template-columns: 1fr 1fr; }
@media (max-width: 900px) {
    .grid-2 { grid-template-columns: 1fr; }
    .content { padding: 1.5rem 1rem; }
    .topbar {
        padding: 0.6rem 1rem;
        gap: 0.75rem;
        grid-template-columns: auto 1fr auto;
    }
    .topbar .nav-links { gap: 0.9rem; }
    .topbar .nav-user .nav-user-name { display: none; }
    .topbar .btn-import span { display: none; }
    .topbar .btn-import { padding: 0.42rem 0.55rem; }
    .header-search { width: 160px; }
}
@media (max-width: 640px) {
    .topbar {
        grid-template-columns: 1fr auto;
        grid-template-areas: "left right" "center center";
        row-gap: 0.5rem;
    }
    .topbar-left   { grid-area: left; }
    .topbar-right  { grid-area: right; }
    .topbar-center { grid-area: center; overflow-x: auto; justify-content: flex-start; }
    .topbar .nav-links { gap: 1rem; padding-bottom: 0.25rem; }
    .header-search { width: 140px; }
}

.contact-list { list-style: none; padding: 0; margin: 0; }
.contact-list li {
    border-bottom: 1px solid var(--border);
    padding: 1rem 0;
}
.contact-list li:last-child { border-bottom: none; }
.contact-list li strong { font-weight: 600; }

.comments { list-style: none; padding: 0; margin-top: 1.25rem; }
.comments li {
    border-bottom: 1px solid var(--border);
    padding: 0.85rem 0;
}
.comments li:last-child { border-bottom: none; }
.comment-meta {
    display: flex;
    gap: 0.6rem;
    align-items: center;
    font-size: 0.82rem;
    margin-bottom: 0.35rem;
}
.comment-meta strong { font-weight: 600; }
.comment-body { white-space: pre-wrap; font-size: 0.9rem; color: var(--text); }

/* Page tip line */
p.muted.small {
    margin: 0.5rem 0 1rem;
    font-size: 0.78rem;
    color: var(--muted);
    letter-spacing: 0.02em;
}

/* Sticky table header for long tables */
.data-table thead th { position: sticky; top: 0; }

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}

/* ------------ STATUS CHECKBOX CHIPS (dashboard filter) ----------- */
.status-filter {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    align-items: center;
    width: 100%;
    margin-top: 0.5rem;
}
.status-filter .filter-label {
    font-size: 0.7rem;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--soft);
    font-weight: 600;
    margin-right: 0.5rem;
}
.status-chip {
    cursor: pointer;
    user-select: none;
    position: relative;
}
.status-chip input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    pointer-events: none;
    width: 0;
    height: 0;
}
.status-chip .badge {
    opacity: 0.5;
    border: 1px dashed var(--border-strong);
    background: var(--surface);
    transition: all var(--transition);
}
.status-chip:hover .badge { opacity: 0.85; }
.status-chip input[type="checkbox"]:checked + .badge {
    opacity: 1;
    border: 1px solid transparent;
}
.status-chip input[type="checkbox"]:focus-visible + .badge {
    outline: 2px solid var(--brand);
    outline-offset: 2px;
}
.status-chip input[type="checkbox"]:checked + .badge::before {
    content: '\2713 ';
    font-weight: 700;
    margin-right: 2px;
}
.filter-actions {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    grid-column: 1 / -1;
    justify-content: flex-end;
    margin-top: 0.25rem;
}
@media (max-width: 700px) {
    .filter-actions { justify-content: flex-start; }
}

/* ============== CLIENT PAGE LAYOUT ============== */
.client-layout {
    display: grid;
    grid-template-columns: 340px 1fr;
    gap: 1.5rem;
    align-items: flex-start;
}
.client-sidebar { display: flex; flex-direction: column; gap: 1rem; position: sticky; top: 80px; }
.client-main    { display: flex; flex-direction: column; gap: 1rem; min-width: 0; }
@media (max-width: 1000px) {
    .client-layout { grid-template-columns: 1fr; }
    .client-sidebar { position: static; }
}

/* ============== CONTACT LIST (no emoji icons) ============== */
.contact-list li {
    padding: 0.85rem 0;
    border-bottom: 1px solid var(--border);
    position: relative;
}
.contact-list li:last-child { border-bottom: none; }
.contact-head {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.5rem;
    margin-bottom: 0.35rem;
}
.contact-role {
    color: var(--muted);
    font-size: 0.78rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}
.contact-row {
    display: flex;
    gap: 0.6rem;
    align-items: baseline;
    margin: 2px 0;
    font-size: 0.9rem;
}
.contact-label {
    color: var(--muted);
    font-size: 0.7rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    min-width: 42px;
    font-weight: 500;
}
.contact-delete { margin-top: 0.5rem; }
.btn-link.small { font-size: 0.75rem; letter-spacing: 0.04em; }

/* ============== TIMELINE ============== */
.timeline-compose { margin-bottom: 1.25rem; }
.timeline {
    list-style: none;
    padding: 0;
    margin: 0;
    position: relative;
}
.timeline::before {
    content: '';
    position: absolute;
    left: 7px;
    top: 6px;
    bottom: 6px;
    width: 1px;
    background: var(--border-strong);
}
.timeline-entry {
    position: relative;
    padding: 0.3rem 0 0.85rem 2rem;
}
.timeline-marker {
    position: absolute;
    left: 0;
    top: 0.5rem;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--surface);
    border: 2px solid var(--muted);
    box-shadow: 0 0 0 3px var(--surface);
}
.timeline-comment .timeline-marker        { border-color: var(--brand); background: var(--brand); }
.timeline-client_update .timeline-marker  { border-color: var(--warn); }
.timeline-contact_add .timeline-marker    { border-color: var(--success); }
.timeline-contact_delete .timeline-marker { border-color: var(--danger); }
.timeline-email_send .timeline-marker     { border-color: var(--danger); background: var(--danger); }
.timeline-import .timeline-marker         { border-color: #8b5cf6; }

.timeline-head {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: baseline;
    margin-bottom: 0.25rem;
}
.timeline-kind {
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-soft);
}
.timeline-meta {
    color: var(--muted);
    font-size: 0.78rem;
    margin-left: auto;
}
.timeline-body {
    font-size: 0.9rem;
    color: var(--text);
    white-space: pre-wrap;
    line-height: 1.5;
}
.timeline-body.muted { color: var(--text-soft); font-size: 0.85rem; }
.timeline-details {
    margin-top: 0.4rem;
    font-size: 0.8rem;
}
.timeline-details pre {
    background: var(--surface-2);
    padding: 8px 10px;
    border-radius: var(--radius-xs);
    overflow-x: auto;
    margin: 0.4rem 0 0;
    color: var(--text-soft);
    font-size: 0.74rem;
    border: 1px solid var(--border);
}

/* ============== TABLE FOOTER (totals row) ============== */
.data-table tfoot th {
    background: var(--surface-2);
    color: var(--text);
    font-weight: 600;
    font-size: 0.85rem;
    border-top: 2px solid var(--border-strong);
    border-bottom: none;
    padding: 0.85rem 1.25rem;
    text-transform: none;
    letter-spacing: 0;
}

/* ============== RECORD HEADER (Zoho-style) ============== */
.record-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 18px;
    margin-bottom: 1rem;
    box-shadow: var(--shadow-sm);
}
.record-back {
    width: 32px; height: 32px;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: var(--radius-xs);
    color: var(--text-soft);
    font-size: 1.1rem;
    transition: background var(--transition), color var(--transition);
    text-decoration: none;
}
.record-back:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.record-title { flex: 1; min-width: 0; }
.record-title-row {
    display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap;
}
.record-title-row h1 { font-size: 1.3rem; }
.record-subtitle {
    color: var(--text-soft);
    font-size: 0.84rem;
    margin-top: 0.25rem;
    display: flex;
    gap: 0.4rem;
    flex-wrap: wrap;
}
.record-subtitle .dot { color: var(--border-strong); }
.record-actions { display: flex; gap: 0.5rem; align-items: center; }

/* ============== TABS ============== */
.tabs {
    display: flex;
    gap: 4px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 0;
    background: var(--surface);
    border-radius: var(--radius) var(--radius) 0 0;
    padding: 6px 10px 0;
    border: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
}
.tab {
    padding: 9px 14px;
    color: var(--text-soft);
    font-size: 0.86rem;
    font-weight: 500;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    cursor: pointer;
    transition: color var(--transition), border-color var(--transition);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    border-radius: var(--radius-xs) var(--radius-xs) 0 0;
}
.tab:hover { color: var(--text); text-decoration: none; background: var(--surface-2); }
.tab.active {
    color: var(--brand);
    border-bottom-color: var(--brand);
    font-weight: 600;
    background: transparent;
}
.tab-count {
    display: inline-block;
    background: var(--surface-3);
    color: var(--muted);
    font-size: 0.72rem;
    padding: 1px 7px;
    border-radius: var(--radius-pill);
    font-weight: 600;
}
.tab.active .tab-count { background: var(--brand-soft); color: var(--brand); }

.tab-panel { display: none; }
.tab-panel.active { display: block; }
/* When .card immediately follows .tabs, blend them visually */
.tabs + .tab-panel.card {
    border-top: none;
    border-top-left-radius: 0;
    border-top-right-radius: 0;
    margin-top: 0;
}

/* Shared admin section tab bar — Common settings, Users, Email templates */
.admin-tabs { margin-bottom: 1rem; flex-wrap: wrap; }

/* ============== SIDEBAR CARDS ============== */
.sidebar-card { padding: 1rem 1.1rem; }
.sidebar-card-head {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--soft);
    letter-spacing: 0.05em;
    text-transform: uppercase;
    margin-bottom: 0.7rem;
    padding-bottom: 0;
    border-bottom: 0;
}
.sidebar-card .stack label {
    text-transform: none;
    letter-spacing: 0;
    font-size: 0.75rem;
    color: var(--muted);
}
.sidebar-foot {
    padding: 0.5rem 1.5rem 1rem;
    text-align: center;
}

/* Related contact */
.related-contact {
    display: flex;
    gap: 0.7rem;
    align-items: flex-start;
}
.avatar {
    width: 32px; height: 32px;
    background: var(--brand-soft);
    color: var(--brand);
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    flex-shrink: 0;
    border: 0;
}

/* Key-value Other Info */
.kv {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 0.4rem 0.85rem;
    margin: 0;
}
.kv dt {
    color: var(--muted);
    font-size: 0.74rem;
    font-weight: 500;
}
.kv dd {
    margin: 0;
    color: var(--text);
    font-size: 0.84rem;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* ============== TIMELINE date headers ============== */
.timeline-wrap { position: relative; }
.timeline-day-head {
    font-size: 0.7rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
    font-weight: 600;
    margin: 1rem 0 0.5rem 4rem;
    padding-top: 0.5rem;
}
.timeline-day-head:first-of-type { margin-top: 0; }

.timeline { position: relative; padding-left: 4rem; }
.timeline::before { left: 4rem; }   /* shift vertical line right to make room for time */

.timeline-time {
    position: absolute;
    left: -3.8rem;
    top: 0.6rem;
    width: 3rem;
    text-align: right;
    color: var(--muted);
    font-size: 0.78rem;
    font-variant-numeric: tabular-nums;
}
.timeline-entry { padding-left: 1.5rem; }
.timeline-marker { left: -7px; }

/* ============== TIMELINE COMPOSER (chat style) ============== */
.timeline-compose {
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    padding: 8px 10px 8px 14px;
    transition: border-color var(--transition), box-shadow var(--transition);
    margin-bottom: 1.25rem;
}
.timeline-compose:focus-within {
    border-color: var(--brand);
    box-shadow: 0 0 0 3px var(--brand-soft);
}
.timeline-compose textarea {
    width: 100%;
    border: 0;
    outline: 0;
    background: transparent;
    resize: vertical;
    min-height: 56px;
    font: 0.9rem/1.5 'Inter', sans-serif;
    color: var(--text);
    padding: 6px 0;
}
.timeline-compose textarea::placeholder { color: var(--muted); }
.timeline-compose .row { padding-top: 0.4rem; border-top: 1px solid var(--border); }

/* IOP update marker in timeline */
.timeline-iop_update .timeline-marker {
    border-color: #8b5cf6;
    background: #8b5cf6;
}
.timeline-iop_update .timeline-kind { color: #6d28d9; }

/* IOP review marker in timeline (customer reviewed in IOP Review) */
.timeline-iop_review .timeline-marker {
    border-color: #0d9488;
    background: #0d9488;
}
.timeline-iop_review .timeline-kind { color: #0f766e; }

/* Timeline "show comments only" filter */
.timeline-filter {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.8rem;
    color: var(--text-soft);
    cursor: pointer;
    white-space: nowrap;
}
.timeline-filter input { cursor: pointer; }
.timeline-wrap.tl-comments-only .timeline-entry:not(.timeline-comment) { display: none; }

/* Email body textarea — monospace-ish for clarity of plain text */
textarea.email-body {
    font-family: 'Inter', sans-serif;
    line-height: 1.6;
    white-space: pre-wrap;
}

/* ============== COMPACT SIDEBAR ============== */
.client-layout { grid-template-columns: 300px 1fr; gap: 1.25rem; }
.client-sidebar { gap: 0.65rem; }
.sidebar-card {
    padding: 0.95rem 1.1rem;
    margin-bottom: 0;
}
.sidebar-card-head {
    font-size: 0.72rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
    font-weight: 600;
    margin-bottom: 0.65rem;
    padding-bottom: 0.4rem;
    border-bottom: 1px solid var(--border);
}
.sidebar-card .stack { gap: 0.5rem; }
.sidebar-card .stack label {
    font-size: 0.7rem;
}
.sidebar-card .stack label input,
.sidebar-card .stack label select,
.sidebar-card .stack label textarea {
    padding: 0.45rem 0.6rem;
    font-size: 0.85rem;
}
.sidebar-card .stack textarea[rows="3"] { min-height: 60px; }
.sidebar-card .stack button.btn { padding: 0.5rem 1rem; font-size: 0.78rem; }
.sidebar-card details summary { font-size: 0.78rem; }

/* Compact related-contact block */
.related-contact { gap: 0.7rem; }
.avatar { width: 32px; height: 32px; font-size: 0.72rem; }
.related-contact .contact-row { font-size: 0.82rem; margin: 1px 0; }
.contact-label { font-size: 0.65rem; min-width: 36px; }

/* Compact kv list */
.kv { gap: 0.35rem 0.85rem; }
.kv dt { font-size: 0.7rem; }
.kv dd { font-size: 0.82rem; }

/* Compose-new "button as <summary>" styling fix */
#compose-details > summary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 16px;
    background: var(--brand);
    color: #fff;
    border: 1px solid var(--brand);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    list-style: none;
    transition: background var(--transition);
}
#compose-details > summary::before { content: ''; margin: 0; }
#compose-details > summary::-webkit-details-marker { display: none; }
#compose-details > summary:hover { background: var(--brand-hover); }
#compose-details[open] > summary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }

/* Sent emails table — distinguish status pills inline */
.sent-emails .badge { font-size: 0.66rem; padding: 2px 8px; }

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

/* ============== IOP REVIEW MODULE ============== */
/* Sticky progress strip with inline workflow buttons (Exit / Skip / Save / Save & Next) */
.iopcheck-progress {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 16px 12px;
    margin: 0 0 1rem;
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 60px;
    z-index: 30;
}
.iopcheck-progress-row {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}
.iopcheck-progress-meta {
    display: flex;
    align-items: baseline;
    gap: 10px;
    flex: 0 0 auto;
    font-size: 0.86rem;
}
.iopcheck-progress-meta strong { font-weight: 600; color: var(--text); }
.iopcheck-progress-meta .muted { color: var(--muted); font-size: 0.82rem; }
.iopcheck-progress-bar {
    height: 6px;
    background: var(--surface-3);
    border-radius: var(--radius-pill);
    overflow: hidden;
    position: relative;
    flex: 1 1 200px;
    min-width: 120px;
}
.iopcheck-progress-bar > span {
    display: block;
    height: 100%;
    background: linear-gradient(90deg, var(--brand) 0%, #60a5fa 100%);
    border-radius: var(--radius-pill);
    transition: width var(--transition);
}
.iopcheck-progress-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 0 0 auto;
}

.iopcheck-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem 1.5rem;
    box-shadow: var(--shadow-sm);
}
.iopcheck-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: 1.25rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}
.iopcheck-head h2 { font-size: 1.2rem; margin-bottom: 0.25rem; }

.iopcheck-grid {
    display: grid;
    grid-template-columns: 1.4fr 1fr;
    gap: 2rem;
}
@media (max-width: 1000px) { .iopcheck-grid { grid-template-columns: 1fr; } }

.iopcheck-grid h3 {
    font-size: 0.7rem;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--soft);
    font-weight: 600;
    margin-bottom: 0.6rem;
}

.iopcheck-form .required-mark {
    color: var(--danger);
    font-size: 0.65rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    margin-left: 0.4rem;
}
.iopcheck-actions {
    display: flex;
    gap: 0.6rem;
    justify-content: flex-end;
    margin-top: 0.75rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}
.iopcheck-actions .btn.primary { padding: 8px 16px; font-size: 0.85rem; }

.iopcheck-fieldset {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.85rem 1.1rem;
    margin: 0;
    background: var(--surface);
}
.iopcheck-fieldset legend {
    font-size: 0.7rem;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--soft);
    font-weight: 600;
    padding: 0 0.4rem;
}
.iopcheck-fieldset label.row { gap: 0.5rem; padding: 0.2rem 0; }

/* IOP Check — flagged invoices (already sent a notice, deadline expired) */
.data-table tr.invoice-flagged {
    background: #fef2f2;
    border-left: 3px solid var(--danger);
}
.data-table tr.invoice-flagged:hover { background: #fee2e2; }
.data-table tr.invoice-flagged td { border-bottom-color: rgba(220,38,38,0.12); }

.flag-pill {
    display: inline-block;
    padding: 2px 8px;
    margin-left: 6px;
    border-radius: var(--radius-pill);
    background: var(--danger-soft);
    color: var(--danger);
    font-size: 0.64rem;
    letter-spacing: 0.03em;
    font-weight: 600;
    text-transform: uppercase;
}

.iop-flagged-banner {
    background: #fef2f2;
    border: 1px solid rgba(220,38,38,0.2);
    border-left: 3px solid var(--danger);
    color: #7f1d1d;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    margin-top: 0.75rem;
    font-size: 0.88rem;
}
.iop-flagged-banner strong { color: var(--danger); }

/* ============== CREDIT / DEBIT / FUTURE invoice indicators ============== */
.data-table tr.invoice-credit {
    background: #ecfdf5;
    border-left: 3px solid var(--success);
}
.data-table tr.invoice-credit:hover { background: #d1fae5; }
.data-table tr.invoice-future {
    background: var(--surface-2);
    color: var(--text-soft);
}
.data-table .amount-credit { color: var(--success); font-weight: 600; }
.data-table .amount-debit  { color: var(--danger);  font-weight: 600; }

.credit-pill {
    display: inline-block;
    padding: 2px 8px;
    margin-left: 6px;
    border-radius: var(--radius-pill);
    background: var(--success-soft);
    color: var(--success);
    font-size: 0.64rem;
    letter-spacing: 0.03em;
    font-weight: 600;
    text-transform: uppercase;
}
.future-pill {
    display: inline-block;
    padding: 2px 8px;
    margin-left: 6px;
    border-radius: var(--radius-pill);
    background: var(--surface-3);
    color: var(--muted);
    font-size: 0.64rem;
    letter-spacing: 0.03em;
    font-weight: 600;
    text-transform: uppercase;
}

/* ============== IOP check: credit/debit mixing warning ============== */
.iop-mix-banner {
    background: #fffbeb;
    border: 1px solid rgba(217,119,6,0.25);
    border-left: 3px solid var(--warn);
    color: #78350f;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    margin: 0 0 1rem;
    font-size: 0.88rem;
}
.iop-mix-banner.info {
    background: #eff6ff;
    border-color: rgba(37,99,235,0.22);
    border-left-color: var(--brand);
    color: var(--text-soft);
}

/* ============== Email composer banners ============== */
.email-mode-banner {
    background: #fffbeb;
    border: 1px solid rgba(217,119,6,0.25);
    border-left: 3px solid var(--warn);
    color: #78350f;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    margin-bottom: 1rem;
    font-size: 0.88rem;
}
.email-mode-banner.stern-recommended {
    background: #fef2f2;
    border-color: rgba(220,38,38,0.22);
    border-left-color: var(--danger);
    color: #7f1d1d;
}
.email-mode-banner .btn-link { margin-left: 0.5rem; font-weight: 600; }

.email-overpayment-banner {
    background: #fffbeb;
    border: 1px solid rgba(217,119,6,0.25);
    border-left: 3px solid var(--warn);
    color: #78350f;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    margin-bottom: 1rem;
    font-size: 0.88rem;
}

.email-mode-tag {
    display: inline-block;
    background: var(--surface-2);
    border: 1px solid var(--border);
    padding: 6px 12px;
    border-radius: var(--radius-xs);
    font-size: 0.78rem;
    color: var(--text-soft);
    margin-bottom: 0.85rem;
}
.email-mode-tag strong { color: var(--text); }

.email-confirm {
    margin: 0.5rem 0;
    padding: 10px 14px;
    background: var(--surface-2);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    font-size: 0.86rem;
    align-items: flex-start !important;
}
.email-confirm input[type="checkbox"] {
    width: 16px; height: 16px;
    flex-shrink: 0;
    margin-top: 2px;
    accent-color: var(--brand);
}
.email-confirm span strong { color: var(--danger); }

/* Dashboard "Only overdue / All open" radio toggle */
.view-toggle {
    display: flex;
    gap: 0.4rem;
    align-items: center;
    margin-right: 1rem;
}
.view-chip input[type="radio"] {
    position: absolute;
    opacity: 0;
    pointer-events: none;
    width: 0; height: 0;
}
.view-chip .badge.view-badge {
    background: var(--surface);
    border: 1px solid var(--border-strong);
    color: var(--text-soft);
    opacity: 0.85;
    cursor: pointer;
    transition: all var(--transition);
}
.view-chip:hover .badge.view-badge { opacity: 1; border-color: var(--text-soft); }
.view-chip input[type="radio"]:checked + .badge.view-badge {
    background: var(--brand);
    color: #fff;
    border-color: var(--brand);
    opacity: 1;
}

/* ============ Days-overdue coloring ============ */
.days-overdue { color: var(--text); font-weight: 600; }
.days-future  { color: var(--success); font-weight: 600; }

/* ============ Dashboard: expanded row visual link ============ */
.data-table tr.client-row.row-expanded {
    background: var(--brand-soft);
    box-shadow: inset 3px 0 0 var(--brand);
}
.data-table tr.client-row.row-expanded:hover { background: rgba(37,99,235,0.14); }
.data-table tr.client-row.row-expanded td { border-bottom-color: transparent; }
.data-table tr.client-row.row-expanded .row-toggle {
    background: var(--brand);
    color: #fff;
    border-color: var(--brand);
}
.data-table tr.invoices-row > td.invoices-cell {
    border-left: 3px solid var(--brand);
    background: var(--surface-2) !important;
    padding: 0.6rem 0 0.85rem !important;
}

/* ============ Sub-invoices table (expanded view) ============ */
table.sub-invoices {
    width: 100%;
    background: transparent;
    border-radius: 0;
    box-shadow: none;
    border: 0;
}
table.sub-invoices thead th {
    background: transparent;
    color: var(--soft);
    font-size: 0.66rem;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    border-bottom: 1px solid var(--border-strong);
    padding: 6px 14px;
    font-weight: 600;
}
table.sub-invoices tbody td {
    padding: 7px 14px;
    border-bottom: 1px solid var(--border);
    font-size: 0.84rem;
}
table.sub-invoices tr.year-head td {
    background: var(--surface-3);
    color: var(--text);
    font-weight: 700;
    font-size: 0.78rem;
    letter-spacing: 0.03em;
    padding: 7px 14px;
    border-bottom: 1px solid var(--border-strong);
}
table.sub-invoices tr.year-head td.year-cell { padding-left: 1.5rem; }
table.sub-invoices tr.year-head td.year-meta {
    color: var(--text-soft);
    font-weight: 500;
    text-transform: none;
    letter-spacing: 0;
}
table.sub-invoices td.year-pad { width: 1.5rem; }
table.sub-invoices tfoot td {
    background: var(--surface-3);
    border-top: 2px solid var(--border-strong);
    padding: 8px 14px;
    font-size: 0.86rem;
    color: var(--text);
}

/* ============== NOTICE LEVEL pills + manual mark toolbar ============== */
.notice-level-pill {
    display: inline-block;
    padding: 2px 8px;
    margin-left: 6px;
    border-radius: var(--radius-pill);
    font-size: 0.64rem;
    letter-spacing: 0.03em;
    font-weight: 700;
    text-transform: uppercase;
}
.notice-level-1 { background: #fef3c7; color: #92400e; }
.notice-level-2 { background: #fed7aa; color: #9a3412; }
.notice-level-3 { background: #fecaca; color: #991b1b; }

.manual-mark-toolbar {
    margin-top: 1rem;
    padding: 10px 14px;
    background: var(--surface-2);
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius-sm);
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}
.manual-mark-toolbar .manual-mark-label {
    flex-basis: 100%;
    margin: 0 0 4px;
    display: block;
}
.manual-mark-toolbar > form.inline {
    flex: 1 1 0;
    min-width: 0;
    margin: 0;
}
.manual-mark-toolbar > form.inline .btn {
    width: 100%;
    padding: 7px 12px;
    font-size: 0.82rem;
}

/* Sub-invoices footer — two totals (all + overdue) */
table.sub-invoices tfoot tr.ft-total td {
    background: rgba(0,0,0,0.03);
    border-top: 2px solid var(--border-strong);
}
table.sub-invoices tfoot tr.ft-overdue td {
    background: rgba(204,0,0,0.05);
    border-top: 1px dashed rgba(204,0,0,0.3);
    color: var(--danger);
}
table.sub-invoices tfoot tr.ft-overdue td.num.amount-debit { color: var(--danger); }

/* ============================================================
 * Reports — funnels (reminder stage + aging buckets)
 * ============================================================ */
/* Subtler, more refined funnel rows: muted tinted bars + clean labels. */
.funnel { display: flex; flex-direction: column; gap: 6px; margin-top: 0.75rem; }
.funnel-row {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    overflow: hidden;
    transition: border-color var(--transition), box-shadow var(--transition);
}
.funnel-row:hover { border-color: var(--border-strong); }
.funnel-row[open] { box-shadow: var(--shadow-sm); border-color: var(--border-strong); }
.funnel-summary {
    position: relative;
    list-style: none;
    cursor: pointer;
    padding: 12px 18px;
    display: block;
    min-height: 3rem;
    user-select: none;
}
.funnel-summary::-webkit-details-marker { display: none; }
.funnel-summary::after {
    content: '\203A';
    position: absolute;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--muted);
    font-size: 1.2rem;
    transition: transform 0.15s ease;
    pointer-events: none;
    line-height: 1;
}
.funnel-row[open] > .funnel-summary::after { transform: translateY(-50%) rotate(90deg); }

/* The bar fills proportionally to the bucket count, behind the row content.
   Opacity kept low (12%) so the bar reads as ambient background, not a poster. */
.funnel-bar {
    position: absolute;
    inset: 0 auto 0 0;
    background: var(--brand);
    opacity: 0.12;
    min-width: 3px;
    transition: width 0.25s ease;
    pointer-events: none;
    border-radius: 0;
}

.funnel-meta {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding-right: 1.5rem;
}
.funnel-label {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text);
    display: inline-flex;
    align-items: center;
    gap: 8px;
}
/* Small colored dot next to the label, in the row's tint */
.funnel-label::before {
    content: '';
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--funnel-tint, var(--muted));
}
.funnel-stats {
    color: var(--muted);
    font-size: 0.88rem;
    font-variant-numeric: tabular-nums;
    display: inline-flex;
    align-items: baseline;
    gap: 10px;
}
.funnel-stats strong { color: var(--text); font-weight: 600; }
.funnel-stats .funnel-stats-sep { color: var(--border-strong); }

.funnel-clients {
    margin: 0;
    border-top: 1px solid var(--border);
    border-radius: 0;
    box-shadow: none;
    background: var(--surface);
}
.funnel-clients th, .funnel-clients td { padding: 9px 18px; font-size: 0.85rem; }
.funnel-clients tbody tr:nth-child(even) { background: var(--surface-2); }
.funnel-clients tbody tr:hover { background: var(--brand-soft); }

/* ============================================================
 * Notifications — nav bell + inbox list + @mentions
 * ============================================================ */

/* Bell in the top nav */
.nav-bell {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: var(--radius-xs);
    color: var(--text-soft);
    text-decoration: none;
    transition: background var(--transition), color var(--transition);
}
.nav-bell:hover { background: var(--surface-2); color: var(--text); }
.nav-bell.has-unread { color: var(--text); }
.nav-bell-badge {
    position: absolute;
    top: 0px;
    right: 0px;
    background: var(--danger);
    color: #fff;
    font-size: 0.62rem;
    font-weight: 700;
    line-height: 1;
    padding: 2px 5px;
    border-radius: 999px;
    min-width: 16px;
    text-align: center;
    box-shadow: 0 0 0 2px var(--surface);
}

/* Inbox list */
.notif-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.notif-item {
    display: grid;
    grid-template-columns: 8px 1fr auto;
    gap: 0.75rem;
    align-items: start;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    transition: border-color var(--transition);
}
.notif-item:hover { border-color: var(--border-strong); }
.notif-item.unread { background: var(--brand-soft); border-color: rgba(37,99,235,0.20); }
.notif-dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: transparent;
    margin-top: 0.5rem;
}
.notif-item.unread .notif-dot { background: var(--danger); }
.notif-head { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.notif-type {
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-size: 0.64rem;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: var(--radius-xs);
    background: var(--surface-3);
    color: var(--text-soft);
}
.notif-type.type-mention { background: var(--brand-soft); color: var(--brand); }
.notif-title { font-weight: 500; font-size: 0.92rem; }
.notif-preview {
    margin-top: 0.4rem;
    color: var(--text-soft);
    font-size: 0.88rem;
    line-height: 1.45;
    background: var(--surface-2);
    padding: 8px 10px;
    border-radius: var(--radius-xs);
    border-left: 3px solid var(--border-strong);
}
.notif-meta { margin-top: 0.35rem; display: flex; gap: 0.4rem; color: var(--muted); font-size: 0.78rem; }
.notif-actions { display: flex; flex-direction: column; gap: 0.3rem; align-items: flex-end; }

/* @mention highlight inside rendered comment bodies */
.mention {
    display: inline-block;
    color: var(--brand);
    background: var(--brand-soft);
    padding: 0 4px;
    border-radius: var(--radius-xs);
    font-weight: 600;
    text-decoration: none;
}

/* @mention autocomplete popup */
.mention-popup {
    position: absolute;
    z-index: 1000;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    max-height: 260px;
    overflow-y: auto;
    min-width: 240px;
    padding: 4px 0;
}
.mention-item {
    display: flex;
    align-items: baseline;
    gap: 0.55rem;
    width: 100%;
    padding: 7px 12px;
    border: 0;
    background: transparent;
    text-align: left;
    cursor: pointer;
    font: inherit;
    color: var(--text);
}
.mention-item:hover, .mention-item.selected {
    background: var(--brand-soft);
}
.mention-handle { font-weight: 600; color: var(--brand); }
.mention-name { color: var(--muted); font-size: 0.84rem; }
.mention-empty {
    padding: 8px 12px;
    color: var(--muted);
    font-size: 0.85rem;
}

/* ============================================================
 * Reminders + sub-nav (Notifications ↔ My reminders)
 * ============================================================ */
.subnav {
    display: flex;
    gap: 0.25rem;
    margin: -0.25rem 0 1rem;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.5rem;
}
.subnav a {
    color: var(--text-soft);
    text-decoration: none;
    font-size: 0.88rem;
    font-weight: 500;
    padding: 6px 12px;
    border-radius: var(--radius-xs);
    transition: background var(--transition), color var(--transition);
}
.subnav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.subnav a.active {
    background: var(--brand-soft);
    color: var(--brand);
}
.subnav-count {
    display: inline-block;
    background: var(--surface-3);
    color: var(--muted);
    border-radius: 999px;
    padding: 0 0.5em;
    margin-left: 0.35em;
    font-size: 0.75em;
    font-weight: 600;
}
.subnav a.active .subnav-count {
    background: rgba(37,99,235,0.18);
    color: var(--brand);
}

/* Inline "Add reminder" form on /reminders.php */
.reminder-quick {
    display: flex;
    gap: 0.6rem;
    align-items: flex-end;
    flex-wrap: wrap;
}
.reminder-quick label { display: flex; flex-direction: column; gap: 0.2rem; min-width: 0; }
.reminder-quick label.grow { flex: 1 1 240px; }
.reminder-quick input[type="date"],
.reminder-quick input[type="text"] {
    padding: 7px 10px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-xs);
    background: var(--surface);
    font: inherit;
    font-size: 0.88rem;
}
.reminder-quick.reminder-quick-stack { flex-direction: column; align-items: stretch; }
.reminder-quick.reminder-quick-stack label { width: 100%; }
.reminder-quick.reminder-quick-stack input[type="date"],
.reminder-quick.reminder-quick-stack input[type="text"] { width: 100%; }

/* Sidebar list of this client's pending reminders */
.reminder-list {
    list-style: none;
    padding: 0;
    margin: 0.75rem 0 0;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}
.reminder-list li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 7px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    background: var(--surface-2);
    font-size: 0.84rem;
}
.reminder-list li.reminder-due {
    border-color: rgba(220,38,38,0.3);
    background: var(--danger-soft);
}

.reminder-status {
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-size: 0.66rem;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: var(--radius-xs);
}
.reminder-pending   { background: var(--brand-soft);   color: var(--brand); }
.reminder-fired     { background: var(--success-soft); color: var(--success); }
.reminder-cancelled { background: var(--surface-3);    color: var(--muted); }

tr.reminder-due td:first-child { color: var(--danger); font-weight: 600; }

/* ============================================================
 * IOP Check — inline email compose + history widgets
 * ============================================================ */
.iopcheck-email .iopcheck-email-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 0.6rem;
}
.iopcheck-email-buttons { margin: 0.5rem 0; }
.iopcheck-compose {
    margin-top: 0.85rem;
    padding-top: 0.85rem;
    border-top: 1px solid var(--border);
}
.iopcheck-compose .email-mode-tag {
    background: rgba(0,0,0,0.04);
    border-radius: var(--radius-sm);
    padding: 0.4rem 0.65rem;
    font-size: 0.82rem;
}

/* Scrollable full-comment list inside IOP Check */
.comments-scroll {
    max-height: 280px;
    overflow-y: auto;
    padding-right: 0.4rem;
}

/* Smaller sent-emails / per-invoice table inside IOP Check */
.data-table.small th, .data-table.small td {
    padding: 0.35rem 0.55rem;
    font-size: 0.82rem;
}

.iop-past-invoices summary { cursor: pointer; padding: 0.25rem 0; }

/* ============================================================
 * Logs tab — complete audit_log view on the client page
 * ============================================================ */
.logs-table th, .logs-table td { vertical-align: top; }
.logs-table .logs-action {
    display: inline-block;
    padding: 2px 8px;
    border-radius: var(--radius-xs);
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    background: var(--surface-3);
    color: var(--text-soft);
    white-space: nowrap;
}
.logs-table .logs-action-email_send       { background: var(--brand-soft);   color: var(--brand); }
.logs-table .logs-action-comment_add      { background: var(--success-soft); color: var(--success); }
.logs-table .logs-action-contact_add      { background: rgba(234,88,12,0.12); color: #c2410c; }
.logs-table .logs-action-contact_delete   { background: var(--danger-soft);  color: var(--danger); }
.logs-table .logs-action-client_update    { background: rgba(139,92,246,0.12); color: #6d28d9; }
.logs-table .logs-action-status_change    { background: var(--warn-soft);    color: #b45309; }
.logs-table .logs-action-reminder_add     { background: rgba(14,165,233,0.12); color: #0369a1; }
.logs-table .logs-action-reminder_cancel  { background: var(--surface-3);    color: var(--muted); }
.logs-table .logs-details-pre {
    background: var(--surface-2);
    padding: 8px 10px;
    border-radius: var(--radius-xs);
    font-size: 0.74rem;
    max-width: 100%;
    overflow-x: auto;
    white-space: pre-wrap;
    margin: 0.35rem 0 0;
    border: 1px solid var(--border);
}

/* ============================================================
 * IOP Review — client-page-style header + action bar
 * ============================================================ */
.iopcheck-header {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 18px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    flex-wrap: wrap;
    margin: 0 0 1rem;
    box-shadow: var(--shadow-sm);
}
.iopcheck-header-title h1 {
    font-size: 1.3rem;
    margin: 0 0 4px;
    letter-spacing: -0.01em;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.iopcheck-header-title .muted {
    font-size: 0.84rem;
    color: var(--text-soft);
}
.iopcheck-action-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    flex-shrink: 0;
}
.iopcheck-action-pane { margin-bottom: 1rem; }
.iopcheck-action-pane h3 { font-size: 1rem; font-weight: 600; margin: 0 0 0.5rem; }

/* Client header stats row (Zapadlo / Total / Days …) */
.iopcheck-stats {
    display: flex;
    gap: 1.5rem;
    flex-wrap: wrap;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
    width: 100%;
    flex-basis: 100%;
}
.iopcheck-stats .stat-cell {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.iopcheck-stats .stat-cell .label {
    font-size: 0.66rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--soft);
    font-weight: 600;
}
.iopcheck-stats .stat-cell .value {
    font-size: 1rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}
.iopcheck-stats .stat-cell.danger .value { color: var(--danger); }
.iopcheck-stats .stat-cell.warn .value { color: var(--warn); }
.iopcheck-stats .stat-cell .value.sm { font-size: 0.85rem; font-weight: 500; }

/* ============================================================
 * Trust level — pill + inline select in IOP Review workflow
 * ============================================================ */
.trust-pill {
    display: inline-block;
    padding: 2px 10px;
    border-radius: var(--radius-pill);
    font-size: 0.78rem;
    font-weight: 600;
    border: 1px solid transparent;
    line-height: 1.5;
}
.trust-pill-3     { background: var(--success-soft); color: var(--success); }
.trust-pill-2     { background: var(--brand-soft);   color: var(--brand); }
.trust-pill-1     { background: var(--warn-soft);    color: #b45309; }
.trust-pill-0     { background: var(--danger-soft);  color: var(--danger); }
.trust-pill-unset { background: var(--surface-3);    color: var(--muted); border-color: var(--border); }

/* Inline trust select sitting next to the workflow buttons in the sticky strip */
.iopcheck-progress-actions .trust-select-wrap {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px 4px 12px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    font-size: 0.82rem;
    color: var(--text-soft);
}
.iopcheck-progress-actions .trust-select-wrap:focus-within {
    border-color: var(--brand);
    box-shadow: 0 0 0 3px var(--brand-soft);
}
.iopcheck-progress-actions .trust-select-label {
    color: var(--soft);
    font-weight: 500;
    text-transform: uppercase;
    font-size: 0.7rem;
    letter-spacing: 0.04em;
}
.iopcheck-progress-actions .trust-select {
    border: 0;
    background: transparent;
    color: var(--text);
    font: inherit;
    font-weight: 600;
    padding: 4px 0;
    cursor: pointer;
    outline: none;
}
.iopcheck-progress-actions .trust-select:invalid {
    color: var(--muted);
    font-weight: 500;
}

/* ============================================================
 * Mobile: keep tables horizontally scrollable on their own.
 * Without this, a wide .data-table forces the whole page to
 * scroll sideways, which is hostile on phones. With .table-wrap
 * only the table itself scrolls; the rest of the page stays put.
 *
 * The wrapper is added automatically by app.js around every
 * top-level .data-table — no template changes needed.
 * ============================================================ */
.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius);
    /* Subtle right-edge fade hints "there is more content" — only when
       the table is actually wider than its container and is scrollable.
       Pure cosmetic: background-attachment trick using two layered
       gradients pinned to the right edge. */
    background:
        linear-gradient(to right, transparent, transparent 90%, rgba(15,23,42,0.04)) 100% 0 / 24px 100% no-repeat;
}
.table-wrap > table {
    margin-bottom: 0;
}
/* When the table itself has rounded corners + shadow (its own .data-table
   styling), the wrap mirrors them so the scrollable bounds line up cleanly. */
.table-wrap > .data-table {
    box-shadow: none; /* wrap absorbs the visual frame */
}

/* Slightly tighter cells on small screens so more of the table fits. */
@media (max-width: 768px) {
    /* Hard guard against any accidental horizontal overflow on mobile.
       Wraps every wide element to within the viewport instead of
       pushing the page sideways. */
    html, body { overflow-x: hidden; max-width: 100%; }

    .data-table th,
    .data-table td {
        white-space: nowrap;
        padding: 8px 12px;
        font-size: 0.82rem;
    }
    .data-table thead th {
        font-size: 0.66rem;
    }
    .content {
        padding: 1rem 0.85rem 2.5rem;
    }
    /* Stats grid — let cards drop to 2-up on small phones */
    .stats { gap: 0.65rem; }
    .iopcheck-stats { gap: 0.85rem 1rem; }
    .iopcheck-stats .stat-cell {
        flex: 1 1 calc(50% - 0.5rem);
        min-width: 0;
    }
    .iopcheck-stats .stat-cell .value { font-size: 0.95rem; }
    /* Progress strip wraps; bars and selectors get full width */
    .iopcheck-progress-bar { flex: 1 1 100%; order: 2; }
    .iopcheck-progress-actions {
        flex-wrap: wrap;
        gap: 6px;
    }
    .iopcheck-progress-actions .trust-select-wrap {
        flex: 1 1 100%;
    }

    /* IOP Review / client page header: stack title, action bar, stats vertically. */
    .iopcheck-header {
        padding: 12px 14px;
    }
    .iopcheck-header-title {
        flex: 1 1 100%;
        min-width: 0;
        width: 100%;
    }
    .iopcheck-header-title h1 {
        font-size: 1.1rem;
        flex-wrap: wrap;
        word-break: break-word;
    }
    .iopcheck-action-bar {
        flex: 1 1 100%;
        min-width: 0;
        width: 100%;
        flex-wrap: wrap;
        gap: 6px;
    }
    /* Buttons share the row width — 2 per row on most phones,
       3-4 buttons wrap automatically without overflowing. */
    .iopcheck-action-bar > .btn {
        flex: 1 1 calc(50% - 3px);
        justify-content: center;
        min-width: 0;
        padding: 7px 10px;
        font-size: 0.82rem;
    }

    /* Filters: drop to single-column on phones */
    .filters input,
    .filters select,
    .filters .dropdown-multi {
        flex: 1 1 100%;
    }
    /* Modal padding shrinks */
    .modal-overlay { padding: 3vh 0.5rem 0.5rem; }
    .modal-card { padding: 1.1rem 1rem; }

    /* Topbar: brand + actions get tight; nav scrolls if needed */
    .topbar { padding: 0.5rem 0.85rem; }
    .header-search { width: 100%; }
}

@media (max-width: 480px) {
    /* On very small phones drop action buttons to a single column too. */
    .iopcheck-action-bar > .btn {
        flex: 1 1 100%;
    }
}

/* ============================================================
 * Modal popups — used by Log Manual Notice + Send Debt Notice
 * ============================================================ */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15,23,42,0.55);
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
    z-index: 100;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 5vh 1rem 1rem;
    overflow-y: auto;
    animation: modal-fade-in 0.15s ease;
}
.modal-overlay[hidden] { display: none; }
@keyframes modal-fade-in { from { opacity: 0; } to { opacity: 1; } }

.modal-card {
    background: var(--surface);
    border-radius: var(--radius);
    width: 100%;
    max-width: 640px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    padding: 1.5rem 1.75rem;
    position: relative;
    animation: modal-slide-in 0.2s cubic-bezier(.4,0,.2,1);
}
.modal-card.wide { max-width: 760px; }
@keyframes modal-slide-in {
    from { transform: translateY(-12px); opacity: 0; }
    to   { transform: translateY(0); opacity: 1; }
}
.modal-card > h3 {
    font-size: 1.1rem;
    font-weight: 600;
    margin: 0 0 0.25rem;
    padding-right: 2rem;
}
.modal-card .modal-subtitle {
    color: var(--text-soft);
    font-size: 0.88rem;
    margin: 0 0 1.25rem;
}
.modal-close {
    position: absolute;
    top: 12px;
    right: 12px;
    background: transparent;
    border: 0;
    width: 32px;
    height: 32px;
    border-radius: var(--radius-xs);
    cursor: pointer;
    color: var(--text-soft);
    font-size: 1.5rem;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition), color var(--transition);
}
.modal-close:hover { background: var(--surface-2); color: var(--text); }
.modal-close:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px var(--brand-soft);
}
body.modal-open { overflow: hidden; }

/* ============================================================
 * Multi-select dropdown (filter "Include status", "Show", etc.)
 * Replaces the heavy chip rows with a compact button + popup.
 * ============================================================ */
.dropdown-multi { position: relative; display: inline-block; }
.dropdown-multi-trigger {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 7px 12px;
    border: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--text);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.85rem;
    font-family: inherit;
    font-weight: 500;
    line-height: 1.2;
    white-space: nowrap;
    transition: background var(--transition), border-color var(--transition);
}
.dropdown-multi-trigger:hover { background: var(--surface-2); border-color: var(--text-soft); }
.dropdown-multi-trigger:focus-visible {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px var(--brand-soft);
}
.dropdown-multi.is-open .dropdown-multi-trigger {
    border-color: var(--brand);
    box-shadow: 0 0 0 3px var(--brand-soft);
}
.dropdown-multi-trigger .dropdown-multi-label { color: var(--text-soft); font-weight: 500; }
.dropdown-multi-trigger .dropdown-multi-count {
    display: inline-block;
    background: var(--brand-soft);
    color: var(--brand);
    padding: 1px 8px;
    border-radius: var(--radius-pill);
    font-size: 0.75rem;
    font-weight: 600;
}
.dropdown-multi-trigger .dropdown-multi-count.all  { background: var(--surface-3); color: var(--muted); }
.dropdown-multi-trigger .dropdown-multi-caret {
    color: var(--muted);
    font-size: 0.7rem;
    transition: transform 0.15s ease;
}
.dropdown-multi.is-open .dropdown-multi-caret { transform: rotate(180deg); }

.dropdown-multi-panel {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    min-width: 220px;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    z-index: 40;
    padding: 6px;
    max-height: 60vh;
    overflow-y: auto;
}
.dropdown-multi-panel[hidden] { display: none; }
.dropdown-multi-panel .dropdown-multi-item {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 7px 9px;
    border-radius: var(--radius-xs);
    cursor: pointer;
    font-size: 0.86rem;
    color: var(--text);
    user-select: none;
}
.dropdown-multi-panel .dropdown-multi-item:hover { background: var(--surface-2); }
.dropdown-multi-panel .dropdown-multi-item input[type="checkbox"],
.dropdown-multi-panel .dropdown-multi-item input[type="radio"] {
    accent-color: var(--brand);
    width: 16px;
    height: 16px;
    margin: 0;
    flex: 0 0 auto;
}
.dropdown-multi-panel .dropdown-multi-divider {
    height: 1px;
    background: var(--border);
    margin: 4px 0;
}
.dropdown-multi-panel .dropdown-multi-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 9px 4px;
    border-top: 1px solid var(--border);
    margin-top: 4px;
    gap: 8px;
}
.dropdown-multi-panel .dropdown-multi-footer .btn-link {
    font-size: 0.78rem;
}

/* ============================================================
   Rich text (WYSIWYG) editor — email templates + composers
   ============================================================ */
.rich-editor {
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    overflow: hidden;
}
.rich-editor:focus-within {
    border-color: var(--brand);
    box-shadow: 0 0 0 3px var(--brand-soft);
}
.rich-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: 6px;
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
}
.rte-btn {
    min-width: 32px;
    height: 30px;
    padding: 0 9px;
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    background: var(--surface);
    color: var(--text);
    font-size: 0.82rem;
    line-height: 1;
    cursor: pointer;
    transition: background var(--transition), border-color var(--transition);
}
.rte-btn:hover {
    background: var(--brand-soft);
    border-color: var(--brand);
}
.rte-btn:active { background: var(--surface-3); }
.rte-btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px var(--brand-soft);
}
.rte-btn-clear { color: var(--muted); }
.rich-area {
    padding: 12px 14px;
    font-size: 0.9rem;
    line-height: 1.6;
    color: var(--text);
    outline: none;
    overflow-y: auto;
    max-height: 560px;
}
.rich-area:empty::before {
    content: attr(data-placeholder);
    color: var(--muted);
}
.rich-area p { margin: 0 0 0.7em; }
.rich-area p:last-child { margin-bottom: 0; }
.rich-area ul,
.rich-area ol { margin: 0 0 0.7em 1.4em; padding: 0; }
.rich-area li { margin: 0.15em 0; }
.rich-area a { color: var(--brand); }

/* ============================================================
   Updates feed (updates.php)
   ============================================================ */
.updates-list { list-style: none; margin: 0; padding: 0; }
.update-item {
    display: flex;
    gap: 1rem;
    padding: 0.85rem 0;
    border-bottom: 1px solid var(--border);
}
.update-item:first-child { padding-top: 0; }
.update-item:last-child { border-bottom: none; padding-bottom: 0; }
.update-body { flex: 1 1 auto; min-width: 0; }
.update-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.4rem;
    margin-bottom: 0.3rem;
    font-size: 0.9rem;
}
.update-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: var(--radius-pill);
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.update-badge-comment { background: var(--brand-soft); color: var(--brand); }
.update-badge-notice  { background: var(--warn-soft);  color: var(--warn); }
.update-content {
    font-size: 0.88rem;
    line-height: 1.55;
    color: var(--text-soft);
    word-break: break-word;
}
.update-content.clamped .update-text {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.update-toggle {
    margin-top: 0.3rem;
    padding: 0;
    border: 0;
    background: none;
    color: var(--brand);
    font-weight: 600;
    font-size: 0.82rem;
    font-family: inherit;
    cursor: pointer;
}
.update-toggle:hover { text-decoration: underline; }
.update-failed {
    color: var(--danger);
    font-weight: 600;
    font-size: 0.82rem;
}
.update-when {
    flex: 0 0 auto;
    text-align: right;
    white-space: nowrap;
    font-size: 0.78rem;
    color: var(--muted);
    line-height: 1.4;
}
.update-when-date { display: block; }
.update-when-time { display: block; }
