:root {
  --canvas: #f7f8f7;
  --surface: #ffffff;
  --sidebar: #eef1ef;
  --line: #dce2df;
  --line-strong: #cbd4cf;
  --ink: #15201b;
  --muted: #66736d;
  --soft: #8a9690;
  --accent: #087f69;
  --accent-dark: #075e50;
  --accent-soft: #dff2ed;
  --amber: #b26c17;
  --amber-soft: #fff0d7;
  --red: #b64b42;
  --red-soft: #fbe9e6;
  --shadow: 0 14px 34px rgba(23, 38, 30, 0.08);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; margin: 0; }
body {
  min-width: 320px;
  min-height: 100dvh;
  display: flex;
  overflow: hidden;
  background: var(--canvas);
  color: var(--ink);
  font: 15px/1.65 Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, textarea { font: inherit; }
button { color: inherit; cursor: pointer; }
button:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.sidebar {
  width: 272px;
  flex: 0 0 272px;
  display: flex;
  flex-direction: column;
  background: var(--sidebar);
  border-right: 1px solid var(--line);
  transition: margin-left 180ms ease;
}
body.sidebar-collapsed .sidebar { margin-left: -272px; }
.sidebar-top { height: 68px; padding: 0 16px 0 20px; display: flex; align-items: center; justify-content: space-between; }
.brand-lockup { display: flex; align-items: center; gap: 10px; font-weight: 750; letter-spacing: .01em; }
.brand-mark { width: 28px; height: 28px; display: grid; place-items: center; border-radius: 8px; background: var(--accent); color: #fff; font-size: 18px; font-weight: 600; }
.icon-button { width: 34px; height: 34px; display: grid; place-items: center; border: 0; border-radius: 8px; background: transparent; color: var(--muted); font-size: 21px; line-height: 1; }
.icon-button:hover { background: rgba(8, 127, 105, .09); color: var(--ink); }
.new-request { margin: 4px 16px 22px; min-height: 42px; display: flex; align-items: center; gap: 10px; padding: 0 14px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--surface); color: var(--ink); font-weight: 650; box-shadow: 0 2px 4px rgba(23, 38, 30, .03); }
.new-request:hover { border-color: var(--accent); color: var(--accent-dark); }
.button-icon { font-size: 21px; font-weight: 400; line-height: 1; }
.sidebar-label { padding: 0 20px 8px; color: var(--soft); font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.request-list { min-height: 0; flex: 1; overflow: auto; padding: 0 10px; }
.request-row { display: flex; align-items: center; gap: 8px; min-height: 42px; padding: 7px 10px; border-radius: 7px; color: var(--muted); cursor: pointer; }
.request-row:hover, .request-row.active { background: rgba(255,255,255,.72); color: var(--ink); }
.request-row.active { box-shadow: inset 3px 0 0 var(--accent); }
.request-row .request-icon { width: 20px; color: var(--accent); font-size: 14px; text-align: center; }
.request-row .request-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.request-empty { padding: 10px; color: var(--soft); font-size: 13px; }
.sidebar-footer { padding: 18px 18px 20px; border-top: 1px solid var(--line); }
.storage-note { display: flex; gap: 9px; align-items: flex-start; margin-bottom: 13px; color: var(--muted); font-size: 12px; line-height: 1.45; }
.storage-note strong, .storage-note span { display: block; }
.storage-note strong { color: var(--ink); font-size: 13px; }
.status-dot { width: 8px; height: 8px; flex: 0 0 auto; margin-top: 6px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.footer-link { padding: 0; border: 0; background: transparent; color: var(--soft); font-size: 12px; }
.footer-link:hover { color: var(--red); }

.main-shell { min-width: 0; flex: 1; display: flex; flex-direction: column; }
.topbar { height: 68px; flex: 0 0 68px; display: flex; align-items: center; gap: 10px; padding: 0 28px; border-bottom: 1px solid var(--line); background: rgba(247,248,247,.9); }
.topbar-title { min-width: 0; }
.eyebrow { display: block; color: var(--soft); font-size: 10px; font-weight: 750; letter-spacing: .14em; line-height: 1.2; }
.topbar h1 { margin: 2px 0 0; font-size: 17px; line-height: 1.2; letter-spacing: .01em; }
.topbar-actions { margin-left: auto; }
.mode-badge { display: inline-flex; align-items: center; gap: 8px; padding: 5px 10px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); background: rgba(255,255,255,.68); font-size: 12px; }
.mode-badge .status-dot { width: 6px; height: 6px; margin: 0; box-shadow: none; }
.mobile-only { display: none; }
.scroll-area { min-height: 0; flex: 1; overflow: auto; }
.thread { width: min(100%, 850px); margin: 0 auto; padding: 40px 30px 30px; }
.welcome { padding: 68px 0 40px; }
.welcome-kicker { color: var(--accent); font-size: 12px; font-weight: 750; letter-spacing: .09em; text-transform: uppercase; }
.welcome h2 { margin: 8px 0 8px; font-size: clamp(30px, 5vw, 48px); line-height: 1.12; letter-spacing: -.035em; }
.welcome p { max-width: 520px; margin: 0; color: var(--muted); font-size: 16px; }
.suggestions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 26px; }
.suggestion { padding: 8px 12px; border: 1px solid var(--line); border-radius: 7px; background: rgba(255,255,255,.76); color: var(--muted); font-size: 13px; text-align: left; }
.suggestion:hover { border-color: var(--accent); color: var(--accent-dark); background: var(--surface); }
.message { margin: 0 0 30px; }
.message.user { display: flex; justify-content: flex-end; }
.user-bubble { max-width: min(76%, 620px); padding: 11px 15px; border-radius: 14px 14px 3px 14px; background: #e7ece9; white-space: pre-wrap; overflow-wrap: anywhere; }
.assistant-head { display: flex; align-items: center; gap: 8px; margin-bottom: 9px; color: var(--accent-dark); font-size: 13px; font-weight: 700; }
.assistant-mark { width: 22px; height: 22px; display: grid; place-items: center; border-radius: 6px; background: var(--accent); color: #fff; font-size: 12px; }
.assistant-body { color: var(--ink); }
.assistant-body p { margin: .4em 0 1em; }
.assistant-body strong { font-weight: 700; }
.streaming { color: var(--muted); }
.streaming::after { content: ""; display: inline-block; width: 5px; height: 15px; margin-left: 5px; vertical-align: -2px; background: var(--accent); animation: blink 900ms steps(2, start) infinite; }
@keyframes blink { 50% { opacity: 0; } }

.source-grid { display: grid; gap: 10px; margin-top: 15px; }
.source-card { padding: 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); box-shadow: 0 2px 5px rgba(23, 38, 30, .025); }
.source-card:hover { border-color: #a9c8bd; }
.source-top { display: flex; align-items: flex-start; gap: 12px; }
.source-icon { width: 32px; height: 32px; flex: 0 0 auto; display: grid; place-items: center; border-radius: 7px; background: var(--accent-soft); color: var(--accent-dark); font-size: 16px; font-weight: 750; }
.source-main { min-width: 0; flex: 1; }
.source-title { margin: 0; font-size: 15px; font-weight: 700; line-height: 1.35; overflow-wrap: anywhere; }
.source-url { margin-top: 3px; color: var(--soft); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.source-meta { display: flex; flex-wrap: wrap; gap: 7px 14px; margin: 10px 0 0 44px; color: var(--muted); font-size: 12px; }
.source-meta span { display: inline-flex; align-items: center; gap: 5px; }
.source-meta .label { color: var(--soft); }
.source-actions { display: flex; justify-content: flex-end; gap: 7px; margin-top: 12px; }
.source-actions button, .source-actions a { min-height: 32px; display: inline-flex; align-items: center; padding: 0 11px; border-radius: 6px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--muted); font-size: 12px; text-decoration: none; }
.source-actions button:hover, .source-actions a:hover { border-color: var(--accent); color: var(--accent-dark); }
.source-actions .primary { border-color: var(--accent); background: var(--accent); color: #fff; }
.source-actions .primary:hover { background: var(--accent-dark); color: #fff; }
.source-actions button:disabled { cursor: default; opacity: .68; }
.source-status { display: inline-flex; align-items: center; gap: 5px; padding: 3px 7px; border-radius: 4px; font-size: 11px; font-weight: 700; }
.source-status.available { color: var(--accent-dark); background: var(--accent-soft); }
.source-status.cached { color: #6d4b13; background: var(--amber-soft); }
.source-status.error { color: var(--red); background: var(--red-soft); }

.queue-panel { margin-top: 14px; padding: 13px 14px; border: 1px solid var(--line); border-radius: 8px; background: #fbfcfb; }
.queue-head { display: flex; align-items: center; gap: 10px; }
.queue-title { font-size: 13px; font-weight: 700; }
.queue-id { margin-left: auto; color: var(--soft); font: 11px/1.3 ui-monospace, SFMono-Regular, Menlo, monospace; }
.queue-track { height: 6px; margin-top: 11px; overflow: hidden; border-radius: 999px; background: #e5ebe7; }
.queue-progress { width: 0; height: 100%; border-radius: inherit; background: var(--accent); transition: width 300ms ease; }
.queue-info { display: flex; justify-content: space-between; gap: 12px; margin-top: 7px; color: var(--muted); font-size: 12px; }
.queue-info strong { color: var(--ink); }
.queue-download { display: inline-flex; align-items: center; gap: 5px; min-height: 30px; margin-top: 10px; padding: 0 10px; border: 1px solid var(--accent); border-radius: 6px; background: var(--surface); color: var(--accent-dark); font-size: 12px; font-weight: 700; text-decoration: none; }
.queue-download:hover { background: var(--accent-soft); }

.composer-wrap { flex: 0 0 auto; padding: 0 30px 22px; }
.composer { width: min(100%, 850px); min-height: 58px; display: flex; align-items: flex-end; gap: 10px; margin: 0 auto; padding: 9px 10px 9px 17px; border: 1px solid var(--line-strong); border-radius: 12px; background: var(--surface); box-shadow: var(--shadow); }
.composer textarea { min-width: 0; flex: 1; height: 38px; max-height: 180px; resize: none; padding: 6px 0; border: 0; outline: 0; background: transparent; color: var(--ink); font-size: 15px; line-height: 1.55; }
.composer textarea::placeholder { color: var(--soft); }
.send-button { width: 38px; height: 38px; flex: 0 0 auto; display: grid; place-items: center; border: 0; border-radius: 8px; background: var(--accent); color: #fff; font-size: 22px; line-height: 1; }
.send-button:hover { background: var(--accent-dark); }
.send-button:disabled { background: #d5ddd8; color: #829089; cursor: default; }
.composer-foot { width: min(100%, 850px); display: flex; justify-content: space-between; gap: 14px; margin: 8px auto 0; color: var(--soft); font-size: 11px; }
.mobile-scrim { display: none; }
.toast { position: fixed; left: 50%; bottom: 30px; z-index: 10; max-width: min(90vw, 420px); padding: 10px 14px; border: 1px solid var(--line-strong); border-radius: 7px; background: var(--ink); color: #fff; font-size: 13px; opacity: 0; transform: translate(-50%, 10px); pointer-events: none; transition: opacity 160ms ease, transform 160ms ease; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 760px) {
  body { overflow: hidden; }
  .sidebar { position: fixed; inset: 0 auto 0 0; z-index: 5; box-shadow: 14px 0 30px rgba(20, 34, 26, .11); }
  body.sidebar-collapsed .sidebar { margin-left: -272px; }
  .mobile-only { display: grid; }
  .mobile-scrim { position: fixed; inset: 0; z-index: 4; display: block; background: rgba(15, 27, 21, .25); opacity: 0; pointer-events: none; transition: opacity 180ms ease; }
  body.sidebar-open .mobile-scrim { opacity: 1; pointer-events: auto; }
  body.sidebar-open .sidebar { margin-left: 0; }
  .topbar { padding: 0 16px; }
  .thread { padding: 28px 16px 25px; }
  .welcome { padding: 46px 0 28px; }
  .welcome h2 { font-size: 34px; }
  .user-bubble { max-width: 88%; }
  .composer-wrap { padding: 0 14px 14px; }
  .composer-foot { padding: 0 3px; }
  .composer-foot span:last-child { display: none; }
}

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