:root {
  color-scheme: light;
  --red: #c9252c;
  --red-dark: #a8171d;
  --ink: #171717;
  --muted: #686865;
  --soft: #f4f4f1;
  --panel: #fafaf8;
  --paper: #ffffff;
  --line: #e1e1dc;
  --line-strong: #d1d1ca;
  --green: #2d8a5b;
  --blue: #286f9b;
  --amber: #a86814;
  --shadow: 0 10px 28px rgba(24, 24, 20, .08);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  height: 100dvh;
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, textarea { font: inherit; }
button { cursor: pointer; }

.app-shell { height: 100dvh; display: grid; grid-template-rows: 68px minmax(0, 1fr); }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 10px clamp(18px, 3vw, 38px);
  background: white;
  border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 8px rgba(20, 20, 18, .04);
  z-index: 5;
}
.brand { min-width: 0; display: flex; align-items: center; gap: 16px; }
.brand img { display: block; width: auto; height: 39px; object-fit: contain; }
.brand-divider { width: 1px; height: 34px; background: var(--line-strong); }
.product-name { display: grid; gap: 2px; white-space: nowrap; }
.product-name strong { font-size: .94rem; letter-spacing: -.01em; }
.product-name span { color: var(--muted); font-size: .72rem; }
.header-status { display: flex; align-items: center; gap: 8px; color: #555651; font-size: .78rem; white-space: nowrap; }
.header-status > span { width: 8px; height: 8px; background: #3ca86f; border-radius: 50%; box-shadow: 0 0 0 4px rgba(60,168,111,.12); }

.app-body { min-height: 0; display: grid; grid-template-columns: 292px minmax(0, 1fr); }
.suggestion-rail {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  padding: 26px 18px 16px;
  background: var(--panel);
  border-right: 1px solid var(--line);
}
.rail-heading { padding: 0 8px 17px; }
.rail-heading p { margin: 0 0 5px; color: var(--red); font-size: .65rem; font-weight: 750; letter-spacing: .12em; }
.rail-heading h1 { margin: 0; font-size: 1rem; letter-spacing: -.01em; }
.prompt-list { min-height: 0; display: grid; align-content: start; gap: 8px; overflow-y: auto; padding: 0 4px 10px; scrollbar-width: thin; }
.chip {
  width: 100%;
  padding: 11px 12px;
  color: #353532;
  text-align: left;
  font-size: .79rem;
  line-height: 1.38;
  background: white;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 1px 2px rgba(20,20,18,.03);
  transition: border-color .15s, background .15s, transform .15s, box-shadow .15s;
}
.chip:hover, .chip:focus-visible { border-color: #d65c61; background: #fffafa; box-shadow: 0 4px 12px rgba(82,26,29,.07); transform: translateY(-1px); outline: none; }
.chip:disabled { cursor: wait; opacity: .55; transform: none; }
.rail-footer { display: flex; align-items: center; gap: 7px; padding: 13px 8px 0; color: #797975; border-top: 1px solid var(--line); font-size: .66rem; }
.rail-footer strong { color: #575753; font-weight: 650; }
.rail-dot { width: 6px; height: 6px; background: var(--green); border-radius: 50%; }

.chat-surface { min-width: 0; min-height: 0; display: grid; grid-template-rows: minmax(0, 1fr) auto; background: white; }
.transcript { min-height: 0; overflow-y: auto; overscroll-behavior: contain; scroll-behavior: smooth; scrollbar-gutter: stable; }
.welcome { width: min(700px, calc(100% - 40px)); min-height: 100%; margin: 0 auto; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 44px 0; text-align: center; }
.welcome-mark { display: grid; place-items: center; width: 54px; height: 54px; color: white; background: var(--red); clip-path: polygon(50% 0, 100% 100%, 68% 100%, 57% 70%, 43% 70%, 32% 100%, 0 100%); font-size: 0; filter: drop-shadow(0 8px 12px rgba(201,37,44,.18)); }
.welcome h2 { margin: 21px 0 8px; font-size: clamp(1.65rem, 3vw, 2.25rem); font-weight: 620; letter-spacing: -.035em; }
.welcome > p { max-width: 580px; margin: 0; color: var(--muted); line-height: 1.55; }
.welcome-note { max-width: 610px; display: flex; align-items: center; gap: 10px; margin-top: 24px; padding: 12px 15px; color: #565651; text-align: left; font-size: .78rem; line-height: 1.4; background: var(--soft); border-radius: 10px; }
.welcome-note svg { flex: 0 0 22px; width: 22px; fill: none; stroke: var(--green); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.turn { width: min(900px, calc(100% - 44px)); margin: 0 auto; padding: 25px 0; }
.turn + .turn { border-top: 1px solid #eeeeea; }
.user-turn { display: flex; justify-content: flex-end; padding-top: 20px; padding-bottom: 20px; }
.user-bubble { max-width: min(680px, 84%); padding: 12px 16px; color: #20201e; background: #f0f0ec; border-radius: 17px 17px 4px 17px; line-height: 1.5; white-space: pre-wrap; }
.assistant-turn { display: grid; grid-template-columns: 34px minmax(0, 1fr); gap: 14px; }
.assistant-avatar { display: grid; place-items: center; width: 30px; height: 30px; margin-top: 2px; color: white; background: var(--red); border-radius: 8px; font-size: .82rem; font-weight: 800; }
.assistant-content { min-width: 0; }
.assistant-label { display: flex; align-items: center; justify-content: space-between; min-height: 30px; margin-bottom: 7px; }
.assistant-label strong { font-size: .85rem; }
.response-state { color: var(--muted); font-size: .71rem; }

.activity {
  width: min(680px, 100%);
  margin: 7px 0 14px;
  background: #f7f7f4;
  border: 1px solid var(--line);
  border-radius: 11px;
  overflow: hidden;
}
.activity summary, .sources summary { list-style: none; }
.activity summary::-webkit-details-marker, .sources summary::-webkit-details-marker { display: none; }
.activity-summary {
  min-height: 43px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  color: #4c4c48;
  font-size: .78rem;
  font-weight: 620;
  cursor: pointer;
  user-select: none;
}
.activity-summary::after, .sources-summary::after { content: ''; width: 7px; height: 7px; margin-left: auto; border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor; transform: rotate(45deg) translateY(-2px); transition: transform .15s; }
details[open] > .activity-summary::after, details[open] > .sources-summary::after { transform: rotate(225deg) translate(-2px, -1px); }
.activity-pulse { width: 8px; height: 8px; background: var(--red); border-radius: 50%; animation: activityPulse 1.15s ease-in-out infinite; }
.activity.finished .activity-pulse { background: var(--green); animation: none; }
.activity-list { position: relative; display: grid; gap: 0; margin: 0; padding: 0 13px 12px 41px; list-style: none; }
.activity-list::before { content: ''; position: absolute; left: 20px; top: 2px; bottom: 21px; width: 1px; background: #d4d4ce; }
.activity-row { position: relative; min-height: 37px; padding: 2px 0 9px; }
.activity-row::before { content: ''; position: absolute; left: -25px; top: 5px; width: 9px; height: 9px; background: white; border: 2px solid #b5b5ae; border-radius: 50%; z-index: 1; }
.activity-row.active::before { border-color: var(--red); border-top-color: transparent; animation: spin .85s linear infinite; }
.activity-row.complete::before { background: var(--green); border-color: var(--green); box-shadow: inset 0 0 0 2px white; }
.activity-row.error::before { background: var(--red); border-color: var(--red); }
.activity-label { display: block; color: #3f3f3b; font-size: .76rem; font-weight: 650; line-height: 1.25; }
.activity-detail { display: block; margin-top: 2px; color: #787873; font-size: .7rem; line-height: 1.35; }

.answer { color: #272724; font-size: .96rem; line-height: 1.7; white-space: pre-wrap; overflow-wrap: anywhere; }
.answer:empty { display: none; }
.answer.streaming::after { content: ''; display: inline-block; width: 6px; height: 1em; margin-left: 3px; vertical-align: -.14em; background: var(--red); animation: caret 1s steps(1) infinite; }
.error-panel { margin-top: 12px; padding: 11px 13px; color: #881c21; background: #fff2f2; border: 1px solid #f1c7c9; border-radius: 9px; font-size: .78rem; line-height: 1.45; }

.sources { margin-top: 16px; border-top: 1px solid var(--line); }
.sources-summary { display: flex; align-items: center; gap: 8px; padding: 13px 1px 6px; color: #4b4b47; font-size: .78rem; font-weight: 650; cursor: pointer; user-select: none; }
.source-icon { width: 18px; height: 18px; fill: none; stroke: var(--blue); stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.source-count { display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px; color: #53534f; background: #ecece7; border-radius: 10px; font-size: .68rem; }
.source-list { max-height: 280px; display: grid; gap: 8px; overflow-y: auto; padding: 8px 3px 4px 1px; }
.source-card { padding: 12px 13px; background: #f8fafb; border: 1px solid #dce5e9; border-radius: 9px; }
.source-card.local { background: #fff9ee; border-color: #edd9aa; }
.source-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.source-title { margin: 0; color: #303b42; font-size: .78rem; font-weight: 700; line-height: 1.35; overflow-wrap: anywhere; }
.source-badge { flex: 0 0 auto; padding: 3px 6px; color: var(--blue); background: #e9f3f7; border-radius: 5px; font-size: .58rem; font-weight: 750; letter-spacing: .04em; text-transform: uppercase; }
.source-card.local .source-badge { color: #8a5a10; background: #f7e9c8; }
.source-excerpt { margin: 7px 0 0; color: #626d73; font-size: .72rem; line-height: 1.45; }
.source-meta { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 8px; color: #818b90; font-size: .64rem; }
.source-uri { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--blue); text-decoration: none; }
.source-uri:hover { text-decoration: underline; }

.composer-area { padding: 10px clamp(20px, 4vw, 42px) 12px; background: linear-gradient(to bottom, rgba(255,255,255,.7), white 22%); }
.composer { width: min(900px, 100%); min-height: 54px; display: grid; grid-template-columns: minmax(0, 1fr) 42px; align-items: end; gap: 8px; margin: 0 auto; padding: 6px 7px 6px 16px; background: white; border: 1px solid var(--line-strong); border-radius: 16px; box-shadow: var(--shadow); }
.composer:focus-within { border-color: #b7b7af; box-shadow: 0 10px 30px rgba(24,24,20,.1), 0 0 0 3px rgba(201,37,44,.06); }
textarea { width: 100%; min-height: 40px; max-height: 118px; padding: 10px 0 8px; resize: none; overflow-y: auto; color: var(--ink); background: transparent; border: 0; outline: 0; line-height: 1.4; }
textarea::placeholder { color: #92928d; }
#send-button { width: 40px; height: 40px; display: grid; place-items: center; color: white; background: var(--red); border: 0; border-radius: 11px; transition: background .15s, transform .15s; }
#send-button:hover, #send-button:focus-visible { background: var(--red-dark); transform: translateY(-1px); outline: none; }
#send-button:disabled { cursor: wait; background: #bcbcb7; transform: none; }
#send-button svg { width: 20px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.disclaimer { margin: 8px 0 0; color: #8a8a85; text-align: center; font-size: .64rem; }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
[hidden] { display: none !important; }

@keyframes activityPulse { 0%,100% { opacity: .35; transform: scale(.8); } 50% { opacity: 1; transform: scale(1.18); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes caret { 0%,49% { opacity: 1; } 50%,100% { opacity: 0; } }

@media (max-width: 850px) {
  .app-shell { grid-template-rows: 62px minmax(0, 1fr); }
  .topbar { padding-inline: 16px; }
  .brand img { height: 32px; }
  .brand-divider, .product-name span { display: none; }
  .app-body { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); }
  .suggestion-rail { display: block; padding: 9px 12px; border-right: 0; border-bottom: 1px solid var(--line); }
  .rail-heading, .rail-footer { display: none; }
  .prompt-list { display: flex; gap: 8px; overflow-x: auto; overflow-y: hidden; padding: 0 0 2px; scrollbar-width: none; }
  .prompt-list::-webkit-scrollbar { display: none; }
  .chip { flex: 0 0 270px; max-height: 53px; overflow: hidden; padding: 9px 11px; font-size: .72rem; }
  body.has-messages .suggestion-rail { display: none; }
  .turn { width: min(100% - 28px, 860px); }
  .composer-area { padding: 9px 14px 10px; }
}

@media (max-width: 560px) {
  .header-status { font-size: 0; }.header-status::after { content: 'Grounded'; font-size: .7rem; }
  .product-name strong { font-size: .8rem; }
  .brand { gap: 9px; }.brand img { height: 27px; }
  .welcome { width: calc(100% - 30px); padding: 28px 0; }
  .welcome-note { align-items: flex-start; }
  .turn { padding-block: 18px; }
  .assistant-turn { grid-template-columns: 29px minmax(0,1fr); gap: 10px; }
  .assistant-avatar { width: 27px; height: 27px; border-radius: 7px; }
  .user-bubble { max-width: 92%; }
  .source-list { max-height: 220px; }
}

@media (max-height: 650px) {
  .app-shell { grid-template-rows: 56px minmax(0, 1fr); }
  .topbar { padding-block: 7px; }.brand img { height: 29px; }
  .welcome { padding-block: 24px; }.welcome-mark { width: 42px; height: 42px; }
  .welcome h2 { margin-top: 14px; }.welcome-note { margin-top: 14px; }
  .composer-area { padding-top: 7px; padding-bottom: 7px; }.disclaimer { margin-top: 5px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
