/* ── Variables ─────────────────────────────────────────────────────────────── */
:root {
  --background:        #f5f0e8;
  --foreground:        #3d3529;
  --card:              #faf7f2;
  --card-foreground:   #3d3529;
  --primary:           #8b7355;
  --primary-foreground:#faf7f2;
  --secondary:         #ebe5d9;
  --muted:             #ebe5d9;
  --muted-foreground:  #8a7e6e;
  --border:            #ddd5c5;
  --destructive:       #b85c4a;
  --action-green:      #34964b;
}

/* ── Reset + base ──────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--background);
  color: var(--foreground);
  font-family: 'DM Sans', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button { font-family: inherit; cursor: pointer; }
button:focus-visible { outline: 2px solid var(--action-green); outline-offset: 2px; }

/* ── Login overlay ─────────────────────────────────────────────────────────── */
#login-overlay {
  position: fixed;
  inset: 0;
  background: var(--background);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

#login-overlay.hidden { display: none; }

.login-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
}

.login-subtitle {
  margin: 0;
  font-size: 0.875rem;
  color: var(--muted-foreground);
}

/* ── Page layout ───────────────────────────────────────────────────────────── */
#page {
  display: flex;
  min-height: 100svh;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem 1rem;
}

#page.has-answers {
  justify-content: flex-start;
  padding-top: 4rem;
}

.container {
  display: flex;
  width: 100%;
  max-width: 42rem;
  flex-direction: column;
  align-items: center;
  gap: 2rem;
}

/* ── School logo ───────────────────────────────────────────────────────────── */
.school-logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.school-logo img {
  width: 180px;
  height: auto;
}

.school-logo .subtitle {
  margin: 0;
  font-size: 0.875rem;
  color: var(--muted-foreground);
}

/* ── Answers list ──────────────────────────────────────────────────────────── */
#answers-list {
  display: none;
  width: 100%;
  flex-direction: column;
  gap: 0.75rem;
}

/* ── Input area ────────────────────────────────────────────────────────────── */
.input-area {
  display: flex;
  width: 100%;
  flex-direction: column;
  gap: 1rem;
}

/* ── Chat input box ────────────────────────────────────────────────────────── */
.chat-input-box {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  border-radius: 1rem;
  border: 2px solid var(--border);
  background: var(--card);
  padding: 0.75rem 1rem;
  box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  transition: box-shadow 0.2s, border-color 0.2s;
}

.chat-input-box:focus-within {
  box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  border-color: var(--action-green);
}

.chat-textarea {
  flex: 1;
  resize: none;
  background: transparent;
  color: var(--foreground);
  font-size: 1rem;
  line-height: 1.625;
  outline: none;
  border: none;
  padding: 0;
  min-height: 28px;
  max-height: 4.8em;
  overflow: hidden;
  font-family: inherit;
}

.chat-textarea::placeholder {
  color: var(--muted-foreground);
}

.chat-textarea:disabled {
  color: var(--muted-foreground);
}

.send-btn {
  display: flex;
  height: 2.25rem;
  width: 2.25rem;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  border-radius: 0.75rem;
  background: var(--action-green);
  color: white;
  border: none;
  transition: opacity 0.2s;
  padding: 0;
}

.send-btn:hover:not(:disabled) { opacity: 0.9; }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.send-btn svg { width: 1rem; height: 1rem; }

/* ── Suggestion pills — collapsed ─────────────────────────────────────────── */
.pills-collapsed {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
}

.pill-btn {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  border-radius: 9999px;
  border: 1px solid var(--border);
  background: var(--card);
  padding: 0.5rem 0.875rem;
  font-size: 0.875rem;
  color: var(--muted-foreground);
  transition: border-color 0.3s, color 0.3s, box-shadow 0.3s;
}

.pill-btn:hover {
  border-color: rgba(139, 115, 85, 0.4);
  color: var(--foreground);
  box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05);
}

.pill-symbol { font-size: 0.875rem; flex-shrink: 0; }

.pill-lang-emoji {
  font-size: 1rem;
  line-height: 1;
}

/* ── Suggestion pills — expanded ──────────────────────────────────────────── */
.pills-expanded {
  display: flex;
  gap: 0.75rem;
  width: 100%;
  align-items: flex-start;
}

.pills-sidebar {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  flex-shrink: 0;
}

.pill-sidebar-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 9999px;
  border: 1px solid var(--border);
  background: var(--card);
  height: 2rem;
  width: 2rem;
  color: var(--muted-foreground);
  transition: border-color 0.3s, color 0.3s, background 0.3s;
  padding: 0;
}

.pill-sidebar-btn:hover {
  border-color: rgba(139, 115, 85, 0.4);
  color: var(--foreground);
}

.pill-sidebar-btn.active {
  border-color: rgba(139, 115, 85, 0.5);
  background: rgba(139, 115, 85, 0.1);
  color: var(--foreground);
  box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05);
}

.pill-sidebar-btn .pill-symbol { font-size: 1rem; }
.pill-label { display: none; }

@media (min-width: 768px) {
  .pill-sidebar-btn {
    height: auto;
    width: auto;
    gap: 0.375rem;
    padding: 0.375rem 0.75rem;
    white-space: nowrap;
    font-size: 0.75rem;
  }
  .pill-label { display: inline; }
}

/* ── Questions panel ───────────────────────────────────────────────────────── */
.questions-panel {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  flex: 1;
  min-width: 0;
}

.question-btn {
  width: 100%;
  border-radius: 0.75rem;
  border: 1px solid rgba(221, 213, 197, 0.6);
  background: rgba(250, 247, 242, 0.8);
  padding: 0.625rem 0.875rem;
  text-align: left;
  font-size: 0.875rem;
  line-height: 1.375;
  color: var(--muted-foreground);
  transition: border-color 0.2s, background 0.2s, color 0.2s, box-shadow 0.2s;
}

.question-btn:hover {
  border-color: rgba(139, 115, 85, 0.3);
  background: var(--card);
  color: var(--foreground);
  box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05);
}

/* ── Answer card ───────────────────────────────────────────────────────────── */
.answer-card {
  border-radius: 1rem;
  border: 2px solid var(--border);
  background: var(--card);
  padding: 1.5rem;
  box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05);
}

.answer-card.answer-card-error {
  border-color: var(--destructive) !important;
}

.answer-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.answer-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.answer-question {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--muted-foreground);
  margin: 0;
}

.answer-divider {
  height: 1px;
  background: var(--border);
  border: none;
  margin: 0;
}

.answer-text {
  color: var(--foreground);
  line-height: 1.625;
  margin: 0;
}

.answer-text.answer-text-error {
  color: var(--destructive);
}

.answer-warning {
  color: var(--destructive);
  font-size: 0.75rem;
  margin: 0 0 0.75rem;
  opacity: 0.8;
}

/* ── Source details ────────────────────────────────────────────────────────── */
.source-details {
  display: block;
}

.source-details summary {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  border-radius: 0.375rem;
  background: rgba(139, 115, 85, 0.8);
  padding: 0.125rem 0.5rem;
  font-size: 0.75rem;
  color: var(--primary-foreground);
  cursor: pointer;
  list-style: none;
  transition: background 0.2s;
  border: none;
  user-select: none;
}

.source-details summary::-webkit-details-marker { display: none; }
.source-details summary::marker { display: none; }
.source-details summary:hover { background: var(--primary); }
.source-details summary svg { width: 0.75rem; height: 0.75rem; }

.facts-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.75rem;
  padding: 0.75rem;
  border-radius: 0.5rem;
  background: var(--secondary);
  border: 1px solid var(--border);
}

.fact-item {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.fact-source-id {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.fact-text {
  font-size: 0.8125rem;
  color: var(--foreground);
  line-height: 1.5;
  margin: 0;
}

/* ── Dismiss button ────────────────────────────────────────────────────────── */
.dismiss-btn {
  flex-shrink: 0;
  border-radius: 0.5rem;
  padding: 0.375rem;
  color: var(--muted-foreground);
  background: transparent;
  border: none;
  transition: color 0.2s, background 0.2s;
}

.dismiss-btn:hover { color: var(--foreground); background: var(--secondary); }
.dismiss-btn svg { width: 1rem; height: 1rem; display: block; }

/* ── Answer action bar ─────────────────────────────────────────────────────── */
.answer-actions {
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem;
}

.action-btn {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  border-radius: 0.5rem;
  padding: 0.375rem 0.625rem;
  font-size: 0.75rem;
  color: var(--muted-foreground);
  background: transparent;
  border: 2px solid transparent;
  transition: color 0.2s, background 0.2s;
}

.action-btn:hover { color: var(--foreground); background: var(--secondary); }
.action-btn svg { width: 0.875rem; height: 0.875rem; flex-shrink: 0; }

.action-btn-inactive { cursor: default; }
.action-btn-inactive:hover { color: var(--muted-foreground); background: transparent; }

.action-btn-selected { color: var(--foreground); background: var(--secondary); }

/* Disclaimer button states */
.action-btn-disclaimer.disclaimer-unseen {
  animation: soft-pulse-border 1.2s ease-in-out infinite;
}

.action-btn-disclaimer.disclaimer-unseen:hover {
  animation-play-state: paused;
  border-color: var(--action-green);
  color: var(--foreground);
}

.action-btn-disclaimer.disclaimer-seen {
  color: rgba(138, 126, 110, 0.4);
}

.action-btn-disclaimer.disclaimer-seen:hover {
  color: var(--muted-foreground);
  background: var(--secondary);
  border-color: transparent;
}

/* ── Animations ────────────────────────────────────────────────────────────── */
@keyframes fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes slide-in-from-bottom-4 {
  from { opacity: 0; transform: translateY(1rem); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes slide-in-from-bottom-1 {
  from { opacity: 0; transform: translateY(0.25rem); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes slide-in-from-left-2 {
  from { opacity: 0; transform: translateX(-0.5rem); }
  to   { opacity: 1; transform: translateX(0); }
}

@keyframes soft-pulse-border {
  0%, 100% { border-color: transparent; }
  50%       { border-color: var(--action-green); }
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

.anim-card   { animation: slide-in-from-bottom-4 0.3s ease both; }
.anim-fade   { animation: fade-in 0.3s ease both; }
.anim-panel  { animation: slide-in-from-left-2 0.3s ease both; }
.anim-question { animation: slide-in-from-bottom-1 0.3s ease both; }
.spin        { animation: spin 1s linear infinite; }

/* ── Thinking panel ────────────────────────────────────────────────────────── */
.pending-card { opacity: 0.8; }

.thinking-details {
  display: block;
  margin-top: 0.375rem;
}

.thinking-details > summary {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.7rem;
  color: var(--muted-foreground);
  cursor: pointer;
  list-style: none;
  user-select: none;
  opacity: 0.7;
}

.thinking-details > summary::-webkit-details-marker { display: none; }
.thinking-details > summary::marker { display: none; }
.thinking-details > summary:hover { opacity: 1; }

.thinking-steps {
  list-style: none;
  margin: 0.375rem 0 0;
  padding: 0 0 0 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  border-left: 2px solid var(--border);
}

.thinking-step {
  font-size: 0.7rem;
  color: var(--muted-foreground);
  line-height: 1.4;
}

.step-ms {
  font-size: 0.625rem;
  opacity: 0.5;
  margin-left: 0.25rem;
}
