/* Chatcase — local-first AI chat */
:root {
  --primary: #2f6b5f;
  --primary-ink: #ffffff;
  --border: #e3ded3;
  --bg-color: #f4efe5;
  --bg-image: none;
  --bg-opacity: 1;
  --bg-blur: 0px;
  --user-bg: #2f6b5f;
  --user-text: #ffffff;
  --user-radius: 20px;
  --user-border-color: transparent;
  --ai-bg: #ffffff;
  --ai-text: #232826;
  --ai-radius: 20px;
  --ai-border-color: var(--border);
  --msg-font-size: 15px;

  --ink: #232a27;
  --muted: #6d746f;
  --faint: #939993;
  --danger: #b64b40;
  --danger-soft: #f6e7e3;
  --surface: rgba(255, 255, 255, 0.55);
  --surface-strong: rgba(252, 251, 248, 0.9);
  --surface-soft: rgba(255, 255, 255, 0.34);
  --topbar-bg: color-mix(in srgb, var(--primary) 4%, rgba(252, 251, 248, 0.82));
  --focus-ring: color-mix(in srgb, var(--primary) 20%, transparent);
  --shadow-soft: 0 16px 44px -26px rgba(31, 39, 34, 0.35);
  --shadow-card: 0 20px 60px -34px rgba(31, 39, 34, 0.45);
  --font-ui: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --font-mono: "SFMono-Regular", "SF Mono", "JetBrains Mono", "Cascadia Code", ui-monospace, Menlo, Consolas, monospace;
  --composer-height: 150px;
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  overflow: hidden;
  background: #fbfaf6;
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior: none;
}

button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:disabled { cursor: default; }
img { max-width: 100%; }
::selection { background: color-mix(in srgb, var(--primary) 26%, transparent); }
[hidden] { display: none !important; }

* { scrollbar-width: thin; scrollbar-color: color-mix(in srgb, var(--muted) 30%, transparent) transparent; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--muted) 26%, transparent);
  border-radius: 99px;
  border: 2px solid transparent;
  background-clip: content-box;
}

:focus-visible { outline: 2px solid color-mix(in srgb, var(--primary) 72%, white); outline-offset: 2px; }

.icon-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.bg-layer {
  position: fixed;
  inset: -72px;
  z-index: 0;
  background-color: var(--bg-color);
  background-image: var(--bg-image);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  opacity: var(--bg-opacity);
  filter: blur(var(--bg-blur));
  transform: scale(1.015);
  transition: background-color 0.3s ease, opacity 0.25s ease, filter 0.25s ease;
  pointer-events: none;
}

.app {
  position: relative;
  z-index: 1;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* ---------- Topbar ---------- */
.topbar {
  flex: none;
  z-index: 20;
  height: calc(60px + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) clamp(12px, 3.5vw, 24px) 0;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  background: var(--topbar-bg);
  -webkit-backdrop-filter: blur(22px) saturate(1.35);
  backdrop-filter: blur(22px) saturate(1.35);
  border-bottom: 1px solid color-mix(in srgb, var(--border) 78%, transparent);
}

.topbar-side { display: flex; align-items: center; gap: 2px; min-width: 0; }
.topbar-side-right { justify-content: flex-end; }

.topbar-title {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 0;
  color: var(--primary);
  font-weight: 650;
  letter-spacing: -0.02em;
  font-size: 16px;
}
.topbar-title-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: min(46vw, 420px);
}
.brand-mark {
  width: 24px;
  height: 24px;
  border-radius: 7px;
  display: grid;
  place-items: center;
  color: var(--primary-ink);
  background: var(--primary);
  box-shadow: 0 4px 12px -6px color-mix(in srgb, var(--primary) 70%, transparent);
  flex: none;
}
.brand-mark svg { width: 19px; height: 19px; }

.icon-btn {
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 11px;
  background: transparent;
  color: color-mix(in srgb, var(--ink) 68%, var(--muted));
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.16s ease, color 0.16s ease;
}
.icon-btn:hover { background: color-mix(in srgb, var(--primary) 8%, transparent); color: var(--primary); }
.icon-btn:active { background: color-mix(in srgb, var(--primary) 13%, transparent); }
.icon-btn.tiny { width: 26px; height: 26px; border-radius: 8px; }
.icon-btn.tiny .icon { width: 15px; height: 15px; }

/* ---------- Chat area ---------- */
.chat {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  position: relative;
  -webkit-overflow-scrolling: touch;
}
.chat-inner {
  width: min(100%, 900px);
  min-height: 100%;
  margin: 0 auto;
  padding: 20px clamp(14px, 4vw, 32px) 30px;
  display: flex;
  flex-direction: column;
}

.empty-state {
  flex: 1 1 auto;
  min-height: calc(100dvh - 270px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: clamp(26px, 7vh, 78px) 4px 36px;
  animation: fade-up 0.45s ease both;
}
.empty-mark {
  width: 66px;
  height: 66px;
  border-radius: 21px;
  display: grid;
  place-items: center;
  color: var(--primary);
  background: color-mix(in srgb, var(--primary) 9%, var(--surface-strong));
  border: 1px solid color-mix(in srgb, var(--primary) 16%, var(--border));
  box-shadow: var(--shadow-soft), inset 0 1px 0 rgba(255, 255, 255, 0.5);
  margin-bottom: 24px;
}
.empty-mark svg { width: 46px; height: 46px; }

.eyebrow {
  margin: 0 0 9px;
  font-size: 10px;
  line-height: 1.4;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: color-mix(in srgb, var(--primary) 62%, var(--muted));
}
.empty-state h1 {
  margin: 0 0 13px;
  font-size: clamp(27px, 6.2vw, 40px);
  line-height: 1.16;
  letter-spacing: -0.045em;
  font-weight: 650;
  color: var(--ink);
}
.empty-lead {
  max-width: 31em;
  margin: 0 auto 22px;
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.78;
}
.empty-actions { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 9px; }
.empty-tags {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px 14px;
  margin-top: 24px;
  color: var(--faint);
  font-size: 10.5px;
  letter-spacing: 0.02em;
}
.empty-tags span + span::before { content: "·"; margin-right: 14px; color: color-mix(in srgb, var(--primary) 45%, var(--faint)); }
.empty-suggestions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 7px;
  margin-top: 22px;
}
.empty-suggestions button {
  border: 1px solid color-mix(in srgb, var(--border) 82%, transparent);
  background: color-mix(in srgb, white 36%, transparent);
  color: var(--muted);
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 11.5px;
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  transition: color 0.16s ease, border-color 0.16s ease, background-color 0.16s ease;
}
.empty-suggestions button:hover {
  color: var(--primary);
  border-color: color-mix(in srgb, var(--primary) 30%, var(--border));
  background: color-mix(in srgb, var(--primary) 6%, white 40%);
}

.messages { display: flex; flex-direction: column; gap: 18px; }
.msg { display: flex; flex-direction: column; min-width: 0; animation: msg-in 0.22s ease both; }
.msg.user { align-items: flex-end; }
.msg.assistant { align-items: flex-start; }

.msg .bubble {
  position: relative;
  min-width: 0;
  max-width: 100%;
  padding: 13px 15px;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.msg.user .bubble {
  max-width: min(86%, 640px);
  background: var(--user-bg);
  color: var(--user-text);
  border: 1px solid var(--user-border-color);
  border-radius: var(--user-radius);
  box-shadow: 0 14px 30px -22px color-mix(in srgb, var(--user-bg) 85%, transparent);
}
.msg.assistant .bubble {
  width: min(100%, 770px);
  max-width: min(100%, 770px);
  background: var(--ai-bg);
  color: var(--ai-text);
  border: 1px solid var(--ai-border-color);
  border-radius: var(--ai-radius);
  box-shadow: 0 4px 26px -20px rgba(30, 38, 33, 0.55);
}

.msg-foot {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 24px;
  margin-top: 2px;
  padding: 0 3px;
  color: var(--faint);
  font-size: 10.5px;
}
.msg-action {
  border: 0;
  background: transparent;
  color: var(--faint);
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 6px;
  border-radius: 7px;
  font-size: 10.5px;
  transition: color 0.15s ease, background-color 0.15s ease;
}
.msg-action:hover { color: var(--primary); background: color-mix(in srgb, var(--primary) 8%, transparent); }
.msg-action .icon { width: 13px; height: 13px; }
.stopped-note { color: var(--faint); padding-left: 4px; }

/* Attachments inside messages */
.msg-attachments { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 9px; }
.msg-attachments:last-child { margin-bottom: 0; }
.msg-image {
  width: min(158px, 44vw);
  border: 0;
  padding: 0;
  border-radius: 12px;
  overflow: hidden;
  background: color-mix(in srgb, currentColor 8%, transparent);
  cursor: zoom-in;
  display: block;
  line-height: 0;
}
.msg-image img { width: 100%; height: auto; max-height: 190px; object-fit: cover; display: block; }
.msg-file {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  max-width: 100%;
  padding: 6px 9px;
  border-radius: 9px;
  border: 1px solid color-mix(in srgb, currentColor 15%, transparent);
  background: color-mix(in srgb, currentColor 7%, transparent);
  font-size: 11px;
  line-height: 1.4;
  color: inherit;
}
.msg-file .icon { width: 14px; height: 14px; opacity: 0.72; }
.msg-file .file-name { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-file .file-size { opacity: 0.6; flex: none; }

/* Web search note */
.msg-extras { margin-top: 7px; max-width: min(100%, 640px); }
.search-note {
  border: 1px solid color-mix(in srgb, var(--border) 75%, transparent);
  background: var(--surface-soft);
  border-radius: 11px;
  padding: 7px 10px;
  color: var(--muted);
  font-size: 11px;
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}
.search-note summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 7px;
  user-select: none;
}
.search-note summary::-webkit-details-marker { display: none; }
.search-note summary::after {
  content: "";
  width: 5px;
  height: 5px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(45deg) translateY(-2px);
  margin-left: auto;
  opacity: 0.55;
  transition: transform 0.15s ease;
}
.search-note[open] summary::after { transform: rotate(-135deg) translateY(-1px); }
.search-note .icon { width: 13px; height: 13px; }
.search-note.is-error { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 22%, transparent); background: color-mix(in srgb, var(--danger) 6%, var(--surface-soft)); }
.search-error-text { margin: 8px 0 0; font-size: 10.5px; line-height: 1.6; white-space: pre-wrap; overflow-wrap: anywhere; color: color-mix(in srgb, var(--danger) 82%, var(--muted)); }
.search-pending { display: flex; align-items: center; gap: 7px; }
.search-results { margin: 8px 0 0; padding-left: 17px; display: grid; gap: 5px; line-height: 1.5; }
.search-results a { color: var(--primary); text-decoration: none; }
.search-results a:hover { text-decoration: underline; text-underline-offset: 2px; }
.search-pending .search-spinner {
  width: 11px;
  height: 11px;
  border: 1.5px solid color-mix(in srgb, var(--primary) 25%, transparent);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* Reasoning panel */
.reasoning {
  margin: 0 0 10px;
  padding: 8px 10px;
  border-radius: max(9px, calc(var(--ai-radius) * 0.55));
  border: 1px dashed color-mix(in srgb, var(--muted) 26%, transparent);
  background: color-mix(in srgb, var(--muted) 5%, transparent);
  color: color-mix(in srgb, currentColor 76%, transparent);
  font-size: 12px;
}
.reasoning summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: color-mix(in srgb, currentColor 62%, transparent);
  user-select: none;
}
.reasoning summary::-webkit-details-marker { display: none; }
.reasoning summary::before {
  content: "";
  width: 5px;
  height: 5px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(-45deg);
  margin-left: 1px;
  opacity: 0.65;
  transition: transform 0.15s ease;
}
.reasoning[open] summary::before { transform: rotate(45deg) translate(-1px, -1px); }
.reasoning-duration { margin-left: auto; font-weight: 500; color: color-mix(in srgb, currentColor 48%, transparent); font-variant-numeric: tabular-nums; }
.reasoning-body {
  margin-top: 7px;
  max-height: 300px;
  overflow-y: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.68;
  font-size: 11.5px;
}
body.follow-theme .msg .reasoning {
  border-color: color-mix(in srgb, var(--primary) 25%, transparent);
  background: color-mix(in srgb, var(--primary) 7%, transparent);
}

/* Typing and cursor */
.typing { display: inline-flex; align-items: center; gap: 4px; height: 20px; }
.typing span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.26;
  animation: dot-pulse 1.25s infinite ease-in-out;
}
.typing span:nth-child(2) { animation-delay: 0.14s; }
.typing span:nth-child(3) { animation-delay: 0.28s; }
.stream-cursor {
  display: inline-block;
  width: 2px;
  height: 1.05em;
  margin-left: 2px;
  border-radius: 2px;
  background: currentColor;
  opacity: 0.48;
  vertical-align: -0.12em;
  animation: cursor-blink 1s steps(1) infinite;
}

/* ---------- Rendered content ---------- */
.msg-content {
  font-size: var(--msg-font-size);
  line-height: 1.76;
  letter-spacing: 0.002em;
  min-width: 0;
}
.msg-content > :first-child { margin-top: 0 !important; }
.msg-content > :last-child { margin-bottom: 0 !important; }
.msg-content p { margin: 0.64em 0; }
.msg-content h1, .msg-content h2, .msg-content h3, .msg-content h4, .msg-content h5, .msg-content h6 {
  margin: 1.15em 0 0.48em;
  line-height: 1.35;
  font-weight: 650;
  letter-spacing: -0.015em;
}
.msg-content h1 { font-size: 1.38em; }
.msg-content h2 { font-size: 1.23em; }
.msg-content h3 { font-size: 1.1em; }
.msg-content h4, .msg-content h5, .msg-content h6 { font-size: 1em; }
.msg-content strong { font-weight: 650; }
.msg-content em { font-style: italic; }
.msg-content ul, .msg-content ol { margin: 0.62em 0; padding-left: 1.38em; }
.msg-content li { margin: 0.23em 0; padding-left: 0.1em; }
.msg-content li > p { margin: 0.2em 0; }
.msg-content li::marker { color: color-mix(in srgb, var(--primary) 62%, currentColor); }
.msg-content a { color: var(--primary); text-decoration: underline; text-decoration-color: color-mix(in srgb, var(--primary) 36%, transparent); text-underline-offset: 3px; }
.msg-content a:hover { text-decoration-color: currentColor; }
.msg.user .msg-content a { color: inherit; text-decoration-color: currentColor; }
.msg-content hr { border: 0; border-top: 1px solid var(--panel-border, var(--border)); margin: 1.2em 0; }
.msg-content blockquote {
  margin: 0.8em 0;
  padding: 8px 12px;
  border-left: 2px solid color-mix(in srgb, var(--primary) 60%, currentColor);
  background: var(--panel-bg, color-mix(in srgb, var(--muted) 5%, transparent));
  border-radius: 0 8px 8px 0;
  color: color-mix(in srgb, currentColor 78%, transparent);
}
.msg-content blockquote p { margin: 0.25em 0; }
.msg-content img { max-width: 100%; height: auto; border-radius: 10px; margin: 0.55em 0; cursor: zoom-in; }
.msg-content video, .msg-content audio { max-width: 100%; border-radius: 10px; }
.msg-content details { margin: 0.7em 0; padding: 8px 10px; border: 1px solid var(--panel-border, var(--border)); border-radius: 9px; background: var(--panel-bg, transparent); }
.msg-content summary { cursor: pointer; font-weight: 550; }
.msg-content kbd {
  font-family: var(--font-mono);
  font-size: 0.82em;
  padding: 0.14em 0.42em;
  border: 1px solid var(--panel-border, var(--border));
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--panel-bg, color-mix(in srgb, var(--muted) 6%, transparent));
}
.msg-content mark { background: color-mix(in srgb, var(--primary) 18%, transparent); color: inherit; padding: 0 0.15em; border-radius: 3px; }
.msg-content input[type="checkbox"] { accent-color: var(--primary); margin-right: 0.35em; vertical-align: -0.08em; }

.msg-content code {
  font-family: var(--font-mono);
  font-size: 0.86em;
  padding: 0.14em 0.38em;
  border-radius: 5px;
  background: color-mix(in srgb, currentColor 8%, transparent);
  border: 1px solid color-mix(in srgb, currentColor 9%, transparent);
  overflow-wrap: break-word;
}
.msg-content pre {
  position: relative;
  margin: 0.85em 0;
  padding: 13px 14px;
  border-radius: 11px;
  border: 1px solid var(--panel-border, color-mix(in srgb, currentColor 12%, transparent));
  background: var(--panel-bg, color-mix(in srgb, currentColor 5%, transparent));
  overflow: auto;
  font-size: 0.84em;
  line-height: 1.62;
  tab-size: 2;
}
.msg-content pre code {
  display: block;
  padding: 0;
  border: 0;
  background: transparent;
  font-size: 1em;
  white-space: pre;
  overflow-wrap: normal;
  word-break: normal;
}
.msg-content pre::-webkit-scrollbar { height: 6px; }

.code-copy {
  position: absolute;
  top: 7px;
  right: 7px;
  z-index: 2;
  border: 1px solid var(--panel-border, color-mix(in srgb, currentColor 14%, transparent));
  background: color-mix(in srgb, var(--ai-bg, white) 82%, transparent);
  color: var(--muted);
  border-radius: 7px;
  padding: 3px 7px;
  font-size: 10px;
  line-height: 1.5;
  opacity: 0;
  transition: opacity 0.15s ease, color 0.15s ease;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}
.msg-content pre:hover .code-copy, .code-copy:focus-visible { opacity: 1; }
.code-copy:hover { color: var(--primary); }
.code-copy.copied { color: var(--primary); opacity: 1; }

.msg-content .table-wrap { width: 100%; overflow-x: auto; margin: 0.8em 0; border-radius: 9px; border: 1px solid var(--panel-border, color-mix(in srgb, currentColor 12%, transparent)); }
.msg-content table { border-collapse: collapse; min-width: 100%; font-size: 0.9em; line-height: 1.55; }
.msg-content th, .msg-content td { padding: 7px 10px; border-bottom: 1px solid var(--panel-border, color-mix(in srgb, currentColor 12%, transparent)); border-right: 1px solid var(--panel-border, color-mix(in srgb, currentColor 10%, transparent)); text-align: left; vertical-align: top; }
.msg-content th:last-child, .msg-content td:last-child { border-right: 0; }
.msg-content tr:last-child td { border-bottom: 0; }
.msg-content th { background: var(--panel-head, color-mix(in srgb, currentColor 7%, transparent)); font-weight: 600; white-space: nowrap; }
.msg-content tbody tr:nth-child(even) td { background: color-mix(in srgb, currentColor 2%, transparent); }

body.follow-theme .msg.assistant {
  --panel-bg: color-mix(in srgb, var(--primary) 7%, var(--ai-bg));
  --panel-border: color-mix(in srgb, var(--primary) 20%, var(--border));
  --panel-head: color-mix(in srgb, var(--primary) 9%, var(--ai-bg));
}
body.follow-theme .msg.user {
  --panel-bg: color-mix(in srgb, var(--primary) 18%, var(--user-bg));
  --panel-border: color-mix(in srgb, currentColor 25%, transparent);
  --panel-head: color-mix(in srgb, currentColor 10%, transparent);
}
.msg.assistant { --panel-bg: color-mix(in srgb, var(--muted) 6%, transparent); --panel-border: color-mix(in srgb, var(--muted) 18%, transparent); --panel-head: color-mix(in srgb, var(--muted) 9%, transparent); }
.msg.user { --panel-bg: color-mix(in srgb, currentColor 9%, transparent); --panel-border: color-mix(in srgb, currentColor 18%, transparent); --panel-head: color-mix(in srgb, currentColor 12%, transparent); }

/* KaTeX */
.katex { font-size: 1.06em; color: inherit; }
.math-display { display: block; }
.math-inline { display: inline; }
.katex-display {
  margin: 0.85em 0;
  padding: 1px 0 3px;
  overflow-x: auto;
  overflow-y: hidden;
}
.katex-display > .katex { white-space: normal; }
.katex-display::-webkit-scrollbar { height: 5px; }
.katex-error { color: var(--danger) !important; font-family: var(--font-mono); font-size: 0.88em; overflow-wrap: anywhere; }
.msg.user .katex-error { color: #ffe0da !important; }

/* ---------- Composer ---------- */
.composer-zone {
  flex: none;
  position: relative;
  z-index: 16;
  padding: 8px clamp(10px, 4vw, 26px) calc(9px + env(safe-area-inset-bottom));
}
.composer-inner { width: min(100%, 800px); margin: 0 auto; }

.notice {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  padding: 8px 8px 8px 11px;
  border-radius: 12px;
  border: 1px solid color-mix(in srgb, var(--primary) 16%, var(--border));
  background: color-mix(in srgb, var(--primary) 7%, var(--surface-strong));
  color: color-mix(in srgb, var(--ink) 82%, var(--primary));
  font-size: 11.5px;
  line-height: 1.5;
  box-shadow: 0 8px 24px -20px rgba(25, 32, 28, 0.4);
  animation: fade-up 0.2s ease;
}
.notice.error { border-color: color-mix(in srgb, var(--danger) 24%, var(--border)); background: color-mix(in srgb, var(--danger) 7%, var(--surface-strong)); color: var(--danger); }
.notice-icon { width: 15px; height: 15px; color: var(--primary); flex: none; }
.notice.error .notice-icon { color: var(--danger); }
.notice-text { flex: 1; min-width: 0; overflow-wrap: anywhere; white-space: pre-wrap; }
.notice-action { flex: none; color: var(--primary); font-weight: 600; white-space: nowrap; }
.notice.error .notice-action { color: var(--danger); }

.attachment-strip {
  display: flex;
  gap: 7px;
  overflow-x: auto;
  padding: 0 2px 8px;
  scrollbar-width: none;
}
.attachment-strip::-webkit-scrollbar { display: none; }
.attach-chip {
  flex: none;
  display: flex;
  align-items: center;
  gap: 7px;
  max-width: 210px;
  height: 38px;
  padding: 4px 5px 4px 6px;
  border-radius: 10px;
  border: 1px solid color-mix(in srgb, var(--border) 88%, transparent);
  background: var(--surface-strong);
  box-shadow: 0 6px 18px -16px rgba(30, 37, 32, 0.4);
  font-size: 10.5px;
  color: var(--muted);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
}
.attach-chip img { width: 28px; height: 28px; border-radius: 6px; object-fit: cover; }
.attach-chip .icon { width: 16px; height: 16px; color: var(--primary); }
.attach-chip .chip-name { max-width: 108px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink); }
.attach-chip .chip-size { flex: none; opacity: 0.55; }
.attach-remove { width: 22px; height: 22px; flex: none; border: 0; border-radius: 6px; background: transparent; color: var(--faint); display: grid; place-items: center; }
.attach-remove:hover { background: color-mix(in srgb, var(--danger) 9%, transparent); color: var(--danger); }
.attach-remove .icon { width: 12px; height: 12px; }

.composer {
  border: 1px solid color-mix(in srgb, var(--border) 88%, transparent);
  background: var(--surface-strong);
  -webkit-backdrop-filter: blur(20px) saturate(1.2);
  backdrop-filter: blur(20px) saturate(1.2);
  border-radius: 20px;
  padding: 8px 9px 8px 13px;
  box-shadow: 0 18px 50px -32px rgba(28, 36, 31, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.4);
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}
.composer:focus-within {
  border-color: color-mix(in srgb, var(--primary) 34%, var(--border));
  box-shadow: 0 18px 50px -32px rgba(28, 36, 31, 0.55), 0 0 0 2px color-mix(in srgb, var(--primary) 11%, transparent);
}
#promptInput {
  display: block;
  width: 100%;
  min-height: 26px;
  max-height: 152px;
  margin: 0;
  padding: 5px 5px 7px 2px;
  border: 0;
  outline: 0;
  resize: none;
  background: transparent;
  color: var(--ink);
  font-size: 15px;
  line-height: 1.62;
}
#promptInput::placeholder { color: var(--faint); }
.composer-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.composer-tools { display: flex; align-items: center; gap: 2px; min-width: 0; }

.tool-btn {
  height: 32px;
  min-width: 32px;
  padding: 0 8px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  font-size: 11.5px;
  transition: color 0.15s ease, background-color 0.15s ease, border-color 0.15s ease;
}
.tool-btn .icon { width: 17px; height: 17px; }
.tool-btn.icon-only { padding: 0; }
.tool-btn:hover { color: var(--primary); background: color-mix(in srgb, var(--primary) 7%, transparent); }
.tool-btn[aria-pressed="true"] {
  color: var(--primary);
  background: color-mix(in srgb, var(--primary) 10%, transparent);
  border-color: color-mix(in srgb, var(--primary) 16%, transparent);
}
.tool-btn:disabled { opacity: 0.38; }

.send-btn {
  width: 38px;
  height: 38px;
  flex: none;
  border: 0;
  border-radius: 12px;
  background: var(--primary);
  color: var(--primary-ink);
  display: grid;
  place-items: center;
  box-shadow: 0 8px 18px -10px color-mix(in srgb, var(--primary) 68%, transparent);
  transition: filter 0.15s ease, transform 0.12s ease, opacity 0.15s ease;
}
.send-btn .icon { width: 20px; height: 20px; stroke-width: 2; }
.send-btn .stop-icon { display: none; }
.send-btn:hover { filter: brightness(1.06); }
.send-btn:active { transform: scale(0.96); }
.send-btn[disabled] { opacity: 0.4; box-shadow: none; }
.send-btn.streaming .send-icon { display: none; }
.send-btn.streaming .stop-icon { display: block; }

.composer-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 5px 0;
  min-width: 0;
}
.model-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  max-width: 64%;
  padding: 2px 0;
  border: 0;
  background: none;
  color: var(--faint);
  font-size: 10.5px;
  text-align: left;
}
.model-chip > span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.model-chip:hover { color: var(--primary); }
.status-dot { width: 6px; height: 6px; border-radius: 50%; flex: none; background: var(--faint); box-shadow: 0 0 0 2px color-mix(in srgb, var(--faint) 14%, transparent); }
.model-chip.ready .status-dot { background: var(--primary); box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary) 16%, transparent); }
.model-chip.missing .status-dot { background: #bf8a3e; box-shadow: 0 0 0 2px rgba(191, 138, 62, 0.16); }
.kbd-hint { color: var(--faint); font-size: 10px; white-space: nowrap; letter-spacing: 0.01em; }

/* ---------- Buttons ---------- */
.primary-btn, .ghost-btn, .outline-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-radius: 11px;
  padding: 9px 15px;
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1.35;
  transition: filter 0.15s ease, background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.1s ease;
}
.primary-btn { border: 0; background: var(--primary); color: var(--primary-ink); box-shadow: 0 10px 24px -16px color-mix(in srgb, var(--primary) 76%, transparent); }
.primary-btn:hover { filter: brightness(1.055); }
.primary-btn:active { transform: translateY(1px); }
.primary-btn.wide { width: 100%; }
.primary-btn .icon, .ghost-btn .icon { width: 15px; height: 15px; }
.ghost-btn {
  border: 1px solid color-mix(in srgb, var(--border) 92%, transparent);
  background: color-mix(in srgb, white 36%, transparent);
  color: color-mix(in srgb, var(--ink) 78%, var(--muted));
}
.ghost-btn:hover { border-color: color-mix(in srgb, var(--primary) 28%, var(--border)); color: var(--primary); }
.ghost-btn.small { padding: 6px 11px; font-size: 11.5px; border-radius: 9px; }
.text-btn { border: 0; background: none; color: var(--primary); font-size: 11.5px; padding: 3px 1px; font-weight: 550; white-space: nowrap; }
.text-btn:hover { text-decoration: underline; text-underline-offset: 3px; }
.outline-btn {
  border: 1px solid color-mix(in srgb, var(--border) 95%, transparent);
  background: transparent;
  color: var(--muted);
  font-weight: 500;
}
.outline-btn:hover { border-color: color-mix(in srgb, var(--primary) 30%, var(--border)); color: var(--primary); }
.outline-btn.danger, .danger-text { color: var(--danger); }
.outline-btn.danger:hover { border-color: color-mix(in srgb, var(--danger) 35%, var(--border)); color: var(--danger); }

/* ---------- Overlay / Drawer / Sheet ---------- */
.scrim {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(21, 27, 23, 0.26);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}
body.overlay-open .scrim { opacity: 1; pointer-events: auto; }

.drawer {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 60;
  width: min(344px, 88vw);
  display: flex;
  flex-direction: column;
  background: color-mix(in srgb, var(--surface-strong) 94%, var(--bg-color));
  -webkit-backdrop-filter: blur(26px) saturate(1.2);
  backdrop-filter: blur(26px) saturate(1.2);
  border-right: 1px solid color-mix(in srgb, var(--border) 80%, transparent);
  box-shadow: 30px 0 80px -40px rgba(20, 27, 22, 0.6);
  transform: translateX(-103%);
  transition: transform 0.3s cubic-bezier(0.22, 0.8, 0.24, 1);
  visibility: hidden;
}
body.history-open .drawer { transform: none; visibility: visible; }
.drawer-head {
  flex: none;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: calc(22px + env(safe-area-inset-top)) 16px 15px 20px;
  border-bottom: 1px solid color-mix(in srgb, var(--border) 68%, transparent);
}
.drawer-head h2, .sheet-head h2 { margin: 0; font-size: 22px; letter-spacing: -0.035em; font-weight: 640; }
.drawer-head .eyebrow, .sheet-head .eyebrow { margin-bottom: 5px; }
.drawer-body { flex: 1; overflow-y: auto; padding: 12px 10px; }
.history-list { display: flex; flex-direction: column; gap: 3px; }
.history-item { display: flex; align-items: stretch; border-radius: 11px; overflow: hidden; }
.history-item.active { background: color-mix(in srgb, var(--primary) 9%, transparent); }
.history-main {
  flex: 1;
  min-width: 0;
  border: 0;
  background: none;
  text-align: left;
  padding: 10px 8px 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  border-radius: 11px;
}
.history-main:hover { background: color-mix(in srgb, var(--ink) 4%, transparent); }
.history-item.active .history-main:hover { background: transparent; }
.history-title { font-size: 12.5px; font-weight: 550; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-item.active .history-title { color: var(--primary); }
.history-meta { font-size: 10px; color: var(--faint); display: flex; gap: 7px; }
.history-del {
  flex: none;
  width: 34px;
  border: 0;
  background: none;
  color: var(--faint);
  opacity: 0;
  transition: opacity 0.15s ease, color 0.15s ease;
}
.history-item:hover .history-del { opacity: 1; }
.history-del:hover { color: var(--danger); }
.history-del .icon { width: 14px; height: 14px; }
.history-empty { padding: 28px 14px; text-align: center; color: var(--faint); font-size: 12px; line-height: 1.7; }
.drawer-foot {
  flex: none;
  padding: 12px 16px calc(14px + env(safe-area-inset-bottom));
  border-top: 1px solid color-mix(in srgb, var(--border) 68%, transparent);
}
.local-only { display: flex; align-items: center; justify-content: center; gap: 5px; margin: 9px 0 0; color: var(--faint); font-size: 10px; }
.local-only .icon { width: 12px; height: 12px; }

.sheet {
  position: fixed;
  z-index: 70;
  top: 0;
  right: 0;
  height: 100dvh;
  width: min(580px, 100%);
  display: flex;
  flex-direction: column;
  background: color-mix(in srgb, var(--surface-strong) 95%, var(--bg-color));
  -webkit-backdrop-filter: blur(30px) saturate(1.2);
  backdrop-filter: blur(30px) saturate(1.2);
  border-left: 1px solid color-mix(in srgb, var(--border) 80%, transparent);
  box-shadow: -30px 0 90px -44px rgba(20, 27, 22, 0.6);
  transform: translateX(103%);
  transition: transform 0.32s cubic-bezier(0.22, 0.8, 0.24, 1);
  visibility: hidden;
}
body.settings-open .sheet { transform: none; visibility: visible; }
.sheet-head {
  flex: none;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: calc(22px + env(safe-area-inset-top)) 20px 12px;
}
.sheet-tabs {
  flex: none;
  display: flex;
  gap: 3px;
  padding: 0 20px 12px;
  border-bottom: 1px solid color-mix(in srgb, var(--border) 68%, transparent);
  overflow-x: auto;
  scrollbar-width: none;
}
.sheet-tabs::-webkit-scrollbar { display: none; }
.tab-btn {
  flex: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  padding: 7px 12px;
  border-radius: 8px;
  transition: color 0.15s ease, background-color 0.15s ease;
}
.tab-btn:hover { color: var(--ink); background: color-mix(in srgb, var(--ink) 4%, transparent); }
.tab-btn.active { color: var(--primary); background: color-mix(in srgb, var(--primary) 10%, transparent); font-weight: 600; }
.sheet-body { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 18px 20px calc(40px + env(safe-area-inset-bottom)); }
.tab-panel { display: none; }
.tab-panel.active { display: block; animation: tab-in 0.22s ease both; }

.section { padding: 4px 0 22px; }
.section + .section { border-top: 1px solid color-mix(in srgb, var(--border) 64%, transparent); padding-top: 22px; }
.section-head { margin-bottom: 13px; }
.section-head.with-action { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.section-head h3 { margin: 0 0 5px; font-size: 13.5px; font-weight: 650; letter-spacing: -0.01em; }
.section-head p { margin: 0; color: var(--muted); font-size: 11.5px; line-height: 1.65; max-width: 46em; }
.section-head.with-action > div { min-width: 0; }

.field { display: flex; flex-direction: column; gap: 6px; margin-top: 12px; }
.field:first-of-type { margin-top: 0; }
.field-label { font-size: 11px; color: var(--muted); font-weight: 500; }
.field input, .field select, .prompt-textarea, .tpl-edit input, .tpl-edit textarea {
  width: 100%;
  border: 1px solid color-mix(in srgb, var(--border) 92%, transparent);
  border-radius: 10px;
  background: color-mix(in srgb, white 46%, transparent);
  color: var(--ink);
  font-size: 13px;
  outline: 0;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}
.field input, .field select { height: 40px; padding: 0 11px; }
.field input:focus, .field select:focus, .prompt-textarea:focus, .tpl-edit input:focus, .tpl-edit textarea:focus {
  border-color: color-mix(in srgb, var(--primary) 48%, var(--border));
  box-shadow: 0 0 0 3px var(--focus-ring);
  background: color-mix(in srgb, white 60%, transparent);
}
.field input::placeholder, .prompt-textarea::placeholder, .tpl-edit textarea::placeholder { color: var(--faint); }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field-grid .field { margin-top: 12px; }
.field-hint { margin: 10px 0 0; color: var(--faint); font-size: 10.5px; line-height: 1.65; }
.field-hint:empty { display: none; }
.privacy-note {
  display: flex;
  gap: 7px;
  margin: 12px 0 0;
  padding: 9px 10px;
  border-radius: 9px;
  background: color-mix(in srgb, var(--primary) 5%, transparent);
  color: var(--muted);
  font-size: 10.5px;
  line-height: 1.6;
}
.privacy-note .icon { width: 13px; height: 13px; color: var(--primary); margin-top: 1px; flex: none; }

.select-wrap { position: relative; display: block; }
.select-wrap select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 34px;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='m1 1.5 5 5 5-5' fill='none' stroke='%237c837d' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}
.input-wrap { position: relative; display: block; }
.input-wrap input { padding-right: 42px; }
.input-action {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 32px;
  height: 32px;
  border: 0;
  background: transparent;
  border-radius: 7px;
  color: var(--faint);
  display: grid;
  place-items: center;
}
.input-action:hover { color: var(--primary); background: color-mix(in srgb, var(--primary) 7%, transparent); }
.input-action .icon { width: 16px; height: 16px; }

.color-row { display: flex; gap: 10px; flex-wrap: wrap; }
.color-field { flex: 1; min-width: 140px; display: flex; flex-direction: column; gap: 6px; }
.color-field-label { font-size: 11px; color: var(--muted); }
.color-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 5px 8px;
  border-radius: 10px;
  border: 1px solid color-mix(in srgb, var(--border) 92%, transparent);
  background: color-mix(in srgb, white 44%, transparent);
}
.color-pill.small { min-height: 32px; padding: 3px 6px; gap: 6px; }
.color-pill input[type="color"] {
  width: 24px;
  height: 24px;
  padding: 0;
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
  flex: none;
}
.color-pill.small input[type="color"] { width: 20px; height: 20px; border-radius: 5px; }
.color-pill input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.color-pill input[type="color"]::-webkit-color-swatch { border: 0; border-radius: 5px; }
.color-hex { font-family: var(--font-mono); font-size: 10.5px; color: color-mix(in srgb, var(--ink) 76%, var(--muted)); letter-spacing: -0.02em; }

.segmented {
  display: inline-flex;
  padding: 3px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--ink) 5%, transparent);
  gap: 2px;
}
.segmented button {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 6px 14px;
  border-radius: 8px;
  font-size: 11.5px;
  transition: color 0.15s ease, background-color 0.15s ease, box-shadow 0.15s ease;
}
.segmented button.active {
  background: color-mix(in srgb, white 82%, transparent);
  color: var(--ink);
  box-shadow: 0 2px 7px -4px rgba(25, 32, 27, 0.35);
}

.bg-colors { display: flex; flex-wrap: wrap; gap: 9px; margin-top: 13px; }
.bg-swatch {
  width: 53px;
  border: 0;
  background: none;
  padding: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  color: var(--muted);
  font-size: 10px;
}
.bg-swatch .swatch {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.08);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.32);
  transition: outline-color 0.15s ease, transform 0.15s ease;
}
.bg-swatch:hover .swatch { transform: scale(1.04); }
.bg-swatch.active { color: var(--primary); }
.bg-swatch.active .swatch { outline: 2px solid var(--primary); outline-offset: 2px; }

.bg-image-panel { display: flex; align-items: center; gap: 12px; margin-top: 12px; flex-wrap: wrap; }
.bg-preview {
  width: 112px;
  height: 68px;
  border-radius: 11px;
  border: 1px dashed color-mix(in srgb, var(--border) 110%, transparent);
  background: color-mix(in srgb, var(--ink) 4%, transparent);
  padding: 0;
  overflow: hidden;
  display: grid;
  place-items: center;
  color: var(--faint);
}
.bg-preview:hover { border-color: color-mix(in srgb, var(--primary) 40%, var(--border)); color: var(--primary); }
.bg-preview img { width: 100%; height: 100%; object-fit: cover; display: block; }
.bg-preview-empty { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 9.5px; }
.bg-preview-empty .icon { width: 20px; height: 20px; }
.bg-image-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.range-field { display: block; margin-top: 14px; color: var(--muted); font-size: 11px; }
.range-field > span { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 11px; }
.range-field output { color: color-mix(in srgb, var(--ink) 72%, var(--muted)); font-family: var(--font-mono); font-size: 10px; }
.range-field input[type="range"] {
  width: 100%;
  margin: 8px 0 0;
  accent-color: var(--primary);
  height: 18px;
  cursor: pointer;
}
.range-field.compact { margin-top: 10px; }
.bubble-settings { display: grid; grid-template-columns: repeat(auto-fit, minmax(215px, 1fr)); gap: 10px; }
.bubble-fieldset {
  margin: 0;
  padding: 11px 12px 12px;
  border: 1px solid color-mix(in srgb, var(--border) 88%, transparent);
  border-radius: 12px;
  background: color-mix(in srgb, white 30%, transparent);
  min-width: 0;
}
.bubble-fieldset legend { padding: 0 5px; font-size: 11px; font-weight: 600; color: var(--ink); }
.mini-color-row { display: flex; gap: 8px; flex-wrap: wrap; }
.mini-color { flex: 1; min-width: 94px; display: flex; flex-direction: column; gap: 5px; color: var(--muted); font-size: 10px; }
.mini-color .color-hex { font-size: 9px; }

.switch-row {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 12px;
  cursor: pointer;
  user-select: none;
}
.switch-copy { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.switch-title { font-size: 12px; color: var(--ink); font-weight: 500; }
.switch-desc { font-size: 10.5px; line-height: 1.6; color: var(--muted); }
.switch-input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.switch-ui {
  position: relative;
  flex: none;
  width: 37px;
  height: 22px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--muted) 26%, transparent);
  transition: background-color 0.18s ease;
}
.switch-ui::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 4px rgba(23, 31, 26, 0.24);
  transition: transform 0.18s cubic-bezier(0.22, 0.8, 0.24, 1);
}
.switch-input:checked + .switch-ui { background: var(--primary); }
.switch-input:checked + .switch-ui::after { transform: translateX(15px); }
.switch-input:focus-visible + .switch-ui { box-shadow: 0 0 0 3px var(--focus-ring); }
.switch-row.compact { margin-top: 8px; padding: 0; gap: 8px; }
.switch-row.compact .switch-title { font-size: 11px; color: var(--muted); font-weight: 500; }
.switch-row.compact .switch-ui { width: 32px; height: 19px; }
.switch-row.compact .switch-ui::after { width: 13px; height: 13px; }
.switch-row.compact .switch-input:checked + .switch-ui::after { transform: translateX(13px); }

.prompt-textarea { min-height: 148px; padding: 11px 12px; line-height: 1.7; resize: vertical; font-size: 12.5px; }
.prompt-meta { display: flex; justify-content: space-between; align-items: center; margin-top: 7px; color: var(--faint); font-size: 10px; }
.template-list { display: flex; flex-direction: column; gap: 9px; }
.template-card {
  border: 1px solid color-mix(in srgb, var(--border) 88%, transparent);
  border-radius: 12px;
  background: color-mix(in srgb, white 30%, transparent);
  padding: 11px 12px;
}
.template-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.template-head strong { font-size: 12px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.template-actions { display: flex; align-items: center; gap: 2px; flex: none; }
.template-actions button { border: 0; background: none; color: var(--primary); font-size: 10.5px; padding: 4px 6px; border-radius: 6px; }
.template-actions button:hover { background: color-mix(in srgb, var(--primary) 8%, transparent); }
.template-preview { margin: 5px 0 0; color: var(--muted); font-size: 10.5px; line-height: 1.65; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.tpl-edit { display: grid; gap: 7px; margin-top: 9px; }
.tpl-edit input { height: 34px; padding: 0 9px; font-size: 11.5px; }
.tpl-edit textarea { min-height: 96px; padding: 8px 9px; line-height: 1.65; resize: vertical; font-size: 11.5px; }
.tpl-edit-actions { display: flex; justify-content: flex-end; gap: 4px; }

.data-stats {
  margin: 0 0 11px;
  padding: 9px 10px;
  border-radius: 9px;
  background: color-mix(in srgb, var(--ink) 4%, transparent);
  color: var(--muted);
  font-size: 11px;
  line-height: 1.6;
}
.danger-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.about-section p { margin: 0 0 8px; color: var(--muted); font-size: 11.5px; line-height: 1.7; }
.about-section .version-line { color: var(--faint); font-family: var(--font-mono); font-size: 10px; margin: 14px 0 0; }

/* ---------- Jump button, lightbox, toast ---------- */
.jump-btn {
  position: fixed;
  left: 50%;
  bottom: calc(var(--composer-height, 150px) + 12px);
  transform: translate(-50%, 6px);
  z-index: 18;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid color-mix(in srgb, var(--border) 85%, transparent);
  background: var(--surface-strong);
  color: var(--muted);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  box-shadow: 0 8px 24px -14px rgba(25, 33, 28, 0.5);
  display: grid;
  place-items: center;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease, color 0.15s ease, visibility 0.18s;
}
.jump-btn.visible { opacity: 1; visibility: visible; pointer-events: auto; transform: translate(-50%, 0); }
.jump-btn:hover { color: var(--primary); }
.jump-btn .icon { width: 17px; height: 17px; }

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 110;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 44px 18px;
  background: rgba(13, 17, 15, 0.84);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  animation: fade-in 0.18s ease;
}
.lightbox img { max-width: 94vw; max-height: 84vh; border-radius: 10px; box-shadow: 0 30px 90px rgba(0, 0, 0, 0.45); }
.lightbox-close {
  position: absolute;
  top: max(14px, env(safe-area-inset-top));
  right: 14px;
  color: #fff;
  background: rgba(255, 255, 255, 0.1);
}
.lightbox-close:hover { background: rgba(255, 255, 255, 0.18); color: #fff; }

.toast-wrap {
  position: fixed;
  z-index: 120;
  left: 50%;
  bottom: calc(var(--composer-height, 150px) + 16px);
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100vw - 28px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  pointer-events: none;
}
.toast {
  background: color-mix(in srgb, #202823 93%, transparent);
  color: #f6f5f0;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 11.5px;
  line-height: 1.5;
  box-shadow: 0 12px 34px -18px rgba(0, 0, 0, 0.6);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  animation: toast-in 0.22s ease both;
  overflow-wrap: anywhere;
  text-align: center;
}
.toast.error { background: color-mix(in srgb, #7d342d 94%, transparent); }
.toast.leaving { animation: toast-out 0.2s ease both; }

/* ---------- Responsive ---------- */
@media (max-width: 720px) {
  .kbd-hint { display: none; }
  .model-chip { max-width: 100%; }
  .composer-meta { padding-top: 8px; }
  .empty-state h1 { letter-spacing: -0.04em; }
  .empty-tags { margin-top: 20px; }
  .empty-suggestions { margin-top: 18px; }
}

@media (max-width: 520px) {
  .topbar { height: calc(56px + env(safe-area-inset-top)); padding-left: 8px; padding-right: 8px; }
  .topbar-title { font-size: 15px; gap: 6px; }
  .brand-mark { width: 22px; height: 22px; border-radius: 6px; }
  .brand-mark svg { width: 17px; height: 17px; }
  .icon-btn { width: 36px; height: 36px; }
  .chat-inner { padding-top: 14px; padding-bottom: 22px; }
  .empty-state { min-height: calc(100dvh - 240px); padding-top: 20px; }
  .empty-mark { width: 58px; height: 58px; border-radius: 18px; margin-bottom: 20px; }
  .empty-mark svg { width: 40px; height: 40px; }
  .empty-lead { font-size: 12.5px; max-width: 25em; }
  .empty-tags { display: none; }
  .empty-suggestions button:nth-child(3) { display: none; }
  .msg .bubble { padding: 12px 13px; }
  .msg.user .bubble { max-width: 90%; }
  .msg-content { line-height: 1.72; }
  .composer-zone { padding-left: 8px; padding-right: 8px; }
  .composer { border-radius: 18px; padding-left: 10px; padding-right: 7px; }
  .field-grid { grid-template-columns: 1fr; gap: 0; }
  .field-grid .field { margin-top: 12px; }
  .field-grid .field + .field { margin-top: 10px; }
  .sheet-head { padding-left: 16px; padding-right: 16px; }
  .sheet-tabs { padding-left: 14px; padding-right: 14px; }
  .sheet-body { padding-left: 16px; padding-right: 16px; }
  .color-row { gap: 8px; }
  .color-field { min-width: 120px; }
  .bubble-settings { grid-template-columns: 1fr; }
  .notice { align-items: flex-start; }
  .notice .notice-action { margin-top: 1px; }
  .toast { font-size: 11px; }
}

@media (max-height: 660px) {
  .empty-state { min-height: 0; justify-content: center; padding-top: 18px; padding-bottom: 20px; }
  .empty-mark { display: none; }
  .empty-tags { display: none; }
  .empty-state h1 { font-size: clamp(24px, 5.4vw, 32px); margin-bottom: 8px; }
  .empty-lead { font-size: 12px; margin-bottom: 15px; line-height: 1.65; }
  .empty-suggestions { display: none; }
  .composer-meta { padding-top: 5px; }
}

@media (min-width: 900px) {
  .sheet {
    top: 14px;
    right: 14px;
    height: calc(100dvh - 28px);
    border-radius: 20px;
    border: 1px solid color-mix(in srgb, var(--border) 80%, transparent);
    overflow: hidden;
  }
  .sheet-head { padding-top: 20px; }
}

@media (hover: none) {
  .history-del { opacity: 0.55; }
  .code-copy { opacity: 0.78; }
}

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

@keyframes msg-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes fade-up { from { opacity: 0; transform: translateY(7px); } to { opacity: 1; transform: translateY(0); } }
@keyframes tab-in { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: translateY(0); } }
@keyframes dot-pulse { 0%, 60%, 100% { opacity: 0.24; transform: translateY(0); } 30% { opacity: 0.8; transform: translateY(-2px); } }
@keyframes cursor-blink { 0%, 49% { opacity: 0.5; } 50%, 100% { opacity: 0; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes toast-in { from { opacity: 0; transform: translateY(5px) scale(0.98); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(4px) scale(0.98); } }