:root {
  color-scheme: light;
  --bg: #f3f5f7;
  --surface: #ffffff;
  --surface-soft: #f8fafb;
  --text: #17212b;
  --muted: #66717d;
  --line: #dce3e8;
  --primary: #165d66;
  --primary-strong: #0f4b53;
  --primary-soft: #eaf5f5;
  --ok: #26734d;
  --ok-soft: #edf7f1;
  --review: #946116;
  --review-soft: #fff7e8;
  --review-line: #e8c78e;
  --error: #a53c3c;
  --error-soft: #fff0f0;
  --shadow: 0 10px 28px rgba(21, 36, 50, .065);
  --shadow-strong: 0 16px 40px rgba(21, 36, 50, .10);
}

* { box-sizing: border-box; }
html { min-height: 100%; scroll-padding-top: 100px; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, textarea { font: inherit; }
button { cursor: pointer; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; }
.hidden { display: none !important; }

.page-shell { min-height: 100vh; }
.topbar {
  min-height: 72px;
  padding: 11px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255,255,255,.97);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(12px);
}
.brand { display: flex; align-items: center; gap: 13px; min-width: 0; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 11px;
  display: grid; place-items: center;
  background: var(--primary); color: white; font-weight: 800; font-size: 13px;
  letter-spacing: .04em; flex: 0 0 auto;
}
.brand-title { font-weight: 760; font-size: 15px; }
.brand-subtitle { margin-top: 2px; color: var(--muted); font-size: 11px; }
.system-state {
  display: flex; align-items: center; gap: 8px;
  border: 1px solid var(--line); background: var(--surface-soft);
  padding: 7px 10px; border-radius: 999px;
  color: var(--muted); font-size: 11px; white-space: nowrap;
}
.state-dot { width: 8px; height: 8px; border-radius: 50%; background: #9aa4ae; }
.system-state[data-state="ready"] .state-dot { background: var(--ok); }
.system-state[data-state="ready"] { color: var(--ok); border-color: #cfe6d9; background: var(--ok-soft); }
.system-state[data-state="error"] .state-dot { background: var(--error); }
.system-state[data-state="error"] { color: var(--error); border-color: #efd0d0; background: var(--error-soft); }

.content { width: min(1080px, calc(100% - 48px)); margin: 0 auto; padding: 44px 0 88px; }
.hero { padding: 4px 0 20px; scroll-margin-top: 96px; }
.hero-kicker { color: var(--primary); font-weight: 800; letter-spacing: .08em; text-transform: uppercase; font-size: 10px; margin-bottom: 9px; }
.hero h1 { margin: 0; font-size: clamp(32px, 4.2vw, 46px); line-height: 1.08; letter-spacing: -.032em; max-width: 760px; }
.hero > p { color: var(--muted); font-size: 16px; line-height: 1.55; max-width: 760px; margin: 14px 0 24px; }
.search-box {
  background: var(--surface); border: 1px solid #d6dde2; border-radius: 17px;
  padding: 15px; box-shadow: var(--shadow);
}
.search-box:focus-within { border-color: #8db5b9; box-shadow: 0 12px 32px rgba(22,93,102,.105); }
textarea {
  width: 100%; resize: vertical; min-height: 72px; max-height: 210px;
  border: 0; outline: 0; background: transparent; color: var(--text);
  font-size: 17px; line-height: 1.5; padding: 3px 4px 11px;
}
textarea::placeholder { color: #98a2ad; }
.search-actions { border-top: 1px solid #edf0f2; padding-top: 11px; display: flex; justify-content: space-between; align-items: center; gap: 14px; }
.search-hint { color: #8a949e; font-size: 11px; }
#submitButton {
  border: 0; border-radius: 10px; background: var(--primary); color: white;
  padding: 10px 21px; font-weight: 760; min-width: 100px;
}
#submitButton:hover { background: var(--primary-strong); }
#submitButton:disabled { opacity: .58; cursor: default; }
.examples { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.example-query { border: 1px solid var(--line); background: rgba(255,255,255,.72); color: #52606c; padding: 7px 10px; border-radius: 9px; font-size: 11px; }
.example-query:hover { border-color: #afc4c7; color: var(--primary); background: white; }

.loading-panel, .error-panel, .insufficient, .review-banner {
  border-radius: 14px; padding: 15px 17px; display: flex; align-items: flex-start; gap: 12px; margin-top: 20px;
}
.loading-panel { background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); align-items: center; }
.loading-copy { min-width: 0; }
.spinner { width: 26px; height: 26px; border: 3px solid #d9e4e5; border-top-color: var(--primary); border-radius: 50%; animation: spin .9s linear infinite; flex: 0 0 auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-title { font-weight: 760; }
.loading-text { color: var(--muted); font-size: 12px; line-height: 1.45; margin-top: 3px; }
.loading-elapsed { color: var(--primary); font-size: 11px; font-weight: 760; margin-top: 6px; }
.error-panel { background: var(--error-soft); border: 1px solid #efcccc; color: #7c2f2f; }
.error-title { font-weight: 760; margin-bottom: 3px; }
.insufficient { background: #eef4f8; border: 1px solid #d6e3ec; color: #38556a; }
.insufficient-icon, .review-icon, .bibliography-icon { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; flex: 0 0 auto; font-weight: 800; }
.insufficient-icon { background: #dbe8f1; color: #38556a; }
.insufficient-title { font-weight: 800; margin-bottom: 3px; }

.result { margin-top: 26px; scroll-margin-top: 92px; }
.result-header { display: flex; justify-content: space-between; gap: 22px; align-items: flex-end; margin-bottom: 14px; }
.eyebrow { color: var(--primary); font-weight: 800; letter-spacing: .08em; text-transform: uppercase; font-size: 9px; margin-bottom: 5px; }
.result-header h2, .section-heading h3 { margin: 0; letter-spacing: -.018em; }
.result-header h2 { font-size: 24px; line-height: 1.2; }
.latency { color: var(--muted); font-size: 11px; white-space: nowrap; }

.review-banner {
  background: #fffaf0;
  border: 1px solid var(--review-line);
  color: #654817;
  padding: 14px 16px;
  margin-top: 12px;
  box-shadow: none;
}
.review-icon { background: #f4dfb9; color: var(--review); }
.review-copy { min-width: 0; }
.review-banner strong { display: block; font-size: 14px; margin-bottom: 3px; }
.review-banner span { display: block; font-size: 12px; line-height: 1.45; }
.review-explainer { font-size: 11px; line-height: 1.42; color: #866938; margin-top: 3px; }

.bibliography-note {
  margin-top: 10px;
  padding: 9px 11px;
  border: 1px solid #dfe9ec;
  border-radius: 10px;
  background: #f7fafb;
  color: #5b6973;
  display: flex;
  gap: 8px;
  font-size: 11px;
  line-height: 1.45;
}
.bibliography-icon { width: 20px; height: 20px; background: #e4eff1; color: var(--primary); font-size: 11px; }

.answer-section { margin-top: 27px; }
.answer-heading { margin-bottom: 11px; }
.answer-heading h3 { font-size: 19px; }
.answer-count { color: var(--muted); font-size: 11px; }
.section-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; }
.answer-items { display: grid; gap: 12px; }
.answer-item {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 15px;
  padding: 18px 19px 16px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}
.answer-item::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: #9fc5c9;
}
.answer-item.review { border-color: #ead6b4; background: #fffdfa; }
.answer-item.review::before { background: #c8923e; }
.answer-item-header { min-height: 18px; display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.answer-item-descriptor { color: #87929c; font-size: 10px; font-weight: 760; text-transform: uppercase; letter-spacing: .06em; }
.answer-quality { font-size: 10px; font-weight: 800; border-radius: 999px; padding: 4px 7px; }
.answer-quality.review { background: var(--review-soft); color: var(--review); border: 1px solid #edd2a4; }
.answer-text { white-space: pre-wrap; line-height: 1.68; font-size: 15px; color: #24313c; }
.answer-item-footer { margin-top: 13px; padding-top: 11px; border-top: 1px solid #edf0f2; }
.citation-row { display: flex; gap: 7px; flex-wrap: wrap; }
.citation-pill {
  border: 1px solid #b9d4d6; background: var(--primary-soft); color: var(--primary-strong);
  border-radius: 999px; padding: 5px 9px; font-size: 10px; font-weight: 800;
  display: inline-flex; align-items: center; gap: 6px;
}
.citation-pill:hover { background: #dfeff0; }
.citation-pill.review { background: var(--review-soft); border-color: #e9cfa7; color: #845618; }
.citation-flag { border-left: 1px solid currentColor; padding-left: 6px; opacity: .78; }

.sources-section { margin-top: 31px; }
.section-heading { margin-bottom: 11px; }
.section-heading h3 { font-size: 19px; }
.source-count { color: var(--muted); font-size: 11px; }
.source-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); gap: 10px; }
.source-card {
  width: 100%; text-align: left; border: 1px solid var(--line); border-radius: 14px;
  background: var(--surface); padding: 14px 15px; display: grid; grid-template-columns: auto 1fr auto;
  gap: 12px; align-items: start; color: inherit; box-shadow: 0 5px 16px rgba(21,36,50,.035);
}
.source-card.review { border-color: #ead8ba; }
.source-card:hover { border-color: #afc8cb; box-shadow: 0 8px 20px rgba(21,36,50,.06); }
.source-number { width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; background: var(--primary); color: #fff; font-size: 11px; font-weight: 800; }
.source-number.review { background: var(--review); }
.source-card-body { min-width: 0; }
.source-title { font-weight: 760; line-height: 1.3; font-size: 14px; }
.source-meta { margin-top: 5px; color: var(--muted); font-size: 11px; display: flex; flex-wrap: wrap; gap: 5px 10px; }
.source-quality { margin-top: 8px; font-size: 10px; font-weight: 800; display: inline-flex; border-radius: 999px; padding: 4px 7px; }
.source-quality.accepted { color: var(--ok); background: var(--ok-soft); }
.source-quality.review { color: var(--review); background: var(--review-soft); }
.source-arrow { color: #97a1aa; font-size: 21px; line-height: 1; align-self: center; }

.drawer-backdrop { position: fixed; inset: 0; background: rgba(15, 25, 33, .40); z-index: 40; backdrop-filter: blur(1px); }
.source-drawer {
  position: fixed; top: 0; right: 0; width: min(500px, 100%); height: 100vh; background: #fff;
  z-index: 50; transform: translateX(100%); transition: transform .22s ease; box-shadow: -18px 0 40px rgba(15,25,33,.15);
  display: flex; flex-direction: column;
}
.source-drawer.open { transform: translateX(0); }
.drawer-header { padding: 21px 24px 17px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: flex-start; gap: 18px; }
.drawer-header h3 { margin: 0; font-size: 21px; line-height: 1.3; letter-spacing: -.015em; }
.drawer-close { width: 34px; height: 34px; border-radius: 9px; border: 1px solid var(--line); background: #fff; font-size: 23px; line-height: 1; color: #5f6b76; }
.drawer-close:hover { background: var(--surface-soft); }
.drawer-body { overflow-y: auto; padding: 20px 24px 34px; }
.drawer-facts { display: flex; flex-wrap: wrap; gap: 7px; padding-bottom: 18px; border-bottom: 1px solid #edf0f2; }
.drawer-fact { display: inline-flex; align-items: center; border-radius: 999px; padding: 6px 9px; background: #f4f7f8; color: #53616c; font-size: 11px; font-weight: 700; }
.drawer-fact.review { background: var(--review-soft); color: var(--review); }
.drawer-fact.accepted { background: var(--ok-soft); color: var(--ok); }
.drawer-block { margin-top: 20px; }
.drawer-label { color: var(--muted); font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; }
.source-text { white-space: pre-wrap; margin-top: 9px; line-height: 1.68; font-size: 14px; padding: 0; color: #26333e; background: transparent; border: 0; }
.drawer-document-line { margin-top: 25px; padding-top: 17px; border-top: 1px solid #edf0f2; display: flex; align-items: flex-end; justify-content: space-between; gap: 14px; }
.document-name { font-weight: 760; margin-top: 6px; }
.document-pages { margin-top: 3px; font-size: 11px; color: var(--muted); }
.secondary-button { border: 1px solid #b7d2d5; background: var(--primary-soft); color: var(--primary-strong); border-radius: 9px; padding: 9px 11px; white-space: nowrap; font-weight: 700; }

@media (max-width: 760px) {
  html { scroll-padding-top: 86px; }
  .topbar { min-height: auto; padding: 12px 16px; gap: 10px; align-items: flex-start; }
  .brand-subtitle { display: none; }
  .brand-title { font-size: 13px; }
  .system-state { margin-top: 1px; }
  .content { width: min(100% - 26px, 1080px); padding-top: 28px; }
  .hero h1 { font-size: 33px; }
  .hero > p { font-size: 14px; }
  .search-actions { align-items: flex-end; }
  .search-hint { max-width: 160px; }
  .result-header, .section-heading { align-items: flex-start; flex-direction: column; gap: 7px; }
  .source-list { grid-template-columns: 1fr; }
  .source-card { grid-template-columns: auto 1fr; }
  .source-arrow { display: none; }
  .answer-item { padding: 16px 16px 14px; }
  .answer-item-header { align-items: flex-start; }
  .drawer-document-line { align-items: flex-start; flex-direction: column; }
}

/* Keep long extraction-quality labels inside the drawer on narrow viewports. */
.drawer-fact { max-width: 100%; white-space: normal; overflow-wrap: anywhere; flex: 0 1 auto; min-width: 0; }
