/* ============================================================
   DataDigest Portal — Styles Premium & Responsive
   ============================================================ */

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

/* ─── RESET & BASE ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* Shared Colors */
  --purple: #8b5cf6;
  --purple-light: #a78bfa;
  --purple-dim: rgba(139,92,246,0.15);
  --blue: #3b82f6;
  --green: #10b981;
  --yellow: #f59e0b;
  --red: #ef4444;
  --orange: #f97316;
  
  /* Dark Theme (Default) */
  --bg-root: #030305;
  --bg-card: rgba(18, 18, 31, 0.6);
  --bg-input: rgba(255,255,255,0.03);
  --bg-hover: rgba(255,255,255,0.04);
  --border: rgba(255,255,255,0.06);
  --border-hover: rgba(139,92,246,0.4);
  
  --text-primary: #f8f8f8;
  --text-muted: #a1a1aa;
  --text-dim: #71717a;
  
  --shadow: 0 20px 40px rgba(0,0,0,0.4);
  --glass-shadow: 0 24px 80px rgba(0,0,0,0.5), inset 0 1px 0 rgba(255,255,255,0.1);
  
  --radius: 20px;
  --radius-sm: 12px;
  --sidebar-w: 260px;
  --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="light"] {
  --bg-root: #f8fafc;
  --bg-card: rgba(255, 255, 255, 0.7);
  --bg-input: #ffffff;
  --bg-hover: rgba(0,0,0,0.03);
  --border: rgba(0,0,0,0.08);
  --border-hover: rgba(139,92,246,0.4);
  
  --text-primary: #0f172a;
  --text-muted: #64748b;
  --text-dim: #94a3b8;
  
  --shadow: 0 15px 35px rgba(148, 163, 184, 0.15);
  --glass-shadow: 0 20px 40px rgba(148, 163, 184, 0.1), inset 0 1px 0 rgba(255,255,255,0.5);
}

html { font-size: 15px; }

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg-root);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.4s ease, color 0.4s ease;
  overflow-x: hidden;
}

/* Background Noise */
body::before {
  content: '';
  position: fixed; inset: 0;
  background-image: 
    linear-gradient(var(--border) 1px, transparent 1px),
    linear-gradient(90deg, var(--border) 1px, transparent 1px);
  background-size: 40px 40px;
  pointer-events: none; z-index: 0; opacity: 0.3;
}

a { color: var(--purple-light); text-decoration: none; transition: color var(--transition); }
[data-theme="light"] a { color: var(--purple); }
a:hover { color: var(--text-primary); }

/* ─── LAYOUT AVEC SIDEBAR ──────────────────────────────────── */
.portal-layout {
  display: flex;
  min-height: 100vh;
  width: 100%;
  position: relative;
  z-index: 1;
}

/* ─── SIDEBAR ───────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-root);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: fixed; top: 0; left: 0; bottom: 0;
  z-index: 100; transition: transform var(--transition);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
}

.sidebar-logo {
  display: flex; align-items: center; gap: 12px;
  padding: 32px 24px; border-bottom: 1px solid var(--border);
}

.logo-icon {
  width: 36px; height: 36px; background: linear-gradient(135deg, var(--purple), var(--blue));
  border-radius: 10px; display: flex; align-items: center; justify-content: center;
  font-size: 18px; color: #fff; box-shadow: 0 4px 12px rgba(139,92,246,0.3);
}

.logo-text { font-size: 18px; font-weight: 800; color: var(--text-primary); letter-spacing: -0.02em; }

.sidebar-nav {
  flex: 1; padding: 24px 16px; display: flex; flex-direction: column; gap: 4px;
}

.nav-section-label {
  font-size: 10px; font-weight: 700; letter-spacing: 0.1em;
  text-transform: uppercase; color: var(--text-dim); padding: 16px 12px 8px;
}

.nav-item {
  display: flex; align-items: center; gap: 12px; padding: 10px 14px;
  border-radius: var(--radius-sm); color: var(--text-muted);
  font-size: 14px; font-weight: 500; cursor: pointer; transition: all var(--transition);
}
.nav-item:hover { background: var(--bg-hover); color: var(--text-primary); transform: translateX(4px); }
.nav-item.active { background: var(--purple-dim); color: var(--purple-light); border: 1px solid rgba(139,92,246,0.2); font-weight: 600; }
[data-theme="light"] .nav-item.active { color: var(--purple); }
.nav-item .nav-icon { font-size: 18px; width: 22px; text-align: center; transition: transform 0.3s;}
.nav-item:hover .nav-icon { transform: scale(1.1); }

.sidebar-footer { padding: 20px 16px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 8px; position: relative; }

/* ─── USER DROPDOWN ─────────────────────────────────────────── */
#user-dropdown { position: relative; }

.user-dropdown-menu {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0; right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: 0 -8px 32px rgba(0,0,0,0.4);
  backdrop-filter: blur(20px);
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  transform: translateY(6px);
  transition: opacity 0.18s ease, transform 0.18s ease;
  z-index: 200;
}

.user-dropdown-menu.open {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.dropdown-header {
  padding: 12px 14px 10px;
}

.dropdown-divider {
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  text-decoration: none;
}

.dropdown-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.dropdown-item span { font-size: 15px; width: 18px; text-align: center; flex-shrink: 0; }

.dropdown-danger { color: var(--red) !important; }
.dropdown-danger:hover { background: rgba(239,68,68,0.08) !important; color: var(--red) !important; }

.theme-toggle-btn {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: var(--radius-sm);
  cursor: pointer; color: var(--text-muted); font-size: 13px; font-weight: 500; transition: all var(--transition);
}
.theme-toggle-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

.user-pill {
  display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: var(--radius-sm);
  cursor: pointer; background: var(--bg-hover); border: 1px solid transparent; transition: all var(--transition);
}
.user-pill:hover { border-color: var(--border-hover); transform: translateY(-2px); box-shadow: var(--shadow);}

.user-avatar {
  width: 36px; height: 36px; border-radius: 10px; background: linear-gradient(135deg, var(--purple), var(--blue));
  display: flex; align-items: center; justify-content: center; font-size: 14px; font-weight: 800; color: #fff; flex-shrink: 0;
  box-shadow: 0 4px 10px rgba(139,92,246,0.3);
}

.user-info { flex: 1; min-width: 0; }
.user-name  { font-size: 13px; font-weight: 700; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-plan  { font-size: 11px; color: var(--text-muted); font-weight: 500; text-transform: capitalize; }

/* ─── MAIN CONTENT ───────────────── */
.main-content {
  margin-left: var(--sidebar-w);
  width: calc(100% - var(--sidebar-w));
  padding: 40px;
  max-width: 1200px;
}

/* ─── PAGE HEADER ───────────────────────────────────────────── */
.page-header { margin-bottom: 40px; }
.page-title { font-size: 32px; font-weight: 800; color: var(--text-primary); letter-spacing: -0.02em; }
.page-subtitle { font-size: 15px; color: var(--text-muted); margin-top: 6px; }

/* ─── SECTION TITLES ────────────────────────────────────────── */
.section-title {
  font-size: 20px; font-weight: 800; color: var(--text-primary);
  margin: 40px 0 20px 0; display: flex; align-items: center; justify-content: space-between;
}

/* ─── CARDS & GLASSMORPHISM ─────────────────────────────────── */
.card {
  background: var(--bg-card); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 32px;
  box-shadow: var(--glass-shadow); transition: transform 0.3s, border-color 0.3s;
  margin-bottom: 32px;
  overflow: hidden;
}
.card-sm { padding: 20px 24px; }

/* ─── FORMULAIRES ─────────────── */
.form-group { margin-bottom: 24px; max-width: 100%; }

label {
  display: block; font-size: 13px; font-weight: 600; color: var(--text-muted); margin-bottom: 8px; letter-spacing: 0.02em;
}

input[type="text"], input[type="email"], input[type="password"], input[type="url"], select, textarea {
  width: 100%; padding: 14px 18px;
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text-primary);
  font-size: 15px; font-family: inherit; outline: none;
  transition: all var(--transition);
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.1);
}

input:focus, select:focus, textarea:focus {
  border-color: var(--purple-light); background: var(--bg-card); box-shadow: 0 0 0 3px var(--purple-dim);
}
[data-theme="light"] input:focus, [data-theme="light"] select:focus, [data-theme="light"] textarea:focus { border-color: var(--purple); }

select { cursor: pointer; appearance: none; }
textarea { resize: vertical; min-height: 120px; line-height: 1.6; }
input::placeholder, textarea::placeholder { color: var(--text-dim); }

.form-hint { font-size: 12px; color: var(--text-dim); margin-top: 6px; }
.form-error { font-size: 12px; color: var(--red); margin-top: 6px; font-weight: 500;}

/* ─── BOUTONS ───────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 24px; border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 600; cursor: pointer;
  border: none; transition: all var(--transition);
  text-decoration: none; white-space: nowrap; font-family: inherit;
}

.btn-primary { background: linear-gradient(135deg, var(--purple), var(--blue)); color: #fff !important; box-shadow: 0 4px 14px rgba(124,58,237,0.4); border: 1px solid rgba(255,255,255,0.1); }
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(124,58,237,0.6); }

.btn-ghost { background: var(--bg-hover); color: var(--text-primary); border: 1px solid var(--border); backdrop-filter: blur(10px); }
.btn-ghost:hover { border-color: var(--border-hover); transform: translateY(-2px); box-shadow: var(--shadow); }

.btn-danger { background: rgba(239,68,68,0.1); color: var(--red); border: 1px solid rgba(239,68,68,0.2); }
.btn-danger:hover { background: rgba(239,68,68,0.2); color: #fff; transform: translateY(-2px); }

.btn-sm { padding: 8px 16px; font-size: 13px; border-radius: 8px;}

/* ─── STAT GRID ─────────────────────────────────────────────── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 20px; margin-bottom: 40px; }
.stat-card { background: var(--bg-card); backdrop-filter: blur(10px); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; transition: all var(--transition); }
.stat-card:hover { border-color: var(--border-hover); transform: translateY(-4px); box-shadow: var(--shadow); }
.stat-label { font-size: 12px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 12px; }
.stat-value { font-size: 36px; font-weight: 900; color: var(--text-primary); letter-spacing: -0.03em; line-height: 1; }
.stat-sub { font-size: 13px; color: var(--text-muted); margin-top: 8px; font-weight: 500;}

/* ─── TABLES ─────────────────────────────────────────────────── */
.table-wrap { 
  overflow-x: auto; 
  border-radius: var(--radius); 
  border: 1px solid var(--border); 
  background: var(--bg-card); 
  backdrop-filter: blur(20px); 
}
table { width: 100%; border-collapse: collapse; font-size: 14px; }
thead th { padding: 16px 20px; text-align: left; font-size: 11px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.1em; border-bottom: 1px solid var(--border); background: var(--bg-hover); }
tbody tr { border-bottom: 1px dashed var(--border); transition: background var(--transition); }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--bg-hover); }
td { padding: 16px 20px; color: var(--text-primary); vertical-align: middle; }

/* ─── PLAN CARDS (ABONNEMENT) ────────────────────────── */
.plans-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 24px; margin-bottom: 40px; }
.plan-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 40px 32px; position: relative; transition: all var(--transition); backdrop-filter: blur(20px); display: flex; flex-direction: column; min-height: 100%; }
.plan-card.current { border-color: var(--purple-light); box-shadow: 0 0 30px var(--purple-dim); }
[data-theme="light"] .plan-card.current { border-color: var(--purple); }
.plan-card.featured { transform: scale(1.03); background: linear-gradient(160deg, var(--bg-card) 0%, rgba(139,92,246,0.05) 100%); }
.plan-badge { position: absolute; top: -14px; left: 50%; transform: translateX(-50%); background: linear-gradient(135deg, var(--purple), var(--blue)); color: #fff; font-size: 11px; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; padding: 6px 20px; border-radius: 100px; white-space: nowrap; box-shadow: 0 4px 12px rgba(139,92,246,0.3); }
.plan-name { font-size: 16px; font-weight: 800; color: var(--purple-light); text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 12px; }
[data-theme="light"] .plan-name { color: var(--purple); }
.plan-price { font-size: 48px; font-weight: 900; color: var(--text-primary); letter-spacing: -2px; margin: 8px 0 4px; line-height: 1; display: flex; align-items: baseline; gap: 8px;}
.plan-price span { font-size: 16px; font-weight: 500; color: var(--text-muted); letter-spacing: 0; }
.plan-desc { font-size: 14px; color: var(--text-dim); margin-bottom: 24px; line-height: 1.5; }
.plan-features { list-style: none; display: flex; flex-direction: column; flex: 1; margin-bottom: 24px; }
.plan-features li { display: flex; align-items: flex-start; gap: 12px; font-size: 14px; color: var(--text-primary); font-weight: 400; padding: 12px 0; margin-bottom: 8px; border-bottom: 1px solid var(--border); }
.plan-features li:last-child { border-bottom: none; padding-bottom: 0; margin-bottom: 0;}
.plan-features li::before { content: '✓'; color: var(--green); font-weight: 900; font-size: 16px;}
.plan-features li.disabled { color: var(--text-dim); text-decoration: line-through; opacity: 0.7;}
.plan-features li.disabled::before { content: '✗'; color: var(--text-dim); font-weight: 400; }
.plan-card .btn-plan { margin-top: auto; }

/* ─── TOAST NOTIFICATIONS (RÉPARÉ) ───────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 9999;
}

.toast {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 18px;
  font-size: 13px;
  color: var(--text-primary);
  box-shadow: var(--glass-shadow);
  animation: slideIn 0.2s ease;
  max-width: 320px;
  backdrop-filter: blur(10px);
}

.toast.success { border-left: 3px solid var(--green); }
.toast.error   { border-left: 3px solid var(--red); }
.toast.info    { border-left: 3px solid var(--purple-light); }

@keyframes slideIn { 
  from { opacity: 0; transform: translateX(16px); } 
  to { opacity: 1; transform: none; } 
}

/* ─── POP-INS / MODALS (RÉPARÉ) ───────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  backdrop-filter: blur(4px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.modal {
  background: var(--bg-root);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  width: 100%;
  max-width: 480px;
  transform: translateY(12px);
  transition: transform 0.2s;
  box-shadow: var(--glass-shadow);
}

.modal-overlay.open .modal {
  transform: none;
}

.modal-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.modal-sub {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 24px;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 24px;
}

/* ─── ALERTS & ZONE DANGEREUSE ───────────────────────────────── */
.alert { padding: 16px 20px; border-radius: var(--radius-sm); font-size: 14px; display: flex; align-items: flex-start; gap: 12px; margin-bottom: 24px; background: var(--bg-card); border: 1px solid var(--border); }
.alert-error { background: rgba(239,68,68,0.05); border-color: rgba(239,68,68,0.2); color: #fca5a5; }
[data-theme="light"] .alert-error { color: #b91c1c; border-color: rgba(239,68,68,0.4); }

.zone-dangereuse { border: 1px solid rgba(239,68,68,0.3); border-radius: var(--radius); padding: 32px; background: rgba(239,68,68,0.02); margin-top: 40px; margin-bottom: 40px; }
.zone-dangereuse h3 { color: var(--red); font-size: 18px; margin-bottom: 12px;}
.zone-dangereuse p { color: var(--text-muted); font-size: 14px; margin-bottom: 20px;}

/* ─── BADGES ────────────────────────────────────────── */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px; border-radius: 100px; font-size: 12px; font-weight: 700; letter-spacing: 0.03em; }
.badge-green  { background: rgba(16,185,129,0.1);  color: var(--green);  border: 1px solid rgba(16,185,129,0.2); }
.badge-yellow { background: rgba(245,158,11,0.1);  color: var(--yellow); border: 1px solid rgba(245,158,11,0.2); }
.badge-red    { background: rgba(239,68,68,0.1);   color: var(--red);    border: 1px solid rgba(239,68,68,0.2); }
.badge-gray   { background: rgba(113,113,122,0.1); color: var(--text-muted); border: 1px solid rgba(113,113,122,0.2); }
.badge-blue   { background: rgba(59,130,246,0.1);  color: #60a5fa;       border: 1px solid rgba(59,130,246,0.2); }
.badge-purple { background: var(--purple-dim);     color: var(--purple-light); border: 1px solid rgba(139,92,246,0.25); }
[data-theme="light"] .badge-blue   { color: #2563eb; }
[data-theme="light"] .badge-purple { color: var(--purple); }

/* ─── ALERTS ─────────────────────────────────────────── */
.alert { padding: 14px 18px; border-radius: var(--radius-sm); font-size: 13px; display: flex; align-items: flex-start; gap: 10px; margin-bottom: 20px; line-height: 1.5; }
.alert-info    { background: rgba(59,130,246,0.08);  border: 1px solid rgba(59,130,246,0.2);  color: #93c5fd; }
.alert-success { background: rgba(16,185,129,0.08);  border: 1px solid rgba(16,185,129,0.2);  color: #6ee7b7; }
.alert-warning { background: rgba(245,158,11,0.08);  border: 1px solid rgba(245,158,11,0.2);  color: #fcd34d; }
.alert-error   { background: rgba(239,68,68,0.08);   border: 1px solid rgba(239,68,68,0.2);   color: #fca5a5; }
[data-theme="light"] .alert-info    { color: #1d4ed8; background: rgba(59,130,246,0.06);  }
[data-theme="light"] .alert-success { color: #065f46; background: rgba(16,185,129,0.06);  }
[data-theme="light"] .alert-warning { color: #92400e; background: rgba(245,158,11,0.06);  }
[data-theme="light"] .alert-error   { color: #991b1b; background: rgba(239,68,68,0.06);   }

/* ─── EMPTY STATE & LOADER ───────────────────────────────────────────── */
.empty-state { text-align: center; padding: 80px 24px; }
.empty-icon { font-size: 56px; margin-bottom: 20px; opacity: 0.8; }
.empty-title { font-size: 20px; font-weight: 700; color: var(--text-primary); margin-bottom: 10px; }
.empty-desc  { font-size: 15px; color: var(--text-muted); max-width: 400px; margin: 0 auto; line-height: 1.6;}

.loader { width: 24px; height: 24px; border: 3px solid var(--purple-dim); border-top-color: var(--purple); border-radius: 50%; animation: spin 0.8s cubic-bezier(0.4, 0, 0.2, 1) infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.page-loader { display: flex; align-items: center; justify-content: center; min-height: 300px; gap: 16px; color: var(--text-muted); font-size: 15px; font-weight: 500;}

/* ─── RESPONSIVE ────────────────────────────────────────────── */
@media (max-width: 992px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: none; }
  .main-content { margin-left: 0; width: 100%; padding: 30px; }
}
@media (max-width: 768px) {
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .main-content { padding: 20px; }
}

/* ─── UTILITAIRES DE BASE ───────────────────────────────────── */
.flex         { display: flex; }
.flex-center  { display: flex; align-items: center; justify-content: center; }
.gap-8        { gap: 8px; }
.gap-12       { gap: 12px; }
.gap-16       { gap: 16px; }
.mb-8         { margin-bottom: 8px; }
.mb-16        { margin-bottom: 16px; }
.mb-24        { margin-bottom: 24px; }
.mb-32        { margin-bottom: 32px; }
.mt-auto      { margin-top: auto; }
.text-muted   { color: var(--text-muted); }
.text-dim     { color: var(--text-dim); }
.text-danger  { color: var(--red); }
.text-sm      { font-size: 13px; }
.text-xs      { font-size: 11px; }
.font-bold    { font-weight: 700; }
.w-full       { width: 100%; }
.text-right   { text-align: right; }
.text-center  { text-align: center; }
.hidden       { display: none !important; }