/* ═══════════════════════════════════════════════════════════════
   Sophia's N5 Study App
   Brand: Black (#1a1a1a), Gold (#FFD700), White (#fff)
   Matches Stein Group colour scheme.
   ═══════════════════════════════════════════════════════════════ */

:root {
  --black:      #1a1a1a;
  --black-deep: #000000;
  --gold:       #FFD700;
  --gold-dark:  #e6c200;
  --gold-light: #fff8cc;
  --gold-pale:  #fffbe6;
  --white:      #ffffff;
  --bg:         #f5f5f0;
  --border:     #e0e0d8;
  --text:       #1a1a1a;
  --text-muted: #666660;
  --green:      #16a34a;
  --amber:      #d97706;
  --red:        #dc2626;
  --shadow-sm:  0 1px 3px rgba(0,0,0,0.10);
  --shadow-md:  0 2px 8px rgba(0,0,0,0.14);
  --shadow-lg:  0 4px 20px rgba(0,0,0,0.16);
  --radius:     10px;
}

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

html { font-size: 17px; -webkit-text-size-adjust: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 1rem;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: inherit; text-decoration: none; }
img { max-width: 100%; height: auto; }

/* ─── Navigation ────────────────────────────────────────────── */

.site-nav {
  background: var(--black);
  border-bottom: 4px solid var(--gold);
  position: sticky;
  top: 0;
  z-index: 1000;
  box-shadow: var(--shadow-md);
}

.nav-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1.25rem;
  height: 60px;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--white);
  font-weight: 700;
  font-size: 1rem;
  text-decoration: none;
}

.nav-logo {
  width: 36px;
  height: 36px;
  background: var(--gold);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.nav-logo svg { color: var(--black); }

.nav-links {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.nav-link {
  color: #c0bfba;
  font-size: 0.9rem;
  font-weight: 500;
  padding: 0.4rem 0.75rem;
  border-radius: 6px;
  transition: color 0.15s, background 0.15s;
}
.nav-link:hover { color: var(--gold); }

.nav-logout {
  background: rgba(255,215,0,0.12);
  color: var(--gold);
  font-size: 0.875rem;
  font-weight: 600;
  padding: 0.45rem 1rem;
  border-radius: 6px;
  border: 1px solid rgba(255,215,0,0.3);
  transition: background 0.15s;
  cursor: pointer;
}
.nav-logout:hover { background: rgba(255,215,0,0.22); }

/* ─── Buttons ───────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font-weight: 700;
  border-radius: var(--radius);
  cursor: pointer;
  transition: filter 0.15s, transform 0.1s;
  border: none;
  white-space: nowrap;
  text-align: center;
  text-decoration: none;
}
.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--gold);
  color: var(--black);
  font-size: 1rem;
  padding: 0.85rem 1.5rem;
  min-height: 52px;
  box-shadow: 0 2px 8px rgba(255,215,0,0.35);
}
.btn-primary:hover { filter: brightness(1.06); }
.btn-primary:disabled {
  background: #d0cfc8;
  color: #888;
  box-shadow: none;
  cursor: not-allowed;
  transform: none;
}

.btn-dark {
  background: var(--black);
  color: var(--white);
  font-size: 1rem;
  padding: 0.85rem 1.5rem;
  min-height: 52px;
}
.btn-dark:hover { background: #2a2a2a; }

.btn-ghost {
  background: #ebebeb;
  color: var(--black);
  font-size: 0.9rem;
  padding: 0.75rem 1.2rem;
  min-height: 48px;
}
.btn-ghost:hover { background: #ddd; }

.btn-sm {
  font-size: 0.875rem;
  padding: 0.6rem 1rem;
  min-height: 42px;
}

.btn-full { width: 100%; }

/* ─── Cards ─────────────────────────────────────────────────── */

.card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-sm);
}

.card-header {
  padding: 1.1rem 1.4rem;
  border-bottom: 1px solid #f0efe8;
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--black);
}

.card-body { padding: 1.4rem; }

/* ─── Form inputs ───────────────────────────────────────────── */

.form-input {
  width: 100%;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 0.8rem 1rem;
  font-size: 1rem;
  color: var(--text);
  background: var(--white);
  transition: border-color 0.15s, box-shadow 0.15s;
  outline: none;
}
.form-input:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(255,215,0,0.2);
}

.form-label {
  display: block;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--black);
  margin-bottom: 0.4rem;
}

.form-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.3rem;
}

/* ─── Flash messages ────────────────────────────────────────── */

.flash-message {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 1rem 1.1rem;
  border-radius: var(--radius);
  margin-bottom: 0.75rem;
  font-size: 0.9rem;
  font-weight: 500;
  animation: slideIn 0.25s ease-out;
}
.flash-success {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  color: #15803d;
}
.flash-error {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #b91c1c;
}

@keyframes slideIn {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ─── Subject colour chips ──────────────────────────────────── */

.subj-english  { background: #4f46e5; }
.subj-maths    { background: #0369a1; }
.subj-history  { background: #92400e; }
.subj-spanish  { background: #b91c1c; }
.subj-physics  { background: #0e7490; }
.subj-biology  { background: #15803d; }
.subj-business { background: #0f766e; }

.subj-chip {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 0.85rem;
  flex-shrink: 0;
}

/* ─── Progress / mastery bars ───────────────────────────────── */

.mastery-bar {
  height: 10px;
  border-radius: 9999px;
  background: #ebebeb;
  overflow: hidden;
}

.mastery-fill {
  height: 100%;
  border-radius: 9999px;
  transition: width 0.6s cubic-bezier(0.4,0,0.2,1);
}

.mastery-fill.green  { background: var(--green); }
.mastery-fill.amber  { background: var(--amber); }
.mastery-fill.red    { background: var(--red); }
.mastery-fill.gold   { background: var(--gold); }

/* ─── Score badges ──────────────────────────────────────────── */

.score-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  border-radius: 9999px;
  font-size: 0.8rem;
  font-weight: 700;
  padding: 3px 10px;
}
.score-full    { background: #dcfce7; color: #166534; }
.score-partial { background: #fef9c3; color: #92400e; }
.score-none    { background: #fee2e2; color: #991b1b; }

/* ─── Gold points badge ─────────────────────────────────────── */

.points-badge {
  background: var(--black);
  border: 2px solid var(--gold);
  color: var(--gold);
  border-radius: 12px;
  padding: 0.65rem 1.1rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
.points-badge .pts-num { font-size: 1.3rem; font-weight: 800; line-height: 1; }
.points-badge .pts-cash { font-size: 0.8rem; color: #c0bfba; }

/* ─── Review banner ─────────────────────────────────────────── */

.review-banner {
  background: var(--gold-pale);
  border: 1px solid #fde68a;
  border-left: 4px solid var(--gold);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
}

/* ─── Subject study card ────────────────────────────────────── */

.subject-card {
  background: var(--white);
  border: 2px solid var(--border);
  border-radius: 14px;
  padding: 1.25rem;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.subject-card:hover {
  border-color: var(--gold);
  box-shadow: 0 4px 16px rgba(255,215,0,0.2);
}

/* ─── Login PIN pad ─────────────────────────────────────────── */

.pin-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid #ccc;
  transition: background 0.15s, border-color 0.15s;
}
.pin-dot.filled {
  background: var(--gold);
  border-color: var(--gold-dark);
}

.numpad-btn {
  background: var(--white);
  border: 2px solid var(--border);
  border-radius: 12px;
  min-height: 68px;
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--black);
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, transform 0.08s;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.numpad-btn:hover  { background: var(--gold-pale); border-color: var(--gold); }
.numpad-btn:active { transform: scale(0.93); background: var(--gold-light); }

.numpad-clear {
  background: #fef2f2;
  border-color: #fecaca;
  color: var(--red);
  font-size: 0.95rem;
  font-weight: 700;
}
.numpad-back {
  background: #f9fafb;
  border-color: #e5e7eb;
}

/* ─── Chat interface ────────────────────────────────────────── */

.chat-wrap {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.chat-topbar {
  background: var(--black);
  border-bottom: 3px solid var(--gold);
  padding: 0 1rem;
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  box-shadow: var(--shadow-md);
}

.chat-topbar-title { color: var(--white); font-weight: 700; font-size: 1rem; }
.chat-topbar-sub   { color: #b0afa8; font-size: 0.8rem; }

.chat-get-q-btn {
  background: var(--gold);
  color: var(--black);
  font-weight: 700;
  font-size: 0.85rem;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  transition: filter 0.15s;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  min-height: 40px;
}
.chat-get-q-btn:hover { filter: brightness(1.08); }
.chat-get-q-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.chat-end-btn {
  background: transparent;
  color: #b0afa8;
  font-weight: 600;
  font-size: 0.85rem;
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.15);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
  min-height: 40px;
}
.chat-end-btn:hover { color: #ff6b6b; border-color: #ff6b6b; }

#chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.2rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  background: var(--bg);
}

.chat-input-area {
  background: var(--white);
  border-top: 1px solid var(--border);
  padding: 0.85rem 1rem;
  flex-shrink: 0;
}

.chat-input-row {
  display: flex;
  gap: 0.6rem;
  align-items: flex-end;
  max-width: 860px;
  margin: 0 auto;
}

#chat-input {
  flex: 1;
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 0.75rem 1rem;
  font-size: 1rem;
  resize: none;
  overflow: hidden;
  outline: none;
  min-height: 50px;
  max-height: 130px;
  line-height: 1.45;
  transition: border-color 0.15s, box-shadow 0.15s;
}
#chat-input:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(255,215,0,0.2);
}

#send-btn {
  width: 50px;
  height: 50px;
  background: var(--gold);
  color: var(--black);
  border: none;
  border-radius: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: filter 0.15s, transform 0.1s;
}
#send-btn:hover:not(:disabled) { filter: brightness(1.08); }
#send-btn:active:not(:disabled) { transform: scale(0.95); }
#send-btn:disabled { background: #ddd; cursor: not-allowed; }

.pending-indicator {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
  color: #92400e;
  background: var(--gold-pale);
  border: 1px solid #fde68a;
  border-radius: 8px;
  padding: 0.45rem 0.75rem;
  margin-top: 0.5rem;
  max-width: 860px;
  margin-left: auto;
  margin-right: auto;
}

/* ─── Chat message bubbles ──────────────────────────────────── */

.msg-user {
  display: flex;
  justify-content: flex-end;
}
.msg-user .bubble {
  background: var(--black);
  color: var(--white);
  border-radius: 18px 18px 4px 18px;
  padding: 0.8rem 1rem;
  max-width: 82%;
  font-size: 0.95rem;
  line-height: 1.5;
}

.msg-agent {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
}
.agent-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--black);
  border: 2px solid var(--gold);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
}
.agent-avatar svg { color: var(--gold); }

.msg-agent .bubble {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 4px 18px 18px 18px;
  padding: 0.8rem 1rem;
  max-width: 82%;
  font-size: 0.95rem;
  line-height: 1.55;
}

.msg-assessor .bubble {
  background: #f0fdf4;
  border-color: #bbf7d0;
}

.msg-question .bubble {
  background: var(--white);
  border: 2px solid var(--gold);
  border-radius: 14px;
  padding: 1rem 1.1rem;
  width: 100%;
  max-width: 760px;
  align-self: center;
}

.question-badge {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.75rem;
  font-weight: 700;
  color: #92400e;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.5rem;
}

.cmd-badge {
  display: inline-block;
  background: var(--gold);
  color: var(--black);
  font-size: 0.75rem;
  font-weight: 700;
  padding: 1px 8px;
  border-radius: 4px;
}

.seen-warning {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.8rem;
  color: var(--amber);
  margin-top: 0.6rem;
}

/* ─── Typing indicator ──────────────────────────────────────── */

.typing-dot {
  width: 8px;
  height: 8px;
  background: #bbb;
  border-radius: 50%;
  display: inline-block;
  animation: bounce 1.4s ease-in-out infinite;
}
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
  0%,60%,100% { transform: translateY(0); opacity: 0.4; }
  30%         { transform: translateY(-6px); opacity: 1; }
}

/* ─── Marks badge (in chat) ─────────────────────────────────── */

.marks-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border-radius: 9999px;
  font-size: 0.8rem;
  font-weight: 700;
  padding: 3px 10px;
  margin-bottom: 0.5rem;
}
.marks-chip.full    { background: #dcfce7; color: #15803d; }
.marks-chip.partial { background: #fef9c3; color: #92400e; }
.marks-chip.none    { background: #fee2e2; color: #b91c1c; }

/* ─── Modals ────────────────────────────────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 1rem;
}
.modal-box {
  background: var(--white);
  border-radius: 18px;
  padding: 1.8rem;
  max-width: 380px;
  width: 100%;
  box-shadow: var(--shadow-lg);
}
.modal-title {
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  color: var(--black);
}
.modal-text {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 1.4rem;
}
.modal-actions {
  display: flex;
  gap: 0.75rem;
}

/* ─── Scrollbar ─────────────────────────────────────────────── */

#chat-messages::-webkit-scrollbar { width: 4px; }
#chat-messages::-webkit-scrollbar-track { background: transparent; }
#chat-messages::-webkit-scrollbar-thumb { background: #d0d0c8; border-radius: 9999px; }

/* ─── Topic list ────────────────────────────────────────────── */

.topic-unit-header {
  background: var(--black);
  color: var(--gold);
  padding: 0.5rem 1.2rem;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.topic-row {
  padding: 0.85rem 1.2rem;
  border-bottom: 1px solid #f0efe8;
}
.topic-row:last-child { border-bottom: none; }

/* ─── KPI stat cards ────────────────────────────────────────── */

.kpi-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.1rem;
  text-align: center;
}
.kpi-card .kpi-num {
  font-size: 1.8rem;
  font-weight: 800;
  line-height: 1;
}
.kpi-card .kpi-label {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 0.3rem;
}

/* ─── Print styles (parent view) ───────────────────────────── */

@media print {
  .site-nav, footer, .no-print, button { display: none !important; }
  body { background: white; font-size: 13px; }
  .card { border: 1px solid #ddd; box-shadow: none; }
}

/* ─── Mobile ────────────────────────────────────────────────── */

@media (max-width: 640px) {
  html { font-size: 16px; }

  .btn-primary, .btn-dark { min-height: 54px; font-size: 1rem; }

  input[type="text"],
  input[type="password"],
  input[type="email"],
  input[type="number"],
  select,
  textarea {
    font-size: 16px; /* prevent iOS zoom */
  }

  .numpad-btn { min-height: 64px; font-size: 1.5rem; }

  #chat-input { font-size: 16px; }

  .chat-topbar { height: 54px; }
}

/* ─── Loading spinner ───────────────────────────────────────── */

.spinner {
  width: 22px;
  height: 22px;
  border: 3px solid #e0e0d8;
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Misc utils ────────────────────────────────────────────── */

.text-gold  { color: var(--gold); }
.bg-gold    { background: var(--gold); }
.border-gold{ border-color: var(--gold); }

.divider { border: none; border-top: 1px solid var(--border); margin: 1.25rem 0; }
