/* Design tokens — Addcontrol brand (see ADR-004). */
:root {
  --c-bg: #0d0c2e;
  --c-surface: #1a1848;
  --c-surface2: #221f5a;
  --c-surface3: #2a2670;
  --c-border: rgba(46, 42, 106, 0.8);
  --c-border2: rgba(46, 42, 106, 1);
  --c-accent: #df5124;
  --c-accent2: #e58925;
  --c-success: #10b981;
  --c-warning: #f59e0b;
  --c-error: #ef4444;
  --c-text: #e2e8f0;
  --c-text-strong: #ffffff;
  --c-muted: #94a3b8;
  --c-muted2: #64748b;

  --font-ui: "DM Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;

  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;

  --shadow-sm: 0 2px 12px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.3);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: var(--font-ui);
  color: var(--c-text);
  background: var(--c-bg);
  font-size: 14px;
  line-height: 1.6;
  overflow: hidden;
}

button {
  font-family: inherit;
  cursor: pointer;
}

textarea {
  font-family: inherit;
  resize: none;
}

.mono {
  font-family: var(--font-mono);
}

.muted {
  color: var(--c-muted);
}

.small {
  font-size: 12px;
}

/* ── App layout ─────────────────────────────────────────────────────────── */
.app {
  display: grid;
  grid-template-columns: 280px 1fr;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ────────────────────────────────────────────────────────────── */
.sidebar {
  background: var(--c-surface);
  border-right: 1px solid var(--c-border);
  display: flex;
  flex-direction: column;
  padding: 16px;
  gap: 14px;
  overflow: hidden;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--c-border);
}

.logo {
  width: 36px;
  height: 36px;
  border-radius: var(--r-sm);
  background: var(--c-surface2);
  padding: 4px;
}

.brand-title {
  font-weight: 700;
  font-size: 15px;
  color: var(--c-text-strong);
  letter-spacing: 0.02em;
}

.brand-subtitle {
  font-size: 11px;
  color: var(--c-muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.new-chat-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--r-sm);
  border: 1px solid var(--c-border2);
  background: linear-gradient(135deg, var(--c-accent) 0%, var(--c-accent2) 100%);
  color: #fff;
  font-weight: 600;
  font-size: 13px;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.new-chat-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(223, 81, 36, 0.4);
}

.conv-label {
  font-size: 11px;
  color: var(--c-muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  padding: 4px 0;
  margin-top: 4px;
}

.conversations {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 0;
}

.conversations::-webkit-scrollbar {
  width: 6px;
}
.conversations::-webkit-scrollbar-thumb {
  background: var(--c-border2);
  border-radius: 3px;
}

.conv-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 10px;
  border-radius: var(--r-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
  background: transparent;
}

.conv-item:hover {
  background: var(--c-surface2);
}

.conv-item.active {
  background: var(--c-surface2);
  border-color: var(--c-accent);
}

.conv-item-preview {
  font-size: 13px;
  color: var(--c-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conv-item-time {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--c-muted);
}

.sidebar-footer {
  padding-top: 10px;
  border-top: 1px solid var(--c-border);
}

.user-bar {
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-email {
  flex: 1;
  font-size: 11px;
  color: var(--c-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-small {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  font-size: 11px;
}

/* ── Chat area ──────────────────────────────────────────────────────────── */
.chat {
  display: flex;
  flex-direction: column;
  height: 100vh;
  background: var(--c-bg);
}

.chat-header {
  padding: 16px 28px;
  border-bottom: 1px solid var(--c-border);
  background: rgba(26, 24, 72, 0.5);
  backdrop-filter: blur(8px);
}

.chat-title {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: var(--c-text-strong);
}

.chat-subtitle {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--c-muted);
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 28px 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
}

.messages::-webkit-scrollbar {
  width: 8px;
}
.messages::-webkit-scrollbar-thumb {
  background: var(--c-border2);
  border-radius: 4px;
}

/* ── Welcome screen ─────────────────────────────────────────────────────── */
.welcome {
  margin: auto;
  text-align: center;
  max-width: 560px;
}

.welcome h2 {
  font-size: 26px;
  font-weight: 600;
  color: var(--c-text-strong);
  margin: 0 0 8px;
  background: linear-gradient(90deg, var(--c-accent) 0%, var(--c-accent2) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.welcome-sub {
  color: var(--c-muted);
  margin: 0 0 24px;
}

.examples {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 480px;
  margin: 0 auto;
}

.example {
  text-align: left;
  padding: 12px 14px;
  border-radius: var(--r-md);
  border: 1px solid var(--c-border);
  background: var(--c-surface);
  color: var(--c-text);
  font-size: 13px;
  transition: border-color 0.15s ease, transform 0.15s ease;
}

.example:hover {
  border-color: var(--c-accent);
  transform: translateY(-1px);
}

/* ── Bubbles ────────────────────────────────────────────────────────────── */
.bubble-row {
  display: flex;
  flex-direction: column;
  max-width: 720px;
  width: 100%;
  align-self: flex-start;
}

.bubble-row.user {
  align-self: flex-end;
  align-items: flex-end;
}

.bubble {
  padding: 12px 16px;
  border-radius: var(--r-lg);
  font-size: 14px;
  line-height: 1.65;
  box-shadow: var(--shadow-sm);
}

.bubble-row.user .bubble {
  background: var(--c-accent);
  color: #fff;
  border-bottom-right-radius: 4px;
  max-width: 80%;
}

.bubble-row.bot .bubble {
  background: var(--c-surface2);
  border: 1px solid var(--c-border);
  color: var(--c-text);
  border-top-left-radius: 4px;
}

.bubble-row.bot .bubble.thinking {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--c-muted);
  font-style: italic;
}

.thinking-dots {
  display: inline-flex;
  gap: 3px;
}
.thinking-dots span {
  width: 6px;
  height: 6px;
  background: var(--c-accent);
  border-radius: 50%;
  animation: dot-pulse 1.4s infinite both;
}
.thinking-dots span:nth-child(2) {
  animation-delay: 0.2s;
}
.thinking-dots span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes dot-pulse {
  0%,
  60%,
  100% {
    opacity: 0.3;
    transform: scale(0.85);
  }
  30% {
    opacity: 1;
    transform: scale(1);
  }
}

/* Markdown inside bot bubble */
.bubble p {
  margin: 0 0 8px;
}
.bubble p:last-child {
  margin-bottom: 0;
}
.bubble ul,
.bubble ol {
  margin: 6px 0 8px;
  padding-left: 22px;
}
.bubble li {
  margin: 2px 0;
}
.bubble strong {
  color: var(--c-text-strong);
}
.bubble code {
  font-family: var(--font-mono);
  font-size: 12.5px;
  background: rgba(0, 0, 0, 0.3);
  padding: 1px 6px;
  border-radius: 4px;
}
.bubble pre {
  background: rgba(0, 0, 0, 0.4);
  padding: 12px;
  border-radius: var(--r-sm);
  overflow-x: auto;
}

/* ── Sources + feedback bar ─────────────────────────────────────────────── */
.bubble-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
  align-items: center;
}

.source-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--c-border);
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--c-muted);
}

.source-chip strong {
  color: var(--c-accent2);
  font-weight: 500;
}

.fb-bar {
  display: flex;
  gap: 4px;
  margin-left: auto;
}

.fb-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 6px;
  border: 1px solid var(--c-border);
  background: transparent;
  color: var(--c-muted);
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.fb-btn:hover {
  background: var(--c-surface2);
  color: var(--c-text);
}

.fb-btn.active.up {
  background: rgba(16, 185, 129, 0.18);
  border-color: var(--c-success);
  color: var(--c-success);
}

.fb-btn.active.down {
  background: rgba(239, 68, 68, 0.18);
  border-color: var(--c-error);
  color: var(--c-error);
}

/* ── Composer ───────────────────────────────────────────────────────────── */
.chat-form {
  display: flex;
  gap: 8px;
  padding: 12px 28px 20px;
  border-top: 1px solid var(--c-border);
  background: var(--c-bg);
  align-items: flex-end;
}

#user-input {
  flex: 1;
  min-height: 44px;
  max-height: 200px;
  padding: 12px 14px;
  border-radius: var(--r-md);
  border: 1px solid var(--c-border2);
  background: var(--c-surface);
  color: var(--c-text);
  font-size: 14px;
  line-height: 1.4;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

#user-input:focus {
  border-color: var(--c-accent);
  box-shadow: 0 0 0 3px rgba(223, 81, 36, 0.15);
}

#send-btn {
  width: 44px;
  height: 44px;
  border-radius: var(--r-md);
  border: none;
  background: linear-gradient(135deg, var(--c-accent) 0%, var(--c-accent2) 100%);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

#send-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(223, 81, 36, 0.4);
}

#send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ── Modal ──────────────────────────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

/* `display: flex` above silently beats the HTML `hidden` attribute — restore it. */
.modal[hidden] {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(2px);
}

.modal-content {
  position: relative;
  background: var(--c-surface);
  border: 1px solid var(--c-border2);
  border-radius: var(--r-lg);
  padding: 22px 24px;
  width: min(440px, calc(100vw - 32px));
  box-shadow: var(--shadow-md);
}

.modal-content h3 {
  margin: 0 0 4px;
  font-size: 16px;
  color: var(--c-text-strong);
}

.modal-content .muted {
  margin: 0 0 16px;
  font-size: 13px;
}

.reasons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 16px;
}

.reason-btn {
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--c-border2);
  background: var(--c-surface2);
  color: var(--c-text);
  font-size: 12px;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.reason-btn.active {
  border-color: var(--c-accent);
  background: rgba(223, 81, 36, 0.18);
  color: var(--c-accent2);
}

#feedback-comment {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--r-sm);
  border: 1px solid var(--c-border2);
  background: var(--c-surface2);
  color: var(--c-text);
  font-size: 13px;
  outline: none;
  margin-top: 6px;
}

#feedback-comment:focus {
  border-color: var(--c-accent);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}

.btn-ghost {
  padding: 8px 14px;
  border-radius: var(--r-sm);
  border: 1px solid var(--c-border2);
  background: transparent;
  color: var(--c-muted);
  font-size: 13px;
}

.btn-ghost:hover {
  color: var(--c-text);
  border-color: var(--c-border2);
}

.btn-primary {
  padding: 8px 16px;
  border-radius: var(--r-sm);
  border: none;
  background: linear-gradient(135deg, var(--c-accent) 0%, var(--c-accent2) 100%);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(223, 81, 36, 0.4);
}

/* ── Toast / tiny inline status ─────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--c-surface2);
  border: 1px solid var(--c-border2);
  color: var(--c-text);
  padding: 10px 16px;
  border-radius: var(--r-sm);
  font-size: 13px;
  box-shadow: var(--shadow-md);
  z-index: 200;
  animation: toast-in 0.18s ease;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translate(-50%, 8px);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

/* ── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 760px) {
  .app {
    grid-template-columns: 1fr;
  }
  .sidebar {
    display: none;
  }
}
