/* InsightSerenity CSV Data Explorer — style.css */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=Space+Grotesk:wght@700;800&display=swap');

:root {
  --bg: #0f1117;
  --bg-card: #1a1d27;
  --bg-input: #13151f;
  --text: #f1f1f1;
  --text-muted: #9ca3af;
  --primary: #ffc451;
  --border: #2a2d3e;
  --radius: 0.75rem;
  --success: #34d399;
  --danger: #f87171;
}

*, *::before, *::after { box-sizing: border-box; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', sans-serif;
  margin: 0;
  min-height: 100vh;
}

/* ── Header ── */
.header {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 1rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-left h1 {
  font-size: 1rem;
  font-weight: 800;
  margin: 0;
  color: var(--text);
}

.header-left h1 span {
  color: var(--primary);
}

.header-left p {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin: 0.15rem 0 0;
}

.header-right {
  display: flex;
  gap: 0.625rem;
  align-items: center;
}

/* ── Container ── */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem;
}

/* ── Upload Zone ── */
.upload-zone {
  background: var(--bg-card);
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 3rem;
  text-align: center;
  margin-bottom: 1.5rem;
  transition: border-color 0.15s, background 0.15s;
  cursor: pointer;
}

.upload-zone:hover,
.upload-zone.dragover {
  border-color: var(--primary);
  background: rgba(255, 196, 81, 0.03);
}

.upload-icon {
  font-size: 2.5rem;
  margin-bottom: 0.75rem;
}

.upload-zone h3 {
  font-size: 0.95rem;
  font-weight: 700;
  margin: 0 0 0.5rem;
  color: var(--text);
}

.upload-zone p {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin: 0 0 1rem;
}

.or-divider {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 1rem 0;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.or-divider::before,
.or-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ── Buttons ── */
.btn-primary {
  background: var(--primary);
  color: #000;
  border: none;
  border-radius: 0.5rem;
  padding: 0.625rem 1.25rem;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s;
  font-family: 'Inter', sans-serif;
}

.btn-primary:hover {
  background: #e6b048;
}

.btn-ghost {
  background: transparent;
  color: var(--primary);
  border: 1px solid rgba(255, 196, 81, 0.3);
  border-radius: 0.5rem;
  padding: 0.625rem 1.25rem;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  font-family: 'Inter', sans-serif;
}

.btn-ghost:hover {
  background: rgba(255, 196, 81, 0.08);
  border-color: rgba(255, 196, 81, 0.5);
}

.parse-row {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  margin-top: 0.75rem;
}

/* ── Textarea ── */
.csv-textarea {
  width: 100%;
  height: 140px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 0.875rem;
  color: var(--text);
  font-size: 0.78rem;
  font-family: 'Courier New', monospace;
  box-sizing: border-box;
  outline: none;
  resize: vertical;
  transition: border-color 0.15s;
}

.csv-textarea:focus {
  border-color: var(--primary);
}

/* ── Error ── */
.error-msg {
  background: rgba(248, 113, 113, 0.1);
  border: 1px solid rgba(248, 113, 113, 0.3);
  border-radius: 0.5rem;
  padding: 0.75rem 1rem;
  color: var(--danger);
  font-size: 0.8rem;
  margin-bottom: 1rem;
  display: none;
}

/* ── Stats Bar ── */
.stats-bar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-pill {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  text-align: center;
}

.stat-pill .val {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--primary);
  font-family: 'Space Grotesk', sans-serif;
}

.stat-pill .lbl {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 0.25rem;
}

/* ── Section Cards ── */
.section-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

.section-card h2 {
  font-size: 0.875rem;
  font-weight: 700;
  margin: 0 0 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text);
}

.section-card h2 .badge {
  font-size: 0.65rem;
  font-weight: 700;
  background: rgba(255, 196, 81, 0.15);
  color: var(--primary);
  border-radius: 999px;
  padding: 0.15rem 0.5rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

/* ── Table ── */
.table-container {
  overflow-x: auto;
  max-height: 360px;
  overflow-y: auto;
  border-radius: 0.5rem;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.table-container::-webkit-scrollbar {
  height: 5px;
  width: 5px;
}

.table-container::-webkit-scrollbar-track {
  background: transparent;
}

.table-container::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
}

th {
  background: var(--bg-input);
  padding: 0.625rem 0.875rem;
  text-align: left;
  font-weight: 700;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  z-index: 1;
}

th:hover {
  color: var(--primary);
}

td {
  padding: 0.5rem 0.875rem;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  white-space: nowrap;
}

tr:last-child td {
  border-bottom: none;
}

tr:hover td {
  background: rgba(255, 255, 255, 0.02);
}

.sort-icon {
  margin-left: 0.25rem;
  color: var(--text-muted);
  font-size: 0.7rem;
}

th.asc .sort-icon::after { content: ' ▲'; color: var(--primary); }
th.desc .sort-icon::after { content: ' ▼'; color: var(--primary); }
th:not(.asc):not(.desc) .sort-icon::after { content: ' ⇅'; }

/* ── Column Stats ── */
.col-stats {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 0.75rem;
}

.col-stat-card {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 0.875rem;
}

.col-stat-name {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.col-stat-type {
  font-size: 0.65rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
  font-weight: 600;
  background: rgba(255,255,255,0.05);
  border-radius: 3px;
  padding: 1px 5px;
  display: inline-block;
}

.col-stat-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.72rem;
  padding: 0.1rem 0;
}

.col-stat-row .label {
  color: var(--text-muted);
}

.col-stat-row .value {
  color: var(--text);
  font-weight: 600;
}

/* ── Chart Controls ── */
.chart-controls {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  align-items: center;
}

.chart-controls label {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 600;
}

.chart-controls select {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 0.375rem 0.75rem;
  color: var(--text);
  font-size: 0.78rem;
  outline: none;
  font-family: 'Inter', sans-serif;
  cursor: pointer;
  transition: border-color 0.15s;
}

.chart-controls select:focus,
.chart-controls select:hover {
  border-color: var(--primary);
}

.chart-container {
  position: relative;
  height: 300px;
}

/* ── Hidden by default ── */
.data-section {
  display: none;
}

/* ── Back to Main ── */
.back-to-main {
  display: inline-flex;
  align-items: center;
  gap: .375rem;
  padding: .375rem .875rem;
  border: 1.5px solid rgba(255,196,81,0.3);
  border-radius: .5rem;
  font-size: .8125rem;
  font-weight: 600;
  color: #ffc451;
  background: rgba(255,196,81,0.08);
  text-decoration: none;
  transition: all .2s;
  white-space: nowrap;
}
.back-to-main:hover { background: #ffc451; color: #000; }

/* ── Format Toggle ── */
.format-toggle {
  display: inline-flex;
  gap: 0.375rem;
  margin: 0.75rem 0 0.5rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 0.25rem;
}

.fmt-btn {
  background: transparent;
  border: none;
  border-radius: 0.375rem;
  padding: 0.3rem 0.875rem;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-muted);
  cursor: pointer;
  font-family: 'Inter', sans-serif;
  transition: all 0.15s;
}
.fmt-btn.active {
  background: var(--primary);
  color: #000;
}
.fmt-btn:hover:not(.active) {
  color: var(--primary);
}

/* ── Data Toolbar ── */
.data-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center;
  margin-bottom: 1.25rem;
  padding: 0.875rem 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.toolbar-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.limit-btns {
  display: flex;
  gap: 0.25rem;
}

.limit-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  padding: 0.25rem 0.625rem;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-muted);
  cursor: pointer;
  font-family: 'Inter', sans-serif;
  transition: all 0.15s;
}
.limit-btn.active {
  background: var(--primary);
  color: #000;
  border-color: var(--primary);
}
.limit-btn:hover:not(.active) {
  border-color: var(--primary);
  color: var(--primary);
}

/* ── Small ghost btn ── */
.btn-sm {
  padding: 0.3rem 0.75rem !important;
  font-size: 0.72rem !important;
}

/* ── Column Visibility Panel ── */
.col-vis-wrap {
  position: relative;
}

.col-vis-panel {
  display: none;
  position: absolute;
  top: calc(100% + 0.5rem);
  left: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem;
  min-width: 180px;
  max-height: 260px;
  overflow-y: auto;
  z-index: 50;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
}
.col-vis-panel.open { display: block; }

.col-vis-checkboxes {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.col-vis-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.78rem;
  color: var(--text);
  cursor: pointer;
  padding: 0.2rem 0.25rem;
  border-radius: 0.25rem;
  transition: background 0.1s;
}
.col-vis-item:hover { background: rgba(255,255,255,0.04); }
.col-vis-item input[type=checkbox] { accent-color: var(--primary); cursor: pointer; }

/* ── Export wrap ── */
.export-wrap {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* ── Table footer ── */
.table-footer {
  text-align: center;
  padding: 0.625rem;
  font-size: 0.72rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
}

/* ── Correlation Panel ── */
.corr-controls {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  align-items: center;
}

.corr-controls label {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 600;
}

.corr-controls select {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 0.375rem 0.75rem;
  color: var(--text);
  font-size: 0.78rem;
  outline: none;
  font-family: 'Inter', sans-serif;
  cursor: pointer;
  transition: border-color 0.15s;
}
.corr-controls select:focus { border-color: var(--primary); }

.corr-result {
  padding: 0.875rem 1rem;
  background: rgba(255,196,81,0.06);
  border-left: 3px solid var(--primary);
  border-radius: 0 0.5rem 0.5rem 0;
  font-size: 0.85rem;
  color: var(--text);
  min-height: 2.5rem;
}
.corr-result:empty { display: none; }

/* ── Responsive ── */
@media (max-width: 700px) {
  .stats-bar {
    grid-template-columns: repeat(2, 1fr);
  }
  .header {
    flex-direction: column;
    gap: 0.75rem;
    align-items: flex-start;
    padding: 0.875rem 1rem;
  }
  .header-right {
    width: 100%;
    flex-wrap: wrap;
    gap: 0.5rem;
  }
  .header-left h1 {
    font-size: 1.05rem;
  }
  .header-left p {
    font-size: 0.72rem;
  }
  .container {
    padding: 1rem;
  }
  .upload-zone {
    padding: 1.75rem 1rem;
  }
  .col-stats {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  }
  .data-toolbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
  }
  .toolbar-group {
    width: 100%;
  }
  .limit-btns {
    flex-wrap: wrap;
  }
  .chart-controls {
    flex-wrap: wrap;
    gap: 0.5rem;
  }
  .chart-controls select {
    width: 100%;
  }
  .corr-controls {
    flex-wrap: wrap;
    gap: 0.5rem;
  }
  .corr-controls select {
    width: 100%;
  }
  .section-card {
    padding: 1rem;
  }
  .back-to-main {
    font-size: 0.72rem;
    padding: 0.3rem 0.625rem;
  }
}

@media (max-width: 420px) {
  .stats-bar {
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
  }
  .stat-pill {
    padding: 0.625rem;
  }
  .format-toggle {
    gap: 0.375rem;
  }
  .parse-row {
    flex-direction: column;
    gap: 0.5rem;
  }
  .parse-row button {
    width: 100%;
  }
}
