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

:root {
  --bg: #ffffff;
  --surface: #f5f5f4;
  --surface2: #eeecea;
  --border: #e2deda;
  --border-dark: #ccc8c2;
  --accent: #2563eb;
  --accent-light: #dbeafe;
  --text: #1c1917;
  --text-muted: #78716c;
  --text-dim: #b5b0aa;
  --user-bg: #2563eb;
  --user-text: #ffffff;
  --radius: 14px;
  --font:
    ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Monaco, Consolas, monospace;
  --danger: #ef4444;
  --danger-light: #fef2f2;
}

html,
body,
#root {
  height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
}

#root {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  background: #2563eb;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  flex-shrink: 0;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo {
  width: 28px;
  height: 28px;
  background: #ffffff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
}

.logo img {
  width: 24px;
  height: 24px;
  object-fit: contain;
}

.header-title {
  font-size: 20px;
  font-weight: 600;
  color: #ffffff;
}

.header-sub {
  font-size: 14px;
  color: rgba(219, 234, 254, 0.9);
  margin-top: 1px;
}

.clear-btn {
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: #ffffff;
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 12px;
  font-family: var(--font);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: background 0.15s;
}
.clear-btn:hover {
  background: rgba(255, 255, 255, 0.25);
}
.clear-btn-text {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
@media (min-width: 480px) {
  .clear-btn-text {
    position: static;
    width: auto;
    height: auto;
    padding: 0;
    margin: 0;
    overflow: visible;
    clip: auto;
    white-space: normal;
    border: 0;
  }
}

.chat-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  width: 100%;
  max-width: 896px;
  margin: 0 auto;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  background: #f9fafb;
}

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

.msg-row {
  display: flex;
  flex-direction: row;
  width: 100%;
  gap: 8px;
  align-items: flex-start;
}

.msg-row.user {
  justify-content: flex-end;
}

.msg-row.assistant {
  justify-content: flex-start;
}

.msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  flex-shrink: 0;
  background: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  margin-top: 2px;
}

.msg-avatar img {
  width: 24px;
  height: 24px;
  object-fit: contain;
}

.user-avatar {
  background: #9ca3af;
  font-size: 11px;
  font-weight: 600;
  color: #ffffff;
}

.msg-content {
  display: flex;
  flex-direction: column;
  max-width: min(78%, 480px);
}

.msg-row.user .msg-content {
  align-items: flex-end;
}

.msg-row.assistant .msg-content {
  align-items: flex-start;
}

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

.msg-row.user .bubble {
  background: var(--user-bg);
  color: var(--user-text);
  border-bottom-right-radius: 4px;
}

.msg-row.assistant .bubble {
  background: #ffffff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  color: var(--text);
  border-bottom-left-radius: 4px;
}

.bubble p {
  margin: 0 0 0.5em;
}
.bubble p:last-child {
  margin-bottom: 0;
}
.bubble ul,
.bubble ol {
  padding-left: 1.4em;
  margin: 0.4em 0;
}
.bubble li {
  margin: 0.2em 0;
}
.bubble h1,
.bubble h2,
.bubble h3 {
  font-weight: 600;
  margin: 0.6em 0 0.3em;
}
.bubble h1 {
  font-size: 1.1em;
}
.bubble h2 {
  font-size: 1.05em;
}
.bubble h3 {
  font-size: 1em;
}
.bubble code {
  font-family: var(--mono);
  font-size: 0.875em;
  background: rgba(0, 0, 0, 0.07);
  padding: 1px 4px;
  border-radius: 3px;
}
.bubble pre {
  background: rgba(0, 0, 0, 0.06);
  border-radius: 6px;
  padding: 10px 12px;
  overflow-x: auto;
  margin: 0.5em 0;
}
.bubble pre code {
  background: none;
  padding: 0;
  font-size: 0.85em;
}
.bubble a {
  color: var(--accent);
  text-decoration: none;
}
.bubble a:hover {
  text-decoration: underline;
}
.bubble strong {
  font-weight: 600;
}

.thinking-bubble {
  color: #9ca3af;
  font-size: 14px;
}

.shimmer {
  position: relative;
  display: inline-block;
  overflow: hidden;
}
.shimmer::after {
  content: "";
  position: absolute;
  top: 0;
  left: -150%;
  width: 200%;
  height: 100%;
  pointer-events: none;
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0) 0%,
    rgba(255, 255, 255, 0.6) 50%,
    rgba(255, 255, 255, 0) 100%
  );
  transform: skewX(-20deg);
  animation: shimmer-slide 1.2s linear infinite;
}

@keyframes shimmer-slide {
  from {
    left: -150%;
  }
  to {
    left: 150%;
  }
}

.msg-row.assistant .bubble.streaming::after {
  content: "▋";
  display: inline;
  color: var(--accent);
  animation: blink 0.75s step-end infinite;
}

@keyframes blink {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0;
  }
}

.msg-row.assistant .bubble.error {
  background: linear-gradient(135deg, #fee2e2, #fecaca);
  box-shadow: none;
  border-left: 4px solid #dc2626;
  color: #b91c1c;
}

.support-contact {
  font-size: 12.5px;
  color: var(--text-muted);
  line-height: 1.6;
  padding-top: 4px;
}

.support-contact a {
  color: var(--accent);
  text-decoration: none;
}
.support-contact a:hover {
  text-decoration: underline;
}

.cite-badge a {
  color: inherit;
  text-decoration: none;
}

.cite-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: #fff;
  border-radius: 4px;
  font-size: 9px;
  font-weight: 700;
  padding: 0 4px;
  min-width: 15px;
  height: 15px;
  vertical-align: super;
  line-height: 1;
  margin: 0 1px;
  font-style: normal;
}

.sources-block {
  padding: 8px 2px 0;
}

.sources-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-dim);
  display: block;
  margin-bottom: 6px;
}

.source-cards {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.source-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.12s;
}

.source-card:hover {
  border-color: var(--accent);
}

.source-card-num {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  min-width: 14px;
  text-align: center;
}

.source-card-body {
  display: flex;
  flex-direction: column;
  gap: 1px;
  overflow: hidden;
}

.source-card-title {
  font-size: 12px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.source-card-domain {
  font-size: 11px;
  color: var(--text-dim);
}

.feedback-row {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 2px 6px;
  height: 42px;
}

.thumb-btn {
  background: none;
  border: 1px solid transparent;
  border-radius: 5px;
  padding: 2px 5px;
  font-size: 22px;
  cursor: pointer;
  transition: all 0.12s;
  color: var(--text-dim);
  line-height: 1;
}
.thumb-btn:hover {
  border-color: var(--border-dark);
  color: var(--text-muted);
}
.thumb-btn.active.up {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-light);
}
.thumb-btn.active.down {
  color: var(--danger);
  border-color: var(--danger);
  background: var(--danger-light);
}
.feedback-sent {
  font-size: 10px;
  color: #22c55e;
  margin-left: 2px;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.modal {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  width: min(340px, calc(100vw - 32px));
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
}

.modal h3 {
  font-size: 14px;
  font-weight: 500;
}

.modal textarea {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  padding: 9px 11px;
  resize: none;
  outline: none;
  transition: border-color 0.15s;
  height: 80px;
}
.modal textarea:focus {
  border-color: var(--accent);
}
.modal textarea::placeholder {
  color: var(--text-dim);
}
.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.btn-ghost {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 12px;
  font-family: var(--font);
  cursor: pointer;
  transition: all 0.12s;
}
.btn-ghost:hover {
  border-color: var(--border-dark);
  color: var(--text);
}

.btn-primary {
  background: var(--accent);
  border: none;
  color: #fff;
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 12px;
  font-family: var(--font);
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.12s;
}
.btn-primary:hover {
  opacity: 0.88;
}

.input-area {
  padding: 28px 16px 16px;
  border-top: 1px solid var(--border);
  background: #ffffff;
  flex-shrink: 0;
}

.input-row {
  display: flex;
  align-items: stretch;
  gap: 10px;
}

.input-wrap {
  flex: 1;
  display: flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
  transition: border-color 0.15s;
}
.input-wrap:focus-within {
  border-color: var(--accent);
}

.input-wrap input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
}
.input-wrap input::placeholder {
  color: var(--text-dim);
}

.send-btn {
  background: var(--accent);
  border: none;
  color: #fff;
  border-radius: 8px;
  padding: 6px 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s;
}
.send-btn:disabled {
  opacity: 0.5;
  cursor: default;
}
.send-btn:not(:disabled):hover {
  background: #1d4ed8;
}

.clear-toast {
  align-self: center;
  background: #dcfce7;
  color: #166534;
  font-size: 13px;
  padding: 8px 16px;
  border-radius: 8px;
}

.empty-state {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 6px;
  color: var(--text-dim);
  font-size: 13px;
  text-align: center;
}
.empty-icon {
  font-size: 26px;
  margin-bottom: 4px;
  opacity: 0.5;
}

/* ── Consent screen ─────────────────────────── */

.consent-screen {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  background: #f9fafb;
}

.consent-card {
  width: min(380px, 100%);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.08);
  overflow: hidden;
}

.consent-card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 20px;
  background: #2563eb;
}

.consent-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.consent-notice {
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--text-muted);
}

.consent-notice a {
  color: var(--accent);
  text-decoration: none;
}
.consent-notice a:hover {
  text-decoration: underline;
}

.consent-checkbox {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  font-size: 13px;
  line-height: 1.55;
  color: var(--text);
  cursor: pointer;
}

.consent-checkbox input[type="checkbox"] {
  margin-top: 2px;
  flex-shrink: 0;
  accent-color: var(--accent);
  width: 14px;
  height: 14px;
  cursor: pointer;
}

.consent-checkbox a {
  color: var(--accent);
  text-decoration: none;
}
.consent-checkbox a:hover {
  text-decoration: underline;
}

.consent-footer {
  padding: 0 20px 20px;
}

.consent-accept-btn {
  width: 100%;
  padding: 9px 16px;
  font-size: 13px;
}

.consent-accept-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

/* ── Clarification chips ────────────────────── */

.chips-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 2px 0;
}

.chip {
  background: var(--accent-light);
  border: 1px solid var(--accent);
  color: var(--accent);
  border-radius: 16px;
  padding: 5px 14px;
  font-size: 13px;
  font-family: var(--font);
  font-weight: 500;
  cursor: pointer;
  transition:
    background 0.12s,
    color 0.12s;
  white-space: nowrap;
}

.chip:hover {
  background: var(--accent);
  color: #ffffff;
}

.chip-other {
  background: transparent;
  border-style: dashed;
  opacity: 0.7;
}

.chip-other:hover {
  background: var(--accent-light);
  color: var(--accent);
  opacity: 1;
}

.chip-other-input {
  border: 1px dashed var(--accent);
  border-radius: 16px;
  padding: 5px 14px;
  font-size: 13px;
  font-family: var(--font);
  color: var(--accent);
  outline: none;
  min-width: 160px;
}
