/* =====================================================
   CISC106/108 Review – style.css
   - White theme (default) + Dark theme via [data-theme="dark"]
   - Sidebar + workspace layout
   - Buttons, progress bar, editor, console, overlays
   - REPL line highlight for valid function defs
   ===================================================== */

/* ---------- Theme tokens ---------- */
:root {
  --bg: #ffffff;
  --text: #0b1324;
  --muted: #6b7280;
  --panel: #f6f8fb;
  --border: #e5e7eb;
  --accent: #2563eb;       /* blue-600 */
  --accent-weak: #dbeafe;  /* blue-100 */
  --ok: #07bfa3;
  --fail: #d22f2f;
  --warn: #ffc107;
  --shadow: 0 10px 28px rgba(2, 6, 23, .08);
  --font-sans: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Inter, "Helvetica Neue", Arial, "Apple Color Emoji","Segoe UI Emoji";
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

html[data-theme="dark"] {
  --bg: #0b1020;
  --text: #e8eef8;
  --muted: #9aa8c7;
  --panel: #0f152b;
  --border: #1f2a44;
  --accent: #8ab4ff;       /* light blue */
  --accent-weak: #10213f;
  --ok: #18c7b3;
  --fail: #ff6b6b;
  --warn: #ffd166;
  --shadow: 0 10px 28px rgba(0, 0, 0, .4);
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 var(--font-sans);
}

/* Accessible focus */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}

/* Utility */
.muted { color: var(--muted); }
.spacer { flex: 1; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.brand {
  margin: 0;
  font-weight: 800;
  letter-spacing: .3px;
}

/* ---------- Progress ---------- */
.progress {
  height: 6px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent) 0%, var(--ok) 100%);
  transition: width .25s ease;
}

/* ---------- Layout ---------- */
.layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 0;
  min-height: calc(100vh - 60px);
}

@media (max-width: 960px) {
  .layout {
    grid-template-columns: 1fr;
  }
}

/* ---------- Sidebar ---------- */
.sidebar {
  border-right: 1px solid var(--border);
  background: var(--panel);
  min-height: 0;
  overflow: auto;
}

.qlist { padding: 10px; }

.section-header {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 8px 6px;
  margin: 10px 0 4px;
  border-bottom: 1px dashed var(--border);
}

.section-toggle {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--bg);
  padding: 2px 8px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 700;
}

.section-title { font-weight: 700; }
.section-meta { color: var(--muted); font-size: 12px; }

.qitem {
  display: grid;
  grid-template-columns: 18px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 10px 8px;
  border-radius: 10px;
  border: 1px solid transparent;
  cursor: pointer;
}
.qitem:hover {
  background: var(--accent-weak);
  border-color: var(--border);
}
.qitem[aria-current="true"] {
  border-color: var(--accent);
  background: color-mix(in oklab, var(--accent) 12%, transparent);
}
.qitem .check {
  width: 12px; height: 12px;
  border-radius: 999px;
  border: 2px solid var(--muted);
}
.qitem.done .check {
  background: var(--ok);
  border-color: var(--ok);
}
.qitem .title { font-weight: 600; }
.qitem .badge {
  font-size: 12px;
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 2px 8px;
  border-radius: 999px;
}

/* ---------- Workspace ---------- */
.workspace {
  display: grid;
  grid-template-rows: auto auto auto 1fr;
  gap: 12px;
  padding: 16px;
}

.prompt h2 { margin: 0 0 2px; }
.qprompt { margin: 6px 0 0; }

/* Editor area */
.editor-wrap { display: grid; gap: 6px; }
.editor-wrap label { color: var(--muted); font-size: 13px; }

.editor {
  height: 320px;
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  background: var(--bg);
  overflow: hidden;
}

/* Ace font */
.ace_editor, .ace_scroller {
  font-family: var(--font-mono) !important;
  font-size: 14px !important;
}

/* Controls */
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

/* Buttons */
.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
  transition: transform .04s ease, background .15s ease;
}
.btn:hover { background: var(--panel); }
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: var(--accent);
  color: #fff;
  border-color: color-mix(in oklab, var(--accent) 64%, var(--border));
}
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger {
  border-color: color-mix(in oklab, var(--fail) 60%, var(--border));
  color: var(--fail);
}

/* Console */
.console {
  margin: 0;
  padding: 12px;
  background: var(--panel);
  border: 1px dashed var(--border);
  border-radius: 12px;
  min-height: 88px;
  overflow: auto;
}
.console .ok,
.console .fail {
  display: inline-block;
  margin: 0 8px 8px 0;
  padding: 4px 10px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 12px;
  border: 1px solid var(--border);
}
.console .ok   { color: var(--ok);   background: color-mix(in oklab, var(--ok) 12%, transparent); }
.console .fail { color: var(--fail); background: color-mix(in oklab, var(--fail) 12%, transparent); }

.console-block {
  white-space: pre-wrap;
  font-family: var(--font-mono);
  font-size: 13px;
}

/* ---------- Overlay / Admin sheet ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.overlay.hidden { display: none; }

.sheet {
  width: min(980px, 94vw);
  max-height: 86vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  box-shadow: var(--shadow);
}
.sheet-head {
  display: flex; align-items: center; gap: 8px;
  border-bottom: 1px dashed var(--border);
  padding-bottom: 8px;
}
#problemsEditor {
  width: 100%;
  height: 48vh;
  resize: vertical;
  font-family: var(--font-mono);
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  background: var(--panel);
  color: var(--text);
}
.sheet-actions { display: flex; gap: 10px; align-items: center; }
.file-input { font-size: 14px; }

/* ---------- REPL (overlay is injected by JS; this adds polish) ---------- */
#replFab {
  box-shadow: var(--shadow);
}
#replOverlay .repl-card {
  background: var(--bg);
  border-radius: 14px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}
#replOverlay .repl-title {
  display: flex;
  align-items: center;
  gap: 8px;
}
#replOutput {
  background: color-mix(in oklab, var(--text) 2%, var(--bg));
}

/* Full-line green highlight for valid def lines (added by JS markers) */
.repl-def-ok {
  position: absolute;
  inset: 0;
  background: color-mix(in oklab, var(--ok) 15%, transparent);
  pointer-events: none;
}

/* ---------- Small tweaks ---------- */
label[for="aceEditor"] { user-select: none; }
pre, code { font-family: var(--font-mono); }

/* Improve contrast in dark mode for panels */
html[data-theme="dark"] .editor { background: #0b1020; }
html[data-theme="dark"] .console { background: #0f152b; }

/* Mobile */
@media (max-width: 640px) {
  .controls { gap: 6px; }
  .btn { padding: 7px 10px; }
  .editor { height: 260px; }
}
