:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #dbeafe;
  --primary-ring: rgba(37, 99, 235, 0.15);
  --bg: #f0f4f8;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --success-bg: #f0fdf4;
  --success-border: #86efac;
  --success-text: #166534;
  --radius: 18px;
  --radius-sm: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.1);
}

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

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

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ── Header ── */
header {
  background: var(--primary);
  color: #fff;
  padding: 12px 20px;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(37,99,235,0.35);
  z-index: 10;
}

.header-inner {
  max-width: 820px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.3px;
  flex-shrink: 0;
}

.header-subtitle {
  flex: 1;
  font-size: 0.8125rem;
  opacity: 0.8;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn-outline {
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.35);
  color: #fff;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.8125rem;
  font-weight: 500;
  transition: background 0.15s;
  white-space: nowrap;
  flex-shrink: 0;
}
.btn-outline:hover { background: rgba(255,255,255,0.25); }

/* ── Main ── */
#main {
  flex: 1;
  overflow: hidden;
  display: flex;
  justify-content: center;
}

/* ── Welcome ── */
.welcome-view {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 16px;
  width: 100%;
}

.welcome-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 48px 40px;
  max-width: 480px;
  width: 100%;
  text-align: center;
  box-shadow: var(--shadow-md);
}

.welcome-icon { margin-bottom: 20px; }

.welcome-title {
  font-size: 2rem;
  font-weight: 800;
  color: var(--primary);
  letter-spacing: -0.5px;
  margin-bottom: 4px;
}

.welcome-heading {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 16px;
}

.welcome-desc {
  color: var(--text-muted);
  font-size: 0.9375rem;
  line-height: 1.65;
  margin-bottom: 28px;
}

.welcome-note {
  margin-top: 16px;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 10px 22px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.9375rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: background 0.15s, opacity 0.15s;
}
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary.btn-large { padding: 14px 32px; font-size: 1rem; border-radius: var(--radius-sm); }

/* ── Chat view ── */
.chat-view {
  width: 100%;
  max-width: 820px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#chatArea {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px 8px;
  scroll-behavior: smooth;
}

#messages {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* ── Message bubbles ── */
.msg {
  display: flex;
  flex-direction: column;
  max-width: 72%;
}

.msg.assessor { align-self: flex-start; }
.msg.parent   { align-self: flex-end; align-items: flex-end; }

.msg-label {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 5px;
}

.bubble {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 0.9375rem;
  line-height: 1.55;
  word-break: break-word;
}

.assessor .bubble {
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
  box-shadow: var(--shadow);
  color: var(--text);
}

.parent .bubble {
  background: var(--primary);
  color: #fff;
  border-bottom-right-radius: 4px;
}

/* Markdown inside bubbles */
.bubble p { margin: 0 0 0.5em; }
.bubble p:last-child { margin-bottom: 0; }
.bubble h3, .bubble h4, .bubble h5 {
  margin: 0.75em 0 0.25em;
  font-size: 0.9375rem;
  font-weight: 700;
}
.bubble ul, .bubble ol { padding-left: 1.25em; margin: 0.4em 0; }
.bubble li { margin-bottom: 0.2em; }
.bubble strong { font-weight: 700; }
.summary-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  margin-bottom: 12px;
}
.summary-download {
  display: inline-block;
  padding: 6px 14px;
  background: var(--primary);
  color: #fff;
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  font-weight: 500;
  text-decoration: none;
}
.summary-download:hover { background: var(--primary-dark); }
.bubble em { font-style: italic; }
.bubble code {
  background: rgba(0,0,0,0.06);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 0.875em;
  font-family: "Menlo", "Consolas", monospace;
}
.parent .bubble code { background: rgba(255,255,255,0.18); }

/* Typing indicator */
.typing-indicator {
  display: flex;
  gap: 5px;
  align-items: center;
  padding: 14px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  border-bottom-left-radius: 4px;
  box-shadow: var(--shadow);
  width: fit-content;
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: pulse 1.3s infinite ease-in-out;
}
.dot:nth-child(2) { animation-delay: 0.2s; }
.dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes pulse {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* Session ended banner */
.session-ended-banner {
  text-align: center;
  padding: 14px 20px;
  background: var(--success-bg);
  border: 1px solid var(--success-border);
  border-radius: var(--radius-sm);
  color: var(--success-text);
  font-size: 0.875rem;
  margin-top: 4px;
}
.session-ended-banner a {
  color: var(--primary);
  font-weight: 600;
  text-decoration: none;
}
.session-ended-banner a:hover { text-decoration: underline; }

/* ── Quick-response buttons ── */
.quick-snap {
  display: flex;
  align-items: stretch;
}

.snap-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 0.8125rem;
  font-weight: 600;
  font-family: inherit;
  padding: 0 14px;
  white-space: nowrap;
  color: var(--text-muted);
  transition: background 0.15s, color 0.15s;
  align-self: stretch;
}
.snap-btn:hover         { background: var(--bg); }
.snap-btn.yes           { color: #166534; }
.snap-btn.yes:hover     { background: #f0fdf4; }
.snap-btn.no            { color: #991b1b; }
.snap-btn.no:hover      { background: #fef2f2; }
.snap-btn.not-sure:hover { background: var(--bg); }
.snap-btn:disabled      { opacity: 0.4; cursor: not-allowed; }

.snap-divider {
  width: 1px;
  background: var(--border);
  align-self: stretch;
  flex-shrink: 0;
}

/* ── Input bar ── */
.input-wrapper {
  background: var(--surface);
  border-top: 1px solid var(--border);
  box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.06);
  padding: 12px 20px;
  flex-shrink: 0;
}

.input-inner {
  max-width: 820px;
  margin: 0 auto;
}

.input-bar {
  display: flex;
  align-items: stretch;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input-bar:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-ring);
}

#messageInput {
  flex: 1;
  padding: 11px 14px;
  border: none;
  font-size: 0.9375rem;
  font-family: inherit;
  color: var(--text);
  resize: none;
  outline: none;
  min-height: 44px;
  max-height: 120px;
  overflow-y: auto;
  line-height: 1.5;
  background: transparent;
}
#messageInput::placeholder { color: var(--text-muted); }
#messageInput:disabled {
  background: #f8fafc;
  color: var(--text-muted);
  cursor: not-allowed;
}

.send-btn {
  background: var(--primary);
  color: #fff;
  border: none;
  cursor: pointer;
  width: 44px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.send-btn:hover:not(:disabled) { background: var(--primary-dark); }
.send-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Inactivity dialog ── */
.inactivity-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.inactivity-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 36px 40px;
  max-width: 320px;
  width: 100%;
  text-align: center;
  box-shadow: var(--shadow-md);
}

.inactivity-heading {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 8px;
}

.inactivity-sub {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-bottom: 24px;
}

.inactivity-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}
.inactivity-actions .btn-outline {
  color: var(--text);
  border-color: var(--border);
  background: transparent;
}
.inactivity-actions .btn-outline:hover {
  background: var(--bg);
}

/* Utility */
.hidden { display: none !important; }

@media (max-width: 768px) {
  #messageInput { font-size: 1rem; }
}
