*,*::before,*::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --sidebar-w: 300px;
  --header-h: 56px;
  --radius: 14px;
  --radius-sm: 10px;
  --transition: .22s cubic-bezier(.4,0,.2,1);

  --bg: #f2f3f7;
  --bg-chat: #eceef2;
  --surface: #ffffff;
  --surface-hover: #f5f6f8;
  --surface-active: #edeef1;
  --border: rgba(0,0,0,.06);
  --border-subtle: rgba(0,0,0,.04);
  --text: #1a1a1e;
  --text-secondary: #5c5c66;
  --text-muted: #9c9ca6;
  --accent: #10b981;
  --accent-hover: #059669;
  --accent-subtle: rgba(16,185,129,.08);
  --user-bubble: linear-gradient(135deg, #10b981, #0d9668);
  --user-bubble-flat: #10b981;
  --user-bubble-text: #fff;
  --assistant-bubble: #ffffff;
  --assistant-border: rgba(0,0,0,.06);
  --error-bg: #fef2f2;
  --error-text: #dc2626;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.04), 0 1px 2px rgba(0,0,0,.03);
  --shadow-md: 0 4px 16px rgba(0,0,0,.06), 0 1px 3px rgba(0,0,0,.04);
  --shadow-lg: 0 12px 40px rgba(0,0,0,.1), 0 4px 12px rgba(0,0,0,.05);
  --glass: rgba(255,255,255,.72);
  --glass-border: rgba(255,255,255,.5);
  --glass-blur: blur(20px) saturate(180%);
  --scrollbar: rgba(0,0,0,.12);
  --scrollbar-hover: rgba(0,0,0,.22);
  --badge-bg: rgba(0,0,0,.04);
  --badge-border: rgba(0,0,0,.06);
  --code-bg: rgba(0,0,0,.04);
  --code-color: #c026d3;
  --codeblock-bg: #1e1e2e;
  --codeblock-text: #cdd6f4;
  --quote-bg: rgba(16,185,129,.05);
}

[data-theme="dark"] {
  --bg: #0f0f11;
  --bg-chat: #131316;
  --surface: #1a1a1e;
  --surface-hover: #222226;
  --surface-active: #2a2a2e;
  --border: rgba(255,255,255,.07);
  --border-subtle: rgba(255,255,255,.04);
  --text: #ededf0;
  --text-secondary: #9c9ca6;
  --text-muted: #5c5c66;
  --accent: #34d399;
  --accent-hover: #10b981;
  --accent-subtle: rgba(52,211,153,.1);
  --user-bubble: linear-gradient(135deg, #10b981, #059669);
  --user-bubble-flat: #10b981;
  --assistant-bubble: #1e1e22;
  --assistant-border: rgba(255,255,255,.06);
  --error-bg: rgba(220,38,38,.1);
  --error-text: #f87171;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.2);
  --shadow-md: 0 4px 16px rgba(0,0,0,.3);
  --shadow-lg: 0 12px 40px rgba(0,0,0,.4);
  --glass: rgba(26,26,30,.78);
  --glass-border: rgba(255,255,255,.08);
  --glass-blur: blur(20px) saturate(150%);
  --scrollbar: rgba(255,255,255,.1);
  --scrollbar-hover: rgba(255,255,255,.2);
  --badge-bg: rgba(255,255,255,.05);
  --badge-border: rgba(255,255,255,.07);
  --code-bg: rgba(255,255,255,.06);
  --code-color: #e879f9;
  --codeblock-bg: #0c0c0f;
  --codeblock-text: #e4e4e7;
  --quote-bg: rgba(52,211,153,.06);
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  transition: background .3s, color .3s;
}

#app {
  display: flex;
  height: 100dvh;
  width: 100vw;
}

::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--scrollbar); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: var(--scrollbar-hover); }

/* ===== Sidebar ===== */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--glass);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-right: 1px solid var(--glass-border);
  transition: transform var(--transition);
  z-index: 100;
}

.sidebar-header {
  padding: 20px 20px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sidebar-header-left { flex: 1; }

.logo {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -.02em;
  background: linear-gradient(135deg, var(--accent), #0891b2);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.slogan {
  margin-top: 2px;
  font-size: 12px;
  color: var(--text-muted);
}

.theme-toggle {
  width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  flex-shrink: 0;
}

.theme-toggle:hover { background: var(--surface-hover); color: var(--text); }
.theme-toggle:active { transform: scale(.92); }

.persona-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.contacts-header {
  background: var(--glass);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  padding: 10px 12px 8px;
  position: sticky;
  top: 0;
  z-index: 5;
  border-bottom: 1px solid var(--border);
}

.search-box {
  display: flex;
  align-items: center;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0 10px;
  height: 36px;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.search-box:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}

.search-icon { font-size: 13px; margin-right: 8px; opacity: 0.4; }

.search-input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-size: 13px;
  height: 36px;
  font-family: inherit;
  color: var(--text);
}

.search-input::placeholder { color: var(--text-muted); }

.contacts-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 8px;
  padding-left: 2px;
}

.contacts-body { flex: 1; overflow-y: auto; }

.sidebar-tools {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--glass);
}

.sidebar-tool {
  width: 100%;
  height: 38px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: all var(--transition);
}

.sidebar-tool:hover {
  border-color: var(--accent);
  background: var(--accent-subtle);
}

.sidebar-tool-icon {
  width: 18px;
  height: 18px;
  color: var(--accent);
  flex-shrink: 0;
}

.section-title {
  display: flex;
  align-items: center;
  padding: 10px 16px 6px;
  font-size: 11px;
  color: var(--text-muted);
  background: var(--bg);
  font-weight: 600;
  letter-spacing: .04em;
}

.section-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  margin-right: 8px;
  flex-shrink: 0;
}

.section-count {
  margin-left: 6px;
  font-size: 10px;
  color: var(--text-muted);
  font-weight: 400;
  opacity: .5;
}

.section-list { background: var(--surface); }

.contact-item {
  display: flex;
  align-items: center;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border-subtle);
  cursor: pointer;
  transition: background var(--transition);
}

.contact-item:hover { background: var(--surface-hover); }
.contact-item:active { background: var(--surface-active); }
.contact-item.active { background: var(--accent-subtle); }

.contact-item .avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 600;
  font-size: 16px;
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
}

.contact-body { flex: 1; margin-left: 12px; overflow: hidden; min-width: 0; }

.contact-row { display: flex; align-items: center; gap: 8px; }

.contact-name { font-size: 14px; font-weight: 500; color: var(--text); }

.contact-badge {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--badge-bg);
  border: 1px solid var(--badge-border);
  flex-shrink: 0;
}

.contact-tagline {
  display: block;
  font-size: 12px;
  color: var(--accent);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.contact-summary {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-size: 12px;
  line-height: 1.45;
  color: var(--text-muted);
  margin-top: 3px;
}

.contact-arrow { font-size: 16px; color: var(--text-muted); margin-left: 8px; flex-shrink: 0; opacity: .3; }

.avatar.avatar-emoji { font-size: 1.15em; }
.avatar.avatar-multi { font-size: .78em; letter-spacing: .5px; }
.profile-avatar-lg.avatar-emoji { font-size: 34px; }
.profile-avatar-lg.avatar-multi { font-size: 22px; letter-spacing: 1px; }

/* ===== Overlay (mobile) ===== */
.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.3);
  backdrop-filter: blur(8px);
  z-index: 90;
  opacity: 0;
  transition: opacity var(--transition);
}
.overlay.show { display: block; opacity: 1; }

/* ===== Main Chat ===== */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg-chat);
  position: relative;
}

.chat-header {
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  background: var(--glass);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-bottom: 1px solid var(--glass-border);
  flex-shrink: 0;
  z-index: 10;
}

.menu-btn {
  display: none;
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  transition: background var(--transition);
}
.menu-btn:hover { background: var(--surface-hover); }

.header-persona { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; }

.header-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 600;
  font-size: 14px;
  flex-shrink: 0;
  background: linear-gradient(145deg, #71717a, #a1a1aa);
  box-shadow: var(--shadow-sm);
}

.header-info { display: flex; flex-direction: column; min-width: 0; }
.header-name { font-size: 14px; font-weight: 600; color: var(--text); }
.header-tagline { font-size: 11px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.clear-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
  transition: all var(--transition);
  flex-shrink: 0;
}
.clear-btn:hover { background: var(--error-bg); color: var(--error-text); }

/* ===== Message Area ===== */
.msg-area {
  flex: 1;
  overflow-y: auto;
  padding: 24px 24px 0;
  scroll-behavior: smooth;
}

.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
  animation: fadeUp .5s ease-out;
}

.welcome-icon {
  width: 60px;
  height: 60px;
  border-radius: 16px;
  background: linear-gradient(135deg, #10b981, #0891b2);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 28px;
  margin-bottom: 16px;
  box-shadow: 0 8px 24px rgba(16,185,129,.25);
}
.welcome h2 {
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -.02em;
}
.welcome p { color: var(--text-secondary); font-size: 15px; margin-top: 6px; }
.welcome-sub { color: var(--text-muted) !important; font-size: 13px !important; margin-top: 20px !important; }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.samples { padding: 16px 0 24px; animation: fadeUp .35s ease-out; }
.samples-hint { text-align: center; font-size: 12px; color: var(--text-muted); margin-bottom: 14px; }

.samples-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 8px;
  max-width: 620px;
  margin: 0 auto;
}

.sample-chip {
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
  line-height: 1.5;
  box-shadow: var(--shadow-sm);
}

.sample-chip:hover {
  border-color: var(--accent);
  color: var(--text);
  background: var(--accent-subtle);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.sample-chip:active { transform: translateY(0) scale(.98); }

/* Messages */
.msg-list { max-width: 760px; margin: 0 auto; width: 100%; }

.msg-row {
  display: flex;
  align-items: flex-start;
  margin-bottom: 18px;
  gap: 10px;
  animation: msgIn .25s ease-out;
}

@keyframes msgIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.msg-user { flex-direction: row-reverse; }

.avatar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 600;
  border-radius: 50%;
}

.avatar-sm { width: 34px; height: 34px; font-size: 13px; }

.bubble-col {
  flex: 1;
  min-width: 0;
  max-width: calc(100% - 48px);
  display: flex;
  flex-direction: column;
}

.bubble-col-user {
  flex: none;
  max-width: 75%;
  align-items: flex-end;
}

.bubble {
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 14px;
  line-height: 1.7;
  word-break: break-word;
  max-width: 100%;
  position: relative;
}

.bubble-user {
  background: var(--user-bubble);
  color: var(--user-bubble-text);
  border-bottom-right-radius: 4px;
  box-shadow: 0 2px 8px rgba(16,185,129,.2);
}

.bubble-assistant {
  background: var(--assistant-bubble);
  color: var(--text);
  border-bottom-left-radius: 4px;
  border: 1px solid var(--assistant-border);
  box-shadow: var(--shadow-sm);
}

.copy-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 11px;
  border-radius: 4px;
  cursor: pointer;
  transition: all var(--transition);
  font-family: inherit;
}

.copy-btn:hover { background: var(--badge-bg); color: var(--accent); }
.copy-btn svg { flex-shrink: 0; }

.bubble-meta { display: flex; align-items: center; gap: 4px; margin-top: 4px; flex-wrap: wrap; }

.token-stats {
  font-size: 10px;
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  color: var(--text-muted);
  opacity: 0.7;
  white-space: nowrap;
  padding: 3px 6px;
  user-select: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  letter-spacing: 0.02em;
}

.token-stats .ts-up { color: #3b82f6; }
.token-stats .ts-down { color: #10b981; }
.token-stats .ts-cache { color: #f59e0b; }
.token-stats .ts-ctx { color: var(--text-muted); }

.bubble-error {
  background: var(--error-bg) !important;
  color: var(--error-text) !important;
  border-color: transparent !important;
}

.plain-text { white-space: pre-wrap; }

/* Markdown inside bubbles */
.md-block + .md-block { margin-top: 8px; }
.md-p { white-space: pre-wrap; }
.md-bold { font-weight: 600; color: var(--text); }
.md-italic { font-style: italic; color: var(--text-secondary); }
.md-h { font-weight: 700; color: var(--text); line-height: 1.4; }
.md-h1 { font-size: 17px; margin-bottom: 6px; }
.md-h2 { font-size: 15px; margin-bottom: 4px; }
.md-h3 { font-size: 14px; margin-bottom: 3px; }
.md-hr { height: 1px; background: var(--border); margin: 12px 0; }

.md-li { display: flex; align-items: flex-start; margin-top: 5px; }
.md-li-dot { flex-shrink: 0; width: 16px; color: var(--text-muted); line-height: 1.7; }
.md-li-body { flex: 1; min-width: 0; white-space: pre-wrap; }
.md-li-num { width: auto; min-width: 16px; margin-right: 4px; color: var(--accent); font-weight: 500; }
.md-li-indent1 { padding-left: 16px; }
.md-li-indent2 { padding-left: 32px; }
.md-li-indent3 { padding-left: 48px; }

.md-code {
  font-family: "SF Mono", "Fira Code", Menlo, Consolas, monospace;
  font-size: 12px;
  background: var(--code-bg);
  color: var(--code-color);
  padding: 2px 6px;
  border-radius: 4px;
}

.md-link {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-color: rgba(16,185,129,.3);
  text-underline-offset: 2px;
}

.md-codeblock {
  margin: 8px 0;
  padding: 14px 16px;
  background: var(--codeblock-bg);
  border-radius: var(--radius-sm);
  overflow-x: auto;
}

.md-codeblock-text {
  display: block;
  font-family: "SF Mono", "Fira Code", Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.6;
  color: var(--codeblock-text);
  white-space: pre;
}

.md-quote {
  padding: 10px 14px;
  margin: 6px 0;
  background: var(--quote-bg);
  border-left: 3px solid var(--accent);
  border-radius: 4px;
  white-space: pre-wrap;
  color: var(--text-secondary);
}

.md-table-cards { margin: 8px 0; }
.md-table-card {
  background: var(--badge-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-bottom: 8px;
}
.md-table-card:last-child { margin-bottom: 0; }
.md-table-kv + .md-table-kv { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--border-subtle); }
.md-table-label { font-size: 11px; color: var(--text-muted); font-weight: 500; margin-bottom: 2px; }
.md-table-value { font-size: 13px; color: var(--text); line-height: 1.55; white-space: pre-wrap; }

/* Stream / Typing */
.stream-row, .typing-row { max-width: 760px; margin: 0 auto 18px; width: 100%; }
.bubble-stream { position: relative; }
.md-stream { white-space: normal; }
.stream-cursor { color: var(--accent); animation: blink 1s infinite; font-weight: 700; display: inline; }

.bubble-typing { display: flex; align-items: center; gap: 3px; padding: 10px 16px; }
.typing-label { font-size: 12px; color: var(--text-muted); margin-right: 4px; }
.dot { animation: blink 1.2s infinite; font-size: 20px; line-height: 1; color: var(--text-muted); }
.dot:nth-of-type(2) { animation-delay: .2s; }
.dot:nth-of-type(3) { animation-delay: .4s; }

@keyframes blink {
  0%, 80%, 100% { opacity: .2; }
  40% { opacity: 1; }
}

.scroll-bottom { height: 20px; }

/* ===== Input Bar ===== */
.input-bar {
  padding: 12px 24px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  background: var(--bg-chat);
  flex-shrink: 0;
}

.input-wrap {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  max-width: 760px;
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px 8px 16px;
  box-shadow: var(--shadow-md);
  transition: border-color var(--transition), box-shadow var(--transition);
}

.input-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-subtle), var(--shadow-md);
}

.input-field {
  flex: 1;
  border: none;
  outline: none;
  font-size: 14px;
  line-height: 1.5;
  resize: none;
  max-height: 120px;
  background: transparent;
  color: var(--text);
  font-family: inherit;
}

.input-field::placeholder { color: var(--text-muted); }

.send-btn {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: var(--surface-active);
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all var(--transition);
}

.send-btn:not(:disabled) {
  background: var(--user-bubble);
  color: #fff;
  box-shadow: 0 2px 8px rgba(16,185,129,.25);
}

.send-btn:not(:disabled):hover { filter: brightness(1.1); }
.send-btn:not(:disabled):active { transform: scale(.92); }
.send-btn:disabled { cursor: not-allowed; opacity: .4; }

/* ===== Confirm Dialog ===== */
.dialog-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.3);
  backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  animation: fadeIn .15s ease-out;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.dialog {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 28px 20px;
  min-width: 300px;
  max-width: 380px;
  box-shadow: var(--shadow-lg);
  animation: scaleIn .2s ease-out;
}

@keyframes scaleIn {
  from { opacity: 0; transform: scale(.95); }
  to { opacity: 1; transform: scale(1); }
}

.dialog h3 { font-size: 16px; font-weight: 600; margin-bottom: 6px; }
.dialog p { font-size: 13px; color: var(--text-secondary); margin-bottom: 20px; }

.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
.dialog-actions button {
  padding: 7px 18px;
  border-radius: 8px;
  border: none;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-cancel {
  background: var(--surface-hover);
  color: var(--text-secondary);
  border: 1px solid var(--border) !important;
}
.btn-cancel:hover { background: var(--surface-active); }

.btn-danger { background: #dc2626; color: #fff; }
.btn-danger:hover { background: #b91c1c; }

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  background: var(--glass);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  color: var(--text);
  padding: 8px 20px;
  border-radius: 20px;
  font-size: 13px;
  z-index: 300;
  opacity: 0;
  transition: all .25s ease;
  pointer-events: none;
  box-shadow: var(--shadow-md);
}

.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ===== Profile Panel ===== */
.profile-panel {
  position: absolute;
  inset: var(--header-h) 0 0 0;
  background: var(--bg-chat);
  z-index: 50;
  animation: slideUp .25s ease-out;
  overflow: hidden;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

.profile-panel-scroll { height: 100%; overflow-y: auto; padding: 24px; padding-bottom: 100px; }

.profile-close-btn {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 34px;
  height: 34px;
  border: 1px solid var(--border);
  background: var(--glass);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
  z-index: 5;
}

.profile-close-btn:hover { background: var(--surface-hover); color: var(--text); }

.profile-card {
  max-width: 560px;
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  text-align: center;
  box-shadow: var(--shadow-sm);
}

.profile-avatar-lg {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 28px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-md);
}

.profile-name-row { display: flex; align-items: center; justify-content: center; gap: 8px; margin-bottom: 4px; }
.profile-persona-name { font-size: 20px; font-weight: 700; color: var(--text); }
.profile-badge { font-size: 11px; font-weight: 500; padding: 2px 8px; border-radius: 4px; color: #fff; }
.profile-fullname { font-size: 13px; color: var(--text-secondary); margin-bottom: 2px; }
.profile-lifetime { font-size: 12px; color: var(--text-muted); display: block; margin-bottom: 10px; }
.profile-title { font-size: 13px; color: var(--text-secondary); font-weight: 500; margin-bottom: 14px; display: block; }

.profile-tags { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.profile-tag {
  font-size: 11px;
  font-weight: 500;
  padding: 3px 10px;
  border-radius: 6px;
  background: var(--badge-bg);
  border: 1px solid var(--badge-border);
}

.profile-sections { max-width: 560px; margin: 14px auto 0; }

.profile-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-top: 10px;
  box-shadow: var(--shadow-sm);
}

.profile-section-header { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.profile-section-icon { font-size: 16px; }
.profile-section-label { font-size: 13px; font-weight: 600; color: var(--text); }
.profile-bio { font-size: 13px; line-height: 1.8; color: var(--text-secondary); }

.profile-achievement-item { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 8px; }
.profile-achievement-item:last-child { margin-bottom: 0; }
.profile-achievement-dot { width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; margin-top: 7px; }
.profile-achievement-text { font-size: 13px; color: var(--text-secondary); line-height: 1.6; }

.profile-philosophy-item { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 10px; }
.profile-philosophy-item:last-child { margin-bottom: 0; }
.profile-quote-bar { width: 3px; min-height: 18px; border-radius: 2px; flex-shrink: 0; align-self: stretch; }
.profile-philosophy-text { font-size: 13px; color: var(--text-secondary); line-height: 1.7; font-style: italic; }

.profile-sample-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--badge-bg);
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
  cursor: pointer;
  transition: all var(--transition);
  border: 1px solid transparent;
}
.profile-sample-item:last-child { margin-bottom: 0; }
.profile-sample-item:hover { border-color: var(--accent); background: var(--accent-subtle); }
.profile-sample-text { font-size: 13px; color: var(--text-secondary); flex: 1; }
.profile-sample-arrow { color: var(--text-muted); font-size: 16px; margin-left: 8px; }

.profile-bottom { max-width: 560px; margin: 16px auto 0; text-align: center; }
.profile-chat-btn {
  width: 100%;
  padding: 12px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--user-bubble);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  box-shadow: 0 2px 8px rgba(16,185,129,.2);
}
.profile-chat-btn:hover { filter: brightness(1.1); }
.profile-chat-btn:active { transform: scale(.98); }

.header-info[role="button"] {
  cursor: pointer;
  border-radius: 6px;
  padding: 4px 8px;
  margin: -4px -8px;
  transition: background var(--transition);
}
.header-info[role="button"]:hover { background: var(--surface-hover); }

/* ===== Mobile TabBar ===== */
.tab-bar {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(50px + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--glass);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-top: 1px solid var(--glass-border);
  z-index: 200;
  justify-content: space-around;
  align-items: center;
}

.tab-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 0;
  font-size: 10px;
  color: var(--text-muted);
  cursor: pointer;
  transition: color .2s;
  -webkit-tap-highlight-color: transparent;
}

.tab-item.active { color: var(--accent); }
.tab-icon { width: 22px; height: 22px; }

/* ===== Tab Pages ===== */
.tab-page {
  display: none;
  position: fixed;
  inset: 0;
  bottom: calc(50px + env(safe-area-inset-bottom));
  background: var(--bg);
  z-index: 150;
  flex-direction: column;
  overflow: hidden;
}

.page-header {
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--glass);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-bottom: 1px solid var(--glass-border);
  font-size: 16px;
  font-weight: 600;
  flex-shrink: 0;
}

.conv-list { flex: 1; overflow-y: auto; }

.conv-item {
  display: flex;
  align-items: flex-start;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border-subtle);
  cursor: pointer;
  transition: background .15s;
}
.conv-item:active { background: var(--surface-hover); }
.conv-item .avatar { margin-top: 1px; }

.conv-body { flex: 1; margin-left: 12px; overflow: hidden; min-width: 0; }
.conv-top { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 3px; }
.conv-name-row { display: flex; align-items: center; gap: 6px; min-width: 0; }
.conv-name { font-size: 14px; font-weight: 500; }
.conv-group { font-size: 10px; padding: 1px 5px; border-radius: 3px; background: var(--badge-bg); flex-shrink: 0; }
.conv-time { font-size: 11px; color: var(--text-muted); flex-shrink: 0; margin-left: 8px; margin-top: 2px; }
.conv-preview { font-size: 12px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; line-height: 1.4; }
.conv-pending { color: var(--accent); }

.empty-state { padding: 80px 32px; text-align: center; }
.empty-icon { font-size: 36px; margin-bottom: 12px; opacity: .5; }
.empty-title { font-size: 16px; color: var(--text); margin-bottom: 6px; font-weight: 500; }
.empty-desc { font-size: 13px; color: var(--text-muted); line-height: 1.6; }

.btn-primary {
  margin-top: 20px;
  background: var(--user-bubble);
  color: #fff;
  font-size: 13px;
  border: none;
  border-radius: 8px;
  padding: 9px 32px;
  cursor: pointer;
  font-family: inherit;
  font-weight: 500;
  transition: all var(--transition);
  box-shadow: 0 2px 8px rgba(16,185,129,.2);
}
.btn-primary:hover { filter: brightness(1.1); }
.btn-primary:active { transform: scale(.97); }

.mobile-contacts { flex: 1; overflow-y: auto; }

/* Me page */
.me-content { flex: 1; overflow-y: auto; }
.me-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px 0 24px;
  background: var(--surface);
  margin-bottom: 10px;
}

.me-avatar {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  background: linear-gradient(135deg, #10b981, #0891b2);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 24px;
  box-shadow: 0 6px 20px rgba(16,185,129,.25);
}

.me-name { font-size: 18px; font-weight: 600; margin-top: 10px; }
.me-desc { font-size: 13px; color: var(--text-muted); margin-top: 3px; }

.me-card { background: var(--surface); margin-bottom: 10px; }
.me-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-subtle);
  font-size: 14px;
  cursor: pointer;
  transition: background .15s;
}
.me-row:last-child { border-bottom: none; }
.me-row:active { background: var(--surface-hover); }

.me-row-label { color: var(--text-secondary); flex-shrink: 0; margin-right: 12px; }
.me-row-value { color: var(--text); text-align: right; word-break: break-all; font-size: 12px; }
.me-mono { font-family: monospace; }
.me-ok { color: var(--accent); }
.me-err { color: var(--error-text); }
.me-danger { color: var(--error-text); justify-content: center; }

.me-usage-card .me-row { cursor: default; }
.me-usage-card .me-row:active { background: transparent; }

.usage-bar-wrap { height: 4px; background: var(--badge-bg); border-radius: 2px; margin: 0 16px 4px; overflow: hidden; }
.usage-bar { height: 100%; border-radius: 2px; background: var(--accent); transition: width .4s ease; width: 0; }
.usage-bar.warn { background: #f59e0b; }
.usage-bar.danger { background: #ef4444; }
.usage-detail { font-size: 11px; color: var(--text-muted); padding: 0 16px 8px; }

.me-about {
  padding: 24px 16px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 11px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  cursor: pointer;
}
.me-about-hint { font-size: 10px; color: var(--text-muted); opacity: .5; }
.me-dev { margin-top: 0; }

/* ===== WeRead Dashboard ===== */
.weread-panel {
  position: absolute;
  inset: var(--header-h) 0 0 0;
  background: var(--bg);
  z-index: 45;
  overflow: hidden;
}

.weread-mobile { flex: 1; overflow-y: auto; }

.weread-view {
  height: 100%;
  overflow-y: auto;
  padding: 22px;
  color: var(--text);
}

.weread-view-mobile { padding: 12px; }

.weread-topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.weread-kicker {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: .08em;
  text-transform: uppercase;
}

.weread-topbar h2 {
  font-size: 22px;
  line-height: 1.25;
  margin-top: 2px;
  letter-spacing: 0;
}

.weread-topbar p {
  color: var(--text-muted);
  font-size: 13px;
  margin-top: 3px;
}

.weread-actions { display: flex; gap: 8px; }

.weread-text-btn {
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.weread-text-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.weread-icon-btn {
  width: 34px;
  height: 34px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  transition: all var(--transition);
}

.weread-icon-btn:hover { color: var(--accent); border-color: var(--accent); }

.weread-search {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.weread-search-input {
  flex: 1;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  padding: 0 12px;
  outline: none;
  font: inherit;
  font-size: 13px;
}

.weread-search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}

.weread-config {
  width: min(560px, 100%);
  margin-top: 22px;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

.weread-config h3 {
  font-size: 17px;
  line-height: 1.35;
  margin-bottom: 6px;
}

.weread-config p {
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.6;
}

.weread-config-link {
  display: inline-block;
  margin-top: 8px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
}

.weread-config-link:hover {
  text-decoration: underline;
}

.weread-config-form {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

.weread-key-input {
  flex: 1;
  min-width: 0;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--input-bg);
  color: var(--text);
  padding: 0 12px;
  outline: none;
}

.weread-key-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}

.weread-config-form .btn-primary {
  margin-top: 0;
  height: 40px;
  padding: 0 16px;
}

.weread-search .btn-primary {
  margin-top: 0;
  padding: 0 18px;
  height: 38px;
}

.weread-search-results { margin-bottom: 12px; }
.weread-search-group { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 12px; margin-bottom: 8px; }
.weread-search-group-title { font-size: 12px; color: var(--text-muted); margin-bottom: 8px; font-weight: 600; }

.weread-metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.weread-metric {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 13px 14px;
  min-width: 0;
}

.weread-metric span,
.weread-metric small {
  display: block;
  color: var(--text-muted);
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.weread-metric strong {
  display: block;
  font-size: 22px;
  line-height: 1.25;
  margin: 4px 0;
  letter-spacing: 0;
}

.weread-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.weread-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  min-width: 0;
}

.weread-wide { margin-top: 10px; }

.weread-section-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 10px;
}

.weread-section-head h3 {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0;
}

.weread-section-head span {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.weread-book-list,
.weread-rank-list,
.weread-note-list {
  display: grid;
  gap: 7px;
}

.weread-book-card,
.weread-rank,
.weread-note {
  display: flex;
  align-items: center;
  width: 100%;
  min-width: 0;
  border: 1px solid var(--border-subtle);
  background: var(--bg);
  color: var(--text);
  border-radius: 8px;
  padding: 8px;
  cursor: pointer;
  text-align: left;
  font: inherit;
  transition: all var(--transition);
}

.weread-book-card:hover,
.weread-rank:hover,
.weread-note:hover {
  border-color: var(--accent);
  background: var(--accent-subtle);
}

.weread-cover {
  width: 34px;
  height: 46px;
  border-radius: 4px;
  overflow: hidden;
  background: var(--surface-active);
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 12px;
}

.weread-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.weread-cover-lg { width: 62px; height: 84px; }

.weread-book-info {
  min-width: 0;
  margin-left: 10px;
  display: block;
}

.weread-book-title,
.weread-book-meta {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.weread-book-title { font-size: 13px; font-weight: 600; }
.weread-book-meta { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

.weread-rank,
.weread-note {
  gap: 10px;
  height: 38px;
}

.weread-rank span,
.weread-note span {
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  background: var(--surface);
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
}

.weread-rank strong,
.weread-note strong {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.weread-rank em,
.weread-note em {
  font-style: normal;
  font-size: 11px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.weread-bars { display: grid; gap: 9px; }
.weread-bar-row { display: grid; grid-template-columns: 84px 1fr 74px; align-items: center; gap: 8px; font-size: 12px; }
.weread-bar-row span,
.weread-bar-row em { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.weread-bar-row em { font-style: normal; color: var(--text-muted); text-align: right; }
.weread-bar-row div { height: 6px; background: var(--badge-bg); border-radius: 4px; overflow: hidden; }
.weread-bar-row i { display: block; height: 100%; background: var(--accent); border-radius: inherit; }

/* 偏好分类：环形饼图 + 多彩图例 */
.weread-cat { display: flex; align-items: center; gap: 18px; }
.weread-donut-wrap { position: relative; width: 140px; height: 140px; flex-shrink: 0; }
.weread-donut { display: block; }
.weread-donut-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.weread-donut-center strong { font-size: 30px; font-weight: 700; color: var(--text); line-height: 1; }
.weread-donut-center span { margin-top: 3px; font-size: 11px; color: var(--text-muted); }
.weread-legend { flex: 1; min-width: 0; display: grid; gap: 8px; }
.weread-legend-item { display: grid; grid-template-columns: 12px 1fr auto; align-items: center; gap: 9px; font-size: 12px; }
.weread-legend-item i { width: 10px; height: 10px; border-radius: 3px; }
.weread-legend-item span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.weread-legend-item em { font-style: normal; font-weight: 600; color: var(--text); }

.weread-reco-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.weread-reco {
  border: 1px solid var(--border-subtle);
  background: var(--bg);
  border-radius: 8px;
  padding: 8px;
  min-width: 0;
}

.weread-reco .weread-book-card { border: none; background: transparent; padding: 0; }
.weread-reco p { margin-top: 8px; font-size: 11px; color: var(--text-muted); line-height: 1.5; display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

.weread-empty,
.weread-state {
  color: var(--text-muted);
  font-size: 13px;
  padding: 24px;
  text-align: center;
}

.weread-state {
  min-height: 220px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.weread-state-title { color: var(--text); font-size: 15px; font-weight: 700; }
.weread-state-desc { color: var(--error-text); font-size: 12px; max-width: 420px; }
.weread-state-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.weread-state-actions .btn-primary {
  margin-top: 0;
}

.weread-dialog-overlay {
  position: fixed;
  inset: 0;
  z-index: 400;
  background: rgba(0,0,0,.34);
  backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.weread-dialog {
  width: min(860px, 100%);
  max-height: min(760px, 92vh);
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
  padding: 18px;
  position: relative;
}

.weread-dialog-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 30px;
  height: 30px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 18px;
}

.weread-book-hero { display: flex; gap: 14px; align-items: flex-start; padding-right: 36px; }
.weread-book-hero h3 { font-size: 18px; line-height: 1.35; margin-bottom: 4px; }
.weread-book-hero p { font-size: 12px; color: var(--text-muted); margin-bottom: 8px; }
.weread-book-hero a { color: var(--accent); font-size: 12px; }

.weread-detail-metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin: 14px 0;
}

.weread-detail-metrics div {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
}

.weread-detail-metrics span { display: block; color: var(--text-muted); font-size: 11px; }
.weread-detail-metrics strong { display: block; font-size: 16px; margin-top: 2px; }

.weread-dialog-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.weread-dialog-grid h4 { font-size: 14px; margin-bottom: 8px; }
.weread-dialog blockquote {
  margin: 0 0 8px;
  padding: 10px 12px;
  border-left: 3px solid var(--accent);
  background: var(--quote-bg);
  border-radius: 4px;
  font-size: 12px;
  line-height: 1.65;
  color: var(--text-secondary);
}
.weread-dialog blockquote small { display: block; margin-top: 6px; color: var(--text-muted); }

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    transform: translateX(-100%);
    box-shadow: none;
  }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
  .menu-btn { display: flex; }
  .msg-area { padding: 14px 12px 0; }
  .input-bar { padding: 8px 12px; }
  .bubble-col-user { max-width: 85%; }
  .samples-grid { grid-template-columns: 1fr; }
  .profile-panel-scroll { padding: 16px; padding-bottom: 100px; }
  .profile-card { padding: 20px 16px; }
  .profile-section { padding: 14px 16px; }
  .weread-metrics,
  .weread-grid,
  .weread-reco-grid,
  .weread-dialog-grid,
  .weread-detail-metrics {
    grid-template-columns: 1fr;
  }
  .weread-topbar h2 { font-size: 20px; }
  .weread-search { flex-direction: column; }
  .weread-search .btn-primary { width: 100%; }
  .weread-actions { flex-wrap: wrap; justify-content: flex-end; }
  .weread-config-form { flex-direction: column; }
  .weread-config-form .btn-primary { width: 100%; }
  .weread-bar-row { grid-template-columns: 72px 1fr 64px; }
  .weread-dialog-overlay { padding: 10px; align-items: stretch; }
  .weread-dialog { max-height: 100%; }
  .tab-bar { display: flex; }
  .tab-page { flex-direction: column; }
}

@media (min-width: 769px) {
  .menu-btn { display: none; }
  .tab-bar { display: none !important; }
  .tab-page { display: none !important; }
}

/* ===== Taste Redesign: quiet workbench system ===== */
:root {
  --sidebar-w: 316px;
  --header-h: 60px;
  --radius: 12px;
  --radius-sm: 8px;
  --transition: .18s cubic-bezier(.2,0,.2,1);

  --bg: #eef1f4;
  --bg-chat: #f6f7f8;
  --surface: #ffffff;
  --surface-hover: #f3f6f5;
  --surface-active: #e8efec;
  --border: rgba(20,36,31,.1);
  --border-subtle: rgba(20,36,31,.07);
  --text: #17201c;
  --text-secondary: #4f5d57;
  --text-muted: #87938e;
  --accent: #0f766e;
  --accent-hover: #0b5f59;
  --accent-subtle: rgba(15,118,110,.1);
  --user-bubble: #0f766e;
  --user-bubble-flat: #0f766e;
  --assistant-bubble: #ffffff;
  --assistant-border: rgba(20,36,31,.1);
  --error-bg: #fff1f1;
  --error-text: #be2f2f;
  --shadow-sm: 0 1px 2px rgba(20,36,31,.06);
  --shadow-md: 0 10px 28px rgba(20,36,31,.08), 0 2px 6px rgba(20,36,31,.05);
  --shadow-lg: 0 24px 70px rgba(20,36,31,.16), 0 8px 20px rgba(20,36,31,.08);
  --glass: rgba(255,255,255,.9);
  --glass-border: rgba(20,36,31,.08);
  --glass-blur: blur(18px) saturate(135%);
  --badge-bg: rgba(15,118,110,.07);
  --badge-border: rgba(15,118,110,.12);
  --quote-bg: rgba(15,118,110,.07);
  --code-color: #0f766e;
}

[data-theme="dark"] {
  --bg: #101513;
  --bg-chat: #131816;
  --surface: #18201d;
  --surface-hover: #202a26;
  --surface-active: #26322e;
  --border: rgba(230,238,234,.1);
  --border-subtle: rgba(230,238,234,.07);
  --text: #edf3f0;
  --text-secondary: #b6c1bc;
  --text-muted: #7d8984;
  --accent: #5eead4;
  --accent-hover: #2dd4bf;
  --accent-subtle: rgba(94,234,212,.11);
  --user-bubble: #0f766e;
  --assistant-bubble: #18201d;
  --assistant-border: rgba(230,238,234,.1);
  --glass: rgba(24,32,29,.9);
  --glass-border: rgba(230,238,234,.08);
  --badge-bg: rgba(94,234,212,.08);
  --badge-border: rgba(94,234,212,.14);
  --quote-bg: rgba(94,234,212,.08);
  --code-color: #5eead4;
}

body {
  letter-spacing: 0;
  background:
    linear-gradient(180deg, rgba(255,255,255,.55), transparent 220px),
    var(--bg);
}

.sidebar {
  background: var(--glass);
  border-right-color: var(--border);
}

.sidebar-header {
  padding: 22px 22px 16px;
  border-bottom-color: var(--border);
}

.logo {
  color: var(--text);
  background: none;
  -webkit-text-fill-color: currentColor;
  letter-spacing: 0;
}

.slogan {
  color: var(--text-secondary);
  max-width: 18em;
}

.theme-toggle,
.sidebar-tool,
.weread-icon-btn,
.dialog-actions button,
.weread-dialog-close {
  border-radius: var(--radius-sm);
}

.theme-toggle,
.sidebar-tool,
.search-box,
.weread-search-input,
.input-wrap {
  border-color: var(--border);
  box-shadow: none;
}

.sidebar-tool {
  height: 42px;
  background: transparent;
  justify-content: flex-start;
}

.sidebar-tool:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.contacts-header {
  background: var(--glass);
  padding: 12px 14px 10px;
}

.search-box {
  height: 40px;
  border-radius: var(--radius-sm);
  background: var(--surface);
}

.section-title {
  padding: 12px 16px 7px;
  background: transparent;
  letter-spacing: 0;
  text-transform: none;
}

.section-dot {
  border-radius: 2px;
}

.contact-item,
.conv-item {
  padding: 13px 16px;
  background: transparent;
}

.contact-item:hover,
.contact-item.active,
.conv-item:active {
  background: var(--surface);
}

.contact-item .avatar,
.header-avatar,
.avatar-sm,
.me-avatar,
.profile-avatar-lg,
.welcome-icon {
  border-radius: 12px;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.22), var(--shadow-sm);
}

.contact-name,
.conv-name,
.header-name,
.profile-persona-name,
.me-name {
  font-weight: 650;
}

.contact-badge,
.conv-group,
.profile-badge,
.profile-tag {
  border-radius: 6px;
  background: var(--badge-bg);
  border: 1px solid var(--badge-border);
}

.chat-main {
  background:
    linear-gradient(180deg, rgba(255,255,255,.72), transparent 170px),
    var(--bg-chat);
}

.chat-header,
.page-header,
.tab-bar {
  background: var(--glass);
  border-color: var(--border);
}

.msg-area {
  padding-top: 30px;
}

.msg-list,
.stream-row,
.typing-row,
.input-wrap {
  max-width: 820px;
}

.welcome {
  justify-content: flex-start;
  padding-top: min(18vh, 140px);
}

.welcome-icon {
  background: var(--accent);
}

.welcome h2 {
  font-size: 32px;
  letter-spacing: 0;
}

.sample-chip,
.bubble,
.dialog,
.profile-card,
.profile-section,
.weread-section,
.weread-metric,
.weread-reco,
.weread-dialog,
.weread-search-group,
.md-table-card {
  border-radius: var(--radius);
}

.sample-chip {
  box-shadow: none;
}

.sample-chip:hover {
  box-shadow: var(--shadow-sm);
}

.bubble {
  padding: 12px 15px;
}

.bubble-user {
  background: var(--user-bubble);
  border-bottom-right-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
}

.bubble-assistant {
  border-bottom-left-radius: var(--radius-sm);
  box-shadow: none;
}

.copy-btn,
.token-stats {
  border-radius: 6px;
}

.input-bar {
  background: linear-gradient(180deg, transparent, var(--bg-chat) 28%);
  padding-top: 16px;
}

.input-wrap {
  border-radius: 16px;
  padding: 9px 10px 9px 16px;
  box-shadow: 0 12px 36px rgba(20,36,31,.1);
}

.send-btn {
  border-radius: 12px;
  background: var(--surface-active);
}

.send-btn:not(:disabled) {
  background: var(--accent);
  box-shadow: none;
}

.dialog-overlay,
.weread-dialog-overlay {
  background: rgba(16,24,22,.42);
}

.profile-panel,
.weread-panel,
.tab-page {
  background: var(--bg-chat);
}

.profile-panel-scroll {
  padding-top: 30px;
}

.profile-card,
.profile-section,
.me-card,
.weread-section,
.weread-metric,
.weread-reco,
.weread-dialog {
  box-shadow: none;
}

.profile-chat-btn,
.btn-primary,
.chat-btn {
  border-radius: var(--radius-sm);
  background: var(--accent);
  box-shadow: none;
}

.profile-chat-btn:hover,
.btn-primary:hover {
  background: var(--accent-hover);
  filter: none;
}

.me-header {
  margin: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.me-card {
  margin: 0 12px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.weread-view {
  padding: 28px;
}

.weread-kicker {
  color: var(--text-secondary);
  letter-spacing: .04em;
}

.weread-topbar h2 {
  font-size: 26px;
  letter-spacing: 0;
}

.weread-metrics {
  gap: 12px;
}

.weread-grid {
  gap: 12px;
}

.weread-book-card,
.weread-rank,
.weread-note {
  background: transparent;
  border-color: var(--border);
}

.weread-cover {
  border-radius: 6px;
}

.weread-bar-row div {
  background: rgba(15,118,110,.09);
}

.weread-bar-row i {
  background: var(--accent);
}

.token-stats .ts-down,
.token-stats .ts-cache,
.copy-btn:hover,
.md-li-num,
.md-link,
.stream-cursor,
.send-btn:not(:disabled),
.btn-primary,
.profile-chat-btn,
.chat-btn,
.welcome-icon {
  color: #0f766e;
}

.token-stats .ts-down,
.token-stats .ts-cache {
  color: #0f766e;
}

.ts-up,
.contact-tagline,
.conv-pending,
.row-value.ok,
.me-ok {
  color: #0f766e;
}

.usage-bar.warn {
  color: #a16207;
  background: #f59e0b;
}

.usage-bar.danger,
.row-value.err,
.me-err,
.btn-danger {
  color: #be2f2f;
}

.header-avatar,
.me-avatar,
.welcome-icon {
  background: #0f766e;
}

.profile-achievement-dot,
.quote-bar,
.section-dot {
  background: #0f766e;
}

.send-btn:not(:disabled),
.btn-primary,
.profile-chat-btn,
.chat-btn,
.welcome-icon {
  color: #fff;
}

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

@media (max-width: 768px) {
  :root {
    --radius: 12px;
    --radius-sm: 8px;
  }

  .page-header {
    height: 48px;
    font-size: 15px;
  }

  .tab-bar {
    height: calc(58px + env(safe-area-inset-bottom));
  }

  .tab-item {
    padding-top: 8px;
  }

  .tab-page {
    bottom: calc(58px + env(safe-area-inset-bottom));
  }

  .conv-list,
  .mobile-contacts,
  .weread-mobile,
  .me-content {
    padding: 10px 10px 0;
  }

  .conv-item,
  .contact-item {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 8px;
    background: var(--surface);
  }

  .contacts-header {
    margin-bottom: 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    position: sticky;
  }

  .msg-area {
    padding: 16px 12px 0;
  }

  .input-wrap {
    border-radius: 14px;
  }

  .weread-view-mobile {
    padding: 0;
  }

  .weread-topbar {
    align-items: center;
  }

  .weread-section,
  .weread-metric,
  .weread-reco {
    border-radius: var(--radius);
  }
}
