/* ==============================================================================
   PLANIF_AI - SYSTÈME DE DESIGN & TOKENS DE BASE (Inter & Palette Pro)
   ============================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

:root,
[data-theme="dark"] {
  /* Nuances sombres luxueuses (Par défaut en mode sombre) */
  --bg-primary: #090d16;
  --bg-secondary: #0f172a;
  --bg-card: #1e293b;
  --bg-card-hover: #27354f;
  --bg-translucent: rgba(30, 41, 59, 0.7);
  --bg-navbar: rgba(15, 23, 42, 0.88);
  --bg-modal: #0f172a;
  --bg-input: #1e293b;

  /* Tokens Apple Frosted Glassmorphism (Mode Sombre) */
  --navbar-glass-bg: rgba(8, 12, 22, 0.1);
  --navbar-glass-blur: 18px;
  --navbar-glass-saturate: 120%;
  --navbar-border: rgba(255, 255, 255, 0.08);
  --navbar-shadow: 0 4px 30px rgba(0, 0, 0, 0.08);

  /* Accents Haute Précision & Élégance (Palette Executive Saphir Cobalt & Cyan Givré) */
  --accent-cyan: #38bdf8;
  --accent-primary: #2563eb;
  --accent-cobalt: #1d4ed8;
  --accent-indigo: #3b82f6;
  --accent-teal: #06b6d4;
  --accent-gradient: linear-gradient(135deg, #1d4ed8 0%, #2563eb 50%, #0ea5e9 100%);
  --accent-gradient-hover: linear-gradient(135deg, #1e40af 0%, #1d4ed8 50%, #0284c7 100%);

  /* Statuts temporels d'intervention */
  --status-upcoming: #3b82f6;       /* Bleu (À venir) */
  --status-upcoming-bg: rgba(59, 130, 246, 0.12);
  --status-inprogress: #f97316;     /* Orange (En cours) */
  --status-inprogress-bg: rgba(249, 115, 22, 0.14);
  --status-completed: #10b981;      /* Vert / Gris neutre (Terminé) */
  --status-completed-bg: rgba(16, 185, 129, 0.12);

  /* Couleurs de statut système */
  --color-success: #10b981;
  --color-warning: #f59e0b;
  --color-danger: #ef4444;
  --color-info: #0ea5e9;

  /* Typographie & Contraste */
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;

  /* Bordures & Ombres */
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-hover: rgba(255, 255, 255, 0.22);
  --border-focus: rgba(37, 99, 235, 0.5);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 24px rgba(37, 99, 235, 0.25);

  /* Tables & Modales */
  --table-header-bg: #0f172a;
  --table-row-hover: rgba(255, 255, 255, 0.03);
  --modal-overlay-bg: rgba(0, 0, 0, 0.75);
  --access-box-bg: rgba(245, 158, 11, 0.08);
  --access-box-border: rgba(245, 158, 11, 0.25);
  --access-box-text: #fde68a;
  --login-bg: radial-gradient(circle at top center, #0f2744 0%, #07090e 80%);

  /* Rayons de courbure */
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-full: 9999px;

  /* Transitions */
  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

/* ==============================================================================
   MODE CLAIR (LIGHT THEME - Design épuré, haute lisibilité & contraste parfait)
   ============================================================================== */
[data-theme="light"] {
  --bg-primary: #f8fafc;
  --bg-secondary: #ffffff;
  --bg-card: #ffffff;
  --bg-card-hover: #f1f5f9;
  --bg-translucent: rgba(255, 255, 255, 0.88);
  --bg-navbar: rgba(255, 255, 255, 0.94);
  --bg-modal: #ffffff;
  --bg-input: #ffffff;

  /* Tokens Apple Frosted Glassmorphism (Mode Clair) */
  --navbar-glass-bg: rgba(255, 255, 255, 0.1);
  --navbar-glass-blur: 18px;
  --navbar-glass-saturate: 120%;
  --navbar-border: rgba(203, 213, 225, 0.6);
  --navbar-shadow: 0 4px 30px rgba(0, 0, 0, 0.08);

  --accent-cyan: #0284c7;
  --accent-primary: #2563eb;
  --accent-cobalt: #1d4ed8;
  --accent-indigo: #2563eb;
  --accent-teal: #0891b2;
  --accent-gradient: linear-gradient(135deg, #1e40af 0%, #2563eb 50%, #0284c7 100%);
  --accent-gradient-hover: linear-gradient(135deg, #172554 0%, #1e40af 50%, #0369a1 100%);

  --status-upcoming: #2563eb;
  --status-upcoming-bg: #eff6ff;
  --status-inprogress: #ea580c;
  --status-inprogress-bg: #fff7ed;
  --status-completed: #059669;
  --status-completed-bg: #ecfdf5;

  --color-success: #059669;
  --color-warning: #d97706;
  --color-danger: #dc2626;
  --color-info: #0284c7;

  --text-main: #0f172a;
  --text-muted: #475569;
  --text-dim: #94a3b8;

  --border-subtle: #e2e8f0;
  --border-hover: #cbd5e1;
  --border-focus: rgba(37, 99, 235, 0.5);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 16px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.12);
  --shadow-glow: 0 0 24px rgba(37, 99, 235, 0.15);

  --table-header-bg: #f8fafc;
  --table-row-hover: #f1f5f9;
  --modal-overlay-bg: rgba(15, 23, 42, 0.55);
  --access-box-bg: #fffbeb;
  --access-box-border: #fcd34d;
  --access-box-text: #92400e;
  --login-bg: radial-gradient(circle at top center, #e0f2fe 0%, #f8fafc 80%);
}

/* Prise en compte automatique de la préférence système de l'OS si non forcé */
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg-primary: #f8fafc;
    --bg-secondary: #ffffff;
    --bg-card: #ffffff;
    --bg-card-hover: #f1f5f9;
    --bg-translucent: rgba(255, 255, 255, 0.88);
    --bg-navbar: rgba(255, 255, 255, 0.94);
    --bg-modal: #ffffff;
    --bg-input: #ffffff;

    /* Tokens Apple Frosted Glassmorphism (Préférence Système Clair) */
    --navbar-glass-bg: rgba(255, 255, 255, 0.1);
    --navbar-glass-blur: 18px;
    --navbar-glass-saturate: 120%;
    --navbar-border: rgba(203, 213, 225, 0.6);
    --navbar-shadow: 0 4px 30px rgba(0, 0, 0, 0.08);

    --accent-cyan: #0284c7;
    --accent-primary: #2563eb;
    --accent-cobalt: #1d4ed8;
    --accent-indigo: #2563eb;
    --accent-teal: #0891b2;
    --accent-gradient: linear-gradient(135deg, #1e40af 0%, #2563eb 50%, #0284c7 100%);
    --accent-gradient-hover: linear-gradient(135deg, #172554 0%, #1e40af 50%, #0369a1 100%);

    --status-upcoming: #2563eb;
    --status-upcoming-bg: #eff6ff;
    --status-inprogress: #ea580c;
    --status-inprogress-bg: #fff7ed;
    --status-completed: #059669;
    --status-completed-bg: #ecfdf5;

    --color-success: #059669;
    --color-warning: #d97706;
    --color-danger: #dc2626;
    --color-info: #0284c7;

    --text-main: #0f172a;
    --text-muted: #475569;
    --text-dim: #94a3b8;

    --border-subtle: #e2e8f0;
    --border-hover: #cbd5e1;
    --border-focus: rgba(37, 99, 235, 0.5);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05), 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 4px 16px rgba(15, 23, 42, 0.08);
    --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.12);
    --shadow-glow: 0 0 24px rgba(37, 99, 235, 0.15);

    --table-header-bg: #f8fafc;
    --table-row-hover: #f1f5f9;
    --modal-overlay-bg: rgba(15, 23, 42, 0.55);
    --access-box-bg: #fffbeb;
    --access-box-border: #fcd34d;
    --access-box-text: #92400e;
    --login-bg: radial-gradient(circle at top center, #e0f2fe 0%, #f8fafc 80%);
  }
}

/* Reset & Normalisation */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-main);
  min-height: 100vh;
  line-height: 1.5;
  font-feature-settings: "cv02", "cv03", "cv04", "cv11";
  overflow-x: clip;
}

/* Typographie */
h1, h2, h3, h4, h5, h6 {
  font-weight: 700;
  color: var(--text-main);
  letter-spacing: -0.02em;
}

p {
  color: var(--text-muted);
}

a {
  color: var(--accent-cyan);
  text-decoration: none;
  transition: color var(--transition-fast);
}

a:hover {
  color: #7dd3fc;
}

/* Boutons universels */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.65rem 1.25rem;
  font-size: 0.925rem;
  font-weight: 600;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--transition-normal);
  user-select: none;
  text-decoration: none;
  white-space: nowrap;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--accent-gradient);
  color: #ffffff;
  box-shadow: 0 4px 14px rgba(37, 99, 235, 0.35);
}

.btn-primary:hover {
  background: var(--accent-gradient-hover);
  box-shadow: 0 6px 20px rgba(37, 99, 235, 0.5);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-main);
  border-color: var(--border-subtle);
}

.btn-secondary:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-hover);
}

.btn-danger {
  background: rgba(239, 68, 68, 0.15);
  color: #fca5a5;
  border-color: rgba(239, 68, 68, 0.3);
}

.btn-danger:hover {
  background: rgba(239, 68, 68, 0.25);
  border-color: var(--color-danger);
}

.btn-outline {
  background: transparent;
  color: var(--text-main);
  border-color: var(--border-subtle);
}

.btn-outline:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-hover);
}

/* Bouton Universel de Bascule Thème Clair / Sombre */
.btn-theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: var(--radius-full);
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  cursor: pointer;
  font-size: 1.15rem;
  transition: all var(--transition-normal);
  box-shadow: var(--shadow-sm);
  outline: none;
  user-select: none;
  flex-shrink: 0;
}

.btn-theme-toggle:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-hover);
  transform: scale(1.08) rotate(15deg);
  box-shadow: var(--shadow-md);
}

.btn-theme-toggle:active {
  transform: scale(0.92);
}

/* Badges & Tags */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.65rem;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: var(--radius-full);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.badge-upcoming {
  background: var(--status-upcoming-bg);
  color: var(--status-upcoming);
  border: 1px solid rgba(59, 130, 246, 0.3);
}

.badge-inprogress {
  background: var(--status-inprogress-bg);
  color: var(--status-inprogress);
  border: 1px solid rgba(249, 115, 22, 0.3);
  animation: pulse-badge 2s infinite ease-in-out;
}

.badge-completed {
  background: var(--status-completed-bg);
  color: var(--status-completed);
  border: 1px solid rgba(16, 185, 129, 0.3);
}

@keyframes pulse-badge {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.75; transform: scale(1.03); }
}

/* Pastilles de statut PWA Admin */
.status-indicator {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  font-weight: 500;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-dot.green {
  background-color: var(--color-success);
  box-shadow: 0 0 10px var(--color-success);
}

.status-dot.yellow {
  background-color: var(--color-warning);
  box-shadow: 0 0 10px var(--color-warning);
}

.status-dot.red {
  background-color: var(--color-danger);
  box-shadow: 0 0 10px var(--color-danger);
}

/* Formulaires & Champs de saisie */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 1.1rem;
}

.form-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-main);
}

.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 0.7rem 0.95rem;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  font-size: 0.95rem;
  font-family: inherit;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
}

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

/* Modale Universelle */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--modal-overlay-bg);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 2000;
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition-normal);
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modal-container {
  background: var(--bg-modal);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg), var(--shadow-glow);
  width: 100%;
  max-width: 620px;
  max-height: 90vh;
  overflow-y: auto;
  transform: translateY(20px) scale(0.98);
  transition: all var(--transition-normal);
}

.modal-overlay.active .modal-container {
  transform: translateY(0) scale(1);
}

.modal-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  font-size: 1.15rem;
  font-weight: 700;
}

.modal-close {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
  padding: 0.25rem;
  transition: color var(--transition-fast);
}

.modal-close:hover {
  color: var(--text-main);
}

.modal-body {
  padding: 1.5rem;
}

.modal-footer {
  padding: 1.25rem 1.5rem;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
}

/* Toast Notifications Système */
.toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  z-index: 2500;
}

.toast {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-left: 4px solid var(--accent-cyan);
  padding: 0.85rem 1.2rem;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  color: var(--text-main);
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  animation: slideInToast 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  max-width: 360px;
}

.toast.success { border-left-color: var(--color-success); }
.toast.error { border-left-color: var(--color-danger); }
.toast.warning { border-left-color: var(--color-warning); }

@keyframes slideInToast {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* Micro-animations Audio Waveform pour la saisie vocale */
.audio-waves {
  display: flex;
  align-items: center;
  gap: 4px;
  height: 24px;
}

.audio-bar {
  width: 4px;
  height: 100%;
  background: var(--accent-cyan);
  border-radius: 2px;
  animation: wave 1s infinite ease-in-out;
}

.audio-bar:nth-child(1) { animation-delay: 0.0s; height: 35%; }
.audio-bar:nth-child(2) { animation-delay: 0.2s; height: 75%; }
.audio-bar:nth-child(3) { animation-delay: 0.4s; height: 100%; }
.audio-bar:nth-child(4) { animation-delay: 0.1s; height: 60%; }
.audio-bar:nth-child(5) { animation-delay: 0.3s; height: 40%; }

@keyframes wave {
  0%, 100% { transform: scaleY(0.3); }
  50% { transform: scaleY(1); }
}

/* Responsive Mobile Modals (Transformation Bottom Sheet fluide) */
@media (max-width: 768px) {
  .modal-overlay {
    padding: 0;
    align-items: flex-end;
  }

  .modal-container {
    max-width: 100%;
    width: 100%;
    max-height: 86vh;
    border-radius: 20px 20px 0 0;
    margin: 0;
    transform: translateY(100%);
    box-shadow: 0 -12px 36px rgba(0, 0, 0, 0.6);
  }

  .modal-overlay.active .modal-container {
    transform: translateY(0);
  }

  .modal-header {
    padding: 1rem 1.25rem;
    position: sticky;
    top: 0;
    background: var(--bg-secondary);
    z-index: 10;
  }

  .modal-footer {
    position: sticky;
    bottom: 0;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-subtle);
    padding: 0.85rem 1.25rem;
    z-index: 10;
  }
}

