/* ============================================================
   KidKare Finance - Invoice Automation
   Dark Theme Styles
   ============================================================ */

:root {
    --bg-primary: #0f1419;
    --bg-secondary: #1a2332;
    --bg-card: #1c2a3a;
    --bg-header: #0d1117;
    --bg-nav: #161b22;
    --bg-table-header: #151d28;
    --bg-table-row: #0f1419;
    --bg-table-row-alt: #131a24;
    --bg-input: #1c2a3a;
    --bg-modal: rgba(0, 0, 0, 0.7);

    --text-primary: #e6edf3;
    --text-secondary: #8b949e;
    --text-muted: #6e7681;

    --accent: #2ea7a7;
    --accent-hover: #3dd8d8;
    --accent-light: #2ea7a740;

    --danger: #f85149;
    --warning: #d29922;
    --success: #3fb950;

    --border: #30363d;
    --border-light: #21262d;
    --rail-bg: #1A202C;
    --rail-icon-color: #718096;
    --rail-hover-bg: rgba(255,255,255,0.05);
    --rail-active-bg: rgba(255,255,255,0.08);

    --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    --font-mono: 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
}

/* ---- Light Theme Override ---- */
[data-theme="light"] {
    --bg-primary: #f0f2f5;
    --bg-secondary: #ffffff;
    --bg-card: #ffffff;
    --bg-header: #f6f8fa;
    --bg-nav: #ffffff;
    --bg-table-header: #f6f8fa;
    --bg-table-row: #ffffff;
    --bg-table-row-alt: #f8f9fb;
    --bg-input: #ffffff;
    --bg-modal: rgba(0, 0, 0, 0.4);

    --text-primary: #1f2328;
    --text-secondary: #656d76;
    --text-muted: #8b949e;

    --accent: #0e8a8a;
    --accent-hover: #0a6e6e;
    --accent-light: #0e8a8a25;

    --danger: #d1242f;
    --warning: #9a6700;
    --success: #1a7f37;

    --border: #d0d7de;
    --border-light: #e3e8ee;
    --rail-bg: #2D3748;
    --rail-icon-color: #A0AEC0;
    --rail-hover-bg: rgba(255,255,255,0.08);
    --rail-active-bg: rgba(255,255,255,0.12);
}

[data-theme="light"] .login-page {
    background: linear-gradient(135deg, #e8ecf1 0%, #f0f2f5 50%, #e8ecf1 100%);
}

[data-theme="light"] .login-card,
[data-theme="light"] .top-nav {
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

[data-theme="light"] .filter-date {
    color-scheme: light;
}

/* ---- Reset & Base ---- */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    font-family: var(--font-family);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a {
    color: var(--accent);
    text-decoration: none;
}

a:hover {
    color: var(--accent-hover);
    text-decoration: underline;
}

/* ============================================================
   LOGIN PAGE
   ============================================================ */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #0f1419 0%, #1a2332 50%, #0f1419 100%);
}

.login-container {
    width: 100%;
    max-width: 400px;
    padding: 20px;
}

.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 40px 32px;
}

.login-header {
    text-align: center;
    margin-bottom: 32px;
}

.login-header h1 {
    font-size: 24px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.login-header p {
    color: var(--text-secondary);
    font-size: 14px;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.form-group input {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}

.form-group input:focus {
    border-color: var(--accent);
}

.error-message {
    background: rgba(248, 81, 73, 0.1);
    border: 1px solid rgba(248, 81, 73, 0.3);
    color: var(--danger);
    padding: 10px 14px;
    border-radius: 6px;
    font-size: 13px;
    margin-bottom: 16px;
}

.btn-primary {
    width: 100%;
    padding: 12px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* ============================================================
   TOP NAVIGATION
   ============================================================ */
.top-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 56px;
    padding: 0 20px;
    background: var(--bg-nav);
    border-bottom: 1px solid var(--border-light);
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-left, .nav-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.nav-icon-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 6px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    transition: color 0.2s, background 0.2s;
}

.nav-icon-btn:hover {
    color: var(--text-primary);
    background: var(--bg-secondary);
}

.nav-sync-btn {
    gap: 6px;
    padding: 6px 10px;
}
.nav-sync-btn .sync-label {
    font-size: 13px;
    font-weight: 500;
}

/* Syncing state: spinning icon + accent color; stops when complete */
.nav-sync-btn.syncing {
    color: var(--accent);
    pointer-events: none;
}
.nav-sync-btn.syncing svg {
    animation: nav-sync-spin 1s linear infinite;
}
@keyframes nav-sync-spin {
    to { transform: rotate(360deg); }
}

.sync-date-input {
    font-size: 13px;
    padding: 6px 8px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--bg-primary);
    color: var(--text-primary);
}

.nav-title {
    font-size: 26px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
    line-height: 1;
}

/* Environment Switcher */
.env-switcher {
    display: flex;
    align-items: center;
}

.env-toggle {
    background: none;
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 4px 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s;
}

.env-toggle:hover {
    border-color: var(--accent);
}

.env-label {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.env-switcher[data-env="test"] .env-toggle {
    border-color: var(--warning);
    background: rgba(210, 153, 34, 0.1);
}

.env-switcher[data-env="test"] .env-label {
    color: var(--warning);
}

.env-switcher[data-env="production"] .env-toggle {
    border-color: var(--success);
    background: rgba(63, 185, 80, 0.1);
}

.env-switcher[data-env="production"] .env-label {
    color: var(--success);
}

.user-email {
    color: var(--text-secondary);
    font-size: 13px;
}

/* ============================================================
   DASHBOARD MAIN
   ============================================================ */
.dashboard-main {
    padding: 24px 28px;
    margin: 0;
    margin-left: 48px;
    position: relative;
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 20, 25, 0.85);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 200;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 16px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-overlay p {
    color: var(--text-secondary);
    font-size: 14px;
}

/* ============================================================
   STATS ROW
   ============================================================ */
.stats-row {
    display: flex;
    gap: 16px;
    margin-bottom: 24px;
    align-items: stretch;
    flex-wrap: wrap;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px 20px;
    min-width: 150px;
    flex: 1;
    position: relative;
}

.stat-header {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 8px;
}

.stat-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: none;
    flex: 1;
}

.stat-warning {
    display: inline-flex;
}

.stat-menu-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 16px;
    padding: 2px 4px;
    line-height: 1;
}

.stat-value {
    font-size: 36px;
    font-weight: 700;
    line-height: 1.1;
    margin-bottom: 2px;
}

.stat-dollar {
    font-size: 36px;
}

.stat-label {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.stat-trend {
    font-size: 13px;
    font-weight: 600;
}

.trend-positive {
    color: var(--accent);
}

.trend-negative {
    color: var(--danger);
}


.btn-send {
    background: var(--accent);
    color: #fff;
    border: none;
    padding: 14px 28px;
    border-radius: 28px;
    font-size: 14px;
    font-weight: 700;
    letter-spacing: 0.5px;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
    white-space: nowrap;
}

.btn-sm {
    padding: 8px 16px;
    font-size: 12px;
}


.btn-send:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
}

.btn-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* ============================================================
   TAB BAR
   ============================================================ */
.tab-bar {
    display: flex;
    align-items: center;
    background: var(--bg-secondary);
    border-radius: 8px 8px 0 0;
    border: 1px solid var(--border);
    border-bottom: none;
    overflow: hidden;
}

.tabs {
    display: flex;
    flex: 1;
}

.tab {
    background: none;
    border: none;
    color: var(--text-secondary);
    padding: 12px 24px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: color 0.2s, border-color 0.2s, background 0.2s;
}

.tab:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.03);
}

.tab.active {
    color: var(--text-primary);
    border-bottom-color: var(--accent);
    background: rgba(46, 167, 167, 0.08);
}

.tab-filters {
    padding: 0 16px;
}

.status-filter {
    display: inline-flex;
    gap: 4px;
    margin-right: 12px;
}

.status-chip {
    background: var(--bg-card);
    color: var(--text-secondary);
    border: 1px solid var(--border);
    padding: 5px 14px;
    border-radius: 16px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    font-family: var(--font-family);
}

.status-chip:hover {
    color: var(--text-primary);
    border-color: var(--accent);
}

.status-chip.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.filter-select {
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border);
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 13px;
    cursor: pointer;
    outline: none;
    text-align: left;
}

.filter-select:focus {
    border-color: var(--accent);
}

.custom-date-range {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-left: 8px;
}

.filter-date {
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border);
    padding: 6px 10px;
    border-radius: 4px;
    font-size: 13px;
    outline: none;
    font-family: var(--font-family);
    color-scheme: dark;
}

.filter-date:focus {
    border-color: var(--accent);
}

.date-separator {
    color: var(--text-secondary);
    font-size: 13px;
}

.btn-apply-date {
    background: var(--accent);
    color: #fff;
    border: none;
    padding: 6px 14px;
    border-radius: 4px;
    font-size: 13px;
    cursor: pointer;
    font-family: var(--font-family);
}

.btn-apply-date:hover {
    background: var(--accent-hover);
}

/* ============================================================
   SEARCH BAR
   ============================================================ */
.search-bar {
    display: flex;
    gap: 12px;
    padding: 12px 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-top: none;
    align-items: center;
}

.search-field {
    position: relative;
    flex: 1;
    max-width: 320px;
}

.search-icon {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}

.search-field input {
    width: 100%;
    padding: 8px 12px 8px 34px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 13px;
    outline: none;
    transition: border-color 0.2s;
}

.search-field input:focus {
    border-color: var(--accent);
}

.search-field input::placeholder {
    color: var(--text-muted);
}

.btn-clear-search {
    background: var(--bg-card);
    color: var(--text-secondary);
    border: 1px solid var(--border);
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
    transition: color 0.2s, background 0.2s;
    white-space: nowrap;
}

.btn-clear-search:hover {
    color: var(--text-primary);
    background: var(--border);
}

/* ============================================================
   DATA TABLE
   ============================================================ */
.table-container {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 8px 8px;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.data-table thead {
    background: var(--bg-table-header);
}

.data-table th {
    padding: 12px 16px;
    text-align: left;
    font-weight: 600;
    font-style: italic;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border);
    font-size: 12px;
}

.data-table td {
    padding: 10px 16px;
    border-bottom: 1px solid var(--border-light);
}

.data-table tbody tr {
    background: var(--bg-table-row);
    transition: background 0.15s;
}

.data-table tbody tr:nth-child(even) {
    background: var(--bg-table-row-alt);
}

.data-table tbody tr:hover {
    background: rgba(46, 167, 167, 0.05);
}

.col-customer {
    max-width: 180px;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.customer-link {
    color: var(--accent);
    font-weight: 500;
}

.customer-link:hover {
    color: var(--accent-hover);
}

.sparkline {
    display: inline-block;
    vertical-align: middle;
}

.text-accent {
    color: var(--accent);
}

.text-danger {
    color: var(--danger);
}

.table-empty {
    text-align: center;
    padding: 40px 16px !important;
    color: var(--text-muted);
}

.table-error {
    color: var(--danger);
}

/* Sortable column headers */
.data-table th.sortable {
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
    transition: color 0.15s;
}

.data-table th.sortable:hover {
    color: var(--text-primary);
}

.data-table th.sortable .sort-icon::after {
    content: '\2195';
    margin-left: 4px;
    font-size: 10px;
    opacity: 0.3;
    font-style: normal;
}

.data-table th.sortable.sort-asc .sort-icon::after {
    content: '\25B2';
    opacity: 1;
    color: var(--accent);
}

.data-table th.sortable.sort-desc .sort-icon::after {
    content: '\25BC';
    opacity: 1;
    color: var(--accent);
}

/* Hide type column when on a specific sponsor tab */
.data-table.hide-type-col .col-type {
    display: none;
}

/* Email column */
.col-email {
    font-size: 12px;
    color: var(--text-secondary);
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Checkbox column */
.col-checkbox {
    width: 40px;
    text-align: center;
}

.col-checkbox input[type="checkbox"] {
    accent-color: var(--accent);
    width: 16px;
    height: 16px;
    cursor: pointer;
}

.data-table tbody tr.row-selected {
    background: rgba(46, 167, 167, 0.1);
}

.data-table tbody tr.row-selected:hover {
    background: rgba(46, 167, 167, 0.15);
}

/* Selection Toolbar */
.selection-toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    background: var(--bg-card);
    border: 1px solid var(--accent);
    border-radius: 6px;
    margin-bottom: 12px;
    font-size: 13px;
    color: var(--text-primary);
}

.selection-toolbar #selectionCount,
.selection-toolbar #arAgingSelectionCount {
    flex: 1;
    font-weight: 600;
    color: var(--accent);
}

.btn-send-sm {
    padding: 8px 20px;
    font-size: 13px;
    border-radius: 20px;
}

.btn-clear-selection {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 13px;
    cursor: pointer;
    transition: color 0.2s, border-color 0.2s;
}

.btn-clear-selection:hover {
    color: var(--text-primary);
    border-color: var(--text-secondary);
}

/* ============================================================
   MODAL
   ============================================================ */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-modal);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 300;
}

.modal {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    width: 560px;
    max-width: 90vw;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px 16px;
    border-bottom: 1px solid var(--border-light);
}

.modal-header h2 {
    font-size: 18px;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 24px;
    cursor: pointer;
    padding: 4px 8px;
    line-height: 1;
}

.modal-close:hover {
    color: var(--text-primary);
}

.modal-body {
    padding: 20px 24px;
    overflow-y: auto;
    flex: 1;
}

#syncModalMessage {
    white-space: pre-line;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding: 16px 24px 20px;
    border-top: 1px solid var(--border-light);
}

.btn-secondary {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border);
    padding: 10px 20px;
    border-radius: 6px;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-secondary:hover {
    background: var(--border);
}

.invoice-checklist {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 12px;
}

.checklist-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--bg-secondary);
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    transition: background 0.15s;
}

.checklist-item:hover {
    background: var(--bg-table-row-alt);
}

.checklist-item.select-all {
    background: var(--bg-card);
    border: 1px solid var(--border);
    margin-bottom: 4px;
}

.checklist-item input[type="checkbox"] {
    accent-color: var(--accent);
    width: 16px;
    height: 16px;
}

.send-results h3 {
    margin-bottom: 12px;
    font-size: 15px;
}

.send-results ul {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.send-results li {
    padding: 8px 12px;
    border-radius: 4px;
    font-size: 13px;
}

.result-success {
    background: rgba(63, 185, 80, 0.1);
    color: var(--success);
}

.result-fail {
    background: rgba(248, 81, 73, 0.1);
    color: var(--danger);
}

/* ============================================================
   INVOICE DETAIL MODAL (split-panel)
   ============================================================ */

.modal-wide {
    width: 1200px;
    max-width: 95vw;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
}

.modal-split {
    display: flex;
    flex-direction: row;
    padding: 0;
    gap: 0;
    overflow: hidden;
    flex: 1;
    min-height: 0;
}

/* --- Left Panel: Invoice List --- */

.invoice-list-panel {
    width: 340px;
    min-width: 280px;
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    background: var(--bg-secondary);
}

.invoice-list-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-light);
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 600;
    flex-shrink: 0;
}

.invoice-list-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

/* (mrr-filter-controls class removed — sort controls now use mrr-sort-controls) */

/* Header controls row (chips + toggle buttons in modal header) */
.mrr-header-controls {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-left: auto;
    margin-right: 12px;
    flex-shrink: 1;
    flex-wrap: wrap;
}
.mrr-header-divider {
    width: 1px;
    height: 18px;
    background: var(--border);
    flex-shrink: 0;
}
.mrr-toggle-btn {
    font-size: 10px;
    padding: 2px 8px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--bg-primary);
    color: var(--text-secondary);
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s, border-color 0.15s;
}
.mrr-toggle-btn.active {
    background: var(--accent-light);
    border-color: var(--accent);
    color: var(--text-primary);
}
.mrr-toggle-btn:hover {
    border-color: var(--accent);
}

.mrr-filter-select {
    font-size: 11px;
    padding: 2px 4px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--bg-primary);
    color: var(--text-primary);
    cursor: pointer;
}

.mrr-filter-op {
    width: 48px;
}

.mrr-filter-amount-group {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.mrr-filter-input {
    font-size: 11px;
    padding: 2px 4px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--bg-primary);
    color: var(--text-primary);
    width: 72px;
}

.mrr-filter-input:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.mrr-modal-product-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.mrr-modal-product-chips .status-chip {
    padding: 3px 8px;
    font-size: 10px;
    border-radius: 12px;
    cursor: pointer;
}

/* Sort dropdown button */
.mrr-sort-controls {
    display: inline-flex;
    align-items: center;
}
.mrr-sort-dropdown-wrap {
    position: relative;
}
.mrr-sort-btn {
    font-size: 11px;
    padding: 3px 8px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--bg-primary);
    color: var(--text-primary);
    cursor: pointer;
    white-space: nowrap;
}
.mrr-sort-btn:hover {
    border-color: var(--accent);
}
.mrr-sort-arrow {
    font-size: 9px;
    margin-left: 2px;
}
.mrr-sort-menu {
    position: absolute;
    top: 100%;
    left: 0;
    margin-top: 2px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    z-index: 100;
    min-width: 120px;
    overflow: hidden;
}
.mrr-sort-option {
    padding: 6px 12px;
    font-size: 12px;
    cursor: pointer;
    color: var(--text-primary);
    white-space: nowrap;
}
.mrr-sort-option:hover {
    background: var(--accent-light);
}
.mrr-sort-option.active {
    color: var(--accent);
    font-weight: 600;
}

.invoice-list {
    flex: 1;
    overflow-y: auto;
}

.invoice-list-loading,
.invoice-list-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 16px;
    color: var(--text-muted);
    font-size: 13px;
    gap: 8px;
    text-align: center;
}

.spinner-sm {
    width: 24px;
    height: 24px;
    border-width: 2px;
}

/* --- Invoice List Items --- */

.invoice-list-item {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-light);
    cursor: pointer;
    transition: background 0.15s;
}

.invoice-list-item:hover {
    background: rgba(46, 167, 167, 0.05);
}

.invoice-list-item.active {
    background: var(--accent-light);
    border-left: 3px solid var(--accent);
    padding-left: 13px;
}

.invoice-list-item-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 4px;
}

.invoice-list-item-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.invoice-list-item-amount {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-primary);
    white-space: nowrap;
}

.invoice-list-item-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.invoice-list-item-separator {
    color: var(--text-muted);
    font-size: 8px;
}

.invoice-list-item-status-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.invoice-list-item-status {
    display: inline-block;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.5px;
    padding: 2px 8px;
    border-radius: 3px;
    text-transform: uppercase;
}

.invoice-list-item-mrr-delta {
    font-size: 11px;
    font-weight: 600;
}

.mrr-delta-up { color: var(--success); }
.mrr-delta-down { color: var(--danger); }
.mrr-delta-neutral { color: var(--text-secondary); }

.status-draft { background: rgba(210, 153, 34, 0.15); color: var(--warning); }
.status-sent, .status-viewed { background: rgba(46, 167, 167, 0.15); color: var(--accent); }
.status-paid { background: rgba(63, 185, 80, 0.15); color: var(--success); }
.status-overdue { background: rgba(248, 81, 73, 0.15); color: var(--danger); }
.status-partiallypaid { background: rgba(46, 167, 167, 0.1); color: var(--accent); }
.status-void { background: rgba(110, 118, 129, 0.15); color: var(--text-muted); }

/* --- Right Panel: Invoice Detail --- */

.invoice-detail-panel {
    flex: 1;
    overflow-y: auto;
    background: var(--bg-primary);
    display: flex;
    flex-direction: column;
    min-width: 0;
    position: relative;
}

.invoice-detail-loading,
.invoice-detail-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    color: var(--text-muted);
    font-size: 14px;
    gap: 12px;
    flex: 1;
    text-align: center;
}

.invoice-detail-loading {
    position: absolute;
    inset: 0;
    background: var(--bg-primary);
    z-index: 5;
}

.invoice-detail-content {
    padding: 24px;
    overflow-y: auto;
    flex: 1;
}

/* --- Invoice Preview (rendered invoice document) --- */

.invoice-preview {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 32px;
    position: relative;
    max-width: 800px;
    margin: 0 auto;
}

.invoice-preview-badge {
    position: absolute;
    top: 16px;
    left: -4px;
    padding: 4px 12px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.5px;
    border-radius: 0 4px 4px 0;
    color: #fff;
}

.badge-paid { background: var(--success); }
.badge-draft { background: var(--warning); }
.badge-sent, .badge-viewed { background: var(--accent); }
.badge-overdue { background: var(--danger); }
.badge-void { background: var(--text-muted); }
.badge-partially_paid { background: var(--accent); }

.invoice-preview-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 32px;
    padding-bottom: 20px;
    border-bottom: 2px solid var(--accent);
}

.invoice-preview-brand {
    font-size: 24px;
    font-weight: 700;
    color: var(--accent);
}

.invoice-preview-brand-sub {
    font-size: 11px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.invoice-preview-logo p {
    font-size: 12px;
    color: var(--text-secondary);
    line-height: 1.6;
    margin: 0;
}

.invoice-preview-title {
    text-align: right;
}

.invoice-preview-title h3 {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0 0 4px 0;
}

.invoice-preview-title p {
    font-size: 13px;
    color: var(--text-secondary);
    margin: 0;
}

.invoice-preview-balance-box {
    margin-top: 8px;
    padding: 8px 12px;
    background: var(--bg-secondary);
    border-radius: 4px;
    text-align: right;
}

.invoice-preview-balance-box span {
    display: block;
    font-size: 11px;
    color: var(--text-secondary);
    font-weight: 600;
}

.invoice-preview-balance-box strong {
    font-size: 18px;
    color: var(--text-primary);
}

/* Bill-to and dates */

.invoice-preview-info {
    display: flex;
    justify-content: space-between;
    margin-bottom: 24px;
    gap: 24px;
}

.invoice-preview-label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.invoice-preview-billto strong {
    display: block;
    color: var(--accent);
    font-size: 14px;
    margin-bottom: 2px;
}

.invoice-preview-billto p {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.5;
    margin: 0;
}

.invoice-preview-emails-edit {
    margin-top: 12px;
    padding: 0 2px 16px;
}

.invoice-preview-emails-edit .invoice-preview-label {
    display: block;
    margin-bottom: 4px;
}

.invoice-preview-emails-edit textarea {
    width: 100%;
    font-size: 13px;
    color: var(--text-secondary);
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 4px 6px;
    font-family: var(--font-family);
    line-height: 1.5;
    resize: none;
    overflow: hidden;
    box-sizing: border-box;
}

.invoice-preview-emails-edit textarea:focus {
    outline: none;
    border-color: var(--accent);
}

.invoice-preview-emails-actions {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 6px;
    margin-top: 6px;
}

.invoice-preview-emails-edit #saveEmailsBtn {
    background: var(--accent);
    color: #fff;
    border: none;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 12px;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s;
}

.invoice-preview-emails-edit #saveEmailsBtn:hover {
    background: var(--accent-hover);
}

.invoice-preview-emails-edit #saveEmailsBtn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.email-save-success {
    font-size: 12px;
    color: var(--success);
    white-space: nowrap;
}

.email-save-error {
    font-size: 12px;
    color: var(--danger);
    white-space: nowrap;
}

.invoice-preview-notes {
    margin-top: 8px;
    font-style: italic;
    color: var(--text-muted) !important;
    font-size: 12px !important;
    white-space: pre-line;
}

.invoice-preview-dates {
    text-align: right;
    flex-shrink: 0;
}

.invoice-preview-dates div {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    margin-bottom: 4px;
    font-size: 13px;
}

.invoice-preview-dates div span:first-child {
    color: var(--text-secondary);
}

.invoice-preview-dates div span:last-child {
    font-weight: 600;
    color: var(--text-primary);
    min-width: 100px;
    text-align: right;
}

/* Line items table */

.invoice-preview-lines {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 24px;
    font-size: 13px;
}

.invoice-preview-lines thead {
    background: var(--accent);
}

.invoice-preview-lines th {
    padding: 10px 12px;
    text-align: left;
    font-weight: 600;
    color: #fff;
    font-size: 12px;
}

.invoice-preview-lines th.col-num { width: 40px; text-align: center; }
.invoice-preview-lines th.col-qty,
.invoice-preview-lines th.col-rate,
.invoice-preview-lines th.col-amount { text-align: right; width: 90px; }

.invoice-preview-lines td {
    padding: 12px;
    border-bottom: 1px solid var(--border-light);
    vertical-align: top;
    color: var(--text-primary);
}

.invoice-preview-lines td:first-child {
    text-align: center;
    color: var(--text-secondary);
}

.invoice-preview-lines td.text-right {
    text-align: right;
}

.invoice-preview-lines .line-description {
    font-size: 12px;
    color: var(--text-secondary);
    line-height: 1.5;
}

/* Totals */

.invoice-preview-totals {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
}

.total-line {
    display: flex;
    justify-content: space-between;
    min-width: 250px;
    padding: 6px 12px;
    font-size: 13px;
}

.total-line span:first-child { color: var(--text-secondary); }
.total-line span:last-child { font-weight: 600; text-align: right; min-width: 100px; }

.total-main {
    font-weight: 700;
    border-top: 1px solid var(--border);
    margin-top: 4px;
    padding-top: 8px;
}

.total-main span:last-child {
    font-size: 15px;
    color: var(--text-primary);
}

.total-balance {
    background: var(--bg-secondary);
    border-radius: 4px;
    font-weight: 700;
    padding: 10px 12px;
    margin-top: 4px;
}

.total-balance span:last-child {
    font-size: 16px;
    color: var(--text-primary);
}

/* Payments section */

.invoice-preview-payments {
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--border-light);
}

.invoice-preview-payments .invoice-preview-label {
    margin-bottom: 8px;
    display: block;
}

.invoice-preview-payments-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.invoice-preview-payments-table th {
    text-align: left;
    font-weight: 600;
    color: var(--text-secondary);
    padding: 6px 8px;
    border-bottom: 1px solid var(--border);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.invoice-preview-payments-table td {
    padding: 8px 8px;
    border-bottom: 1px solid var(--border-light);
    color: var(--text-primary);
}

.invoice-preview-payments-table th.text-right,
.invoice-preview-payments-table td.text-right {
    text-align: right;
}

/* ============================================================
   AR AGING REPORT (inline panel)
   ============================================================ */

.ar-aging-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    color: var(--text-muted);
    gap: 12px;
}

.ar-aging-error {
    text-align: center;
    padding: 40px 20px;
    color: var(--danger);
    font-size: 14px;
}

.ar-overdue-filter {
    display: inline-flex;
    gap: 4px;
    margin-right: 12px;
}

.ar-result-count {
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
}

/* -- AR Aging table wrapper -- */
.ar-aging-table-wrap {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 8px 8px;
}

.ar-aging-table .ar-col-amount {
    text-align: right;
    font-variant-numeric: tabular-nums;
    min-width: 100px;
}

.ar-aging-table .ar-drilldown {
    cursor: pointer;
    color: var(--accent);
    font-weight: 500;
}

.ar-aging-table .ar-drilldown:hover {
    color: var(--accent-hover);
    text-decoration: underline;
}

.ar-aging-table thead th.ar-col-amount {
    text-align: right;
}

.ar-aging-grand-total {
    background: var(--bg-table-header) !important;
}

.ar-aging-grand-total td {
    border-top: 2px solid var(--accent);
    padding-top: 12px;
    padding-bottom: 12px;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */

/* ---- Tablet landscape / small desktop (<=1200px) ---- */
@media (max-width: 1200px) {
    .stats-row {
        gap: 12px;
    }

    .stat-card {
        min-width: 150px;
    }

    /* Hide T-2 columns to free space */
    .col-t2 {
        display: none;
    }

    .data-table th,
    .data-table td {
        padding: 10px 10px;
        font-size: 12px;
    }
}

/* ---- Tablet portrait (<=900px) ---- */
@media (max-width: 900px) {
    .dashboard-main {
        padding: 16px;
    }

    /* Stats: 2-column grid */
    .stats-row {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 12px;
    }

    .stat-card {
        min-width: 0;
    }

    /* Tab bar stacks */
    .tab-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .tabs {
        flex-wrap: wrap;
    }

    .tab-filters {
        padding: 8px 16px 12px;
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
        align-items: center;
    }

    .custom-date-range {
        margin-left: 0;
        flex-wrap: wrap;
    }

    /* Search bar stacks */
    .search-bar {
        flex-direction: column;
        gap: 8px;
    }

    .search-field {
        max-width: none;
    }

    .btn-clear-search {
        align-self: flex-end;
    }

    /* Also hide trend, MoM & email columns */
    .col-trend,
    .col-mom,
    .col-email {
        display: none;
    }

    /* AR Aging table: reduce min-width on tablet */
    .ar-aging-table .ar-col-amount {
        min-width: 80px;
    }

    .data-table th,
    .data-table td {
        padding: 8px 8px;
        font-size: 12px;
    }

    .data-table th {
        font-size: 11px;
    }

    /* Modal full-width */
    .modal {
        width: 95vw;
    }

    /* Invoice detail modal: stack panels vertically */
    .modal-split {
        flex-direction: column;
        min-height: 0;
    }

    .invoice-list-panel {
        width: 100%;
        min-width: 0;
        max-height: 200px;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    .mrr-header-controls {
        display: none !important;
    }
    .mrr-sort-controls {
        display: none !important;
    }

    .invoice-detail-panel {
        min-height: 300px;
    }

    .invoice-preview {
        padding: 20px;
    }

    .invoice-preview-header {
        flex-direction: column;
        gap: 16px;
    }

    .invoice-preview-title {
        text-align: left;
    }

    .invoice-preview-info {
        flex-direction: column;
        gap: 16px;
    }

    .invoice-preview-dates {
        text-align: left;
    }

    .invoice-preview-dates div {
        justify-content: flex-start;
    }
}

/* ---- Mobile (<=600px) ---- */
@media (max-width: 600px) {
    /* Nav */
    .top-nav {
        padding: 0 12px;
    }

    .nav-right {
        gap: 4px;
    }

    .user-email {
        display: none;
    }

    .dashboard-main {
        padding: 12px;
    }

    .nav-title {
        font-size: 18px;
    }

    /* Stats: single column */
    .stats-row {
        grid-template-columns: 1fr;
    }

    .stat-value {
        font-size: 28px;
    }

    .stat-dollar {
        font-size: 24px;
    }

    /* Tabs: equal-width */
    .tabs {
        width: 100%;
    }

    .tab {
        flex: 1;
        padding: 10px 12px;
        font-size: 12px;
        text-align: center;
    }

    /* Filters stack */
    .tab-filters {
        flex-direction: column;
        align-items: stretch;
    }

    .status-filter {
        margin-right: 0;
        flex-wrap: wrap;
    }

    .status-chip {
        flex: 1;
        text-align: center;
    }

    .filter-select {
        width: 100%;
    }

    .custom-date-range {
        flex-direction: column;
        align-items: stretch;
        gap: 6px;
    }

    .date-separator {
        text-align: center;
    }

    .btn-apply-date {
        width: 100%;
        padding: 10px;
    }

    /* ---- Card-based table layout ---- */
    .table-container {
        overflow-x: visible;
        border: none;
        border-radius: 0;
    }

    .data-table thead {
        display: none;
    }

    .data-table,
    .data-table tbody {
        display: block;
        width: 100%;
    }

    .data-table tbody tr {
        display: block;
        background: var(--bg-card);
        border: 1px solid var(--border);
        border-radius: 8px;
        margin-bottom: 12px;
        padding: 12px 16px;
    }

    .data-table tbody tr:nth-child(even) {
        background: var(--bg-card);
    }

    .data-table tbody tr:hover {
        background: var(--bg-secondary);
    }

    .data-table td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 6px 0;
        border-bottom: 1px solid var(--border-light);
        font-size: 13px;
    }

    .data-table td:last-child {
        border-bottom: none;
    }

    .data-table td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--text-secondary);
        font-size: 12px;
        margin-right: 12px;
        flex-shrink: 0;
    }

    /* Show all columns again in card view */
    .col-t2,
    .col-trend,
    .col-mom,
    .col-type,
    .col-checkbox,
    .col-email {
        display: flex;
        max-width: none;
    }

    /* Empty-state row stays full-width */
    .data-table td.table-empty {
        display: block;
        text-align: center;
        border: 1px solid var(--border);
        border-radius: 8px;
        padding: 40px 16px;
    }

    .data-table td.table-empty::before {
        content: none;
    }

    /* Modal */
    .modal {
        max-width: 100vw;
        max-height: 90vh;
        border-radius: 8px;
    }

    .modal-header {
        padding: 16px;
    }

    .modal-body {
        padding: 16px;
    }

    .modal-footer {
        padding: 12px 16px;
        flex-direction: column;
    }

    .modal-footer .btn-send,
    .modal-footer .btn-secondary {
        width: 100%;
        text-align: center;
    }

    /* Invoice detail modal mobile */
    .modal-wide {
        max-width: 100vw;
        max-height: 95vh;
    }

    .ar-overdue-filter {
        justify-content: center;
    }

    .invoice-list-panel {
        max-height: 180px;
    }

    .invoice-preview {
        padding: 16px;
    }

    .invoice-preview-brand {
        font-size: 20px;
    }

    .invoice-preview-title h3 {
        font-size: 22px;
    }

    .invoice-preview-lines th,
    .invoice-preview-lines td {
        padding: 8px 6px;
        font-size: 11px;
    }

    .total-line {
        min-width: 200px;
    }

    /* Login card */
    .login-card {
        padding: 28px 20px;
    }

    .mrr-charts,
    .mrr-tables {
        grid-template-columns: 1fr;
    }
}

/* Icon Rail Navigation */
.icon-rail {
    position: fixed;
    left: 0;
    top: 56px;
    bottom: 0;
    width: 48px;
    background: var(--rail-bg);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-top: 8px;
    z-index: 90;
    border-right: 1px solid var(--border);
}

.rail-btn {
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: var(--rail-icon-color);
    cursor: pointer;
    position: relative;
    border-left: 3px solid transparent;
    transition: background 0.15s, color 0.15s;
}

.rail-btn:hover {
    background: var(--rail-hover-bg);
}

.rail-btn.active {
    border-left-color: var(--accent);
    background: var(--rail-active-bg);
    color: var(--accent);
}

.rail-btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

.rail-btn svg {
    pointer-events: none;
}

.rail-drawer {
    position: fixed;
    left: 48px;
    top: 56px;
    bottom: 0;
    width: 220px;
    background: var(--rail-bg);
    box-shadow: 4px 0 12px rgba(0,0,0,0.15);
    z-index: 89;
    transform: translateX(-220px);
    transition: transform 200ms ease;
    visibility: hidden;
    pointer-events: none;
    padding: 16px;
}

.rail-drawer.open {
    transform: translateX(0);
    visibility: visible;
    pointer-events: auto;
}

.drawer-group-label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--rail-icon-color);
    margin-bottom: 12px;
}

.drawer-links {
    list-style: none;
    padding: 0;
    margin: 0;
}

.drawer-links li {
    margin-bottom: 2px;
}

.drawer-links a {
    display: block;
    padding: 8px 12px;
    color: var(--rail-icon-color);
    text-decoration: none;
    border-radius: 4px;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.drawer-links a:hover,
.drawer-links a.active {
    background: var(--rail-active-bg);
    color: #fff;
}

/* MRR Snapshot view */
.mrr-loading,
.mrr-error {
    text-align: center;
    padding: 24px;
    color: var(--text-secondary);
}
.mrr-error {
    color: var(--danger);
}
.mrr-filters {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    margin-bottom: 16px;
    overflow: visible;
}
.mrr-filters .status-chip {
    padding: 3px 10px;
    font-size: 11px;
    border-radius: 12px;
}
.mrr-filters .status-filter {
    gap: 3px;
    margin-right: 4px;
}
.mrr-filters-right {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 8px;
    margin-left: auto;
    flex-shrink: 0;
}
.mrr-product-labels {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    white-space: nowrap;
}
.mrr-customer-search {
    position: relative;
    display: flex;
    align-items: center;
}
.mrr-customer-input {
    width: 160px;
    padding: 6px 28px 6px 12px;
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 13px;
    outline: none;
}
.mrr-customer-input:focus {
    border-color: var(--accent);
}
.mrr-customer-input.mrr-customer-active {
    border-color: var(--accent);
    background: rgba(46, 167, 167, 0.08);
}
.mrr-customer-clear {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 16px;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}
.mrr-customer-clear:hover {
    color: var(--text-primary);
}
.mrr-customer-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    margin-top: 4px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 6px;
    max-height: 240px;
    overflow-y: auto;
    z-index: 100;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}
.mrr-customer-dropdown-item {
    padding: 8px 12px;
    font-size: 13px;
    cursor: pointer;
    color: var(--text-primary);
}
.mrr-customer-dropdown-item:hover {
    background: var(--bg-secondary);
}
.mrr-customer-dropdown-empty {
    padding: 8px 12px;
    font-size: 13px;
    color: var(--text-muted);
    font-style: italic;
}
.mrr-date-mode {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    color: var(--text-secondary);
}
.mrr-date-mode-label {
    font-weight: 600;
}
.mrr-date-mode-segmented {
    display: inline-flex;
    border-radius: 8px;
    padding: 2px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
}
.mrr-date-mode-segment {
    padding: 4px 10px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    background: transparent;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: color 0.2s, background 0.2s;
}
.mrr-date-mode-segment:hover {
    color: var(--text-primary);
    background: var(--bg-card);
}
.mrr-date-mode-segment.active {
    color: var(--accent);
    background: var(--bg-card);
    box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}
.mrr-product-line-notice {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 12px;
    padding: 8px 12px;
    background: var(--bg-secondary);
    border-radius: 6px;
    border-left: 3px solid var(--accent);
}
.mrr-kpi-row {
    margin-bottom: 20px;
}
.mrr-kpi-row .stat-value {
    margin-bottom: 4px;
}
.mrr-kpi-row .stat-trend {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 12px;
    margin-top: 12px;
    min-height: 1.2em;
}
.mrr-kpi-row .stat-trend .mrr-trend-mom {
    flex: 0 0 auto;
}
.mrr-kpi-row .stat-trend .mrr-trend-yoy {
    flex: 0 0 auto;
    text-align: right;
}
.stat-card.clickable {
    cursor: pointer;
    transition: border-color 0.15s;
}
.stat-card.clickable:hover {
    border-color: var(--accent);
}
.mrr-charts {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 24px;
}
.mrr-chart-container {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px;
    min-height: 240px;
    height: 280px;
    position: relative;
    width: 100%;
    box-sizing: border-box;
}
.mrr-chart-container canvas {
    max-width: 100%;
    width: 100% !important;
    height: 100% !important;
}
.mrr-chart-bridge {
    grid-column: 1 / -1;
    height: 260px;
    min-height: 220px;
    display: flex;
    flex-direction: column;
}
.mrr-chart-bridge .mrr-chart-bridge-header {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex: 0 0 auto;
    margin-bottom: 8px;
    min-height: 24px;
}
.mrr-chart-bridge-header > div:first-child {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}
.mrr-chart-bridge-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
}
.mrr-chart-bridge-subtitle {
    font-size: 10px;
    font-weight: 400;
    color: var(--text-muted, var(--text-secondary));
    opacity: 0.85;
}
.mrr-chart-bridge-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: flex-end;
    align-items: center;
    font-size: 12px;
    color: var(--text-secondary);
}
.mrr-chart-bridge-legend span {
    display: inline-flex;
    align-items: center;
    gap: 5px;
}
.mrr-chart-bridge-legend .legend-swatch {
    width: 12px;
    height: 12px;
    border-radius: 2px;
    flex-shrink: 0;
}
.mrr-chart-bridge canvas {
    flex: 1;
    min-height: 0;
    padding-top: 16px;
}
.mrr-chart-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 180px;
    color: var(--text-muted);
    font-size: 13px;
}
.mrr-tables-wrap {
    margin-bottom: 0;
}
.mrr-table-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 16px;
    flex-wrap: wrap;
    border-bottom: 1px solid var(--border);
}
.mrr-table-header-row .mrr-table-title {
    margin: 0;
    padding: 0;
}
.mrr-top-n-inline {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-left: auto;
}
.mrr-top-n-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
}
.mrr-top-n-select {
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border);
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 13px;
    cursor: pointer;
    outline: none;
}
.mrr-top-n-select:focus {
    border-color: var(--accent);
}
.mrr-top-n-suffix {
    font-size: 13px;
    color: var(--text-muted);
}
.mrr-tables {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}
.mrr-table-block {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}
.mrr-table-title {
    margin: 0;
    padding: 12px 16px;
    font-size: 15px;
    font-weight: 600;
    border-bottom: 1px solid var(--border);
}
.mrr-table-block .table-container {
    border: none;
    border-radius: 0;
}

/* MRR Sub-Tab Navigation */
.mrr-sub-tab-bar {
    display: flex;
    gap: 2px;
    padding: 0 0 12px 0;
    border-bottom: 1px solid var(--border);
    margin-bottom: 12px;
    overflow-x: auto;
}

.mrr-sub-tab {
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    white-space: nowrap;
    transition: color 0.2s, border-color 0.2s;
}

.mrr-sub-tab:hover {
    color: var(--text-primary);
}

.mrr-sub-tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

.mrr-view-panel {
    min-height: 200px;
}

/* Chart cards for Charts & Trends tab */
.mrr-charts-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 16px;
    margin-bottom: 16px;
}

.mrr-charts-row2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.mrr-chart-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 18px;
}

.mrr-chart-card-title {
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 2px;
}

.mrr-chart-card-sub {
    font-size: 11px;
    color: var(--text-secondary);
    margin-bottom: 14px;
}

/* Insight cards */
.mrr-insight-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 13px;
    margin-bottom: 20px;
}

.mrr-insight-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 16px 18px;
    border-left: 4px solid var(--border);
}

.mrr-insight-card.sev-green { border-left-color: var(--success); }
.mrr-insight-card.sev-red { border-left-color: var(--danger); }
.mrr-insight-card.sev-amber { border-left-color: var(--warning); }

.mrr-insight-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.mrr-insight-value {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.5px;
    margin-bottom: 4px;
}

.mrr-insight-sub {
    font-size: 11px;
    color: var(--text-secondary);
}

/* Recommendation cards */
.mrr-rec-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 13px;
    margin-bottom: 20px;
}

.mrr-rec-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 16px 18px;
}

.mrr-rec-priority {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    padding: 2px 8px;
    border-radius: 10px;
    display: inline-block;
    margin-bottom: 8px;
}

.mrr-rec-priority.p1 { background: rgba(248,81,73,0.15); color: var(--danger); }
.mrr-rec-priority.p2 { background: rgba(210,153,34,0.15); color: var(--warning); }
.mrr-rec-priority.p3 { background: rgba(46,167,167,0.15); color: var(--accent); }

.mrr-rec-title {
    font-size: 13px;
    font-weight: 700;
    margin-bottom: 6px;
}

.mrr-rec-body {
    font-size: 12px;
    color: var(--text-secondary);
    line-height: 1.55;
}

.mrr-rec-metric {
    display: inline-block;
    margin-top: 10px;
    padding: 5px 10px;
    background: var(--bg-secondary);
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-primary);
}

/* Two-column layout for insight tables */
.mrr-two-col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 16px;
}

.mrr-section-title {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 4px;
}

.mrr-section-sub {
    font-size: 11px;
    color: var(--text-secondary);
    margin-bottom: 10px;
}

/* ── MRR Pivot Table Styles ── */
.mrr-pivot-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
}

.mrr-pivot-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}

.mrr-pivot-header .mrr-section-title {
    margin-bottom: 0;
}

.mrr-pivot-controls {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-left: auto;
    flex-wrap: wrap;
}

.mrr-pivot-scroll {
    overflow-x: auto;
    overflow-y: auto;
}

.mrr-pivot-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
    font-variant-numeric: tabular-nums;
}

.mrr-pivot-table thead th {
    padding: 10px 14px;
    text-align: right;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    background: var(--bg-table-header);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    position: sticky;
    top: 0;
    z-index: 2;
}

.mrr-pivot-table thead th:first-child {
    text-align: left;
    position: sticky;
    left: 0;
    z-index: 4;
    background: var(--bg-table-header);
    min-width: 140px;
}

.mrr-pivot-table thead th.mrr-col-type {
    text-align: left;
    min-width: 70px;
}

.mrr-pivot-table tbody td {
    padding: 8px 14px;
    text-align: right;
    border-bottom: 1px solid var(--border-light);
    white-space: nowrap;
}

.mrr-pivot-table tbody td:first-child {
    text-align: left;
    position: sticky;
    left: 0;
    z-index: 1;
    background: var(--bg-table-row);
    font-weight: 500;
    max-width: 240px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mrr-pivot-table tbody tr {
    background: var(--bg-table-row);
    transition: background 0.12s;
}

.mrr-pivot-table tbody tr:nth-child(even) {
    background: var(--bg-table-row-alt);
}

.mrr-pivot-table tbody tr:nth-child(even) td:first-child {
    background: var(--bg-table-row-alt);
}

.mrr-pivot-table tbody tr:hover {
    background: rgba(46, 167, 167, 0.06);
}

.mrr-pivot-table tbody tr:hover td:first-child {
    background: rgba(46, 167, 167, 0.06);
}

.mrr-pivot-table .mrr-grand-row td {
    background: var(--bg-secondary) !important;
    font-weight: 700;
    font-size: 13px;
    border-top: 2px solid var(--accent);
    border-bottom: none;
}

.mrr-pivot-table .mrr-grand-row td:first-child {
    background: var(--bg-secondary) !important;
}

/* Heatmap cell */
.mrr-heat-cell {
    font-variant-numeric: tabular-nums;
    transition: background 0.15s;
}

/* Type badge in customer table */
.mrr-type-badge {
    display: inline-block;
    font-size: 10px;
    font-weight: 600;
    padding: 1px 6px;
    border-radius: 3px;
    background: var(--bg-secondary);
    color: var(--text-secondary);
    letter-spacing: 0.3px;
}

/* Truncation indicator */
.mrr-truncation-notice {
    font-size: 11px;
    color: var(--text-muted);
    padding: 10px 18px;
    border-bottom: 1px solid var(--border-light);
    background: var(--bg-table-header);
}

/* Empty state */
.mrr-empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--text-muted);
    font-size: 13px;
}

/* Toggle button group */
.mrr-toggle-group {
    display: flex;
    gap: 1px;
    background: var(--border);
    border-radius: 6px;
    padding: 1px;
    overflow: hidden;
}

.mrr-toggle-btn {
    padding: 5px 14px;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    background: var(--bg-card);
    color: var(--text-secondary);
    transition: background 0.15s, color 0.15s;
    white-space: nowrap;
}

.mrr-toggle-btn:first-child { border-radius: 5px 0 0 5px; }
.mrr-toggle-btn:last-child { border-radius: 0 5px 5px 0; }

.mrr-toggle-btn.active {
    background: var(--accent);
    color: #fff;
}

.mrr-toggle-btn:hover:not(.active) {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

/* Filter controls */
.mrr-filter-input {
    padding: 6px 12px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 12px;
    outline: none;
    transition: border-color 0.15s;
}

.mrr-filter-input:focus {
    border-color: var(--accent);
}

.mrr-filter-select {
    padding: 6px 10px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 12px;
    outline: none;
    cursor: pointer;
}

/* Color helper classes */
.c-pos { color: var(--success); font-weight: 600; }
.c-neg { color: var(--danger); font-weight: 600; }
.c-dim { color: var(--text-muted); }

@media (max-width: 900px) {
    .mrr-charts-grid,
    .mrr-charts-row2,
    .mrr-two-col {
        grid-template-columns: 1fr;
    }
}

/* ============================================================
   Configuration Options Modal - Tab Header
   ============================================================ */
.cfg-modal-header {
    flex-wrap: wrap;
    align-items: flex-start;
    padding-bottom: 0;
}
.cfg-header-left {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
}
.cfg-header-left h2 {
    margin-bottom: 8px;
}
.cfg-tabs {
    display: flex;
    gap: 0;
}
.cfg-tab {
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    cursor: pointer;
    transition: color 0.2s, border-color 0.2s;
}
.cfg-tab:hover {
    color: var(--text-primary);
}
.cfg-tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}
.cfg-panel {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
}

/* ============================================================
   Product Lines Configuration Modal
   ============================================================ */
.product-lines-modal {
    width: 900px;
    max-width: 95vw;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
}
.pl-body {
    display: flex;
    flex: 1;
    overflow: hidden;
    padding: 0 !important;
}
.pl-left-panel {
    width: 200px;
    min-width: 200px;
    display: flex;
    flex-direction: column;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
}
.pl-left-panel .pl-label {
    padding: 12px 12px 8px;
}
.pl-line-list {
    flex: 1;
    overflow-y: auto;
}
.pl-line-item {
    padding: 6px 10px;
    cursor: pointer;
    border-left: 3px solid transparent;
    font-size: 14px;
    color: var(--text-primary);
    transition: background 0.15s;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 4px;
}
.pl-line-item:hover {
    background: var(--bg-primary);
}
.pl-line-item.active {
    border-left-color: var(--accent);
    background: var(--accent-light);
    font-weight: 600;
}
.pl-line-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.pl-line-arrows {
    display: flex;
    flex-direction: column;
    gap: 1px;
    flex-shrink: 0;
}
.pl-arrow-btn {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    font-size: 10px;
    line-height: 1;
    padding: 1px 4px;
    border-radius: 3px;
    cursor: pointer;
}
.pl-arrow-btn:hover:not(:disabled) {
    border-color: var(--accent);
    color: var(--accent);
}
.pl-arrow-btn:disabled {
    opacity: 0.25;
    cursor: default;
}
.pl-left-actions {
    padding: 8px;
    display: flex;
    gap: 6px;
    border-top: 1px solid var(--border);
}
.pl-left-actions .btn-sm {
    flex: 1;
}
.pl-right-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    padding: 16px 20px;
}
.pl-empty-state {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    color: var(--text-muted);
    font-size: 14px;
}
.pl-detail {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
}
.pl-section {
    margin-bottom: 16px;
}
.pl-section-grow {
    margin-bottom: 16px;
    flex: 1;
    display: flex;
    flex-direction: column;
}
.pl-label {
    display: block;
    font-size: 12px;
    text-transform: uppercase;
    color: var(--text-secondary);
    font-weight: 600;
    margin-bottom: 6px;
    letter-spacing: 0.5px;
}
.pl-input {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-primary);
    font-size: 14px;
    padding: 6px 10px;
    border-radius: 6px;
    outline: none;
    box-sizing: border-box;
}
.pl-input:focus {
    border-color: var(--accent);
}
.pl-pattern-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 8px;
    min-height: 28px;
}
.pl-pattern-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: var(--accent-light);
    border: 1px solid var(--accent);
    color: var(--text-primary);
    font-size: 13px;
    padding: 3px 8px;
    border-radius: 12px;
}
.pl-pattern-chip .pl-chip-remove {
    cursor: pointer;
    font-size: 15px;
    line-height: 1;
    color: var(--text-secondary);
    margin-left: 2px;
}
.pl-pattern-chip .pl-chip-remove:hover {
    color: var(--danger);
}
.pl-pattern-add {
    display: flex;
    gap: 6px;
    margin-bottom: 8px;
}
.pl-pattern-add .pl-input {
    flex: 1;
}
.pl-resolve-btn {
    width: 100%;
}
.pl-customer-list {
    max-height: 200px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: 6px;
    flex: 1;
}
.pl-customer-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 10px;
    font-size: 13px;
    border-bottom: 1px solid var(--border-light);
    color: var(--text-primary);
}
.pl-customer-item:last-child {
    border-bottom: none;
}
.pl-customer-item .pl-cust-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.pl-customer-item .pl-cust-id {
    color: var(--text-muted);
    font-size: 12px;
    margin: 0 8px;
    flex-shrink: 0;
}
.pl-customer-item .pl-cust-remove {
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 15px;
    flex-shrink: 0;
}
.pl-customer-item .pl-cust-remove:hover {
    color: var(--danger);
}
.pl-search-row {
    display: flex;
    gap: 6px;
    margin-bottom: 8px;
}
.pl-search-row .pl-input {
    flex: 1;
}
.pl-search-results {
    max-height: 160px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: 6px;
}
.pl-search-results:empty {
    display: none;
}
.pl-search-item {
    display: flex;
    align-items: center;
    padding: 5px 10px;
    font-size: 13px;
    cursor: pointer;
    border-bottom: 1px solid var(--border-light);
    color: var(--text-primary);
}
.pl-search-item:last-child {
    border-bottom: none;
}
.pl-search-item:hover {
    background: var(--accent-light);
}
.pl-search-item .pl-cust-name {
    flex: 1;
}
.pl-search-item .pl-cust-id {
    color: var(--text-muted);
    font-size: 12px;
    margin-left: 8px;
}
.pl-line-item-results {
    max-height: 200px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: 6px;
}
.pl-line-item-results:empty {
    display: none;
}
.pl-line-item-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    font-size: 13px;
    border-bottom: 1px solid var(--border-light);
    color: var(--text-primary);
}
.pl-line-item-row:last-child {
    border-bottom: none;
}
.pl-line-item-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.pl-line-item-count {
    font-size: 11px;
    color: var(--text-muted);
    background: var(--bg-secondary);
    border-radius: 10px;
    padding: 2px 8px;
    white-space: nowrap;
}
.pl-line-item-row .pl-assign-select {
    flex-shrink: 0;
}
.btn-danger-sm {
    background: none;
    border: 1px solid var(--danger);
    color: var(--danger);
    font-size: 13px;
    padding: 4px 10px;
    border-radius: 6px;
    cursor: pointer;
}
.btn-danger-sm:hover {
    background: var(--danger);
    color: #fff;
}
.btn-danger-sm:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}
.btn-danger-sm:disabled:hover {
    background: none;
    color: var(--danger);
}
.btn-sm {
    font-size: 13px;
    padding: 4px 10px;
}
.pl-save-status {
    font-size: 13px;
    color: var(--success);
    margin-right: auto;
}
/* Unmatched nav item */
.pl-left-separator {
    border-top: 1px solid var(--border);
    margin: 4px 0;
}
.pl-unmatched-item-nav {
    cursor: pointer;
    font-size: 13px;
    color: var(--text-secondary);
}
.pl-unmatched-item-nav.active {
    border-left-color: var(--warning);
    background: rgba(210, 153, 34, 0.12);
    color: var(--text-primary);
    font-weight: 600;
}
.pl-unmatched-badge {
    font-size: 11px;
    background: var(--warning);
    color: #000;
    padding: 1px 6px;
    border-radius: 10px;
    font-weight: 700;
    margin-left: 4px;
}
.pl-unmatched-badge:empty {
    display: none;
}

/* Unmatched right panel view */
.pl-unmatched-view {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
}
.pl-unmatched-subtitle {
    display: block;
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 2px;
}
.pl-unmatched-row {
    display: flex;
    align-items: center;
    padding: 5px 10px;
    font-size: 13px;
    border-bottom: 1px solid var(--border-light);
    color: var(--text-primary);
}
.pl-unmatched-row:last-child {
    border-bottom: none;
}
.pl-unmatched-row .pl-cust-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.pl-unmatched-row .pl-cust-id {
    color: var(--text-muted);
    font-size: 12px;
    margin: 0 8px;
    flex-shrink: 0;
}
.pl-assign-select {
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-primary);
    font-size: 12px;
    padding: 2px 6px;
    border-radius: 4px;
    cursor: pointer;
    flex-shrink: 0;
}
.pl-assign-select:focus {
    border-color: var(--accent);
    outline: none;
}

/* Application confirm/alert modal */
.app-confirm-modal {
    width: 420px;
    max-width: 90vw;
}
.app-confirm-modal .modal-body p {
    margin: 0;
    font-size: 14px;
    line-height: 1.6;
    color: var(--text-primary);
}

/* Conflict banner */
.pl-conflicts {
    background: rgba(248, 81, 73, 0.12);
    border: 1px solid var(--danger);
    border-radius: 6px;
    padding: 8px 14px;
    margin: 0 16px;
    font-size: 13px;
    color: var(--danger);
    line-height: 1.5;
}
.pl-conflicts-title {
    font-weight: 700;
    margin-right: 6px;
}

@media (max-width: 700px) {
    .pl-body {
        flex-direction: column;
    }
    .pl-left-panel {
        width: 100%;
        min-width: 100%;
        max-height: 150px;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }
    .product-lines-modal {
        width: 98vw;
    }
    .cfg-tabs {
        flex-wrap: wrap;
    }
    .cfg-tab {
        font-size: 12px;
        padding: 6px 12px;
    }
}

/* ---- Customer List Modal Table ---- */
.customer-list-container {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.modal-split.customer-mode {
    position: relative;
    min-height: 60vh;
}
.modal-wide.customer-mode-parent {
    width: 95vw;
    max-width: 1500px;
    max-height: 92vh;
}
.customer-list-search-row { display: flex; align-items: center; gap: 12px; padding: 8px 16px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.customer-list-search { flex: 1; padding: 6px 10px; border: 1px solid var(--border); border-radius: 4px; background: var(--bg-secondary); color: var(--text-primary); font-size: 13px; }
.customer-list-search::placeholder { color: var(--text-muted); }
.customer-list-count { font-size: 12px; color: var(--text-secondary); white-space: nowrap; }
.customer-list-table-wrap { flex: 1 1 0; min-height: 0; overflow-y: auto; }
.customer-list-table { table-layout: fixed; width: 100%; }
.customer-list-table th, .customer-list-table td { padding: 4px 6px; font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.customer-list-table th:nth-child(1), .customer-list-table td:nth-child(1) { width: 14%; }
.customer-list-table th:nth-child(2), .customer-list-table td:nth-child(2) { width: 8%; font-size: 10px; }
.customer-list-table th:nth-child(3), .customer-list-table td:nth-child(3) { width: 5%; }
.customer-list-table th:nth-child(4), .customer-list-table td:nth-child(4),
.customer-list-table th:nth-child(5), .customer-list-table td:nth-child(5),
.customer-list-table th:nth-child(6), .customer-list-table td:nth-child(6) { width: 8%; text-align: right; }
.customer-list-table th:nth-child(7), .customer-list-table td:nth-child(7),
.customer-list-table th:nth-child(8), .customer-list-table td:nth-child(8),
.customer-list-table th:nth-child(9), .customer-list-table td:nth-child(9) { width: 7%; text-align: right; }
.customer-list-table th:nth-child(10), .customer-list-table td:nth-child(10) { width: 5%; text-align: center; }
.customer-list-table th:nth-child(11), .customer-list-table td:nth-child(11) { width: 6%; text-align: right; }
.customer-list-table th.sortable { cursor: pointer; user-select: none; }
.customer-list-table th.sortable:hover { color: var(--accent); }
.customer-list-table th .sort-icon { font-size: 9px; margin-left: 1px; }
.customer-list-table tbody tr { cursor: pointer; }
.customer-list-table tbody tr:hover { background: var(--accent-light); }

/* Section-level loading indicator (progressive rendering) */
.section-loading {
    opacity: 0.4;
    pointer-events: none;
    position: relative;
    min-height: 60px;
}
.section-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 24px;
    height: 24px;
    margin: -12px 0 0 -12px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: section-spin 0.6s linear infinite;
    z-index: 10;
}
@keyframes section-spin {
    to { transform: rotate(360deg); }
}

/* Adjustments tab */
.adj-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.adj-dot-on { background: var(--accent); box-shadow: 0 0 4px var(--accent); }
.adj-config-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.adj-stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 16px; padding: 10px 12px; background: var(--bg-secondary); border-radius: 6px; }
.adj-stat { display: flex; flex-direction: column; gap: 1px; }
.adj-stat-label { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); }
.adj-stat-value { font-size: 13px; color: var(--text-primary); }
