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

:root {
  --bg-base:     #080c14;
  --bg-surface:  #0f1623;
  --bg-elevated: #161e2e;
  --bg-hover:    #1c2638;
  --border:      #1e2d45;
  --border-light:#243450;
  --accent:      #4f8ef7;
  --accent-glow: rgba(79,142,247,0.25);
  --accent2:     #7c3aed;
  --success:     #22c55e;
  --warning:     #f59e0b;
  --danger:      #ef4444;
  --text-primary:#e2e8f0;
  --text-muted:  #64748b;
  --text-faint:  #334155;
  --font-mono:   'Space Mono', monospace;
  --font-sans:   'DM Sans', sans-serif;
  --radius:      8px;
  --radius-lg:   12px;
  --shadow:      0 4px 24px rgba(0,0,0,0.4);
}

html, body { height: 100%; }
body {
  font-family: var(--font-sans);
  background: var(--bg-base);
  color: var(--text-primary);
  overflow: hidden;
}

/* ===== LAYOUT ===== */
.app-shell {
  display: flex;
  height: 100vh;
}

/* ===== SIDEBAR ===== */
.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 24px 0;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 20px 28px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}
.logo-icon {
  font-size: 24px;
  color: var(--accent);
  line-height: 1;
}
.logo-text {
  font-family: var(--font-sans);
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.4;
  letter-spacing: 0.05em;
}
.logo-text strong { color: var(--text-primary); font-size: 14px; }

.nav { flex: 1; padding: 8px 12px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
  user-select: none;
  margin-bottom: 2px;
}
.nav-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.nav-item.active {
  background: linear-gradient(135deg, rgba(79,142,247,0.15), rgba(124,58,237,0.1));
  color: var(--accent);
  border: 1px solid rgba(79,142,247,0.25);
}
.nav-icon { font-size: 14px; width: 18px; text-align: center; }

.sidebar-footer {
  padding: 16px 20px 0;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}
.status-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--text-faint);
  transition: background 0.3s;
}
.status-dot.active { background: var(--success); box-shadow: 0 0 6px var(--success); }

/* ===== MAIN CONTENT ===== */
.main-content {
  flex: 1;
  overflow-y: auto;
  padding: 40px 48px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

/* ===== SECTIONS ===== */
.section { display: none; animation: fadeIn 0.2s ease; }
.section.active { display: block; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.section-header { margin-bottom: 32px; }
.section-header h1 {
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.5px;
  color: var(--text-primary);
}
.subtitle { color: var(--text-muted); font-size: 14px; margin-top: 4px; }

/* ===== CARDS ===== */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  margin-bottom: 16px;
}
.card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 16px;
}

/* ===== UPLOAD ZONE ===== */
.upload-zone {
  border: 2px dashed var(--border-light);
  border-radius: var(--radius-lg);
  padding: 60px 40px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  background: var(--bg-surface);
}
.upload-zone:hover, .upload-zone.drag-over {
  border-color: var(--accent);
  background: rgba(79,142,247,0.05);
}
.upload-icon { font-size: 36px; margin-bottom: 12px; opacity: 0.5; }
.upload-text { font-size: 16px; font-weight: 500; color: var(--text-primary); }
.upload-sub { font-size: 13px; color: var(--text-muted); margin-top: 4px; }

.upload-status {
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 8px 0;
}
.upload-status.success { color: var(--success); }
.upload-status.error { color: var(--danger); }
.upload-status.loading { color: var(--accent); }

/* ===== STATS GRID ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 20px;
  position: relative;
  overflow: hidden;
}
.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
}
.stat-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.08em; }
.stat-value { font-size: 26px; font-weight: 700; font-family: var(--font-mono); color: var(--text-primary); margin-top: 4px; }
.stat-sub { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

/* ===== TABS ===== */
.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 0;
  border-bottom: 1px solid var(--border);
}
.tab {
  padding: 10px 18px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: all 0.15s;
  margin-bottom: -1px;
}
.tab:hover { color: var(--text-primary); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.tab-panel { border-top: none; border-radius: 0 0 var(--radius-lg) var(--radius-lg); }

/* ===== TABLES ===== */
.data-table, .table-scroll table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.data-table th, .table-scroll th {
  text-align: left;
  padding: 8px 12px;
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-bottom: 1px solid var(--border);
}
.data-table td, .table-scroll td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 12px;
}
.data-table tr:last-child td, .table-scroll tr:last-child td { border-bottom: none; }
.data-table tr:hover td, .table-scroll tr:hover td { background: var(--bg-hover); }
.table-scroll { overflow-x: auto; }
.stats-scroll { overflow-x: auto; max-height: 400px; overflow-y: auto; }

.dtype-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-family: var(--font-mono);
  background: var(--bg-elevated);
  color: var(--accent);
  border: 1px solid var(--border);
}

/* ===== MISSING BARS ===== */
.missing-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
  font-size: 12px;
}
.missing-col { width: 160px; flex-shrink: 0; color: var(--text-primary); font-family: var(--font-mono); truncate; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.missing-bar-wrap { flex: 1; height: 6px; background: var(--bg-elevated); border-radius: 3px; overflow: hidden; }
.missing-bar { height: 100%; border-radius: 3px; background: linear-gradient(90deg, var(--accent), var(--accent2)); transition: width 0.5s; }
.missing-pct { width: 45px; text-align: right; color: var(--text-muted); flex-shrink: 0; }

/* ===== CONTROLS ===== */
.controls-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 16px;
}
.control-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
  min-width: 140px;
}
.control-group label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
}
.hint { font-weight: 400; color: var(--text-faint); text-transform: none; letter-spacing: 0; }

select, input[type="text"], input[type="number"] {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 13px;
  padding: 8px 12px;
  outline: none;
  transition: border-color 0.15s;
  width: 100%;
}
select:focus, input:focus { border-color: var(--accent); }
select[multiple] { padding: 4px; }
select[multiple] option {
  padding: 5px 8px;
  border-radius: 4px;
}
select[multiple] option:checked {
  background: linear-gradient(rgba(79,142,247,0.2), rgba(79,142,247,0.2));
  color: var(--accent);
}

input[type="range"] {
  padding: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

/* ===== BUTTONS ===== */
.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 10px 20px;
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  white-space: nowrap;
}
.btn-primary:hover { opacity: 0.9; transform: translateY(-1px); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn-primary.full-width { width: 100%; margin-top: 8px; padding: 12px; }

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 9px 18px;
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-secondary:hover { background: rgba(79,142,247,0.1); }

.btn-ghost {
  background: none;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 14px;
  font-family: var(--font-sans);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-ghost:hover { border-color: var(--border-light); color: var(--text-primary); }

.feature-actions {
  display: flex;
  gap: 8px;
  margin-top: 6px;
}

/* ===== PLOT ===== */
.plot-container {
  min-height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.plot-empty {
  color: var(--text-faint);
  font-size: 14px;
  text-align: center;
}
.plot-container img {
  max-width: 100%;
  border-radius: var(--radius);
  display: block;
  margin: 0 auto;
}

/* ===== TRAIN ===== */
.train-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.metrics-display {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
}
.metric-item {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 20px;
  min-width: 140px;
  position: relative;
}
.metric-item::after {
  content: '';
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--success), #16a34a);
  border-radius: 0 0 var(--radius) var(--radius);
}
.metric-name { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.07em; }
.metric-value { font-size: 28px; font-weight: 700; font-family: var(--font-mono); color: var(--success); margin-top: 2px; }

.task-badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 16px;
}
.task-badge.classification { background: rgba(99,102,241,0.15); color: #818cf8; border: 1px solid rgba(99,102,241,0.3); }
.task-badge.regression { background: rgba(245,158,11,0.15); color: #fbbf24; border: 1px solid rgba(245,158,11,0.3); }

.model-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* ===== PREDICT ===== */
.predict-inputs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
}

.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}
.empty-state p { margin-bottom: 16px; }

.prediction-result {
  text-align: center;
  padding: 32px;
  border-color: var(--accent);
  background: linear-gradient(135deg, rgba(79,142,247,0.08), rgba(124,58,237,0.08));
}
.prediction-label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.1em; }
.prediction-value {
  font-size: 48px;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--accent);
  margin-top: 8px;
  word-break: break-all;
}

/* ===== TOAST ===== */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 20px;
  font-size: 13px;
  color: var(--text-primary);
  box-shadow: var(--shadow);
  transform: translateY(80px);
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  z-index: 1000;
  max-width: 320px;
}
.toast.show { transform: translateY(0); opacity: 1; }
.toast.success { border-color: var(--success); }
.toast.error { border-color: var(--danger); }

/* ===== LOADING SPINNER ===== */
@keyframes spin { to { transform: rotate(360deg); } }
.spinner {
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: middle;
  margin-right: 6px;
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-light); }