:root {
  color-scheme: light;
  --cream: #faf6f0;
  --cream-2: #f3eadf;
  --paper: #ffffff;
  --ink: #241913;
  --muted: #6c5b50;
  --subtle: #8f7d71;
  --edge: #e9dfd2;
  --edge-strong: #dcccb9;
  --orange: #f26b38;
  --accent: #bd4214;
  --accent-hover: #9f350d;
  --accent-soft: #fff1ea;
  --user-bg: #241913;
  --user-fg: #fffaf5;
  --bot-bg: #f6f0e8;
  --err-bg: #fff2f0;
  --err-edge: #f3c4be;
  --err-ink: #8f2217;
  --green: #16a34a;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--cream);
}

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

html, body {
  margin: 0;
  padding: 0;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

body {
  background:
    radial-gradient(ellipse 65% 42% at 90% 0%, rgba(250, 123, 76, 0.2), transparent 65%),
    var(--cream);
}

.shell {
  width: min(100% - 2rem, 46rem);
  margin-inline: auto;
  min-height: 100dvh;
  padding-block: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

/* Standalone top bar */
.site-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding-bottom: 0.85rem;
  border-bottom: 1px solid var(--edge);
}

.brand-group {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  min-width: 0;
}

.logo-badge {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  background: var(--paper);
  border: 1px solid var(--edge);
  display: grid;
  place-items: center;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(36, 25, 19, 0.05);
}

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

.brand-copy {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.brand-title-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.brand-title-row h1 {
  margin: 0;
  font-size: 1.08rem;
  font-weight: 780;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.brand-sub {
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.35;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.7rem;
  font-weight: 650;
  color: #15803d;
  background: #eaf9ef;
  border: 1px solid #ccefd8;
  padding: 2px 8px;
  border-radius: 999px;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--green);
  flex-shrink: 0;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-shrink: 0;
}

.icon-btn {
  appearance: none;
  border: 1px solid var(--edge);
  background: var(--paper);
  color: var(--muted);
  width: 32px;
  height: 32px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.icon-btn:hover {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: #f4c1aa;
}

.ext-link {
  font-size: 0.8rem;
  font-weight: 620;
  color: var(--accent);
  text-decoration: none;
  padding: 6px 11px;
  border-radius: 9px;
  border: 1px solid var(--edge);
  background: var(--paper);
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s;
}

.ext-link:hover {
  background: var(--accent-soft);
  border-color: #f4c1aa;
}

/* Main chat card */
.chat-card {
  background: var(--paper);
  border: 1px solid var(--edge);
  border-radius: 18px;
  overflow: hidden;
  box-shadow: 0 12px 32px rgba(56, 34, 18, 0.07);
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
}

/* Widget bar (shown only in embed mode) */
.widget-bar {
  display: none;
  background: var(--user-bg);
  color: #fffaf5;
  padding: 12px 14px;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-shrink: 0;
}

.widget-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.widget-logo {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: #ffffff;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.widget-logo img {
  width: 20px;
  height: 20px;
  object-fit: contain;
  display: block;
}

.widget-title {
  font-size: 0.9rem;
  font-weight: 700;
  line-height: 1.2;
}

.widget-sub {
  font-size: 0.72rem;
  color: #d6c5b8;
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 2px;
}

.widget-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.widget-btn {
  appearance: none;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: 0;
  background: rgba(255, 255, 255, 0.1);
  color: #fffaf5;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.15s;
}

.widget-btn:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* Message stream */
.conversation {
  flex: 1 1 auto;
  min-height: 22rem;
  max-height: 58dvh;
  overflow-y: auto;
  padding: 1.15rem 1.15rem 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  scroll-behavior: smooth;
}

.msg-row {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  max-width: 88%;
}

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

.msg-row.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.msg-avatar {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  background: var(--cream);
  border: 1px solid var(--edge);
  display: grid;
  place-items: center;
  flex-shrink: 0;
  margin-bottom: 2px;
}

.msg-avatar img {
  width: 16px;
  height: 16px;
  object-fit: contain;
  display: block;
}

.msg-col {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

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

.msg-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.7rem;
  color: var(--subtle);
  padding-inline: 2px;
}

.msg-meta strong {
  color: var(--muted);
  font-weight: 650;
}

.bubble {
  padding: 0.68rem 0.88rem;
  border-radius: 14px;
  font-size: 0.88rem;
  line-height: 1.54;
  overflow-wrap: anywhere;
}

.msg-row.assistant .bubble {
  background: var(--bot-bg);
  color: var(--ink);
  border-bottom-left-radius: 5px;
}

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

.msg-row.error .bubble {
  background: var(--err-bg);
  border: 1px solid var(--err-edge);
  color: var(--err-ink);
  border-bottom-left-radius: 5px;
}

.bubble p {
  margin: 0;
  white-space: pre-wrap;
}

.bubble p + p {
  margin-top: 0.45rem;
}

.bubble ul {
  margin: 0.45rem 0 0.15rem;
  padding-left: 1.15rem;
}

.bubble li {
  margin: 0.18rem 0;
}

.source-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 0.55rem;
  padding-top: 0.48rem;
  border-top: 1px solid rgba(108, 91, 80, 0.14);
}

.feedback-group {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
}

.fb-btn {
  appearance: none;
  border: 1px solid var(--edge);
  background: var(--paper);
  color: var(--muted);
  font: inherit;
  font-size: 0.72rem;
  padding: 2px 7px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.fb-btn:hover:not(:disabled) {
  background: var(--accent-soft);
  border-color: var(--orange);
  color: var(--accent);
}

.fb-btn.active {
  background: var(--user-bg);
  border-color: var(--user-bg);
  color: #ffffff;
}

.fb-btn:disabled {
  cursor: default;
  opacity: 0.75;
}

.fb-note {
  font-size: 0.7rem;
  color: var(--subtle);
}

.source-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.74rem;
  font-weight: 620;
  color: var(--accent);
  background: var(--paper);
  border: 1px solid var(--edge-strong);
  padding: 3px 9px;
  border-radius: 999px;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s;
}

.source-chip:hover {
  background: var(--accent-soft);
  border-color: var(--orange);
}

/* Typing indicator */
.typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 2px;
}

.typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  opacity: 0.35;
  animation: bm-bounce 1.1s infinite ease-in-out;
}

.typing-dots span:nth-child(2) {
  animation-delay: 0.18s;
}

.typing-dots span:nth-child(3) {
  animation-delay: 0.36s;
}

@keyframes bm-bounce {
  0%, 80%, 100% { opacity: 0.3; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-2px); }
}

/* Quick suggestion pills docked above composer */
.quick-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0.65rem 1rem 0.15rem;
  border-top: 1px solid var(--edge);
  background: #fffdfb;
  flex-shrink: 0;
}

.quick-bar.hidden {
  display: none;
}

.chip-btn {
  appearance: none;
  border: 1px solid var(--edge-strong);
  background: var(--paper);
  color: #6b3113;
  font: inherit;
  font-size: 0.77rem;
  font-weight: 560;
  padding: 0.38rem 0.72rem;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}

.chip-btn:hover:not(:disabled) {
  background: var(--accent-soft);
  border-color: var(--orange);
  transform: translateY(-1px);
}

.chip-btn:disabled {
  opacity: 0.5;
  cursor: wait;
}

/* Composer */
.composer-wrap {
  padding: 0.65rem 0.9rem 0.75rem;
  background: #fffdfb;
  border-top: 1px solid var(--edge);
  flex-shrink: 0;
}

.quick-bar:not(.hidden) + .composer-wrap {
  border-top: 0;
}

.composer-box {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  background: var(--paper);
  border: 1.5px solid var(--edge-strong);
  border-radius: 13px;
  padding: 6px 6px 6px 12px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.composer-box:focus-within {
  border-color: var(--orange);
  box-shadow: 0 0 0 3px rgba(242, 107, 56, 0.15);
}

textarea {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  resize: none;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 0.88rem;
  line-height: 1.45;
  padding: 5px 0;
  max-height: 100px;
}

textarea::placeholder {
  color: var(--subtle);
}

#send {
  appearance: none;
  border: 0;
  background: var(--accent);
  color: #ffffff;
  width: 35px;
  height: 35px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.1s, opacity 0.15s;
}

#send:hover:not(:disabled) {
  background: var(--accent-hover);
}

#send:active:not(:disabled) {
  transform: scale(0.95);
}

#send:disabled {
  opacity: 0.45;
  cursor: wait;
}

.trust-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 6px 12px;
  margin-top: 0.5rem;
  padding-inline: 2px;
  font-size: 0.72rem;
  color: var(--subtle);
}

.trust-left {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
}

.trust-left svg {
  flex-shrink: 0;
}

.trust-right {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-variant-numeric: tabular-nums;
  margin-left: auto;
}

.kbd-hint {
  padding: 1px 5px;
  border-radius: 4px;
  border: 1px solid var(--edge);
  background: var(--cream);
  color: var(--muted);
  font-size: 0.66rem;
  font-weight: 620;
}

.site-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  font-size: 0.8rem;
  padding-top: 0.25rem;
}

.site-footer a {
  color: var(--accent);
  text-underline-offset: 0.2em;
}

.site-footer a:hover {
  text-decoration-thickness: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ================= EMBEDDED WIDGET MODE ================= */
html.is-embed,
html.is-embed body {
  height: 100%;
  min-height: 100%;
  overflow: hidden;
  background: var(--paper);
}

html.is-embed .shell {
  width: 100%;
  height: 100dvh;
  min-height: 100%;
  padding: 0;
  gap: 0;
}

html.is-embed .site-bar,
html.is-embed .site-footer {
  display: none;
}

html.is-embed .widget-bar {
  display: flex;
}

html.is-embed .chat-card {
  border: 0;
  border-radius: 0;
  box-shadow: none;
  height: 100%;
}

html.is-embed .conversation {
  min-height: 0;
  max-height: none;
  padding: 0.9rem 0.85rem 0.7rem;
  gap: 0.7rem;
}

html.is-embed .msg-row {
  max-width: 92%;
}

html.is-embed .bubble {
  font-size: 0.84rem;
  padding: 0.6rem 0.78rem;
}

html.is-embed .quick-bar {
  padding: 0.55rem 0.75rem 0.1rem;
}

html.is-embed .composer-wrap {
  padding: 0.55rem 0.75rem 0.65rem;
}

html.is-embed .kbd-hint {
  display: none;
}

@media (max-width: 520px) {
  .shell {
    width: 100%;
    padding: 0.75rem;
  }

  .conversation {
    min-height: 18rem;
    padding: 0.9rem 0.85rem;
  }

  .msg-row {
    max-width: 94%;
  }

  .kbd-hint {
    display: none;
  }
}
