/* ═══════════════════════════════════════════════════════════════════════
   CRM COTY Agency — Base, design tokens, fenêtre frameless
   ═══════════════════════════════════════════════════════════════════════ */

/* ─── Tokens partagés (NON-couleur) : valables quel que soit le thème ─── */
:root {
  /* Typographie — Inter (tracking serré) + DM Mono pour les chiffres/montants/dates */
  --font-body: 'Inter', -apple-system, 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'DM Mono', 'Cascadia Mono', Consolas, monospace;
  --tracking: -0.011em;

  /* Mesures */
  --radius:    8px;
  --radius-lg: 12px;
  --radius-sm: 6px;
  --header-h:  52px;
  --sidebar-w: 236px;

  --t-fast: 120ms;
  --t-base: 180ms;
  --ease:   cubic-bezier(0.4, 0, 0.2, 1);
  --ease-spring: cubic-bezier(0.34, 1.4, 0.5, 1);
}

/* ─── Thème SOMBRE (défaut) — direction « Linear futuriste » (handoff 02) ─── */
:root[data-theme="dark"] {
  color-scheme: dark;

  /* Surfaces */
  --bg:          #0b0c0e;
  --bg-surface:  #121316;
  --bg-elevated: #17181c;
  --bg-hover:    #1d1f24;

  --border:      rgba(255,255,255,0.09);
  --border-hi:   rgba(94,106,210,0.6);

  --accent:      #5e6ad2;
  --accent-soft: rgba(94,106,210,0.15);
  --success:     #4cb782;
  --success-soft:rgba(76,183,130,0.15);
  --danger:      #eb5757;
  --danger-soft: rgba(235,87,87,0.15);
  --warning:     #f2c94c;
  --warning-soft:rgba(242,201,76,0.15);

  --text:        #f7f8f8;
  --text-muted:  #8a8f98;
  --text-dim:    #7c818a;   /* audit UI-5 : 5.0:1 sur --bg (≥ WCAG AA), au lieu de #62666d (3.4:1) */

  /* Statuts du pipeline */
  --st-prospect:   #8a8f98;
  --st-discussion: #5e6ad2;
  --st-devis:      #f2c94c;
  --st-nego:       #e8985a;
  --st-client:     #4cb782;
  --st-refuse:     #eb5757;
  --st-abandon:    #62666d;

  --shadow:    0 1px 2px rgba(0,0,0,0.4);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.45);
  --shadow-lg: 0 16px 48px rgba(0,0,0,0.55);
  --ring: 0 0 0 3px var(--accent-soft);

  /* Couche futuriste — accent2 (violet) + spark (cyan) UNIQUEMENT en dégradés/glows */
  --accent2:   #8b5cf6;
  --spark:     #22d3ee;
  --grad:      linear-gradient(135deg, #5e6ad2, #8b5cf6 52%, #22d3ee);
  --grad-soft: linear-gradient(135deg, rgba(94,106,210,0.9), rgba(139,92,246,0.85) 55%, rgba(34,211,238,0.8));
  --glass:     color-mix(in srgb, var(--bg-surface) 70%, transparent);
  --glass-el:  color-mix(in srgb, var(--bg-elevated) 84%, transparent);
  --grid-line: rgba(140,160,255,0.05);
}

/* ─── Thème CLAIR — direction « Linear futuriste » (handoff 02) ─── */
:root[data-theme="light"] {
  color-scheme: light;

  /* Surfaces */
  --bg:          #fbfbfb;
  --bg-surface:  #ffffff;
  --bg-elevated: #ffffff;
  --bg-hover:    #f4f5f8;

  --border:      rgba(10,10,20,0.10);
  --border-hi:   rgba(94,106,210,0.5);

  --accent:      #5e6ad2;
  --accent-soft: rgba(94,106,210,0.12);
  --success:     #2f9e6f;
  --success-soft:rgba(47,158,111,0.12);
  --danger:      #d64545;
  --danger-soft: rgba(214,69,69,0.12);
  --warning:     #c79019;
  --warning-soft:rgba(199,144,25,0.13);

  --text:        #08090a;
  --text-muted:  #6b7280;
  --text-dim:    #6e7480;   /* thème clair : ≥4.5:1 sur fond clair (audit S5-16 ; avant #9097a1 = 2.85:1) */

  /* Statuts du pipeline */
  --st-prospect:   #6b7280;
  --st-discussion: #5e6ad2;
  --st-devis:      #c79019;
  --st-nego:       #c2772f;
  --st-client:     #2f9e6f;
  --st-refuse:     #d64545;
  --st-abandon:    #9097a1;

  --shadow:    0 1px 2px rgba(10,12,30,0.06);
  --shadow-md: 0 4px 16px rgba(10,12,30,0.08);
  --shadow-lg: 0 16px 48px rgba(10,12,30,0.12);
  --ring: 0 0 0 3px var(--accent-soft);

  /* Couche futuriste */
  --accent2:   #7c4ddb;
  --spark:     #0891b2;
  --grad:      linear-gradient(135deg, #5e6ad2, #7c4ddb 52%, #0891b2);
  --grad-soft: linear-gradient(135deg, rgba(94,106,210,0.85), rgba(124,77,219,0.8) 55%, rgba(8,145,178,0.75));
  --glass:     color-mix(in srgb, var(--bg-surface) 82%, transparent);
  --glass-el:  color-mix(in srgb, var(--bg-elevated) 90%, transparent);
  --grid-line: rgba(40,50,120,0.05);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { background: var(--bg); }
html, body {
  height: 100%;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.5;
  letter-spacing: var(--tracking);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;
}
/* Contenu SÉLECTIONNABLE (copier un email, un nom, une note) ; seuls les contrôles
   d'interface restent non sélectionnables pour garder le ressenti « application ».
   Avant, `user-select:none` global empêchait toute copie de donnée. (audit S5-17) */
html { user-select: text; }
button, .btn, .icon-btn, .nav-item, .badge, .chip { user-select: none; }
body { background: transparent; }

#app { height: calc(100vh - var(--header-h)); }

a { color: var(--accent); text-decoration: none; }
h1, h2, h3, h4 { letter-spacing: -0.02em; }

/* ═══════ NÉBULEUSE DE FOND (couche futuriste, derrière l'app) ═══════ */
#bgfx { position: fixed; inset: 0; z-index: -1; pointer-events: none; overflow: hidden; }
#bgfx .neb { position: absolute; border-radius: 50%; filter: blur(64px); }
#bgfx .n1 { width: 60vw; height: 60vw; left: -12vw; top: -22vh;
  background: radial-gradient(circle, color-mix(in srgb, var(--accent) 22%, transparent), transparent 70%);
  animation: neb-drift 30s var(--ease) infinite alternate; }
#bgfx .n2 { width: 50vw; height: 50vw; right: -14vw; top: 6vh;
  background: radial-gradient(circle, color-mix(in srgb, var(--accent2) 16%, transparent), transparent 70%);
  animation: neb-drift 38s var(--ease) infinite alternate-reverse; }
#bgfx .n3 { width: 46vw; height: 46vw; left: 20vw; bottom: -24vh;
  background: radial-gradient(circle, color-mix(in srgb, var(--spark) 10%, transparent), transparent 70%);
  animation: neb-drift 46s var(--ease) infinite alternate; }
#bgfx .grid { position: absolute; inset: 0;
  background-image: linear-gradient(var(--grid-line) 1px, transparent 1px),
                    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 48px 48px;
  -webkit-mask-image: radial-gradient(circle at 50% 38%, #000, transparent 82%);
          mask-image: radial-gradient(circle at 50% 38%, #000, transparent 82%); }
@keyframes neb-drift { from { transform: translate(0,0) scale(1); } to { transform: translate(42px,32px) scale(1.08); } }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 6px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--border-hi); }

/* ═══════ HEADER FRAMELESS — en verre, marque Orbit ═══════ */
#hdr {
  height: var(--header-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 8px 0 16px;
  background: color-mix(in srgb, var(--bg-surface) 58%, transparent);
  backdrop-filter: blur(16px) saturate(1.1);
  -webkit-backdrop-filter: blur(16px) saturate(1.1);
  border-bottom: 1px solid var(--border);
  position: relative; z-index: 100;
}
/* Balayage lumineux sous la barre (couleur d'accent → accent2) */
#hdr::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent), var(--accent2), transparent);
  background-size: 50% 100%; opacity: 0.55;
  animation: hdr-sweep 9s linear infinite; pointer-events: none;
}
@keyframes hdr-sweep { 0% { background-position: -100% 0; } 100% { background-position: 200% 0; } }

.brand { display: flex; align-items: center; gap: 9px; pointer-events: none; }
.brand .brand-glyph { width: 22px; height: 22px; flex: none; filter: drop-shadow(0 0 8px color-mix(in srgb, var(--accent) 60%, transparent)); }
.brand-mark {
  font-weight: 600; font-size: 16px; letter-spacing: -0.02em;
  background: var(--grad); -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; color: transparent;
}

/* Indicateur « EN LIGNE » (point pulsant, mono) */
.hdr-status {
  display: inline-flex; align-items: center; gap: 6px; margin-left: 6px;
  font-family: var(--font-mono); font-size: 10.5px; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--text-dim); pointer-events: none;
}
.hdr-status .sdot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--success);
  animation: sdot-pulse 2.6s var(--ease) infinite;
}
@keyframes sdot-pulse {
  0%   { box-shadow: 0 0 0 0 color-mix(in srgb, var(--success) 50%, transparent); }
  70%  { box-shadow: 0 0 0 7px color-mix(in srgb, var(--success) 0%, transparent); }
  100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--success) 0%, transparent); }
}

/* Côté droit du header : actions + pastilles fenêtre */
.hdr-right { display: flex; align-items: center; gap: 12px; -webkit-app-region: no-drag; }

/* Bouton-icône générique du header (toggle thème…) */
.icon-btn {
  width: 30px; height: 30px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--bg-elevated); color: var(--text-muted); cursor: pointer;
  -webkit-app-region: no-drag;
  transition: background var(--t-fast), color var(--t-fast), border-color var(--t-fast), transform var(--t-fast);
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); border-color: var(--border-hi); }
.icon-btn:active { transform: scale(0.92); }
.icon-btn svg { width: 16px; height: 16px; display: block; }

/* ═══════ WINDOW CONTROLS (macOS-style pastilles) ═══════ */
#win-controls {
  display: none; align-items: center; gap: 8px;
  -webkit-app-region: no-drag;
}
.win-btn {
  width: 13px; height: 13px; border-radius: 50%; border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 8px; line-height: 1; font-weight: 700; color: transparent;
  transition: color var(--t-fast), filter var(--t-fast), transform var(--t-fast);
}
#win-controls:hover .win-btn { color: rgba(0,0,0,0.55); }
.win-btn:active { transform: scale(0.86); }
#win-min   { background: #febc2e; }
#win-full  { background: #28c840; }
#win-close { background: #ff5f57; }
.win-btn:hover { filter: brightness(1.12); }
.win-btn--fullscreen-active { background: var(--accent) !important; }

/* ═══════ RESIZE HANDLES ═══════ */
.rh { position: fixed; z-index: 99999; background: transparent; }
.rh-n  { top: 0;    left: 6px;  right: 6px;  height: 5px; cursor: n-resize; }
.rh-s  { bottom: 0; left: 6px;  right: 6px;  height: 5px; cursor: s-resize; }
.rh-e  { right: 0;  top: 6px;   bottom: 6px; width: 5px;  cursor: e-resize; }
.rh-w  { left: 0;   top: 6px;   bottom: 6px; width: 5px;  cursor: w-resize; }
.rh-nw { top: 0; left: 0;     width: 10px; height: 10px; cursor: nw-resize; }
.rh-ne { top: 0; right: 0;    width: 10px; height: 10px; cursor: ne-resize; }
.rh-sw { bottom: 0; left: 0;  width: 10px; height: 10px; cursor: sw-resize; }
.rh-se { bottom: 0; right: 0; width: 10px; height: 10px; cursor: se-resize; }

/* ═══════ MODALS ═══════ */
.modal-overlay {
  position: fixed; inset: 0; z-index: 9999;
  display: flex; align-items: center; justify-content: center;
  background: rgba(1,4,9,0.66);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.modal-box {
  background: var(--glass-el);
  backdrop-filter: blur(18px) saturate(1.1);
  -webkit-backdrop-filter: blur(18px) saturate(1.1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 26px 28px 22px;
  min-width: 340px; max-width: 460px;
  box-shadow: var(--shadow-lg);
  animation: modal-in 0.2s var(--ease-spring) both;
}
.modal-title { font-size: 16px; font-weight: 700; margin-bottom: 8px; }
.modal-body { font-size: 13px; color: var(--text-muted); line-height: 1.6; margin-bottom: 20px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }
@keyframes modal-in {
  from { opacity: 0; transform: scale(0.95) translateY(-8px); }
  to   { opacity: 1; transform: none; }
}

/* Utilitaires */
.mono { font-family: var(--font-mono); font-feature-settings: "tnum"; }
.muted { color: var(--text-muted); }
.dim { color: var(--text-dim); }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

/* ═══════ FOCUS VISIBLE ═══════ */
/* Contour OPAQUE ≥3:1 (audit S5-04 : le halo seul était à ~1.15:1, invisible). */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; box-shadow: var(--ring); border-radius: var(--radius-sm); }
button:focus-visible, a:focus-visible, .nav-item:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; box-shadow: var(--ring); }

::selection { background: var(--accent-soft); color: var(--text); }

/* ═══════ MOUVEMENT RÉDUIT — coupe les animations d'accent ═══════ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
  #bgfx .neb, #hdr::after, .hdr-status .sdot { animation: none !important; }
}
