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

:root {
  --bg: #0d0d0f;
  --sidebar: #161618;
  --surface: #1e1e22;
  --surface2: #26262c;
  --border: #2e2e36;
  --text: #ececf1;
  --muted: #8e8ea0;
  --accent: #10a37f;
  --accent-hover: #0d8c6d;
  --user-bubble: #343541;
  --ai-bubble: #1e1e22;
  --input-bg: #2a2a32;
  --radius: 12px;
}

:root.light {
  --bg:         #f7f7f8;
  --sidebar:    #ececf1;
  --surface:    #ffffff;
  --surface2:   #e4e4ec;
  --border:     #d1d1dc;
  --text:       #0d0d0f;
  --muted:      #6e6e80;
  --user-bubble:#e4e4ec;
  --ai-bubble:  #ffffff;
  --input-bg:   #ebebf2;
}

body {
  font-family: 'Sora', sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  display: flex;
  overflow: hidden;
}

/* ── SIDEBAR ── */
.sidebar {
  width: 260px;
  min-width: 260px;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  gap: 8px;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}

.logo-icon {
  width: 32px; height: 32px;
  background: var(--accent);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
}

.logo-text { font-weight: 600; font-size: 15px; letter-spacing: -0.3px; }

.new-chat-btn {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font-family: 'Sora', sans-serif;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s;
}
.new-chat-btn:hover { background: var(--surface2); }
.new-chat-btn svg { opacity: 0.7; }

.sidebar-section-label {
  font-size: 11px; font-weight: 500;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  padding: 8px 10px 4px;
}

.gdpr-notice {
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
}

.chat-history-item {
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background 0.15s, color 0.15s;
}
.chat-history-item:hover { background: var(--surface2); color: var(--text); }
.chat-history-item.active { background: var(--surface2); color: var(--text); }

.sidebar-footer {
  margin-top: auto;
  border-top: 1px solid var(--border);
  padding-top: 12px;
  display: flex; flex-direction: column; gap: 4px;
}

.sidebar-footer-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 8px;
  font-size: 13px; color: var(--muted);
  cursor: default; transition: background 0.15s;
}
a.sidebar-footer-item {
  text-decoration: none;
  cursor: pointer;
}
a.sidebar-footer-item:hover {
  background: var(--surface2);
  color: var(--text);
}
.avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: linear-gradient(135deg, #6c5ce7, #a29bfe);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600; color: #fff;
}

/* ── MAIN ── */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── TOPBAR ── */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  min-height: 56px;
}

.model-selector {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: 8px;
  background: var(--surface2);
  border: none; color: var(--text);
  font-family: 'Sora', sans-serif; font-size: 13px;
  cursor: default; font-weight: 500;
}

.topbar-actions { display: flex; gap: 8px; }
.topbar-btn {
  padding: 6px 14px; border-radius: 8px;
  border: 1px solid var(--border); background: transparent;
  color: var(--muted); font-family: 'Sora', sans-serif;
  font-size: 12px; cursor: pointer;
  transition: all 0.15s;
}
.topbar-btn:hover { background: var(--surface2); color: var(--text); }

/* ── MESSAGES ── */
.messages-area {
  flex: 1; overflow-y: auto; padding: 24px 0;
  scroll-behavior: smooth;
}

.messages-area::-webkit-scrollbar { width: 6px; }
.messages-area::-webkit-scrollbar-track { background: transparent; }
.messages-area::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }

.message-row {
  display: flex; gap: 14px;
  max-width: 780px; margin: 0 auto 24px;
  padding: 0 24px;
  animation: fadeUp 0.3s ease;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

.message-icon {
  width: 32px; height: 32px; min-width: 32px; border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px;
}
.message-icon.ai { background: var(--accent); }
.message-icon.user { background: linear-gradient(135deg, #6c5ce7, #a29bfe); }

.message-content { flex: 1; padding-top: 4px; }
.message-sender {
  font-size: 12px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.5px;
  margin-bottom: 6px;
}
.message-text {
  font-size: 14.5px; line-height: 1.7; color: var(--text);
}

/* ── QUESTION TYPES ── */
.question-label {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 10px; font-weight: 600; letter-spacing: 0.8px;
  text-transform: uppercase; padding: 3px 8px; border-radius: 99px;
  margin-bottom: 10px;
}
.question-label.multiple { background: rgba(16,163,127,0.15); color: var(--accent); border: 1px solid rgba(16,163,127,0.3); }
.question-label.text { background: rgba(108,92,231,0.15); color: #a29bfe; border: 1px solid rgba(108,92,231,0.3); }

/* Multiple choice */
.choices { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.choice-btn {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: 'Sora', sans-serif; font-size: 14px;
  cursor: pointer; text-align: left;
  transition: all 0.15s;
}
.choice-btn:hover:not(:disabled) { border-color: var(--accent); background: rgba(16,163,127,0.07); }
.choice-btn.selected { border-color: var(--accent); background: rgba(16,163,127,0.12); }
.choice-btn:disabled { cursor: default; opacity: 0.7; }
.choice-letter {
  min-width: 26px; height: 26px; border-radius: 6px;
  background: var(--surface2); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 600; font-family: 'JetBrains Mono', monospace;
  color: var(--muted);
  transition: all 0.15s;
}
.choice-btn.selected .choice-letter { background: var(--accent); border-color: var(--accent); color: #fff; }

/* Text answer display */
.user-answer {
  display: inline-block;
  background: var(--user-bubble);
  border-radius: 10px 10px 2px 10px;
  padding: 10px 14px;
  font-size: 14px; line-height: 1.6;
  margin-top: 4px;
}

/* Progress */
.progress-bar-wrap {
  max-width: 780px; margin: 0 auto 4px; padding: 0 24px;
}
.progress-info { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-bottom: 6px; }
.progress-bar { height: 3px; background: var(--surface2); border-radius: 99px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--accent); border-radius: 99px; transition: width 0.5s ease; }

/* Typing indicator */
.typing-indicator { display: flex; gap: 5px; align-items: center; padding-top: 4px; }
.typing-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--muted);
  animation: bounce 1.2s 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.5; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* ── INPUT AREA ── */
.input-area {
  padding: 16px 24px 24px;
  background: var(--bg);
  border-top: 1px solid var(--border);
}

.input-wrap {
  max-width: 780px; margin: 0 auto;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  display: flex; align-items: flex-end;
  padding: 12px 16px; gap: 10px;
  transition: border-color 0.2s;
}
.input-wrap:focus-within { border-color: var(--accent); }

textarea {
  flex: 1; border: none; outline: none;
  background: transparent; color: var(--text);
  font-family: 'Sora', sans-serif; font-size: 14px;
  line-height: 1.6; resize: none;
  min-height: 24px; max-height: 180px;
}
textarea::placeholder { color: var(--muted); }

.input-actions { display: flex; align-items: center; gap: 8px; }
.attach-btn {
  width: 32px; height: 32px; border-radius: 8px;
  background: transparent; border: 1px solid var(--border);
  color: var(--muted); cursor: pointer; display: flex;
  align-items: center; justify-content: center;
  transition: all 0.15s;
}
.attach-btn:hover { background: var(--surface2); color: var(--text); }

.send-btn {
  width: 32px; height: 32px; border-radius: 8px;
  background: var(--accent); border: none;
  color: #fff; cursor: pointer; display: flex;
  align-items: center; justify-content: center;
  transition: background 0.15s;
}
.send-btn:hover:not(:disabled) { background: var(--accent-hover); }
.send-btn:disabled { background: var(--surface2); color: var(--muted); cursor: default; }

.input-hint {
  max-width: 780px; margin: 8px auto 0;
  text-align: center; font-size: 11px; color: var(--muted);
}

textarea:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── MOBILE SIDEBAR ── */
.sidebar-backdrop { display: none; }
.hamburger-btn    { display: none; }

@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
  }
  .sidebar.open { transform: translateX(0); }

  .sidebar-backdrop {
    display: block;
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 49;
    opacity: 0; pointer-events: none;
    transition: opacity 0.3s ease;
  }
  .sidebar-backdrop.open { opacity: 1; pointer-events: auto; }

  .hamburger-btn {
    display: flex; align-items: center; justify-content: center;
    width: 36px; height: 36px; border-radius: 8px;
    background: transparent; border: 1px solid var(--border);
    color: var(--muted); cursor: pointer;
  }
}

/* Empty state */
.empty-state {
  max-width: 600px; margin: auto; padding: 60px 24px;
  text-align: center;
  animation: fadeUp 0.4s ease;
}
.empty-state h1 { font-size: 28px; font-weight: 600; letter-spacing: -0.5px; margin-bottom: 10px; }
.empty-state p { color: var(--muted); font-size: 14px; line-height: 1.6; }

/* Auto-reset countdown */
.auto-reset-notice {
  margin-top: 10px;
  font-size: 12px;
  color: var(--muted);
  font-style: italic;
}

/* ── MULTI-SELECT ── */
.question-label.multi-select {
  background: rgba(255,159,67,0.15);
  color: #ffb142;
  border: 1px solid rgba(255,159,67,0.3);
}

.choice-check {
  min-width: 18px; height: 18px; border-radius: 4px;
  border: 2px solid var(--border);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 11px; flex-shrink: 0;
  transition: all 0.15s;
}
.choice-btn.multi-choice.selected .choice-check::after { content: '✓'; }
.choice-btn.multi-choice.selected .choice-check {
  background: var(--accent); border-color: var(--accent); color: #fff;
}

.confirm-multi-btn {
  display: inline-flex; align-items: center; gap: 6px;
  margin-top: 10px; padding: 9px 18px; border-radius: 8px;
  background: var(--accent); border: none;
  color: #fff; font-family: 'Sora', sans-serif; font-size: 13px;
  cursor: pointer; transition: background 0.15s;
}
.confirm-multi-btn:hover:not(:disabled) { background: var(--accent-hover); }
.confirm-multi-btn:disabled { background: var(--surface2); color: var(--muted); cursor: default; }

/* Completion */
.completion-badge {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 18px; border-radius: 99px;
  background: rgba(16,163,127,0.1); border: 1px solid rgba(16,163,127,0.3);
  color: var(--accent); font-size: 14px; font-weight: 500;
  margin-top: 14px;
}

/* Error state */
.error-notice {
  max-width: 600px; margin: 40px auto; padding: 20px 24px;
  background: rgba(220, 53, 69, 0.1); border: 1px solid rgba(220, 53, 69, 0.3);
  border-radius: var(--radius); color: #ff6b6b; text-align: center;
  font-size: 14px;
}

/* ── Bug report link in error notice ── */
.error-bug-link {
  display: inline-flex; align-items: center; gap: 5px;
  margin-top: 12px; padding: 6px 14px;
  background: rgba(220,53,69,0.15); border: 1px solid rgba(220,53,69,0.35);
  border-radius: 99px; color: #ff6b6b; font-size: 12px; font-weight: 500;
  text-decoration: none; transition: background 0.15s;
}
.error-bug-link:hover { background: rgba(220,53,69,0.25); }

/* ── Sidebar bug report link ── */
.bug-report-link { color: var(--muted); text-decoration: none; }
.bug-report-link:hover { color: var(--text); }

/* ── Landing page ── */
.landing-page {
  flex: 1;
  overflow-y: auto;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 48px 24px;
}

.landing-inner {
  max-width: 560px;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  text-align: center;
}

.landing-logo {
  font-size: 52px;
  line-height: 1;
  filter: drop-shadow(0 0 18px rgba(16,163,127,0.35));
}

.landing-title {
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.5px;
}

.landing-subtitle {
  font-size: 14px;
  color: var(--muted);
  margin-top: -12px;
}

.landing-card {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  text-align: left;
}

.landing-card h2 {
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.landing-card p {
  font-size: 14px;
  color: var(--muted);
  line-height: 1.6;
}

.landing-footer {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 13px;
  color: var(--muted);
  flex-wrap: wrap;
  justify-content: center;
}

.landing-bug-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 14px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 99px; color: var(--muted); font-size: 12px;
  text-decoration: none; transition: color 0.15s, border-color 0.15s;
}
.landing-bug-btn:hover { color: var(--text); border-color: var(--muted); }

/* ── TSP logo link ── */
.tsp-logo-img {
  height: 20px;
  width: 20px;
  object-fit: contain;
  flex-shrink: 0;
}

.tsp-link {
  text-decoration: none;
  color: var(--muted);
}
.tsp-link:hover { color: var(--text); }

.landing-tsp-link {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  text-decoration: none;
  color: var(--muted);
  font-size: 13px;
  transition: color 0.15s;
}
.landing-tsp-link:hover { color: var(--text); }
.landing-tsp-link .tsp-logo-img { height: 22px; width: 22px; }
