:root {
  --bg: #f5f4ef;
  --panel: #ffffff;
  --panel-2: #ecebe5;
  --text: #1d201d;
  --muted: #70756f;
  --line: #dcded8;
  --accent: #176b4d;
  --accent-2: #0f513a;
  --accent-soft: #dceee6;
  --danger: #a63e3e;
  --shadow: 0 18px 50px rgba(35, 44, 38, .11);
  --code: #17201c;
  --code-text: #e7eee9;
}

[data-theme="dark"] {
  --bg: #121512;
  --panel: #1a1e1b;
  --panel-2: #232824;
  --text: #edf1ed;
  --muted: #9aa39c;
  --line: #333a35;
  --accent: #56b58d;
  --accent-2: #73c9a4;
  --accent-soft: #203d31;
  --danger: #ef8b8b;
  --shadow: 0 18px 50px rgba(0, 0, 0, .3);
  --code: #0d110f;
  --code-text: #dce8e0;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body { font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif; }
button, input, select, textarea { font: inherit; }
button, select { cursor: pointer; }
.hidden { display: none !important; }
.mobile-only { display: none; }

.login-shell { min-height: 100%; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at 15% 10%, var(--accent-soft), transparent 35%), var(--bg); }
.login-card { width: min(420px, 100%); padding: 42px; border: 1px solid var(--line); border-radius: 24px; background: color-mix(in srgb, var(--panel) 94%, transparent); box-shadow: var(--shadow); }
.brand-mark, .welcome-mark, .mini-mark { display: grid; place-items: center; background: var(--accent); color: white; font-family: Georgia, serif; font-weight: 700; }
.brand-mark { width: 52px; height: 52px; border-radius: 16px; font-size: 28px; }
.eyebrow { margin: 26px 0 6px; color: var(--accent); font-size: 11px; letter-spacing: .18em; font-weight: 750; }
.login-card h1 { margin: 0; font-family: Georgia, "Songti SC", serif; font-size: 42px; letter-spacing: -.03em; }
.muted { color: var(--muted); line-height: 1.65; }
.login-card form { margin-top: 28px; display: grid; gap: 18px; }
.login-card label { display: grid; gap: 8px; color: var(--muted); font-size: 13px; }
.login-card input { width: 100%; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); color: var(--text); padding: 13px 14px; outline: none; }
.login-card input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.primary { border: 0; background: var(--accent); color: white; border-radius: 12px; padding: 13px 18px; font-weight: 700; }
.primary:hover { background: var(--accent-2); }
.wide { width: 100%; }
.error { min-height: 20px; margin: 0; color: var(--danger); font-size: 13px; }

.app-shell { height: 100%; display: grid; grid-template-columns: 270px minmax(0, 1fr); }
.sidebar { min-width: 0; background: var(--panel-2); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 16px 12px 12px; z-index: 20; }
.sidebar-head { display: flex; align-items: center; justify-content: space-between; padding: 3px 8px 15px; }
.wordmark { display: flex; align-items: center; gap: 10px; font-weight: 750; letter-spacing: -.02em; }
.mini-mark { width: 30px; height: 30px; border-radius: 9px; }
.new-chat { width: 100%; padding: 11px 13px; border: 1px solid var(--line); border-radius: 11px; background: var(--panel); color: var(--text); text-align: left; font-weight: 650; }
.chat-list { flex: 1; min-height: 0; overflow: auto; margin: 14px 0; }
.chat-item { width: 100%; display: block; border: 0; background: transparent; color: var(--text); padding: 10px 11px; border-radius: 9px; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin: 2px 0; }
.chat-item:hover, .chat-item.active { background: var(--panel); }
.chat-item small { display: block; color: var(--muted); margin-top: 4px; font-size: 11px; }
.sidebar-foot { display: flex; align-items: center; gap: 8px; padding: 11px 7px 2px; border-top: 1px solid var(--line); color: var(--muted); font-size: 13px; }
.sidebar-foot span { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.quiet, .icon { border: 0; background: transparent; color: var(--muted); padding: 6px; border-radius: 8px; }
.quiet:hover, .icon:hover { background: var(--panel); color: var(--text); }

.workspace-shell { min-width: 0; height: 100%; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; }
.topbar { display: flex; align-items: center; gap: 18px; padding: 12px 22px; border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--panel) 92%, transparent); backdrop-filter: blur(12px); }
.title-wrap { min-width: 150px; flex: 1; display: flex; align-items: center; gap: 12px; }
#chat-title { min-width: 0; width: min(330px, 100%); border: 0; background: transparent; color: var(--text); font-weight: 720; outline: none; text-overflow: ellipsis; }
.status { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; white-space: nowrap; }
.status i { width: 7px; height: 7px; border-radius: 50%; background: #8b928c; }
.status.running i { background: var(--accent); animation: pulse 1.3s infinite; }
.status.error i { background: var(--danger); }
@keyframes pulse { 50% { box-shadow: 0 0 0 5px color-mix(in srgb, var(--accent) 12%, transparent); } }
.selectors { display: flex; align-items: end; gap: 8px; }
.selectors label { display: grid; gap: 3px; color: var(--muted); font-size: 10px; }
.selectors select { max-width: 180px; border: 1px solid var(--line); border-radius: 9px; background: var(--panel); color: var(--text); padding: 7px 27px 7px 9px; }

.messages { overflow: auto; padding: 42px max(24px, calc((100% - 880px) / 2)) 26px; scroll-behavior: smooth; }
.welcome { max-width: 720px; margin: 10vh auto 0; text-align: center; }
.welcome-mark { width: 56px; height: 56px; margin: auto; border-radius: 18px; font-size: 28px; }
.welcome h2 { margin: 20px 0 8px; font-family: Georgia, "Songti SC", serif; font-size: clamp(28px, 4vw, 42px); letter-spacing: -.03em; }
.welcome p { color: var(--muted); line-height: 1.7; }
.suggestions { margin-top: 28px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.suggestions button { border: 1px solid var(--line); background: var(--panel); color: var(--text); padding: 14px; border-radius: 13px; text-align: left; line-height: 1.45; }
.suggestions button:hover { border-color: var(--accent); transform: translateY(-1px); }
.message { margin: 0 0 28px; display: grid; grid-template-columns: 34px minmax(0, 1fr); gap: 13px; }
.avatar { width: 32px; height: 32px; border-radius: 10px; display: grid; place-items: center; font-size: 12px; font-weight: 800; background: var(--panel-2); color: var(--muted); }
.message.assistant .avatar { background: var(--accent); color: white; font-family: Georgia, serif; font-size: 18px; }
.message-head { display: flex; gap: 8px; align-items: baseline; margin-bottom: 7px; }
.message-head strong { font-size: 13px; }
.message-head span { color: var(--muted); font-size: 11px; }
.message-body { line-height: 1.72; overflow-wrap: anywhere; }
.message-body p { margin: 0 0 12px; }
.message-body h1, .message-body h2, .message-body h3 { margin: 22px 0 10px; line-height: 1.3; }
.message-body ul, .message-body ol { padding-left: 24px; }
.message-body code { padding: 2px 5px; border-radius: 5px; background: var(--panel-2); font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: .9em; }
.code-wrap { margin: 14px 0; border-radius: 13px; overflow: hidden; background: var(--code); border: 1px solid color-mix(in srgb, var(--line) 60%, transparent); }
.code-head { display: flex; justify-content: space-between; padding: 7px 11px; color: #aeb9b2; background: rgba(255,255,255,.05); font-size: 11px; }
.copy-code { border: 0; background: transparent; color: inherit; }
.code-wrap pre { margin: 0; padding: 15px; overflow: auto; color: var(--code-text); line-height: 1.55; tab-size: 2; }
.code-wrap pre code { padding: 0; background: transparent; color: inherit; }
.event-log { margin-top: 10px; border-left: 2px solid var(--line); padding-left: 12px; color: var(--muted); font-size: 12px; }

.composer { padding: 9px max(24px, calc((100% - 880px) / 2)) 18px; background: linear-gradient(transparent, var(--bg) 20%); }
.safety-note { font-size: 11px; color: var(--muted); margin: 0 7px 7px; }
.safety-note.write { color: #9a6b14; }
.composer-row { display: flex; align-items: flex-end; gap: 10px; border: 1px solid var(--line); border-radius: 18px; background: var(--panel); padding: 10px 10px 10px 16px; box-shadow: 0 8px 30px rgba(25, 35, 29, .07); }
#prompt { flex: 1; min-height: 28px; max-height: 180px; resize: none; border: 0; outline: 0; background: transparent; color: var(--text); line-height: 1.55; padding: 4px 0; }
.send { width: 38px; height: 38px; border-radius: 12px; border: 0; background: var(--accent); color: white; font-size: 22px; font-weight: 700; }
.send:disabled { opacity: .4; cursor: not-allowed; }
.composer-hint { margin: 7px 0 0; color: var(--muted); text-align: center; font-size: 10px; }
.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 15; }

@media (max-width: 1020px) {
  .selectors label span { display: none; }
  .selectors select { max-width: 140px; }
}

@media (max-width: 760px) {
  .mobile-only { display: inline-grid; place-items: center; }
  .app-shell { display: block; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(86vw, 310px); transform: translateX(-105%); transition: transform .2s ease; box-shadow: var(--shadow); }
  .sidebar.open { transform: translateX(0); }
  .workspace-shell { height: 100%; }
  .topbar { padding: 10px 12px; gap: 8px; flex-wrap: wrap; }
  .title-wrap { width: calc(100% - 48px); order: 1; }
  .selectors { order: 2; width: 100%; overflow-x: auto; padding-bottom: 2px; }
  .selectors label { flex: 0 0 auto; }
  .selectors select { max-width: 160px; }
  .messages { padding: 26px 15px 18px; }
  .welcome { margin-top: 5vh; }
  .suggestions { grid-template-columns: 1fr; }
  .message { grid-template-columns: 28px minmax(0, 1fr); gap: 9px; }
  .avatar { width: 28px; height: 28px; border-radius: 8px; }
  .composer { padding: 8px 12px calc(12px + env(safe-area-inset-bottom)); }
  .composer-hint { display: none; }
}

