/*
 * Clozia Design System v8.0 — Apple Design Language
 * Inspiré de iOS 17 / macOS Sonoma — propre, aéré, précis
 * SF Pro feel via Inter, palette iOS, zéro décoration superflue
 */

/* ── DESIGN TOKENS ─────────────────────────────────────────────── */
:root {
  /* Primary — iOS Blue */
  --color-primary: #007AFF;
  --color-primary-light: #3B99FF;
  --color-primary-dim: rgba(0, 122, 255, 0.08);
  --color-primary-hover: #0066D6;
  --color-primary-shadow: rgba(0, 122, 255, 0.22);
  --color-primary-text: #FFFFFF;

  /* Text — Apple label hierarchy */
  --color-text: #1C1C1E;
  --color-text-secondary: #3C3C43;
  --color-text-muted: #8E8E93;
  --color-text-dimmed: #AEAEB2;

  /* Backgrounds — Apple systemBackground */
  --color-bg: #F2F2F7;
  --color-bg-alt: #E5E5EA;
  --color-surface: #FFFFFF;
  --color-card: #FFFFFF;
  --color-card-solid: #FAFAFA;
  --color-surface-hover: #F2F2F7;
  --color-input-bg: #FFFFFF;

  /* Sidebar — macOS light sidebar */
  --sidebar-bg: #F2F2F7;
  --sidebar-text: #1C1C1E;
  --sidebar-text-muted: #8E8E93;
  --sidebar-border: rgba(0, 0, 0, 0.08);
  --sidebar-icon-bg: rgba(0, 0, 0, 0.05);

  /* Borders */
  --color-border: rgba(0, 0, 0, 0.08);
  --color-border-light: rgba(0, 0, 0, 0.05);

  /* Status — iOS palette */
  --color-success: #34C759;
  --color-success-bg: rgba(52, 199, 89, 0.08);
  --color-error: #FF3B30;
  --color-error-bg: rgba(255, 59, 48, 0.08);
  --color-warning: #FF9500;
  --color-warning-bg: rgba(255, 149, 0, 0.08);

  /* Brand scale — iOS blue */
  --brand-50: #EBF5FF;
  --brand-100: #D1EAFF;
  --brand-200: #A8D4FF;
  --brand-300: #6DBAFF;
  --brand-400: #3B99FF;
  --brand-500: #007AFF;
  --brand-600: #0066D6;
  --brand-700: #0055B3;
  --brand-800: #004494;
  --brand-900: #003375;

  /* Gray scale — Apple neutrals */
  --gray-50: #F2F2F7;
  --gray-100: #E5E5EA;
  --gray-200: #D1D1D6;
  --gray-300: #C7C7CC;
  --gray-400: #AEAEB2;
  --gray-500: #8E8E93;
  --gray-600: #636366;
  --gray-700: #48484A;
  --gray-800: #3A3A3C;
  --gray-900: #1C1C1E;

  /* Font — SF Pro feel via Inter */
  --font-sans: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', sans-serif;
  --font-display: -apple-system, BlinkMacSystemFont, 'Inter', sans-serif;
  --font-mono: 'SF Mono', 'JetBrains Mono', 'Fira Code', monospace;

  /* Radius — iOS-style */
  --radius-xs: 4px;
  --radius-sm: 8px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 18px;
  --radius-2xl: 22px;
  --radius-full: 9999px;

  /* Shadows — micro-shadows only */
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06), 0 2px 8px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.06), 0 4px 20px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.08), 0 8px 32px rgba(0, 0, 0, 0.06);
  --shadow-brand: 0 2px 8px rgba(0, 122, 255, 0.20), 0 1px 3px rgba(0, 122, 255, 0.10);
  --shadow-glass: 0 2px 16px rgba(0, 0, 0, 0.06), inset 0 1px 0 rgba(255, 255, 255, 0.9);

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-normal: 200ms cubic-bezier(0.16, 1, 0.3, 1);
  --transition-base: 280ms cubic-bezier(0.16, 1, 0.3, 1);
  --transition-slow: 450ms cubic-bezier(0.16, 1, 0.3, 1);
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-spring: cubic-bezier(0.34, 1.36, 0.64, 1);
}

/* ── DARK MODE ─────────────────────────────────────────────────── */
[data-theme="dark"] {
  --color-primary: #0A84FF;
  --color-primary-light: #4DA3FF;
  --color-primary-dim: rgba(10, 132, 255, 0.15);
  --color-primary-hover: #3B99FF;
  --color-primary-shadow: rgba(10, 132, 255, 0.30);

  --color-text: #FFFFFF;
  --color-text-secondary: #EBEBF5;
  --color-text-muted: #636366;
  --color-text-dimmed: #48484A;

  --color-bg: #000000;
  --color-bg-alt: #1C1C1E;
  --color-surface: #1C1C1E;
  --color-card: #2C2C2E;
  --color-card-solid: #3A3A3C;
  --color-surface-hover: #3A3A3C;
  --color-input-bg: #2C2C2E;

  --sidebar-bg: #1C1C1E;
  --sidebar-text: #FFFFFF;
  --sidebar-text-muted: #636366;
  --sidebar-border: rgba(255, 255, 255, 0.08);
  --sidebar-icon-bg: rgba(255, 255, 255, 0.08);

  --color-border: rgba(255, 255, 255, 0.08);
  --color-border-light: rgba(255, 255, 255, 0.05);

  --color-success: #30D158;
  --color-success-bg: rgba(48, 209, 88, 0.12);
  --color-error: #FF453A;
  --color-error-bg: rgba(255, 69, 58, 0.12);
  --color-warning: #FF9F0A;
  --color-warning-bg: rgba(255, 159, 10, 0.12);

  --shadow-sm: 0 1px 4px rgba(0, 0, 0, 0.40);
  --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.50);
  --shadow-lg: 0 4px 20px rgba(0, 0, 0, 0.60);
  --shadow-glass: 0 4px 24px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

/* ── BASE ──────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

body {
  font-family: var(--font-sans) !important;
  color: var(--color-text);
  background: var(--color-bg) !important;
  line-height: 1.5;
  font-size: 14px;
  overflow-x: hidden;
  letter-spacing: -0.01em;
}

/* Clean background — no pattern */
body::before { display: none !important; }

#root { position: relative; z-index: 1; }

::selection {
  background: rgba(0, 122, 255, 0.15);
  color: var(--color-text);
}

/* ── SCROLLBAR ─────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.12);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover { background: rgba(0, 0, 0, 0.22); }
[data-theme="dark"] ::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.12); }
[data-theme="dark"] ::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.22); }

/* ── FOCUS ──────────────────────────────────────────────────────── */
:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}
:focus:not(:focus-visible) { outline: none; }

/* ══════════════════════════════════════════════════════════════════
   SIDEBAR — Light macOS style
   ══════════════════════════════════════════════════════════════════ */

div[class*="sidebar"] {
  background: var(--sidebar-bg) !important;
  backdrop-filter: none !important;
  border-right: 1px solid var(--sidebar-border) !important;
  border-image: none !important;
  color: var(--sidebar-text) !important;
}

/* Supprime tous les pseudo-elements décoratifs */
div[class*="sidebar"]::before,
div[class*="sidebar"]::after {
  display: none !important;
}

/* Force text color dark in sidebar */
div[class*="sidebar"] * {
  color: var(--sidebar-text) !important;
}

/* Section headers */
div[class*="sidebar"] [style*="fontSize: 10"],
div[class*="sidebar"] [style*="fontSize: 11"],
div[class*="sidebar"] [style*="textTransform"],
.sidebar-section-label {
  color: var(--sidebar-text-muted) !important;
  font-size: 11px !important;
  font-weight: 600 !important;
  letter-spacing: 0.04em !important;
  text-transform: uppercase !important;
}

/* Sidebar separator */
.sidebar-separator {
  height: 1px !important;
  background: var(--sidebar-border) !important;
  margin: 6px 0 !important;
}

/* Nav items */
.nav-item {
  border-radius: var(--radius-md) !important;
  transition: background var(--transition-fast), color var(--transition-fast) !important;
  color: var(--sidebar-text) !important;
  font-weight: 500 !important;
  position: relative !important;
}
.nav-item:hover {
  background: rgba(0, 0, 0, 0.05) !important;
  color: var(--sidebar-text) !important;
  transform: none !important;
}
[data-theme="dark"] .nav-item:hover {
  background: rgba(255, 255, 255, 0.07) !important;
}

/* Active nav — iOS blue pill */
.nav-item-active {
  background: var(--color-primary) !important;
  color: #FFFFFF !important;
  border-left: none !important;
  box-shadow: var(--shadow-brand) !important;
  backdrop-filter: none !important;
}
.nav-item-active * {
  color: #FFFFFF !important;
}
.nav-item-active:hover {
  background: var(--color-primary-hover) !important;
  transform: none !important;
}

/* ── BUTTONS ───────────────────────────────────────────────────── */
button, .btn, [role="button"] {
  font-family: var(--font-sans) !important;
  transition: all var(--transition-normal) !important;
  cursor: pointer;
  letter-spacing: -0.01em;
}

/* Primary — iOS blue, flat */
.btn-primary {
  background: var(--color-primary) !important;
  color: #FFFFFF !important;
  border-radius: var(--radius-md) !important;
  box-shadow: var(--shadow-brand) !important;
  font-weight: 600 !important;
  letter-spacing: -0.01em !important;
}
.btn-primary:hover {
  background: var(--color-primary-hover) !important;
  transform: none !important;
  box-shadow: 0 2px 12px rgba(0, 122, 255, 0.30) !important;
}
.btn-primary:active {
  transform: scale(0.98) !important;
}

/* Primary inline style overrides — map old blue to new */
[style*="background: rgb(37, 99"]:not(div[class*="sidebar"] *),
[style*="background: #2563EB"]:not(div[class*="sidebar"] *),
[style*="backgroundColor: rgb(37, 99"]:not(div[class*="sidebar"] *) {
  background: var(--color-primary) !important;
  box-shadow: var(--shadow-brand) !important;
}

/* Secondary / ghost */
.btn-secondary {
  background: transparent !important;
  border: 1px solid var(--color-border) !important;
  border-radius: var(--radius-md) !important;
  color: var(--color-text-secondary) !important;
  font-weight: 500 !important;
}
.btn-secondary:hover {
  background: var(--color-surface-hover) !important;
  border-color: var(--color-primary) !important;
  color: var(--color-primary) !important;
}

/* Danger */
.btn-danger {
  background: var(--color-error) !important;
  border-radius: var(--radius-md) !important;
  color: white !important;
  font-weight: 600 !important;
  box-shadow: none !important;
}
.btn-danger:hover {
  filter: brightness(0.92) !important;
}

/* ── INPUTS ────────────────────────────────────────────────────── */
input, textarea, select {
  font-family: var(--font-sans) !important;
  background: var(--color-input-bg) !important;
  border: 1px solid var(--color-border) !important;
  border-radius: var(--radius-md) !important;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast) !important;
  min-height: 40px !important;
  color: var(--color-text) !important;
  font-size: 14px !important;
  letter-spacing: -0.01em !important;
  box-shadow: none !important;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--color-primary) !important;
  box-shadow: 0 0 0 3px var(--color-primary-dim) !important;
  outline: none !important;
}
input::placeholder, textarea::placeholder {
  color: var(--color-text-dimmed) !important;
}
[data-theme="dark"] input,
[data-theme="dark"] textarea,
[data-theme="dark"] select {
  background: var(--color-input-bg) !important;
  border-color: var(--color-border) !important;
  color: var(--color-text) !important;
}

/* ── TYPOGRAPHY ────────────────────────────────────────────────── */
/* Headings — SF Pro feel */
div[style*="fontSize: 28"], div[style*="fontSize: 26"], div[style*="fontSize: 24"],
div[style*="fontSize: 22"], div[style*="fontSize: 20"],
span[style*="fontSize: 28"], span[style*="fontSize: 26"], span[style*="fontSize: 24"],
span[style*="fontSize: 22"], span[style*="fontSize: 20"] {
  font-family: var(--font-display) !important;
  font-weight: 700 !important;
  letter-spacing: -0.03em !important;
}

div[style*="fontSize: 18"], div[style*="fontSize: 17"], div[style*="fontSize: 16"],
span[style*="fontSize: 18"], span[style*="fontSize: 17"], span[style*="fontSize: 16"] {
  font-family: var(--font-display) !important;
  font-weight: 600 !important;
  letter-spacing: -0.02em !important;
}

/* ── BADGES & TAGS ─────────────────────────────────────────────── */
.tag-btn {
  border-radius: var(--radius-full) !important;
  transition: all var(--transition-fast) !important;
  font-weight: 500 !important;
  font-size: 12px !important;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0;
}
.badge-primary { background: var(--color-primary-dim); color: var(--color-primary); }
.badge-success { background: var(--color-success-bg); color: var(--color-success); }
.badge-warning { background: var(--color-warning-bg); color: var(--color-warning); }
.badge-danger  { background: var(--color-error-bg); color: var(--color-error); }
.badge-secondary { background: var(--color-surface-hover); color: var(--color-text-muted); }

/* Temperature */
.temp-hot  { background: var(--color-error-bg) !important; color: var(--color-error) !important; }
.temp-warm { background: var(--color-warning-bg) !important; color: var(--color-warning) !important; }
.temp-cold { background: var(--color-primary-dim) !important; color: var(--color-primary) !important; }

/* ── CARDS ─────────────────────────────────────────────────────── */
.kanban-card, .dash-metric-card {
  background: var(--color-card) !important;
  border: 1px solid var(--color-border) !important;
  border-radius: var(--radius-lg) !important;
  box-shadow: var(--shadow-sm) !important;
  transition: box-shadow var(--transition-normal), transform var(--transition-normal), border-color var(--transition-normal) !important;
}
.kanban-card:hover {
  box-shadow: var(--shadow-md) !important;
  transform: translateY(-2px) !important;
  border-color: rgba(0, 122, 255, 0.14) !important;
}
.dash-metric-card:hover {
  box-shadow: var(--shadow-md) !important;
  transform: translateY(-1px) !important;
  border-color: rgba(0, 122, 255, 0.12) !important;
}
.dash-metric-card::before { display: none !important; }

.dash-section {
  background: var(--color-card) !important;
  border: 1px solid var(--color-border) !important;
  border-radius: var(--radius-lg) !important;
  overflow: hidden;
}

/* ── CONVERSATION LIST ─────────────────────────────────────────── */
.conv-item {
  border-radius: var(--radius-md) !important;
  transition: background var(--transition-fast) !important;
}
.conv-item:hover {
  background: var(--color-surface-hover) !important;
  transform: none !important;
}

/* ── TABLE ─────────────────────────────────────────────────────── */
.data-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
.data-table th {
  background: var(--color-bg);
  color: var(--color-text-muted);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--color-border);
}
.data-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--color-border-light);
  color: var(--color-text);
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr { transition: background var(--transition-fast); }
.data-table tbody tr:hover { background: var(--color-surface-hover) !important; }

/* ── TOAST ─────────────────────────────────────────────────────── */
.toast, #clozia-toast {
  border-radius: var(--radius-lg) !important;
  backdrop-filter: blur(24px) saturate(180%) !important;
  box-shadow: var(--shadow-lg) !important;
  font-size: 13px !important;
  font-weight: 600 !important;
  letter-spacing: -0.01em !important;
}

/* ── QUICK REPLY ───────────────────────────────────────────────── */
.quick-reply {
  border-radius: var(--radius-full) !important;
  transition: all var(--transition-fast) !important;
  font-weight: 500 !important;
}
.quick-reply:hover {
  transform: none !important;
  box-shadow: var(--shadow-sm) !important;
}

/* ── SKELETON ──────────────────────────────────────────────────── */
.skeleton {
  background: linear-gradient(90deg, var(--color-bg-alt) 25%, var(--color-surface-hover) 50%, var(--color-bg-alt) 75%);
  background-size: 400% 100%;
  animation: skeletonShimmer 1.2s ease infinite;
  border-radius: var(--radius-md);
}
@keyframes skeletonShimmer {
  0% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

/* ── MODAL BACKDROP ────────────────────────────────────────────── */
[style*="position: fixed"][style*="background: rgba(0"],
[style*="position: fixed"][style*="background:rgba(0"] {
  backdrop-filter: blur(8px) !important;
}

/* ── NOTIFICATION BADGES ───────────────────────────────────────── */
span[style*="background: rgb(239, 68"],
span[style*="background: rgb(37, 99"] {
  border-radius: var(--radius-full) !important;
  font-size: 10px !important;
  font-weight: 700 !important;
  min-width: 18px !important;
  height: 18px !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  padding: 0 5px !important;
}

/* ── FUNNEL BAR ────────────────────────────────────────────────── */
.funnel-bar {
  border-radius: var(--radius-sm);
  transition: width 0.5s var(--ease);
}
.funnel-bar::after { display: none; }

/* ── TREND ─────────────────────────────────────────────────────── */
.trend-up { color: var(--color-success) !important; font-weight: 600; }
.trend-down { color: var(--color-error) !important; font-weight: 600; }

/* ── SPARKLINE ─────────────────────────────────────────────────── */
.sparkline { display: flex; align-items: flex-end; gap: 1px; height: 20px; }
.sparkline-bar {
  flex: 1;
  background: var(--brand-300);
  border-radius: 2px 2px 0 0;
  min-height: 2px;
  opacity: 0.5;
  transition: opacity var(--transition-fast);
}
.sparkline-bar:last-child { opacity: 1; background: var(--color-primary); }

/* ── LINKS ─────────────────────────────────────────────────────── */
a { color: var(--color-primary); text-decoration: none; transition: color var(--transition-fast); }
a:hover { color: var(--color-primary-hover); }

/* ── ANIMATIONS ────────────────────────────────────────────────── */
@keyframes fadeUp { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }
@keyframes slideIn { from { opacity: 0; transform: translateX(-8px); } to { opacity: 1; transform: translateX(0); } }
@keyframes toastIn { from { opacity: 0; transform: translateY(-14px) scale(0.95); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes toastOut { from { opacity: 1; transform: translateY(0) scale(1); } to { opacity: 0; transform: translateY(-14px) scale(0.95); } }
@keyframes logoFloat { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-4px); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shimmer { 0% { background-position: 200% center; } 100% { background-position: -200% center; } }
@keyframes popIn { from { opacity: 0; transform: scale(0.94); } to { opacity: 1; transform: scale(1); } }

/* ── SAFE AREA (iOS) ─────────────────────────────────────────── */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .pb-safe { padding-bottom: env(safe-area-inset-bottom); }
}

/* ── RESPONSIVE ─────────────────────────────────────────────── */
html, body { max-width: 100vw; overflow-x: hidden; }

@media (max-width: 768px) {
  .tabs-scroll {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    scrollbar-width: none !important;
    white-space: nowrap !important;
  }
  .tabs-scroll::-webkit-scrollbar { display: none !important; }

  .labels-container { display: flex !important; flex-wrap: wrap !important; gap: 6px !important; }
  .label-badge { white-space: nowrap !important; font-size: 12px !important; padding: 4px 10px !important; }

  .msg-row div { word-break: break-word; overflow-wrap: break-word; }

  .grid-cols-2, .grid-cols-3, .grid-cols-4 {
    grid-template-columns: 1fr !important;
  }

  .data-table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .dash-metric-card { padding: 14px !important; }
  .dash-section { padding: 0 !important; }

  .kanban-scroll {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    flex-wrap: nowrap !important;
    scrollbar-width: none !important;
    padding-bottom: 8px !important;
  }
  .kanban-scroll::-webkit-scrollbar { display: none !important; }

  input, textarea, select { font-size: 16px !important; }
}

@media (max-width: 480px) {
  h1 { font-size: 20px !important; letter-spacing: -0.4px !important; }
  h2 { font-size: 17px !important; }
  button, [role="button"] { min-height: 36px !important; }
  .modal-content {
    width: calc(100vw - 24px) !important;
    max-width: 100% !important;
    margin: 12px !important;
    border-radius: var(--radius-lg) !important;
  }
  .chat-step-indicators { display: none !important; }
  .page-padding { padding: 12px !important; }
}

/* ── DARK MODE REFINEMENTS ─────────────────────────────────── */
[data-theme="dark"] div[class*="sidebar"] {
  background: var(--sidebar-bg) !important;
  border-right-color: var(--sidebar-border) !important;
}

[data-theme="dark"] .dash-metric-card,
[data-theme="dark"] .kanban-card {
  background: var(--color-card) !important;
  border-color: var(--color-border) !important;
  box-shadow: var(--shadow-sm) !important;
}

[data-theme="dark"] .dash-metric-card:hover,
[data-theme="dark"] .kanban-card:hover {
  border-color: rgba(10, 132, 255, 0.25) !important;
  box-shadow: var(--shadow-md) !important;
}

[data-theme="dark"] .data-table th { background: var(--color-bg-alt); }
[data-theme="dark"] .data-table tbody tr:hover { background: var(--color-surface-hover) !important; }

/* Supprime les overrides agressifs hérités */
.ai-toggle-wrap:hover .ai-toggle-tooltip {
  opacity: 1 !important;
  transition: opacity 0.2s ease 0.5s;
}

/* Section steps (IA Setting wizard) */
.section-step-item { color: var(--color-text-muted) !important; border-radius: var(--radius-sm) !important; }
.section-step-item:hover { background: var(--color-surface-hover) !important; color: var(--color-text) !important; }

/* Support button */
.support-btn { transition: all var(--transition-normal) !important; }
.support-btn:hover { transform: scale(1.06) !important; box-shadow: var(--shadow-brand) !important; }

/* Stat card hover */
.stat-card:hover { transform: translateY(-1px) !important; box-shadow: var(--shadow-md) !important; }

/* ══════════════════════════════════════════════════════════════════
   DESIGN SYSTEM v8.1 — UX/UI POLISH (audit 2026-05-09)
   Ameliorations transverses, sans casser l'existant
   ══════════════════════════════════════════════════════════════════ */

/* ── TOUCH TARGETS (mobile WCAG / iOS HIG) ─────────────────────── */
@media (max-width: 768px) {
  /* iOS HIG : minimum 44x44px pour le pouce. On ne force pas sur tous
     les boutons (icones inline) mais sur les CTA et controles primaires. */
  .btn-primary, .btn-secondary, .btn-danger,
  button[type="submit"], button.cta, .nav-item {
    min-height: 44px !important;
  }
  /* Inputs : 16px font deja gere ligne 598, on ajoute padding confortable */
  input:not([type="checkbox"]):not([type="radio"]),
  textarea, select {
    min-height: 44px !important;
    padding: 10px 14px !important;
  }
  /* Checkbox / radio : zone de tap plus grande */
  label {
    min-height: 32px;
    display: inline-flex;
    align-items: center;
  }
}

/* ── FOCUS VISIBLE — accessibilite WCAG AA ────────────────────── */
button:focus-visible,
.btn:focus-visible,
[role="button"]:focus-visible,
a:focus-visible {
  outline: 2px solid var(--color-primary) !important;
  outline-offset: 2px !important;
  box-shadow: 0 0 0 4px var(--color-primary-dim) !important;
}

/* ── SKELETON LOADERS — utilitaires ─────────────────────────── */
.skeleton-text {
  height: 12px;
  margin: 6px 0;
  background: linear-gradient(90deg, var(--color-bg-alt) 25%, var(--color-surface-hover) 50%, var(--color-bg-alt) 75%);
  background-size: 400% 100%;
  animation: skeletonShimmer 1.2s ease infinite;
  border-radius: var(--radius-sm);
}
.skeleton-text.w-50 { width: 50%; }
.skeleton-text.w-75 { width: 75%; }
.skeleton-text.w-100 { width: 100%; }
.skeleton-card {
  height: 80px;
  background: linear-gradient(90deg, var(--color-bg-alt) 25%, var(--color-surface-hover) 50%, var(--color-bg-alt) 75%);
  background-size: 400% 100%;
  animation: skeletonShimmer 1.2s ease infinite;
  border-radius: var(--radius-lg);
  margin-bottom: 12px;
}
.skeleton-circle {
  width: 36px; height: 36px;
  background: var(--color-bg-alt);
  border-radius: 50%;
  animation: skeletonShimmer 1.2s ease infinite;
  background: linear-gradient(90deg, var(--color-bg-alt) 25%, var(--color-surface-hover) 50%, var(--color-bg-alt) 75%);
  background-size: 400% 100%;
}

/* ── SPINNER inline (pour boutons loading) ────────────────────── */
.spinner-inline {
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: middle;
}
.btn-loading {
  pointer-events: none;
  opacity: 0.75;
  position: relative;
}
.btn-loading::after {
  content: '';
  position: absolute;
  right: 14px; top: 50%;
  width: 14px; height: 14px;
  margin-top: -7px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

/* ── EMPTY STATES ─────────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 24px;
  text-align: center;
  color: var(--color-text-muted);
  min-height: 240px;
}
.empty-state-icon {
  width: 56px; height: 56px;
  border-radius: var(--radius-full);
  background: var(--color-primary-dim);
  color: var(--color-primary);
  display: flex; align-items: center; justify-content: center;
  font-size: 24px;
  margin-bottom: 16px;
}
.empty-state-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: 4px;
  letter-spacing: -0.01em;
}
.empty-state-desc {
  font-size: 13px;
  color: var(--color-text-muted);
  max-width: 320px;
  line-height: 1.5;
  margin-bottom: 16px;
}

/* ── MOBILE SIDEBAR — pattern overlay generique ────────────────── */
.mobile-sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(2px);
  z-index: 998;
  animation: fadeIn 0.2s ease;
}
@media (min-width: 1024px) {
  .mobile-sidebar-overlay { display: none !important; }
}

/* Sidebar slide-in mobile */
@media (max-width: 1023px) {
  .sidebar-mobile-hidden {
    transform: translateX(-100%) !important;
    transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1) !important;
  }
  .sidebar-mobile-visible {
    transform: translateX(0) !important;
    transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1) !important;
    z-index: 999 !important;
  }
}

/* Hamburger button — mobile uniquement */
.mobile-menu-btn {
  display: none;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  width: 40px; height: 40px;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
@media (max-width: 1023px) {
  .mobile-menu-btn { display: inline-flex; }
}

/* ── TABLES — scroll horizontal mobile ─────────────────────────── */
@media (max-width: 768px) {
  table { min-width: 100%; }
  /* Wrapper utilitaire pour les tableaux */
  .table-wrap {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    border-radius: var(--radius-md);
  }
}

/* ── FORM LABELS / VALIDATION VISUELLE ─────────────────────────── */
label.required::after {
  content: ' *';
  color: var(--color-error);
  font-weight: 600;
}
input.error, textarea.error, select.error,
input[aria-invalid="true"], textarea[aria-invalid="true"], select[aria-invalid="true"] {
  border-color: var(--color-error) !important;
  box-shadow: 0 0 0 3px var(--color-error-bg) !important;
}
.field-error {
  display: block;
  color: var(--color-error);
  font-size: 12px;
  margin-top: 4px;
  font-weight: 500;
}
.field-hint {
  display: block;
  color: var(--color-text-muted);
  font-size: 12px;
  margin-top: 4px;
}

/* ── CONTRAST FIX — text-secondary trop clair en light mode ────── */
:root {
  /* WCAG AA exige 4.5:1 sur fond blanc. #3C3C43 = OK (~ 11:1).
     #8E8E93 sur blanc = 3.8:1 — sous le seuil AA pour le texte normal.
     On garde pour les meta uniquement, jamais pour les labels lisibles. */
  --color-text-meta: var(--color-text-muted);
}
[data-theme="dark"] {
  /* Fix : --color-text-muted #636366 sur #1C1C1E = 4.4:1 (limite AA).
     On le remonte pour les usages secondaires. */
  --color-text-secondary: #EBEBF5;
  --color-text-muted: #98989F;
}

/* ── PRESSABLE FEEDBACK (haptic-feel via scale) ────────────────── */
@media (hover: hover) {
  .pressable:active,
  button:not(:disabled):active,
  .btn:not(:disabled):active {
    transform: scale(0.97);
    transition: transform 80ms ease;
  }
}

/* ── SAFE AREA (PWA iOS notch) ────────────────────────────────── */
@supports (padding: env(safe-area-inset-top)) {
  .pt-safe { padding-top: env(safe-area-inset-top); }
  .pl-safe { padding-left: env(safe-area-inset-left); }
  .pr-safe { padding-right: env(safe-area-inset-right); }
}

/* ── REDUCED MOTION (a11y) ────────────────────────────────────── */
@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;
  }
}

/* ── DISABLED STATES ──────────────────────────────────────────── */
button:disabled, .btn:disabled, [role="button"][aria-disabled="true"] {
  opacity: 0.5 !important;
  cursor: not-allowed !important;
  pointer-events: none;
}
input:disabled, textarea:disabled, select:disabled {
  background: var(--color-bg-alt) !important;
  color: var(--color-text-muted) !important;
  cursor: not-allowed !important;
}

/* ── DIVIDER ──────────────────────────────────────────────────── */
.divider {
  height: 1px;
  background: var(--color-border);
  margin: 12px 0;
  border: none;
}
.divider-vertical {
  width: 1px;
  background: var(--color-border);
  align-self: stretch;
  margin: 0 8px;
}

/* ── TYPOGRAPHIE — hierarchie utilitaire ──────────────────────── */
.text-xs   { font-size: 11px; line-height: 1.4; }
.text-sm   { font-size: 13px; line-height: 1.5; }
.text-base { font-size: 14px; line-height: 1.5; }
.text-lg   { font-size: 16px; line-height: 1.4; font-weight: 600; letter-spacing: -0.02em; }
.text-xl   { font-size: 20px; line-height: 1.3; font-weight: 700; letter-spacing: -0.03em; }
.text-2xl  { font-size: 24px; line-height: 1.25; font-weight: 700; letter-spacing: -0.03em; }
.text-3xl  { font-size: 30px; line-height: 1.2; font-weight: 800; letter-spacing: -0.04em; }
.text-muted     { color: var(--color-text-muted); }
.text-secondary { color: var(--color-text-secondary); }
.text-primary   { color: var(--color-primary); }
.text-success   { color: var(--color-success); }
.text-error     { color: var(--color-error); }

/* ── ANIMATIONS — entree douce pour vues ──────────────────────── */
.view-enter {
  animation: fadeUp 0.32s cubic-bezier(0.16, 1, 0.3, 1);
}

/* ── DARK MODE — corrections finales ─────────────────────────── */
[data-theme="dark"] body {
  background: var(--color-bg) !important;
  color: var(--color-text) !important;
}
[data-theme="dark"] .data-table th {
  color: var(--color-text-muted);
  border-bottom-color: var(--color-border);
}
[data-theme="dark"] .empty-state-title { color: var(--color-text); }
[data-theme="dark"] .mobile-menu-btn {
  background: var(--color-card);
  border-color: var(--color-border);
  color: var(--color-text);
}
[data-theme="dark"] .skeleton,
[data-theme="dark"] .skeleton-text,
[data-theme="dark"] .skeleton-card {
  background: linear-gradient(90deg, #2C2C2E 25%, #3A3A3C 50%, #2C2C2E 75%);
  background-size: 400% 100%;
}

/* ── UTILITES SPACING ─────────────────────────────────────────── */
.gap-1 { gap: 4px; } .gap-2 { gap: 8px; } .gap-3 { gap: 12px; } .gap-4 { gap: 16px; }
.gap-5 { gap: 20px; } .gap-6 { gap: 24px; }

/* ── PREVENT TEXT OVERFLOW ────────────────────────────────────── */
.truncate {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.line-clamp-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.line-clamp-3 {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ── KANBAN SCROLL — meilleur indicateur visuel ──────────────── */
.kanban-scroll {
  scroll-snap-type: x mandatory;
}
.kanban-scroll > * {
  scroll-snap-align: start;
}

/* ── MODAL — backdrop + animation ─────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(8px);
  z-index: 1000;
  animation: fadeIn 0.2s ease;
}
.modal-content-anim {
  animation: popIn 0.28s cubic-bezier(0.16, 1, 0.3, 1);
}
@media (max-width: 480px) {
  .modal-content {
    /* Bottom sheet sur mobile pour CTA accessibles au pouce */
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0 !important;
    max-height: 90vh;
    overflow-y: auto;
    animation: slideUpSheet 0.32s cubic-bezier(0.16, 1, 0.3, 1);
  }
}
@keyframes slideUpSheet {
  from { transform: translateY(100%); opacity: 0.5; }
  to   { transform: translateY(0); opacity: 1; }
}

/* ── STICKY HEADER (pour vues longues) ───────────────────────── */
.sticky-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--color-surface);
  backdrop-filter: blur(12px) saturate(180%);
  border-bottom: 1px solid var(--color-border);
}

/* ── BADGE NOTIFICATION — animated pulse ─────────────────────── */
.badge-notif {
  position: relative;
}
.badge-notif::after {
  content: '';
  position: absolute;
  top: -2px; right: -2px;
  width: 8px; height: 8px;
  background: var(--color-error);
  border-radius: 50%;
  border: 2px solid var(--color-surface);
  animation: pulse 2s ease-in-out infinite;
}

/* ── FORMS — better focus on dark mode ───────────────────────── */
[data-theme="dark"] input:focus,
[data-theme="dark"] textarea:focus,
[data-theme="dark"] select:focus {
  border-color: var(--color-primary) !important;
  box-shadow: 0 0 0 3px rgba(10, 132, 255, 0.25) !important;
}

/* ── HOVER STATES — desktop only ─────────────────────────────── */
@media (hover: none) {
  .btn-primary:hover,
  .btn-secondary:hover,
  .kanban-card:hover,
  .dash-metric-card:hover {
    transform: none !important;
    box-shadow: var(--shadow-sm) !important;
  }
}
