:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f8fafb;
  --border: #e2e7ec;
  --text: #17212b;
  --muted: #5d6b78;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --accent-soft: #e6f3f1;
  --user: #0f766e;
  --warn-bg: #fff8e6;
  --warn-border: #f1d58a;
  --error: #b42318;
  --scroll-thumb: rgb(15 118 110 / 0.35);
  --scroll-thumb-hover: rgb(15 118 110 / 0.55);
  --radius: 14px;
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, "Noto Sans Arabic", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1418;
    --surface: #161d23;
    --surface-2: #1b242b;
    --border: #2a353e;
    --text: #e6ecf0;
    --muted: #9aa8b3;
    --accent: #2bb3a6;
    --accent-ink: #06201d;
    --accent-soft: #15302d;
    --user: #1f8f84;
    --warn-bg: #2b2412;
    --warn-border: #5c4a1c;
    --error: #ff8a80;
    --scroll-thumb: rgb(43 179 166 / 0.42);
    --scroll-thumb-hover: rgb(43 179 166 / 0.72);
  }
}

/* Slim scrollbars: chat log, sources panel, input box, "How I found this" */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--scroll-thumb);
  border-radius: 999px;
  border: 2px solid transparent; /* inset from the edge: a 6px visible thumb */
  background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover { background-color: var(--scroll-thumb-hover); }
::-webkit-scrollbar-corner { background: transparent; }
@supports not selector(::-webkit-scrollbar) {
  * { scrollbar-width: thin; scrollbar-color: var(--scroll-thumb) transparent; }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 var(--font);
}
button, input, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }

.app {
  max-width: 820px;
  height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  position: relative;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo {
  width: 36px; height: 36px; flex: none;
  display: grid; place-items: center;
  border-radius: 10px;
  background: var(--accent); color: var(--accent-ink);
}
h1 { font-size: 17px; margin: 0; line-height: 1.2; }
.subtitle { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.top-actions { display: flex; gap: 6px; flex: none; }

.ghost {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 12px;
  cursor: pointer;
  font-size: 13px;
}
.ghost:hover { background: var(--surface-2); }
.ghost.small { padding: 4px 10px; }

.sources-panel {
  position: absolute;
  top: 66px; right: 12px; left: 12px;
  z-index: 5;
  max-height: 70vh;
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: 0 10px 30px rgb(0 0 0 / 0.12);
}
.sources-head { display: flex; justify-content: space-between; align-items: center; }
.sources-head h2 { font-size: 15px; margin: 0; }
.source-pages { padding-left: 20px; margin: 8px 0; }
.source-pages li { margin: 6px 0; }
.source-pages .meta { display: block; color: var(--muted); font-size: 12px; }

.chat {
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.msg { display: flex; }
.msg.user { justify-content: flex-end; }
.bubble {
  max-width: min(640px, 92%);
  padding: 11px 14px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  overflow-wrap: anywhere;
}
.msg.user .bubble {
  background: var(--user);
  color: #fff;
  border-color: transparent;
  border-bottom-right-radius: 4px;
  white-space: pre-wrap;
}
.msg.bot .bubble { border-bottom-left-radius: 4px; }
.bubble p { margin: 0 0 8px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { margin: 4px 0 8px; padding-left: 22px; }
.bubble li { margin: 2px 0; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.chip {
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
  text-align: left;
}
.chip:hover { border-color: var(--accent); }

.disclaimer {
  margin-top: 10px;
  padding: 8px 10px;
  font-size: 13px;
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  border-radius: 10px;
}

.sources {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px dashed var(--border);
  font-size: 13px;
}
.sources-label { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.sources ul { list-style: none; padding: 0; margin: 4px 0 0; }
.sources li { margin: 4px 0; }
.sources .section { color: var(--muted); }

.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; align-items: center; }
.primary {
  background: var(--accent);
  color: var(--accent-ink);
  border: 0;
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.primary:hover { filter: brightness(1.05); }
.primary:disabled { opacity: .6; cursor: default; }

details.why { margin-top: 8px; font-size: 12px; color: var(--muted); }
details.why summary { cursor: pointer; }
details.why pre {
  white-space: pre-wrap;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  margin: 6px 0 0;
  font: 12px/1.45 ui-monospace, Consolas, monospace;
}

.lead-form {
  margin-top: 10px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
  display: grid;
  gap: 8px;
  font-size: 13px;
}
.lead-title { margin: 0; font-weight: 600; font-size: 14px; }
.lead-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.lead-form label { display: grid; gap: 4px; }
.lead-form input[type="text"], .lead-form input[type="email"], .lead-form textarea {
  width: 100%;
  padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}
.lead-form .consent { display: flex; gap: 8px; align-items: flex-start; }
.lead-actions { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.lead-status { margin: 0; }
.lead-status.error { color: var(--error); }

.typing .bubble { display: inline-flex; gap: 4px; padding: 14px; }
.typing span {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--muted);
  animation: blink 1.2s infinite ease-in-out;
}
.typing span:nth-child(2) { animation-delay: .15s; }
.typing span:nth-child(3) { animation-delay: .3s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

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

.composer {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.composer textarea {
  flex: 1;
  resize: none;
  max-height: 140px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
  outline: none;
}
.composer textarea:focus { border-color: var(--accent); }
.send {
  flex: none;
  width: 42px; height: 42px;
  border-radius: 12px;
  border: 0;
  background: var(--accent);
  color: var(--accent-ink);
  cursor: pointer;
  display: grid; place-items: center;
}
.send:disabled { opacity: .5; cursor: default; }
.footnote { margin: 0; padding: 0 16px 10px; background: var(--surface); color: var(--muted); font-size: 11.5px; text-align: center; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.link { font-size: 13px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

@media (max-width: 560px) {
  .subtitle { display: none; }
  .lead-grid { grid-template-columns: 1fr; }
  .bubble { max-width: 100%; }
}
