/* ═══════════════════════════════════════════════════
   Universal CSV Analytics — style.css
   Dark-first design with glassmorphism, animations,
   sidebar layout, and full light-mode support.
═══════════════════════════════════════════════════ */

/* ── CSS Variables ── */
:root {
  --bg:        #000000;
  --bg-2:      #09090b;
  --bg-3:      #18181b;
  --card:      rgba(24, 24, 27, 0.75);
  --border:    rgba(14, 165, 233, 0.25);
  --text:      #f8fafc;
  --text-2:    #cbd5e1;
  --text-muted:#94a3b8;
  --primary:   #0ea5e9;
  --primary-2: #0284c7;
  --purple:    #8b5cf6;
  --green:     #10b981;
  --amber:     #f59e0b;
  --red:       #ef4444;
  --cyan:      #06b6d4;
  --sidebar-w: 220px;
  --topbar-h:  60px;
  --shadow:    0 8px 32px rgba(0, 0, 0, 0.6);
  --radius:    14px;
  --radius-sm: 8px;
  --grad:      linear-gradient(135deg, #0ea5e9 0%, #38bdf8 100%);
  --font:      'Inter', system-ui, sans-serif;
  --font-h:    'Outfit', system-ui, sans-serif;
  --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="light"] {
  --bg:        #f0f4ff;
  --bg-2:      #e8edf8;
  --bg-3:      #dde3f0;
  --card:      rgba(255, 255, 255, 0.80);
  --border:    rgba(0, 0, 0, 0.08);
  --text:      #0f172a;
  --text-2:    #334155;
  --text-muted:#64748b;
  --shadow:    0 4px 20px rgba(15, 23, 42, 0.10);
}

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

html { scroll-behavior: smooth; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  display: flex;
  min-height: 100vh;
  overflow-x: hidden;
  transition: background var(--transition), color var(--transition);
}

/* ── Utilities ── */
.hidden   { display: none !important; }
.mb-3     { margin-bottom: 1.75rem; }
.gradient-text {
  background: var(--grad);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* ── Glassmorphism ── */
.glassmorphism {
  background: var(--card);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--border);
}

.glass-card {
  background: var(--card);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
  transition: transform var(--transition), box-shadow var(--transition);
}
.glass-card:hover { transform: translateY(-2px); box-shadow: 0 12px 40px rgba(0,0,0,0.5); }

/* ════════════════════════════════════════
   SIDEBAR
════════════════════════════════════════ */
.sidebar {
  position: fixed;
  top: 0; left: 0;
  width: var(--sidebar-w);
  height: 100vh;
  background: rgba(10, 15, 30, 0.95);
  border-right: 1px solid var(--border);
  backdrop-filter: blur(20px);
  display: flex;
  flex-direction: column;
  z-index: 200;
  transition: transform var(--transition);
}

[data-theme="light"] .sidebar {
  background: rgba(255,255,255,0.92);
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 1.4rem 1.5rem;
  font-family: var(--font-h);
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text);
  border-bottom: 1px solid var(--border);
}
.sidebar-logo i { color: var(--primary); font-size: 1.5rem; }

.sidebar-nav {
  flex: 1;
  padding: 1rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
}
.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 1rem;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  transition: all var(--transition);
  cursor: pointer;
}
.nav-item i { font-size: 1.1rem; width: 1.25rem; text-align: center; }
.nav-item:hover  { background: rgba(59,130,246,0.1); color: var(--text); }
.nav-item.active { background: rgba(59,130,246,0.15); color: var(--primary); border: 1px solid rgba(59,130,246,0.2); }
.nav-item.disabled { opacity: 0.35; pointer-events: none; }

.sidebar-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
}

.btn-icon-lg {
  background: rgba(59,130,246,0.1);
  border: 1px solid rgba(59,130,246,0.2);
  color: var(--text-2);
  width: 40px; height: 40px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1.1rem;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition);
}
.btn-icon-lg:hover { background: var(--primary); color: #fff; }

/* ════════════════════════════════════════
   MAIN WRAPPER
════════════════════════════════════════ */
.main-wrapper {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  transition: margin-left var(--transition);
}

/* ── Topbar ── */
.topbar {
  position: sticky;
  top: 0;
  height: var(--topbar-h);
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  z-index: 100;
  border-bottom: 1px solid var(--border);
}

.sidebar-toggle {
  background: none; border: none; color: var(--text-2);
  font-size: 1.4rem; cursor: pointer;
  display: flex; align-items: center;
  transition: color var(--transition);
}
.sidebar-toggle:hover { color: var(--primary); }

.topbar-title {
  flex: 1;
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text-muted);
}

.topbar-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* ── Pages ── */
.page { display: none; padding: 2rem 2.5rem; animation: fadeUp 0.45s ease forwards; }
.page.active { display: block; }

/* ════════════════════════════════════════
   UPLOAD PAGE
════════════════════════════════════════ */
.upload-hero {
  max-width: 760px;
  margin: 2rem auto;
  text-align: center;
}

.hero-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: rgba(59,130,246,0.12);
  border: 1px solid rgba(59,130,246,0.3);
  color: var(--primary);
  padding: 0.3rem 0.85rem;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.4px;
  margin-bottom: 1.25rem;
}

.hero-title {
  font-family: var(--font-h);
  font-size: clamp(2.2rem, 5vw, 3.2rem);
  font-weight: 800;
  line-height: 1.15;
  margin-bottom: 1rem;
}

.hero-subtitle {
  font-size: 1.05rem;
  color: var(--text-muted);
  margin-bottom: 1.5rem;
  max-width: 580px;
  margin-inline: auto;
}

.feature-pills {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
  margin-bottom: 2rem;
}
.pill {
  background: var(--bg-3);
  border: 1px solid var(--border);
  padding: 0.3rem 0.75rem;
  border-radius: 999px;
  font-size: 0.82rem;
  color: var(--text-2);
  display: flex; align-items: center; gap: 0.35rem;
}
.pill i { color: var(--primary); }

/* Drop Zone */
.drop-zone {
  border: 2px dashed rgba(59,130,246,0.45);
  border-radius: var(--radius);
  padding: 3rem 2rem;
  cursor: pointer;
  transition: all var(--transition);
  background: rgba(59,130,246,0.03);
  position: relative;
}
.drop-zone.dragover {
  border-color: var(--primary);
  background: rgba(59,130,246,0.1);
  transform: scale(1.015);
}
.drop-zone-inner { display: flex; flex-direction: column; align-items: center; gap: 0.6rem; }

.drop-icon-wrap {
  width: 80px; height: 80px;
  background: rgba(59,130,246,0.1);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 0.5rem;
  animation: pulse 3s infinite;
}
.drop-icon { font-size: 2.5rem; color: var(--primary); }

.upload-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

.alert-error {
  background: rgba(239,68,68,0.12);
  border: 1px solid rgba(239,68,68,0.3);
  color: #fca5a5;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  margin-top: 1rem;
  font-size: 0.9rem;
}

/* ════════════════════════════════════════
   LOADING PAGE
════════════════════════════════════════ */
.loading-center {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  min-height: calc(100vh - var(--topbar-h));
  gap: 1rem; text-align: center;
}

.loader-ring {
  width: 64px; height: 64px;
  position: relative; margin-bottom: 0.5rem;
}
.loader-ring div {
  position: absolute;
  width: 100%; height: 100%;
  border: 4px solid transparent;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
.loader-ring div:nth-child(2) { animation-delay: -0.25s; border-top-color: var(--purple); }
.loader-ring div:nth-child(3) { animation-delay: -0.5s; border-top-color: var(--cyan); width:80%;height:80%;top:10%;left:10%; }
.loader-ring div:nth-child(4) { animation-delay: -0.75s; border-top-color: var(--amber); width:60%;height:60%;top:20%;left:20%; }

.loading-steps {
  display: flex; flex-wrap: wrap; justify-content: center;
  gap: 0.5rem; margin-top: 1.5rem;
}
.step {
  display: flex; align-items: center; gap: 0.4rem;
  background: var(--bg-3);
  border: 1px solid var(--border);
  padding: 0.4rem 0.9rem;
  border-radius: 999px;
  font-size: 0.82rem;
  color: var(--text-muted);
  transition: all var(--transition);
}
.step.active {
  background: rgba(59,130,246,0.15);
  border-color: rgba(59,130,246,0.3);
  color: var(--primary);
}
.step.done {
  background: rgba(16,185,129,0.1);
  border-color: rgba(16,185,129,0.3);
  color: var(--green);
}

/* ════════════════════════════════════════
   DASHBOARD LAYOUT
════════════════════════════════════════ */
.dash-section { display: none; }
.dash-section.active { display: block; animation: fadeUp 0.4s ease; }

.section-header {
  display: flex; justify-content: space-between;
  align-items: flex-start; flex-wrap: wrap;
  gap: 1rem; margin-bottom: 1.75rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}
.section-header h2 {
  font-family: var(--font-h); font-size: 1.5rem;
  font-weight: 700; color: var(--text);
  display: flex; align-items: center; gap: 0.6rem;
}
.section-header h2 i { color: var(--primary); }

.header-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* Dataset Info Row */
.dataset-info-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
}
.info-chip {
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  display: flex; flex-direction: column; gap: 0.25rem;
}
.info-chip .chip-label { font-size: 0.78rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }
.info-chip .chip-value { font-size: 1.1rem; font-weight: 600; color: var(--text); font-family: var(--font-h); }

/* KPI Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 1.25rem;
}
.kpi-card {
  border-radius: var(--radius);
  padding: 1.4rem 1.25rem;
  display: flex; flex-direction: column; gap: 0.75rem;
  position: relative; overflow: hidden;
  cursor: default;
  transition: transform var(--transition), box-shadow var(--transition);
}
.kpi-card::before {
  content: "";
  position: absolute; inset: 0;
  opacity: 0.07;
  background: var(--kpi-color, var(--primary));
  border-radius: inherit;
}
.kpi-card:hover { transform: translateY(-3px); box-shadow: 0 16px 40px rgba(0,0,0,0.4); }

.kpi-icon {
  width: 40px; height: 40px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.3rem;
  background: rgba(255,255,255,0.08);
  color: var(--kpi-color, var(--primary));
  flex-shrink: 0;
}
.kpi-label {
  font-size: 0.78rem; text-transform: uppercase;
  letter-spacing: 0.6px; color: var(--text-muted); font-weight: 500;
}
.kpi-value {
  font-family: var(--font-h);
  font-size: 1.7rem; font-weight: 700;
  color: var(--text); line-height: 1;
}

/* Health Card */
.health-card { display: flex; flex-wrap: wrap; gap: 2rem; align-items: center; }
.health-score-wrap {
  display: flex; flex-direction: column; align-items: center; gap: 0.4rem;
}
.health-score-number {
  font-family: var(--font-h); font-size: 3.5rem; font-weight: 800;
  line-height: 1;
}
.health-score-label { font-size: 0.82rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }
.health-details { flex: 1; display: flex; flex-direction: column; gap: 0.5rem; }
.health-row {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--bg-3); padding: 0.5rem 0.85rem;
  border-radius: var(--radius-sm); font-size: 0.88rem;
}
.health-row .badge-val {
  background: rgba(59,130,246,0.15);
  color: var(--primary); padding: 0.1rem 0.5rem;
  border-radius: 999px; font-size: 0.8rem; font-weight: 600;
}
.health-actions { flex: 1; display: flex; flex-direction: column; gap: 0.4rem; }
.suggestion-item {
  display: flex; align-items: flex-start; gap: 0.5rem;
  font-size: 0.85rem; color: var(--text-2);
  background: rgba(16,185,129,0.06); border: 1px solid rgba(16,185,129,0.15);
  padding: 0.5rem 0.75rem; border-radius: var(--radius-sm);
}
.suggestion-item i { color: var(--green); margin-top: 2px; flex-shrink: 0; }

/* Chart Grid */
.chart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 450px), 1fr));
  gap: 1.5rem;
}
.chart-card {
  background: var(--card);
  backdrop-filter: blur(14px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 0.75rem;
  box-shadow: var(--shadow);
  min-height: 420px;
  min-width: 0; /* allows shrinking below grid width */
  transition: transform var(--transition);
}
.chart-card:hover { transform: translateY(-2px); }
.chart-card.full-width { grid-column: 1 / -1; }

/* Preview Table */
.table-wrap { overflow-x: auto; }
.card-title {
  font-family: var(--font-h); font-size: 1rem; font-weight: 600;
  margin-bottom: 1rem; color: var(--text-2);
  display: flex; align-items: center; gap: 0.4rem;
}
.card-title i { color: var(--primary); }

.data-table {
  width: 100%; border-collapse: collapse; font-size: 0.83rem;
}
.data-table th {
  background: rgba(59,130,246,0.12);
  color: var(--primary); font-weight: 600;
  padding: 0.65rem 0.9rem; text-align: left;
  border-bottom: 1px solid rgba(59,130,246,0.2);
  white-space: nowrap; font-size: 0.78rem; letter-spacing: 0.3px;
}
.data-table td {
  padding: 0.55rem 0.9rem; color: var(--text-2);
  border-bottom: 1px solid var(--border);
  max-width: 200px; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: rgba(59,130,246,0.04); }

/* Stats Table */
.stats-content { overflow-x: auto; }
.stats-table {
  width: 100%; border-collapse: collapse; font-size: 0.82rem;
}
.stats-table th {
  background: var(--bg-3); color: var(--text-muted);
  font-weight: 600; font-size: 0.78rem; letter-spacing: 0.4px;
  padding: 0.6rem 0.8rem; text-align: right;
  border-bottom: 1px solid var(--border);
}
.stats-table th:first-child { text-align: left; color: var(--primary); }
.stats-table td {
  padding: 0.55rem 0.8rem; color: var(--text-2);
  border-bottom: 1px solid var(--border); text-align: right;
}
.stats-table td:first-child { text-align: left; color: var(--text); font-weight: 500; }
.stats-table tr:hover td { background: rgba(59,130,246,0.04); }

/* Insights */
.insights-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
  gap: 1.5rem;
}
.insight-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-left: 4px solid var(--amber);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
  transition: transform var(--transition);
  display: flex; flex-direction: column; gap: 1rem;
}
.insight-card:hover { transform: translateY(-2px); }

.insight-section-label {
  display: flex; align-items: center; gap: 0.5rem;
  font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.8px;
  font-weight: 700; color: var(--amber);
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

.insight-row {
  display: flex; flex-direction: column; gap: 0.2rem;
}
.insight-row-label {
  font-size: 0.72rem; text-transform: uppercase;
  letter-spacing: 0.5px; color: var(--text-muted); font-weight: 600;
}
.insight-row-text { font-size: 0.9rem; color: var(--text-2); line-height: 1.5; }
.insight-risk .insight-row-text {
  color: #fca5a5;
  background: rgba(239,68,68,0.06);
  border: 1px solid rgba(239,68,68,0.15);
  padding: 0.4rem 0.65rem; border-radius: var(--radius-sm);
}

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 0.45rem;
  padding: 0.55rem 1.1rem;
  border-radius: var(--radius-sm);
  border: none; cursor: pointer;
  font-family: var(--font); font-weight: 500; font-size: 0.88rem;
  transition: all var(--transition);
  white-space: nowrap;
}
.btn-sm { padding: 0.4rem 0.85rem; font-size: 0.82rem; }

.btn-primary {
  background: var(--grad);
  color: #fff;
  box-shadow: 0 4px 14px rgba(59,130,246,0.35);
}
.btn-primary:hover { box-shadow: 0 6px 20px rgba(59,130,246,0.55); transform: translateY(-1px); }

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-2);
}
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }

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

/* ════════════════════════════════════════
   ANIMATIONS
════════════════════════════════════════ */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(18px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(59,130,246,0.4); }
  50%       { box-shadow: 0 0 0 12px rgba(59,130,246,0); }
}

/* ════════════════════════════════════════
   RESPONSIVE — Sidebar Collapse
════════════════════════════════════════ */
@media (max-width: 900px) {
  :root { --sidebar-w: 0px; }
  .sidebar { transform: translateX(-220px); }
  .sidebar.open { transform: translateX(0); width: 220px; }
  .main-wrapper { margin-left: 0; }
  .chart-grid { grid-template-columns: 1fr; }
  .insights-grid { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
  .page { padding: 1.25rem 1rem; }
}
