:root {
  --accent: #4d6bfe;
  --accent-hover: #5a75ff;
  --bg: #ffffff;
  --bg-secondary: #f7f7f8;
  --sidebar-bg: #fafafc;
  --input-bg: #ffffff;
  --border: #e5e5ea;
  --border-strong: #d4d4da;
  --text: #1a1a1d;
  --text-dim: #6b6b73;
  --user-bubble: #eef1ff;
  --code-bg: #f4f4f6;
  --hover: #f0f0f3;
  --danger: #ef4444;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.1);
  --radius: 12px;
}

html[data-theme="dark"] {
  --accent: #5f7bff;
  --accent-hover: #7b92ff;
  --bg: #212121;
  --bg-secondary: #1a1a1c;
  --sidebar-bg: #262626;
  --input-bg: #303030;
  --border: #3a3a40;
  --border-strong: #4a4a52;
  --text: #ececf1;
  --text-dim: #a0a0ab;
  --user-bubble: #39405c;
  --code-bg: #17171a;
  --hover: #2c2c30;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
}

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

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  transition: background 0.2s, color 0.2s;
}

svg { flex-shrink: 0; }

button { font-family: inherit; }

.app {
  display: flex;
  height: 100dvh;
  min-height: -webkit-fill-available;
}

/* ---------------- sidebar ---------------- */
.sidebar {
  width: 264px;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: transform 0.25s ease, background 0.2s;
  z-index: 30;
}

.sidebar-top { padding: 16px 12px 8px; }

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 18px;
}
.brand-logo { width: 28px; height: 28px; color: var(--accent); }
.brand-name { font-size: 18px; font-weight: 700; letter-spacing: -0.02em; }

.new-chat {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--accent);
  border: none;
  border-radius: 10px;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.new-chat:hover { background: var(--accent-hover); }
.new-chat:active { transform: scale(0.98); }
.new-chat svg { width: 17px; height: 17px; }

.chat-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px 8px;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
}
.chat-list::-webkit-scrollbar { width: 6px; }
.chat-list::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }

.chat-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  margin: 2px 0;
  border-radius: 9px;
  font-size: 13.5px;
  color: var(--text-dim);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background 0.12s, color 0.12s;
}
.chat-item:hover { background: var(--hover); color: var(--text); }
.chat-item.active { background: var(--hover); color: var(--text); font-weight: 600; }

.chat-item-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }

.chat-item-actions {
  display: none;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}
.chat-item:hover .chat-item-actions,
.chat-item.active .chat-item-actions { display: flex; }

.mini-btn {
  background: none;
  border: none;
  border-radius: 6px;
  width: 24px;
  height: 24px;
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.12s;
}
.mini-btn:hover { color: var(--text); background: var(--bg-secondary); }
.mini-btn.danger:hover { color: var(--danger); }
.mini-btn svg { width: 14px; height: 14px; }

.sidebar-bottom {
  padding: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}
.model-badge {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  min-width: 0;
}
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #34d399; box-shadow: 0 0 6px rgba(52, 211, 153, 0.7); }
.model-name { font-weight: 600; white-space: nowrap; }
.model-online { color: #34d399; font-size: 11px; white-space: nowrap; }

.icon-btn, .theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: 9px;
  width: 34px;
  height: 34px;
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  flex-shrink: 0;
}
.icon-btn:hover, .theme-toggle:hover { color: var(--text); border-color: var(--border-strong); }
.icon-btn svg, .theme-toggle svg { width: 17px; height: 17px; }
.theme-toggle .icon-sun { display: none; }
html[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
html[data-theme="dark"] .theme-toggle .icon-sun { display: block; }

/* ---------------- main ---------------- */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--bg); height: 100dvh; }

.main-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
}
.menu-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  display: none;
  padding: 4px;
}
.menu-btn svg { width: 21px; height: 21px; }
.menu-btn:hover { color: var(--text); }
.header-title { font-size: 15px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.header-right { margin-left: auto; display: flex; align-items: center; }
.pill {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--text-dim);
  border: 1px solid var(--border);
  background: var(--bg-secondary);
  padding: 6px 12px;
  border-radius: 999px;
}
.pill svg { width: 14px; height: 14px; color: var(--accent); }

/* ---------------- chat area ---------------- */
.chat-area {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  height: 100dvh;
}
.chat-area::-webkit-scrollbar { width: 8px; }
.chat-area::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }

.empty-state {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px 20px;
  -webkit-overflow-scrolling: touch;
}
.empty-logo {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  background: linear-gradient(135deg, #4d6bfe, #7a5cff);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 20px;
  box-shadow: 0 8px 30px rgba(77, 107, 254, 0.35);
  animation: pop 0.4s ease;
}
@keyframes pop { from { transform: scale(0.75); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.empty-logo svg { width: 34px; height: 34px; color: #fff; }
.empty-state h2 { font-size: 24px; font-weight: 700; margin-bottom: 8px; letter-spacing: -0.02em; }
.empty-state > p { color: var(--text-dim); font-size: 14px; margin-bottom: 22px; }

.capability-chips { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin-bottom: 30px; }
.chip {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 7px 14px;
  background: var(--bg-secondary);
  transition: all 0.15s;
}
.chip:hover { color: var(--text); border-color: var(--accent); }
.chip svg { width: 15px; height: 15px; color: var(--accent); }

.suggestions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 12px;
  max-width: 780px;
  width: 100%;
}
.suggestion {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 15px 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13.5px;
  font-family: inherit;
  line-height: 1.45;
  text-align: left;
  cursor: pointer;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.suggestion:hover { border-color: var(--accent); box-shadow: var(--shadow); transform: translateY(-1px); }
.suggestion svg { width: 19px; height: 19px; color: var(--accent); margin-top: 1px; }

/* ---------------- messages ---------------- */
.messages {
  padding: 26px 20px 10px;
  max-width: 820px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.msg { display: flex; flex-direction: column; gap: 4px; animation: fadeUp 0.25s ease; position: relative; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* user message */
.msg.user { align-items: flex-end; }
.msg.user .msg-body {
  max-width: 85%;
  background: var(--user-bubble);
  border-radius: 14px 14px 4px 14px;
  padding: 11px 15px;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 14.5px;
  line-height: 1.7;
}

/* assistant message */
.msg.assistant .msg-body { display: flex; gap: 14px; align-items: flex-start; }
.msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), #7a5cff);
  margin-top: 2px;
}
.msg-avatar svg { width: 17px; height: 17px; }
.msg-content { flex: 1; min-width: 0; font-size: 14.5px; line-height: 1.7; }

.msg-content p { margin-bottom: 10px; }
.msg-content p:last-child { margin-bottom: 0; }

.msg-content h1, .msg-content h2, .msg-content h3,
.msg-content h4, .msg-content h5, .msg-content h6 {
  margin: 18px 0 10px;
  line-height: 1.3;
  display: flex;
  align-items: center;
  gap: 8px;
}
.msg-content h1:first-child, .msg-content h2:first-child,
.msg-content h3:first-child, .msg-content h4:first-child,
.msg-content h5:first-child, .msg-content h6:first-child { margin-top: 0; }
.msg-content ul, .msg-content ol { padding-left: 22px; margin-bottom: 10px; }
.msg-content li { margin-bottom: 3px; }
.msg-content code {
  background: var(--code-bg);
  border: 1px solid var(--border);
  padding: 2px 6px;
  border-radius: 5px;
  font-family: "Cascadia Code", "SF Mono", Consolas, "Courier New", monospace;
  font-size: 13px;
}
.msg-content table { border-collapse: collapse; margin-bottom: 12px; width: 100%; }
.msg-content th, .msg-content td { border: 1px solid var(--border); padding: 7px 12px; text-align: left; }
.msg-content th { background: var(--bg-secondary); }
.msg-content blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 14px;
  color: var(--text-dim);
  margin-bottom: 12px;
}
.msg-content a { color: var(--accent); }
.msg-content hr { border: none; border-top: 1px solid var(--border); margin: 14px 0; }

/* code blocks */
.msg-content pre {
  position: relative;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 40px 16px 14px;
  overflow-x: auto;
  margin-bottom: 14px;
}
.msg-content pre code { background: none; border: none; padding: 0; font-size: 13px; line-height: 1.6; display: block; }

.code-block::before {
  content: attr(data-lang);
  position: absolute;
  top: 8px;
  left: 14px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-dim);
  opacity: 0.7;
}

.copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text-dim);
  font-size: 12px;
  padding: 5px 10px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s, border-color 0.15s;
  z-index: 2;
}
.copy-btn svg { width: 13px; height: 13px; }
.msg-content pre:hover .copy-btn { opacity: 1; }
.copy-btn:hover { color: var(--text); border-color: var(--border-strong); }
.copy-btn .ok { color: #10b981; }

.section-copy {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--text-dim);
  cursor: pointer;
  padding: 3px;
  opacity: 0;
  transition: opacity 0.15s, border-color 0.15s, color 0.15s;
}
.section-copy svg { width: 14px; height: 14px; }
.msg-content h1:hover .section-copy, .msg-content h2:hover .section-copy,
.msg-content h3:hover .section-copy, .msg-content h4:hover .section-copy,
.msg-content h5:hover .section-copy, .msg-content h6:hover .section-copy { opacity: 1; }
.section-copy:hover { color: var(--text); border-color: var(--border-strong); }

/* message actions */
.msg-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 0 0 46px;
  opacity: 1;
  transition: opacity 0.15s;
}
.msg.user .msg-actions { padding-left: 0; padding-right: 8px; justify-content: flex-end; }
.msg:hover .msg-actions { opacity: 1; }

.act-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: none;
  border: none;
  border-radius: 7px;
  color: var(--text-dim);
  font-size: 12px;
  cursor: pointer;
  padding: 5px 8px;
  transition: all 0.12s;
}
.act-btn:hover { color: var(--text); background: var(--hover); }
.act-btn svg { width: 14px; height: 14px; }
.act-btn .ok { color: #10b981; }
.act-btn[data-act="regen"]:hover svg { animation: spin 0.7s linear; }
@keyframes spin { to { transform: rotate(360deg); } }

.msg-meta { font-size: 11.5px; color: var(--text-dim); margin-top: 8px; }

/* editing */
.edit-box {
  width: 100%;
  max-width: 85%;
  background: var(--input-bg);
  border: 1px solid var(--accent);
  border-radius: 12px;
  padding: 10px 13px;
  color: var(--text);
  font-size: 14.5px;
  font-family: inherit;
  line-height: 1.6;
  resize: vertical;
  min-height: 60px;
  outline: none;
  box-shadow: var(--shadow);
}

.err {
  background: rgba(239, 68, 68, 0.08);
  border: 1px solid rgba(239, 68, 68, 0.4);
  color: var(--danger);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 14px;
}

/* typing */
.typing { display: inline-flex; gap: 5px; padding: 10px 0; }
.typing span {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--accent);
  animation: blink 1.4s infinite;
}
.typing span:nth-child(2) { animation-delay: 0.2s; opacity: 0.6; }
.typing span:nth-child(3) { animation-delay: 0.4s; opacity: 0.3; }
@keyframes blink { 0%, 80%, 100% { transform: translateY(0); opacity: 0.35; } 40% { transform: translateY(-3px); opacity: 1; } }

.msg.assistant .msg-content { transition: opacity 0.35s ease; }
.msg.assistant.streaming .msg-content { opacity: 0.92; }

/* ---------------- composer ---------------- */
.composer-wrap {
  padding: 12px 20px 14px;
  flex-shrink: 0;
  background: var(--bg);
}
.composer { max-width: 820px; margin: 0 auto; }
.composer-box {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--input-bg);
  border: 1px solid var(--border-strong);
  border-radius: 18px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.composer-box:focus-within { border-color: var(--accent); box-shadow: var(--shadow-lg); }
.composer-box textarea {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  resize: none;
  color: var(--text);
  font-size: 14.5px;
  font-family: inherit;
  line-height: 1.5;
  max-height: 160px;
  padding: 2px 0;
  -webkit-text-size-adjust: 100%;
  min-width: 0;
}
.composer-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.send-btn {
  background: var(--accent);
  border: none;
  border-radius: 11px;
  width: 38px;
  height: 38px;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.send-btn:hover:not(:disabled) { background: var(--accent-hover); transform: scale(1.04); }
.send-btn:disabled { background: var(--border-strong); cursor: not-allowed; opacity: 0.6; }
.send-btn svg { width: 17px; height: 17px; }

.stop-btn {
  background: var(--bg-secondary);
  border: 1px solid var(--border-strong);
  border-radius: 11px;
  width: 38px;
  height: 38px;
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.stop-btn:hover { border-color: #ef4444; color: #ef4444; }
.stop-btn svg { width: 14px; height: 14px; }

.composer-hint { text-align: center; font-size: 12px; color: var(--text-dim); margin-top: 10px; }
.status-error { color: #ef4444; }
.status-thinking { color: var(--accent); }

/* highlight.js integration */
.msg-content .hljs { background: transparent; padding: 0; }

/* ---------------- search ---------------- */
.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 8px 10px;
  margin: 10px 0 4px;
  transition: border-color 0.15s;
}
.search-box:focus-within { border-color: var(--accent); }
.search-box svg { width: 15px; height: 15px; color: var(--text-dim); flex-shrink: 0; }
.search-box input {
  flex: 1;
  min-width: 0;
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  -webkit-text-size-adjust: 100%;
}
.search-box input::placeholder { color: var(--text-dim); }

.chat-item-count {
  font-size: 11px;
  color: var(--text-dim);
  background: var(--bg-secondary);
  border-radius: 999px;
  padding: 1px 7px;
  flex-shrink: 0;
}
.chat-empty { padding: 18px 12px; font-size: 13px; color: var(--text-dim); text-align: center; }

/* ------------------- touch feedback ------------------- */
button:active,
.chat-item:active,
.suggestion:active,
.seg-btn:active,
.tool-btn:active,
.followup-btn:active,
.mini-btn:active,
.header-btn:active,
.attach-btn:active,
.icon-btn:active,
.theme-toggle:active,
.ghost-btn:active {
  transform: scale(0.95);
}
.touch-feedback {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
body {
  -webkit-tap-highlight-color: transparent;
}

/* ---------------- header buttons ---------------- */
.header-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 9px;
  width: 34px;
  height: 34px;
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.header-btn:hover { color: var(--text); border-color: var(--border-strong); }
.header-btn svg { width: 17px; height: 17px; }

/* ---------------- composer attach / file chip ---------------- */
.attach-btn {
  background: none;
  border: none;
  border-radius: 10px;
  width: 34px;
  height: 34px;
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.attach-btn:hover { color: var(--text); background: var(--hover); }
.attach-btn svg { width: 19px; height: 19px; }

.file-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 8px 6px 12px;
  margin-bottom: 8px;
  font-size: 12.5px;
  color: var(--text);
}
.file-chip svg { width: 14px; height: 14px; color: var(--accent); flex-shrink: 0; }
.file-chip-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-chip-x {
  background: none;
  border: none;
  border-radius: 50%;
  width: 22px;
  height: 22px;
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.file-chip-x:hover { color: var(--danger); background: var(--hover); }
.file-chip-x svg { width: 13px; height: 13px; color: inherit; }

/* ---------------- follow-up suggestions ---------------- */
.followup {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding: 0 0 0 46px;
  margin-top: 8px;
}
.followup-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-dim);
  font-size: 12.5px;
  font-family: inherit;
  padding: 6px 13px;
  cursor: pointer;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.followup-btn:hover { color: var(--text); border-color: var(--accent); }
.followup-btn svg { width: 14px; height: 14px; color: var(--accent); }

/* ---------------- listen state ---------------- */
.act-btn.active { color: var(--accent); background: var(--hover); }
.act-btn.active svg { animation: pulse 1s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }

/* ---------------- panels / overlay ---------------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 60;
  animation: fadeIn 0.15s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.panel {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 400px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  z-index: 70;
  padding: 20px;
  animation: pop 0.2s ease;
  -webkit-overflow-scrolling: touch;
}
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.panel-header h3 { font-size: 16px; font-weight: 700; }
.panel-close {
  background: none;
  border: none;
  border-radius: 8px;
  width: 30px;
  height: 30px;
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.panel-close:hover { color: var(--text); background: var(--hover); }
.panel-close svg { width: 16px; height: 16px; }

.set-group { margin-bottom: 18px; }
.set-label { font-size: 12.5px; font-weight: 600; color: var(--text-dim); margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.04em; }
.radio-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  margin-bottom: 8px;
  transition: all 0.15s;
}
.radio-row:hover { border-color: var(--border-strong); background: var(--bg-secondary); }
.radio-row:has(input:checked) { border-color: var(--accent); background: var(--bg-secondary); }
.radio-row input { accent-color: var(--accent); }
.radio-txt { display: flex; flex-direction: column; gap: 2px; }
.radio-txt strong { font-size: 14px; }
.radio-txt span { font-size: 12px; color: var(--text-dim); }

.set-group select {
  width: 100%;
  background: var(--input-bg);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  padding: 10px 12px;
  outline: none;
}
.set-group select:focus { border-color: var(--accent); }

.set-textarea {
  width: 100%;
  margin-top: 8px;
  background: var(--input-bg);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  color: var(--text);
  font-size: 13.5px;
  font-family: inherit;
  line-height: 1.5;
  padding: 10px 12px;
  resize: vertical;
  min-height: 90px;
  outline: none;
}
.set-textarea:focus { border-color: var(--accent); }

/* ---- wide settings panel ---- */
  .panel.panel-wide { width: min(1160px, calc(100vw - 48px)); }
.set-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 28px; align-items: start; }
.set-grid .span2 { grid-column: 1 / -1; }
.set-input {
  width: 100%;
  box-sizing: border-box;
  background: var(--input-bg);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  padding: 10px 12px;
  outline: none;
}
.set-input:focus { border-color: var(--accent); }
.set-note { font-size: 12px; color: var(--text-dim); margin-top: 6px; line-height: 1.4; }

/* ---- name modal ---- */
.name-modal { text-align: center; padding: 26px 24px; width: 400px; }
.name-logo {
  width: 64px;
  height: 64px;
  margin: 0 auto 14px;
  border-radius: 20px;
  background: linear-gradient(135deg, #4d6bfe, #a855f7);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
}
.name-logo svg { width: 34px; height: 34px; }
.name-title { font-size: 20px; font-weight: 700; margin: 0 0 6px; }
.name-intro { font-size: 14px; color: var(--text-dim); margin: 0 0 18px; }
.name-intro strong { color: var(--text); }
.name-actions { display: flex; gap: 10px; margin-top: 14px; }
.name-actions .ghost-btn { width: auto; margin: 0; padding: 10px 16px; }

/* ---- primary button ---- */
.btn-primary {
  flex: 1;
  background: var(--accent);
  border: none;
  border-radius: 10px;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  padding: 10px 18px;
  cursor: pointer;
  transition: opacity 0.15s;
}
.btn-primary:hover { opacity: 0.9; }

/* ---- cookie banner ---- */
.cookie-banner {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  flex-wrap: wrap;
  padding: 12px 18px;
  background: var(--bg);
  border-top: 1px solid var(--border);
  box-shadow: 0 -6px 24px rgba(0, 0, 0, 0.1);
  font-size: 13.5px;
}
.cookie-banner[hidden] { display: none; }
.cookie-banner p { margin: 0; max-width: 620px; line-height: 1.5; }
.cookie-banner a { color: var(--accent); font-weight: 600; }
.cookie-actions { display: flex; gap: 8px; }
.cookie-actions .ghost-btn { width: auto; margin: 0; padding: 10px 14px; }
.cookie-actions .btn-primary { flex: none; padding: 10px 20px; }

.set-group input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  -webkit-appearance: none;
  height: 30px;
  padding: 0;
  margin: 8px 0;
  background: transparent;
  cursor: pointer;
}

.set-group input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  cursor: pointer;
  touch-action: none;
}

.set-group input[type="range"]::-moz-range-thumb {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  cursor: pointer;
}

.set-group input[type="range"]::-webkit-slider-runnable-track {
  height: 8px;
  border-radius: 4px;
}

.set-group input[type="range"]::-moz-range-track {
  height: 8px;
  border-radius: 4px;
}

.ghost-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  justify-content: flex-start;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 13.5px;
  font-family: inherit;
  padding: 10px 12px;
  cursor: pointer;
  margin-bottom: 8px;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.ghost-btn:hover { border-color: var(--accent); color: var(--text); }
.ghost-btn svg { width: 16px; height: 16px; color: var(--accent); }

.shortcut {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 0;
  font-size: 13.5px;
  border-bottom: 1px solid var(--border);
}
.shortcut:last-child { border-bottom: none; }
.shortcut span:first-child {
  font-family: "Cascadia Code", "SF Mono", Consolas, monospace;
  font-size: 12.5px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 8px;
  color: var(--text);
  white-space: nowrap;
}
.shortcut span:last-child { color: var(--text-dim); }

/* ================= v7 · Lina ================= */

/* ---- display settings (html classes) ---- */

html.fs-small .msg-content { font-size: 13px; }
html.fs-small .msg-content code { font-size: 12px; }
html.fs-small .msg.user .msg-body { font-size: 13px; }
html.fs-small .composer-box textarea { font-size: 13px; }
html.fs-small .empty-state h2 { font-size: 21px; }

html.fs-large .msg-content { font-size: 16px; line-height: 1.75; }
html.fs-large .msg-content code { font-size: 14px; }
html.fs-large .msg.user .msg-body { font-size: 16px; }
html.fs-large .composer-box textarea { font-size: 16px; }
html.fs-large .empty-state h2 { font-size: 28px; }

html.density-compact .messages { gap: 14px; padding-top: 18px; }
html.density-compact .msg-meta { margin-top: 4px; }
html.density-compact .composer-wrap { padding-top: 8px; }
html.density-compact .followup { margin-top: 4px; }

html.no-anim *,
html.no-anim *::before,
html.no-anim *::after { animation: none !important; transition: none !important; }

/* ---- brand glow ---- */

.brand { position: relative; }
.brand-glow {
  position: absolute;
  left: 0;
  top: 0;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(77, 107, 254, 0.4), transparent 70%);
  filter: blur(5px);
  pointer-events: none;
  animation: glowPulse 3s ease-in-out infinite;
}
@keyframes glowPulse {
  0%, 100% { opacity: 0.7; transform: scale(0.9); }
  50% { opacity: 1; transform: scale(1.15); }
}
.brand-logo, .brand-name { position: relative; }

/* ---- gradient text ---- */

.gradient-text {
  background: linear-gradient(90deg, #4d6bfe, #7a5cff);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
}

/* ---- header pill clickable ---- */

.pill { cursor: pointer; }
.pill:hover { color: var(--text); border-color: var(--border-strong); }

/* ---- composer toolbar ---- */

.composer-tools {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
  flex-wrap: wrap;
  min-height: 30px;
}
.tool-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-dim);
  font-size: 12.5px;
  font-family: inherit;
  padding: 5px 10px;
  cursor: pointer;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.tool-btn:hover { color: var(--text); border-color: var(--accent); }
.tool-btn svg { width: 14px; height: 14px; }
.tool-btn .ic-mute { display: none; }
.tool-btn.muted { opacity: 0.65; }
.tool-btn.muted .ic-sound { display: none; }
.tool-btn.muted .ic-mute { display: block; }
.tool-select {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 12.5px;
  font-family: inherit;
  padding: 5px 8px;
  cursor: pointer;
  outline: none;
  max-width: 150px;
}
.tool-select:focus { border-color: var(--accent); }
.tool-spacer { flex: 1; }
.char-count {
  font-size: 11.5px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* ---- typing label ---- */

.thinking { display: flex; flex-direction: column; }
.typing-label {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 4px;
  padding-left: 2px;
}

/* ---- segmented controls ---- */

.seg {
  display: flex;
  gap: 4px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px;
  margin-bottom: 8px;
}
.seg:last-child { margin-bottom: 0; }
.seg-btn {
  flex: 1;
  background: none;
  border: none;
  border-radius: 7px;
  color: var(--text-dim);
  font-size: 13px;
  font-family: inherit;
  padding: 7px 8px;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}
.seg-btn:hover { color: var(--text); }
.seg-btn.active {
  background: var(--input-bg);
  color: var(--text);
  font-weight: 600;
  box-shadow: var(--shadow);
}

/* ---- switches ---- */

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  font-size: 13.5px;
  cursor: pointer;
}
.switch { position: relative; display: inline-block; width: 38px; height: 22px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute;
  inset: 0;
  background: var(--border-strong);
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.2s;
}
.slider::before {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  left: 2px;
  top: 2px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  transition: transform 0.2s;
}
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(16px); }

/* =================== Mobile / Tablet =================== */

@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
    height: 100dvh;
  }
  .sidebar.open { transform: translateX(0); }
  .menu-btn { display: block; }
  .suggestions { grid-template-columns: 1fr; }
  .messages { padding: 20px 14px 6px; }
  .composer-wrap { padding: 10px 12px 8px; }

  /* Keep composer visible above the mobile keyboard */
  .composer-wrap {
    position: sticky;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10;
    background: var(--bg);
  }

  /* Ensure chat area scrolls behind the composer */
  .chat-area {
    height: calc(100dvh - 0px);
    padding-bottom: 120px;
  }

  /* Reduce composer vertical padding on small screens */
  .composer-box {
    border-radius: 14px;
    padding: 10px 12px;
  }

  .composer-tools {
    gap: 5px;
  }

  .tool-select {
    max-width: 120px;
  }
  .tool-btn {
    padding: 5px 8px;
  }
  .tool-btn svg {
    display: none;
  }
  .followup { padding-left: 0; }
  .msg-actions { padding-left: 0; }
  .msg.user .msg-actions { padding-right: 0; }

  /* Make the textarea more thumb-friendly */
  .composer-box textarea {
    font-size: 16px; /* Prevents iOS zoom on focus */
    line-height: 1.5;
    max-height: 120px;
    padding: 4px 0;
  }

  .send-btn { width: 34px; height: 34px; }
  .stop-btn { width: 34px; height: 34px; }
  .attach-btn { width: 30px; height: 30px; }
  .attach-btn svg { width: 18px; height: 18px; }

  /* Touch-friendly segmented controls */
  .seg-btn {
    padding: 10px 12px;
    font-size: 14px;
    min-height: 44px;
  }

  /* Touch-friendly range slider */
  .set-group input[type="range"] {
    height: 36px;
    padding: 0;
    margin: 4px 0;
  }

  /* Wider tap targets for header buttons */
  .header-btn { width: 44px; height: 44px; }
  .menu-btn svg { width: 24px; height: 24px; }

  /* Wider tap targets for sidebar bottom buttons */
  .icon-btn { width: 40px; height: 40px; }
  .theme-toggle { width: 40px; height: 40px; }

  /* Make model selection radios easier to tap */
  .radio-row {
    padding: 14px 12px;
    min-height: 50px;
  }

  /* Full-width panels on mobile */
  .panel {
    width: calc(100vw - 24px);
    max-height: calc(100dvh - 48px);
    padding: 18px;
  }
  .panel-header h3 { font-size: 17px; }

  /* Hide the empty-state logo animation on low-power devices */
  @media (prefers-reduced-motion: reduce) {
    .empty-logo { animation: none; }
    .msg { animation: none; }
    .panel { animation: none; }
    .brand-glow { animation: none; }
  }
}

@media (max-width: 480px) {
  .sidebar {
    width: 280px;
  }
  .capability-chips {
    gap: 6px;
    justify-content: center;
  }
  .chat-item {
    font-size: 13px;
    padding: 10px 12px;
  }
  .suggestions {
    grid-template-columns: 1fr;
    gap: 10px;
  }
  .msg.assistant .msg-body {
    gap: 10px;
  }
  .msg-avatar {
    width: 28px;
    height: 28px;
    border-radius: 8px;
  }
  .msg-content {
    font-size: 14px;
    line-height: 1.6;
  }
  .msg.user .msg-body {
    font-size: 14px;
  }
  .empty-state {
    padding: 20px 16px;
  }
  .empty-state h2 { font-size: 20px; }
  .empty-state > p { font-size: 13px; }
}

/* Fix for iOS Safari dynamic toolbar */
@supports (height: 100dvh) {
  .app { height: 100dvh; }
  .main { height: 100dvh; }
  .chat-area { height: 100dvh; }
}

/* Prevent overscroll bounce causing double-tap zoom issues */
html, body {
  -webkit-touch-callout: default;
}
.composer-box textarea {
  -webkit-touch-callout: default;
  -webkit-user-select: text;
  user-select: text;
}

/* ---- responsive: settings grid collapses to one column ---- */
@media (max-width: 900px) {
  .panel.panel-wide { width: calc(100vw - 32px); }
  .set-grid { grid-template-columns: 1fr; }
}
