/* StudyGuideTool styles.
 *
 * UI_GUIDELINES.md Palette 1 (Slate & Indigo), 8px corner radius, system font
 * stack. Dark mode follows prefers-color-scheme and a manual toggle, per
 * section 6 of that document.
 */

:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-alt: #f1f5f9;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #475569;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-text: #ffffff;
  --accent: #0ea5e9;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --danger-soft-bg: #fef2f2;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 1px 3px rgba(15, 23, 42, 0.1);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f172a;
    --surface: #1e293b;
    --surface-alt: #172033;
    --border: #334155;
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --primary: #6366f1;
    --primary-hover: #818cf8;
    --accent: #38bdf8;
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
    --danger-soft-bg: #2a1416;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  }
}

:root[data-theme="dark"] {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-alt: #172033;
  --border: #334155;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --primary: #6366f1;
  --primary-hover: #818cf8;
  --accent: #38bdf8;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --danger-soft-bg: #2a1416;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", Inter, system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

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

/* --- Layout ------------------------------------------------------------- */

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 16px;
}
.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 16px;
  height: 56px;
}
.brand {
  font-weight: 600;
  font-size: 18px;
  color: var(--text);
  text-decoration: none;
}
.topbar nav { display: flex; gap: 4px; margin-left: auto; align-items: center; }
.topbar nav a {
  padding: 8px 12px;
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text-muted);
}
.topbar nav a:hover { background: var(--surface-alt); color: var(--text); }

main { max-width: 1200px; margin: 0 auto; padding: 24px 16px 64px; }

.page-header {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 24px;
}
.page-header h1 { margin: 0 0 4px; font-size: 24px; }
.page-header .subtitle { color: var(--text-muted); margin: 0; }
.page-header .actions { margin-left: auto; display: flex; gap: 8px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 16px; }
.card h2 { margin-top: 0; font-size: 20px; }

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

/* Zero-JS modal (base.html #global-feedback): shown purely by `:target`
   matching this element's id, hidden the instant the URL fragment changes.
   No script involved, so opening/closing it never touches page state - the
   property that lets it sit on top of a running test timer safely. */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 1000;
}
.modal-overlay:target { display: flex; }
.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  width: 100%;
  max-width: 420px;
  max-height: 90vh;
  overflow-y: auto;
}

/* Welcome tutorial (base.html #onboarding-N, edited from /admin/onboarding).
   A step with no uploaded screenshot yet shows this placeholder instead -
   deliberately plain, so it reads as "not done yet" to whoever is editing. */
.onboarding-mockup { margin-top: 12px; }
.onboarding-mockup img {
  display: block;
  max-width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.onboarding-placeholder {
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 32px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
}
/* Admin-only inline editing controls inside the tutorial overlay - visually
   set apart from the content a normal user would eventually see. */
.onboarding-editor {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px dashed var(--border);
}

.auth-shell { max-width: 400px; margin: 64px auto; }

/* --- Stat tiles --------------------------------------------------------- */

.stats { display: flex; flex-wrap: wrap; gap: 16px; margin-bottom: 24px; }
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  min-width: 120px;
}
.stat .value { font-size: 24px; font-weight: 600; }
.stat .label { color: var(--text-muted); font-size: 14px; }

/* --- Buttons ------------------------------------------------------------ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 8px 16px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  background: var(--surface-alt);
  color: var(--text);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { background: var(--border); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }

.btn-primary { background: var(--primary); color: var(--primary-text); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: transparent; border-color: var(--border); color: var(--text-muted); }
.btn-secondary:hover { background: var(--surface-alt); color: var(--text); }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-alt); }
.btn-danger { background: var(--danger); color: #fff; }
/* Soft variant for a destructive action sitting inline with other actions -
   available but not visually dominant (UI_GUIDELINES section 5). */
.btn-danger-soft {
  background: var(--danger-soft-bg);
  border-color: var(--danger);
  color: var(--danger);
}
.btn-sm { min-height: 32px; padding: 4px 10px; font-size: 14px; }
.btn-block { width: 100%; }

/* --- Forms -------------------------------------------------------------- */

.field { margin-bottom: 16px; }
.field label { display: block; font-weight: 500; margin-bottom: 4px; }
.field .hint { color: var(--text-muted); font-size: 14px; margin-top: 4px; }
input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="date"], input[type="search"], select, textarea {
  width: 100%;
  min-height: 40px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 0;
  border-color: var(--accent);
}
.field-error { color: var(--danger); font-size: 14px; margin-top: 4px; }

/* A "how many to generate" input sitting inline next to a button, not in its
   own labelled field - the shared input rule's 100% width is sized for a
   full-width field, not a small fixed box. Sized for a 3-digit value (the
   generation count can go up to several hundred) plus the browser's native
   up/down spinner control, which eats a fixed ~20px regardless of the
   digits beside it - too narrow here and the spinner crowds the number down
   to an unreadable sliver rather than actually clipping it. */
.count-input {
  width: 5.5em;
  min-width: 80px;
  padding: 8px 4px 8px 10px;
  text-align: left;
}
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
legend { font-weight: 600; padding: 0 4px; }

.password-wrap { display: flex; gap: 8px; }
.password-wrap input { flex: 1; }
.reveal {
  min-width: 40px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-alt);
  cursor: pointer;
  font-size: 16px;
}

/* --- Banners ------------------------------------------------------------ */

.banner {
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 16px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
}
.banner-error { border-color: var(--danger); color: var(--danger); background: var(--danger-soft-bg); }
.banner-success { border-color: var(--success); color: var(--success); }
.banner-warning { border-color: var(--warning); color: var(--warning); }

/* --- Tables ------------------------------------------------------------- */

table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--surface-alt);
  border-bottom: 2px solid var(--border);
  padding: 8px 12px;
}
tbody td { padding: 8px 12px; border-bottom: 1px solid var(--border); height: 40px; }
tbody tr:nth-child(even) { background: var(--surface-alt); }
.table-wrap { overflow-x: auto; }
.row-actions { display: flex; gap: 4px; flex-wrap: wrap; }

/* --- Status pills ------------------------------------------------------- */

.pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 14px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
}
.pill-ready { color: var(--success); border-color: var(--success); }
.pill-failed { color: var(--danger); border-color: var(--danger); }
.pill-pending { color: var(--warning); border-color: var(--warning); }

/* --- Empty state -------------------------------------------------------- */

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

/* --- Flashcards --------------------------------------------------------- */

.flashcard {
  min-height: 220px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 20px;
  padding: 32px;
}
/* The answer card carries both class="flashcard" and the hidden attribute
   until revealed - an author-stylesheet class rule and the browser's own
   [hidden] rule sit at equal specificity, and author beats user-agent at a
   tie, so plain `.flashcard { display: flex }` was winning and the answer
   showed unconditionally regardless of the hidden attribute. This rule is
   more specific than either on its own, so hidden wins again when set. */
.flashcard[hidden] { display: none; }
.rating-row { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }

/* --- Test runner -------------------------------------------------------- */

.timer {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  padding: 4px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.timer-low { color: var(--danger); border-color: var(--danger); }

.choice { display: block; margin-bottom: 8px; }
.choice label {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  background: var(--surface);
}
.choice label:hover { background: var(--surface-alt); }
.choice input:focus-visible + span { outline: 2px solid var(--accent); }
.choice-correct { border-color: var(--success); }
.choice-wrong { border-color: var(--danger); }

.qnav { display: flex; flex-wrap: wrap; gap: 4px; }
.qnav a {
  min-width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text);
}
.qnav a.answered { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
.qnav a.flagged { border-color: var(--warning); border-width: 2px; }
.qnav a.current { outline: 2px solid var(--accent); }

.muted { color: var(--text-muted); }
.small { font-size: 14px; }
.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; }
.stack { display: flex; flex-direction: column; gap: 8px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { margin-left: auto; }
.prose { max-width: 72ch; }
.prose h2 { margin-top: 32px; }

/* Plain HTML disclosure, used for the audit log's per-row detail and the
   Help page's how-to guides - no JS, no library, just the element doing
   what it already does. */
details { border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; }
details + details { margin-top: 8px; }
details summary { cursor: pointer; font-weight: 500; }
details[open] summary { margin-bottom: 4px; }
.cite { font-size: 14px; color: var(--text-muted); }
/* Search hit highlighting. A fixed dark foreground rather than --text: that
   token flips to a light color in dark mode, which would fail contrast
   against the amber background there. */
mark { background: var(--warning); color: #1c1200; border-radius: 2px; padding: 0 1px; }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* --- Job status ---------------------------------------------------------- */

.job {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.job:last-child { border-bottom: none; }
.job .job-label { font-weight: 500; }
.job .job-detail { color: var(--text-muted); font-size: 14px; }
.job-spinner {
  width: 12px;
  height: 12px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: job-spin 0.9s linear infinite;
  flex: none;
}
@keyframes job-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .job-spinner { animation: none; border-top-color: var(--border); }
}

/* --- Copyright notice ---------------------------------------------------- */

.notice-copyright { border-left: 4px solid var(--accent); }
.notice-copyright p { margin: 0 0 8px; }

/* --- Rendered study guide ------------------------------------------------ */

.guide-body { max-width: 72ch; }
.guide-body h2 { font-size: 22px; margin: 32px 0 8px; }
.guide-body h3 { font-size: 18px; margin: 24px 0 8px; }
.guide-body h4 { font-size: 16px; margin: 20px 0 4px; color: var(--text-muted); }
.guide-body h2:first-child, .guide-body h3:first-child { margin-top: 0; }
.guide-body p { margin: 0 0 12px; }
.guide-body ul, .guide-body ol { margin: 0 0 12px; padding-left: 24px; }
.guide-body li { margin-bottom: 4px; }
.guide-body hr { border: none; border-top: 1px solid var(--border); margin: 24px 0; }
.guide-body code {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 0.9em;
  background: var(--surface-alt);
  padding: 1px 4px;
  border-radius: 4px;
}

/* --- Workflow stepper ----------------------------------------------------
 * documents -> guide -> flashcards -> questions. Always left-to-right - a
 * narrow viewport scrolls horizontally rather than wrapping the steps into a
 * vertical stack, which read as "top to bottom" instead of a pipeline. */

.stepper {
  display: flex;
  align-items: flex-start;
  flex-wrap: nowrap;
  gap: 4px;
  margin: 16px 0 24px;
  overflow-x: auto;
}
.stepper-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: 130px;
  flex: none;
  text-align: center;
  color: var(--text-muted);
}
.stepper-connector {
  flex: 1 0 24px;
  min-width: 24px;
  height: 2px;
  background: var(--border);
  margin-top: 19px;
}
.stepper-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  background: var(--surface);
}
.stepper-label { font-weight: 500; font-size: 14px; color: var(--text); }
.stepper-status { font-size: 12px; }

.stepper-done .stepper-icon { border-color: var(--success); color: var(--success); }
.stepper-done .stepper-status { color: var(--success); }
.stepper-failed .stepper-icon { border-color: var(--danger); color: var(--danger); }
.stepper-failed .stepper-status { color: var(--danger); }
.stepper-queued .stepper-icon,
.stepper-running .stepper-icon,
.stepper-processing .stepper-icon { border-color: var(--primary); }
.stepper-queued .stepper-status,
.stepper-running .stepper-status,
.stepper-processing .stepper-status { color: var(--primary); }
.stepper-not_started .stepper-icon { opacity: 0.5; }
/* A job that ran to completion with no error but produced nothing usable -
   distinct from "not_started" (never attempted) and not an error either,
   so neither the muted not-started look nor the alarming failed one fits. */
.stepper-empty .stepper-icon { border-color: var(--warning); color: var(--warning); }
.stepper-empty .stepper-status { color: var(--warning); }
