/* ═══════════════════════════════════════════════════════════════
   SOFIA Dashboard — Custom theme (violet/pink + cyan IA accent)
   ═══════════════════════════════════════════════════════════════ */

:root {
  --tblr-primary: #8b5cf6;
  --tblr-primary-rgb: 139, 92, 246;
  --tblr-primary-hover: #7c3aed;
  /* Brand gradient principal : violet → rose */
  --brand-grad: linear-gradient(135deg, #8b5cf6 0%, #ec4899 100%);
  --brand-grad-soft: linear-gradient(135deg, rgba(139,92,246,.15) 0%, rgba(236,72,153,.15) 100%);
  /* AI accent : cyan électrique pour signaler le côté IA / tech / circuit */
  --ai-accent: #06b6d4;
  --ai-accent-bright: #22d3ee;
  --ai-grad: linear-gradient(135deg, #8b5cf6 0%, #06b6d4 100%);
  /* Logo SOFIA = violet → cyan (signal IA) */
  --sofia-grad: linear-gradient(90deg, #8b5cf6 0%, #ec4899 50%, #06b6d4 100%);
}

/* Style pour le nom SOFIA quand affiché en logo / titre */
.sofia-name {
  font-weight: 800;
  letter-spacing: 0.15em;
  background: var(--sofia-grad);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  font-variant-numeric: tabular-nums;
}

/* AI badge — petite pastille cyan qui signale "IA active" */
.ai-badge {
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(6, 182, 212, 0.12);
  border: 1px solid rgba(6, 182, 212, 0.35);
  color: #22d3ee;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.4px;
}
.ai-badge::before {
  content: '';
  width: 6px; height: 6px;
  background: #22d3ee;
  border-radius: 50%;
  box-shadow: 0 0 8px #22d3ee;
  animation: ai-pulse 2s ease-in-out infinite;
}
@keyframes ai-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.8); }
}

[data-bs-theme="dark"] {
  --tblr-bg-surface: #0f1014;
  --tblr-bg-surface-secondary: #181a21;
}

body[data-bs-theme="dark"] {
  background: radial-gradient(ellipse at 20% 0%, rgba(139,92,246,.08), transparent 60%),
              radial-gradient(ellipse at 80% 100%, rgba(236,72,153,.06), transparent 60%),
              #0b0c10;
}

/* Brand gradient text & avatars */
.brand-text {
  background: var(--brand-grad);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  font-weight: 700;
}
.brand-bg { background: var(--brand-grad); color: white; }
.brand-bg-soft { background: var(--brand-grad-soft); }

/* Cards : subtle glow & glass */
.card {
  border-radius: 14px !important;
  border: 1px solid rgba(255,255,255,.05) !important;
  backdrop-filter: blur(8px);
  transition: transform .15s ease, box-shadow .15s ease;
}
.card:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 24px rgba(139,92,246,.15);
}
.card-header {
  border-bottom-color: rgba(255,255,255,.05) !important;
}

/* KPI cards */
.kpi-card .h1 {
  background: var(--brand-grad);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* Buttons */
.btn-primary {
  background: var(--brand-grad);
  border: none;
  font-weight: 500;
}
.btn-primary:hover { filter: brightness(1.1); }

/* Sidebar nav active */
.navbar-nav .nav-link.active,
.navbar-nav .nav-item.active .nav-link {
  background: var(--brand-grad-soft);
  border-radius: 8px;
  color: #c4b5fd !important;
}

/* Tables : cleaner rows */
.table-vcenter td, .table-vcenter th { padding: .75rem 1rem; }
.table > tbody > tr:hover { background: rgba(139,92,246,.05); }

/* Status badges custom */
.badge.bg-red-lt    { background: rgba(239,68,68,.15) !important; color: #fca5a5 !important; }
.badge.bg-blue-lt   { background: rgba(99,102,241,.15) !important; color: #a5b4fc !important; }
.badge.bg-green-lt  { background: rgba(34,197,94,.15) !important; color: #86efac !important; }
.badge.bg-orange-lt { background: rgba(249,115,22,.15) !important; color: #fdba74 !important; }
.badge.bg-purple-lt { background: rgba(168,85,247,.15) !important; color: #d8b4fe !important; }
.badge.bg-yellow-lt { background: rgba(234,179,8,.15) !important; color: #fde047 !important; }
.badge.bg-secondary-lt { background: rgba(148,163,184,.15) !important; color: #cbd5e1 !important; }

/* Avatar gradient default */
.avatar.brand-avatar { background: var(--brand-grad); color: white; }

/* Page title gradient bar */
.page-title-glow {
  position: relative;
  display: inline-block;
}
.page-title-glow::after {
  content: ''; position: absolute; left: 0; bottom: -4px;
  width: 32px; height: 3px;
  background: var(--brand-grad);
  border-radius: 3px;
}

/* Chat container — hauteur stable cross-platform */
.chat-container {
  height: calc(100vh - 220px);
  /* 100dvh = "dynamic viewport height" — gère bien la barre URL mobile */
  height: calc(100dvh - 220px);
  min-height: 400px;
}
@media (max-width: 768px) {
  .chat-container {
    /* Plein écran sur mobile — utilise dvh pour gérer la barre URL Safari/Chrome */
    height: calc(100dvh - 130px);
    border-radius: 0 !important;
    border-left: 0 !important;
    border-right: 0 !important;
    margin-left: -12px;
    margin-right: -12px;
  }
  .chat-container .card-body {
    padding: 12px !important;
  }
  .chat-container .card-footer {
    /* Sticky input bar en bas, respecte safe-area iPhone */
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom)) 12px !important;
    background: rgba(11, 13, 26, .92);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    position: sticky;
    bottom: 0;
  }
  #chat-input {
    font-size: 16px !important; /* >=16px = pas de zoom auto iOS */
    border-radius: 22px !important;
    padding: 10px 14px !important;
  }
  #chat-mic, #chat-send {
    min-width: 44px; min-height: 44px; /* Apple HIG : cibles tactiles >=44px */
    border-radius: 50% !important;
    padding: 0 !important;
  }
  #chat-mic { font-size: 18px; }
  #chat-send #chat-send-label { display: none; } /* sur mobile, juste l'icône */
  #chat-send::before {
    content: '➤'; font-size: 18px;
  }
}

/* ──────────────────────────────────────────────────────────────
   PWA STANDALONE MODE — masque les éléments inutiles, gère le notch
   ────────────────────────────────────────────────────────────── */
@media all and (display-mode: standalone) {
  body {
    /* Safe area top (notch iPhone) + bottom (home indicator) */
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    background: #0b0d1a; /* couleur splash pour transition fluide */
  }
  /* Masque le bouton "Installer SOFIA" si déjà installé */
  #pwa-install-btn { display: none !important; }
  /* Bord du chat plein écran */
  .chat-container { border-radius: 0 !important; border: 0 !important; }
}

/* iOS standalone uniquement : la status bar est translucide en black-translucent.
   On ajoute le padding pour ne pas que le titre passe sous l'horloge. */
@supports (-webkit-touch-callout: none) {
  @media all and (display-mode: standalone) {
    .page-header { padding-top: calc(env(safe-area-inset-top) + 8px) !important; }
  }
}

/* Chat bubbles */
.msg-bubble {
  max-width: 75%;
  padding: 10px 14px;
  border-radius: 14px;
  margin-bottom: 8px;
  word-wrap: break-word;
  white-space: pre-wrap;
  line-height: 1.5;
}
.msg-user {
  background: var(--brand-grad);
  color: white;
  margin-left: auto;
  border-bottom-right-radius: 4px;
}
.msg-assistant {
  background: rgba(255,255,255,.06);
  color: #e2e8f0;
  margin-right: auto;
  border-bottom-left-radius: 4px;
}
.msg-meta {
  font-size: 11px;
  color: #6b7280;
  margin: 2px 8px 8px;
}

/* Command palette modal */
#cmdk-modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.6); backdrop-filter: blur(8px);
  z-index: 9999; display: none; align-items: flex-start; justify-content: center;
  padding-top: 12vh;
}
#cmdk-modal.show { display: flex; }
#cmdk-box {
  width: min(560px, 90vw); background: #1a1c24; border: 1px solid rgba(255,255,255,.08);
  border-radius: 16px; box-shadow: 0 24px 80px rgba(0,0,0,.5);
  overflow: hidden;
}
#cmdk-input {
  width: 100%; padding: 16px 20px; background: transparent; border: 0; outline: none;
  color: white; font-size: 16px;
  border-bottom: 1px solid rgba(255,255,255,.05);
}
#cmdk-results { max-height: 50vh; overflow-y: auto; padding: 8px; }
.cmdk-item {
  padding: 10px 14px; border-radius: 8px; cursor: pointer; color: #e2e8f0;
  display: flex; align-items: center; gap: 12px;
}
.cmdk-item:hover, .cmdk-item.active { background: rgba(139,92,246,.15); }
.cmdk-section { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #6b7280; padding: 8px 14px 4px; }

/* FAB quick add */
.fab {
  position: fixed; bottom: 24px; right: 24px;
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--brand-grad);
  color: white; font-size: 24px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 8px 24px rgba(139,92,246,.4);
  cursor: pointer; border: none; z-index: 100;
  transition: transform .15s ease;
}
.fab:hover { transform: scale(1.05) rotate(90deg); }

/* Loading shimmer */
@keyframes shimmer { 0% { background-position: -200% 0 } 100% { background-position: 200% 0 } }
.shimmer {
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.05), transparent);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}

/* Empty state */
.empty-state { text-align: center; padding: 48px 16px; color: #6b7280; }
.empty-state-icon { font-size: 48px; margin-bottom: 12px; opacity: .4; }

/* Scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(139,92,246,.2); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: rgba(139,92,246,.4); }

/* ─────────────────────────────────────────────────────────────
   MOBILE OPTIMISATIONS
   ─────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  /* Réduction des paddings globaux */
  .container-xl { padding-left: 12px !important; padding-right: 12px !important; }
  .page-header { padding-top: 12px; padding-bottom: 12px; }
  .page-title { font-size: 1.4rem !important; }
  .page-pretitle { font-size: 0.7rem; }

  /* Cartes plus compactes */
  .card-body { padding: 16px !important; }
  .card-header { padding: 12px 16px !important; }
  .card-header .card-title { font-size: 1rem; }

  /* KPIs (h1 chiffres) — pas trop gros */
  .row-deck .h1, .h1.mb-0 { font-size: 1.6rem; }

  /* Tables : passe en bloc scrollable horizontalement ET ajuste */
  .table-responsive { -webkit-overflow-scrolling: touch; }
  .table { font-size: 0.85rem; }
  .table td, .table th { padding: 8px 10px; }
  .table .btn-sm { padding: 4px 8px; font-size: 0.75rem; }

  /* Chat bubbles plus larges sur mobile */
  .msg-bubble { max-width: 88%; padding: 10px 12px; font-size: 14px; }
  .msg-meta { font-size: 10px; }

  /* FAB plus accessible (pas dans la zone gestures iOS) */
  .fab { bottom: 16px; right: 16px; width: 48px; height: 48px; font-size: 20px; }

  /* Header navbar : la marque + avatar restent visibles */
  .navbar-brand .brand-text { font-size: 1.1rem; }

  /* Modals + cmdk : plein écran sur mobile */
  #cmdk-modal { padding-top: 5vh; padding-left: 12px; padding-right: 12px; }
  #cmdk-box { width: 100%; }

  /* Forms : labels + inputs un peu plus aérés */
  .form-control, .form-select { font-size: 16px !important; } /* 16px = empêche le zoom iOS au focus */

  /* Stats stacker */
  .row-cards > [class*="col-"] { margin-bottom: 12px; }
}

/* Très petits écrans (iPhone SE et similaires) */
@media (max-width: 380px) {
  .page-title { font-size: 1.2rem !important; }
  .card-body { padding: 12px !important; }
  .table { font-size: 0.78rem; }
  .navbar-brand .brand-text { display: none; }
}

/* Tablette / paysage : un peu plus compact que desktop */
@media (min-width: 768px) and (max-width: 1024px) {
  .container-xl { padding-left: 20px; padding-right: 20px; }
}

/* ─────────────────────────────────────────────────────────────
   PRO LOCKS — affichage des features réservées aux Pro
   ─────────────────────────────────────────────────────────── */
.pro-locked {
  position: relative;
  opacity: 0.55;
  filter: saturate(0.4);
  cursor: pointer;
  transition: opacity .2s;
}
.pro-locked:hover {
  opacity: 0.75;
}
.pro-locked::after {
  content: '🔒 Pro';
  position: absolute;
  top: 8px; right: 8px;
  background: linear-gradient(135deg, #8b5cf6, #ec4899);
  color: white;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.3px;
  box-shadow: 0 4px 12px rgba(139, 92, 246, .35);
  z-index: 5;
  pointer-events: none;
}
/* Override pour les éléments inline-block */
.pro-locked.inline-pro {
  display: inline-block;
}
.pro-locked.inline-pro::after {
  top: -8px; right: -8px;
  padding: 2px 6px;
  font-size: 9px;
}

/* Modal d'upgrade */
#pro-upgrade-modal {
  position: fixed; inset: 0; z-index: 99999;
  display: none;
  align-items: center; justify-content: center;
  padding: 16px;
}
#pro-upgrade-modal.open { display: flex; }
.pum-overlay {
  position: absolute; inset: 0;
  background: rgba(10, 11, 16, 0.85);
  backdrop-filter: blur(12px);
}
.pum-card {
  position: relative;
  max-width: 440px; width: 100%;
  background: #14161f;
  border: 1px solid rgba(139, 92, 246, 0.3);
  border-radius: 20px;
  padding: 32px 28px;
  text-align: center;
  box-shadow: 0 24px 80px rgba(139, 92, 246, 0.2);
}
.pum-icon {
  font-size: 64px;
  margin-bottom: 12px;
}
.pum-title {
  font-size: 26px; font-weight: 800;
  background: linear-gradient(135deg, #c4b5fd, #f9a8d4);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 8px;
}
.pum-text {
  color: #94a3b8;
  font-size: 14px;
  margin-bottom: 20px;
  line-height: 1.5;
}
.pum-list {
  background: rgba(139, 92, 246, 0.06);
  border: 1px solid rgba(139, 92, 246, 0.15);
  border-radius: 12px;
  padding: 16px 20px;
  margin-bottom: 24px;
  text-align: left;
  list-style: none;
  font-size: 13px;
  color: #cbd5e1;
}
.pum-list li {
  padding: 4px 0;
}
.pum-actions {
  display: flex; flex-direction: column; gap: 10px;
}
.pum-btn {
  display: block;
  padding: 12px 20px;
  border-radius: 10px;
  font-weight: 600;
  text-decoration: none;
  font-size: 14px;
  cursor: pointer;
  border: none;
  text-align: center;
  transition: all .15s;
}
.pum-btn-primary {
  background: linear-gradient(135deg, #8b5cf6, #ec4899);
  color: white;
  box-shadow: 0 6px 20px rgba(139, 92, 246, .3);
}
.pum-btn-primary:hover {
  transform: translateY(-1px);
  filter: brightness(1.05);
  color: white;
}
.pum-btn-ghost {
  background: transparent;
  color: #94a3b8;
  border: 1px solid rgba(255,255,255,.1);
}
.pum-btn-ghost:hover {
  color: #e2e8f0;
}

/* Bannière "Passe en Pro" pour les free users */
.pro-banner {
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.12), rgba(236, 72, 153, 0.08));
  border: 1px solid rgba(139, 92, 246, 0.3);
  border-radius: 12px;
  padding: 14px 20px;
  margin-bottom: 20px;
  display: flex; align-items: center; gap: 14px;
  flex-wrap: wrap;
}
.pro-banner .pb-icon { font-size: 24px; }
.pro-banner .pb-text { flex-grow: 1; font-size: 13px; color: #cbd5e1; min-width: 200px; }
.pro-banner .pb-text strong { color: #c4b5fd; }
.pro-banner .pb-cta {
  background: linear-gradient(135deg, #8b5cf6, #ec4899);
  color: white;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  transition: transform .1s;
  white-space: nowrap;
}
.pro-banner .pb-cta:hover {
  transform: translateY(-1px);
  color: white;
}
