:root {
  color-scheme: light;
  --bg: #ffffff;
  --sidebar: #f9f9f9;
  --line: #e5e5e5;
  --text: #0d0d0d;
  --muted: #676767;
  --soft: #f4f4f4;
  --accent: #10a37f;
  --accent-dark: #0b7d63;
  --danger: #d64f4f;
  --shadow: 0 18px 60px rgba(0, 0, 0, .10);
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
html, body { width: 100%; min-height: 100%; margin: 0; background: var(--bg); color: var(--text); }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }
.muted { color: var(--muted); font-size: 13px; }

.app-shell { display: grid; grid-template-columns: 260px minmax(0, 1fr); height: 100dvh; overflow: hidden; }
.sidebar { background: var(--sidebar); display: flex; flex-direction: column; min-width: 0; }
.brand-row { display: flex; align-items: center; gap: 11px; min-height: 66px; padding: 13px 14px; }
.brand-row > div:nth-child(2) { display: grid; gap: 2px; min-width: 0; }
.brand-row strong { font-size: 14px; }
.brand-row span { color: var(--muted); font-size: 11px; }
.brand-mark, .hero-mark { display: grid; place-items: center; color: white; background: #161718; font-weight: 750; }
.brand-mark { width: 32px; height: 32px; border-radius: 10px; }
.hero-mark { width: 52px; height: 52px; border-radius: 17px; margin-bottom: 15px; font-size: 22px; box-shadow: 0 10px 25px rgba(0,0,0,.13); }
.new-chat { margin: 3px 9px 12px; padding: 11px 12px; border: 0; border-radius: 9px; text-align: left; background: transparent; color: var(--text); font-weight: 600; }
.new-chat:hover { background: #ececec; }
.history-search { padding: 0 12px 10px; }
.history-search input { width: 100%; border: 1px solid transparent; background: #ececee; border-radius: 9px; padding: 9px 11px; outline: none; }
.history-search input:focus { background: white; border-color: #d0d0d2; }
.section-title { display: flex; align-items: center; justify-content: space-between; padding: 7px 12px; color: var(--muted); font-size: 12px; font-weight: 650; }
.icon-button, .text-button { border: 0; background: transparent; color: var(--muted); }
.icon-button { width: 34px; height: 34px; border-radius: 8px; font-size: 18px; }
.icon-button:hover, .text-button:hover { background: #e8e8e9; color: var(--text); }
.history-list { flex: 1; min-height: 0; overflow: auto; padding: 0 8px 12px; }
.history-item { display: block; width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; border: 0; border-radius: 9px; padding: 9px 10px; background: transparent; text-align: left; color: #34363a; font-size: 13px; }
.history-item:hover { background: #ececee; }
.history-item.active { background: #e2e2e4; color: #111; font-weight: 620; }
.sidebar-footer { border-top: 1px solid var(--line); padding: 11px 13px; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.connection { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 11px; }
.connection i { width: 8px; height: 8px; border-radius: 50%; background: #a4a7ac; }
.connection i.online { background: var(--accent); box-shadow: 0 0 0 3px rgba(16,163,127,.12); }
.connection i.offline { background: var(--danger); }
.text-button { padding: 7px 8px; border-radius: 8px; font-size: 12px; }

.main { position: relative; display: flex; flex-direction: column; min-width: 0; height: 100dvh; }
.topbar { height: 60px; flex: 0 0 auto; display: flex; align-items: center; gap: 12px; padding: 0 18px; background: rgba(255,255,255,.92); backdrop-filter: blur(12px); z-index: 2; }
.model-wrap { display: flex; align-items: center; gap: 8px; min-width: 0; color: var(--muted); font-size: 12px; }
.model-wrap select { max-width: min(390px, 48vw); border: 0; border-radius: 9px; padding: 8px 28px 8px 9px; background: transparent; color: var(--text); font-size: 16px; font-weight: 600; outline: none; }
.model-wrap select:hover { background: var(--soft); }
.topbar-right { margin-left: auto; }
.subscription-pill { display: inline-flex; padding: 7px 10px; border-radius: 999px; background: #ecfaf6; color: var(--accent-dark); font-size: 11px; font-weight: 720; }
.mobile { display: none; }

.welcome { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 30px 22px 178px; text-align: center; }
.eyebrow { margin: 0 0 10px; font-size: 10px; font-weight: 760; letter-spacing: .18em; color: var(--muted); }
.welcome h1 { margin: 0; font-size: clamp(28px, 3vw, 34px); letter-spacing: -.035em; font-weight: 550; }
.welcome > p:not(.eyebrow) { max-width: 610px; margin: 14px 0 0; color: var(--muted); line-height: 1.7; font-size: 14px; }
.quick-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 24px; }
.quick-actions button { border: 1px solid var(--line); background: white; border-radius: 999px; padding: 9px 13px; color: #55585d; font-size: 12px; }
.quick-actions button:hover { border-color: #c6c8ca; color: var(--text); }

.messages { flex: 1; min-width: 0; min-height: 0; overflow-x: hidden; overflow-y: auto; padding: 24px 0 190px; scroll-behavior: smooth; }
.message { display: flex; width: min(100%, 816px); min-width: 0; margin: 0 auto 30px; padding: 0 24px; }
.message-avatar, .message-role { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }
.message-body { min-width: 0; width: 100%; max-width: 100%; }
.message.user .message-body { width: auto; max-width: min(70%, 620px); margin-left: auto; padding: 10px 16px; border-radius: 22px; background: var(--soft); }
.message-content { min-width: 0; max-width: 100%; line-height: 1.75; word-break: break-word; overflow-wrap: anywhere; font-size: 16px; }
.message-content > * { max-width: 100%; }
.message.user .message-content { white-space: pre-wrap; }
.message.assistant .message-content { white-space: normal; }
.message-content a { color: #0b57d0; text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 2px; }
.message-content > :first-child { margin-top: 0; }
.message-content > :last-child { margin-bottom: 0; }
.message-content p { margin: 0 0 1.05em; }
.message-content h1, .message-content h2, .message-content h3, .message-content h4 { line-height: 1.35; letter-spacing: -.018em; }
.message-content h1 { margin: 1.55em 0 .72em; font-size: 1.5em; font-weight: 700; }
.message-content h2 { margin: 1.4em 0 .68em; font-size: 1.28em; font-weight: 700; }
.message-content h3 { margin: 1.25em 0 .6em; font-size: 1.12em; font-weight: 700; }
.message-content h4 { margin: 1.15em 0 .55em; font-size: 1em; font-weight: 700; }
.message-content ul, .message-content ol { margin: .55em 0 1.05em; padding-left: 1.6em; }
.message-content li { margin: .28em 0; padding-left: .15em; }
.message-content li > p { margin: .3em 0; }
.message-content blockquote { margin: 1em 0; padding: .1em 0 .1em 1em; border-left: 3px solid #d0d0d0; color: #404040; }
.message-content blockquote p { margin: .55em 0; }
.message-content hr { height: 1px; margin: 1.7em 0; border: 0; background: var(--line); }
.message-content code { border-radius: 5px; padding: .15em .32em; background: #ececec; font: .88em/1.45 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; }
.code-block { margin: 1.2em 0; overflow: hidden; border: 1px solid #343434; border-radius: 10px; background: #171717; color: #f5f5f5; }
.code-header { display: flex; align-items: center; justify-content: space-between; min-height: 38px; padding: 0 13px; background: #2f2f2f; color: #d5d5d5; font-size: 12px; }
.copy-code { border: 0; padding: 5px 7px; border-radius: 6px; background: transparent; color: #e9e9e9; font-size: 12px; }
.copy-code:hover { background: #474747; }
.code-block pre { margin: 0; padding: 16px; overflow: auto; }
.code-block pre code { display: block; min-width: max-content; padding: 0; border-radius: 0; background: transparent; color: inherit; font-size: 13px; line-height: 1.65; white-space: pre; }
.message-content table { display: block; width: 100%; margin: 1.2em 0; overflow-x: auto; border-spacing: 0; border-collapse: collapse; }
.message-content th, .message-content td { min-width: 110px; padding: 9px 12px; border: 1px solid #d9d9d9; text-align: left; vertical-align: top; }
.message-content th { background: #f7f7f7; font-weight: 650; }
.math-block { max-width: 100%; margin: 1.25em 0; padding: .25em 0; overflow-x: auto; overflow-y: hidden; text-align: center; }
.math-inline { display: inline-block; max-width: 100%; vertical-align: -.12em; }
.citation-badge { display: inline-flex; align-items: center; margin: 0 .12em; padding: 1px 5px; border-radius: 999px; background: #ececec; color: #555; font-size: .72em; font-weight: 650; line-height: 1.5; vertical-align: .22em; cursor: help; }
.image-gallery { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin: 1.2em 0; }
.image-gallery.single { grid-template-columns: minmax(0, 1fr); }
.image-gallery figure { margin: 0; overflow: hidden; border: 1px solid var(--line); border-radius: 14px; background: #f4f4f4; }
.image-gallery img { display: block; width: 100%; height: auto; max-height: 620px; object-fit: contain; }
.message.user .image-gallery { width: min(320px, 70vw); margin: 0 0 .7em; }
.message-actions { min-height: 28px; margin-top: 8px; opacity: 0; transition: opacity .15s ease; }
.message.assistant:hover .message-actions, .message-actions:focus-within { opacity: 1; }
.message-actions button { width: 28px; height: 28px; border: 0; border-radius: 7px; background: transparent; color: #777; font-size: 17px; }
.message-actions button:hover { background: var(--soft); color: #222; }
.message.pending .message-content { color: var(--muted); }
.message.error .message-body, .message.notice .message-body { padding: 12px 14px; border: 1px solid #e3e3e3; border-radius: 12px; background: #f7f7f7; color: #555; }
.message.error .message-body { border-color: #efd0d0; background: #fff7f7; color: #8a3535; }
.thinking { display: inline-flex; gap: 5px; align-items: center; }
.thinking i { width: 5px; height: 5px; border-radius: 50%; background: #999; animation: pulse 1.2s infinite; }
.thinking i:nth-child(2) { animation-delay: .15s; }
.thinking i:nth-child(3) { animation-delay: .3s; }
@keyframes pulse { 0%,70%,100% { opacity: .25; transform: translateY(0); } 35% { opacity: 1; transform: translateY(-2px); } }

.composer-area { position: absolute; left: 0; right: 0; bottom: 0; padding: 22px max(20px, calc((100% - 800px) / 2)) calc(12px + env(safe-area-inset-bottom)); background: linear-gradient(180deg, transparent, white 25%, white); }
.composer { border: 1px solid transparent; border-radius: 26px; background: var(--soft); box-shadow: 0 1px 7px rgba(0,0,0,.08); padding: 13px 13px 10px; }
.composer:focus-within { border-color: #dedede; box-shadow: 0 2px 10px rgba(0,0,0,.10); }
.composer textarea { display: block; width: 100%; max-height: 180px; resize: none; border: 0; outline: 0; padding: 1px 4px 9px; line-height: 1.5; font-size: 15px; background: transparent; }
.composer-bottom { display: flex; align-items: center; min-height: 34px; gap: 9px; }
.attachment-preview { display: flex; gap: 8px; overflow-x: auto; padding: 0 2px 10px; }
.attachment-card { position: relative; flex: 0 0 72px; width: 72px; height: 72px; overflow: visible; border: 1px solid #d6d6d6; border-radius: 12px; background: white; }
.attachment-card img { display: block; width: 100%; height: 100%; border-radius: 11px; object-fit: cover; }
.attachment-card button { position: absolute; top: -7px; right: -7px; display: grid; place-items: center; width: 22px; height: 22px; padding: 0; border: 2px solid white; border-radius: 50%; background: #202020; color: white; line-height: 1; }
.attach-button { display: grid; flex: 0 0 auto; place-items: center; width: 34px; height: 34px; border: 1px solid var(--line); border-radius: 50%; color: #333; background: white; cursor: pointer; font-size: 22px; line-height: 1; }
.attach-button:hover { background: #e9e9e9; }
.attach-button input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.search-toggle { display: inline-flex; align-items: center; }
.search-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.search-toggle span { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 999px; padding: 6px 10px; color: var(--muted); font-size: 12px; font-weight: 620; }
.search-toggle input:checked + span { border-color: #7ec8b5; background: #edfaf7; color: var(--accent-dark); }
.mode-note { color: #9a9da1; font-size: 10px; }
.send-button { margin-left: auto; width: 34px; height: 34px; border: 0; border-radius: 50%; background: #111; color: white; font-size: 20px; line-height: 1; }
.send-button:hover { background: #333; }
.send-button:disabled { background: #bbb; cursor: default; }
.privacy-note { text-align: center; margin: 8px 0 0; color: #a1a3a7; font-size: 10px; }

.login-page { display: grid; place-items: center; min-height: 100dvh; padding: 22px; background: radial-gradient(circle at 50% 0, #f0faf7, white 42%); }
.login-card { width: min(420px, 100%); padding: 36px; border: 1px solid var(--line); border-radius: 24px; background: rgba(255,255,255,.94); box-shadow: var(--shadow); }
.login-card .hero-mark { margin: 0 auto 19px; }
.login-card .eyebrow, .login-card h1, .login-card > p { text-align: center; }
.login-card h1 { margin: 0; font-size: 28px; letter-spacing: -.025em; }
.login-card > p:not(.eyebrow) { margin: 12px 0 24px; color: var(--muted); font-size: 13px; line-height: 1.6; }
.login-card form { display: grid; gap: 9px; }
.login-card label { font-size: 12px; font-weight: 650; }
.login-card input { width: 100%; padding: 12px 13px; border: 1px solid #d3d4d6; border-radius: 11px; outline: none; }
.login-card input:focus { border-color: #8c8f92; box-shadow: 0 0 0 3px rgba(16,163,127,.1); }
.login-button { margin-top: 5px; border: 0; border-radius: 11px; padding: 12px; background: #151617; color: white; font-weight: 700; }
.login-button:disabled { opacity: .55; }
.form-error { min-height: 18px; margin: 0; color: var(--danger); text-align: center; font-size: 12px; }
.toast { position: fixed; left: 50%; bottom: 120px; z-index: 20; transform: translateX(-50%); max-width: min(520px, calc(100vw - 30px)); padding: 10px 14px; border-radius: 10px; color: white; background: rgba(25,26,28,.92); box-shadow: var(--shadow); font-size: 12px; }

@media (max-width: 760px) {
  .app-shell { display: block; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(84vw, 310px); z-index: 10; box-shadow: 14px 0 40px rgba(0,0,0,.16); transform: translateX(-105%); transition: transform .2s ease; }
  .sidebar.open { transform: translateX(0); }
  .mobile { display: inline-grid; place-items: center; }
  .topbar { padding: 0 10px; gap: 6px; }
  .topbar-right { display: none; }
  .model-wrap > span { display: none; }
  .model-wrap select { max-width: calc(100vw - 72px); }
  .messages { padding: 20px 0 190px; }
  .message { padding: 0 14px; }
  .message { margin-bottom: 24px; }
  .message.user .message-body { max-width: 88%; }
  .message-content { font-size: 15px; }
  .message-actions { opacity: 1; }
  .image-gallery { grid-template-columns: minmax(0, 1fr); }
  .composer-area { padding-left: 10px; padding-right: 10px; }
  .mode-note { display: none; }
  .welcome { padding-left: 18px; padding-right: 18px; }
  .welcome h1 { font-size: 30px; }
}
