/* ============================================================
   MathPath Admin Dashboard — Styles
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #f5f7fa;
  color: #333;
  line-height: 1.6;
}

/* ── Header ─────────────────────────────────────────────── */
.header {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 1.5rem 2rem;
  box-shadow: 0 2px 8px rgba(0,0,0,.12);
}
.header h1 { font-size: 1.6rem; margin-bottom: .2rem; }
.header p  { opacity: .85; font-size: .9rem; }

/* ── Config bar ──────────────────────────────────────────── */
.config-bar {
  background: white;
  padding: .875rem 2rem;
  border-bottom: 1px solid #e1e4e8;
  display: flex;
  gap: .75rem;
  align-items: center;
  flex-wrap: wrap;
}
.config-bar input, .config-bar select {
  padding: .45rem .75rem;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: .875rem;
}
.config-bar input[type="text"],
.config-bar input[type="password"] { min-width: 260px; }
.remember-key {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  color: #4b5563;
  font-size: .82rem;
  white-space: nowrap;
}
.remember-key input { min-width: 0; }

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  padding: .45rem 1.25rem;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 500;
  font-size: .875rem;
  transition: background .15s, opacity .15s;
  white-space: nowrap;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }

.btn-primary  { background: #667eea; color: white; }
.btn-primary:hover:not(:disabled) { background: #5a67d8; }

.btn-success  { background: #10b981; color: white; }
.btn-success:hover:not(:disabled) { background: #059669; }

.btn-danger   { background: #fee2e2; color: #dc2626; }
.btn-danger:hover:not(:disabled)  { background: #fca5a5; }

.btn-copy     { background: #eff6ff; color: #2563eb; }
.btn-copy:hover:not(:disabled)    { background: #dbeafe; }

.btn-sm { padding: .3rem .75rem; font-size: .8rem; }
.btn-refresh { background: white; color: #667eea; border: 1px solid #667eea; border-radius: 6px; padding: .3rem .875rem; font-size: .8rem; cursor: pointer; }
.btn-refresh:hover { background: #eff3ff; }

/* ── Notice / error ──────────────────────────────────────── */
.notice {
  background: #eff6ff; border: 1px solid #bfdbfe; color: #1d4ed8;
  padding: .6rem 1rem; border-radius: 6px; font-size: .8rem;
}
.error-box {
  background: #fef2f2; border: 1px solid #fecaca; color: #dc2626;
  padding: .875rem 1rem; border-radius: 8px; margin: .75rem 2rem;
}
.success-msg { color: #059669; font-size: .875rem; margin-top: .5rem; }
.error-msg   { color: #dc2626; font-size: .875rem; margin-top: .5rem; }

/* ── Tab navigation ──────────────────────────────────────── */
.tab-nav {
  background: white;
  border-bottom: 2px solid #e5e7eb;
  padding: 0 2rem;
  display: flex;
  gap: 0;
  overflow-x: auto;
}
.tab-btn {
  padding: .7rem 1.25rem;
  border: none;
  background: none;
  font-size: .9rem;
  font-weight: 500;
  color: #6b7280;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  white-space: nowrap;
  transition: color .15s, border-color .15s;
}
.tab-btn:hover { color: #374151; }
.tab-btn.active { color: #667eea; border-bottom-color: #667eea; }

/* ── Tab sections ────────────────────────────────────────── */
.tab-section { display: none; }
.tab-section.active { display: block; }

.tab-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.25rem 2rem .5rem;
}
.tab-toolbar h2 { font-size: 1.1rem; color: #374151; }

/* ── Container / layout ──────────────────────────────────── */
.container { max-width: 1400px; margin: 0 auto; padding: 1.25rem 2rem 2rem; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1.25rem;
  margin-bottom: 1.5rem;
}
.charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(380px, 1fr));
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}
.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}
@media (max-width: 900px) {
  .two-col { grid-template-columns: 1fr; }
  .charts-grid { grid-template-columns: 1fr; }
}

/* ── Cards ───────────────────────────────────────────────── */
.card {
  background: white;
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
  padding: 1.25rem 1.5rem;
}
.card-title {
  font-size: 1rem;
  font-weight: 600;
  color: #374151;
  margin-bottom: 1rem;
}

.stat-card { background: white; padding: 1.25rem 1.5rem; border-radius: 12px; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.stat-card h3 { font-size: .75rem; color: #6b7280; text-transform: uppercase; letter-spacing: .05em; margin-bottom: .4rem; }
.stat-value  { font-size: 2rem; font-weight: 700; color: #1f2937; line-height: 1.1; }
.stat-sub    { font-size: .8rem; color: #9ca3af; margin-top: .25rem; }
.stat-change { font-size: .8rem; margin-top: .2rem; }
.stat-change.positive { color: #10b981; }
.stat-change.negative { color: #ef4444; }

/* Retention card color accents */
.stat-card.accent-d1  { border-top: 3px solid #667eea; }
.stat-card.accent-d7  { border-top: 3px solid #f59e0b; }
.stat-card.accent-d30 { border-top: 3px solid #10b981; }

/* ── Chart cards ─────────────────────────────────────────── */
.chart-card { background: white; padding: 1.25rem 1.5rem; border-radius: 12px; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.chart-card h2 { font-size: 1rem; font-weight: 600; color: #374151; margin-bottom: .875rem; }
.chart-container { position: relative; height: 280px; }
.chart-container.tall { height: 360px; }

/* ── Funnel ──────────────────────────────────────────────── */
.funnel { display: flex; flex-direction: column; gap: .75rem; }
.funnel-row { display: flex; align-items: center; gap: .75rem; }
.funnel-label { width: 130px; font-size: .85rem; color: #374151; flex-shrink: 0; text-align: right; }
.funnel-bar-wrap { flex: 1; background: #f3f4f6; border-radius: 4px; height: 28px; overflow: hidden; }
.funnel-bar { height: 100%; background: linear-gradient(90deg, #667eea, #764ba2); border-radius: 4px; transition: width .6s ease; display: flex; align-items: center; padding-left: .5rem; }
.funnel-bar span { color: white; font-size: .8rem; font-weight: 600; white-space: nowrap; }
.funnel-count { width: 80px; font-size: .85rem; color: #6b7280; flex-shrink: 0; }

/* ── Tables ──────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; border-radius: 12px; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
table.data-table { width: 100%; border-collapse: collapse; font-size: .875rem; background: white; }
table.data-table th {
  padding: .65rem 1rem;
  text-align: left;
  font-size: .72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: #6b7280;
  background: #f9fafb;
  border-bottom: 1px solid #e5e7eb;
  white-space: nowrap;
}
table.data-table td {
  padding: .65rem 1rem;
  border-bottom: 1px solid #f3f4f6;
  color: #374151;
  vertical-align: middle;
}
table.data-table tr:last-child td { border-bottom: none; }
table.data-table tr:hover td { background: #fafafa; }
table.data-table tr.clickable { cursor: pointer; }

.table-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: .875rem 1.25rem;
  background: white;
  border-bottom: 1px solid #e5e7eb;
  border-radius: 12px 12px 0 0;
}
.table-header h3 { font-size: .975rem; font-weight: 600; color: #374151; }

/* ── Topic mastery bar ───────────────────────────────────── */
.mastery-bar-wrap { background: #f3f4f6; border-radius: 4px; height: 8px; flex: 1; min-width: 60px; overflow: hidden; }
.mastery-bar { height: 100%; border-radius: 4px; transition: width .5s; }

/* ── Search / filter row ─────────────────────────────────── */
.filter-row {
  display: flex;
  gap: .625rem;
  align-items: center;
  flex-wrap: wrap;
  padding: .875rem 1.25rem;
  background: white;
  border-bottom: 1px solid #e5e7eb;
}
.filter-row input, .filter-row select {
  padding: .4rem .75rem;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: .875rem;
}
.filter-row input[type="text"] { min-width: 220px; }

/* ── Badges ──────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: .18rem .55rem;
  border-radius: 9999px;
  font-size: .72rem;
  font-weight: 600;
}
.badge-pending  { background: #dbeafe; color: #1d4ed8; }
.badge-active   { background: #d1fae5; color: #065f46; }
.badge-consumed { background: #f3f4f6; color: #6b7280; }
.badge-expired  { background: #fee2e2; color: #991b1b; }
.badge-mastered    { background: #d1fae5; color: #065f46; }
.badge-proficient  { background: #dbeafe; color: #1e40af; }
.badge-developing  { background: #fef3c7; color: #92400e; }
.badge-beginner    { background: #fee2e2; color: #991b1b; }
.badge-not-started { background: #f3f4f6; color: #6b7280; }

/* ── Code monospace ──────────────────────────────────────── */
.code-mono { font-family: 'Courier New', monospace; font-weight: 600; letter-spacing: .04em; color: #1f2937; }

/* ── Invite codes form ───────────────────────────────────── */
.invite-container { max-width: 1100px; margin: 0 auto; padding: 1.25rem 2rem 2rem; }
.form-row { display: flex; gap: .875rem; align-items: flex-end; flex-wrap: wrap; }
.form-group { display: flex; flex-direction: column; gap: .3rem; }
.form-group label { font-size: .75rem; font-weight: 500; color: #6b7280; text-transform: uppercase; letter-spacing: .04em; }
.form-group select, .form-group input[type="text"], .form-group input[type="number"] {
  padding: .45rem .75rem; border: 1px solid #d1d5db; border-radius: 6px; font-size: .875rem; background: white;
}
.form-group input[type="text"], .form-group input[type="number"] { min-width: 160px; }

/* ── Modal ───────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
  padding: 1rem;
}
.modal-dialog {
  background: white;
  border-radius: 16px;
  width: 100%;
  max-width: 680px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid #e5e7eb;
  flex-shrink: 0;
}
.modal-title    { font-size: 1.1rem; font-weight: 600; color: #1f2937; }
.modal-subtitle { font-size: .85rem; color: #6b7280; margin-top: .15rem; }
.modal-close {
  background: none; border: none; font-size: 1.4rem; color: #9ca3af;
  cursor: pointer; line-height: 1; padding: 0 .25rem; margin-left: .5rem;
}
.modal-close:hover { color: #374151; }
.modal-body { flex: 1; overflow-y: auto; padding: 1.25rem 1.5rem; }
.modal-section { margin-bottom: 1.25rem; }
.modal-section-title { font-size: .8rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: #6b7280; margin-bottom: .625rem; }

/* ── Mastery level rows in modal ─────────────────────────── */
.mastery-row { display: flex; align-items: center; gap: .5rem; padding: .35rem 0; border-bottom: 1px solid #f3f4f6; }
.mastery-row:last-child { border-bottom: none; }
.mastery-topic { flex: 1; font-size: .875rem; color: #374151; }
.mastery-score { font-size: .875rem; font-weight: 600; color: #1f2937; min-width: 40px; text-align: right; }

/* ── Misc ────────────────────────────────────────────────── */
.loading {
  text-align: center; padding: 3rem; color: #9ca3af; font-size: .9rem;
}
.loading::after {
  content: '';
  display: inline-block; width: 18px; height: 18px;
  border: 2px solid #e5e7eb; border-top-color: #667eea;
  border-radius: 50%; animation: spin .8s linear infinite;
  margin-left: .5rem; vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty-state { text-align: center; padding: 2.5rem; color: #9ca3af; font-size: .875rem; }
.last-updated { text-align: right; color: #9ca3af; font-size: .8rem; margin-top: .75rem; }
.hidden { display: none !important; }
.mb-1 { margin-bottom: .5rem; }
.mb-2 { margin-bottom: 1rem; }
.mt-1 { margin-top: .5rem; }
.text-muted { color: #9ca3af; }
.text-sm { font-size: .85rem; }

/* ── Conversion stat mini-cards ─────────────────────────── */
.mini-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin-bottom: 1.5rem; }
.mini-stat { background: white; border-radius: 10px; padding: 1rem 1.25rem; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.mini-stat .label { font-size: .75rem; color: #6b7280; text-transform: uppercase; letter-spacing: .04em; }
.mini-stat .value { font-size: 1.5rem; font-weight: 700; color: #1f2937; }

/* ── Question type badges ────────────────────────────────── */
.badge-q-mc   { background: #ede9fe; color: #6d28d9; }
.badge-q-tf   { background: #fef3c7; color: #92400e; }
.badge-q-free { background: #d1fae5; color: #065f46; }
.badge-q-fill { background: #dbeafe; color: #1e40af; }
.badge-q-word { background: #fce7f3; color: #9d174d; }
.badge-q-other{ background: #f3f4f6; color: #6b7280; }
.badge-q-ai   { background: #fef3c7; color: #b45309; }
.badge-q-seed { background: #e0f2fe; color: #0369a1; }
.badge-q-viz  { background: #ede9fe; color: #7c3aed; font-size: .7rem; vertical-align: middle; }

/* ── Question preview text ───────────────────────────────── */
.q-preview {
  display: block;
  color: #374151;
  font-size: .875rem;
  line-height: 1.45;
  word-break: break-word;
}
.q-preview:hover { color: #667eea; text-decoration: underline; }

/* ── Question modal form groups ──────────────────────────── */
.q-form-group {
  display: flex;
  flex-direction: column;
  gap: .3rem;
  margin-bottom: 1rem;
}
.q-form-group label {
  font-size: .75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: #6b7280;
}
.q-form-group input[type="text"],
.q-form-group input[type="number"],
.q-form-group textarea {
  padding: .45rem .75rem;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: .875rem;
  font-family: inherit;
  resize: vertical;
  background: white;
}
.q-form-group textarea { line-height: 1.5; }
