:root {
  color-scheme: light;
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  --ink: #172033;
  --muted: #69738a;
  --border: #e4e8f1;
  --soft: #f6f8fc;
  --panel: #ffffff;
  --accent: #625cf6;
  --accent-soft: #efefff;
  --accent-deep: #4540d7;
  --danger: #cb345d;
  --shadow: 0 14px 40px rgba(20, 31, 58, 0.08);
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; min-width: 320px; overflow: hidden; background: #f7f8fc; color: var(--ink); }

body { min-height: 100dvh; height: 100dvh; font-size: 16px; }

button, textarea, select { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
button:focus-visible, textarea:focus-visible, select:focus-visible, a:focus-visible {
  outline: 3px solid rgba(98, 92, 246, 0.32);
  outline-offset: 2px;
}

.app-shell { display: flex; height: 100dvh; min-height: 0; overflow: hidden; }

.sidebar {
  z-index: 10;
  display: flex;
  width: 17.5rem;
  min-height: 0;
  flex: 0 0 17.5rem;
  flex-direction: column;
  padding: 1rem;
  border-right: 1px solid var(--border);
  background: #fff;
  transition: transform 180ms ease;
}

.brand-row { display: flex; align-items: center; gap: 0.72rem; padding: 0.35rem 0.35rem 1.3rem; }
.brand-mark { display: grid; width: 2.2rem; height: 2.2rem; place-items: center; border-radius: 0.8rem; background: linear-gradient(135deg, #7d78ff, #3431a9); box-shadow: 0 8px 18px rgba(75, 69, 215, 0.25); color: white; font-weight: 800; }
.brand-row strong { display: block; font-size: 0.98rem; letter-spacing: -0.02em; }
.brand-row span { display: block; margin-top: 0.08rem; color: var(--muted); font-size: 0.75rem; }

.new-chat { display: inline-flex; align-items: center; justify-content: center; gap: 0.45rem; width: 100%; min-height: 2.7rem; border: 0; border-radius: 0.8rem; background: var(--ink); box-shadow: 0 6px 16px rgba(23, 32, 51, 0.15); color: white; cursor: pointer; font-size: 0.9rem; font-weight: 650; transition: background 160ms ease, transform 160ms ease; }
.new-chat:hover { background: #2a354d; transform: translateY(-1px); }
.new-chat span { font-size: 1.25rem; font-weight: 300; line-height: 0; }

.sidebar-label { padding: 1.35rem 0.45rem 0.55rem; color: #8b93a7; font-size: 0.75rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; }
.chat-list { min-height: 0; flex: 1; overflow-y: auto; padding-right: 0.1rem; }
.chat-row { display: flex; align-items: center; gap: 0.42rem; width: 100%; min-height: 2.7rem; padding: 0.48rem 0.42rem 0.48rem 0.7rem; border: 0; border-radius: 0.68rem; background: transparent; color: #4f596d; cursor: pointer; text-align: left; transition: background 140ms ease, color 140ms ease; }
.chat-row:hover { background: var(--soft); color: var(--ink); }
.chat-row.is-active { background: var(--accent-soft); color: #3731c6; }
.chat-row-text { min-width: 0; flex: 1; }
.chat-row-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.875rem; font-weight: 590; }
.chat-row-preview { overflow: hidden; margin-top: 0.14rem; color: #9199ab; font-size: 0.72rem; text-overflow: ellipsis; white-space: nowrap; }
.chat-row.is-active .chat-row-preview { color: #7771d7; }
.chat-delete { display: grid; width: 1.65rem; height: 1.65rem; flex: 0 0 auto; place-items: center; border: 0; border-radius: 0.42rem; background: transparent; color: #9ca4b3; cursor: pointer; opacity: 0; transition: opacity 120ms ease, color 120ms ease, background 120ms ease; }
.chat-row:hover .chat-delete, .chat-row:focus-within .chat-delete { opacity: 1; }
.chat-delete:hover { background: #fff0f3; color: var(--danger); }

.sidebar-footer { display: flex; align-items: center; gap: 0.45rem; margin-top: 0.85rem; padding: 0.8rem 0.35rem 0.15rem; border-top: 1px solid var(--border); color: #7d879b; font-size: 0.75rem; }
.status-dot { width: 0.48rem; height: 0.48rem; flex: 0 0 auto; border-radius: 50%; background: #c7cedb; }
.status-dot.is-ready { background: #2bb276; box-shadow: 0 0 0 3px rgba(43, 178, 118, 0.13); }
.status-dot.is-error { background: #d85a75; box-shadow: 0 0 0 3px rgba(216, 90, 117, 0.13); }

.workspace { position: relative; display: grid; min-width: 0; min-height: 0; flex: 1; overflow: hidden; grid-template-rows: auto minmax(0, 1fr) auto; }
.topbar { display: flex; min-height: 4.1rem; align-items: center; justify-content: space-between; gap: 1rem; padding: 0.75rem clamp(1rem, 3vw, 2.25rem); border-bottom: 1px solid rgba(228, 232, 241, 0.9); background: rgba(255, 255, 255, 0.88); backdrop-filter: blur(10px); }
.topbar-start { display: flex; min-width: 0; align-items: center; gap: 0.72rem; }
.conversation-heading { min-width: 0; }
.conversation-heading strong { display: block; overflow: hidden; font-size: 0.98rem; letter-spacing: -0.015em; text-overflow: ellipsis; white-space: nowrap; }
.conversation-heading span { display: block; overflow: hidden; margin-top: 0.08rem; color: var(--muted); font-size: 0.75rem; text-overflow: ellipsis; white-space: nowrap; }
.model-select-label select { min-height: 2.3rem; max-width: 10rem; padding: 0 2rem 0 0.75rem; border: 1px solid var(--border); border-radius: 0.65rem; background: white; color: #394256; cursor: pointer; font-size: 0.84rem; font-weight: 590; }

.icon-button { display: inline-grid; width: 2.25rem; height: 2.25rem; place-items: center; border: 1px solid var(--border); border-radius: 0.62rem; background: white; color: var(--ink); cursor: pointer; }
.mobile-sidebar { display: none; gap: 0.18rem; align-content: center; }
.mobile-sidebar span { display: block; width: 1rem; height: 1px; border-radius: 2px; background: currentColor; }

.chat-surface { position: relative; min-height: 0; overflow: hidden; }
.message-scroller { height: 100%; min-height: 0; overflow-y: auto; overscroll-behavior: contain; scroll-behavior: auto; }
.message-column { width: min(100%, 54rem); margin: 0 auto; padding: 1.15rem clamp(1rem, 3vw, 2.25rem) 2rem; }
.history-toolbar { display: flex; min-height: 0; justify-content: center; }
.quiet-button { min-height: 2rem; border: 1px solid var(--border); border-radius: 0.55rem; background: white; color: #586379; cursor: pointer; font-size: 0.8rem; font-weight: 600; padding: 0.35rem 0.65rem; transition: background 140ms ease, border-color 140ms ease, color 140ms ease; }
.quiet-button:hover { border-color: #b6bdcf; background: #f9faff; color: var(--ink); }
.message-list { display: grid; gap: 1rem; }

.empty-state { display: grid; max-width: 39rem; min-height: min(34rem, calc(100dvh - 12rem)); margin: 0 auto; align-content: center; justify-items: center; padding: 2rem 0 4rem; text-align: center; }
.empty-state[hidden] { display: none; }
.empty-orb { display: grid; width: 3.75rem; height: 3.75rem; margin-bottom: 1.2rem; place-items: center; border-radius: 1.25rem; background: radial-gradient(circle at 30% 25%, #9c9aff, #5b55e7 55%, #3633a4); box-shadow: 0 16px 34px rgba(82, 77, 223, 0.25); color: #fff; font-size: 1.6rem; }
.empty-state h1 { margin: 0; font-size: clamp(1.45rem, 3vw, 1.9rem); letter-spacing: -0.04em; }
.empty-state p { max-width: 29rem; margin: 0.7rem 0 1.7rem; color: var(--muted); font-size: 0.92rem; line-height: 1.7; }
.prompt-grid { display: grid; width: min(100%, 38rem); grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.6rem; }
.prompt-grid button { min-height: 4.4rem; padding: 0.75rem 0.9rem; border: 1px solid var(--border); border-radius: 0.85rem; background: rgba(255, 255, 255, 0.72); color: #4a556a; cursor: pointer; text-align: left; font-size: 0.87rem; line-height: 1.45; transition: background 140ms ease, border-color 140ms ease, transform 140ms ease; }
.prompt-grid button:hover { border-color: #bcb9ff; background: #f7f6ff; color: #433dd1; transform: translateY(-1px); }

.message { display: grid; grid-template-columns: 2.05rem minmax(0, 1fr); gap: 0.75rem; align-items: start; content-visibility: auto; contain-intrinsic-size: auto 9rem; }
.avatar { display: grid; width: 2.05rem; height: 2.05rem; place-items: center; border-radius: 0.72rem; color: #fff; font-size: 0.76rem; font-weight: 750; }
.message.user .avatar { background: #202b40; }
.message.assistant .avatar { background: linear-gradient(135deg, #7c77ff, #514ddd); box-shadow: 0 5px 12px rgba(84, 78, 220, 0.2); }
.message-card { min-width: 0; }
.message.user .message-card { max-width: 46rem; justify-self: end; }
.message-content { min-width: 0; border: 1px solid #e9ecf4; border-radius: 1rem; background: var(--panel); box-shadow: 0 4px 14px rgba(38, 51, 82, 0.035); padding: 0.9rem 1rem; color: #283347; font-size: 0.96rem; line-height: 1.75; overflow-wrap: anywhere; }
.message.user .message-content { border-color: #252f45; background: #202b40; color: #fff; box-shadow: none; }
.message.user .message-content { white-space: pre-wrap; }
.message-content > :first-child { margin-top: 0; }
.message-content > :last-child { margin-bottom: 0; }
.message-content p { margin: 0.65rem 0; }
.large-content-note { margin: 0 0 0.75rem; color: var(--muted); font-size: 0.82rem; line-height: 1.55; }
.message-content h1, .message-content h2, .message-content h3, .message-content h4 { margin: 1.15rem 0 0.55rem; line-height: 1.35; letter-spacing: -0.02em; }
.message-content h1 { font-size: 1.35rem; }.message-content h2 { font-size: 1.18rem; }.message-content h3 { font-size: 1.04rem; }
.message-content ul, .message-content ol { margin: 0.65rem 0; padding-left: 1.45rem; }
.message-content li + li { margin-top: 0.2rem; }
.message-content blockquote { margin: 0.8rem 0; padding: 0.15rem 0 0.15rem 0.9rem; border-left: 3px solid #aaa7ff; color: #59647a; }
.message-content a { color: #4d48cb; text-decoration: underline; text-decoration-color: rgba(77, 72, 203, 0.35); text-underline-offset: 0.15em; }
.message.user .message-content a { color: #d4d3ff; }
.message-content :not(pre) > code { padding: 0.12rem 0.34rem; border-radius: 0.35rem; background: #eff1f7; color: #cc3160; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.86em; }
.message.user .message-content :not(pre) > code { background: rgba(255,255,255,0.13); color: #f9e6ec; }
.message-content table { display: block; max-width: 100%; overflow-x: auto; border-collapse: collapse; margin: 0.9rem 0; }
.message-content th, .message-content td { min-width: 6rem; padding: 0.42rem 0.55rem; border: 1px solid #dfe4ee; text-align: left; }
.message-content th { background: #f6f7fb; font-weight: 700; }

.code-shell { overflow: hidden; margin: 0.9rem 0; border: 1px solid #28344d; border-radius: 0.72rem; background: #121a2b; color: #eaf0fc; }
.code-shell-header { display: flex; min-height: 2.3rem; align-items: center; justify-content: space-between; gap: 0.6rem; padding: 0.35rem 0.48rem 0.35rem 0.75rem; border-bottom: 1px solid #2e3b57; background: #172137; }
.code-language { color: #aeb9d1; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.72rem; letter-spacing: 0.04em; text-transform: uppercase; }
.code-actions { display: flex; gap: 0.35rem; }
.code-action { min-height: 1.65rem; border: 1px solid #384762; border-radius: 0.38rem; background: transparent; color: #d5def0; cursor: pointer; font-size: 0.72rem; padding: 0.2rem 0.45rem; }
.code-action:hover { background: #293752; }
.code-shell pre { max-height: 24rem; margin: 0; overflow: auto; padding: 0.85rem 1rem; font-size: 0.82rem; line-height: 1.65; }
.code-shell code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; white-space: pre; }

.stream-plain { min-height: 1.5rem; margin: 0; color: #303b51; font: 0.92rem/1.72 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; white-space: pre-wrap; overflow-wrap: anywhere; }
.stream-cursor { display: inline-block; width: 0.36rem; height: 1.1rem; margin-left: 0.16rem; border-radius: 2px; background: var(--accent); vertical-align: -0.18rem; animation: cursor-blink 0.85s steps(2) infinite; }
@keyframes cursor-blink { 50% { opacity: 0.16; } }

.message-status { display: flex; align-items: center; gap: 0.38rem; margin: 0.48rem 0.1rem 0; color: #8791a5; font-size: 0.76rem; }
.message-status > :first-child { min-width: 0; }
.message-status.is-error { color: #bd4865; }
.live-duration { margin-left: auto; color: #929bad; font-variant-numeric: tabular-nums; white-space: nowrap; }
.message-meta { margin: 0.3rem 0.1rem 0; color: #929bad; font-size: 0.72rem; font-variant-numeric: tabular-nums; }
.message-actions { display: flex; gap: 0.35rem; margin-top: 0.45rem; }
.message-actions button { min-height: 1.72rem; border: 0; border-radius: 0.45rem; background: transparent; color: #778196; cursor: pointer; font-size: 0.75rem; padding: 0.2rem 0.4rem; }
.message-actions button:hover { background: #edf0f7; color: #303b51; }

.sources { margin: 0 0 0.7rem; border: 1px solid #e2e6ef; border-radius: 0.7rem; background: #f9faff; overflow: hidden; }
.sources summary { display: flex; align-items: center; gap: 0.45rem; padding: 0.52rem 0.7rem; color: #5a657b; cursor: pointer; font-size: 0.77rem; font-weight: 650; }
.sources-list { display: grid; gap: 0.45rem; padding: 0.1rem 0.7rem 0.7rem; }
.source-item { display: grid; grid-template-columns: 1.35rem minmax(0, 1fr); gap: 0.35rem; color: #69738a; font-size: 0.76rem; line-height: 1.45; }
.source-number { color: #969eb0; font-variant-numeric: tabular-nums; }
.source-title { overflow: hidden; color: #4b45c8; font-weight: 650; text-overflow: ellipsis; white-space: nowrap; }
.source-description { grid-column: 2; color: #7a8498; }

.thinking { margin: 0 0 0.7rem; border: 1px solid #e3e1ff; border-radius: 0.72rem; background: #fafaff; overflow: hidden; }
.thinking summary { padding: 0.5rem 0.7rem; color: #6861d4; cursor: pointer; font-size: 0.78rem; font-weight: 650; }
.thinking pre { max-height: 12rem; margin: 0; overflow: auto; padding: 0 0.7rem 0.7rem; color: #6b7287; font: 0.76rem/1.6 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; white-space: pre-wrap; overflow-wrap: anywhere; }

.scroll-rail { position: absolute; z-index: 4; right: clamp(0.8rem, 2vw, 1.45rem); bottom: 1rem; display: grid; gap: 0.26rem; padding: 0.3rem; border: 1px solid rgba(220, 225, 237, 0.92); border-radius: 0.95rem; background: rgba(255, 255, 255, 0.8); box-shadow: 0 12px 30px rgba(33, 44, 71, 0.14); backdrop-filter: blur(12px); }
.scroll-rail-button { display: inline-flex; min-width: 4.8rem; min-height: 2.3rem; align-items: center; justify-content: center; gap: 0.34rem; border: 0; border-radius: 0.68rem; background: transparent; color: #657087; cursor: pointer; font-size: 0.74rem; font-weight: 720; transition: background 140ms ease, color 140ms ease, transform 140ms ease; }
.scroll-rail-button:hover:not(:disabled) { background: #f0efff; color: #504bd7; transform: translateY(-1px); }
.scroll-rail-button:disabled { color: #aab2c0; cursor: default; opacity: 0.55; }
.scroll-rail-icon { font-size: 1rem; font-weight: 800; line-height: 1; }

.composer-zone { padding: 0.75rem clamp(1rem, 3vw, 2.25rem) 1rem; border-top: 1px solid rgba(228, 232, 241, 0.72); background: linear-gradient(to bottom, rgba(247,248,252,0.7), #f7f8fc); }
.composer-column { width: min(100%, 54rem); margin: 0 auto; }
.composer { border: 1px solid #dfe4ef; border-radius: 1rem; background: #fff; box-shadow: 0 10px 30px rgba(31, 43, 72, 0.07); transition: border-color 150ms ease, box-shadow 150ms ease; }
.composer:focus-within { border-color: #aaa6ff; box-shadow: 0 10px 32px rgba(74, 69, 216, 0.12); }
.composer textarea { display: block; width: 100%; max-height: 11rem; min-height: 3rem; resize: none; overflow-y: auto; padding: 0.9rem 1rem 0.35rem; border: 0; border-radius: 1rem; outline: 0; background: transparent; color: var(--ink); font-size: 0.95rem; line-height: 1.6; }
.composer textarea::placeholder { color: #9aa3b5; }
.composer-actions { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; padding: 0.35rem 0.48rem 0.48rem 0.7rem; }
.toggles { display: flex; min-width: 0; flex-wrap: wrap; gap: 0.35rem; }
.toggle { min-height: 1.9rem; border: 1px solid transparent; border-radius: 999px; background: transparent; color: #778196; cursor: pointer; font-size: 0.76rem; font-weight: 610; padding: 0.25rem 0.58rem; }
.toggle:hover { background: #f4f5f9; color: #4b556a; }
.toggle.is-on { border-color: #d1ceff; background: #f3f2ff; color: #5550d5; }
.send-area { display: flex; align-items: center; gap: 0.55rem; }
.shortcut-hint { color: #9aa3b4; font-size: 0.7rem; white-space: nowrap; }
.send-button { display: inline-flex; min-width: 4.5rem; min-height: 2.15rem; align-items: center; justify-content: center; gap: 0.35rem; border: 0; border-radius: 0.65rem; background: var(--ink); color: white; cursor: pointer; font-size: 0.8rem; font-weight: 700; padding: 0.2rem 0.65rem; transition: transform 140ms ease, background 140ms ease; }
.send-button:hover { background: #303c55; transform: translateY(-1px); }
.send-button.is-stopping { background: var(--danger); }
.send-arrow { font-size: 1rem; line-height: 1; }
.composer-note { margin: 0.45rem 0 0; color: #9099aa; font-size: 0.7rem; text-align: center; }

.code-dialog { width: min(92vw, 58rem); max-height: min(85dvh, 48rem); padding: 0; border: 1px solid #2d3b56; border-radius: 0.95rem; background: #101829; color: #eaf0fc; box-shadow: 0 28px 80px rgba(8, 13, 25, 0.38); }
.code-dialog::backdrop { background: rgba(15, 22, 39, 0.52); backdrop-filter: blur(3px); }
.dialog-header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 0.75rem 0.85rem; border-bottom: 1px solid #2c3a56; background: #172137; }
.dialog-header strong { display: block; font-size: 0.88rem; }.dialog-header span { display: block; margin-top: 0.12rem; color: #93a1bc; font-size: 0.7rem; }
.dialog-actions { display: flex; gap: 0.4rem; }.dialog-actions .quiet-button { border-color: #3a4b6b; background: transparent; color: #e1e9fa; }.dialog-actions .quiet-button:hover { background: #2b3955; }
.close-dialog { border-color: #3a4b6b; background: transparent; color: #e1e9fa; font-size: 1.3rem; }.close-dialog:hover { background: #2b3955; }
.dialog-code { max-height: calc(min(85dvh, 48rem) - 4.6rem); margin: 0; overflow: auto; padding: 1rem; font: 0.82rem/1.65 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; white-space: pre; }

.toast { position: fixed; z-index: 30; left: 50%; bottom: 1.1rem; max-width: min(90vw, 34rem); transform: translateX(-50%); padding: 0.65rem 0.85rem; border: 1px solid #d9d6ff; border-radius: 0.65rem; background: #25213f; box-shadow: 0 12px 30px rgba(25, 28, 48, 0.22); color: #fff; font-size: 0.82rem; line-height: 1.45; }
.toast.is-error { border-color: #f0b9c5; background: #6d2335; }
.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; }

@media (max-width: 760px) {
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(84vw, 19rem); transform: translateX(-105%); box-shadow: 20px 0 55px rgba(30, 39, 64, 0.12); }
  .app-shell.sidebar-open .sidebar { transform: translateX(0); }
  .mobile-sidebar { display: inline-grid; }
  .topbar { min-height: 3.75rem; }
  .message-column { padding: 0.9rem 0.85rem 1.25rem; }
  .composer-zone { padding: 0.6rem 0.85rem calc(0.75rem + env(safe-area-inset-bottom)); }
  .shortcut-hint { display: none; }
  .message-content { padding: 0.8rem 0.85rem; font-size: 0.93rem; }
  .prompt-grid { grid-template-columns: 1fr; }
  .scroll-rail { right: 0.65rem; bottom: 0.65rem; gap: 0.2rem; padding: 0.25rem; border-radius: 0.82rem; }
  .scroll-rail-button { width: 2.6rem; min-width: 2.6rem; min-height: 2.6rem; padding: 0; }
  .scroll-rail-button > span:last-child { display: none; }
}

@media (max-width: 420px) {
  .model-select-label select { max-width: 7.4rem; padding-left: 0.55rem; font-size: 0.76rem; }
  .conversation-heading span { display: none; }
  .composer-actions { align-items: flex-end; }
  .toggle { padding-inline: 0.44rem; font-size: 0.71rem; }
  .send-button { min-width: 3.4rem; }
  .send-arrow { display: none; }
}
