/* Fonts shared with /main marketing page so the in-app feels like the same
   product. Fraunces is used only for top-level headings (h1/h2) to keep
   14px in-app density readable. JetBrains Mono shows up on labels &
   numerals. */
@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght,SOFT,WONK@9..144,300..900,0..100,0..1&family=Plus+Jakarta+Sans:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  --primary: #2649ff;            /* electric blue (matches /main) */
  --primary-dark: #1532b8;
  --primary-light: #ecf0ff;
  --success: #16a34a;
  --success-light: #ecfbe9;
  --warning: #b45309;
  --warning-light: #fef3c7;
  --danger: #b91c1c;
  --danger-light: #fef2f2;
  --text: #0a1432;               /* deep ink */
  --text-muted: #5b6376;         /* cool gray */
  --border: #cfccc2;             /* warm hairline rule */
  --bg: #f3f2ed;                 /* warm paper — main background */
  --bg-card: #ffffff;
  --bg-soft: #ebeae5;            /* paper-2: sidebars, hover states */
  --shadow-sm: 0 1px 2px rgba(10, 20, 50, .05);
  --shadow: 0 8px 24px -10px rgba(10, 20, 50, .12);
  --radius: 6px;
  --radius-sm: 4px;

  --serif: 'Fraunces', 'Times New Roman', Georgia, serif;
  --sans:  'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  --mono:  'JetBrains Mono', ui-monospace, "SFMono-Regular", Menlo, monospace;
  --grid:  rgba(10, 20, 50, .04);
}

[data-theme="dark"] {
  --primary-light: #1e293b;
  --success-light: #0f2419;
  --warning-light: #2a1f0a;
  --danger-light: #2a1212;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --border: #334155;
  --bg: #0f172a;
  --bg-card: #1e293b;
  --bg-soft: #1a2540;
  --grid: rgba(148, 163, 184, .04);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
/* Global UI density: shrink the whole in-app surface to 80% of nominal size.
   Marketing pages (marketing_*.html, role_page.html, demo.html, index.html)
   don't link this stylesheet, so the landing aesthetic is untouched.
   Desktop-only: on phones (<=768px) the zoom hack fights the device-width
   viewport and the responsive breakpoints, so we drop it there and let the
   mobile media block below size things at 1:1. */
@media (min-width: 769px) { html { zoom: 0.8; } }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  letter-spacing: -0.005em;
  position: relative;
}

/* Blueprint grid backdrop — matches /main visual language. Fixed to the
   viewport and below content so it doesn't disturb interactive widgets. */
body::before {
  content: '';
  position: fixed; inset: 0;
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 28px 28px;
  pointer-events: none;
  z-index: 0;
  mask-image: radial-gradient(ellipse 100% 60% at 50% 0%, black 30%, transparent 90%);
}

/* Paper grain — very subtle, blended via multiply. */
body::after {
  content: '';
  position: fixed; inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence baseFrequency='0.85' numOctaves='2' seed='6'/%3E%3CfeColorMatrix values='0 0 0 0 0.04  0 0 0 0 0.08  0 0 0 0 0.20  0 0 0 0.05 0'/%3E%3C/filter%3E%3Crect width='200' height='200' filter='url(%23n)'/%3E%3C/svg%3E");
  opacity: .35;
  mix-blend-mode: multiply;
  pointer-events: none;
  z-index: 1;
}
[data-theme="dark"] body::after { display: none; }

/* Ensure all real content floats above the backdrop. */
.layout, .modal-overlay, .sidebar-toggle { position: relative; z-index: 2; }

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2 {
  margin: 0;
  font-family: var(--serif);
  font-weight: 460;
  letter-spacing: -0.02em;
  font-variation-settings: "opsz" 96, "SOFT" 30;
}
h3, h4 {
  margin: 0;
  font-weight: 600;
  letter-spacing: -0.01em;
}
input, select, textarea, button { font: inherit; color: inherit; }

/* ---------- Layout ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 240px;
  background: var(--bg-soft);
  border-right: 1px solid var(--border);
  padding: 18px 16px;
  flex-shrink: 0;
  position: sticky; top: 0;
  height: 100vh; overflow-y: auto;
}
.sidebar-brand {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 19px;
  letter-spacing: -0.015em;
  padding: 6px 4px 18px;
  display: flex; align-items: baseline; gap: 6px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}
.sidebar-brand .icon { font-style: italic; color: var(--primary); font-size: 22px; }
.nav-section {
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 500;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: 16px 4px 6px;
  letter-spacing: .14em;
}
.sidebar-nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--text);
  text-decoration: none;
  font-size: 13px;
  transition: background .15s, color .15s;
}
.sidebar-nav a:hover { background: var(--primary-light); text-decoration: none; }
.sidebar-nav a.active {
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 600;
}
.sidebar-footer { font-size: 11px; color: var(--text-muted); padding: 16px 8px 4px; }
.main-content { flex: 1; min-width: 0; }
.topbar {
  background: rgba(243, 242, 237, .86);
  backdrop-filter: blur(12px) saturate(1.2);
  -webkit-backdrop-filter: blur(12px) saturate(1.2);
  border-bottom: 1px solid var(--border);
  padding: 14px 24px;
  display: flex; justify-content: space-between; align-items: center;
  position: sticky; top: 0; z-index: 5;
}
.topbar-title {
  font-family: var(--serif);
  font-size: 19px;
  font-weight: 460;
  letter-spacing: -0.015em;
  font-variation-settings: "opsz" 72, "SOFT" 20;
}
.topbar-actions { display: flex; gap: 8px; align-items: center; }
.page-content { padding: 24px; }

.sidebar-toggle {
  display: none;
  position: fixed; top: 12px; left: 12px; z-index: 20;
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 8px;
  width: 40px; height: 40px; cursor: pointer; font-size: 18px;
}
@media (max-width: 768px) {
  .sidebar { position: fixed; left: -260px; transition: left .2s ease; z-index: 15; }
  .sidebar.open { left: 0; }
  .sidebar-toggle { display: block; }

  /* Tighter chrome so dense in-app pages breathe on a phone. */
  .topbar { padding: 10px 14px 10px 64px; }
  .topbar-title { font-size: 16px; }
  .topbar-actions { flex-wrap: wrap; justify-content: flex-end; }
  .page-content { padding: 14px; }

  /* Dense tables (analytics, question bank, admin) become their own
     horizontal scroll container instead of overflowing the viewport.
     CSS-only — no template changes needed. */
  .page-content table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
    max-width: 100%;
  }

  /* Comfortable tap targets. */
  .btn { min-height: 40px; }
  .list-item { padding: 14px 0; }

  /* Stat cards and inline form controls stack full-width. */
  .stat-card { width: 100%; }
  .topbar-actions .btn,
  .topbar-actions form,
  .topbar-actions select { flex: 1 1 auto; }
}

@media (max-width: 480px) {
  .page-content { padding: 10px; }
  .stat-value { font-size: 26px; }
  .grid { gap: 12px; }
}

/* ---------- Cards / lists ---------- */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  margin-bottom: 16px;
}
.card-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
}
.card-header h3 {
  font-family: var(--serif);
  font-size: 17px;
  font-weight: 460;
  letter-spacing: -0.015em;
  font-variation-settings: "opsz" 72, "SOFT" 20;
}
.card-body { padding: 16px 18px; }
.list-item {
  display: flex; gap: 12px; align-items: center;
  padding: 12px 0; border-bottom: 1px solid var(--border);
  text-decoration: none; color: inherit;
}
.list-item:last-child { border-bottom: none; }
.list-item-body { flex: 1; min-width: 0; }
.list-item-title { font-weight: 600; font-size: 13px; margin-bottom: 2px; }
.list-item-meta { font-size: 12px; color: var(--text-muted); }

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 900px) { .grid-3, .grid-4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 600px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } }
.mb-2 { margin-bottom: 8px; }
.mb-4 { margin-bottom: 16px; }

.stat-card {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow-sm);
}
.stat-value {
  font-family: var(--serif);
  font-size: 32px;
  font-weight: 420;
  letter-spacing: -0.025em;
  font-variation-settings: "opsz" 72;
  line-height: 1.05;
}
.stat-label {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .14em;
  margin-top: 4px;
}
.stat-icon {
  width: 44px; height: 44px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center; font-size: 22px;
}
.flex-between { display: flex; justify-content: space-between; align-items: center; }

/* ---------- Buttons / forms ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 100px;          /* pill — matches /main aesthetic */
  border: 1px solid transparent;
  cursor: pointer;
  font-family: var(--sans);
  font-weight: 500;
  font-size: 13px;
  text-decoration: none;
  transition: all .2s ease;
}
.btn-sm { padding: 6px 14px; font-size: 12px; }
.btn-primary {
  background: var(--text);       /* deep ink, like /main primary CTAs */
  color: var(--bg);
}
.btn-primary:hover {
  background: var(--primary);
  text-decoration: none;
  transform: translateY(-1px);
  box-shadow: 0 8px 20px -10px var(--primary);
}
.btn-outline {
  border-color: var(--border);
  background: var(--bg-card);
  color: var(--text);
}
.btn-outline:hover {
  border-color: var(--text);
  color: var(--primary);
  text-decoration: none;
}
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #991b1b; text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.form-control, .form-select {
  width: 100%; padding: 8px 12px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); background: var(--bg-card); color: var(--text);
}
.form-control:focus, .form-select:focus { outline: 2px solid var(--primary); outline-offset: 0; border-color: var(--primary); }
.form-label {
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--text-muted);
  display: block;
  margin-bottom: 5px;
}
.form-group { margin-bottom: 12px; }

.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 100px;
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0;
}
.badge-success { background: var(--success-light); color: var(--success); }
.badge-warning { background: var(--warning-light); color: var(--warning); }
.badge-danger { background: var(--danger-light); color: var(--danger); }
.badge-primary { background: var(--primary-light); color: var(--primary); }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); }
th {
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--text-muted);
}

.q-thumb {
  width: 80px; height: 60px; object-fit: cover;
  border-radius: var(--radius-sm); border: 1px solid var(--border);
}

.empty-state { text-align: center; padding: 32px 16px; color: var(--text-muted); }
.empty-icon { font-size: 36px; margin-bottom: 8px; }
.empty-text { font-size: 13px; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 12px; }
.text-center { text-align: center; }

.fade-in { animation: fadeIn .25s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.modal-overlay {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .6); backdrop-filter: blur(2px);
  display: none; align-items: center; justify-content: center; z-index: 50;
}
.modal-overlay.active { display: flex; }
.modal {
  background: var(--bg-card); border-radius: var(--radius);
  max-width: 600px; width: 100%; max-height: 90vh; overflow: auto; margin: 16px;
}
.modal-header { padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-body { padding: 16px 18px; }
.modal-close { background: none; border: none; cursor: pointer; font-size: 18px; }

mark { background: #fef08a; padding: 0 2px; border-radius: 2px; }

/* Question card with answer choices in practice */
.q-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; margin-bottom: 12px;
}
.q-card img { max-width: 100%; border-radius: var(--radius-sm); margin-bottom: 12px; }
.choice-row { display: flex; gap: 8px; flex-wrap: wrap; }
.choice-btn {
  flex: 1 1 80px; min-width: 80px; padding: 10px;
  border: 2px solid var(--border); background: var(--bg-card); color: var(--text);
  border-radius: var(--radius-sm); cursor: pointer; font-weight: 600;
}
.choice-btn:hover:not(:disabled) { border-color: var(--primary); }
.choice-btn.chosen { border-color: var(--primary); background: var(--primary-light); }
.choice-btn.correct { border-color: var(--success); background: var(--success-light); color: var(--success); }
.choice-btn.wrong { border-color: var(--danger); background: var(--danger-light); color: var(--danger); }
