:root {
  --bg: #f6f7f4;
  --bg-elev: #ffffff;
  --sidebar: #f3f4ef;
  --text: #1c1d1a;
  --muted: #6b7168;
  --border: #e2e4dc;
  --accent: #0d9488;
  --accent-hover: #0f766e;
  --accent-soft: #ccfbf1;
  --user-bg: #0d9488;
  --user-text: #ffffff;
  --assistant-bg: #ffffff;
  --danger: #dc2626;
  --shadow: 0 8px 28px rgba(28, 29, 26, 0.08);
  --radius: 18px;
  --sidebar-w: 280px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --vv-offset: 0px;
}
[data-theme="dark"] {
  --bg: #121311;
  --bg-elev: #1b1c19;
  --sidebar: #181917;
  --text: #eeeee8;
  --muted: #9aa196;
  --border: #2c2e29;
  --accent: #2dd4bf;
  --accent-hover: #5eead4;
  --accent-soft: #134e4a;
  --user-bg: #0f766e;
  --user-text: #f0fdfa;
  --assistant-bg: #232421;
  --danger: #f87171;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}
* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "PingFang SC", "Noto Sans SC", "Hiragino Sans GB", system-ui, sans-serif;
  letter-spacing: 0.01em;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
#app { height: 100%; }
.hidden { display: none !important; }

/* Auth */
.auth-shell {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px calc(24px + var(--safe-bottom));
  background:
    radial-gradient(1200px 500px at 10% -10%, rgba(13, 148, 136, 0.16), transparent 50%),
    var(--bg);
}
.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 32px 28px;
  box-shadow: var(--shadow);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 18px;
}
.brand-mark {
  width: 32px; height: 32px; border-radius: 8px;
  background: #0d9488; color: #fff;
  display: grid; place-items: center;
  font-size: 13px; font-weight: 700;
  flex-shrink: 0;
}
.auth-card h1 { font-size: 22px; margin: 20px 0 6px; font-weight: 650; }
.auth-lead { color: var(--muted); margin: 0 0 22px; font-size: 14px; line-height: 1.55; }
.tabs { display: flex; background: var(--sidebar); border-radius: 12px; padding: 4px; margin-bottom: 18px; }
.tabs button {
  flex: 1; border: 0; background: transparent; border-radius: 9px;
  padding: 10px 8px; color: var(--muted); min-height: 44px;
}
.tabs button.active { background: var(--bg-elev); color: var(--text); font-weight: 600; box-shadow: 0 1px 4px rgba(0,0,0,.06); }
label { display: block; font-size: 13px; margin: 0 0 6px; color: var(--muted); }
.field { margin-bottom: 14px; }
input, textarea, select {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 12px;
  padding: 12px 14px;
  outline: none;
  min-height: 44px;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.btn {
  border: 0; border-radius: 12px; min-height: 44px; padding: 0 16px;
  background: var(--accent); color: #fff; font-weight: 600;
}
.btn:hover { background: var(--accent-hover); }
.btn:disabled { opacity: 0.6; cursor: default; }
.btn-block { width: 100%; margin-top: 6px; }
.btn-ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--sidebar); }
.btn-icon {
  width: 40px; height: 40px; min-height: 40px; padding: 0;
  display: grid; place-items: center; border: 0; border-radius: 10px;
  background: transparent; color: var(--text);
}
.btn-icon:hover { background: var(--accent-soft); }
.error { color: var(--danger); font-size: 13px; min-height: 18px; margin: 0 0 8px; }

/* Shell */
.shell { display: flex; height: 100%; overflow: hidden; }
.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  flex-shrink: 0;
}
.sidebar-top { padding: 16px 14px 10px; display: flex; align-items: center; gap: 8px; }
.sidebar-top .brand { flex: 1; }
.sidebar-actions { padding: 0 14px 12px; }
.sidebar-actions .btn { width: 100%; }
.conv-list { flex: 1; overflow-y: auto; padding: 4px 10px 12px; }
.conv-item {
  display: flex; align-items: center; gap: 6px;
  border-radius: 12px; padding: 8px 8px 8px 12px;
  margin-bottom: 2px; cursor: pointer;
}
.conv-item:hover { background: var(--bg-elev); }
.conv-item.active { background: var(--bg-elev); font-weight: 600; }
.conv-item .meta { flex: 1; min-width: 0; }
.conv-item .title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.conv-item .time { color: var(--muted); font-size: 11px; margin-top: 2px; }
.conv-item .ops { display: none; }
.conv-item:hover .ops, .conv-item.active .ops { display: flex; }
.sidebar-foot {
  border-top: 1px solid var(--border);
  padding: 12px 14px calc(12px + var(--safe-bottom));
  display: flex; align-items: center; gap: 8px;
}
.user-chip { flex: 1; min-width: 0; font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--bg); }
.topbar {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 16px;
  border-bottom: 1px solid transparent;
  min-height: 56px;
}
.menu-btn { display: none; }
.model-select {
  min-width: 0; max-width: 360px; width: auto;
  background: var(--bg-elev); border-radius: 999px; padding: 8px 14px; min-height: 40px;
}
.messages {
  flex: 1; overflow-y: auto;
  padding: 8px 16px 16px;
}
.messages-inner { max-width: 820px; margin: 0 auto; }
.empty-state {
  height: 100%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; color: var(--muted); padding: 32px 16px;
}
.empty-state h2 { color: var(--text); font-weight: 650; margin: 0 0 8px; font-size: 24px; }
.row { display: flex; margin: 14px 0; }
.row.user { justify-content: flex-end; }
.bubble {
  max-width: min(78%, 680px);
  border-radius: var(--radius);
  padding: 12px 16px;
  line-height: 1.65;
  font-size: 15px;
  overflow-wrap: anywhere;
}
.row.user .bubble { background: var(--user-bg); color: var(--user-text); border-bottom-right-radius: 6px; }
.row.assistant .bubble { background: var(--assistant-bg); border: 1px solid var(--border); border-bottom-left-radius: 6px; }
.bubble p { margin: 0 0 0.7em; }
.bubble p:last-child { margin-bottom: 0; }
.bubble pre {
  background: #111213; color: #e5e7eb; border-radius: 12px;
  padding: 12px 14px; overflow-x: auto; font-size: 13px; line-height: 1.5;
}
.bubble code { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 0.92em; }
.bubble :not(pre) > code { background: var(--accent-soft); padding: 1px 5px; border-radius: 5px; }
.bubble ul, .bubble ol { margin: 0.4em 0 0.8em; padding-left: 1.3em; }
.typing { display: inline-flex; gap: 5px; padding: 4px 0; }
.typing i {
  width: 6px; height: 6px; border-radius: 50%; background: var(--muted);
  animation: blink 1.2s infinite ease-in-out;
}
.typing i:nth-child(2) { animation-delay: .15s; }
.typing i:nth-child(3) { animation-delay: .3s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25 } 40% { opacity: 1 } }

.composer {
  padding: 8px 16px calc(16px + var(--safe-bottom) + var(--vv-offset));
}
.composer-inner {
  max-width: 820px; margin: 0 auto;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 8px 8px 8px 16px;
  display: flex; align-items: flex-end; gap: 8px;
  box-shadow: var(--shadow);
}
.composer textarea {
  border: 0; background: transparent; resize: none;
  min-height: 44px; max-height: 180px; padding: 10px 0; box-shadow: none;
  line-height: 1.5;
}
.composer textarea:focus { box-shadow: none; }
.send-btn {
  width: 44px; height: 44px; border: 0; border-radius: 50%;
  background: var(--accent); color: #fff; display: grid; place-items: center; flex-shrink: 0;
}
.send-btn:disabled { opacity: 0.45; }
.hint { text-align: center; color: var(--muted); font-size: 11px; margin: 8px 0 0; }

.backdrop {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 20;
}

@media (max-width: 800px) {
  .menu-btn { display: grid; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 30;
    width: min(86vw, 320px);
    transform: translateX(-105%);
    transition: transform .2s ease;
    box-shadow: var(--shadow);
  }
  .sidebar.open { transform: translateX(0); }
  .backdrop.show { display: block; }
  .bubble { max-width: 88%; }
  .topbar { padding-left: 8px; }
  .composer { padding-left: 10px; padding-right: 10px; }
  .conv-item .ops { display: flex; }
}

@media (min-width: 1200px) {
  .messages-inner, .composer-inner { max-width: 860px; }
}
.sidebar-top #close-sidebar { display: none; }
.sidebar-actions .btn, .send-btn, .auth-card .btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
@media (max-width: 800px) {
  .sidebar-top #close-sidebar { display: grid; }
}
