/* ═══════════════════════════════════════════════
   Dark Mode — CSS Custom Properties
   Matches the new professional flat design.
   Add AFTER styles.css in index.html.
   ═══════════════════════════════════════════════ */

/* ═══ LIGHT THEME (default) ═══ */
:root {
    --bg-body: #e8ecf1;
    --bg-container: #ffffff;
    --bg-section: #fafbfc;
    --bg-hover: #f3f4f6;
    --bg-tabs: #f5f6f8;
    --bg-tab-hover: #ebedf0;
    --bg-tab-active: #ffffff;
    --bg-input: #ffffff;
    --bg-modal-overlay: rgba(0, 0, 0, 0.5);
    --bg-code: #f3f4f6;

    --text-primary: #1f2937;
    --text-secondary: #4b5563;
    --text-muted: #6b7280;
    --text-hint: #9ca3af;
    --text-placeholder: #9ca3af;

    --border-color: #d1d5db;
    --border-light: #e5e7eb;
    --border-section: #e5e7eb;

    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --accent-bg: #eff6ff;
    --accent-border: #bfdbfe;

    --accent-dark: #1e40af;

    --success: #059669;
    --success-bg: #f0fdf4;
    --success-border: #bbf7d0;
    --success-text: #059669;

    --warning: #d97706;
    --warning-bg: #fffbeb;
    --warning-border: #fde68a;
    --warning-text: #92400e;

    --danger: #dc2626;
    --danger-bg: #fef2f2;
    --danger-border: #fecaca;

    --reminder-bg: #fffbeb;
    --reminder-border: #fde68a;
    --reminder-text: #92400e;

    --shadow-card: 0 1px 4px rgba(0, 0, 0, 0.12);
    --shadow-hover: 0 2px 8px rgba(37, 99, 235, 0.15);
    --shadow-light: 0 1px 3px rgba(0, 0, 0, 0.08);

    --table-header-bg: #f3f4f6;
    --table-header-text: #4b5563;
    --table-row-hover: #eff6ff;
    --table-border: #f0f0f0;

    --collapsible-bg: #f0f2f5;
    --collapsible-hover: #e5e7eb;
    --collapsible-text: #1f2937;
    --collapsible-border: #d1d5db;

    --help-bg: #f0f2f5;
    --help-border: #d1d5db;
    --help-hover-bg: #e5e7eb;
    --help-hover-border: #9ca3af;
    --help-active-bg: #e8edf2;
    --help-active-border: #2563eb;
    --help-text: #374151;
    --help-after-color: #9ca3af;
    --help-content-text: #4b5563;

    --cabinet-card-bg: #f8fafc;
    --cabinet-card-border: #e2e8f0;

    --cutlist-bg: #fafbfc;
    --cutlist-border: #d1d5db;

    --toast-bg: #1f2937;
    --toast-text: #ffffff;

    --scrollbar-track: #f3f4f6;
    --scrollbar-thumb: #d1d5db;
    --scrollbar-thumb-hover: #9ca3af;

    --progress-bg: #e5e7eb;
    --progress-inactive: #d1d5db;

    --theme-toggle-bg: rgba(255, 255, 255, 0.15);
    --theme-toggle-hover: rgba(255, 255, 255, 0.25);

    --header-bg: #3b4f6b;
}

/* ═══ DARK THEME ═══ */
[data-theme="dark"] {
    --bg-body: #111827;
    --bg-container: #1f2937;
    --bg-section: #283347;
    --bg-hover: #374151;
    --bg-tabs: #1a2332;
    --bg-tab-hover: #2d3a4d;
    --bg-tab-active: #1f2937;
    --bg-input: #2d3a4d;
    --bg-modal-overlay: rgba(0, 0, 0, 0.7);
    --bg-code: #2d3a4d;

    --text-primary: #e5e7eb;
    --text-secondary: #9ca3af;
    --text-muted: #6b7280;
    --text-hint: #4b5563;
    --text-placeholder: #4b5563;

    --border-color: #374151;
    --border-light: #2d3a4d;
    --border-section: #374151;

    --accent: #60a5fa;
    --accent-hover: #3b82f6;
    --accent-bg: #1e293b;
    --accent-border: #1e3a5f;

    --accent-dark: #93c5fd;

    --success: #34d399;
    --success-bg: #1a2e24;
    --success-border: #264d36;
    --success-text: #34d399;

    --warning: #fbbf24;
    --warning-bg: #2e2a1a;
    --warning-border: #4a4020;
    --warning-text: #fbbf24;

    --danger: #f87171;
    --danger-bg: #2e1a1a;
    --danger-border: #4a2020;

    --reminder-bg: #2e2a1a;
    --reminder-border: #4a4020;
    --reminder-text: #fbbf24;

    --shadow-card: 0 1px 4px rgba(0, 0, 0, 0.4);
    --shadow-hover: 0 2px 8px rgba(96, 165, 250, 0.2);
    --shadow-light: 0 1px 3px rgba(0, 0, 0, 0.3);

    --table-header-bg: #283347;
    --table-header-text: #9ca3af;
    --table-row-hover: #2d3a4d;
    --table-border: #374151;

    --collapsible-bg: #283347;
    --collapsible-hover: #2d3a4d;
    --collapsible-text: #e5e7eb;
    --collapsible-border: #374151;

    --help-bg: #283347;
    --help-border: #374151;
    --help-hover-bg: #2d3a4d;
    --help-hover-border: #4b5563;
    --help-active-bg: #2d3a4d;
    --help-active-border: #60a5fa;
    --help-text: #9ca3af;
    --help-after-color: #4b5563;
    --help-content-text: #9ca3af;

    --cabinet-card-bg: #283347;
    --cabinet-card-border: #374151;

    --cutlist-bg: #283347;
    --cutlist-border: #374151;

    --toast-bg: #e5e7eb;
    --toast-text: #1f2937;

    --scrollbar-track: #1a2332;
    --scrollbar-thumb: #374151;
    --scrollbar-thumb-hover: #4b5563;

    --progress-bg: #2d3a4d;
    --progress-inactive: #374151;

    --theme-toggle-bg: rgba(255, 255, 255, 0.1);
    --theme-toggle-hover: rgba(255, 255, 255, 0.2);

    --header-bg: #1a2332;
}

/* ═══ APPLY VARIABLES ═══ */

body {
    background: var(--bg-body);
}

.container {
    background: var(--bg-container);
    box-shadow: var(--shadow-card);
}

header {
    background: var(--header-bg);
}

/* Tabs */
.tabs {
    background: var(--bg-tabs);
    border-bottom-color: var(--border-color);
}

.tab {
    color: var(--text-muted);
}

.tab:hover {
    background: var(--bg-tab-hover);
    color: var(--text-secondary);
}

.tab.active {
    color: var(--accent);
    background: var(--bg-tab-active);
    border-bottom-color: var(--accent);
}

/* Content */
.tab-content {
    color: var(--text-primary);
}

.section-title {
    color: var(--text-primary);
    border-bottom-color: var(--border-light);
}

.section-description {
    color: var(--text-secondary);
}

/* Forms */
.form-section {
    background: var(--bg-section);
    border-color: var(--border-section);
}

label {
    color: var(--text-secondary);
}

input[type="text"],
input[type="number"],
input[type="email"],
input[type="password"],
select,
textarea {
    background: var(--bg-input);
    color: var(--text-primary);
    border-color: var(--border-color);
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.12);
}

input::placeholder,
textarea::placeholder {
    color: var(--text-placeholder);
}

/* Buttons */
.btn {
    background: var(--header-bg);
}

.btn:hover {
    box-shadow: var(--shadow-hover);
}

.btn-success { background: var(--success); }
.btn-danger { background: var(--danger); }
.btn-warning { background: var(--warning); }
.btn-secondary { background: var(--text-muted); }

/* Tables */
.price-table {
    background: var(--bg-container);
}

.price-table th {
    background: var(--table-header-bg);
    color: var(--table-header-text);
    border-bottom-color: var(--border-color);
}

.price-table td {
    color: var(--text-primary);
    border-bottom-color: var(--table-border);
}

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

.price-table tbody tr:hover {
    background: var(--table-row-hover);
}

.price-table input[type="number"],
.price-table input[type="text"] {
    background: var(--bg-input);
    color: var(--text-primary);
    border-color: var(--border-color);
}

.price-total {
    color: var(--success-text);
}

/* Collapsible */
.collapsible {
    background: var(--collapsible-bg);
    color: var(--collapsible-text);
    border-color: var(--collapsible-border);
}

.collapsible:hover {
    background: var(--collapsible-hover);
}

.collapsible.active {
    background: var(--collapsible-hover);
    border-color: var(--collapsible-border);
}

.collapsible-content {
    background: var(--bg-container);
    border-color: var(--collapsible-border);
}

/* Help & Profile collapsibles */
.help-collapsible,
.profile-collapsible {
    background: var(--help-bg);
    border-color: var(--help-border);
    color: var(--help-text);
}

.help-collapsible::after,
.profile-collapsible::after {
    color: var(--help-after-color);
}

.help-collapsible:hover,
.profile-collapsible:hover {
    background: var(--help-hover-bg);
    border-color: var(--help-hover-border);
}

.help-collapsible.active,
.profile-collapsible.active {
    background: var(--help-active-bg);
    border-color: var(--help-active-border);
}

/* Add-row section */
.add-row-section .btn {
    color: var(--accent);
    border-color: var(--accent-border);
    background: transparent;
}

.add-row-section .btn:hover {
    background: var(--accent-bg);
    border-color: var(--accent);
}

/* Delete row */
.delete-row-btn {
    color: var(--text-hint);
}

.delete-row-btn:hover {
    color: var(--danger);
    background: var(--danger-bg);
}

/* Cabinet preview */
.cabinet-preview-card {
    background: var(--cabinet-card-bg);
    border-color: var(--cabinet-card-border);
}

.cabinet-preview-card:hover {
    border-color: var(--accent);
}

.cabinet-type-name {
    color: var(--accent-dark);
}

.cabinet-description {
    color: var(--text-secondary);
}

/* Cabinet list items */
.cabinet-list-item {
    background: var(--bg-container);
    border-color: var(--border-section);
    border-left-color: var(--accent);
    color: var(--text-primary);
}

.cabinet-list-item:hover {
    background: var(--bg-hover);
}

/* CutList */
.sheet-visualization {
    background: var(--cutlist-bg);
    border-color: var(--cutlist-border);
}

/* Custom door size */
.custom-door-size {
    background: var(--warning-bg);
    border-color: var(--warning);
}

/* Result / Error displays */
.result-display {
    background: var(--success-bg);
    border-left-color: var(--success);
    color: var(--text-primary);
}

.error-display {
    background: var(--danger-bg);
    border-left-color: var(--danger);
    color: var(--text-primary);
}

/* Profile selector */
.profile-selector {
    background: var(--bg-section);
    border-color: var(--border-section);
}

/* Row total */
.row-total {
    color: var(--success-text);
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: var(--scrollbar-track);
}

::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--scrollbar-thumb-hover);
}

/* Spinner */
.spinner {
    border-color: var(--border-color);
    border-top-color: var(--accent);
}

/* ═══ THEME TOGGLE BUTTON ═══ */
.theme-toggle {
    position: absolute;
    top: 50%;
    right: 16px;
    transform: translateY(-50%);
    background: var(--theme-toggle-bg);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 4px;
    padding: 5px 12px;
    font-size: 0.78em;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    color: white;
    white-space: nowrap;
    z-index: 10;
}

.theme-toggle:hover {
    background: var(--theme-toggle-hover);
}

/* ═══ DARK MODE — INLINE STYLE OVERRIDES ═══ */

/* Background overrides */
[data-theme="dark"] [style*="background:#f9fafb"],
[data-theme="dark"] [style*="background: #f9fafb"],
[data-theme="dark"] [style*="background:#f8fafc"],
[data-theme="dark"] [style*="background: #f8fafc"],
[data-theme="dark"] [style*="background:#fafbfc"],
[data-theme="dark"] [style*="background: #fafbfc"] {
    background: var(--bg-section) !important;
}

[data-theme="dark"] [style*="background:#f0f4ff"],
[data-theme="dark"] [style*="background: #f0f4ff"],
[data-theme="dark"] [style*="background:#eff6ff"],
[data-theme="dark"] [style*="background: #eff6ff"] {
    background: var(--accent-bg) !important;
}

[data-theme="dark"] [style*="background:#f0fdf4"],
[data-theme="dark"] [style*="background: #f0fdf4"] {
    background: var(--success-bg) !important;
}

[data-theme="dark"] [style*="background:#fffbeb"],
[data-theme="dark"] [style*="background: #fffbeb"] {
    background: var(--warning-bg) !important;
}

[data-theme="dark"] [style*="background:#fef2f2"],
[data-theme="dark"] [style*="background: #fef2f2"] {
    background: var(--danger-bg) !important;
}

[data-theme="dark"] [style*="background:#f0f0f0"],
[data-theme="dark"] [style*="background: #f0f0f0"],
[data-theme="dark"] [style*="background:#f3f4f6"],
[data-theme="dark"] [style*="background: #f3f4f6"] {
    background: var(--bg-section) !important;
}

[data-theme="dark"] [style*="background:white"],
[data-theme="dark"] [style*="background: white"],
[data-theme="dark"] [style*="background:#fff"],
[data-theme="dark"] [style*="background: #fff"] {
    background: var(--bg-container) !important;
}

[data-theme="dark"] [style*="background:#3b4f6b"] {
    background: var(--header-bg) !important;
}

/* Text color overrides */
[data-theme="dark"] [style*="color:#1f2937"],
[data-theme="dark"] [style*="color: #1f2937"],
[data-theme="dark"] [style*="color:#374151"],
[data-theme="dark"] [style*="color: #374151"] {
    color: var(--text-primary) !important;
}

[data-theme="dark"] [style*="color:#4b5563"],
[data-theme="dark"] [style*="color: #4b5563"] {
    color: var(--text-secondary) !important;
}

[data-theme="dark"] [style*="color:#6b7280"],
[data-theme="dark"] [style*="color: #6b7280"] {
    color: var(--text-muted) !important;
}

[data-theme="dark"] [style*="color:#9ca3af"],
[data-theme="dark"] [style*="color: #9ca3af"] {
    color: var(--text-hint) !important;
}

[data-theme="dark"] [style*="color:#1e40af"],
[data-theme="dark"] [style*="color: #1e40af"] {
    color: var(--accent-dark) !important;
}

[data-theme="dark"] [style*="color:#2563eb"],
[data-theme="dark"] [style*="color: #2563eb"] {
    color: var(--accent) !important;
}

[data-theme="dark"] [style*="color:#059669"],
[data-theme="dark"] [style*="color: #059669"] {
    color: var(--success-text) !important;
}

[data-theme="dark"] [style*="color:#d97706"],
[data-theme="dark"] [style*="color: #d97706"],
[data-theme="dark"] [style*="color:#92400e"],
[data-theme="dark"] [style*="color: #92400e"] {
    color: var(--warning-text) !important;
}

/* Legacy color overrides (for any remaining old inline styles) */
[data-theme="dark"] [style*="color:#333"],
[data-theme="dark"] [style*="color: #333"] {
    color: var(--text-primary) !important;
}

[data-theme="dark"] [style*="color:#555"],
[data-theme="dark"] [style*="color: #555"] {
    color: var(--text-secondary) !important;
}

[data-theme="dark"] [style*="color:#888"],
[data-theme="dark"] [style*="color: #888"] {
    color: var(--text-muted) !important;
}

[data-theme="dark"] [style*="color:#999"],
[data-theme="dark"] [style*="color: #999"] {
    color: var(--text-hint) !important;
}

/* Border overrides */
[data-theme="dark"] [style*="border:1px solid #e2e8f0"],
[data-theme="dark"] [style*="border: 1px solid #e2e8f0"],
[data-theme="dark"] [style*="border:1px solid #e5e7eb"],
[data-theme="dark"] [style*="border: 1px solid #e5e7eb"] {
    border-color: var(--border-section) !important;
}

[data-theme="dark"] [style*="border:1px solid #bbf7d0"],
[data-theme="dark"] [style*="border: 1px solid #bbf7d0"] {
    border-color: var(--success-border) !important;
}

[data-theme="dark"] [style*="border:1px solid #fde68a"],
[data-theme="dark"] [style*="border: 1px solid #fde68a"] {
    border-color: var(--warning-border) !important;
}

[data-theme="dark"] [style*="border:1px solid #fecaca"],
[data-theme="dark"] [style*="border: 1px solid #fecaca"] {
    border-color: var(--danger-border) !important;
}

[data-theme="dark"] [style*="border:1px solid #bfdbfe"],
[data-theme="dark"] [style*="border: 1px solid #bfdbfe"] {
    border-color: var(--accent-border) !important;
}

[data-theme="dark"] [style*="border:1px solid #d1d5db"],
[data-theme="dark"] [style*="border: 1px solid #d1d5db"],
[data-theme="dark"] [style*="border:1px solid #f3f4f6"],
[data-theme="dark"] [style*="border: 1px solid #f3f4f6"] {
    border-color: var(--border-color) !important;
}

[data-theme="dark"] [style*="border:2px solid #e0e0e0"],
[data-theme="dark"] [style*="border-top:2px dashed #e0e0e0"] {
    border-color: var(--border-section) !important;
}

/* Border-top for reminders */
[data-theme="dark"] [style*="border-top:1px solid rgba(255,249,196"] {
    border-top-color: var(--warning-border) !important;
}

/* Auth bar */
[data-theme="dark"] #authBar {
    background: var(--bg-section) !important;
}

/* Modal overrides */
[data-theme="dark"] [style*="background:rgba(0,0,0,0.5)"],
[data-theme="dark"] [style*="background: rgba(0,0,0,0.5)"] {
    background: var(--bg-modal-overlay) !important;
}

[data-theme="dark"] [style*="max-width:500px"][style*="background:white"],
[data-theme="dark"] [style*="max-width:500px"][style*="background: white"],
[data-theme="dark"] [style*="max-width: 500px"][style*="background:white"],
[data-theme="dark"] [style*="max-width: 500px"][style*="background: white"],
[data-theme="dark"] [style*="max-width:550px"][style*="background:white"],
[data-theme="dark"] [style*="max-width:550px"][style*="background: white"] {
    background: var(--bg-container) !important;
}

/* 3D container */
[data-theme="dark"] #cabinet3dContainer {
    border-color: var(--border-color) !important;
    background: var(--bg-section) !important;
}

/* Select option for dark bg */
[data-theme="dark"] option {
    background: var(--bg-input);
    color: var(--text-primary);
}

/* ═══ TRANSITIONS ═══ */
body,
.container,
header,
.tabs,
.tab,
.tab-content,
.form-section,
.collapsible,
.collapsible-content,
.help-collapsible,
.profile-collapsible,
.cabinet-preview-card,
.cabinet-list-item,
.price-table,
.price-table th,
.price-table td,
.sheet-visualization,
.help-video-placeholder,
input,
select,
textarea {
    transition: background 0.25s ease, color 0.25s ease, border-color 0.25s ease;
}

/* ═══ TABS VISIBILITY ON DASHBOARD ═══ */
.tabs.tabs-hidden {
    display: none !important;
}
