/* =============================================================================
 * dark-overrides.css — Global dark-mode override stylesheet (FIRST PASS)
 *
 * Purpose: ~155 pages carry hardcoded light colors (inline #fff/white
 * backgrounds, #000/#333 text) that ignore Bootstrap 5.3's data-bs-theme
 * dark mode and break contrast. This sheet provides conservative, dark-only
 * corrections.
 *
 * CONTRACT:
 *   - EVERY rule is gated under [data-bs-theme="dark"]. Light mode must be
 *     100% unaffected by this file.
 *   - This is a FIRST PASS. Attribute selectors below cover the most common
 *     inline-style spellings only; they cannot catch every variant.
 *   - Wired via includes/theme_head.inc.php, which loads near the TOP of <head>
 *     (before app.min.css). To stay robust against load order, the theme tokens
 *     below use !important so a later-loaded bundle cannot clobber them, and the
 *     inline-style neutralizers use !important because inline styles otherwise
 *     beat any stylesheet rule.
 * ========================================================================= */

/* ---------------------------------------------------------------------------
 * 1) Sane theme tokens. Bootstrap 5.3 already sets dark values, but some
 *    bundled CSS (luxury-palette, launchpad-admin) can clobber them. Re-assert
 *    readable surfaces/text/borders for the dark theme only.
 * ------------------------------------------------------------------------- */
[data-bs-theme="dark"] {
    --bs-body-bg: #14161a !important;
    --bs-body-color: #d4d7dd !important;
    --bs-card-bg: #1c1f26 !important;
    --bs-card-color: #d4d7dd !important;
    --bs-border-color: #2d323c !important;
    --bs-border-color-translucent: rgba(255, 255, 255, 0.12) !important;
    --bs-secondary-bg: #1c1f26 !important;
    --bs-tertiary-bg: #22262f !important;
    --bs-emphasis-color: #f1f3f6 !important;
    --bs-secondary-color: rgba(212, 215, 221, 0.75) !important;
}

/* Card surface follows the token even if a theme hardcoded it. */
[data-bs-theme="dark"] .card {
    background-color: var(--bs-card-bg);
    color: var(--bs-card-color);
    border-color: var(--bs-border-color);
}

/* ---------------------------------------------------------------------------
 * 2) Inline-style neutralizers — hardcoded WHITE/LIGHT BACKGROUNDS.
 *    Attribute selectors match the literal text of common inline styles.
 *    Covers: background / background-color, with #fff, #ffffff, white,
 *    and a few near-white greys, with and without a space after the colon.
 * ------------------------------------------------------------------------- */
[data-bs-theme="dark"] [style*="background:#fff"],
[data-bs-theme="dark"] [style*="background: #fff"],
[data-bs-theme="dark"] [style*="background:#FFF"],
[data-bs-theme="dark"] [style*="background: #FFF"],
[data-bs-theme="dark"] [style*="background:#ffffff"],
[data-bs-theme="dark"] [style*="background: #ffffff"],
[data-bs-theme="dark"] [style*="background:#FFFFFF"],
[data-bs-theme="dark"] [style*="background: #FFFFFF"],
[data-bs-theme="dark"] [style*="background:white"],
[data-bs-theme="dark"] [style*="background: white"],
[data-bs-theme="dark"] [style*="background-color:#fff"],
[data-bs-theme="dark"] [style*="background-color: #fff"],
[data-bs-theme="dark"] [style*="background-color:#FFF"],
[data-bs-theme="dark"] [style*="background-color: #FFF"],
[data-bs-theme="dark"] [style*="background-color:#ffffff"],
[data-bs-theme="dark"] [style*="background-color: #ffffff"],
[data-bs-theme="dark"] [style*="background-color:#FFFFFF"],
[data-bs-theme="dark"] [style*="background-color: #FFFFFF"],
[data-bs-theme="dark"] [style*="background-color:white"],
[data-bs-theme="dark"] [style*="background-color: white"],
[data-bs-theme="dark"] [style*="background:#f8f9fa"],
[data-bs-theme="dark"] [style*="background: #f8f9fa"],
[data-bs-theme="dark"] [style*="background-color:#f8f9fa"],
[data-bs-theme="dark"] [style*="background-color: #f8f9fa"],
[data-bs-theme="dark"] [style*="background:#f5f5f5"],
[data-bs-theme="dark"] [style*="background: #f5f5f5"],
[data-bs-theme="dark"] [style*="background-color:#f5f5f5"],
[data-bs-theme="dark"] [style*="background-color: #f5f5f5"],
[data-bs-theme="dark"] [style*="background:#fafafa"],
[data-bs-theme="dark"] [style*="background: #fafafa"],
[data-bs-theme="dark"] [style*="background-color:#fafafa"],
[data-bs-theme="dark"] [style*="background-color: #fafafa"],
[data-bs-theme="dark"] [style*="background:#eee"],
[data-bs-theme="dark"] [style*="background: #eee"],
[data-bs-theme="dark"] [style*="background-color:#eee"],
[data-bs-theme="dark"] [style*="background-color: #eee"] {
    background-color: var(--bs-card-bg) !important;
    background-image: none !important;
    color: var(--bs-body-color) !important;
}

/* ---------------------------------------------------------------------------
 * 3) Inline-style neutralizers — hardcoded DARK TEXT on (now) dark surfaces.
 *    Covers: color #000 / #333 / #222 / #444 in common spellings.
 * ------------------------------------------------------------------------- */
[data-bs-theme="dark"] [style*="color:#000"],
[data-bs-theme="dark"] [style*="color: #000"],
[data-bs-theme="dark"] [style*="color:#000000"],
[data-bs-theme="dark"] [style*="color: #000000"],
[data-bs-theme="dark"] [style*="color:black"],
[data-bs-theme="dark"] [style*="color: black"],
[data-bs-theme="dark"] [style*="color:#111"],
[data-bs-theme="dark"] [style*="color: #111"],
[data-bs-theme="dark"] [style*="color:#222"],
[data-bs-theme="dark"] [style*="color: #222"],
[data-bs-theme="dark"] [style*="color:#333"],
[data-bs-theme="dark"] [style*="color: #333"],
[data-bs-theme="dark"] [style*="color:#444"],
[data-bs-theme="dark"] [style*="color: #444"],
[data-bs-theme="dark"] [style*="color:#555"],
[data-bs-theme="dark"] [style*="color: #555"] {
    color: var(--bs-body-color) !important;
}

/* ---------------------------------------------------------------------------
 * 4) Combined common pattern: white card with dark text in one inline style.
 *    The rules above already cover each declaration independently; this block
 *    is a belt-and-suspenders catch for elements whose ONLY light cue is a
 *    light border on a light card.
 * ------------------------------------------------------------------------- */
[data-bs-theme="dark"] [style*="border:1px solid #ddd"],
[data-bs-theme="dark"] [style*="border: 1px solid #ddd"],
[data-bs-theme="dark"] [style*="border:1px solid #eee"],
[data-bs-theme="dark"] [style*="border: 1px solid #eee"],
[data-bs-theme="dark"] [style*="border:1px solid #e0e0e0"],
[data-bs-theme="dark"] [style*="border: 1px solid #e0e0e0"],
[data-bs-theme="dark"] [style*="border:1px solid #ccc"],
[data-bs-theme="dark"] [style*="border: 1px solid #ccc"] {
    border-color: var(--bs-border-color) !important;
}

/* ===========================================================================
 * 5) CRM-SPECIFIC OVERRIDES
 *
 * The CRM pages (crm-dashboard, crm-leads, crm-pipeline, crm-tasks,
 * crm-reports, crm-inbox, crm-action-plans, crm-email-templates,
 * crm-email-template-detail, crm-lead-view) declare hardcoded light colors
 * via CLASS selectors inside their own inline <style> blocks (e.g.
 * `.template-card { background: white; }`). Those are NOT inline style="..."
 * attributes, so the attribute neutralizers above can't reach them. Re-skin the
 * common CRM class surfaces here, dark-only. Light mode is untouched.
 * ========================================================================= */

/* App shell surfaces several CRM pages restyle to white. */
[data-bs-theme="dark"] .content,
[data-bs-theme="dark"] .topbar,
[data-bs-theme="dark"] .page-content,
[data-bs-theme="dark"] .footer,
[data-bs-theme="dark"] .themed-footer,
[data-bs-theme="dark"] .crm-pipeline-footer {
    background-color: var(--bs-body-bg) !important;
    color: var(--bs-body-color) !important;
    border-color: var(--bs-border-color) !important;
}

/* Card-like CRM panels with hardcoded white/light backgrounds. */
[data-bs-theme="dark"] .template-card,
[data-bs-theme="dark"] .stats-card,
[data-bs-theme="dark"] .stat-card,
[data-bs-theme="dark"] .page-header,
[data-bs-theme="dark"] .activity-feed,
[data-bs-theme="dark"] .builder-settings,
[data-bs-theme="dark"] .form-container,
[data-bs-theme="dark"] .lead-info-card,
[data-bs-theme="dark"] .preview-frame {
    background-color: var(--bs-card-bg) !important;
    color: var(--bs-body-color) !important;
    border-color: var(--bs-border-color) !important;
}

/* Subtle inset surfaces (light grey) used for previews / info strips. */
[data-bs-theme="dark"] .lead-info-card,
[data-bs-theme="dark"] .preview-frame {
    background-color: var(--bs-tertiary-bg) !important;
}

/* Email-template editor "copy this" merge-field chips (.variable-tag). */
[data-bs-theme="dark"] .variable-tag {
    background-color: var(--bs-tertiary-bg) !important;
    color: var(--bs-body-color) !important;
    border: 1px solid var(--bs-border-color) !important;
}
[data-bs-theme="dark"] .variable-tag:hover {
    background-color: var(--bs-secondary-bg) !important;
}

/* Status / priority pills: keep accent text legible but darken the chip bg so
 * the near-white tints (#fff3cd, #fff9db, #fff5f5, #fff3e0) don't glare. */
[data-bs-theme="dark"] .status-badge,
[data-bs-theme="dark"] .status-badge-lg,
[data-bs-theme="dark"] .priority-badge-lg,
[data-bs-theme="dark"] .overdue-alert {
    background-color: var(--bs-tertiary-bg) !important;
    border-color: var(--bs-border-color) !important;
}

/* Bootstrap soft-tint utility backgrounds some CRM pages define locally.
 * Replace the very light tints with translucent accents readable on dark. */
[data-bs-theme="dark"] .bg-soft-primary { background-color: rgba(13, 110, 253, 0.18) !important; }
[data-bs-theme="dark"] .bg-soft-success { background-color: rgba(25, 135, 84, 0.18) !important; }
[data-bs-theme="dark"] .bg-soft-info    { background-color: rgba(13, 202, 240, 0.18) !important; }
[data-bs-theme="dark"] .bg-soft-warning { background-color: rgba(255, 193, 7, 0.18) !important; }

/* Bootstrap .table-light header rows render near-white; align to dark surface. */
[data-bs-theme="dark"] .table-light,
[data-bs-theme="dark"] .table-light > th,
[data-bs-theme="dark"] .table-light > td,
[data-bs-theme="dark"] .table > thead.table-light th {
    background-color: var(--bs-tertiary-bg) !important;
    color: var(--bs-body-color) !important;
    border-color: var(--bs-border-color) !important;
}

/* CRM dropdown menus that hardcode a white background. */
[data-bs-theme="dark"] .dropdown-menu {
    background-color: var(--bs-card-bg) !important;
    color: var(--bs-body-color) !important;
    border-color: var(--bs-border-color) !important;
}
[data-bs-theme="dark"] .dropdown-menu .dropdown-item {
    color: var(--bs-body-color) !important;
}
[data-bs-theme="dark"] .dropdown-menu .dropdown-item:hover,
[data-bs-theme="dark"] .dropdown-menu .dropdown-item:focus {
    background-color: var(--bs-secondary-bg) !important;
}
