/**
 * Token enforcement — remaps hardcoded Tailwind / inline palette classes to theme variables.
 * Load AFTER compiled Tailwind (Vite) so overrides win.
 *
 * App scope:  .app-theme-content, .lb-dash*, .admin-dashboard, .portal-dashboard
 * Guest scope: .guest-marketing-canvas, .lb-page, .lb-sales, .guest-public-shell
 */

/* ── Shared overlay scrim (modals, drawers, hand-rolled dialogs) ── */
:root {
    --app-overlay-scrim: color-mix(in srgb, var(--theme-header-text-color, #0f172a) 46%, transparent);
    --app-overlay-scrim-light: color-mix(in srgb, var(--theme-surface-overlay, #ffffff) 55%, transparent);
}

.app-shell-overlay:not([class*="bg-transparent"]) {
    background-color: var(--app-overlay-scrim) !important;
}

/* Keep Alpine x-show / hidden overlays from trapping clicks */
.app-shell-overlay[style*="display: none"],
.app-native-dialog-shell[style*="display: none"],
.app-shell-overlay[hidden],
.app-native-dialog-shell[hidden],
.app-shell-overlay[x-cloak],
.app-native-dialog-shell[x-cloak] {
    display: none !important;
    pointer-events: none !important;
    visibility: hidden !important;
}

.app-shell-overlay[class*="bg-slate"],
.app-shell-overlay[class*="bg-zinc"],
.app-shell-overlay[class*="bg-black"] {
    background-color: color-mix(in srgb, var(--theme-header-text-color, #0f172a) 34%, transparent) !important;
}

.app-shell-overlay > .absolute.inset-0[class*="bg-white"],
.app-shell-overlay > .absolute.inset-0[class*="bg-slate"],
.app-shell-overlay > .absolute.inset-0[class*="bg-zinc"],
.app-shell-overlay > [class*="inset-0"][class*="bg-white/"],
.app-shell-overlay > [class*="inset-0"][class*="bg-slate-950/"] {
    background-color: transparent !important;
}

/* ── App dashboard / admin content ── */
.app-theme-content,
.lb-dash,
.lb-dash-workspace,
.lb-dash-page,
.admin-dashboard,
.portal-dashboard,
.app-native-shell {
    /* Surfaces */
    --te-surface: var(--theme-surface-base, var(--app-brand-surface, #ffffff));
    --te-surface-soft: var(--theme-surface-soft, var(--app-brand-background, #f8fafc));
    --te-border: var(--theme-border-color, var(--app-brand-border, #e2e8f0));
    --te-text: var(--theme-header-text-color, var(--app-text-primary, #0f172a));
    --te-muted: var(--theme-muted-text-color, var(--app-text-secondary, #475569));
    --te-accent: var(--theme-accent, var(--app-brand-primary, #0f766e));
    --te-success: var(--theme-success-color, var(--app-brand-success, #22c55e));
    --te-warning: var(--theme-warning-color, var(--app-brand-warning, #f59e0b));
    --te-danger: var(--theme-danger-color, var(--app-brand-error, #ef4444));
    --te-info: var(--theme-chart-blue, var(--app-chart-blue, #3b82f6));
    --te-purple: var(--theme-chart-purple, var(--app-chart-purple, #8b5cf6));
    --te-green: var(--theme-chart-green, var(--app-chart-green, #10b981));
    --te-orange: var(--theme-chart-orange, var(--app-chart-orange, #f59e0b));
}

.app-theme-content .bg-white,
.lb-dash .bg-white,
.lb-dash-workspace .bg-white,
.lb-dash-page .bg-white,
.admin-dashboard .bg-white,
.portal-dashboard .bg-white,
.app-theme-content [class*="bg-white/"],
.lb-dash-workspace [class*="bg-white/"],
.admin-dashboard [class*="bg-white/"],
.portal-dashboard [class*="bg-white/"] {
    background-color: color-mix(in srgb, var(--te-surface) 96%, transparent) !important;
}

.app-theme-content .bg-slate-50,
.app-theme-content .bg-gray-50,
.lb-dash-workspace .bg-slate-50,
.lb-dash-workspace .bg-gray-50,
.admin-dashboard .bg-slate-50,
.portal-dashboard .bg-slate-50 {
    background-color: var(--te-surface-soft) !important;
}

.app-theme-content .bg-slate-100,
.app-theme-content .bg-gray-100,
.lb-dash-workspace .bg-slate-100 {
    background-color: color-mix(in srgb, var(--te-surface-soft) 88%, var(--te-border) 12%) !important;
}

.app-theme-content .text-slate-950,
.app-theme-content .text-slate-900,
.app-theme-content .text-gray-950,
.app-theme-content .text-gray-900,
.lb-dash-workspace .text-slate-950,
.lb-dash-workspace .text-slate-900,
.lb-dash-workspace .text-gray-950,
.lb-dash-workspace .text-gray-900,
.admin-dashboard .text-slate-950,
.admin-dashboard .text-slate-900,
.portal-dashboard .text-slate-950,
.portal-dashboard .text-slate-900 {
    color: var(--te-text) !important;
}

.app-theme-content .text-slate-800,
.app-theme-content .text-slate-700,
.lb-dash-workspace .text-slate-800,
.lb-dash-workspace .text-slate-700,
.admin-dashboard .text-slate-800,
.admin-dashboard .text-slate-700 {
    color: color-mix(in srgb, var(--te-text) 88%, var(--te-muted) 12%) !important;
}

.app-theme-content .text-slate-600,
.app-theme-content .text-slate-500,
.app-theme-content .text-slate-400,
.app-theme-content .text-gray-600,
.app-theme-content .text-gray-500,
.lb-dash-workspace .text-slate-600,
.lb-dash-workspace .text-slate-500,
.lb-dash-workspace .text-slate-400,
.admin-dashboard .text-slate-600,
.admin-dashboard .text-slate-500,
.portal-dashboard .text-slate-600,
.portal-dashboard .text-slate-500 {
    color: var(--te-muted) !important;
}

.app-theme-content .border-slate-100,
.app-theme-content .border-slate-200,
.app-theme-content .border-slate-300,
.app-theme-content .border-gray-200,
.app-theme-content .border-gray-300,
.lb-dash-workspace [class*="border-slate-"]:not(.lb-ui-checkbox__box),
.lb-dash-workspace [class*="border-gray-"]:not(.lb-ui-checkbox__box),
.admin-dashboard [class*="border-slate-"]:not(.lb-ui-checkbox__box),
.portal-dashboard [class*="border-slate-"]:not(.lb-ui-checkbox__box) {
    border-color: color-mix(in srgb, var(--te-border) 82%, transparent) !important;
}

/* Keep unchecked checkbox boxes readable even if slate utilities remain elsewhere */
.lb-dash-workspace .lb-ui-checkbox__input:not(:checked) + .lb-ui-checkbox__box,
.app-theme-content .lb-ui-checkbox__input:not(:checked) + .lb-ui-checkbox__box,
.admin-dashboard .lb-ui-checkbox__input:not(:checked) + .lb-ui-checkbox__box,
.portal-dashboard .lb-ui-checkbox__input:not(:checked) + .lb-ui-checkbox__box,
.guest-marketing-canvas .lb-ui-checkbox__input:not(:checked) + .lb-ui-checkbox__box,
.lb-dash-workspace .peer:not(:checked) + .lb-ui-checkbox__box,
.app-theme-content .peer:not(:checked) + .lb-ui-checkbox__box {
    border-color: color-mix(in srgb, var(--theme-header-text-color, #0f172a) 42%, transparent) !important;
}

.lb-dash-workspace .lb-ui-checkbox__input:checked + .lb-ui-checkbox__box,
.app-theme-content .lb-ui-checkbox__input:checked + .lb-ui-checkbox__box,
.admin-dashboard .lb-ui-checkbox__input:checked + .lb-ui-checkbox__box,
.portal-dashboard .lb-ui-checkbox__input:checked + .lb-ui-checkbox__box,
.guest-marketing-canvas .lb-ui-checkbox__input:checked + .lb-ui-checkbox__box,
.lb-dash-workspace .peer:checked + .lb-ui-checkbox__box,
.app-theme-content .peer:checked + .lb-ui-checkbox__box {
    border-color: var(--theme-accent, #0f766e) !important;
    background-color: var(--theme-accent, #0f766e) !important;
    color: #ffffff !important;
}

.app-theme-content .divide-slate-200 > :not([hidden]) ~ :not([hidden]),
.lb-dash-workspace .divide-slate-200 > :not([hidden]) ~ :not([hidden]) {
    border-color: color-mix(in srgb, var(--te-border) 72%, transparent) !important;
}

.app-theme-content .text-emerald-600,
.app-theme-content .text-emerald-700,
.app-theme-content .text-green-600,
.app-theme-content .text-green-700,
.lb-dash-workspace .text-emerald-600,
.lb-dash-workspace .text-green-600 {
    color: var(--te-success) !important;
}

.app-theme-content .text-amber-600,
.app-theme-content .text-amber-700,
.app-theme-content .text-orange-600,
.app-theme-content .text-yellow-600,
.lb-dash-workspace .text-amber-600,
.lb-dash-workspace .text-orange-600 {
    color: var(--te-warning) !important;
}

.app-theme-content .text-rose-600,
.app-theme-content .text-red-600,
.app-theme-content .text-red-700,
.lb-dash-workspace .text-rose-600,
.lb-dash-workspace .text-red-600 {
    color: var(--te-danger) !important;
}

.app-theme-content .text-sky-600,
.app-theme-content .text-blue-600,
.app-theme-content .text-cyan-600,
.lb-dash-workspace .text-sky-600,
.lb-dash-workspace .text-blue-600 {
    color: var(--te-info) !important;
}

.app-theme-content .text-violet-600,
.app-theme-content .text-purple-600,
.app-theme-content .text-indigo-600,
.lb-dash-workspace .text-violet-600,
.lb-dash-workspace .text-purple-600 {
    color: var(--te-purple) !important;
}

.app-theme-content .text-teal-600,
.app-theme-content .text-teal-700,
.lb-dash-workspace .text-teal-600 {
    color: var(--te-accent) !important;
}

.app-theme-content .bg-emerald-50,
.app-theme-content .bg-green-50,
.lb-dash-workspace .bg-emerald-50 {
    background-color: color-mix(in srgb, var(--te-success) 12%, var(--te-surface) 88%) !important;
}

.app-theme-content .bg-amber-50,
.app-theme-content .bg-orange-50,
.lb-dash-workspace .bg-amber-50 {
    background-color: color-mix(in srgb, var(--te-warning) 12%, var(--te-surface) 88%) !important;
}

.app-theme-content .bg-rose-50,
.app-theme-content .bg-red-50,
.lb-dash-workspace .bg-rose-50 {
    background-color: color-mix(in srgb, var(--te-danger) 10%, var(--te-surface) 90%) !important;
}

.app-theme-content .bg-sky-50,
.app-theme-content .bg-blue-50,
.lb-dash-workspace .bg-sky-50 {
    background-color: color-mix(in srgb, var(--te-info) 10%, var(--te-surface) 90%) !important;
}

.app-theme-content .bg-teal-50,
.lb-dash-workspace .bg-teal-50 {
    background-color: color-mix(in srgb, var(--te-accent) 10%, var(--te-surface) 90%) !important;
}

/* Common inline hex escapes in module blades */
.app-theme-content [style*="color:#0f172a"],
.app-theme-content [style*="color: #0f172a"],
.app-theme-content [style*="color:#111827"],
.app-theme-content [style*="color: #111827"],
.lb-dash-workspace [style*="color:#0f172a"],
.lb-dash-workspace [style*="color: #0f172a"],
.admin-dashboard [style*="color:#0f172a"],
.portal-dashboard [style*="color:#0f172a"] {
    color: var(--te-text) !important;
}

.app-theme-content [style*="color:#64748b"],
.app-theme-content [style*="color: #64748b"],
.app-theme-content [style*="color:#475569"],
.app-theme-content [style*="color: #475569"],
.lb-dash-workspace [style*="color:#64748b"],
.lb-dash-workspace [style*="color: #64748b"] {
    color: var(--te-muted) !important;
}

.app-theme-content [style*="background-color: #fff"],
.app-theme-content [style*="background-color:#fff"],
.app-theme-content [style*="background: #fff"],
.app-theme-content [style*="background:#fff"],
.lb-dash-workspace [style*="background-color: #fff"],
.lb-dash-workspace [style*="background-color:#fff"],
.admin-dashboard [style*="background-color: #fff"],
.portal-dashboard [style*="background-color: #fff"] {
    background-color: var(--te-surface) !important;
}

.app-theme-content [style*="background-color: #f8fafc"],
.app-theme-content [style*="background-color:#f8fafc"],
.lb-dash-workspace [style*="background-color: #f8fafc"] {
    background-color: var(--te-surface-soft) !important;
}

/* ── Guest marketing canvas ── */
.guest-marketing-canvas,
.lb-page,
.lb-sales,
.guest-public-shell {
    --te-surface: var(--lb-cream, var(--theme-surface-bg, #fffefb));
    --te-surface-soft: var(--lb-paper, var(--theme-body-bg, #f7faf6));
    --te-surface-card: var(--lb-cream, #fffefb);
    --te-border: var(--theme-border-color, var(--lb-line, #e8e5dc));
    --te-text: var(--lb-ink, var(--theme-header-text-color, #15201b));
    --te-muted: var(--lb-muted, var(--theme-muted-text-color, #63736b));
    --te-accent: var(--theme-accent, var(--lb-green, #0f766e));
    --te-success: var(--theme-success-color, #22c55e);
    --te-warning: var(--theme-warning-color, #f59e0b);
    --te-danger: var(--theme-danger-color, #ef4444);
}

.guest-marketing-canvas .text-slate-950,
.guest-marketing-canvas .text-slate-900,
.guest-public-shell .text-slate-950,
.guest-public-shell .text-slate-900,
.lb-page .text-slate-950,
.lb-page .text-slate-900,
.lb-sales .text-slate-950 {
    color: var(--te-text) !important;
}

.guest-marketing-canvas .text-slate-600,
.guest-marketing-canvas .text-slate-500,
.guest-public-shell .text-slate-600,
.guest-public-shell .text-slate-500,
.lb-page .text-slate-600,
.lb-page .text-slate-500 {
    color: var(--te-muted) !important;
}

.guest-marketing-canvas .bg-white,
.guest-public-shell .bg-white,
.lb-page .bg-white,
.lb-sales .bg-white,
.guest-marketing-canvas [class*="bg-white/"],
.guest-public-shell [class*="bg-white/"] {
    background-color: color-mix(in srgb, var(--te-surface-card) 96%, transparent) !important;
}

.guest-marketing-canvas .bg-slate-50,
.guest-public-shell .bg-slate-50,
.lb-page .bg-slate-50,
.lb-sales .bg-slate-50 {
    background-color: var(--te-surface-soft) !important;
}

.guest-marketing-canvas [class*="border-slate-"],
.lb-page [class*="border-slate-"] {
    border-color: color-mix(in srgb, var(--te-border) 82%, transparent) !important;
}

.guest-marketing-canvas .text-teal-700,
.guest-marketing-canvas .text-teal-600,
.lb-page .text-teal-700 {
    color: var(--te-accent) !important;
}
