/* ── Reset & Base ────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f8f9fa;
  --surface: #ffffff;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --text: #1f2937;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.08);
}

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

#app {
  height: 100%;
  display: flex;
  flex-direction: column;
}

/* ── Shared ──────────────────────────────────────────────────── */
button {
  cursor: pointer;
  border: none;
  border-radius: var(--radius);
  font-size: .875rem;
  font-weight: 600;
  padding: .5rem 1rem;
  transition: background .15s, transform .1s;
}
button:active { transform: scale(.97); }

.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover { background: var(--primary-hover); }

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}
.btn-outline:hover { background: var(--bg); }

.btn-danger {
  background: var(--danger);
  color: #fff;
}

input, textarea {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .5rem .75rem;
  font-size: .875rem;
  font-family: inherit;
  outline: none;
  transition: border-color .15s;
  width: 100%;
}
input:focus, textarea:focus { border-color: var(--primary); }

/* ── Login ───────────────────────────────────────────────────── */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.login-card {
  background: var(--surface);
  border-radius: 16px;
  padding: 2.5rem 2rem;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,.15);
  max-width: 360px;
  width: 90%;
}

.login-card h1 {
  font-size: 1.75rem;
  margin-bottom: .25rem;
}

.login-card p {
  color: var(--text-muted);
  margin-bottom: 1.5rem;
  font-size: .9rem;
}

.google-btn {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .65rem 1.25rem;
  font-size: .9rem;
  font-weight: 600;
  color: var(--text);
  box-shadow: var(--shadow);
}
.google-btn:hover { background: var(--bg); }

.google-btn svg {
  width: 18px;
  height: 18px;
}

/* ── Navbar ──────────────────────────────────────────────────── */
.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .5rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.navbar-brand {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--primary);
  text-decoration: none;
}

.navbar-links {
  display: flex;
  gap: .5rem;
  align-items: center;
}

.navbar-links a {
  color: var(--text-muted);
  text-decoration: none;
  font-size: .8rem;
  font-weight: 500;
  padding: .35rem .6rem;
  border-radius: 8px;
  transition: background .15s;
}
.navbar-links a:hover, .navbar-links a.active {
  background: var(--bg);
  color: var(--primary);
}

.navbar .user-info {
  font-size: .8rem;
  color: var(--text-muted);
}

/* ── Learner selector ────────────────────────────────────────── */
.learner-selector {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .25rem .5rem;
  font-size: .8rem;
  font-weight: 500;
  background: var(--bg);
  color: var(--text);
  outline: none;
  cursor: pointer;
  max-width: 160px;
}
.learner-selector:focus { border-color: var(--primary); }

/* ── Points badge ────────────────────────────────────────────── */
.points-badge {
  display: inline-flex;
  align-items: center;
  gap: .25rem;
  background: linear-gradient(135deg, #fbbf24, #f59e0b);
  color: #78350f;
  font-size: .75rem;
  font-weight: 700;
  padding: .2rem .6rem;
  border-radius: 999px;
}

/* ── Chat ────────────────────────────────────────────────────── */
.chat-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: .75rem;
}

.message {
  max-width: 75%;
  padding: .75rem 1rem;
  border-radius: var(--radius);
  font-size: .9rem;
  line-height: 1.6;
  word-wrap: break-word;
}

.message.user {
  align-self: flex-end;
  background: var(--primary);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.message.assistant {
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.message.system {
  align-self: center;
  background: transparent;
  color: var(--text-muted);
  font-size: .8rem;
  font-style: italic;
}

/* ── Quiz ────────────────────────────────────────────────────── */
.quiz-card {
  background: #fef3c7;
  border: 1px solid #fcd34d;
  border-radius: var(--radius);
  padding: 1rem;
  margin-top: .5rem;
}

.quiz-card h4 {
  font-size: .85rem;
  margin-bottom: .5rem;
  color: #92400e;
}

.quiz-options {
  display: flex;
  flex-direction: column;
  gap: .35rem;
}

.quiz-option {
  text-align: left;
  background: #fff;
  border: 1px solid #fcd34d;
  border-radius: 8px;
  padding: .5rem .75rem;
  font-size: .85rem;
  color: var(--text);
}
.quiz-option:hover { background: #fffbeb; border-color: #f59e0b; }
.quiz-option.correct { background: #d1fae5; border-color: var(--success); }
.quiz-option.incorrect { background: #fee2e2; border-color: var(--danger); }

/* ── Chat input ──────────────────────────────────────────────── */
.chat-input-bar {
  display: flex;
  gap: .5rem;
  padding: .75rem 1rem;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.chat-input-bar input {
  flex: 1;
}

/* ── Loading ─────────────────────────────────────────────────── */
.loading-dots {
  display: inline-flex;
  gap: 4px;
  padding: .5rem 0;
}
.loading-dots span {
  width: 8px;
  height: 8px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: bounce .6s infinite alternate;
}
.loading-dots span:nth-child(2) { animation-delay: .2s; }
.loading-dots span:nth-child(3) { animation-delay: .4s; }

@keyframes bounce {
  to { opacity: .3; transform: translateY(-4px); }
}

.spinner {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  color: var(--text-muted);
  font-size: .9rem;
}

/* ── Parent Dashboard ────────────────────────────────────────── */
.dashboard {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  max-width: 900px;
  margin: 0 auto;
  width: 100%;
}

.dashboard h2 {
  font-size: 1.25rem;
  margin-bottom: 1rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}

.card h3 {
  font-size: 1rem;
  margin-bottom: .5rem;
}

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

.stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--primary);
}

.stat-label {
  font-size: .8rem;
  color: var(--text-muted);
}

/* ── Audit log ───────────────────────────────────────────────── */
.audit-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .85rem;
}

.audit-table th, .audit-table td {
  text-align: left;
  padding: .5rem .75rem;
  border-bottom: 1px solid var(--border);
}

.audit-table th {
  font-weight: 600;
  color: var(--text-muted);
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .03em;
}

.audit-filters {
  display: flex;
  gap: .5rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.audit-filters select, .audit-filters input {
  width: auto;
  min-width: 140px;
}

.role-badge {
  display: inline-block;
  padding: .1rem .5rem;
  border-radius: 999px;
  font-size: .7rem;
  font-weight: 600;
}
.role-badge.user { background: #dbeafe; color: #1e40af; }
.role-badge.assistant { background: #ede9fe; color: #5b21b6; }
.role-badge.system { background: #f3f4f6; color: #4b5563; }

/* ── Guidelines editor ───────────────────────────────────────── */
.guidelines-editor textarea {
  min-height: 200px;
  font-family: monospace;
  font-size: .85rem;
  resize: vertical;
}

.guidelines-editor .actions {
  display: flex;
  gap: .5rem;
  margin-top: .75rem;
}

/* ── Progress ────────────────────────────────────────────────── */
.mastery-bar {
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
  margin-top: .25rem;
}

.mastery-bar-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 4px;
  transition: width .3s ease;
}

.concept-list {
  display: flex;
  flex-direction: column;
  gap: .75rem;
}

.concept-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.concept-name {
  font-size: .85rem;
  font-weight: 500;
  flex: 1;
}

.concept-level {
  font-size: .75rem;
  color: var(--text-muted);
  min-width: 50px;
  text-align: right;
}

/* ── Empty state ─────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}

.empty-state h3 {
  font-size: 1rem;
  margin-bottom: .5rem;
  color: var(--text);
}

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 600px) {
  .message { max-width: 90%; }
  .dashboard { padding: 1rem; }
  .navbar-links a { font-size: .75rem; padding: .25rem .4rem; }
}
