/* ============================================================
   PostAdmin theme overrides
   Default is dark (set by an inline script in base.html); light
   remains selectable and is persisted in localStorage.theme_v2.
   Client share pages set data-theme="light" data-theme-locked="1"
   and always stay light.
   ============================================================ */

html[data-theme="dark"] {
    color-scheme: dark;
    --bg: #070d18;
    --card-bg: #0f1a2b;
    --surface-2: #142238;
    --surface-3: #1a2c45;
    --text: #e7eef9;
    --text-secondary: #93a5bc;
    --border: #24364e;
    --primary: #ff6b3d;
    --primary-solid: #c2410c;
    --primary-light: #2a1a17;
    --success: #3ddc97;
    --danger: #ff6b6b;
    --danger-solid: #b91c1c;
    --warning: #f5c451;
    --info: #5aa9ff;
    --dash-border: #24364e;
    --dash-muted: #93a5bc;

    --bs-body-bg: #070d18;
    --bs-body-color: #e7eef9;
    --bs-border-color: #24364e;
    --bs-secondary-bg: #142238;
    --bs-tertiary-bg: #1a2c45;
    --bs-modal-bg: #0f1a2b;
    --bs-card-bg: #0f1a2b;
    --bs-table-bg: #0f1a2b;
    --bs-table-striped-bg: #142238;
    --bs-table-hover-bg: #1a2c45;
}

html[data-theme="light"],
html[data-theme-locked="1"] { color-scheme: light; }

html[data-theme="dark"] body {
    background: var(--bg);
    color: var(--text);
}

html[data-theme="dark"] a { color: #71b7ff; }
html[data-theme="dark"] a:hover { color: #a4d1ff; }

/* ---------- shell ---------- */
html[data-theme="dark"] .top-nav {
    background: rgba(7, 13, 24, .94);
    border-bottom-color: var(--border);
}
html[data-theme="dark"] .top-nav .brand { color: var(--primary); }
html[data-theme="dark"] .top-nav .nav-links a { color: var(--text-secondary); }
html[data-theme="dark"] .top-nav .nav-links a:hover,
html[data-theme="dark"] .top-nav .nav-links a.active {
    background: var(--primary-light);
    color: var(--primary);
}
html[data-theme="dark"] .top-nav .nav-right a { color: var(--text-secondary); }
html[data-theme="dark"] .top-nav.mobile-open .nav-links a:hover,
html[data-theme="dark"] .top-nav.mobile-open .nav-links a.active {
    background: var(--primary-light);
    color: var(--primary);
}
html[data-theme="dark"] .nav-toggle { color: var(--text); }
html[data-theme="dark"] .user-badge {
    background: var(--primary-light);
    color: var(--primary);
}
html[data-theme="dark"] .lang-switch {
    background: var(--surface-2);
    border-color: var(--border);
}
html[data-theme="dark"] .lang-switch a { color: var(--text-secondary); }
html[data-theme="dark"] .lang-switch a.active {
    background: var(--primary-solid);
    color: #fff;
}
html[data-theme="dark"] .theme-toggle {
    background: var(--surface-2);
    color: var(--text-secondary);
    border-color: var(--border);
}
html[data-theme="dark"] .theme-toggle:hover {
    background: var(--primary-light);
    color: var(--primary);
}

/* ---------- cards / surfaces ---------- */
html[data-theme="dark"] .flat-card,
html[data-theme="dark"] .card,
html[data-theme="dark"] .modal-content,
html[data-theme="dark"] .dropdown-menu,
html[data-theme="dark"] .offcanvas,
html[data-theme="dark"] .accordion-item,
html[data-theme="dark"] .list-group-item {
    background: var(--card-bg);
    border-color: var(--border);
    color: var(--text);
}
html[data-theme="dark"] .flat-card .card-header,
html[data-theme="dark"] .card-header,
html[data-theme="dark"] .modal-header,
html[data-theme="dark"] .modal-footer,
html[data-theme="dark"] .accordion-button {
    background: var(--card-bg);
    border-color: var(--border);
    color: var(--text);
}
html[data-theme="dark"] .card-body,
html[data-theme="dark"] .modal-body { color: var(--text); }
html[data-theme="dark"] .modal-backdrop.show { opacity: .7; }
html[data-theme="dark"] .modal-header .btn-close { filter: invert(1) grayscale(1); }
html[data-theme="dark"] .dropdown-item { color: var(--text); }
html[data-theme="dark"] .dropdown-item:hover,
html[data-theme="dark"] .dropdown-item:focus {
    background: var(--surface-2);
    color: var(--text);
}
html[data-theme="dark"] .dropdown-divider { border-color: var(--border); }

html[data-theme="dark"] .page-header h4,
html[data-theme="dark"] h1,
html[data-theme="dark"] h2,
html[data-theme="dark"] h3,
html[data-theme="dark"] h4,
html[data-theme="dark"] h5,
html[data-theme="dark"] h6 { color: var(--text); }
html[data-theme="dark"] .text-muted { color: var(--text-secondary) !important; }

/* ---------- shared content rows / read boxes ---------- */
.result-row-ok td { background: #f0fdf4; }
.result-row-fail td { background: #fef2f2; }
.result-row-info td { background: #eff6ff; }
.text-box-note { background: #fffbeb; }
.pj-readbox {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px;
    background: #fafbfc;
    font-size: 13px;
    white-space: pre-wrap;
    line-height: 1.7;
}
.pj-readbox-scroll { max-height: 200px; overflow-y: auto; }
.flat-input[readonly] { background: #f8f9fc; }
.vendor-state-invalid {
    border-color: #d1d5db;
    background: linear-gradient(135deg, #f3f4f6 0%, #f9fafb 100%);
}
.vendor-state-success {
    border-color: #86efac;
    background: linear-gradient(135deg, #ecfdf5 0%, #f0fdf4 100%);
}
.vendor-announcement {
    background: #fefce8;
    border: 1px solid #fde68a;
    border-radius: 10px;
    padding: 12px 18px;
    margin-bottom: 16px;
    font-size: 13px;
    line-height: 1.7;
    color: #78350f;
    white-space: pre-line;
}
.preview-dist-head {
    padding: 12px 14px;
    background: #f8fafc;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}
.preview-result { padding: 12px; border-radius: 8px; border: 1px solid transparent; }
.preview-result.ok { background: #f0fdf4; border-color: #bbf7d0; }
.preview-result.fail { background: #fef2f2; border-color: #fecaca; }
.preview-result.info { background: #eff6ff; border-color: #bfdbfe; }
.preview-note {
    padding: 12px;
    border-radius: 8px;
    background: #fafbfc;
    border: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}
.vendor-preview-locked {
    padding: 24px;
    background: repeating-linear-gradient(135deg, #f8fafc 0, #f8fafc 14px, #eef2f7 14px, #eef2f7 28px);
    min-height: 220px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    color: var(--text-secondary);
    font-weight: 600;
}
.copy-history-head {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 14px;
    border: 1px solid var(--border);
    border-bottom: none;
    border-radius: 8px 8px 0 0;
    background: #f1f5f9;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
}

/* ---------- tables ---------- */
html[data-theme="dark"] .flat-table th,
html[data-theme="dark"] .table thead th {
    background: var(--surface-2);
    color: var(--text-secondary);
    border-bottom-color: var(--border);
}
html[data-theme="dark"] .flat-table td,
html[data-theme="dark"] .table td,
html[data-theme="dark"] .table th {
    border-color: var(--border);
    color: var(--text);
}
html[data-theme="dark"] .flat-table tbody tr:hover,
html[data-theme="dark"] .table tbody tr:hover {
    background: var(--surface-2);
}
html[data-theme="dark"] .flat-table tbody tr.task-row-selected,
html[data-theme="dark"] .flat-table tbody tr.task-row-selected:hover {
    background: var(--surface-3) !important;
}
html[data-theme="dark"] .table-striped > tbody > tr:nth-of-type(odd) > * {
    color: var(--text);
    background: var(--surface-2);
}
html[data-theme="dark"] .table > :not(caption) > * > * {
    background: transparent;
    color: var(--text);
}
html[data-theme="dark"] .flat-table-wrap { background: transparent; }

html[data-theme="dark"] .result-row-ok td { background: #0f2e24; }
html[data-theme="dark"] .result-row-fail td { background: #32181c; }
html[data-theme="dark"] .result-row-info td { background: #102a45; }
html[data-theme="dark"] .text-box {
    background: #0b1524;
    border-color: var(--border);
    color: var(--text);
}
html[data-theme="dark"] .text-box-note {
    background: #2b2414;
    border-color: #6b5522;
    color: #ffd77a;
}
html[data-theme="dark"] .pj-readbox {
    background: var(--surface-2);
    border-color: var(--border);
    color: var(--text);
}
html[data-theme="dark"] #taskDetailFrame { background: var(--card-bg) !important; }
html[data-theme="dark"] .task-scope-tab {
    background: var(--card-bg);
    border-color: var(--border);
    color: var(--text-secondary);
}
html[data-theme="dark"] .task-scope-tab:hover {
    background: var(--surface-2);
    color: var(--text);
}
html[data-theme="dark"] .task-scope-tab.active {
    background: var(--primary-light);
    border-color: #6b3b2f;
    color: var(--primary);
}
html[data-theme="dark"] .cust-row-risk { background: #2a161a; }
html[data-theme="dark"] .cust-row-risk:hover { background: #32181c; }
html[data-theme="dark"] .cust-risk-tip { color: #ffd77a; }
html[data-theme="dark"] .cust-risk-badge { background: #2b2414; color: #ffd77a; }

/* ---------- forms ---------- */
html[data-theme="dark"] .flat-input,
html[data-theme="dark"] .flat-select,
html[data-theme="dark"] input,
html[data-theme="dark"] select,
html[data-theme="dark"] textarea,
html[data-theme="dark"] .form-control,
html[data-theme="dark"] .form-select {
    background: #0b1524;
    border-color: var(--border);
    color: var(--text);
}
html[data-theme="dark"] input::placeholder,
html[data-theme="dark"] textarea::placeholder { color: #6f829b; }
html[data-theme="dark"] select option { background: #0b1524; color: var(--text); }
html[data-theme="dark"] input[type="file"]::file-selector-button {
    background: var(--surface-3);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    padding: 6px 10px;
    margin-right: 8px;
    cursor: pointer;
}
html[data-theme="dark"] .flat-input:focus,
html[data-theme="dark"] .flat-select:focus,
html[data-theme="dark"] .form-control:focus,
html[data-theme="dark"] .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(255, 107, 61, .16);
}
html[data-theme="dark"] .flat-label,
html[data-theme="dark"] .form-label { color: var(--text); }

/* ---------- buttons ---------- */
html[data-theme="dark"] .btn-flat-primary {
    background: var(--primary-solid);
    color: #fff;
}
html[data-theme="dark"] .btn-flat-primary:hover {
    background: #a8380a;
    color: #fff;
}
html[data-theme="dark"] .btn-flat-danger {
    background: var(--danger-solid);
    color: #fff;
}
html[data-theme="dark"] .btn-flat-danger:hover {
    background: #991b1b;
    color: #fff;
}
html[data-theme="dark"] .btn-flat-secondary {
    background: var(--surface-2);
    color: var(--text);
}
html[data-theme="dark"] .btn-flat-secondary:hover {
    background: var(--surface-3);
    color: var(--text);
}
html[data-theme="dark"] .btn-flat-outline {
    border-color: var(--border);
    color: var(--text-secondary);
}
html[data-theme="dark"] .btn-flat-outline:hover {
    background: var(--surface-2);
    border-color: #3b5575;
    color: var(--text);
}
html[data-theme="dark"] .btn-close { filter: invert(1) grayscale(1); }
html[data-theme="dark"] .period-tabs button.active {
    background: var(--primary-solid);
    border-color: var(--primary-solid);
    color: #fff;
}
html[data-theme="dark"] .filter-bar button {
    background: var(--primary-solid);
    color: #fff;
}

/* ---------- alerts ---------- */
html[data-theme="dark"] .flat-alert-success { background: #0f2e24; color: #7ff0bd; }
html[data-theme="dark"] .flat-alert-error { background: #32181c; color: #ff9b9b; }
html[data-theme="dark"] .flat-alert-warning { background: #322813; color: #ffd77a; }
html[data-theme="dark"] .flat-alert-info { background: #102a45; color: #9dccff; }

/* ---------- status / badges ---------- */
html[data-theme="dark"] .st,
html[data-theme="dark"] .tag,
html[data-theme="dark"] .badge {
    border: 1px solid transparent;
}
html[data-theme="dark"] .st-draft,
html[data-theme="dark"] .st-archived,
html[data-theme="dark"] .tag,
html[data-theme="dark"] .badge.bg-secondary {
    background: var(--surface-2);
    color: var(--text-secondary);
}
html[data-theme="dark"] .st-pending,
html[data-theme="dark"] .st-scheduled,
html[data-theme="dark"] .st-distributed {
    background: #2b2414;
    color: #ffd77a;
}
html[data-theme="dark"] .st-published,
html[data-theme="dark"] .st-v-completed {
    background: #0f2e24;
    color: #7ff0bd;
}
html[data-theme="dark"] .st-active { color: #7ff0bd; }
html[data-theme="dark"] .st-failed,
html[data-theme="dark"] .st-removed,
html[data-theme="dark"] .st-filtered {
    background: #32181c;
    color: #ff9b9b;
}
html[data-theme="dark"] .st-v-pending { background: #102a45; color: #9dccff; }
html[data-theme="dark"] .st-v-assigned { background: #2b2414; color: #ffd77a; }
html[data-theme="dark"] .st-v-paused { background: var(--surface-2); color: var(--text-secondary); }

/* ---------- vendor workspace ---------- */
html[data-theme="dark"] .flat-input[readonly] {
    background: var(--surface-2) !important;
    color: var(--text);
}
html[data-theme="dark"] .vendor-state-invalid {
    border-color: var(--border);
    background: linear-gradient(135deg, #142238 0%, #0f1a2b 100%);
}
html[data-theme="dark"] .vendor-state-invalid .card-body { color: var(--text-secondary) !important; }
html[data-theme="dark"] .vendor-state-success {
    border-color: #1c5b45;
    background: linear-gradient(135deg, #0f2e24 0%, #0b241c 100%);
}
html[data-theme="dark"] .vendor-announcement {
    background: #2b2414;
    border-color: #6b5522;
    color: #ffd77a;
}
html[data-theme="dark"] .preview-dist-head {
    background: var(--surface-2);
    border-bottom-color: var(--border);
}
html[data-theme="dark"] .preview-result.ok { background: #0f2e24; border-color: #1c5b45; }
html[data-theme="dark"] .preview-result.fail { background: #32181c; border-color: #6b2e35; }
html[data-theme="dark"] .preview-result.info { background: #102a45; border-color: #2e5f8a; }
html[data-theme="dark"] .preview-note { background: var(--surface-2); border-color: var(--border); }
html[data-theme="dark"] .vendor-preview-locked {
    background: repeating-linear-gradient(135deg, #142238 0, #142238 14px, #1a2c45 14px, #1a2c45 28px);
    color: var(--text-secondary);
}
html[data-theme="dark"] .copy-history-head {
    background: var(--surface-2);
    border-color: var(--border);
    color: var(--text-secondary);
}
html[data-theme="dark"] #copyHistoryDetail,
html[data-theme="dark"] #copyHistoryList { background: var(--surface-3) !important; }
html[data-theme="dark"] [style*="border-bottom:1px solid #f1f5f9"] {
    border-bottom-color: var(--border) !important;
}
html[data-theme="dark"] .vendor-status-pending {
    background: #102a45;
    color: #9dccff;
    border-color: #2e5f8a;
}
html[data-theme="dark"] .vendor-status-assigned {
    background: #2b2414;
    color: #ffd77a;
    border-color: #6b5522;
}
html[data-theme="dark"] .vendor-status-completed {
    background: #0f2e24;
    color: #7ff0bd;
    border-color: #1c5b45;
}
html[data-theme="dark"] .vendor-status-paused {
    background: #32181c;
    color: #ff9b9b;
    border-color: #6b2e35;
}

/* ---------- vendor admin ---------- */
html[data-theme="dark"] .vendor-table .col-distributed { background: #2b2414; color: #ffd77a; }
html[data-theme="dark"] .vendor-table .col-completed { background: #0f2e24; color: #7ff0bd; }
html[data-theme="dark"] .vendor-table .col-filtered { background: #241d3d; color: #c4b5fd; }
html[data-theme="dark"] .vendor-table .col-removed { background: #32181c; color: #ff9b9b; }
html[data-theme="dark"] .perf-fail { color: #ff9b9b; }
html[data-theme="dark"] .perf-ok { color: #7ff0bd; }
html[data-theme="dark"] .perf-risk { color: #ffd77a; }
html[data-theme="dark"] .perf-risk-hit { background: #32181c; }
html[data-theme="dark"] .summary-filter input[type="date"] {
    background: #0b1524;
    border-color: var(--border);
    color: var(--text);
    color-scheme: dark;
}
html[data-theme="dark"] .detail-table th.group-post { background: #102a45; color: #9dccff; }
html[data-theme="dark"] .detail-table th.group-comment { background: #2a1838; color: #d8b4fe; }
html[data-theme="dark"] .detail-table td.col-distributed { color: #ffd77a; }
html[data-theme="dark"] .detail-table td.col-completed { color: #7ff0bd; }
html[data-theme="dark"] .detail-table td.col-filtered { color: #c4b5fd; }
html[data-theme="dark"] .detail-table td.col-removed { color: #ff9b9b; }
html[data-theme="dark"] .detail-table tfoot td { background: var(--surface-2); }
html[data-theme="dark"] .region { border-color: var(--border); background: var(--card-bg); }
html[data-theme="dark"] .region-head {
    background: var(--surface-2);
    border-bottom-color: var(--border);
    color: var(--text);
}
html[data-theme="dark"] .region.r-pending .region-head { background: #102a45; }
html[data-theme="dark"] .region.r-filtered_removed .region-head { background: #241d3d; }
html[data-theme="dark"] .region.r-completed .region-head { background: #0f2e24; }
html[data-theme="dark"] .region-totals .tt { background: var(--surface-3); color: var(--text-secondary); }
html[data-theme="dark"] .region-totals .tt-total { background: var(--primary-solid); color: #fff; }
html[data-theme="dark"] .region-totals .tt-post { background: #102a45; color: #9dccff; }
html[data-theme="dark"] .region-totals .tt-comment { background: #2a1838; color: #d8b4fe; }
html[data-theme="dark"] .task-line { border-bottom-color: var(--border); }
html[data-theme="dark"] .task-line .type.t-post { background: #102a45; color: #9dccff; }
html[data-theme="dark"] .task-line .type.t-comment { background: #2a1838; color: #d8b4fe; }
html[data-theme="dark"] .q-pending { background: var(--surface-2); color: var(--text-secondary); }
html[data-theme="dark"] .q-qualified { background: #0f2e24; color: #7ff0bd; }
html[data-theme="dark"] .q-unqualified { background: #32181c; color: #ff9b9b; }

/* ---------- inline light-theme text colours ---------- */
/* Use a leading ; or start-of-style so border-color/background-color never match. */
html[data-theme="dark"] :is(
    [style^="color:#5a6880"], [style*=";color:#5a6880"], [style*=" color:#5a6880"],
    [style^="color: #5a6880"], [style*=";color: #5a6880"], [style*=" color: #5a6880"],
    [style^="color:#64748b"], [style*=";color:#64748b"], [style*=" color:#64748b"],
    [style^="color: #64748b"], [style*=";color: #64748b"], [style*=" color: #64748b"],
    [style^="color:#475569"], [style*=";color:#475569"], [style*=" color:#475569"],
    [style^="color: #475569"], [style*=";color: #475569"], [style*=" color: #475569"]
) {
    color: var(--text-secondary) !important;
}
html[data-theme="dark"] :is(
    [style^="color:#334155"], [style*=";color:#334155"], [style*=" color:#334155"],
    [style^="color: #334155"], [style*=";color: #334155"], [style*=" color: #334155"]
) {
    color: var(--text) !important;
}
html[data-theme="dark"] :is(
    [style^="color:#047857"], [style*=";color:#047857"], [style*=" color:#047857"],
    [style^="color: #047857"], [style*=";color: #047857"], [style*=" color: #047857"]
) {
    color: #7ff0bd !important;
}
html[data-theme="dark"] :is(
    [style^="color:#b91c1c"], [style*=";color:#b91c1c"], [style*=" color:#b91c1c"],
    [style^="color: #b91c1c"], [style*=";color: #b91c1c"], [style*=" color: #b91c1c"],
    [style^="color:#dc2626"], [style*=";color:#dc2626"], [style*=" color:#dc2626"],
    [style^="color: #dc2626"], [style*=";color: #dc2626"], [style*=" color: #dc2626"]
) {
    color: #ff9b9b !important;
}
html[data-theme="dark"] :is(
    [style^="color:#6d28d9"], [style*=";color:#6d28d9"], [style*=" color:#6d28d9"],
    [style^="color: #6d28d9"], [style*=";color: #6d28d9"], [style*=" color: #6d28d9"]
) {
    color: #c4b5fd !important;
}
html[data-theme="dark"] :is(
    [style^="color:#92400e"], [style*=";color:#92400e"], [style*=" color:#92400e"],
    [style^="color: #92400e"], [style*=";color: #92400e"], [style*=" color: #92400e"],
    [style^="color:#b45309"], [style*=";color:#b45309"], [style*=" color:#b45309"],
    [style^="color: #b45309"], [style*=";color: #b45309"], [style*=" color: #b45309"]
) {
    color: #ffd77a !important;
}

/* ---------- project module ---------- */
html[data-theme="dark"] .pj-subnav { border-bottom-color: var(--border); }
html[data-theme="dark"] .pj-subnav a { color: var(--text-secondary); }
html[data-theme="dark"] .pj-subnav a:hover { background: var(--surface-2); color: var(--text); }
html[data-theme="dark"] .pj-subnav a.on { color: var(--primary); border-bottom-color: var(--primary); }
html[data-theme="dark"] .pj-band,
html[data-theme="dark"] .pj-ctl,
html[data-theme="dark"] .pj-kbox,
html[data-theme="dark"] .pj-ptab,
html[data-theme="dark"] .pj-cal .mo,
html[data-theme="dark"] .pj-cal .mh,
html[data-theme="dark"] .pj-alert,
html[data-theme="dark"] .pj-chip {
    background: var(--card-bg);
    border-color: var(--border);
    color: var(--text);
}
html[data-theme="dark"] .pj-band > div,
html[data-theme="dark"] .pj-kvs > div,
html[data-theme="dark"] .pj-info > div { border-color: var(--border); }
html[data-theme="dark"] .pj-seg { border-color: var(--border); }
html[data-theme="dark"] .pj-seg a {
    background: var(--card-bg);
    color: var(--text-secondary);
    border-right-color: var(--border);
}
html[data-theme="dark"] .pj-seg a:hover { background: var(--surface-2); color: var(--text); }
html[data-theme="dark"] .pj-seg a.on { background: var(--primary-solid); color: #fff; }
html[data-theme="dark"] .pj-ctl input[type=text] {
    background: #0b1524;
    border-color: var(--border);
    color: var(--text);
}
html[data-theme="dark"] .pj-st-run { background: #102a45; color: #9dccff; }
html[data-theme="dark"] .pj-st-wait { background: var(--surface-2); color: var(--text-secondary); }
html[data-theme="dark"] .pj-st-pause { background: #2b2414; color: #ffd77a; }
html[data-theme="dark"] .pj-st-end { background: var(--surface-2); color: var(--text-secondary); }
html[data-theme="dark"] .pj-track,
html[data-theme="dark"] .pj-pbar,
html[data-theme="dark"] .pj-mini { background: #22344c; }
html[data-theme="dark"] .pj-ptab:hover { background: var(--surface-2); border-color: #3b5575; }
html[data-theme="dark"] .pj-ptab.on { background: var(--surface-3); border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }
html[data-theme="dark"] .pj-bars .bf { background: #2c4a78; }
html[data-theme="dark"] .pj-bars .bf.ok { background: var(--primary); }
html[data-theme="dark"] .pj-tl .it { border-left-color: var(--border); }
html[data-theme="dark"] .pj-tl .wk .risk { color: var(--text-secondary); }
html[data-theme="dark"] .pj-alert { background: #2a1c12; border-color: #724327; }
html[data-theme="dark"] .pj-alert .at { color: #ffb38c; }
html[data-theme="dark"] .pj-alert .why { color: #ffd77a; }
html[data-theme="dark"] .pj-alert a { background: var(--card-bg); border-color: #724327; color: #ffc7a8; }
html[data-theme="dark"] .pj-band .k,
html[data-theme="dark"] .pj-band .n,
html[data-theme="dark"] .pj-band .v .u,
html[data-theme="dark"] .pj-ctl .gl > span,
html[data-theme="dark"] .pj-tl .wk .risk,
html[data-theme="dark"] .pj-info .k,
html[data-theme="dark"] .pj-kvs .k,
html[data-theme="dark"] .pj-kvs .n,
html[data-theme="dark"] .pj-kvs .v .u,
html[data-theme="dark"] .pj-ptab .pr,
html[data-theme="dark"] .pj-ptab .ps,
html[data-theme="dark"] .pj-chips .pj-chip,
html[data-theme="dark"] .pj-dhead .back a,
html[data-theme="dark"] .pj-cal .mh .n,
html[data-theme="dark"] .pj-cal .ev span,
html[data-theme="dark"] .pj-mini + .pj-muted,
html[data-theme="dark"] .pj-role-note,
html[data-theme="dark"] .pj-muted,
html[data-theme="dark"] .pj-pcust,
html[data-theme="dark"] .pj-gtools-label,
html[data-theme="dark"] .pj-group-off .card-header,
html[data-theme="dark"] .rmv-n,
html[data-theme="dark"] .rmv-na,
html[data-theme="dark"] .cust-scope a {
    color: var(--text-secondary);
}
html[data-theme="dark"] .cust-scope a:hover {
    background: var(--surface-2);
    color: var(--text);
}
html[data-theme="dark"] .cust-scope a.on {
    background: var(--primary-solid);
    color: #fff;
}
html[data-theme="dark"] .rmv-h { color: #ff9b9b; }
html[data-theme="dark"] .rmv-m { color: #ffd77a; }
html[data-theme="dark"] .rmv-l { color: #7ff0bd; }
html[data-theme="dark"] .pj-due-over { color: #ff9b9b; }
html[data-theme="dark"] .pj-due-soon { color: #ffd77a; }
html[data-theme="dark"] .pj-row-sel { background: var(--surface-3); }
html[data-theme="dark"] .pj-row-sel td,
html[data-theme="dark"] .pj-row-sel td span { color: var(--text-secondary); }
html[data-theme="dark"] .pj-row-sel td b,
html[data-theme="dark"] .pj-row-sel a { color: #c7d2fe; }

/* ---------- vendor analytics ---------- */
html[data-theme="dark"] .va-page { --va-border: var(--border); --va-muted: var(--text-secondary); }
html[data-theme="dark"] .va-tabs { border-bottom-color: var(--border); }
html[data-theme="dark"] .va-tabs a { color: var(--text-secondary); }
html[data-theme="dark"] .va-tabs a:hover { color: var(--text); background: var(--surface-2); }
html[data-theme="dark"] .va-tabs a.on { color: var(--primary); border-bottom-color: var(--primary); }
html[data-theme="dark"] .va-card,
html[data-theme="dark"] .va-stat,
html[data-theme="dark"] .va-panel,
html[data-theme="dark"] .va-tablewrap { background: var(--card-bg); border-color: var(--border); }
html[data-theme="dark"] .va-card-head,
html[data-theme="dark"] .va-panel-head { border-color: var(--border); color: var(--text); }
html[data-theme="dark"] .va-summary { border-color: var(--border); background: var(--card-bg); }
html[data-theme="dark"] .va-stat { border-right-color: var(--border); }
html[data-theme="dark"] .va-table th { background: var(--surface-2); color: var(--text-secondary); border-bottom-color: var(--border); }
html[data-theme="dark"] .va-table td { color: var(--text); border-bottom-color: var(--border); }
html[data-theme="dark"] .va-table tbody tr:hover { background: var(--surface-2); }
html[data-theme="dark"] .va-seg { border-color: var(--border); }
html[data-theme="dark"] .va-seg a { background: var(--card-bg); color: var(--text-secondary); border-right-color: var(--border); }
html[data-theme="dark"] .va-seg a.on { background: var(--primary-solid); color: #fff; }
html[data-theme="dark"] .va-bars { background: transparent; }
html[data-theme="dark"] .va-bars span { background: #2c4a78; }
html[data-theme="dark"] .va-bars span:last-child { background: var(--primary); }
html[data-theme="dark"] .va-bars span b { color: var(--text-secondary); }
html[data-theme="dark"] .va-bars span:last-child b { color: #ffb199; }
html[data-theme="dark"] .va-activity-grid span { border-color: var(--border); }
html[data-theme="dark"] .va-activity-bar { background: #2c4a78; }
html[data-theme="dark"] .va-activity-bar.hot { background: var(--primary); }
html[data-theme="dark"] .va-activity-bar.zero { background: var(--surface-2); }
html[data-theme="dark"] .va-bar { background: #22344c; }
html[data-theme="dark"] .va-sync.ok { background: #0f2e24; border-color: #1c5b45; color: #7ff0bd; }
html[data-theme="dark"] .va-sync.warn { background: #2b2414; border-color: #6b5522; color: #ffd77a; }
html[data-theme="dark"] .va-sync.bad { background: #32181c; border-color: #6b2e35; color: #ff9b9b; }
html[data-theme="dark"] .va-sync.unknown { background: var(--surface-2); border-color: var(--border); color: var(--text-secondary); }
html[data-theme="dark"] .va-sync-bar { background: #32181c; border-color: #6b2e35; color: #ff9b9b; }
html[data-theme="dark"] .va-window-label { color: var(--text); }
html[data-theme="dark"] .va-window-hint { color: var(--text-secondary); }
html[data-theme="dark"] .va-stat .k,
html[data-theme="dark"] .va-stat .n,
html[data-theme="dark"] .va-activity-meta,
html[data-theme="dark"] .va-activity-labels span,
html[data-theme="dark"] .va-activity-legend { color: var(--text-secondary); }
html[data-theme="dark"] .va-activity-meta strong { color: var(--text); }
html[data-theme="dark"] .va-stat.green .v { color: #7ff0bd; }
html[data-theme="dark"] .va-stat.red .v { color: #ff9b9b; }
html[data-theme="dark"] .va-stat.amber .v { color: #ffd77a; }
html[data-theme="dark"] .va-stat.purple .v { color: #c4b5fd; }
html[data-theme="dark"] .va-pagination .current {
    background: var(--primary-solid);
    border-color: var(--primary-solid);
}

html[data-theme="dark"] .va-note {
    background: var(--surface-2);
    border-color: var(--border);
    color: var(--text-secondary);
}
html[data-theme="dark"] .va-quality {
    background: var(--surface-2);
    border-bottom-color: var(--border);
}
html[data-theme="dark"] .va-quality .k,
html[data-theme="dark"] .va-quality .n { color: var(--text-secondary); }
html[data-theme="dark"] .va-quality .v { color: var(--text); }
html[data-theme="dark"] .va-table tfoot td { background: var(--surface-2); color: var(--text); }
html[data-theme="dark"] .va-badge.ok { background: #0f2e24; color: #7ff0bd; }
html[data-theme="dark"] .va-badge.bad { background: #32181c; color: #ff9b9b; }
html[data-theme="dark"] .va-badge.warn { background: #2b2414; color: #ffd77a; }
html[data-theme="dark"] .va-badge.purple { background: #241d3d; color: #c4b5fd; }
html[data-theme="dark"] .va-badge.gray { background: var(--surface-2); color: var(--text-secondary); }
html[data-theme="dark"] .va-badge.blue { background: #102a45; color: #9dccff; }
html[data-theme="dark"] .va-grade { background: var(--surface-2); color: var(--text-secondary); }
html[data-theme="dark"] .va-grade.S { background: #0f2e24; color: #7ff0bd; }
html[data-theme="dark"] .va-grade.A { background: #102a45; color: #9dccff; }
html[data-theme="dark"] .va-grade.B { background: #2b2414; color: #ffd77a; }
html[data-theme="dark"] .va-grade.C { background: #2a1c12; color: #ffb38c; }
html[data-theme="dark"] .va-grade.D { background: #32181c; color: #ff9b9b; }
html[data-theme="dark"] .va-alert { border-bottom-color: var(--border); }
html[data-theme="dark"] .va-alert .title { color: var(--text); }
html[data-theme="dark"] .va-alert.red .icon { background: #32181c; color: #ff9b9b; }
html[data-theme="dark"] .va-alert.yellow .icon { background: #2b2414; color: #ffd77a; }
html[data-theme="dark"] .va-alert.info .icon { background: #102a45; color: #9dccff; }
html[data-theme="dark"] .va-alert.green .icon { background: #0f2e24; color: #7ff0bd; }
html[data-theme="dark"] .va-pagination a:hover { background: var(--surface-2); }
html[data-theme="dark"] .va-customer-table th:first-child,
html[data-theme="dark"] .va-customer-table td:first-child,
html[data-theme="dark"] .va-search-table th:first-child,
html[data-theme="dark"] .va-search-table td:first-child { background: var(--surface-2); }

/* ---------- data integration ---------- */
html[data-theme="dark"] .int-head { background: var(--surface-2); }
html[data-theme="dark"] .int-badge.unmapped { background: #2b2414; color: #ffd77a; }
html[data-theme="dark"] .int-badge.mapped { background: #0f2e24; color: #7ff0bd; }
html[data-theme="dark"] .int-badge.disabled { background: var(--surface-2); color: var(--text-secondary); }

/* ---------- role badges ---------- */
html[data-theme="dark"] .role-type-super { background: #32181c; color: #ff9b9b; }
html[data-theme="dark"] .role-type-system { background: #1e2447; color: #b9c0ff; }
html[data-theme="dark"] .role-type-custom { background: #0f2e24; color: #7ff0bd; }

/* ---------- home dashboard ---------- */
html[data-theme="dark"] .dash-wrap { --dash-border: var(--border); --dash-muted: var(--text-secondary); }
html[data-theme="dark"] .dash-hero {
    background: linear-gradient(135deg, #0f1a2b, #0b1524);
    border-color: var(--border);
}
html[data-theme="dark"] .dash-hero p,
html[data-theme="dark"] .dash-hero-meta { color: var(--text-secondary); }
html[data-theme="dark"] .dash-quick a {
    background: var(--surface-2);
    border-color: var(--border);
    color: var(--text);
}
html[data-theme="dark"] .dash-quick a:hover {
    background: var(--primary-light);
    border-color: var(--primary);
    color: var(--primary);
}
html[data-theme="dark"] .dash-kpi {
    background: var(--card-bg);
    border-color: var(--border);
    color: var(--text);
}
html[data-theme="dark"] a.dash-kpi:hover { border-color: #3b5575; box-shadow: none; }
html[data-theme="dark"] .dash-kpi-value,
html[data-theme="dark"] .dash-kpi-sub,
html[data-theme="dark"] .dash-kpi-label { color: var(--text); }
html[data-theme="dark"] .dash-kpi-sub,
html[data-theme="dark"] .dash-kpi-label { color: var(--text-secondary); }
html[data-theme="dark"] .dash-card {
    background: var(--card-bg);
    border-color: var(--border);
}
html[data-theme="dark"] .dash-card-head {
    border-bottom-color: var(--border);
    color: var(--text);
}
html[data-theme="dark"] .dash-card-head .sub { color: var(--text-secondary); }
html[data-theme="dark"] .dash-todo-item { border-bottom-color: var(--border); color: var(--text); }
html[data-theme="dark"] .dash-todo-item:hover { background: var(--surface-2); }
html[data-theme="dark"] .dash-todo-name,
html[data-theme="dark"] .dash-todo-count { color: var(--text); }
html[data-theme="dark"] .dash-todo-meta,
html[data-theme="dark"] .dash-todo-arrow { color: var(--text-secondary); }
html[data-theme="dark"] .dash-table th { background: var(--surface-2); color: var(--text-secondary); border-bottom-color: var(--border); }
html[data-theme="dark"] .dash-table td { color: var(--text); border-bottom-color: var(--border); }
html[data-theme="dark"] .dash-table .name { color: var(--text); }
html[data-theme="dark"] .dash-sub { color: var(--text-secondary); }
html[data-theme="dark"] .dash-tabs { border-color: var(--border); }
html[data-theme="dark"] .dash-tabs a,
html[data-theme="dark"] .dash-tabs button {
    background: var(--card-bg);
    color: var(--text-secondary);
    border-right-color: var(--border);
}
html[data-theme="dark"] .dash-tabs a:hover,
html[data-theme="dark"] .dash-tabs button:hover { background: var(--surface-2); }
html[data-theme="dark"] .dash-tabs a.on,
html[data-theme="dark"] .dash-tabs a.on,
html[data-theme="dark"] .dash-tabs button.on { background: var(--primary-solid); color: #fff; }
html[data-theme="dark"] .dash-todo-footer { border-top-color: var(--border); color: var(--text-secondary); }
html[data-theme="dark"] .dash-todo-footer a { color: var(--text-secondary); }
html[data-theme="dark"] .dash-stat-line,
html[data-theme="dark"] .dash-chart-meta { color: var(--text-secondary); }
html[data-theme="dark"] .dash-stat-line strong,
html[data-theme="dark"] .dash-chart-meta strong { color: var(--text); }
html[data-theme="dark"] .dash-sync.ok { color: #7ff0bd; }
html[data-theme="dark"] .dash-sync.warn { color: #ffd77a; }
html[data-theme="dark"] .dash-sync.bad { color: #ff9b9b; }
html[data-theme="dark"] .dash-system { color: var(--text-secondary); }
html[data-theme="dark"] .dash-system strong { color: var(--text); }

/* ---------- customer status pills ---------- */
.cust-status {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 12px;
    white-space: nowrap;
}
.cust-status-active { background: #e7f5ee; color: #146c3f; }
.cust-status-inactive { background: #f3f4f6; color: #4b5563; }
html[data-theme="dark"] .cust-status-active { background: #0f2e24; color: #7ff0bd; }
html[data-theme="dark"] .cust-status-inactive { background: var(--surface-2); color: var(--text-secondary); }

/* ---------- publish overview ---------- */
html[data-theme="dark"] .po-table tr.hl td { background: #17253b; color: var(--text); }
html[data-theme="dark"] .po-table tr.total td { background: var(--surface-2); color: var(--text); }
html[data-theme="dark"] .po-table th.grp-cur { background: #17253b; color: var(--text-secondary); }
html[data-theme="dark"] .po-table th.grp-prev { background: #1b2238; color: var(--text-secondary); }
html[data-theme="dark"] .po-table .ok { color: #7ff0bd; }
html[data-theme="dark"] .po-table .fail { color: #ff9b9b; }
html[data-theme="dark"] .po-table .risk { color: #ffd77a; }
html[data-theme="dark"] .po-table .muted,
html[data-theme="dark"] .po-table .section-sub { color: var(--text-secondary); }
html[data-theme="dark"] .trend-bar input[type="date"] {
    background: #0b1524;
    border-color: var(--border);
    color: var(--text);
    color-scheme: dark;
}
html[data-theme="dark"] .range-tabs { border-color: var(--border); }
html[data-theme="dark"] .range-tabs button {
    background: var(--card-bg);
    color: var(--text-secondary);
    border-right-color: var(--border);
}
html[data-theme="dark"] .range-tabs button:hover { background: var(--surface-2); color: var(--text); }
html[data-theme="dark"] .range-tabs button.active { background: var(--primary-solid); color: #fff; }
html[data-theme="dark"] .po-source-switch a.on { background: var(--primary-solid); color: #fff; }

/* ---------- customer list chart ---------- */
html[data-theme="dark"] .cc-row .name { color: var(--text); }
html[data-theme="dark"] .cc-track { background: var(--surface-2); }
html[data-theme="dark"] .cc-track > i { background: var(--info); }
html[data-theme="dark"] .cc-track > i.high { background: var(--danger); }
html[data-theme="dark"] .cc-track > i.mid { background: var(--warning); }
html[data-theme="dark"] .cc-track b { color: var(--text); background: rgba(7, 13, 24, .8); }
html[data-theme="dark"] .cc-axis { color: var(--text-secondary); }

/* ---------- docs / misc ---------- */
html[data-theme="dark"] .dc-box,
html[data-theme="dark"] details,
html[data-theme="dark"] .doc .code,
html[data-theme="dark"] code {
    background: var(--surface-2);
    border-color: var(--border);
    color: var(--text);
}
html[data-theme="dark"] .ds { color: var(--text-secondary); }
html[data-theme="dark"] .toast,
html[data-theme="dark"] .copy-toast {
    background: var(--surface-3);
    border: 1px solid var(--border);
    color: var(--text);
}
html[data-theme="dark"] .flat-table .rmv-na,
html[data-theme="dark"] .pj-muted { color: var(--text-secondary); }

/* ---------- scrollbar ---------- */
html[data-theme="dark"] * {
    scrollbar-color: #334a66 #0b1524;
}
html[data-theme="dark"] ::-webkit-scrollbar { width: 10px; height: 10px; }
html[data-theme="dark"] ::-webkit-scrollbar-track { background: #0b1524; }
html[data-theme="dark"] ::-webkit-scrollbar-thumb { background: #334a66; border-radius: 5px; }

/* ---------- print / export always light ---------- */
@media print {
    body { background: #fff !important; color: #111827 !important; }
    .top-nav,
    .theme-toggle { display: none !important; }
    html[data-theme="dark"] {
        color-scheme: light;
        --bg: #fff;
        --card-bg: #fff;
        --surface-2: #f8fafc;
        --surface-3: #f1f5f9;
        --text: #111827;
        --text-secondary: #475569;
        --border: #d8dee8;
        --primary: #0b2545;
        --primary-light: #eef2f8;
    }
    html[data-theme="dark"] body { background: #fff !important; color: #111827 !important; }
    html[data-theme="dark"] .top-nav,
    html[data-theme="dark"] .theme-toggle { display: none !important; }
}
