:root {
  --bg: #f8fafc;
  --panel: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --accent: #2563eb;
  --accent-600: #1d4ed8;
  --shadow: 0 6px 16px rgba(2, 6, 23, 0.06);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: linear-gradient(180deg, #f9fbff 0%, #f7fafc 100%);
  /* Make right column the scroll container on desktop */
  overflow: hidden;
}

.app {
  display: grid;
  grid-template-columns: 280px 1fr;
  height: 100vh;
}

/* Login screen */
.login-screen { position: fixed; inset: 0; background: #ffffff; color: #111; display: none; align-items: center; justify-content: center; }
.login-hero { max-width: 1000px; width: 100%; padding: 32px; display: grid; grid-template-columns: 1.1fr 0.9fr; gap: 24px; align-items: center; }
.login-left { padding: 16px; }
.login-right { padding: 16px; }
.logo-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.logo { width: 28px; height: 28px; display: inline-block; background: url('/static/ql-icon.svg') no-repeat center / contain; }
.login-screen .brand { font-weight: 700; font-size: 18px; color: #111; }
.hero-title { font-size: 40px; line-height: 1.1; margin: 8px 0 12px; letter-spacing: -0.02em; }
.hero-sub { font-size: 16px; color: #334155; margin: 0 0 14px; }
.feature-list { list-style: none; padding: 0; margin: 0 0 18px; display: grid; grid-template-columns: 1fr 1fr; gap: 6px 18px; color: #111; }
.feature-list li::before { content: '✓'; color: #16a34a; margin-right: 8px; }
.btn.large { padding: 12px 16px; font-size: 16px; border-radius: 12px; }
.fineprint { margin-top: 10px; font-size: 12px; color: #475569; }
.hero-art { border: 1px solid var(--border); border-radius: 14px; padding: 12px; background: #fff; box-shadow: var(--shadow); }
.hero-art .art-main { width: 100%; height: auto; display: block; border-radius: 10px; }
.hero-art .thumbs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 8px; }
.hero-art .thumbs img { width: 100%; border-radius: 8px; border: 1px solid var(--border); }

@media (max-width: 900px) {
  .login-hero { grid-template-columns: 1fr; }
}

.sidebar {
  border-right: 1px solid var(--border);
  background: var(--panel);
  display: flex;
  flex-direction: column;
  padding: 16px;
  gap: 12px;
  /* Keep sidebar fixed while main scrolls */
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
}

.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 18px; }
.brand .logo { width: 20px; height: 20px; display: inline-block; background: url('/static/ql-icon.svg') no-repeat center / contain; }

.actions {
  display: flex;
}

.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  padding: 8px 12px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 500;
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}
.btn.primary:hover { background: var(--accent-600); border-color: var(--accent-600); }
.btn.primary[disabled] { background: #cbd5e1; border-color: #cbd5e1; color: #ffffff; }
.shake { animation: shake 0.3s linear; }
@keyframes shake { 20% { transform: translateX(-2px); } 40% { transform: translateX(2px); } 60% { transform: translateX(-2px); } 80% { transform: translateX(2px); } }

.course-list { overflow: auto; flex: 1; }
.support-list { display: flex; flex-direction: column; gap: 6px; margin: 6px 0 12px; }
.support-item { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 8px; border: 1px solid transparent; cursor: pointer; color: inherit; text-decoration: none; }
.support-item:hover { background: #f1f5f9; }
.support-item .icon { width: 20px; text-align: center; }

.section-label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 4px 2px 2px;
}

.course-item {
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
}
.course-item { text-decoration: none; color: inherit; }
.course-item:hover { background: #f1f5f9; }
.course-item.active { background: #eef2ff; border-color: #c7d2fe; }

.course-item .icon { width: 22px; text-align: center; }
.course-item .meta { margin-left: auto; text-align: right; color: var(--muted); font-size: 12px; }
.course-item .title { font-weight: 600; font-size: 14px; line-height: 1.2; max-height: 2.4em; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; word-break: break-word; }
.course-item .sub { font-size: 12px; color: var(--muted); }

.user-panel {
  border-top: 1px solid var(--border);
  padding-top: 10px;
  margin-top: 8px;
}
.user-panel .user-info { display: flex; align-items: center; gap: 10px; }
.user-panel .avatar { width: 28px; height: 28px; border-radius: 999px; background: #e2e8f0; display:flex; align-items:center; justify-content:center; font-weight:600; color:#475569; }
.user-panel .user-text .name { font-weight: 600; font-size: 14px; }
.user-panel .user-text .status { color: var(--muted); font-size: 12px; }
.user-panel .user-actions { display:flex; gap: 6px; margin-top: 8px; }
.btn.small { padding: 6px 10px; font-size: 12px; border-radius: 8px; }

.main {
  padding: 20px 28px;
  height: 100vh;
  overflow: auto;
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.title { margin: 0; font-size: 22px; font-weight: 600; }
.title .title-link { text-decoration: none; color: inherit; cursor: pointer; }
.title .title-link:hover { text-decoration: underline; }
.subtitle { margin: 4px 0 0; color: var(--muted); }

/* Header nav */
#breadcrumbActions { display: flex; align-items: center; }
.nav-actions { display: flex; gap: 8px; align-items: center; }
.nav-sep { color: var(--muted); }
.btn[disabled] { opacity: 0.6; cursor: not-allowed; }

.cards {
  margin-top: 16px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}

/* Lectures as a list */
.list { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.list-row { display: grid; grid-template-columns: 28px 1fr auto; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--panel); box-shadow: var(--shadow); }
.list-row .drag-handle { text-align: center; color: #64748b; cursor: grab; user-select: none; }
.list-row .row-title { font-weight: 600; }
.list-row .row-title a { color: inherit; text-decoration: none; }
.list-row .row-title a:hover { text-decoration: underline; }
.list-row .row-desc { color: var(--muted); font-size: 13px; }
.list-row.dragging { opacity: 0.75; outline: 2px dashed #94a3b8; }

/* Full-width content area for tab pages */
.content-area { margin-top: 12px; }
.content-area .panel { width: 100%; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  box-shadow: var(--shadow);
}
.card.clickable { cursor: pointer; }
.card.clickable:hover { outline: 2px solid #c7d2fe; }
.card .card-title { font-weight: 600; margin: 0 0 6px; }
.card .card-title a.card-title-link { color: inherit; text-decoration: none; }
.card .card-title a.card-title-link:hover { text-decoration: underline; }
.card .card-desc { color: var(--muted); margin: 0; font-size: 14px; }

.dialog::backdrop { background: rgba(2, 6, 23, 0.35); }
.dialog { border: none; border-radius: 16px; padding: 0; }
.dialog form { padding: 20px; min-width: 360px; }
.label { display: block; font-size: 14px; color: var(--muted); margin-bottom: 6px; }
.input {
  width: 100%;
  font-size: 16px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  margin-bottom: 14px;
}
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* Reader */
.reader-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 10px 0 12px;
}
.reader-progress { color: var(--muted); font-weight: 500; }
.reader-part { padding: 18px; }
.reader-section { color: var(--muted); font-size: 14px; margin-bottom: 8px; }
.reader-html h1, .reader-html h2, .reader-html h3 { margin: 12px 0 8px; }
.reader-html p { line-height: 1.6; }
.reader-html pre { background: #0b1020; color: #e5edff; padding: 10px; border-radius: 8px; overflow: auto; }
.reader-html code { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; }

/* File chips */
.file-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.chip { font-size: 12px; padding: 4px 8px; border-radius: 999px; border: 1px solid var(--border); background: #fff; }
.chip.used { background: #ecfdf5; border-color: #86efac; color: #14532d; }
.chip.unused { background: #fff1f2; border-color: #fecdd3; color: #9f1239; }

/* Lecture split panels */
.lecture-panels { display: grid; grid-template-columns: var(--left-col, 360px) 8px 1fr; gap: 16px; align-items: stretch; }
.splitter { width: 8px; cursor: col-resize; background: transparent; position: relative; }
.splitter::after { content: ""; position: absolute; inset: 0; margin: 0 3px; border-radius: 4px; background: #e2e8f0; }
.splitter:hover::after { background: #cbd5e1; }
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
}
.panel .panel-header { padding: 12px 14px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.panel .panel-title { margin: 0; font-weight: 600; }
.panel .panel-body { padding: 12px 14px; }

.file-list { display: grid; gap: 8px; }
.file-row { display: grid; grid-template-columns: 28px 1fr auto; gap: 10px; align-items: center; padding: 8px; border: 1px solid var(--border); border-radius: 10px; }
.file-meta { color: var(--muted); font-size: 12px; }
.status { font-size: 12px; padding: 3px 8px; border-radius: 999px; border: 1px solid var(--border); }
.status.ok { background: #ecfdf5; border-color: #86efac; color: #14532d; }
.status.bad { background: #fff1f2; border-color: #fecdd3; color: #9f1239; }
.status.neutral { background: #f1f5f9; color: #334155; }

/* Files table */
.files-bar { display: flex; align-items: center; gap: 8px; }
.search { flex: 1; }
.input.search-input { width: 100%; }
.tabs { display: flex; align-items: center; gap: 8px; }
.tab { display: inline-flex; align-items: center; height: 34px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--border); cursor: pointer; background: #fff; font-size: 13px; font-weight: 500; color: #0f172a; }
.tab.active { background: #eef2ff; border-color: #c7d2fe; }
.files-table { width: 100%; border-collapse: collapse; }
.files-table th, .files-table td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--border); font-size: 14px; }
.files-table th { color: var(--muted); font-weight: 600; }
.files-table tbody tr:hover { background: #f8fafc; }
.badge { font-size: 12px; padding: 3px 8px; border-radius: 999px; border: 1px solid var(--border); }
.badge.ok { background: #ecfdf5; border-color: #86efac; color: #14532d; }
.badge.bad { background: #fff1f2; border-color: #fecdd3; color: #9f1239; }
.badge.neutral { background: #f1f5f9; color: #334155; }
.btn.link { border: none; background: transparent; color: var(--accent); padding: 0; }
.btn.link { cursor: pointer; }

@media (max-width: 1100px) {
  .lecture-panels { grid-template-columns: 1fr; }
  .splitter { display: none; }
}

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  /* On small screens, allow natural page scrolling */
  body { overflow: auto; }
  .sidebar { position: sticky; top: 0; z-index: 2; height: auto; }
  .main { height: auto; overflow: visible; }
}
.link { color: var(--accent); text-decoration: none; }
.link:hover { text-decoration: underline; }
.lecture-tabs { display: flex; gap: 8px; margin: 8px 0 12px; }

/* --- Quantitative Learning lesson presentation --- */
.prose { line-height: 1.65; }
.prose h1, .prose h2, .prose h3 { margin: 10px 0 8px; font-weight: 700; }
.prose h1 { font-size: 20px; }
.prose h2 { font-size: 18px; }
.prose h3 { font-size: 16px; }
.prose p { margin: 8px 0; }
.prose code { background: #0b1020; color: #e5edff; padding: 2px 6px; border-radius: 6px; font-size: 90%; }
.prose pre { background: #0b1020; color: #e5edff; padding: 10px; border-radius: 10px; overflow: auto; }
.prose ul, .prose ol { margin: 8px 0 8px 18px; }

.lesson-part { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 16px; box-shadow: var(--shadow); }
.lesson-part h4 { margin: 0 0 10px; font-weight: 700; }
.lesson-grid { display: grid; grid-template-columns: 1fr; gap: 16px; }
@media (min-width: 1000px) {
  .lesson-grid { grid-template-columns: 7fr 5fr; align-items: start; }
}
.lesson-content { display: grid; gap: 14px; }
.lesson-viz { position: sticky; top: 22px; }
.lesson-viz img { width: 100%; height: auto; border-radius: 12px; border: 4px solid #fff; box-shadow: var(--shadow); }
.section-kicker { font-size: 12px; font-weight: 700; color: #6366f1; text-transform: uppercase; letter-spacing: .08em; }
.scenario-box { background: #fff7ed; border: 1px solid #fed7aa; border-radius: 12px; padding: 10px; }
.prompt-box { background: #f8fafc; border: 1px dashed #cbd5e1; border-radius: 12px; padding: 10px; color: #475569; font-size: 14px; }

.quiz { margin: 10px 0; }
.quiz .q { font-weight: 600; margin-bottom: 6px; }
.quiz .opts { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.quiz .opts li { background: #f1f5f9; border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; font-size: 14px; }
.quiz .opts li.ok { background: #ecfdf5; border-color: #86efac; color: #14532d; font-weight: 600; }

/* Education toolbar / chips */
.edu-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 8px 0 12px; flex-wrap: wrap; }
.pills { display: inline-flex; padding: 4px; background: #f1f5f9; border-radius: 12px; border: 1px solid var(--border); gap: 4px; }
.pill { appearance: none; border: none; background: transparent; padding: 6px 10px; border-radius: 10px; cursor: pointer; font-weight: 600; color: #334155; }
.pill.active { background: #eef2ff; color: #1e3a8a; box-shadow: inset 0 0 0 1px #c7d2fe; }
.chips { display: inline-flex; gap: 6px; align-items: center; }
.chip.badge { background: #eef2ff; border-color: #c7d2fe; color: #3730a3; }

/* Part navigation in review mode */
.part-nav { display: flex; align-items: center; gap: 8px; }
.nav-btn { appearance: none; border: 1px solid var(--border); background: #fff; color: var(--text); padding: 6px 10px; border-radius: 10px; cursor: pointer; font-weight: 500; }
.nav-btn:hover { background: #f8fafc; }
.counter { color: var(--muted); font-weight: 600; }

/* Quiz overlay */
.overlay.edu { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(2,6,23,0.55); z-index: 999; }
.edu-box { background: #fff; width: min(760px, 92vw); border-radius: 16px; box-shadow: 0 20px 60px rgba(2,6,23,0.25); border: 1px solid var(--border); }
.edu-box .head { display:flex; align-items:center; justify-content:space-between; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.edu-box .body { padding: 16px; }
.edu-box .foot { display:flex; justify-content:flex-end; gap:8px; padding: 12px 16px; border-top: 1px solid var(--border); }
.opt { display:flex; align-items:center; gap:10px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 12px; cursor: pointer; background: #f8fafc; }
.opt:hover { background: #eef2ff; border-color: #c7d2fe; }
.opt.correct { background: #ecfdf5; border-color: #86efac; color: #14532d; }
.opt.wrong { background: #fff1f2; border-color: #fecdd3; color: #9f1239; }
.explain { margin-top: 8px; color: #475569; font-size: 14px; }
.fade-in { animation: fadein .25s ease-out; }
@keyframes fadein { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

/* Preview device frames */
.device-frame { display: flex; justify-content: center; padding: 10px; }
.device-frame .device-screen { background: #f8fafc; border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow); width: 100%; }
.device-frame.desktop .device-screen { width: min(1000px, 100%); min-height: 560px; }
.device-frame.tablet .device-screen { width: 820px; max-width: 100%; min-height: 560px; border-radius: 20px; }
.device-frame.phone .device-screen { width: 420px; max-width: 100%; min-height: 560px; border-radius: 28px; }
.player { display: flex; flex-direction: column; height: 100%; }
.player-head { display:flex; align-items:center; justify-content:space-between; padding: 12px 14px; }
.player-head .ph-title { font-weight: 700; }
.player-head .ph-sub { color: var(--muted); font-size: 12px; }
.progress { width: 100%; height: 6px; background: #e2e8f0; }
.progress .bar { height: 100%; background: #6366f1; border-radius: 999px; }
.player-body { padding: 14px; overflow:auto; }
.player-foot { display:flex; gap: 8px; padding: 12px 14px; border-top: 1px solid var(--border); }
.stats { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.stat { background: #f8fafc; border: 1px solid var(--border); border-radius: 10px; padding: 6px 10px; font-size: 13px; }

/* Busy overlay */
.overlay { position: fixed; inset: 0; background: rgba(2, 6, 23, 0.45); backdrop-filter: blur(2px); display: flex; align-items: center; justify-content: center; z-index: 1000; }
.overlay .box { background: #fff; border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; box-shadow: var(--shadow); display: flex; align-items: center; gap: 10px; }
.spinner { width: 18px; height: 18px; border-radius: 999px; border: 2px solid #e2e8f0; border-top-color: var(--accent); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.title .inline-input {
  width: auto;
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  font: inherit;
  color: inherit;
  outline: none;
}
.title .inline-input::placeholder { color: var(--muted); }

.card.dragging { opacity: 0.7; outline: 2px dashed #94a3b8; }
.cards .card { user-select: none; }


/* Upload dropzone */
.dropzone { border: 2px dashed var(--border); border-radius: 12px; padding: 16px; background: #f8fafc; text-align: center; }
.dropzone.dragover { border-color: #93c5fd; background: #eff6ff; }


/* How-to figures */
.fig { margin: 10px 0 16px; }
.fig .screenshot { width: 100%; max-width: 720px; border: 1px solid #e5e7eb; border-radius: 8px; box-shadow: 0 1px 2px rgba(0,0,0,0.04); display:block; }
.fig .cap { font-size: 12px; color: #64748b; margin-top: 6px; }
