/* Global light theme for the CRM. Kept separate so legacy screens share one palette. */
:root {
    color-scheme: light;
    --bg: #f4f7fb;
    --surface: #ffffff;
    --surface-hover: #eef2f7;
    --border: #d8dee9;
    --text-main: #172033;
    --text-secondary: #667085;
    --text-muted: #98a2b3;
    --accent: #5563d7;
    --accent-hover: #4653c5;
    --accent-bg: rgba(85, 99, 215, 0.10);
    --bg-color: var(--surface);
    --hover-color: var(--surface-hover);
    --border-color: var(--border);
    --text-color: var(--text-main);
    /* Settings dialogs are siblings of .settings-page, so tokens must be global. */
    --settings-border: #e4e7ec;
    --settings-border-strong: #d0d5dd;
    --settings-surface: var(--surface);
    --settings-surface-2: #f8fafc;
    --settings-surface-3: #f2f4f7;
    --settings-text: var(--text-main);
    --settings-muted: var(--text-secondary);
    --settings-soft: #475467;
}

html body {
    background: var(--bg) !important;
    color: var(--text-main) !important;
}

html body input,
html body select,
html body textarea {
    color-scheme: light;
}

/* All editable fields, including settings modals and JS-created product rows. */
html body input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not([type="hidden"]):not([type="button"]):not([type="submit"]),
html body select,
html body textarea {
    background-color: var(--surface) !important;
    color: var(--text-main) !important;
    border: 1px solid var(--border);
}
html body input:disabled,
html body select:disabled,
html body textarea:disabled,
html body input[readonly] {
    background-color: var(--surface-hover) !important;
    color: var(--text-secondary) !important;
}
html body input:focus-visible,
html body select:focus-visible,
html body textarea:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}
html body .bg-crm-control,
html body .bg-crm-control-hover { color: #344054 !important; }
html body .bg-crm-control .text-white { color: #344054 !important; }
html body .hover\:bg-crm-control-hover:hover,
html body .hover\:bg-crm-control:hover,
html body .hover\:bg-crm-field:hover,
html body .hover\:bg-crm-field\/50:hover,
html body .hover\:bg-crm-subtle\/40:hover {
    background-color: #e2e8f0 !important;
}
html body .service-search-count,
html body .service-search-result-icon,
html body .site-layout-tool-toggle.is-active { color: var(--accent) !important; }

html body input::placeholder,
html body textarea::placeholder {
    color: #98a2b3;
    opacity: 1;
}

/* Legacy Tailwind utility palette. */
html body .bg-slate-50 { background-color: #f8fafc !important; }
html body .bg-crm-control { background-color: #e2e8f0 !important; }
html body .bg-crm-field,
html body .bg-crm-field\/30,
html body .bg-crm-field\/40,
html body .bg-crm-field\/50 { background-color: #ffffff !important; }
html body .bg-crm-subtle,
html body .bg-crm-subtle\/30,
html body .bg-crm-subtle\/40,
html body .bg-crm-subtle\/50 { background-color: #eef2f7 !important; }
html body .bg-crm-inset,
html body .bg-crm-inset\/30,
html body .bg-crm-inset\/50 { background-color: #e7edf5 !important; }
html body .border-slate-400\/20,
html body .border-slate-600,
html body .border-slate-600\/50,
html body .border-slate-700,
html body .border-slate-800 { border-color: #cbd5e1 !important; }
html body .text-slate-300,
html body .text-slate-50 { color: #334155 !important; }
html body .text-slate-400,
html body .text-slate-600,
html body .text-gray-400 { color: #64748b !important; }
html body .bg-gray-50,
html body .bg-gray-100 { background-color: #f1f5f9 !important; }
html body .text-gray-800 { color: #1f2937 !important; }

/* Status colors need darker foregrounds on pale surfaces. */
html body .text-red-200,
html body .text-red-300,
html body .text-red-400 { color: #b42318 !important; }
html body .text-emerald-200,
html body .text-emerald-300,
html body .text-emerald-400,
html body .text-green-400 { color: #067647 !important; }
html body .text-amber-200,
html body .text-amber-300,
html body .text-amber-400 { color: #b54708 !important; }
html body .text-blue-300,
html body .text-blue-400,
html body .text-sky-300,
html body .text-sky-400 { color: #175cd3 !important; }
html body .text-yellow-200,
html body .text-yellow-300,
html body .text-yellow-400 { color: #854d0e !important; }
html body .text-purple-200,
html body .text-purple-300,
html body .text-purple-400,
html body .text-violet-300,
html body .text-violet-400,
html body .text-indigo-300,
html body .text-indigo-400 { color: #6941c6 !important; }

/* Shared catalog surfaces. */
html body .cat-input,
html body .cat-select,
html body .cat-table thead,
html body .stock-inline-input { background: #f8fafc !important; }
html body .cat-table tbody tr:hover,
html body .cat-card:hover { background: #f7f9fc !important; }
html body .cat-empty { background: #f8fafc !important; }
html body .cat-badge.good { color: #067647 !important; }
html body .cat-badge.warn { color: #b54708 !important; }
html body .cat-badge.bad { color: #b42318 !important; }
html body .cat-badge.info { color: #175cd3 !important; }
html body .cat-badge.violet { color: #5925dc !important; }
html body .cat-badge.slate { color: #475467 !important; }

/* Order editor: old page-specific CSS used hard-coded dark cards. */
html body .order-create-panel,
html body .bg-surface.p-6.rounded-lg.shadow-lg,
html body .category-section,
html body .order-entry-card,
html body .deceased-item,
html body .product-item,
html body .monument-item,
html body .portrait-item,
html body .fence-item,
html body .order-item,
html body .service-item-wrapper {
    background: #ffffff !important;
    border-color: #d8dee9 !important;
    box-shadow: 0 8px 24px rgba(16, 24, 40, 0.06) !important;
}
html body .service-header,
html body .service-calculation,
html body .service-item-wrapper .bg-crm-field,
html body .service-item-wrapper .bg-crm-subtle\/30,
html body .service-item-wrapper .bg-crm-subtle\/50 { background: #f7f9fc !important; }
html body .bg-surface.p-6.rounded-lg.shadow-lg input:not([type="checkbox"]):not([type="radio"]),
html body .bg-surface.p-6.rounded-lg.shadow-lg select,
html body .bg-surface.p-6.rounded-lg.shadow-lg textarea {
    background: #ffffff !important;
    border-color: #cbd5e1 !important;
    color: #172033 !important;
}
html body .bg-surface.p-6.rounded-lg.shadow-lg .text-text-main,
html body .service-item-wrapper .text-text-main,
html body .service-item-wrapper .text-primary-light { color: #172033 !important; }
html body .bg-surface.p-6.rounded-lg.shadow-lg .text-text-secondary,
html body .service-item-wrapper .text-text-secondary { color: #667085 !important; }
html body #addMonumentBtn,
html body #add-portrait-btn,
html body #add-fence-btn,
html body #add-product-btn,
html body .order-add-button { background: #f8fafc !important; color: #344054 !important; border-color: #cbd5e1 !important; }
html body #file-upload-area { background: #f8fafc !important; }
html body .service-has-cell,
html body .service-has-tile-cell { background-color: #ffffff !important; border-color: #98a2b3 !important; }
html body .service-has-cell:checked,
html body .service-has-tile-cell:checked { background-color: #3b82f6 !important; border-color: #3b82f6 !important; }

/* Settings has its own component tokens. */
html body .settings-page {
    --settings-border: #e4e7ec;
    --settings-border-strong: #d0d5dd;
    --settings-surface: #ffffff;
    --settings-surface-2: #f8fafc;
    --settings-surface-3: #f2f4f7;
    --settings-text: #172033;
    --settings-muted: #667085;
    --settings-soft: #475467;
}
html body .settings-sidebar-stats div,
html body .settings-pane-header,
html body .settings-related-strip,
html body .settings-chip-row span,
html body .settings-rule-box,
html body .settings-rule-note,
html body .settings-modal-header,
html body .settings-modal-check { background: #f8fafc !important; }
html body .settings-secondary-btn,
html body .settings-link-button,
html body .settings-icon-btn { background: #ffffff !important; color: #344054 !important; }
html body .settings-ghost-btn:hover { background: #eef2f7 !important; }
html body .settings-table th { background: #f2f4f7 !important; }
html body .settings-sticky-save { background: rgba(255, 255, 255, 0.96) !important; box-shadow: 0 12px 30px rgba(16, 24, 40, 0.12) !important; }

/* Search UI is injected by JavaScript, therefore these rules are important. */
html body .service-search-shell,
html body .service-search-results { background: rgba(255, 255, 255, 0.98) !important; border-color: #d8dee9 !important; box-shadow: 0 16px 36px rgba(16, 24, 40, 0.12) !important; }
html body .service-search-input { background: #f8fafc !important; border-color: #d0d5dd !important; color: #172033 !important; }
html body .service-search-input:focus { background: #ffffff !important; }
html body .service-search-title,
html body .service-search-result,
html body .service-search-result-name { color: #172033 !important; }
html body .service-search-result-meta,
html body .service-search-result-status,
html body .service-search-empty { color: #667085 !important; }
html body .service-search-clear:hover { color: #344054 !important; }

/* The plot editor remains visually distinct, but its chrome is light. */
html body .site-layout-summary-card {
    background: linear-gradient(135deg, #ffffff, #f5f7ff) !important;
    border-color: #d8dee9 !important;
    box-shadow: 0 10px 30px rgba(16, 24, 40, 0.08) !important;
}
html body .site-layout-summary-chip { background: #ffffff !important; color: #475467 !important; border-color: #d8dee9 !important; }
html body .site-layout-modal { background: rgba(15, 23, 42, 0.38) !important; }
html body .site-layout-modal-panel,
html body .site-layout-modal-header,
html body .site-layout-sidebar,
html body .site-layout-workspace { background: #f4f7fb !important; color: #172033 !important; }
html body .site-layout-modal-header,
html body .site-layout-workspace,
html body .site-layout-board-toolbar,
html body .site-layout-panel { border-color: #d8dee9 !important; }
html body .site-layout-board-shell { background: #e9eef6 !important; border-color: #cbd5e1 !important; }
html body .site-layout-surface { background-color: #ffffff !important; box-shadow: inset 0 0 0 1px rgba(143, 108, 39, 0.18), 0 18px 48px rgba(16, 24, 40, 0.12) !important; }
html body .site-layout-dimension-chip,
html body .site-layout-ruler-label,
html body .site-layout-measure-label,
html body .site-layout-fence-label { background: #ffffff !important; color: #344054 !important; box-shadow: 0 6px 16px rgba(16, 24, 40, 0.12) !important; }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; }
}
