/* =========================================
   SQLab — Stylesheet
   Theme: Industrial Terminal Aesthetic
   ========================================= */

:root {
  --bg-0: #0d0f13;
  --bg-1: #13161d;
  --bg-2: #1a1e28;
  --bg-3: #222736;
  --bg-4: #2b3045;
  --border: #2e3547;
  --border-bright: #3d4a65;
  --text-0: #e8ecf5;
  --text-1: #a8b4cc;
  --text-2: #6b7a9a;
  --text-3: #404d69;
  --accent: #00d4ff;
  --accent-dim: #0099bb;
  --accent-glow: rgba(0, 212, 255, 0.15);
  --green: #00e896;
  --green-dim: #00b870;
  --red: #ff4d6a;
  --red-dim: #cc3a54;
  --yellow: #ffd166;
  --purple: #c77dff;
  --orange: #ff9f43;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.3);
  --radius: 8px;
  --radius-sm: 4px;
  --font-mono: 'JetBrains Mono', monospace;
  --font-ui: 'Syne', sans-serif;
  --syn-keyword: #00d4ff;
  --syn-function: #c77dff;
  --syn-string: #00e896;
  --syn-number: #ffd166;
  --syn-comment: #5a6a8a;
  --syn-operator: #ff9f43;
}

[data-theme="light"] {
  --bg-0: #f0f2f7;
  --bg-1: #ffffff;
  --bg-2: #f7f8fc;
  --bg-3: #ebedf5;
  --bg-4: #dfe3ef;
  --border: #d0d5e8;
  --border-bright: #b0bbd4;
  --text-0: #111827;
  --text-1: #374151;
  --text-2: #6b7280;
  --text-3: #9ca3af;
  --accent: #0077cc;
  --accent-dim: #005fa3;
  --accent-glow: rgba(0, 119, 204, 0.12);
  --green: #00875a;
  --green-dim: #006644;
  --red: #d93025;
  --red-dim: #b5271f;
  --yellow: #d97706;
  --purple: #7c3aed;
  --orange: #ea580c;
  --shadow: 0 4px 24px rgba(0,0,0,0.1);
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.07);
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: var(--font-ui);
  background: var(--bg-0);
  color: var(--text-0);
  overflow: hidden;
}

/* ── Loading Overlay ── */
#loading-overlay {
  position: fixed; inset: 0; z-index: 9999;
  background: var(--bg-0);
  display: flex; align-items: center; justify-content: center;
  transition: opacity 0.5s ease;
}
#loading-overlay.hidden { opacity: 0; pointer-events: none; }

.loader-box {
  text-align: center;
  display: flex; flex-direction: column; gap: 20px; align-items: center;
}
.loader-logo {
  font-family: var(--font-mono);
  font-size: 3rem; font-weight: 700;
  color: var(--text-0); letter-spacing: -2px;
}
.loader-logo span { color: var(--accent); }
.loader-bar {
  width: 240px; height: 3px;
  background: var(--bg-3); border-radius: 99px; overflow: hidden;
}
.loader-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--purple));
  border-radius: 99px;
  animation: fill-bar 1.8s cubic-bezier(0.4,0,0.2,1) forwards;
}
@keyframes fill-bar { to { width: 100%; } }
.loader-text { font-family: var(--font-mono); font-size: 0.75rem; color: var(--text-2); }

/* ── Topbar ── */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  height: 52px;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
  background: var(--bg-1);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
  gap: 12px;
}
.topbar-left { display: flex; align-items: baseline; gap: 12px; flex-shrink: 0; }
.brand {
  font-family: var(--font-mono);
  font-size: 1.3rem; font-weight: 700;
  color: var(--text-0); letter-spacing: -1px;
}
.brand-accent { color: var(--accent); }
.brand-sub {
  font-size: 0.7rem; color: var(--text-3);
  font-family: var(--font-mono); letter-spacing: 0.05em;
  text-transform: uppercase;
}
.topbar-nav { display: flex; gap: 14px; margin-left: 20px; align-items: center; }
.nav-link { font-family: var(--font-mono); font-size: 0.72rem; color: var(--text-2); text-decoration: none; transition: color 0.15s; text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600; }
.nav-link:hover { color: var(--text-0); }
.topbar-right { display: flex; gap: 8px; align-items: center; flex-shrink: 0; }

/* ── Topbar Progress ── */
.topbar-progress {
  flex: 1; max-width: 300px;
  display: flex; align-items: center; gap: 10px;
}
.progress-track {
  flex: 1; height: 6px;
  background: var(--bg-3);
  border-radius: 99px; overflow: hidden;
}
.progress-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--green));
  border-radius: 99px;
  transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}
.progress-label {
  font-family: var(--font-mono);
  font-size: 0.65rem; color: var(--text-3);
  white-space: nowrap;
}

/* ── Stat Pills ── */
.stat-pill {
  display: flex; align-items: center; gap: 5px;
  padding: 4px 10px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 99px;
  font-family: var(--font-mono);
  font-size: 0.72rem; font-weight: 700;
  color: var(--text-1);
  cursor: default;
  transition: border-color 0.2s;
}
.stat-pill:hover { border-color: var(--accent); }
.stat-pill-icon { font-size: 0.85rem; }

/* ── Buttons ── */
.btn {
  font-family: var(--font-mono);
  font-size: 0.75rem; font-weight: 500;
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
  background: transparent;
  color: var(--text-1);
}
.btn:hover { border-color: var(--border-bright); color: var(--text-0); }
.btn-primary { background: var(--accent); color: #000; border-color: var(--accent); font-weight: 700; }
.btn-primary:hover { background: var(--accent-dim); border-color: var(--accent-dim); color: #000; }
.btn-danger { color: var(--red); border-color: var(--red); }
.btn-danger:hover { background: var(--red); color: #fff; }
.btn-ghost { border-color: transparent; }
.btn-ghost:hover { border-color: var(--border); background: var(--bg-3); }
.btn-sm { padding: 4px 10px; font-size: 0.72rem; }
.btn-xs { padding: 2px 7px; font-size: 0.65rem; }
kbd {
  font-family: var(--font-mono);
  font-size: 0.6rem; font-weight: 400;
  color: var(--text-2);
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1px 4px; margin-left: 6px;
}

/* ── Layout ── */
.layout {
  position: fixed;
  top: 52px; bottom: 28px; left: 0; right: 0;
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 0; overflow: hidden;
}
.layout.playground-mode {
  grid-template-columns: 1fr;
}
.layout.playground-mode .panel-questions {
  display: none;
}

/* ── Footer ── */
.app-footer {
  position: fixed; bottom: 0; left: 0; right: 0;
  height: 28px; background: var(--bg-1);
  border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-mono); font-size: 0.7rem; color: var(--text-3);
  z-index: 100;
}
.app-footer a { color: var(--text-2); text-decoration: none; font-weight: 700; margin-left: 4px; transition: color 0.15s; }
.app-footer a:hover { color: var(--accent); }

/* ── Panel ── */
.panel { display: flex; flex-direction: column; background: var(--bg-1); overflow: hidden; }
.panel-questions { border-right: 1px solid var(--border); background: var(--bg-0); }
.panel-center { background: var(--bg-1); }

.panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.panel-title {
  font-size: 0.8rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--text-2);
}
.q-count {
  font-family: var(--font-mono);
  font-size: 0.65rem; color: var(--accent);
  background: var(--accent-glow);
  padding: 2px 8px; border-radius: 99px;
  border: 1px solid var(--accent-dim);
}

/* ── Search ── */
.search-wrap { padding: 10px 12px; flex-shrink: 0; }
.search-wrap input {
  width: 100%; padding: 7px 12px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-0);
  font-family: var(--font-mono); font-size: 0.75rem;
  outline: none; transition: border-color 0.15s;
}
.search-wrap input:focus { border-color: var(--accent); }
.search-wrap input::placeholder { color: var(--text-3); }

/* ── Level Tabs ── */
.level-tabs { display: flex; gap: 0; padding: 0 12px 10px; flex-shrink: 0; }
.level-tab {
  flex: 1;
  font-family: var(--font-mono);
  font-size: 0.65rem; font-weight: 600;
  padding: 5px 2px;
  border: 1px solid var(--border);
  cursor: pointer;
  background: var(--bg-2); color: var(--text-2);
  transition: all 0.15s;
  text-transform: uppercase; letter-spacing: 0.05em;
}
.level-tab:first-child { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.level-tab:last-child  { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.level-tab:not(:first-child) { border-left: none; }
.level-tab.active { background: var(--accent); color: #000; border-color: var(--accent); }
.level-tab:hover:not(.active) { background: var(--bg-3); color: var(--text-0); }

/* ── Question List ── */
.q-list { flex: 1; overflow-y: auto; padding: 4px 8px 16px; }
.q-list::-webkit-scrollbar { width: 4px; }
.q-list::-webkit-scrollbar-track { background: transparent; }
.q-list::-webkit-scrollbar-thumb { background: var(--bg-4); border-radius: 99px; }

.q-group-label {
  font-size: 0.6rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.1em;
  color: var(--text-3); padding: 12px 8px 4px;
}
.q-item {
  display: flex; align-items: center; gap: 6px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.12s;
  border: 1px solid transparent;
  margin-bottom: 2px;
}
.q-item:hover { background: var(--bg-2); }
.q-item.active { background: var(--accent-glow); border-color: var(--accent-dim); }
.q-item.solved .q-status { color: var(--green); }
.q-item.solved .q-text { color: var(--text-2); }

.q-status {
  font-family: var(--font-mono);
  font-size: 0.7rem; font-weight: 700;
  color: var(--text-3);
  min-width: 14px; text-align: center;
  flex-shrink: 0;
}
.q-num {
  font-family: var(--font-mono);
  font-size: 0.6rem; font-weight: 700;
  color: var(--text-3); min-width: 26px;
}
.q-text { font-size: 0.78rem; flex: 1; color: var(--text-1); line-height: 1.3; }
.q-badge {
  font-family: var(--font-mono);
  font-size: 0.55rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.06em;
  padding: 1px 5px; border-radius: 3px;
  flex-shrink: 0;
}
.badge-beginner     { background: rgba(0,232,150,0.12); color: var(--green); border: 1px solid rgba(0,232,150,0.3); }
.badge-intermediate { background: rgba(255,159,67,0.12); color: var(--orange); border: 1px solid rgba(255,159,67,0.3); }
.badge-advanced     { background: rgba(199,125,255,0.12); color: var(--purple); border: 1px solid rgba(199,125,255,0.3); }

/* ── Schema Bar ── */
.schema-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 14px;
  background: var(--bg-0);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0; flex-wrap: wrap;
}
.schema-label { font-size: 0.65rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-3); }
.schema-table {
  font-family: var(--font-mono); font-size: 0.68rem; color: var(--text-2);
  background: var(--bg-2); padding: 2px 8px;
  border-radius: 3px; border: 1px solid var(--border); cursor: default;
}
.schema-table:hover { border-color: var(--accent); color: var(--accent); }

/* ── Editor Section ── */
.editor-section {
  height: 280px;
  flex-shrink: 0;
  display: flex; flex-direction: column;
  min-height: 48px; /* minimum height to always show the toolbar */
}

#editor-launch-label { cursor: pointer; transition: color 0.15s; }
#editor-launch-label:hover { color: var(--text-0); }

.resizer {
  height: 7px;
  background: var(--bg-1);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  cursor: row-resize;
  display: flex; justify-content: center; align-items: center;
  flex-shrink: 0; transition: background 0.2s;
}
.resizer:hover, .resizer:active {
  background: var(--bg-3);
}
.resizer-handle {
  width: 36px; height: 3px;
  background: var(--border-bright); border-radius: 99px;
}
.editor-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 14px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.toolbar-actions { display: flex; gap: 6px; align-items: center; }
.section-label {
  font-size: 0.7rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--text-2);
}

/* ── Code Editor ── */
.editor-wrap { flex: 1; display: flex; overflow: hidden; background: var(--bg-0); }
.CodeMirror { flex: 1; width: 100%; height: 100%; font-family: var(--font-mono); font-size: 0.82rem; }
.line-nums {
  font-family: var(--font-mono);
  font-size: 0.78rem; line-height: 1.7;
  color: var(--text-3);
  padding: 14px 10px 14px 14px;
  text-align: right; min-width: 40px;
  background: var(--bg-0);
  border-right: 1px solid var(--border);
  user-select: none; overflow: hidden; white-space: pre;
}
#sql-editor {
  flex: 1;
  font-family: var(--font-mono);
  font-size: 0.82rem; line-height: 1.7;
  color: var(--text-0);
  background: var(--bg-0);
  border: none; outline: none; resize: none;
  padding: 14px 16px;
  caret-color: var(--accent);
  tab-size: 2;
}
#sql-editor::placeholder { color: var(--text-3); }
#sql-editor::selection   { background: var(--accent-glow); }

/* ── Results Section ── */
.results-section { flex: 1; display: flex; flex-direction: column; overflow: hidden; transition: flex 0.25s cubic-bezier(0.4,0,0.2,1); }

/* Maximized: results takes full center panel, editor collapses to just its toolbar */
.panel-center.results-maximized .editor-section {
  flex: 0 0 38px;          /* only show the toolbar bar */
  overflow: hidden;
}
.panel-center.results-maximized .editor-section .editor-wrap {
  display: none;
}
.panel-center.results-maximized .results-section {
  flex: 1;
}

/* Minimized: results collapses to just its toolbar */
.panel-center.results-minimized .results-section {
  flex: 0 0 38px;
  overflow: hidden;
}
.panel-center.results-minimized .results-section .results-body {
  display: none;
}
.panel-center.results-minimized .editor-section {
  flex: 1;
}
.results-toolbar {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 14px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.results-meta { flex: 1; font-family: var(--font-mono); font-size: 0.68rem; color: var(--text-2); }
.results-meta .meta-ok   { color: var(--green); }
.results-meta .meta-err  { color: var(--red); }
.results-meta .meta-time { color: var(--text-3); }

.results-body { flex: 1; overflow: auto; background: var(--bg-0); }
.results-body::-webkit-scrollbar { width: 6px; height: 6px; }
.results-body::-webkit-scrollbar-track { background: transparent; }
.results-body::-webkit-scrollbar-thumb { background: var(--bg-4); border-radius: 99px; }

/* Placeholder */
.results-placeholder {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: 100%; gap: 12px; color: var(--text-3);
}
.placeholder-icon { font-size: 2.5rem; opacity: 0.4; }
.placeholder-text { font-size: 0.8rem; font-family: var(--font-mono); }

/* Error display */
.results-error { padding: 20px; }
.error-box {
  background: rgba(255,77,106,0.08);
  border: 1px solid var(--red-dim);
  border-radius: var(--radius);
  padding: 16px 20px;
}
.error-label {
  font-family: var(--font-mono);
  font-size: 0.65rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.1em;
  color: var(--red); margin-bottom: 8px;
  display: flex; align-items: center; gap: 6px;
}
.error-message { font-family: var(--font-mono); font-size: 0.8rem; color: var(--red); line-height: 1.6; white-space: pre-wrap; }

/* ── Validation Banners ── */
.validation-banner {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.validation-correct {
  background: rgba(0, 232, 150, 0.08);
  border-bottom-color: var(--green-dim);
}
.validation-wrong {
  background: rgba(255, 77, 106, 0.08);
  border-bottom-color: var(--red-dim);
}
.v-icon {
  font-size: 1.4rem; flex-shrink: 0;
}
.v-title {
  font-family: var(--font-mono);
  font-size: 0.75rem; font-weight: 700;
  color: var(--text-0); margin-bottom: 3px;
}
.validation-correct .v-title { color: var(--green); }
.validation-wrong   .v-title { color: var(--red); }
.v-sub {
  font-size: 0.72rem; color: var(--text-2);
}
.v-next {
  margin-left: auto; flex-shrink: 0;
  color: var(--accent); border-color: var(--accent-dim);
}
.v-next:hover { background: var(--accent-glow); }

/* Results Table */
.results-table-wrap { overflow: auto; }
.results-table {
  width: 100%; border-collapse: collapse;
  font-family: var(--font-mono); font-size: 0.75rem;
}
.results-table th {
  position: sticky; top: 0;
  background: var(--bg-2); color: var(--text-2);
  font-size: 0.65rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.07em;
  padding: 9px 14px; text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap; z-index: 1;
}
.results-table td {
  padding: 8px 14px; color: var(--text-0);
  border-bottom: 1px solid var(--border);
  white-space: nowrap; max-width: 300px;
  overflow: hidden; text-overflow: ellipsis;
}
.results-table tr:hover td { background: var(--bg-2); }
.results-table td.cell-null  { color: var(--text-3); font-style: italic; }
.results-table td.cell-num   { color: var(--yellow); }

.results-empty {
  padding: 40px; text-align: center;
  font-family: var(--font-mono); font-size: 0.78rem; color: var(--text-3);
}
/* ── Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: rgba(0,0,0,0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  backdrop-filter: blur(4px);
}

.modal {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 800px;
  height: 85vh;              /* ✅ FIXED HEIGHT */
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
}

.modal-wide {
  max-width: 960px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.modal-title {
  font-weight: 700;
  font-size: 1rem;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-2);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: background 0.15s;
}

.modal-close:hover {
  background: var(--bg-3);
  color: var(--text-0);
}

/* ✅ SCROLL FIX (THIS IS THE KEY PART) */
.modal-body {
  flex: 1;
  min-height: 0;              /* 🔥 CRITICAL */
  overflow-y: auto;

  padding: 20px;

  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;

  align-content: start;
  grid-auto-rows: min-content;  /* 🔥 GRID FIX */
}

/* optional smoother scroll */
.modal-body {
  scroll-behavior: smooth;
}

/* Schema cards */
.schema-card { background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.schema-card-header {
  padding: 10px 14px; background: var(--bg-3);
  border-bottom: 1px solid var(--border);
  font-family: var(--font-mono); font-size: 0.78rem; font-weight: 700; color: var(--accent);
}
.schema-card table { width: 100%; border-collapse: collapse; font-family: var(--font-mono); font-size: 0.72rem; }
.schema-card th { padding: 6px 14px; text-align: left; color: var(--text-3); font-size: 0.62rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; }
.schema-card td { padding: 5px 14px; border-top: 1px solid var(--border); color: var(--text-1); }
.schema-card td:first-child { color: var(--text-0); }
.schema-pk { color: var(--yellow) !important; }
.schema-fk { color: var(--orange) !important; }
.type-tag { font-size: 0.6rem; background: var(--bg-4); padding: 1px 5px; border-radius: 3px; color: var(--text-2); }

/* ── Stat Cards (progress modal) ── */
.stat-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
}
.stat-num {
  font-family: var(--font-mono);
  font-size: 2rem; font-weight: 700;
  color: var(--accent); margin-bottom: 6px;
}
.stat-label {
  font-size: 0.7rem; color: var(--text-3);
  text-transform: uppercase; letter-spacing: 0.08em;
}

/* ── Responsive ── */
@media (max-width: 900px) { .layout { grid-template-columns: 260px 1fr; } }
@media (max-width: 700px) {
  .layout { grid-template-columns: 1fr; }
  .panel-questions { display: none; }
  .modal-body { grid-template-columns: 1fr; }
  .topbar-progress { display: none; }
  .stat-pill .stat-pill-icon + span { display: none; }
}

/* ── Animations ── */
@keyframes fade-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.fade-in { animation: fade-in 0.2s ease; }

@keyframes pop-in {
  0%   { transform: scale(0.92); opacity: 0; }
  60%  { transform: scale(1.03); }
  100% { transform: scale(1); opacity: 1; }
}
.pop-in { animation: pop-in 0.3s cubic-bezier(0.34, 1.56, 0.64, 1); }

/* scrollbar globally */
* { scrollbar-width: thin; scrollbar-color: var(--bg-4) transparent; }