/* ============================================================
   L'Affaire Dashboard — Premium Dark Theme
   ============================================================ */

/* ---------- Design Tokens ---------- */
:root {
  --color-bg: #0a0e1a;
  --color-surface: #121829;
  --color-surface-2: #1a2236;
  --color-surface-glass: rgba(18, 24, 41, 0.75);
  --color-border: rgba(255, 255, 255, 0.06);
  --color-border-glow: rgba(99, 102, 241, 0.25);
  --color-text: #e8eaf6;
  --color-text-muted: #8b93b8;
  --color-text-dim: #5a6386;
  --color-blue: #6366f1;
  --color-cyan: #22d3ee;
  --color-green: #10b981;
  --color-purple: #a855f7;
  --color-orange: #f59e0b;
  --color-red: #ef4444;
  --color-pink: #ec4899;
  --color-meta: #1877f2;
  --color-google: #34a853;
  --color-apple: #a2aaad;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --shadow-card: 0 4px 24px rgba(0, 0, 0, 0.35), 0 1px 3px rgba(0, 0, 0, 0.2);
  --shadow-card-hover: 0 8px 40px rgba(0, 0, 0, 0.5), 0 2px 6px rgba(0, 0, 0, 0.25);
  --transition-fast: 0.18s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-smooth: 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ============================================================
   1. Reset & Base
   ============================================================ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
  position: relative;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 50% at 20% 40%, rgba(99, 102, 241, 0.08) 0%, transparent 60%),
    radial-gradient(ellipse 60% 40% at 80% 60%, rgba(34, 211, 238, 0.05) 0%, transparent 55%),
    radial-gradient(ellipse 50% 30% at 50% 90%, rgba(168, 85, 247, 0.04) 0%, transparent 50%);
  pointer-events: none;
  z-index: 0;
  animation: bgPulse 12s ease-in-out infinite alternate;
}

@keyframes bgPulse {
  0%   { opacity: 0.6; transform: scale(1); }
  50%  { opacity: 1;   transform: scale(1.05); }
  100% { opacity: 0.7; transform: scale(0.98); }
}

/* ============================================================
   2. Loading Overlay
   ============================================================ */
.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-bg);
  transition: opacity var(--transition-smooth), visibility var(--transition-smooth);
}

.loading-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ============================================================
   3. Header
   ============================================================ */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 32px;
  background: var(--color-surface-glass);
  backdrop-filter: blur(20px) saturate(1.4);
  -webkit-backdrop-filter: blur(20px) saturate(1.4);
  border-bottom: 1px solid var(--color-border);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

.logo-icon { font-size: 1.5rem; }

.logo-img {
  height: 38px;
  width: auto;
  border-radius: 8px;
  object-fit: contain;
  transition: transform var(--transition-fast), filter var(--transition-fast);
}

.logo-img:hover {
  transform: scale(1.08);
  filter: drop-shadow(0 0 8px rgba(99, 102, 241, 0.4));
}

.logo-text {
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  background: linear-gradient(135deg, var(--color-blue), var(--color-cyan));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border-radius: 999px;
  background: rgba(99, 102, 241, 0.12);
  color: var(--color-blue);
  border: 1px solid rgba(99, 102, 241, 0.2);
}

.badge-heart {
  background: rgba(239, 68, 68, 0.12);
  color: var(--color-red);
  border: 1px solid rgba(239, 68, 68, 0.2);
  text-decoration: none;
  cursor: pointer;
  font-size: 0.8rem;
  padding: 4px 8px;
  justify-content: center;
  transition: background var(--transition-fast), border-color var(--transition-fast), transform var(--transition-fast), box-shadow var(--transition-fast);
}

.badge-heart:hover {
  background: rgba(239, 68, 68, 0.25);
  border-color: rgba(239, 68, 68, 0.45);
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(239, 68, 68, 0.25);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.status-dot, .header-live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-text-dim);
  flex-shrink: 0;
  transition: background var(--transition-fast);
}

.status-text, .header-live-text {
  font-size: 0.78rem;
  color: var(--color-text-muted);
}

.status-dot.live {
  background: var(--color-green);
  box-shadow: 0 0 8px rgba(16, 185, 129, 0.5);
  animation: pulse 2s ease-in-out infinite;
}

.status-dot.error {
  background: var(--color-red);
  box-shadow: 0 0 8px rgba(239, 68, 68, 0.5);
  animation: pulse 1.2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: 0.5; transform: scale(1.3); }
}

/* Date inputs generic */
.date-input {
  font-family: 'Inter', sans-serif;
  font-size: 0.82rem;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  background: var(--color-surface-2);
  color: var(--color-text);
  color-scheme: dark;
  outline: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.date-input:focus {
  border-color: var(--color-blue);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}
.date-sep {
  color: var(--color-text-dim);
  font-size: 0.85rem;
}
.filter-dates {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

/* ============================================================
   4. Global Filter Bar
   ============================================================ */
.global-filter {
  position: relative;
  z-index: 50;
  padding: 16px 32px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}



.filter-presets {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: 8px;
}

.preset-btn {
  font-family: 'Inter', sans-serif;
  font-size: 0.75rem;
  font-weight: 500;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--color-border);
  background: transparent;
  color: var(--color-text-muted);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.preset-btn:hover {
  background: rgba(99, 102, 241, 0.08);
  color: var(--color-text);
  border-color: var(--color-border-glow);
}

.preset-btn.active {
  background: var(--color-blue);
  color: #fff;
  border-color: var(--color-blue);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-family: 'Inter', sans-serif;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  background: var(--color-surface-2);
  color: var(--color-text);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
  user-select: none;
}

.btn:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: var(--color-border-glow);
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0);
}

.btn-primary {
  background: var(--color-blue);
  color: #fff;
  border-color: var(--color-blue);
}

.btn-primary:hover {
  background: #5558e6;
  border-color: #5558e6;
  box-shadow: 0 4px 16px rgba(99, 102, 241, 0.3);
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--color-text-muted);
}

.btn-ghost:hover {
  background: rgba(255, 255, 255, 0.04);
  color: var(--color-text);
  border-color: transparent;
}

.btn-sm {
  font-size: 0.75rem;
  padding: 6px 12px;
}

.btn-icon {
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: var(--radius-sm);
  font-size: 1rem;
}

.btn-icon.active-filter {
  background: rgba(245, 158, 11, 0.12);
  color: var(--color-orange);
  border-color: rgba(245, 158, 11, 0.3);
}

/* ============================================================
   5. Tab Navigation
   ============================================================ */
.tab-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 32px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.tab-nav::-webkit-scrollbar {
  display: none;
}

.tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: 'Inter', sans-serif;
  font-size: 0.82rem;
  font-weight: 500;
  padding: 8px 18px;
  border-radius: 999px;
  border: 1px solid var(--color-border);
  background: transparent;
  color: var(--color-text-muted);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
  user-select: none;
  flex-shrink: 0;
}

.tab-btn:hover {
  background: rgba(99, 102, 241, 0.06);
  color: var(--color-text);
  border-color: var(--color-border-glow);
}

.tab-btn.active {
  background: var(--color-blue);
  color: #fff;
  border-color: var(--color-blue);
  box-shadow: 0 2px 12px rgba(99, 102, 241, 0.25);
}

/* ============================================================
   6. Tab Sections
   ============================================================ */
.tab-section {
  position: relative;
  z-index: 1;
}

.tab-section.hidden {
  display: none;
}

/* ============================================================
   7. Cards
   ============================================================ */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-card);
  transition: transform var(--transition-smooth), box-shadow var(--transition-smooth), border-color var(--transition-smooth);
  position: relative;
  overflow: hidden;
}

.card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-card-hover);
  border-color: var(--color-border-glow);
}

/* Summary Cards Grid — 6 columns */
.summary-cards {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 16px;
  padding: 24px 32px;
}

/* Summary Cards Grid — 4 columns variant */
.summary-cards-4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  padding: 24px 32px;
}

.summary-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 20px;
  position: relative;
  overflow: hidden;
  transition: transform var(--transition-smooth), box-shadow var(--transition-smooth), border-color var(--transition-smooth);
}

.summary-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--accent, var(--color-blue));
  border-radius: var(--radius-md) var(--radius-md) 0 0;
}

.summary-card::after {
  content: '';
  position: absolute;
  top: -40px;
  right: -40px;
  width: 100px;
  height: 100px;
  border-radius: 50%;
  background: radial-gradient(circle, var(--accent, var(--color-blue)) 0%, transparent 70%);
  opacity: 0.06;
  pointer-events: none;
  transition: opacity var(--transition-smooth);
}

.summary-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-card-hover);
  border-color: var(--color-border-glow);
}

.summary-card:hover::after {
  opacity: 0.12;
}

.summary-icon {
  font-size: 1.75rem;
  margin-bottom: 8px;
}
.summary-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.summary-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-dim);
}
.summary-value {
  font-size: 1.65rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--color-text);
  line-height: 1.2;
}
.summary-delta {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  margin-top: 4px;
}
.card-delta { font-size: 0.75rem; }
.card-delta.positive { color: var(--color-green); }
.card-delta.negative { color: var(--color-red); }
.card-delta.neutral { color: var(--color-orange); }

/* ============================================================
   8. Charts Grid
   ============================================================ */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
  padding: 24px 32px;
}

.charts-grid .full-width {
  grid-column: 1 / -1;
}

.charts-grid .half-width {
  grid-column: span 1;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
}

.card-header h2,
.card-header h3 {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--color-text);
  letter-spacing: -0.01em;
}

.card-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Chart Legend */
.chart-legend-custom, .chart-legend {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 0.75rem;
  color: var(--color-text-muted);
}

.chart-legend-custom .legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  color: var(--color-text-muted);
}

.dot, .legend-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
  vertical-align: middle;
  margin-right: 3px;
}

/* Chart Containers */
.chart-container {
  position: relative;
  width: 100%;
  height: 280px;
}

.chart-container-lg {
  position: relative;
  width: 100%;
  height: 340px;
}

.chart-container canvas,
.chart-container-lg canvas {
  width: 100% !important;
  height: 100% !important;
}

/* ============================================================
   9. Per-chart Date Picker
   ============================================================ */
.chart-date-picker {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  margin-bottom: 16px;
  background: var(--color-surface-2);
  border: 1px solid rgba(245, 158, 11, 0.2);
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}

.chart-date-picker.hidden {
  display: none;
}

.chart-date-picker label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--color-text-muted);
  white-space: nowrap;
}

.chart-date-picker input[type="date"] {
  font-family: 'Inter', sans-serif;
  font-size: 0.78rem;
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid var(--color-border);
  background: var(--color-bg);
  color: var(--color-text);
  color-scheme: dark;
  outline: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.chart-date-picker input[type="date"]:focus {
  border-color: var(--color-orange);
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.12);
}

/* ============================================================
   10. Footer
   ============================================================ */
.footer, .dashboard-footer {
  text-align: center;
  padding: 24px 32px;
  border-top: 1px solid var(--color-border);
  color: var(--color-text-dim);
  font-size: 0.75rem;
  position: relative;
  z-index: 1;
}

/* ============================================================
   11. Animations — Staggered Fade-In
   ============================================================ */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.charts-grid .card {
  animation: fadeInUp 0.5s var(--transition-smooth) backwards;
}

.charts-grid .card:nth-child(1)  { animation-delay: 0.05s; }
.charts-grid .card:nth-child(2)  { animation-delay: 0.10s; }
.charts-grid .card:nth-child(3)  { animation-delay: 0.15s; }
.charts-grid .card:nth-child(4)  { animation-delay: 0.20s; }
.charts-grid .card:nth-child(5)  { animation-delay: 0.25s; }
.charts-grid .card:nth-child(6)  { animation-delay: 0.30s; }
.charts-grid .card:nth-child(7)  { animation-delay: 0.35s; }
.charts-grid .card:nth-child(8)  { animation-delay: 0.40s; }
.charts-grid .card:nth-child(9)  { animation-delay: 0.45s; }
.charts-grid .card:nth-child(10) { animation-delay: 0.50s; }
.charts-grid .card:nth-child(11) { animation-delay: 0.55s; }
.charts-grid .card:nth-child(12) { animation-delay: 0.60s; }

.summary-card {
  animation: fadeInUp 0.45s var(--transition-smooth) backwards;
}

.summary-card:nth-child(1) { animation-delay: 0.03s; }
.summary-card:nth-child(2) { animation-delay: 0.06s; }
.summary-card:nth-child(3) { animation-delay: 0.09s; }
.summary-card:nth-child(4) { animation-delay: 0.12s; }
.summary-card:nth-child(5) { animation-delay: 0.15s; }
.summary-card:nth-child(6) { animation-delay: 0.18s; }

/* ============================================================
   12. Responsive
   ============================================================ */

/* ≤ 1400px — 3 col summaries */
@media (max-width: 1400px) {
  .summary-cards {
    grid-template-columns: repeat(3, 1fr);
  }
  .summary-cards-4 {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ≤ 1000px — 2 col summaries, charts single col */
@media (max-width: 1000px) {
  .summary-cards {
    grid-template-columns: repeat(2, 1fr);
  }
  .summary-cards-4 {
    grid-template-columns: repeat(2, 1fr);
  }
  .charts-grid {
    grid-template-columns: 1fr;
  }
  .charts-grid .full-width,
  .charts-grid .half-width {
    grid-column: 1 / -1;
  }
}

/* ≤ 768px — full single-column stack */
@media (max-width: 768px) {
  .header, .dashboard-header {
    flex-direction: column;
    align-items: flex-start;
    padding: 14px 16px;
    gap: 10px;
  }

  .header-right {
    width: 100%;
    justify-content: flex-end;
  }

  .global-filter {
    padding: 14px 16px;
  }

  .filter-row {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .filter-presets {
    margin-left: 0;
    flex-wrap: wrap;
  }

  .tab-nav {
    padding: 10px 16px;
    gap: 6px;
  }

  .summary-cards,
  .summary-cards-4 {
    grid-template-columns: 1fr;
    padding: 16px;
    gap: 12px;
  }

  .charts-grid {
    grid-template-columns: 1fr;
    padding: 16px;
    gap: 14px;
  }

  .card {
    padding: 18px;
  }

  .summary-value {
    font-size: 1.35rem;
  }

  .chart-container {
    height: 220px;
  }

  .chart-container-lg {
    height: 280px;
  }

  .footer, .dashboard-footer {
    padding: 18px 16px;
  }
}

/* ============================================================
   Utility: Selection & Scrollbar
   ============================================================ */
::selection {
  background: rgba(99, 102, 241, 0.3);
  color: #fff;
}

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.14);
}
