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

:root {
  --bg: #FAFAF5;
  --navy: #1B2838;
  --grey-bubble: #F0F0EC;
  --teal: #3D8B7A;
  --teal-dark: #2E6B5E;
  --red: #8B2500;
  --text-secondary: #6B7280;
  --border: #E5E5E0;
  --white: #FFFFFF;
  --font-serif: 'Lora', Georgia, serif;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

html, body {
  height: 100%;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--navy);
  font-size: 15px;
  line-height: 1.5;
}

/* == Overlays == */
.overlay {
  position: fixed; inset: 0;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  transition: opacity 0.3s;
}
.overlay.hidden { display: none; }
.overlay-content {
  text-align: center;
  max-width: 480px;
  padding: 2rem;
}
.overlay-content h1 {
  font-family: var(--font-serif);
  font-size: 2.5rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}
.overlay-content .subtitle {
  color: var(--text-secondary);
  font-size: 1.1rem;
  margin-bottom: 2rem;
}
.summary-text {
  text-align: left;
  background: var(--grey-bubble);
  border-radius: 12px;
  padding: 1.25rem;
  margin-bottom: 1.5rem;
  font-family: var(--font-serif);
  line-height: 1.7;
}
.end-scores {
  display: flex; gap: 1.5rem; justify-content: center;
  margin-bottom: 2rem;
}
.end-score-item { text-align: center; }
.end-score-item .es-val { font-size: 1.8rem; font-weight: 600; color: var(--teal); }
.end-score-item .es-label { font-size: 0.8rem; color: var(--text-secondary); }
.end-actions { display: flex; gap: 1rem; justify-content: center; }

/* == Buttons == */
.btn-primary {
  background: var(--teal); color: var(--white);
  border: none; border-radius: 8px;
  padding: 0.75rem 2rem;
  font-size: 1rem; font-weight: 500;
  cursor: pointer; transition: background 0.2s;
  text-decoration: none; display: inline-block;
}
.btn-primary:hover { background: var(--teal-dark); }
.btn-secondary {
  background: var(--white); color: var(--navy);
  border: 2px solid var(--border); border-radius: 8px;
  padding: 0.7rem 2rem;
  font-size: 1rem; font-weight: 500;
  cursor: pointer; transition: border-color 0.2s;
  text-decoration: none; display: inline-block;
}
.btn-secondary:hover { border-color: var(--teal); color: var(--teal); }

/* == Top Bar == */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 1.5rem;
  height: 56px;
  border-bottom: 1px solid var(--border);
  background: var(--white);
  position: sticky; top: 0; z-index: 50;
}
.topbar-left { display: flex; align-items: center; gap: 1rem; }
.brand {
  font-family: var(--font-serif);
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--navy);
  text-decoration: none;
}
.page-title { color: var(--text-secondary); font-size: 0.9rem; }
.topbar-right { display: flex; align-items: center; gap: 1rem; }
.timer {
  font-variant-numeric: tabular-nums;
  font-size: 0.9rem;
  font-weight: 500;
  padding: 0.3rem 0.75rem;
  border-radius: 6px;
  background: var(--grey-bubble);
}
.timer.active { background: #D4EDDA; color: #155724; }
.timer.idle { background: #FFF3CD; color: #856404; }
.timer.overtime { background: #F8D7DA; color: #721C24; }
.btn-end {
  background: none; border: 1px solid var(--red); color: var(--red);
  border-radius: 6px; padding: 0.3rem 0.75rem;
  font-size: 0.85rem; cursor: pointer; font-weight: 500;
  transition: all 0.2s;
}
.btn-end:hover { background: var(--red); color: var(--white); }

/* == Main Layout == */
.app { display: flex; flex-direction: column; height: 100vh; }
.app.hidden { display: none; }
.main-layout {
  display: flex; flex: 1; overflow: hidden;
}

/* == Chat Panel == */
.chat-panel {
  flex: 1; display: flex; flex-direction: column;
  min-width: 0;
}
.chat-messages {
  flex: 1; overflow-y: auto;
  padding: 1.5rem;
  display: flex; flex-direction: column; gap: 0.75rem;
}

/* Message Bubbles */
.msg {
  max-width: 72%;
  padding: 0.75rem 1rem;
  border-radius: 16px;
  line-height: 1.6;
  animation: fadeIn 0.25s ease;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.msg.tutor {
  align-self: flex-start;
  background: var(--grey-bubble);
  color: var(--navy);
  font-family: var(--font-serif);
  border-bottom-left-radius: 4px;
}
.msg.student {
  align-self: flex-end;
  background: var(--teal);
  color: var(--white);
  border-bottom-right-radius: 4px;
}
.msg.nudge {
  align-self: flex-start;
  background: #FFF5F2;
  color: var(--red);
  font-family: var(--font-serif);
  font-style: italic;
  border-left: 3px solid var(--red);
  border-radius: 4px 12px 12px 4px;
}

/* Typing indicator */
.typing-indicator {
  display: inline-flex; gap: 4px; padding: 0.75rem 1rem;
  align-self: flex-start;
  background: var(--grey-bubble);
  border-radius: 16px; border-bottom-left-radius: 4px;
}
.typing-indicator span {
  width: 7px; height: 7px; border-radius: 50%;
  background: #999;
  animation: bounce 1.2s infinite;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.15s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-6px); }
}

/* == Nudge Banner == */
.nudge-banner {
  padding: 0.6rem 1.5rem;
  background: #FFF5F2;
  color: var(--red);
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 0.9rem;
  border-top: 1px solid #F0D0C8;
  text-align: center;
}
.nudge-banner.hidden { display: none; }

/* == Input Area == */
.input-area {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  background: var(--white);
  display: flex; flex-direction: column; gap: 0.75rem;
  align-items: center;
}
.text-input-row {
  display: flex; width: 100%; gap: 0.5rem;
}
#text-input {
  flex: 1; padding: 0.6rem 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
  font-family: var(--font-sans);
  outline: none;
  transition: border-color 0.2s;
}
#text-input:focus { border-color: var(--teal); }
.btn-send {
  background: var(--teal); color: var(--white);
  border: none; border-radius: 8px;
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: background 0.2s;
}
.btn-send:hover { background: var(--teal-dark); }

/* Mic Button */
.btn-mic {
  background: none; border: 2px solid var(--teal);
  color: var(--teal);
  border-radius: 50%;
  width: 64px; height: 64px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: all 0.2s;
  position: relative;
}
.btn-mic .mic-label {
  position: absolute; bottom: -22px;
  font-size: 0.7rem; color: var(--text-secondary);
  white-space: nowrap;
}
.btn-mic:hover { background: var(--teal); color: var(--white); }
.btn-mic.listening {
  background: var(--teal); color: var(--white);
  animation: pulse 1.5s infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(61,139,122,0.4); }
  50% { box-shadow: 0 0 0 14px rgba(61,139,122,0); }
}
.btn-mic.unsupported { opacity: 0.3; cursor: not-allowed; }

/* == Scores Sidebar == */
.scores-sidebar {
  width: 220px;
  padding: 1.5rem 1.25rem;
  border-left: 1px solid var(--border);
  background: var(--white);
  overflow-y: auto;
}
.scores-sidebar h3 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  margin-bottom: 1.25rem;
}
.score-item { margin-bottom: 1.25rem; }
.score-header { display: flex; justify-content: space-between; margin-bottom: 0.35rem; }
.score-label { font-size: 0.85rem; font-weight: 500; }
.score-value { font-size: 0.85rem; font-weight: 600; color: var(--teal); }
.progress-bar {
  height: 8px; background: var(--grey-bubble); border-radius: 4px; overflow: hidden;
}
.progress-fill {
  height: 100%; border-radius: 4px; transition: width 0.5s ease;
}
.progress-fill.attention { background: var(--teal); }
.progress-fill.comprehension { background: #5B8DBE; }
.progress-fill.accuracy { background: #D4883E; }

.session-stats {
  margin-top: 2rem; padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}
.stat {
  display: flex; justify-content: space-between;
  font-size: 0.85rem; margin-bottom: 0.5rem;
}
.stat-label { color: var(--text-secondary); }

/* == Dashboard == */
.dashboard-body { overflow-y: auto; }
.dashboard {
  max-width: 1100px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}
.summary-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}
.card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
  text-align: center;
}
.card-value { display: block; font-size: 2rem; font-weight: 600; color: var(--teal); }
.card-label { font-size: 0.8rem; color: var(--text-secondary); }

.chart-section {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  margin-bottom: 2rem;
}
.chart-section h2 { font-size: 1.1rem; margin-bottom: 1rem; }
.chart-container { position: relative; height: 300px; }

.dashboard-columns {
  display: grid; grid-template-columns: 1fr 2fr; gap: 1.5rem;
}
.weak-areas, .session-history {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
}
.weak-areas h2, .session-history h2 { font-size: 1.1rem; margin-bottom: 1rem; }

.weak-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--border);
}
.weak-item:last-child { border-bottom: none; }
.weak-topic { font-size: 0.9rem; }
.weak-mastery {
  font-size: 0.8rem; font-weight: 600;
  color: var(--red);
}

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th { text-align: left; font-weight: 600; color: var(--text-secondary); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; padding: 0.6rem 0.75rem; border-bottom: 2px solid var(--border); }
td { padding: 0.6rem 0.75rem; border-bottom: 1px solid var(--border); }

.empty-state {
  text-align: center; padding: 4rem 2rem;
}
.empty-state h2 { margin-bottom: 0.5rem; }
.empty-state p { color: var(--text-secondary); margin-bottom: 1.5rem; }

/* == Responsive == */
@media (max-width: 768px) {
  .main-layout { flex-direction: column; }
  .scores-sidebar {
    width: 100%; border-left: none; border-top: 1px solid var(--border);
    display: flex; flex-wrap: wrap; gap: 1rem; padding: 1rem;
  }
  .scores-sidebar h3 { width: 100%; margin-bottom: 0.5rem; }
  .score-item { flex: 1; min-width: 120px; margin-bottom: 0; }
  .session-stats { width: 100%; margin-top: 0.5rem; padding-top: 0.75rem; display: flex; gap: 2rem; }
  .dashboard-columns { grid-template-columns: 1fr; }
  .msg { max-width: 85%; }
}

/* == End Session Screen == */
.end-screen { max-width: 520px; }
.end-checkmark {
  width: 72px; height: 72px;
  border-radius: 50%;
  background: var(--teal);
  color: var(--white);
  font-size: 2.2rem;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 1.25rem;
}
.end-screen h1 {
  font-family: var(--font-serif);
  font-size: 1.8rem;
  margin-bottom: 1.5rem;
}
.end-bullets {
  text-align: left;
  background: var(--grey-bubble);
  border-radius: 12px;
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.5rem;
  font-family: var(--font-serif);
  font-size: 0.95rem;
  line-height: 1.8;
}

/* == Tutor Avatar == */
.tutor-avatar {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  object-fit: cover;
  margin-bottom: 1.25rem;
  border: 3px solid var(--teal);
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.topbar-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--teal);
}
