html[data-theme="light"],
html:not([data-theme]) {
    --color-primary:#1e3a8a;
    --color-primary-soft:#1a3278;
    --surface: #ffffff;
    --surface-soft: #f8fafc;
    --surface-muted: #eef2f7;
    --border-soft: #dbe3ef;
    --text-main: #0f172a;
    --text-muted: #475569;
    --premium-gradient: linear-gradient(135deg, #1a3278, #1e3a8a);
    --premium-navy-gradient: linear-gradient(180deg, #0f1d46 0%, #15285f 100%);
}

html[data-theme="dark"] {
    --surface: #111827;
    --surface-soft: #0b1220;
    --surface-muted: #1f2937;
    --border-soft: #334155;
    --text-main: #f8fafc;
    --text-muted: #cbd5e1;
    --color-primary: #93a6f0;
    --color-primary-soft: #c7d2fe;
    --color-success: #34d399;
    --color-success-soft: #064e3b;
    --color-warning: #fb923c;
    --color-warning-soft: #7c2d12;
    --color-danger: #f87171;
    --color-danger-soft: #7f1d1d;
    --color-info: #7dd3fc;
    --color-info-soft: #0c4a6e;
    --focus-ring: #93a6f0;
    --premium-gradient: linear-gradient(135deg, #1e3a8a, #2f4cb0);
    --premium-navy-gradient: linear-gradient(180deg, #07111f 0%, #0f1d46 100%);
    --shadow-card: 0 12px 32px rgba(0, 0, 0, 0.35);
}

html[data-theme="high_contrast"] {
    --surface: #ffffff;
    --surface-soft: #ffffff;
    --surface-muted: #f1f5f9;
    --border-soft: #0f172a;
    --text-main: #000000;
    --text-muted: #111827;
    --color-primary: #1e3a8a;
    --color-primary-soft: #1e3a8a;
    --color-success: #14532d;
    --color-warning: #9a3412;
    --color-danger: #7f1d1d;
    --color-info: #0c4a6e;
    --focus-ring: #000000;
    --premium-gradient: linear-gradient(135deg, #0f1d46, #1e3a8a);
    --premium-navy-gradient: #0f1d46;
    --shadow-card: 0 0 0 2px #0f172a;
}

html[data-theme="odoo"] {
    --surface: #ffffff;
    --surface-soft: #f8f1f5;
    --surface-muted: #efe2ea;
    --border-soft: #d9c3d0;
    --text-main: #3b2233;
    --text-muted: #6b4f61;
    --color-primary: #714b67;
    --color-primary-soft: #875a7b;
    --focus-ring: #714b67;
    --premium-gradient: linear-gradient(135deg, #5c3b54, #875a7b);
    --premium-navy-gradient: linear-gradient(180deg, #3d2740 0%, #714b67 100%);
}

html[data-theme="sap_fiori"] {
    --surface: #ffffff;
    --surface-soft: #f5f9fc;
    --surface-muted: #e5eef6;
    --border-soft: #c9d8e6;
    --text-main: #1a2733;
    --text-muted: #4a6073;
    --color-primary: #0a6ed1;
    --color-primary-soft: #0854a0;
    --focus-ring: #0a6ed1;
    --premium-gradient: linear-gradient(135deg, #0854a0, #0a6ed1);
    --premium-navy-gradient: linear-gradient(180deg, #0a2540 0%, #0a4d8c 100%);
}

html[data-theme="oracle"] {
    --surface: #ffffff;
    --surface-soft: #f7f4f1;
    --surface-muted: #ece4dc;
    --border-soft: #d8cdc2;
    --text-main: #2b2622;
    --text-muted: #6b6158;
    --color-primary: #c74634;
    --color-primary-soft: #a33a2b;
    --focus-ring: #c74634;
    --premium-gradient: linear-gradient(135deg, #8f3326, #c74634);
    --premium-navy-gradient: linear-gradient(180deg, #3a3632 0%, #6b2a22 100%);
}

html[data-theme="sage"] {
    --surface: #ffffff;
    --surface-soft: #f3faf5;
    --surface-muted: #dcefe3;
    --border-soft: #b9d8c4;
    --text-main: #12301c;
    --text-muted: #3f6a4d;
    --color-primary: #007a33;
    --color-primary-soft: #009640;
    --focus-ring: #007a33;
    --premium-gradient: linear-gradient(135deg, #005c26, #007a33);
    --premium-navy-gradient: linear-gradient(180deg, #0d2a18 0%, #14532d 100%);
}

html[data-theme="zoho"] {
    --surface: #ffffff;
    --surface-soft: #fff7f6;
    --surface-muted: #fde8e7;
    --border-soft: #f3c5c4;
    --text-main: #1f1616;
    --text-muted: #6b4b4b;
    --color-primary: #e42527;
    --color-primary-soft: #c01d20;
    --focus-ring: #e42527;
    --premium-gradient: linear-gradient(135deg, #b81b1d, #e42527);
    --premium-navy-gradient: linear-gradient(180deg, #1a1f2c 0%, #8f1d22 100%);
}

html[data-theme="emerald"] {
    --surface: #ffffff;
    --surface-soft: #f0fdf6;
    --surface-muted: #d1fae5;
    --border-soft: #a7f3d0;
    --text-main: #064e3b;
    --text-muted: #047857;
    --color-primary: #047857;
    --color-primary-soft: #059669;
    --focus-ring: #047857;
    --premium-gradient: linear-gradient(135deg, #065f46, #10b981);
    --premium-navy-gradient: linear-gradient(180deg, #022c22 0%, #065f46 100%);
}

html[data-theme="graphite"] {
    --surface: #ffffff;
    --surface-soft: #f4f5f7;
    --surface-muted: #e5e7eb;
    --border-soft: #d1d5db;
    --text-main: #111827;
    --text-muted: #4b5563;
    --color-primary: #374151;
    --color-primary-soft: #4b5563;
    --focus-ring: #111827;
    --premium-gradient: linear-gradient(135deg, #1f2937, #4b5563);
    --premium-navy-gradient: linear-gradient(180deg, #111827 0%, #374151 100%);
}

html[data-theme="copper"] {
    --surface: #ffffff;
    --surface-soft: #fdf6ef;
    --surface-muted: #f3e0c8;
    --border-soft: #e7c9a3;
    --text-main: #3f2a12;
    --text-muted: #7c4a1a;
    --color-primary: #b45309;
    --color-primary-soft: #c2410c;
    --focus-ring: #b45309;
    --premium-gradient: linear-gradient(135deg, #9a3412, #d97706);
    --premium-navy-gradient: linear-gradient(180deg, #431407 0%, #7c2d12 100%);
}

html[data-theme="indigo"] {
    --surface: #ffffff;
    --surface-soft: #f5f4ff;
    --surface-muted: #e0e7ff;
    --border-soft: #c7d2fe;
    --text-main: #1e1b4b;
    --text-muted: #4338ca;
    --color-primary: #4338ca;
    --color-primary-soft: #4f46e5;
    --focus-ring: #4338ca;
    --premium-gradient: linear-gradient(135deg, #312e81, #6366f1);
    --premium-navy-gradient: linear-gradient(180deg, #1e1b4b 0%, #3730a3 100%);
}

html[data-theme="forest"] {
    --surface: #ffffff;
    --surface-soft: #f3faf3;
    --surface-muted: #dcfce7;
    --border-soft: #bbf7d0;
    --text-main: #14532d;
    --text-muted: #3f6b4b;
    --color-primary: #166534;
    --color-primary-soft: #15803d;
    --focus-ring: #166534;
    --premium-gradient: linear-gradient(135deg, #14532d, #22c55e);
    --premium-navy-gradient: linear-gradient(180deg, #052e16 0%, #166534 100%);
}

html[data-theme="burgundy"] {
    --surface: #ffffff;
    --surface-soft: #fdf4f6;
    --surface-muted: #fce7ec;
    --border-soft: #f5c2ce;
    --text-main: #4c0519;
    --text-muted: #9f1239;
    --color-primary: #9f1239;
    --color-primary-soft: #be123c;
    --focus-ring: #9f1239;
    --premium-gradient: linear-gradient(135deg, #881337, #e11d48);
    --premium-navy-gradient: linear-gradient(180deg, #4c0519 0%, #9f1239 100%);
}

html[data-theme="sand"] {
    --surface: #fffdf8;
    --surface-soft: #faf6ee;
    --surface-muted: #f0e6d2;
    --border-soft: #e4d3b0;
    --text-main: #3f2e12;
    --text-muted: #7c5c20;
    --color-primary: #a16207;
    --color-primary-soft: #ca8a04;
    --focus-ring: #a16207;
    --premium-gradient: linear-gradient(135deg, #854d0e, #ca8a04);
    --premium-navy-gradient: linear-gradient(180deg, #422006 0%, #854d0e 100%);
}


/* Carwash mapping of the full Cooperative palette. Print keeps its stationery. */
@media screen {
    html[data-theme] {
        --cw-primary:var(--color-primary);
        --cw-primary-strong:var(--color-primary-soft);
        --cw-dark:var(--text-main);
        --cw-ink:var(--text-main);
        --cw-muted:var(--text-muted);
        --cw-line:var(--border-soft);
        --cw-line-soft:var(--surface-muted);
        --cw-bg:var(--surface-soft);
        --cw-surface:var(--surface);
        --cw-surface-soft:var(--surface-soft);
        --cw-on-primary:#fff;
        color-scheme:light;
    }
    html[data-theme="dark"] { color-scheme:dark; --cw-on-primary:#0b1220; }
    html[data-theme] body, html[data-theme] body.report-page { background:var(--surface-soft) !important; color:var(--text-main) !important; }
    html[data-theme] body .sidebar { background:var(--premium-navy-gradient) !important; scrollbar-width:thin; scrollbar-color:#64748b transparent; }
    html[data-theme] body :is(.topbar,.card,.data-card,.form-card,.card-custom,.card-table,.form-section,.dashboard-filter,.filter-bar,.print-document,.dashboard-card,.dashboard-kpi,.metric-card,.report-sheet,.login-card,.dropdown-menu,.modal-content,.permission-block) { background:var(--surface) !important; border-color:var(--border-soft) !important; color:var(--text-main) !important; }
    html[data-theme] body :is(.card-header,.print-info-box,.report-actions,.bg-light,.boutique-nav,.sale-line) { background:var(--surface-muted) !important; border-color:var(--border-soft) !important; color:var(--text-main) !important; }
    html[data-theme] body .bg-white { background:var(--surface) !important; }
    html[data-theme] body :is(.form-control,.form-select,.page-link) { background-color:var(--surface) !important; border-color:var(--border-soft) !important; color:var(--text-main) !important; }
    html[data-theme] body :is(.form-control,.form-select):focus { border-color:var(--color-primary) !important; box-shadow:0 0 0 3px color-mix(in srgb,var(--color-primary) 20%,transparent) !important; }
    html[data-theme] body :is(.text-muted,.form-text,.dashboard-section-title,.page-head p,.report-contact,.report-document-title small,.report-meta span) { color:var(--text-muted) !important; }
    html[data-theme] body :is(.text-dark,.text-black,.page-head h4,.print-company,.print-title,.report-company,.report-meta strong,.report-document-title strong,.report-section-title,.metric-card strong,.dashboard-kpi strong) { color:var(--text-main) !important; }
    html[data-theme] body :is(label,.form-label) { color:var(--text-muted) !important; }
    html[data-theme] body :is(.btn-primary,.btn-info,.btn-login) { background:var(--color-primary) !important; border-color:var(--color-primary) !important; color:var(--cw-on-primary) !important; }
    html[data-theme] body :is(.btn-primary,.btn-info,.btn-login):hover { filter:brightness(.92); }
    html[data-theme] body .btn-light { background:var(--surface-soft) !important; color:var(--text-main) !important; border-color:var(--border-soft) !important; }
    html[data-theme] body :is(.btn-outline-primary,.btn-outline-info) { background:transparent; color:var(--color-primary); border-color:var(--color-primary); }
    html[data-theme] body :is(.btn-outline-dark,.btn-outline-secondary) { color:var(--text-main); border-color:var(--border-soft); }
    html[data-theme] body :is(.btn-outline-primary,.btn-outline-info):hover { background:var(--color-primary); color:var(--cw-on-primary); }
    html[data-theme] body .table { --bs-table-bg:var(--surface); --bs-table-color:var(--text-main); --bs-table-striped-color:var(--text-main); --bs-table-hover-color:var(--text-main); --bs-table-striped-bg:var(--surface-soft); --bs-table-hover-bg:var(--surface-muted); border-color:var(--border-soft) !important; }
    html[data-theme] body .table thead th { background:var(--surface-muted) !important; color:var(--text-main) !important; border-color:var(--border-soft) !important; }
    html[data-theme] body .table tbody td { color:var(--text-main) !important; border-color:var(--border-soft) !important; }
    html[data-theme] body .table tfoot :is(td,th) { background:var(--surface-muted) !important; color:var(--text-main) !important; border-color:var(--color-primary) !important; }
    html[data-theme] body .dashboard-hero, html[data-theme] .login-shell .brand-panel { background:var(--premium-gradient) !important; }
    html[data-theme] body .dashboard-hero::before { background:var(--color-primary-soft); }
    html[data-theme] body .sidebar .submenu a.active { background:var(--premium-gradient); color:#fff; }
    html[data-theme] body :is(.metric-card,.dashboard-kpi) { border-top-color:var(--color-primary) !important; }
    html[data-theme] body :is(.tone-blue,.tone-green) { background:var(--surface-muted); color:var(--color-primary); }
    html[data-theme] body :is(.report-slogan,.report-document-title span) { color:var(--color-primary); }
    html[data-theme] body .report-topbar { background:var(--premium-gradient); }
    html[data-theme] body .report-title-band { color:var(--text-muted); border-color:var(--border-soft); }
    html[data-theme] body .report-sheet .table tbody tr:nth-child(even) td { background:var(--surface-soft) !important; }
    html[data-theme] body .report-footer { color:var(--text-muted) !important; border-color:var(--border-soft); }
    html[data-theme] body .boutique-nav a { color:var(--text-muted); }
    html[data-theme] body .boutique-nav a.active { background:var(--color-primary); color:var(--cw-on-primary); }
    html[data-theme] body .boutique-content .table a:not(.btn):not(.cw-action-item) { color:var(--color-primary); }
    html[data-theme] body .boutique-content { --b-accent:var(--color-primary); --b-line:var(--border-soft); }
    html[data-theme] body .pagination .active .page-link { background:var(--color-primary) !important; color:var(--cw-on-primary) !important; }
    html[data-theme="dark"] body .btn-dark { background:#334155; color:#fff; border-color:#475569; }
    html[data-theme="dark"] body :is(.table-success,.table-warning,.table-danger,.table-info) { --bs-table-bg:var(--surface-muted); --bs-table-color:var(--text-main); }
    html[data-theme="high_contrast"] body :is(.card,.topbar,.form-control,.form-select,.cw-actions-toggle) { border-width:2px !important; }
    html[data-theme] .cw-nav-icon { width:18px; height:18px; flex:0 0 18px; }
    html[data-theme] .sidebar .menu-header { justify-content:flex-start; gap:11px; }
    html[data-theme] .sidebar .menu-header::after { margin-left:auto; }
    .cw-theme-picker { display:flex; align-items:center; gap:8px; min-width:0; }
    .cw-theme-picker label { margin:0; white-space:nowrap; font-size:12px !important; }
    .cw-theme-picker select { width:148px; min-height:36px !important; font-size:12px !important; }
    .cw-theme-floating { position:absolute; right:20px; top:20px; z-index:10; padding:8px 12px; background:var(--surface); border:1px solid var(--border-soft); border-radius:10px; }
    .cw-actions-cell { white-space:nowrap !important; width:1%; overflow:visible; }
    body .cw-actions-toggle { display:inline-flex; align-items:center; gap:9px; background:var(--surface-soft,#f8fafc); color:var(--text-main,#142d4e); border:1px solid var(--border-soft,#dce4ee); border-radius:7px; padding:7px 11px; min-height:34px; font:600 12px/1.4 Inter,'Segoe UI',sans-serif; cursor:pointer; }
    body .cw-actions-toggle:hover, body .cw-actions-toggle[aria-expanded="true"] { background:var(--surface-muted,#e5eef6); border-color:var(--color-primary,#087f8c); }
    body .cw-actions-panel { position:fixed; z-index:1100; width:225px; max-width:calc(100vw - 16px); padding:7px; background:var(--surface,#fff); border:1px solid var(--border-soft,#dce4ee); border-radius:11px; box-shadow:0 12px 40px rgba(0,0,0,.18); overflow-y:auto; text-align:left; }
    body .cw-actions-panel[hidden] { display:none !important; }
    body .cw-actions-panel :is(form,.sales-actions,.history-actions,.d-flex) { display:block !important; margin:0 !important; padding:0 !important; }
    body .cw-actions-panel .cw-action-item { display:flex !important; align-items:center; gap:11px; width:100%; min-height:38px; margin:0; padding:9px 11px !important; border:0 !important; border-radius:6px !important; background:transparent !important; box-shadow:none !important; color:var(--text-main,#20334b) !important; text-align:left; text-decoration:none; font:500 13px/1.4 Inter,'Segoe UI',sans-serif !important; white-space:normal; cursor:pointer; }
    body .cw-actions-panel .cw-action-item:hover, body .cw-actions-panel .cw-action-item:focus-visible { background:var(--surface-muted,#eef2f7) !important; }
    body .cw-actions-panel .cw-action-danger { color:#b42318 !important; }
    html[data-theme="dark"] body .cw-actions-panel .cw-action-danger { color:#fda4a4 !important; }
    .cw-action-icon { width:17px; height:17px; flex-shrink:0; }
    .cw-actions-toggle svg { width:15px; height:15px; }
    @media(max-width:1100px) { body .topbar { flex-wrap:wrap; } }
    @media(max-width:768px) {
        .cw-theme-picker { order:4; width:100%; }
        .cw-theme-picker select { flex:1; width:auto; }
        .cw-theme-floating { position:static; width:calc(100% - 24px); margin:12px; }
        body:has(.login-shell) .login-shell { min-height:calc(100vh - 72px); }
    }
}
@media print { .cw-theme-picker, .cw-actions-toggle, .cw-actions-panel { display:none !important; } }
@media screen {
    body .cw-actions-panel :is(.client-actions,.branch-actions-main,.branch-actions-danger) { display:block !important; margin:0 !important; padding:0 !important; border:0 !important; }
    html[data-theme] body :is(.branch-card,.entete-card,.entete-box,.permission-block) { background:var(--surface) !important; border-color:var(--border-soft) !important; color:var(--text-main) !important; }
    html[data-theme] body :is(.branch-header,.branch-body,.branch-actions) { background:var(--surface) !important; border-color:var(--border-soft) !important; }
    html[data-theme] body :is(.branch-name,.branch-value,.entete-name,.entete-title) { color:var(--text-main) !important; }
    html[data-theme] body :is(.branch-label,.branch-sub,.entete-sub) { color:var(--text-muted) !important; }
    html[data-theme] body .clients-table :is(th,td).actions-col { width:115px; }
    html[data-theme="dark"] .login-shell :is(h2,.subtitle,.login-footer) { color:var(--text-main); }
}
@media screen {
    html[data-theme] body :is(.dashboard-card .fw-bold,.dashboard-kpi span,.dashboard-kpi small,.metric-card span,.login-footer strong) { color:var(--text-main) !important; }
    html[data-theme] body :is(input,textarea)::placeholder { color:var(--text-muted) !important; opacity:1; }
    @media(max-width:768px) {
        html[data-theme] body .main { margin-left:0 !important; }
        html[data-theme] body .sidebar { left:-290px; width:min(86vw,290px); }
        html[data-theme] body .sidebar.active { left:0; }
        html[data-theme] body .sidebar-hidden .sidebar { margin-left:0; }
    }
}
@media screen {
    html[data-theme] .login-shell .login-foot { color:var(--text-muted) !important; border-color:var(--border-soft); }
    html[data-theme] .login-shell .login-foot strong { color:var(--text-main) !important; }
}
