:root {
  --bg: #0c0713;
  --bg-2: #120b1d;
  --panel: rgba(26, 18, 40, 0.66);
  --panel-solid: #170f23;
  --panel-hi: #1e1530;
  --border: rgba(255, 255, 255, 0.075);
  --border-hi: rgba(255, 255, 255, 0.14);
  --text: #f4eefb;
  --muted: #a89bbd;
  --faint: #7b6f8f;
  --pink: #ff9ad5;
  --violet: #a78bfa;
  --grad: linear-gradient(135deg, #ff9ad5 0%, #c08bf5 52%, #a78bfa 100%);
  --grad-soft: linear-gradient(135deg, rgba(255, 154, 213, 0.22), rgba(167, 139, 250, 0.22));
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  --radius: 16px;
  --font: "Segoe UI Variable Display", "Segoe UI", "Microsoft YaHei UI", "Microsoft YaHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    radial-gradient(900px 620px at 8% -6%, rgba(255, 128, 196, 0.16), transparent 62%),
    radial-gradient(1000px 700px at 96% 8%, rgba(130, 96, 246, 0.18), transparent 60%),
    radial-gradient(900px 700px at 50% 112%, rgba(86, 58, 158, 0.22), transparent 65%),
    linear-gradient(180deg, #0d0816 0%, #0a0611 100%);
  z-index: -3;
}

.glow {
  position: fixed;
  border-radius: 50%;
  filter: blur(90px);
  opacity: 0.5;
  pointer-events: none;
  z-index: -2;
}
.glow-a { width: 420px; height: 420px; left: -140px; top: 12%; background: rgba(255, 118, 190, 0.16); }
.glow-b { width: 520px; height: 520px; right: -180px; bottom: -160px; background: rgba(124, 90, 246, 0.18); }

.stars {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  opacity: 0.5;
  background-image:
    radial-gradient(1px 1px at 20px 30px, rgba(255, 255, 255, 0.5), transparent),
    radial-gradient(1px 1px at 140px 90px, rgba(255, 214, 244, 0.45), transparent),
    radial-gradient(1.4px 1.4px at 260px 40px, rgba(255, 255, 255, 0.32), transparent),
    radial-gradient(1px 1px at 320px 160px, rgba(190, 170, 255, 0.45), transparent);
  background-size: 340px 220px;
  mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.85), transparent 75%);
}

button, input, textarea, select { font-family: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
svg { display: block; }
.hidden { display: none !important; }

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.1); border-radius: 99px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.2); background-clip: content-box; }

/* ------------------------------------------------------------------ shell */
.app {
  height: 100vh;
  display: grid;
  grid-template-columns: 282px minmax(0, 1fr);
  overflow: hidden;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 20px 14px 14px;
  background: rgba(17, 11, 27, 0.72);
  border-right: 1px solid var(--border);
  backdrop-filter: blur(18px);
  min-width: 0;
  min-height: 0;
}

.brand { display: flex; align-items: center; gap: 10px; padding: 2px 8px 4px; }
.logo {
  width: 36px; height: 36px; border-radius: 12px;
  display: grid; place-items: center;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 0 22px rgba(255, 154, 213, 0.18);
}
.logo svg { width: 22px; height: 22px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-text b { font-size: 15.5px; letter-spacing: 0.2px; }
.brand-text span { font-size: 10px; letter-spacing: 4px; color: var(--faint); margin-top: 3px; }

.new-chat {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  height: 42px; border-radius: 12px;
  font-size: 14px; font-weight: 600; color: #2a1030;
  background: var(--grad);
  box-shadow: 0 8px 24px rgba(255, 130, 200, 0.22), inset 0 1px 0 rgba(255, 255, 255, 0.45);
  transition: transform 0.15s ease, box-shadow 0.2s ease, filter 0.2s ease;
}
.new-chat svg { width: 17px; height: 17px; }
.new-chat:hover { transform: translateY(-1px); filter: brightness(1.05); box-shadow: 0 12px 30px rgba(255, 130, 200, 0.3); }
.new-chat:active { transform: translateY(0); }

.search {
  position: relative;
  display: flex; align-items: center;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0 10px;
  height: 36px;
  transition: border-color 0.2s ease, background 0.2s ease;
}
.search:focus-within { border-color: rgba(255, 154, 213, 0.45); background: rgba(255, 255, 255, 0.06); }
.search svg { width: 16px; height: 16px; color: var(--faint); flex: none; }
.search input {
  flex: 1; min-width: 0; margin-left: 8px;
  background: none; border: 0; outline: none;
  font-size: 13px; color: var(--text);
}
.search input::placeholder { color: var(--faint); }
.search input::-webkit-search-cancel-button { -webkit-appearance: none; }

.conv-list { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 3px; padding-right: 2px; }
.conv-group-title {
  font-size: 11px; letter-spacing: 1px; color: var(--faint);
  padding: 12px 10px 6px;
}
.conv-item {
  position: relative;
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px;
  border-radius: 11px;
  border: 1px solid transparent;
  text-align: left;
  width: 100%;
  transition: background 0.16s ease, border-color 0.16s ease;
}
.conv-item:hover { background: rgba(255, 255, 255, 0.045); }
.conv-item.active {
  background: linear-gradient(135deg, rgba(255, 154, 213, 0.12), rgba(167, 139, 250, 0.1));
  border-color: rgba(255, 154, 213, 0.22);
}
.conv-item.active::before {
  content: ""; position: absolute; left: -1px; top: 22%; bottom: 22%;
  width: 2.5px; border-radius: 4px; background: var(--grad);
}
.conv-meta { min-width: 0; flex: 1; }
.conv-title { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-sub { font-size: 11.5px; color: var(--faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 3px; }
.conv-time { font-size: 10px; color: var(--faint); flex: none; align-self: flex-start; margin-top: 2px; }

.sidebar-foot { display: flex; align-items: center; gap: 6px; padding-top: 10px; border-top: 1px solid var(--border); }
.foot-btn {
  display: flex; align-items: center; gap: 6px;
  padding: 7px 10px; border-radius: 9px;
  font-size: 12.5px; color: var(--muted);
  transition: background 0.16s ease, color 0.16s ease;
}
.foot-btn svg { width: 15px; height: 15px; }
.foot-btn:hover { background: rgba(255, 255, 255, 0.06); color: var(--text); }
.ver { margin-left: auto; font-size: 10px; color: var(--faint); letter-spacing: 0.5px; }

/* ------------------------------------------------------------------- main */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; position: relative; }

.topbar {
  height: 72px; flex: none;
  display: flex; align-items: center; gap: 14px;
  padding: 0 26px;
  border-bottom: 1px solid var(--border);
  background: rgba(12, 7, 19, 0.55);
  backdrop-filter: blur(14px);
  z-index: 5;
}
.char-face { position: relative; flex: none; }
.char-name-row { display: flex; align-items: center; gap: 8px; }
.char-name-row h2 { font-size: 16px; margin: 0; font-weight: 600; letter-spacing: 0.2px; }
.char-sub { font-size: 12px; color: var(--faint); margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 460px; }
.tag {
  font-size: 10.5px; padding: 2px 7px; border-radius: 99px;
  color: #ffc9e8; background: rgba(255, 154, 213, 0.12);
  border: 1px solid rgba(255, 154, 213, 0.2);
}
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.model-pill {
  font-size: 11.5px; color: var(--muted);
  padding: 6px 11px; border-radius: 99px;
  border: 1px solid var(--border); background: rgba(255, 255, 255, 0.035);
  max-width: 220px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.icon-btn {
  width: 32px; height: 32px; border-radius: 9px;
  display: grid; place-items: center; color: var(--muted);
  border: 1px solid transparent;
  transition: background 0.16s ease, color 0.16s ease, border-color 0.16s ease;
}
.icon-btn svg { width: 17px; height: 17px; }
.icon-btn:hover { background: rgba(255, 255, 255, 0.07); color: var(--text); border-color: var(--border); }

/* ------------------------------------------------------------------- chat */
.chat {
  flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden;
  padding: 30px 26px 10px;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}
.chat-inner { max-width: 880px; margin: 0 auto; display: flex; flex-direction: column; gap: 22px; }

.msg { display: flex; gap: 12px; animation: rise 0.28s cubic-bezier(0.2, 0.7, 0.3, 1) both; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.msg.user { flex-direction: row-reverse; }
.msg-body { min-width: 0; max-width: 78%; display: flex; flex-direction: column; gap: 5px; }
.msg.user .msg-body { align-items: flex-end; }
.msg-head { display: flex; align-items: center; gap: 8px; padding: 0 6px; font-size: 11.5px; color: var(--faint); }
.msg-head .who { color: #ffc9e8; font-weight: 600; letter-spacing: 0.3px; }
.msg.user .msg-head .who { color: #cdb9ff; }
.msg-tools { display: flex; gap: 2px; opacity: 0; transition: opacity 0.15s ease; }
.msg:hover .msg-tools { opacity: 1; }
.msg-tools button {
  width: 24px; height: 24px; border-radius: 7px; display: grid; place-items: center;
  color: var(--faint); transition: background 0.15s ease, color 0.15s ease;
}
.msg-tools button svg { width: 14px; height: 14px; }
.msg-tools button:hover { background: rgba(255, 255, 255, 0.09); color: var(--text); }

.bubble {
  position: relative;
  padding: 13px 16px;
  border-radius: 16px;
  font-size: 14.5px; line-height: 1.75;
  word-break: break-word;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.038);
  backdrop-filter: blur(6px);
  min-width: 60px;
}
.msg.assistant .bubble { border-top-left-radius: 5px; }
.msg.user .bubble {
  border-top-right-radius: 5px;
  background: var(--grad-soft);
  border-color: rgba(255, 154, 213, 0.22);
  box-shadow: 0 8px 26px rgba(255, 130, 200, 0.07);
}
.bubble.error { border-color: rgba(255, 110, 110, 0.4); background: rgba(255, 80, 90, 0.08); color: #ffc4c4; }

.avatar {
  flex: none; width: 38px; height: 38px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 19px; overflow: hidden;
  background: linear-gradient(150deg, rgba(255, 154, 213, 0.22), rgba(167, 139, 250, 0.22));
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.16);
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.sm { width: 30px; height: 30px; font-size: 15px; }
.avatar.lg { width: 46px; height: 46px; font-size: 23px; }

.think {
  margin-bottom: 8px; border-radius: 10px;
  border: 1px dashed rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.025);
  font-size: 12.5px; color: var(--muted);
}
.think summary { cursor: pointer; padding: 7px 11px; list-style: none; color: var(--faint); user-select: none; }
.think summary::-webkit-details-marker { display: none; }
.think[open] summary { border-bottom: 1px dashed rgba(255, 255, 255, 0.1); }
.think .think-body { padding: 9px 12px; white-space: pre-wrap; line-height: 1.65; }

.typing { display: inline-flex; gap: 4px; align-items: center; height: 20px; }
.typing i {
  width: 6px; height: 6px; border-radius: 50%; background: var(--pink);
  opacity: 0.35; animation: blink 1.15s infinite ease-in-out;
}
.typing i:nth-child(2) { animation-delay: 0.15s; }
.typing i:nth-child(3) { animation-delay: 0.3s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-2px); } }

.caret::after {
  content: "";
  display: inline-block; width: 2px; height: 1em; margin-left: 2px;
  background: var(--pink); vertical-align: -2px;
  animation: caret 1s steps(2) infinite;
}
@keyframes caret { 0%, 50% { opacity: 1; } 50.01%, 100% { opacity: 0; } }

/* markdown */
.bubble p { margin: 0 0 9px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble h1, .bubble h2, .bubble h3, .bubble h4 { margin: 14px 0 8px; line-height: 1.4; font-weight: 650; }
.bubble h1 { font-size: 18px; }
.bubble h2 { font-size: 16.5px; }
.bubble h3 { font-size: 15px; }
.bubble h4 { font-size: 14.5px; }
.bubble ul, .bubble ol { margin: 6px 0 10px; padding-left: 22px; }
.bubble li { margin: 3px 0; }
.bubble strong { color: #ffe0f2; font-weight: 650; }
.bubble em { color: #e5d8ff; }
.bubble a { color: #ffb3e0; text-decoration: none; border-bottom: 1px solid rgba(255, 179, 224, 0.35); }
.bubble a:hover { border-bottom-color: #ffb3e0; }
.bubble del { color: var(--faint); }
.bubble blockquote {
  margin: 8px 0; padding: 2px 0 2px 12px;
  border-left: 2px solid rgba(255, 154, 213, 0.45);
  color: var(--muted);
}
.bubble hr { border: 0; border-top: 1px solid var(--border); margin: 14px 0; }
.bubble code {
  font-family: "Cascadia Code", Consolas, "JetBrains Mono", monospace;
  font-size: 12.8px;
  padding: 1.5px 5px; border-radius: 5px;
  background: rgba(255, 255, 255, 0.08); color: #ffc9e8;
}
.codeblock {
  margin: 10px 0; border-radius: 11px; overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.09);
  background: #0a0711;
}
.codebar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 10px; font-size: 11px; color: var(--faint);
  background: rgba(255, 255, 255, 0.035);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.copy-code { font-size: 11px; color: var(--muted); padding: 2px 6px; border-radius: 5px; }
.copy-code:hover { background: rgba(255, 255, 255, 0.1); color: var(--text); }
.codeblock pre { margin: 0; padding: 12px 14px; overflow-x: auto; }
.codeblock pre code { background: none; padding: 0; color: #e8ddf6; font-size: 12.8px; line-height: 1.6; }

/* empty state */
.empty { max-width: 720px; margin: 4vh auto 0; text-align: center; padding: 0 10px; }
.empty-face {
  width: 104px; height: 104px; margin: 0 auto 18px; border-radius: 50%;
  display: grid; place-items: center; font-size: 46px;
  background: linear-gradient(150deg, rgba(255, 154, 213, 0.2), rgba(167, 139, 250, 0.2));
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: 0 0 0 10px rgba(255, 154, 213, 0.04), 0 20px 60px rgba(167, 139, 250, 0.25);
  overflow: hidden;
}
.empty-face img { width: 100%; height: 100%; object-fit: cover; }
.empty h1 { font-size: 25px; margin: 0 0 10px; letter-spacing: 0.5px; font-weight: 600; }
.empty h1 span { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.empty p { color: var(--muted); font-size: 13.5px; margin: 0 0 26px; }
.char-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; text-align: left; }
.char-card {
  position: relative; display: flex; flex-direction: column; gap: 4px;
  padding: 14px; border-radius: 13px; overflow: hidden;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  text-align: left; align-items: flex-start;
  transition: transform 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}
.char-card:hover { transform: translateY(-2px); border-color: rgba(255, 154, 213, 0.4); background: rgba(255, 255, 255, 0.06); }
.char-card .avatar { margin-bottom: 6px; }
.char-card b { font-size: 13.5px; font-weight: 600; }
.char-card small { color: var(--faint); font-size: 11.5px; line-height: 1.45; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* --------------------------------------------------------------- composer */
.composer { flex: none; padding: 10px 26px 14px; background: linear-gradient(180deg, transparent, rgba(9, 5, 15, 0.7) 40%); }
.composer-box { max-width: 880px; margin: 0 auto; }
.composer-note { max-width: 880px; margin: 8px auto 0; }
.composer-inner { max-width: 880px; margin: 0 auto; }
.composer-box {
  border-radius: 16px;
  border: 1px solid var(--border);
  background: rgba(24, 16, 36, 0.82);
  backdrop-filter: blur(16px);
  padding: 10px 12px 9px 16px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.28);
}
.composer-box:focus-within { border-color: rgba(255, 154, 213, 0.42); box-shadow: 0 14px 44px rgba(0, 0, 0, 0.32), 0 0 0 3px rgba(255, 154, 213, 0.07); }
.composer-box textarea {
  width: 100%; max-height: 190px; min-height: 28px; height: 28px;
  resize: none; background: none; border: 0; outline: none;
  font-size: 14.5px; line-height: 1.65; color: var(--text);
  padding: 2px 0;
}
.composer-box textarea::placeholder { color: var(--faint); }
.composer-actions { display: flex; align-items: center; gap: 10px; padding-top: 4px; }
.hint { font-size: 11px; color: var(--faint); margin-right: auto; }
.send {
  width: 36px; height: 36px; border-radius: 11px;
  display: grid; place-items: center; color: #2a1030;
  background: var(--grad);
  box-shadow: 0 6px 18px rgba(255, 130, 200, 0.3);
  transition: transform 0.15s ease, filter 0.15s ease, opacity 0.15s ease;
}
.send svg { width: 17px; height: 17px; }
.send:hover { transform: translateY(-1px); filter: brightness(1.08); }
.send:disabled { opacity: 0.4; transform: none; cursor: default; }
.stop {
  height: 30px; padding: 0 12px; border-radius: 9px;
  font-size: 12.5px; color: #ffc4c4;
  border: 1px solid rgba(255, 120, 120, 0.35);
  background: rgba(255, 90, 90, 0.1);
}
.stop:hover { background: rgba(255, 90, 90, 0.18); }
.composer-note { text-align: center; font-size: 10.5px; color: rgba(255, 255, 255, 0.2); margin-top: 8px; }

/* ----------------------------------------------------------------- modals */
#modal-root { position: fixed; inset: 0; pointer-events: none; z-index: 50; }
.modal-backdrop {
  position: absolute; inset: 0; pointer-events: auto;
  display: grid; place-items: center;
  background: rgba(6, 3, 11, 0.6);
  backdrop-filter: blur(7px);
  opacity: 0; transition: opacity 0.18s ease;
  padding: 24px;
}
.modal-backdrop.show { opacity: 1; }
.modal {
  width: min(560px, 100%); max-height: 88vh;
  display: flex; flex-direction: column;
  background: linear-gradient(180deg, #1b1329 0%, #140e20 100%);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 18px;
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.07);
  transform: translateY(10px) scale(0.985); opacity: 0;
  transition: transform 0.22s cubic-bezier(0.2, 0.8, 0.3, 1), opacity 0.2s ease;
  overflow: hidden;
}
.modal-backdrop.show .modal { transform: none; opacity: 1; }
.modal.lg { width: min(760px, 100%); }
.modal.xl { width: min(940px, 100%); }
.modal-head {
  display: flex; align-items: center; gap: 12px;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
}
.modal-head h3 { margin: 0; font-size: 16px; font-weight: 600; }
.modal-head p { margin: 3px 0 0; font-size: 11.5px; color: var(--faint); }
.modal-head .grow { flex: 1; min-width: 0; }
.modal-body { padding: 18px 20px; overflow-y: auto; }
.modal-foot {
  display: flex; align-items: center; gap: 8px;
  padding: 13px 20px; border-top: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.14);
}
.modal-foot .spacer { flex: 1; }

.btn {
  height: 34px; padding: 0 14px; border-radius: 9px;
  font-size: 13px; color: var(--text);
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.045);
  transition: background 0.16s ease, border-color 0.16s ease, transform 0.12s ease;
  display: inline-flex; align-items: center; gap: 6px;
}
.btn svg { width: 15px; height: 15px; }
.btn:hover { background: rgba(255, 255, 255, 0.09); border-color: var(--border-hi); }
.btn:active { transform: scale(0.985); }
.btn.primary {
  color: #2a1030; font-weight: 650; border: 0;
  background: var(--grad);
  box-shadow: 0 8px 22px rgba(255, 130, 200, 0.22);
}
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: #ffb4b4; border-color: rgba(255, 110, 110, 0.3); }
.btn.danger:hover { background: rgba(255, 90, 90, 0.12); }
.btn.sm { height: 28px; padding: 0 10px; font-size: 12px; border-radius: 8px; }
.btn.ghost { background: none; }

.field { margin-bottom: 15px; }
.field:last-child { margin-bottom: 0; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 7px; letter-spacing: 0.2px; }
.field .tip { font-size: 11px; color: var(--faint); margin-top: 6px; line-height: 1.5; }
.input, .textarea, .select {
  width: 100%; border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(10, 6, 16, 0.66);
  padding: 9px 12px; font-size: 13.5px;
  outline: none; color: var(--text);
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}
.input:focus, .textarea:focus, .select:focus {
  border-color: rgba(255, 154, 213, 0.45);
  box-shadow: 0 0 0 3px rgba(255, 154, 213, 0.08);
}
.textarea { resize: vertical; min-height: 84px; line-height: 1.65; }
.textarea.short { min-height: 62px; }
.select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, #a89bbd 50%), linear-gradient(135deg, #a89bbd 50%, transparent 50%); background-position: calc(100% - 16px) 50%, calc(100% - 11px) 50%; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; padding-right: 32px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.inline { display: flex; gap: 8px; align-items: center; }
.inline .input { flex: 1; min-width: 0; }

.switch { display: flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; padding: 3px 0; }
.field label.switch {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 0; font-size: 13px; color: var(--text);
  padding: 3px 0;
}
.switch input { display: none; }
.switch .track {
  width: 36px; height: 20px; border-radius: 99px; flex: none;
  background: rgba(255, 255, 255, 0.12); position: relative;
  transition: background 0.2s ease;
}
.switch .track::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 16px; height: 16px; border-radius: 50%;
  background: #cbbfd8; transition: transform 0.2s cubic-bezier(0.2, 0.8, 0.3, 1), background 0.2s ease;
}
.switch input:checked + .track { background: var(--grad); }
.switch input:checked + .track::after { transform: translateX(16px); background: #fff; }
.switch .switch-label { font-size: 13px; color: var(--text); }
.switch .switch-label small { display: block; color: var(--faint); font-size: 11px; margin-top: 2px; }

.range-row { display: flex; align-items: center; gap: 12px; }
input[type="range"] {
  -webkit-appearance: none; appearance: none;
  flex: 1; height: 4px; border-radius: 99px;
  background: linear-gradient(90deg, rgba(255, 154, 213, 0.6), rgba(167, 139, 250, 0.6));
  outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 15px; height: 15px; border-radius: 50%;
  background: #fff; border: 2px solid #ff9ad5;
  box-shadow: 0 2px 8px rgba(255, 130, 200, 0.5); cursor: pointer;
}
.range-val { font-size: 12px; color: var(--muted); width: 34px; text-align: right; font-variant-numeric: tabular-nums; }

.greet-list { display: flex; flex-direction: column; gap: 8px; }
.greet-option {
  text-align: left; padding: 12px 14px; border-radius: 11px;
  border: 1px solid var(--border); background: rgba(255, 255, 255, 0.035);
  font-size: 13px; line-height: 1.7; color: var(--text);
  transition: border-color 0.16s ease, background 0.16s ease;
}
.greet-option:hover { border-color: rgba(255, 154, 213, 0.4); background: rgba(255, 154, 213, 0.07); }

/* character manager */.char-manager { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.manage-card {
  position: relative; padding: 15px; border-radius: 14px;
  border: 1px solid var(--border); background: rgba(255, 255, 255, 0.035);
  display: flex; flex-direction: column; gap: 8px;
  transition: border-color 0.18s ease, transform 0.18s ease;
}
.manage-card:hover { border-color: rgba(255, 154, 213, 0.28); transform: translateY(-1px); }
.manage-card .avatar { width: 52px; height: 52px; font-size: 26px; }
.manage-card h4 { margin: 0; font-size: 14px; font-weight: 600; }
.manage-card p { margin: 0; font-size: 11.5px; color: var(--faint); line-height: 1.5; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; min-height: 34px; }
.manage-card .tags { display: flex; flex-wrap: wrap; gap: 4px; }
.manage-card .ops { display: flex; gap: 4px; margin-top: 2px; }
.mini-btn {
  width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center;
  color: var(--muted); border: 1px solid transparent;
  transition: background 0.15s ease, color 0.15s ease;
}
.mini-btn svg { width: 14px; height: 14px; }
.mini-btn:hover { background: rgba(255, 255, 255, 0.08); color: var(--text); }
.mini-btn.danger:hover { background: rgba(255, 90, 90, 0.14); color: #ffb4b4; }

/* character editor */
.editor-top { display: grid; grid-template-columns: 128px 1fr; gap: 16px; margin-bottom: 16px; }
.avatar-picker { display: flex; flex-direction: column; align-items: center; gap: 10px; width: 128px; min-width: 0; }
.avatar-preview {
  width: 96px; height: 96px; border-radius: 24px;
  display: grid; place-items: center; font-size: 42px; overflow: hidden;
  background: linear-gradient(150deg, rgba(255, 154, 213, 0.2), rgba(167, 139, 250, 0.2));
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}
.avatar-preview img { width: 100%; height: 100%; object-fit: cover; }
.emoji-row { display: flex; flex-wrap: wrap; gap: 4px; justify-content: center; width: 100%; }
.emoji-btn {
  width: 26px; height: 26px; border-radius: 7px; font-size: 15px;
  display: grid; place-items: center;
  border: 1px solid transparent;
}
.emoji-btn:hover { background: rgba(255, 255, 255, 0.1); }
.emoji-btn.active { border-color: rgba(255, 154, 213, 0.55); background: rgba(255, 154, 213, 0.12); }

/* dropdown */
.menu {
  position: fixed; z-index: 60;
  min-width: 150px; padding: 6px;
  border-radius: 11px;
  background: #1c1429;
  border: 1px solid var(--border-hi);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.5);
  animation: rise 0.14s ease both;
}
.menu button {
  display: flex; align-items: center; gap: 9px;
  width: 100%; padding: 8px 10px; border-radius: 7px;
  font-size: 12.5px; color: var(--text); text-align: left;
}
.menu button svg { width: 14px; height: 14px; color: var(--muted); }
.menu button:hover { background: rgba(255, 255, 255, 0.07); }
.menu button.danger { color: #ffb4b4; }
.menu button.danger svg { color: #ffb4b4; }
.menu hr { border: 0; border-top: 1px solid var(--border); margin: 5px 4px; }

/* toasts */
.toast-root { position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%); z-index: 80; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast {
  padding: 9px 16px; border-radius: 10px;
  font-size: 12.5px; color: var(--text);
  background: rgba(30, 21, 45, 0.95);
  border: 1px solid var(--border-hi);
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.45);
  animation: toastIn 0.22s ease both;
  max-width: 460px; text-align: center;
}
.toast.error { border-color: rgba(255, 110, 110, 0.45); color: #ffd0d0; }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.empty .char-card .avatar { align-self: flex-start; }

@media (max-width: 1100px) {
  .app { grid-template-columns: 250px minmax(0, 1fr); }
  .sidebar { padding: 18px 10px 12px; }
}

/* --------------------------------------------------- 工具 / 设置分页 / SSH */
.tabs {
  display: flex;
  gap: 4px;
  margin: -4px 0 18px;
  border-bottom: 1px solid var(--border);
}
.tab {
  appearance: none;
  background: none;
  border: 0;
  color: var(--muted);
  font: inherit;
  font-size: 12.5px;
  padding: 8px 12px 9px;
  border-radius: 8px 8px 0 0;
  cursor: pointer;
  position: relative;
  transition: color .15s ease, background .15s ease;
}
.tab:hover { color: var(--text); background: rgba(255, 255, 255, 0.04); }
.tab.active { color: var(--text); background: rgba(255, 255, 255, 0.06); }
.tab.active::after {
  content: "";
  position: absolute;
  left: 10px; right: 10px; bottom: -1px;
  height: 2px;
  border-radius: 2px;
  background: var(--grad);
}
.tab-panel.hidden { display: none; }

.tool-card {
  margin: 8px 0 14px 56px;
  max-width: 740px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.035);
  border-radius: 12px;
  overflow: hidden;
  font-size: 12.5px;
}
.msg-tool .tool-card { margin: 8px 0 14px; }
.tool-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  cursor: pointer;
  user-select: none;
}
.tool-ico { width: 18px; display: inline-flex; align-items: center; justify-content: center; color: #c9b7ea; font-size: 13px; }
.tool-ico svg { width: 14px; height: 14px; display: block; }
.tool-title { font-weight: 600; font-size: 12.5px; color: #efe6fb; }
.tool-status {
  margin-left: auto;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
}
.tool-status.ok { color: #9ef0c0; background: rgba(80, 220, 150, 0.12); }
.tool-status.error { color: #ff9d9d; background: rgba(255, 90, 90, 0.12); }
.tool-status.denied { color: #ffc48a; background: rgba(255, 180, 90, 0.12); }
.tool-status.pending { color: #ffd5a0; background: rgba(255, 200, 120, 0.12); }
.tool-status.running { color: #a9c7ff; background: rgba(120, 160, 255, 0.14); }
.tool-chev { margin-left: 6px; color: var(--faint); font-size: 10px; transition: transform .18s ease; }
.tool-card.open .tool-chev { transform: rotate(180deg); }
.tool-cmd {
  padding: 0 12px 10px 38px;
  color: #cfc4e0;
  font-size: 12px;
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  white-space: pre-wrap;
  word-break: break-word;
}
.tool-body {
  display: none;
  border-top: 1px solid var(--border);
  padding: 10px 12px;
  background: rgba(0, 0, 0, 0.2);
}
.tool-card.open .tool-body { display: block; }
.tool-body pre {
  margin: 0;
  max-height: 320px;
  overflow: auto;
  font-size: 11.5px;
  line-height: 1.55;
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  color: #d9d1e8;
  white-space: pre-wrap;
  word-break: break-word;
}

.appr { display: flex; flex-direction: column; gap: 10px; }
.appr-row { display: flex; flex-direction: column; gap: 4px; }
.appr-label { font-size: 11px; color: var(--faint); letter-spacing: .04em; }
.appr-value {
  font-size: 12.5px;
  color: #e9e1f7;
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 220px;
  overflow: auto;
  margin: 0;
}
.appr-value.mono {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 11.5px;
  line-height: 1.55;
}

.ssh-list { display: flex; flex-direction: column; gap: 8px; }
.ssh-row {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.03);
}
.ssh-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }
.ssh-main b { font-size: 13px; font-weight: 600; }
.ssh-main span {
  font-size: 11.5px;
  color: var(--faint);
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ssh-actions { display: flex; gap: 6px; }

.tab-panel > .tip { font-size: 11px; color: var(--faint); line-height: 1.6; margin-top: 4px; }

.msg-tool { padding-left: 56px; }
.ssh-empty {
  font-size: 12px;
  color: var(--faint);
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 18px;
  text-align: center;
}

.ask-question {
  font-size: 14px;
  line-height: 1.75;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}
.ask-options { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.ask-option {
  appearance: none;
  cursor: pointer;
  font: inherit;
  font-size: 12.5px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-hi);
  border-radius: 999px;
  padding: 7px 14px;
  transition: background .15s ease, border-color .15s ease, transform .15s ease;
}
.ask-option:hover {
  background: var(--grad-soft);
  border-color: rgba(255, 154, 213, 0.45);
  transform: translateY(-1px);
}
