/*
 * OptiTask Design Tokens — Spec 013
 * Source unique des custom properties (--ot-*). Les autres feuilles référencent var(--ot-*).
 * Commentaires FR — noms de variables en anglais.
 */

:root {
    /* ─── Couleurs primaires / neutres ─── */
    --ot-color-primary: #3b82f6;
    --ot-color-primary-hover: color-mix(in srgb, var(--ot-color-primary) 88%, #000 12%);
    --ot-color-primary-soft: color-mix(in srgb, var(--ot-color-primary) 18%, #ffffff 82%);
    --ot-color-primary-muted: color-mix(in srgb, var(--ot-color-primary) 35%, #ffffff 65%);

    --ot-color-on-primary: #ffffff;

    /* Texte — hiérarchie lisible en clair (spec 014 US2, WCAG AA ≥ 4.5:1 sur surfaces courantes) */
    --ot-color-text-primary: #111827;
    --ot-color-text-secondary: #374151;
    --ot-color-text-muted: #4b5563;

    --ot-color-surface: #ffffff;
    --ot-color-surface-alt: #f7fafc;
    --ot-color-surface-muted: #f9fafb;
    /* Lignes de tableau alternées (spec 013 US3) — proche surface-muted */
    --ot-color-surface-alt-soft: #f9fafb;
    --ot-color-surface-hover: #f3f4f6;
    /* Alias neutre (équivalent gray-50, hover léger) */
    --ot-color-neutral-50: #f9fafb;

    --ot-color-border: #d1d5db;
    --ot-color-border-strong: #9ca3af;

    /* Sémantique */
    --ot-color-success: #10b981;
    --ot-color-on-success: #ffffff;
    --ot-color-danger: #ef4444;
    --ot-color-on-danger: #ffffff;
    --ot-color-warning: #f59e0b;
    --ot-color-on-warning: #1a202c;
    --ot-color-info: #3b82f6;
    --ot-color-on-info: #ffffff;

    /* ─── Typographie ─── */
    --ot-font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --ot-font-family-mono: ui-monospace, SFMono-Regular, "Segoe UI Mono", "Cascadia Mono", Menlo, Consolas, monospace;
    --ot-font-size-xs: 0.75rem;
    --ot-font-size-sm: 0.8125rem;
    --ot-font-size-base: 0.875rem;
    --ot-font-size-md: 1rem;
    --ot-font-size-lg: 1.125rem;
    --ot-font-size-xl: 1.25rem;
    --ot-font-size-2xl: 1.5rem;
    --ot-font-size-3xl: 1.75rem;

    --ot-font-weight-400: 400;
    --ot-font-weight-500: 500;
    --ot-font-weight-600: 600;
    --ot-font-weight-700: 700;

    --ot-line-height-tight: 1.2;
    --ot-line-height-base: 1.5;
    --ot-line-height-relaxed: 1.625;

    /* ─── Espacement (échelle 8 px) ─── */
    --ot-space-xs: 4px;
    --ot-space-sm: 8px;
    --ot-space-md: 12px;
    --ot-space-lg: 16px;
    --ot-space-xl: 24px;
    --ot-space-2xl: 32px;
    --ot-space-3xl: 48px;

    /* ─── Rayons ─── */
    --ot-radius-sm: 4px;
    --ot-radius-md: 6px;
    --ot-radius-lg: 8px;
    --ot-radius-full: 999px;

    /* ─── Ombres ─── */
    --ot-shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
    --ot-shadow-md: 0 4px 6px -1px rgba(15, 23, 42, 0.08), 0 2px 4px -2px rgba(15, 23, 42, 0.06);
    --ot-shadow-lg: 0 10px 15px -3px rgba(15, 23, 42, 0.1), 0 4px 6px -4px rgba(15, 23, 42, 0.08);

    /* ─── Transitions ─── */
    --ot-transition-fast: 150ms ease;
    --ot-transition-base: 200ms ease;
    --ot-transition-slow: 300ms ease;

    /* ─── Z-index (empilement) ─── */
    --ot-z-sidebar: 100;
    --ot-z-sidebar-overlay: 99;
    --ot-z-header: 50;
    --ot-z-dropdown: 200;
    --ot-z-modal: 500;
    --ot-z-toast: 600;

    /* ─── Palette étendue (Phase 6 — composants legacy, tables, modales, organigramme) ─── */
    --ot-color-emerald-600: #059669;
    --ot-color-green-800: #166534;
    --ot-color-green-600: #16a34a;
    --ot-color-brand-legacy-blue: #1b6ec2;
    --ot-color-blue-700: #1d4ed8;
    --ot-color-slate-900: #1e293b;
    --ot-color-gray-900: #111827;
    --ot-color-gray-800: #1f2937;
    --ot-color-green-500: #22c55e;
    --ot-color-blue-600: #2563eb;
    --ot-color-gray-700: #374151;
    --ot-color-purple-deep: #3a0647;
    --ot-color-indigo-600: #4f46e5;
    --ot-color-indigo-500: #6366f1;
    --ot-color-violet-500: #a855f7;
    --ot-color-gray-mid: #666666;
    --ot-color-gray-500: #6b7280;
    --ot-color-green-300: #86efac;
    --ot-color-amber-900: #92400e;
    --ot-color-blue-300: #93c5fd;
    --ot-color-slate-400: #94a3b8;
    --ot-color-red-800: #991b1b;
    --ot-color-gray-400: #9ca3af;
    --ot-color-amber-700: #b45309;
    --ot-color-red-700: #b91c1c;
    --ot-color-green-200: #bbf7d0;
    --ot-color-blue-200: #bfdbfe;
    --ot-color-green-100: #d1fae5;
    --ot-color-amber-600: #d97706;
    --ot-color-blue-100: #dbeafe;
    --ot-color-red-600: #dc2626;
    --ot-color-neutral-300: #e0e0e0;
    --ot-color-indigo-100: #e0e7ff;
    --ot-color-slate-200: #e2e8f0;
    --ot-color-orange-600: #ea580c;
    --ot-color-gray-eee: #eeeeee;
    --ot-color-surface-tint: #eef2f7;
    --ot-color-indigo-50: #eef2ff;
    --ot-color-blue-50: #eff6ff;
    --ot-color-sky-50: #f0f9ff;
    --ot-color-green-50: #f0fdf4;
    --ot-color-slate-100: #f1f5f9;
    --ot-color-zinc-50: #fafafa;
    --ot-color-slate-50: #f8fafc;
    --ot-color-red-200: #fecaca;
    --ot-color-red-100: #fee2e2;
    --ot-color-red-50: #fef2f2;
    --ot-color-amber-100: #fef3c7;

    /* Rayons XL (modales, surfaces) */
    --ot-radius-xl: 12px;
    --ot-radius-2xl: 16px;

    /* Ombre modale large */
    --ot-shadow-modal: 0 25px 50px -12px rgba(0, 0, 0, 0.25);

    /* Hauteurs modale (footer/header) */
    --ot-modal-header-min-height: 56px;
    --ot-modal-footer-min-height: 64px;

    /* En-tête / logo / fil d’Ariane (Phase 6) */
    --ot-color-top-row-bg: #f7f7f7;
    --ot-color-top-row-border: #d6d5d5;
    --ot-color-logo-halo-start: #e8f1fc;
    --ot-color-logo-halo-border: #cfe0f5;
    --ot-color-breadcrumb-link-hover: #111111;

    /* Sidebar — thème navy (spec 017 — sync header sombre) */
    --ot-sidebar-bg-start:       #1e3a5f;
    --ot-sidebar-bg-end:         #0f2b5b;
    --ot-sidebar-gradient-end:   #0f2b5b;   /* alias legacy sidebar.css */
    --ot-sidebar-border-soft:    #334155;
    --ot-sidebar-text-pack:      #e2e8f0;
    --ot-sidebar-text-navy:      #f1f5f9;
    --ot-sidebar-hover-pack:     rgba(96, 165, 250, 0.12);
    --ot-sidebar-active-bg-pack: rgba(96, 165, 250, 0.22);
    --ot-brand-pack-blue:        #3b88ec;
    --ot-brand-pack-orange:      #f7953e;
    --ot-color-slate-300:        #94a3b8;
    --ot-sidebar-icon-gradient-low: #1e3a5f;

    /* ─── Spec 016 — Header sombre permanent (FR-001..FR-007) ─── */
    /*
     * Tokens dédiés indépendants de --ot-color-primary et de WorkspaceBrandingState (FR-051).
     * Valeurs sombres par défaut en mode clair ET en mode sombre — le header est sombre
     * quel que soit le thème utilisateur (cf. spec.md Edge Cases — décision F12).
     */
    --ot-color-header-bg-start: #1e293b;
    --ot-color-header-bg-end: #0f172a;
    --ot-color-header-fg: #f1f5f9;
    --ot-color-header-fg-muted: #cbd5e1;
    --ot-color-header-border: #334155;
    /* Pastille logo (header + sidebar) : gris moyen-clair fixe — contraste avec le blanc interne du PNG (cf. Spec 016). */
    --ot-logo-chip-bg: #cbd5e1;
    --ot-logo-chip-border: #64748b;

    /* ─── Spec 016 — Sidebar collapsible (FR-010..FR-016) ─── */
    --ot-sidebar-width-expanded: 16rem;
    --ot-sidebar-width-collapsed: 4.5rem;
    --ot-sidebar-item-min-height: 2.75rem; /* 44 px — cible tactile WCAG */
    /* Menu : 32 px — plus de pixels affichés = PNG pack plus nets (même logique que le logo marque). */
    --ot-sidebar-icon-size: 2rem;

    /* ─── Spec 016 — Hiérarchie boutons (FR-020..FR-025) ─── */
    --ot-button-min-height: 2.25rem;       /* 36 px — cible souris/clavier desktop */
    --ot-button-min-height-touch: 2.75rem; /* 44 px — cible tactile WCAG mobile */
    --ot-button-focus-ring-width: 0.125rem; /* 2 px — anneau focus visible */
    --ot-button-focus-ring-offset: 0.125rem;
}

/*
 * Thème sombre — spec 014 US3 (FR-041). Appliqué sur <html data-theme="dark">.
 * Toutes les --ot-color-* redéfinies pour éviter les « îlots » clairs.
 */
[data-theme="dark"] {
    color-scheme: dark;

    --ot-color-primary: #60a5fa;
    --ot-color-primary-hover: color-mix(in srgb, var(--ot-color-primary) 88%, #000 12%);
    --ot-color-primary-soft: color-mix(in srgb, var(--ot-color-primary) 22%, #1e293b 78%);
    --ot-color-primary-muted: color-mix(in srgb, var(--ot-color-primary) 42%, #334155 58%);
    --ot-color-on-primary: #0f172a;

    --ot-color-text-primary: #f1f5f9;
    --ot-color-text-secondary: #cbd5e1;
    --ot-color-text-muted: #94a3b8;

    --ot-color-surface: #0f172a;
    --ot-color-surface-alt: #1e293b;
    --ot-color-surface-muted: #334155;
    --ot-color-surface-alt-soft: #1e293b;
    --ot-color-surface-hover: #475569;
    --ot-color-neutral-50: #1e293b;

    --ot-color-border: #475569;
    --ot-color-border-strong: #64748b;

    --ot-color-success: #34d399;
    --ot-color-on-success: #042f2e;
    --ot-color-danger: #f87171;
    --ot-color-on-danger: #450a0a;
    --ot-color-warning: #fbbf24;
    --ot-color-on-warning: #1c1917;
    --ot-color-info: #60a5fa;
    --ot-color-on-info: #0f172a;

    --ot-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.45);
    --ot-shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.42), 0 2px 4px -2px rgba(0, 0, 0, 0.38);
    --ot-shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.48), 0 4px 6px -4px rgba(0, 0, 0, 0.42);
    --ot-shadow-modal: 0 25px 50px -12px rgba(0, 0, 0, 0.65);

    --ot-color-emerald-600: #10b981;
    --ot-color-green-800: #6ee7b7;
    --ot-color-green-600: #4ade80;
    --ot-color-brand-legacy-blue: #38bdf8;
    --ot-color-blue-700: #93c5fd;
    --ot-color-slate-900: #f8fafc;
    --ot-color-gray-900: #f8fafc;
    --ot-color-gray-800: #f1f5f9;
    --ot-color-green-500: #4ade80;
    --ot-color-blue-600: #60a5fa;
    --ot-color-gray-700: #e2e8f0;
    --ot-color-purple-deep: #c084fc;
    --ot-color-indigo-600: #818cf8;
    --ot-color-indigo-500: #a5b4fc;
    --ot-color-violet-500: #c4b5fd;
    --ot-color-gray-mid: #94a3b8;
    --ot-color-gray-500: #94a3b8;
    --ot-color-green-300: #047857;
    --ot-color-amber-900: #fde68a;
    --ot-color-blue-300: #1d4ed8;
    --ot-color-slate-400: #64748b;
    --ot-color-red-800: #fecaca;
    --ot-color-gray-400: #64748b;
    --ot-color-amber-700: #fcd34d;
    --ot-color-red-700: #fca5a5;
    --ot-color-green-200: #065f46;
    --ot-color-blue-200: #1e40af;
    --ot-color-green-100: #064e3b;
    --ot-color-amber-600: #fbbf24;
    --ot-color-blue-100: #1e3a8a;
    --ot-color-red-600: #f87171;
    --ot-color-neutral-300: #475569;
    --ot-color-indigo-100: #312e81;
    --ot-color-slate-200: #475569;
    --ot-color-orange-600: #fb923c;
    --ot-color-gray-eee: #334155;
    --ot-color-surface-tint: #1e293b;
    --ot-color-indigo-50: #1e1b4b;
    --ot-color-blue-50: #172554;
    --ot-color-sky-50: #0c4a6e;
    --ot-color-green-50: #052e16;
    --ot-color-slate-100: #334155;
    --ot-color-zinc-50: #18181b;
    --ot-color-slate-50: #1e293b;
    --ot-color-red-200: #991b1b;
    --ot-color-red-100: #7f1d1d;
    --ot-color-red-50: #450a0a;
    --ot-color-amber-100: #78350f;

    --ot-color-top-row-bg: #0f172a;
    --ot-color-top-row-border: #334155;
    --ot-color-logo-halo-start: #1e3a5f;
    --ot-color-logo-halo-border: #334155;
    --ot-color-breadcrumb-link-hover: #f1f5f9;

    --ot-sidebar-bg-start:       #1e3a5f;
    --ot-sidebar-bg-end:         #0f2b5b;
    --ot-sidebar-gradient-end:   #1e293b;
    --ot-sidebar-border-soft:    #334155;
    --ot-sidebar-text-pack:      #cbd5e1;
    --ot-sidebar-text-navy:      #f1f5f9;
    --ot-sidebar-hover-pack:     rgba(96, 165, 250, 0.10);
    --ot-sidebar-active-bg-pack: rgba(96, 165, 250, 0.22);
    --ot-brand-pack-blue:        #60a5fa;
    --ot-brand-pack-orange:      #fb923c;
    --ot-color-slate-300:        #475569;
    --ot-sidebar-icon-gradient-low: #1e293b;

    /* ─── Spec 016 — Header sombre (variant dark, légèrement plus sombre pour cohérence dark-mode) ─── */
    --ot-color-header-bg-start: #0b1424;
    --ot-color-header-bg-end: #040912;
    --ot-color-header-fg: #f1f5f9;
    --ot-color-header-fg-muted: #cbd5e1;
    --ot-color-header-border: #1e293b;

    /* Sidebar tokens identiques en dark (dimensions, pas de couleurs) */
}

/* ─── Impression (FR-054) : forcer le thème clair (évite fonds noirs en aperçu / PDF) — spec 014 Phase 9 T045 ─── */
@media print {
    html {
        color-scheme: light !important;
    }
    /* Même en session `data-theme="dark"`, les variables utilisées à l’impression repassent sur la palette :root. */
    html[data-theme="dark"] {
        --ot-color-primary: #3b82f6;
        --ot-color-primary-hover: color-mix(in srgb, var(--ot-color-primary) 88%, #000 12%);
        --ot-color-primary-soft: color-mix(in srgb, var(--ot-color-primary) 18%, #ffffff 82%);
        --ot-color-primary-muted: color-mix(in srgb, var(--ot-color-primary) 35%, #ffffff 65%);
        --ot-color-on-primary: #ffffff;
        --ot-color-text-primary: #111827;
        --ot-color-text-secondary: #374151;
        --ot-color-text-muted: #4b5563;
        --ot-color-surface: #ffffff;
        --ot-color-surface-alt: #f7fafc;
        --ot-color-surface-muted: #f9fafb;
        --ot-color-surface-alt-soft: #f9fafb;
        --ot-color-surface-hover: #f3f4f6;
        --ot-color-neutral-50: #f9fafb;
        --ot-color-border: #d1d5db;
        --ot-color-border-strong: #9ca3af;
        --ot-color-success: #10b981;
        --ot-color-on-success: #ffffff;
        --ot-color-danger: #ef4444;
        --ot-color-on-danger: #ffffff;
        --ot-color-warning: #f59e0b;
        --ot-color-on-warning: #1a202c;
        --ot-color-info: #3b82f6;
        --ot-color-on-info: #ffffff;
        --ot-shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
        --ot-shadow-md: 0 4px 6px -1px rgba(15, 23, 42, 0.08), 0 2px 4px -2px rgba(15, 23, 42, 0.06);
        --ot-shadow-lg: 0 10px 15px -3px rgba(15, 23, 42, 0.1), 0 4px 6px -4px rgba(15, 23, 42, 0.08);
        --ot-shadow-modal: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
        --ot-color-top-row-bg: #f7f7f7;
        --ot-color-top-row-border: #d6d5d5;
        --ot-sidebar-gradient-end: #f4f8fd;
        --ot-sidebar-border-soft: #cbd5e1;
        --ot-sidebar-text-pack: #334155;
        --ot-sidebar-hover-pack: #eef4fc;
        --ot-sidebar-active-bg-pack: #e4effd;
        --ot-sidebar-bg-start:       #f4f8fd;
        --ot-sidebar-bg-end:         #f4f8fd;
        --ot-sidebar-text-navy:      #0f2b5b;
    }

    /*
     * Spec 016 (FR-052) — Le header sombre NE DOIT PAS s'imprimer.
     * On force les tokens header sur palette claire en impression, quel que soit le thème actif.
     */
    html,
    html[data-theme="dark"] {
        --ot-color-header-bg-start: #ffffff;
        --ot-color-header-bg-end: #ffffff;
        --ot-color-header-fg: #111827;
        --ot-color-header-fg-muted: #4b5563;
        --ot-color-header-border: #d1d5db;
    }
}

/* ─── Reduced motion (accessibilité FR-044) ─── */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ─── Focus visible — clavier uniquement ; pas de halo souris superflu (FR-041) ─── */
:is(
    a,
    button,
    input:not([type="hidden"]),
    textarea,
    select,
    summary,
    [role="button"],
    [role="tab"],
    [role="menuitem"],
    [tabindex]:not([tabindex="-1"])
):focus-visible {
    outline: 2px solid var(--ot-color-primary);
    outline-offset: 2px;
}

:is(a, button, input, textarea, select, summary, [role="button"], [tabindex]):focus:not(:focus-visible) {
    outline: none;
}
