/* =================================================================
   IOP Manager — Tesla-inspired light theme
   Clean minimalism, generous whitespace, subtle shadows, no clutter.
   ================================================================= */

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

:root {
    --bg:            #f4f4f4;
    --surface:       #ffffff;
    --surface-2:     #fafafa;
    --border:        rgba(0,0,0,0.06);
    --border-strong: rgba(0,0,0,0.12);
    --text:          #171a20;
    --text-soft:     #5c5e62;
    --muted:         #8a8c91;
    --accent:        #171a20;
    --accent-hover:  #393c41;
    --primary:       #3457dc;
    --primary-hover: #2944b8;
    --danger:        #cc0000;
    --success:       #12bb6a;
    --warn:          #e89c2b;
    --shadow-sm:     0 1px 2px rgba(0,0,0,0.04);
    --shadow:        0 4px 16px rgba(0,0,0,0.04), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-lg:     0 12px 40px rgba(0,0,0,0.08), 0 2px 6px rgba(0,0,0,0.04);
    --radius:        14px;
    --radius-sm:     8px;
    --radius-pill:   999px;
    --transition:    180ms 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;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-feature-settings: "cv11", "ss01";
    letter-spacing: -0.005em;
}
h1, h2, h3, h4 { font-weight: 600; letter-spacing: -0.02em; margin: 0; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.05rem; }
a { color: var(--text); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--primary); }
code {
    background: var(--surface-2);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.85em;
    font-family: "SF Mono", "JetBrains Mono", monospace;
    color: var(--text-soft);
}

/* ------------ TOP BAR ----------------------------------------- */
.topbar {
    background: rgba(255,255,255,0.85);
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    border-bottom: 1px solid var(--border);
    padding: 1rem 2rem;
    display: flex;
    align-items: center;
    gap: 2.5rem;
    position: sticky;
    top: 0;
    z-index: 50;
}
.topbar .brand {
    color: var(--text);
    font-weight: 600;
    font-size: 1.05rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}
.topbar .nav-links { display: flex; gap: 2rem; flex: 1; }
.topbar .nav-links a {
    color: var(--text-soft);
    font-size: 0.85rem;
    font-weight: 500;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    transition: color var(--transition);
}
.topbar .nav-links a:hover,
.topbar .nav-links a.active { color: var(--text); }
.topbar .nav-user {
    display: flex;
    gap: 1.5rem;
    align-items: center;
    color: var(--text-soft);
    font-size: 0.85rem;
    font-weight: 500;
}
.topbar .nav-user a { color: var(--text-soft); }
.topbar .nav-user a:hover { color: var(--text); }

/* ------------ LAYOUT ------------------------------------------ */
.content {
    max-width: 1500px;
    margin: 0 auto;
    padding: 2.5rem 2rem 3rem;
}
.footer {
    text-align: center;
    padding: 2rem;
    color: var(--muted);
    font-size: 0.8rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

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

/* ------------ CARD / SURFACE ---------------------------------- */
.card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 1.75rem;
    margin-bottom: 1.25rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    transition: box-shadow var(--transition);
}
.card:hover { box-shadow: var(--shadow-lg); }
.card h2 { font-size: 1rem; font-weight: 600; margin-bottom: 1.25rem; letter-spacing: 0.01em; }

/* ------------ STATS ------------------------------------------- */
.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}
.stat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    transition: transform var(--transition), box-shadow var(--transition);
}
.stat:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.stat-label {
    color: var(--muted);
    font-size: 0.72rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    font-weight: 500;
}
.stat-value {
    font-size: 1.75rem;
    font-weight: 600;
    margin-top: 0.4rem;
    letter-spacing: -0.025em;
}

/* ------------ FILTERS ----------------------------------------- */
.filters {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    margin-bottom: 1.25rem;
    background: var(--surface);
    padding: 1rem 1.25rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}
.filters input,
.filters select {
    padding: 0.55rem 0.85rem;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    background: var(--surface);
    color: var(--text);
    font-family: inherit;
    transition: border var(--transition), box-shadow var(--transition);
}
.filters input:focus,
.filters select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(52,87,220,0.12);
}
.filters .btn { padding: 0.55rem 1rem; }

/* ------------ BUTTONS ----------------------------------------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.65rem 1.4rem;
    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;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    text-decoration: none;
    transition: all var(--transition);
}
.btn:hover {
    background: var(--text);
    color: var(--surface);
    border-color: var(--text);
    transform: translateY(-1px);
}
.btn.primary {
    background: var(--accent);
    color: var(--surface);
    border-color: var(--accent);
}
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.danger { background: var(--danger); color: white; border-color: var(--danger); }
.btn.danger:hover { background: #a30000; border-color: #a30000; }

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

/* ------------ TABLES ------------------------------------------ */
.data-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}
.data-table th,
.data-table td {
    padding: 0.95rem 1.25rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
    font-size: 0.88rem;
}
.data-table thead th {
    background: var(--surface-2);
    color: var(--muted);
    font-weight: 500;
    font-size: 0.72rem;
    letter-spacing: 0.08em;
    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.9rem;
    line-height: 0;
    color: var(--text-soft);
    transition: all var(--transition);
}
.data-table .row-toggle:hover { background: var(--text); color: var(--surface); border-color: var(--text); }

/* 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); }
.data-table thead th a.sort-header.sort-active { color: var(--primary); 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.82rem; padding: 0.7rem 1.25rem; }

/* ------------ BADGES ------------------------------------------ */
.badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: var(--radius-pill);
    background: var(--surface-2);
    color: var(--text-soft);
    font-size: 0.7rem;
    font-weight: 500;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    border: 1px solid var(--border);
}
.badge.status-active       { background: #eef1f5; color: #2d3748; border-color: rgba(45,55,72,0.18); }
.badge.status-under_review { background: #f4ede0; color: #6b5a2d; border-color: rgba(107,90,45,0.18); }
.badge.status-rac_partner  { background: #e7eef3; color: #1e3a5f; border-color: rgba(30,58,95,0.18); }
.badge.status-enforcement  { background: #f0dede; color: #6b2424; border-color: rgba(107,36,36,0.22); }
.badge.status-write_off    { background: #ededed; color: #4a4a4a; border-color: rgba(74,74,74,0.18); }
.badge.status-vip          { background: #e9e4f0; color: #4c3a6b; border-color: rgba(76,58,107,0.18); }

/* ------------ 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: 0.85rem 1.25rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1rem;
    font-size: 0.9rem;
    border: 1px solid;
    box-shadow: var(--shadow-sm);
}
.flash-success { background: #e9faf2; border-color: rgba(18,187,106,0.25); color: #065f46; }
.flash-error   { background: #fde9e9; border-color: rgba(204,0,0,0.25);    color: #991b1b; }
.flash-info    { background: #ecf2ff; border-color: rgba(52,87,220,0.25);  color: #1e3a8a; }

/* ------------ AUTH CARD --------------------------------------- */
.auth-card {
    max-width: 440px;
    margin: 5rem auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2.5rem;
    box-shadow: var(--shadow-lg);
}
.auth-card h1 { font-size: 1.4rem; margin-bottom: 1rem; }
.auth-card label { display: block; margin-bottom: 1.25rem; font-size: 0.85rem; color: var(--text-soft); }
.auth-card label input,
.auth-card label select {
    width: 100%;
    padding: 0.7rem 0.85rem;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    margin-top: 0.35rem;
    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(--primary); box-shadow: 0 0 0 3px rgba(52,87,220,0.12); }
.auth-card .btn { width: 100%; padding: 0.85rem; font-size: 0.9rem; }

/* ------------ MISC -------------------------------------------- */
.muted     { color: var(--muted); }
.small     { font-size: 0.85rem; }
.center    { text-align: center; }
.row       { display: flex; gap: 1rem; align-items: center; }
.stack     { display: flex; flex-direction: column; gap: 0.85rem; }
.stack label {
    display: flex; flex-direction: column;
    font-size: 0.78rem;
    color: var(--text-soft);
    gap: 0.35rem;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    font-weight: 500;
}
.stack label input,
.stack label select,
.stack label textarea {
    padding: 0.6rem 0.85rem;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    color: var(--text);
    font-family: inherit;
    background: var(--surface);
    text-transform: none;
    letter-spacing: normal;
    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(--primary);
    box-shadow: 0 0 0 3px rgba(52,87,220,0.12);
}
.stack label.row { flex-direction: row; align-items: center; }
.inline { display: inline; }

details { margin-top: 0.75rem; }
details summary {
    cursor: pointer;
    color: var(--primary);
    font-size: 0.85rem;
    font-weight: 500;
    list-style: none;
    padding: 0.4rem 0;
}
details summary::-webkit-details-marker { display: none; }
details summary::before {
    content: '+';
    margin-right: 0.4rem;
    font-weight: 400;
    color: var(--text-soft);
    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.75rem 1rem; gap: 1rem; flex-wrap: wrap; }
    .topbar .nav-links { gap: 1rem; }
}

.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.4rem;
    align-items: center;
    width: 100%;
    margin-top: 0.5rem;
}
.status-filter .filter-label {
    font-size: 0.72rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
    font-weight: 500;
    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.35;
    border-style: dashed;
    transition: all var(--transition);
}
.status-chip:hover .badge { opacity: 0.7; }
.status-chip input[type="checkbox"]:checked + .badge {
    opacity: 1;
    border-style: solid;
}
.status-chip input[type="checkbox"]:focus-visible + .badge {
    outline: 2px solid var(--primary);
    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;
    width: 100%;
    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.4rem 0 0.9rem 2rem;
}
.timeline-marker {
    position: absolute;
    left: 0;
    top: 0.55rem;
    width: 15px;
    height: 15px;
    border-radius: 50%;
    background: var(--surface);
    border: 2px solid var(--muted);
    box-shadow: 0 0 0 4px var(--surface);
}
.timeline-comment .timeline-marker        { border-color: var(--primary); }
.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(--accent); background: var(--accent); }
.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.7rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text);
}
.timeline-meta {
    color: var(--muted);
    font-size: 0.78rem;
    margin-left: auto;
}
.timeline-body {
    font-size: 0.92rem;
    color: var(--text);
    white-space: pre-wrap;
}
.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: 0.5rem 0.75rem;
    border-radius: var(--radius-sm);
    overflow-x: auto;
    margin: 0.4rem 0 0;
    color: var(--text-soft);
    font-size: 0.75rem;
}

/* ============== 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: 1rem 1.5rem;
    margin-bottom: 1.25rem;
    box-shadow: var(--shadow-sm);
}
.record-back {
    width: 36px; height: 36px;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: 50%;
    color: var(--text);
    font-size: 1.2rem;
    transition: background var(--transition);
}
.record-back:hover { background: var(--surface-2); }
.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.4rem; }
.record-subtitle {
    color: var(--text-soft);
    font-size: 0.85rem;
    margin-top: 0.25rem;
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}
.record-subtitle .dot { color: var(--border-strong); }
.record-actions { display: flex; gap: 0.5rem; }

/* ============== TABS ============== */
.tabs {
    display: flex;
    gap: 0;
    border-bottom: 1px solid var(--border);
    margin-bottom: 1rem;
    background: var(--surface);
    border-radius: var(--radius) var(--radius) 0 0;
    padding: 0 0.5rem;
    box-shadow: var(--shadow-sm);
}
.tab {
    padding: 0.95rem 1.25rem;
    color: var(--text-soft);
    font-size: 0.8rem;
    font-weight: 500;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    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.5rem;
}
.tab:hover { color: var(--text); text-decoration: none; }
.tab.active {
    color: var(--success);
    border-bottom-color: var(--success);
}
.tab-count {
    background: var(--surface-2);
    color: var(--text-soft);
    font-size: 0.7rem;
    padding: 1px 7px;
    border-radius: var(--radius-pill);
    font-weight: 600;
}
.tab.active .tab-count { background: rgba(18,187,106,0.15); color: var(--success); }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ============== SIDEBAR CARDS ============== */
.sidebar-card { padding: 1.25rem 1.5rem; }
.sidebar-card-head {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text);
    letter-spacing: 0.01em;
    margin-bottom: 0.85rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
}
.sidebar-card .stack label {
    text-transform: none;
    letter-spacing: 0;
    font-size: 0.78rem;
    color: var(--text-soft);
}
.sidebar-foot {
    padding: 0.5rem 1.5rem 1rem;
    text-align: center;
}

/* Related contact */
.related-contact {
    display: flex;
    gap: 0.85rem;
    align-items: flex-start;
}
.avatar {
    width: 38px; height: 38px;
    background: var(--surface-2);
    color: var(--text-soft);
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    flex-shrink: 0;
    border: 1px solid var(--border);
}

/* Key-value Other Info */
.kv {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 0.5rem 1rem;
    margin: 0;
}
.kv dt {
    color: var(--muted);
    font-size: 0.75rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}
.kv dd {
    margin: 0;
    color: var(--text);
    font-size: 0.85rem;
    text-align: right;
}

/* ============== 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: 0.5rem 0.5rem 0.5rem 1rem;
    transition: border-color var(--transition), box-shadow var(--transition);
    margin-bottom: 1.5rem;
}
.timeline-compose:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(52,87,220,0.1);
}
.timeline-compose textarea {
    width: 100%;
    border: 0;
    outline: 0;
    background: transparent;
    resize: vertical;
    min-height: 56px;
    font: 0.95rem/1.5 'Inter', sans-serif;
    color: var(--text);
    padding: 0.6rem 0;
}
.timeline-compose textarea::placeholder { color: var(--muted); }
.timeline-compose .row { padding-top: 0.4rem; border-top: 1px dashed var(--border); }

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

/* 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: 0.55rem 1.2rem;
    background: var(--accent);
    color: var(--surface);
    border: 1px solid var(--accent);
    border-radius: var(--radius-sm);
    font-size: 0.78rem;
    font-weight: 500;
    letter-spacing: 0.02em;
    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(--accent-hover); }
#compose-details[open] > summary { background: var(--text-soft); border-color: var(--text-soft); }

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

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

/* ============== IOP CHECK MODULE ============== */
.iopcheck-progress {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.5rem;
    margin-bottom: 1.25rem;
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 70px;
    z-index: 30;
}
.iopcheck-progress-meta {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: 0.5rem;
}
.iopcheck-progress-bar {
    height: 6px;
    background: var(--surface-2);
    border-radius: var(--radius-pill);
    overflow: hidden;
    position: relative;
}
.iopcheck-progress-bar > span {
    display: block;
    height: 100%;
    background: linear-gradient(90deg, var(--success) 0%, #3457dc 100%);
    border-radius: var(--radius-pill);
    transition: width var(--transition);
}
.iopcheck-progress-actions {
    margin-top: 0.5rem;
    text-align: right;
}

.iopcheck-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem 1.75rem;
    box-shadow: var(--shadow);
}
.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.3rem; 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.72rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
    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: 0.7rem 1.6rem; font-size: 0.85rem; }

.iopcheck-fieldset {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 1rem 1.25rem;
    margin: 0;
}
.iopcheck-fieldset legend {
    font-size: 0.7rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
    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: #fff5f3;
    border-left: 3px solid var(--danger);
}
.data-table tr.invoice-flagged:hover { background: #ffece8; }
.data-table tr.invoice-flagged td { border-bottom-color: rgba(204,0,0,0.15); }

.flag-pill {
    display: inline-block;
    padding: 1px 7px;
    margin-left: 6px;
    border-radius: var(--radius-pill);
    background: rgba(204,0,0,0.12);
    color: var(--danger);
    font-size: 0.65rem;
    letter-spacing: 0.04em;
    font-weight: 600;
    text-transform: uppercase;
}

.iop-flagged-banner {
    background: #fff5f3;
    border: 1px solid rgba(204,0,0,0.2);
    color: #7a1f1f;
    padding: 0.75rem 1rem;
    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: #ecfaf1;
    border-left: 3px solid var(--success);
}
.data-table tr.invoice-credit:hover { background: #d9f4e3; }
.data-table tr.invoice-future {
    background: #fafafa;
    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: 1px 7px;
    margin-left: 6px;
    border-radius: var(--radius-pill);
    background: rgba(18,187,106,0.12);
    color: #0f7a47;
    font-size: 0.65rem;
    letter-spacing: 0.04em;
    font-weight: 600;
    text-transform: uppercase;
}
.future-pill {
    display: inline-block;
    padding: 1px 7px;
    margin-left: 6px;
    border-radius: var(--radius-pill);
    background: rgba(138,140,145,0.15);
    color: var(--muted);
    font-size: 0.65rem;
    letter-spacing: 0.04em;
    font-weight: 600;
    text-transform: uppercase;
}

/* ============== IOP check: credit/debit mixing warning ============== */
.iop-mix-banner {
    background: #fff4e6;
    border: 1px solid rgba(232,156,43,0.35);
    border-left: 4px solid var(--warn);
    color: #6b4715;
    padding: 0.85rem 1.1rem;
    border-radius: var(--radius-sm);
    margin: 0 0 1.25rem;
    font-size: 0.9rem;
}
.iop-mix-banner.info {
    background: #f0f6fc;
    border-color: rgba(52,87,220,0.22);
    border-left-color: var(--primary);
    color: var(--text-soft);
}

/* ============== Email composer banners ============== */
.email-mode-banner {
    background: #fff4e6;
    border: 1px solid rgba(232,156,43,0.35);
    border-left: 4px solid var(--warn);
    color: #6b4715;
    padding: 0.85rem 1.1rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1rem;
    font-size: 0.9rem;
}
.email-mode-banner.stern-recommended {
    background: #fdecec;
    border-color: rgba(204,0,0,0.22);
    border-left-color: var(--danger);
    color: #7a1f1f;
}
.email-mode-banner .btn-link { margin-left: 0.5rem; font-weight: 600; }

.email-overpayment-banner {
    background: #fff4e6;
    border: 1px solid rgba(232,156,43,0.35);
    border-left: 4px solid var(--warn);
    color: #6b4715;
    padding: 0.85rem 1.1rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

.email-mode-tag {
    display: inline-block;
    background: var(--surface-2);
    border: 1px solid var(--border);
    padding: 0.35rem 0.75rem;
    border-radius: var(--radius-sm);
    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: 0.75rem 1rem;
    background: var(--surface-2);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    font-size: 0.88rem;
    align-items: flex-start !important;
}
.email-confirm input[type="checkbox"] {
    width: 18px; height: 18px;
    flex-shrink: 0;
    margin-top: 2px;
}
.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-2);
    border: 1px solid var(--border-strong);
    color: var(--text-soft);
    opacity: 0.65;
    cursor: pointer;
    transition: all var(--transition);
}
.view-chip:hover .badge.view-badge { opacity: 0.95; }
.view-chip input[type="radio"]:checked + .badge.view-badge {
    background: var(--text);
    color: var(--surface);
    border-color: var(--text);
    opacity: 1;
}

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

/* ============ Dashboard: expanded row visual link ============ */
.data-table tr.client-row.row-expanded {
    background: #f3f4f5;
    box-shadow: inset 4px 0 0 var(--text);
}
.data-table tr.client-row.row-expanded:hover { background: #ebedef; }
.data-table tr.client-row.row-expanded td { border-bottom-color: transparent; }
.data-table tr.client-row.row-expanded .row-toggle {
    background: var(--text);
    color: white;
    border-color: var(--text);
}
.data-table tr.invoices-row > td.invoices-cell {
    border-left: 4px solid var(--text);
    background: #f6f7f8 !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(--muted);
    font-size: 0.66rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    border-bottom: 1px solid var(--border-strong);
    padding: 0.5rem 1rem;
}
table.sub-invoices tbody td {
    padding: 0.5rem 1rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.85rem;
}
table.sub-invoices tr.year-head td {
    background: rgba(0,0,0,0.04);
    color: var(--text);
    font-weight: 700;
    font-size: 0.78rem;
    letter-spacing: 0.05em;
    padding: 0.55rem 1rem;
    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: rgba(0,0,0,0.04);
    border-top: 2px solid var(--border-strong);
    padding: 0.65rem 1rem;
    font-size: 0.88rem;
    color: var(--text);
}

/* ============== NOTICE LEVEL pills + manual mark toolbar ============== */
.notice-level-pill {
    display: inline-block;
    padding: 1px 7px;
    margin-left: 6px;
    border-radius: var(--radius-pill);
    font-size: 0.65rem;
    letter-spacing: 0.04em;
    font-weight: 700;
    text-transform: uppercase;
}
.notice-level-1 { background: #fef7e6; color: #92400e; border: 1px solid rgba(146,64,14,0.18); }
.notice-level-2 { background: #ffefe1; color: #9a3412; border: 1px solid rgba(154,52,18,0.22); }
.notice-level-3 { background: #fee9e9; color: #991b1b; border: 1px solid rgba(153,27,27,0.25); }

.manual-mark-toolbar {
    margin-top: 1rem;
    padding: 0.85rem 1.1rem;
    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 .btn { padding: 0.4rem 0.85rem; font-size: 0.74rem; }
.manual-mark-toolbar .btn:hover { background: var(--text); color: var(--surface); }

/* 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); }
