:root {
  --bg: #ffffff;
  --sidebar: #f9f9f9;
  --surface: #ffffff;
  --surface-2: #f4f4f4;
  --hover: #ececec;
  --text: #0d0d0d;
  --text-2: #5d5d5d;
  --muted: #8f8f8f;
  --border: #e5e5e5;
  --border-strong: #d0d0d0;
  --accent: #0f766e;
  --accent-soft: #e3f3f0;
  --user-bubble: #f1f1f1;
  --code-bg: #f9f9f9;
  --code-head: #ececec;
  --danger: #d92d20;
  --warn: #b54708;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.12);
  --composer-shadow: 0 2px 12px rgba(0, 0, 0, 0.06), 0 0 0 1px rgba(0, 0, 0, 0.06);
  --radius: 18px;
  --thread: 768px;
  --h-accent: #0f766e;
  --h1-from: #0f766e;
  --h1-to: #2563eb;
  --strong: #134e4a;
  --link: #2563eb;
  --code-inline-bg: #fdf2f8;
  --code-inline: #be185d;
  --mark: #fef3c7;
  --c-note: #2563eb;
  --c-tip: #16a34a;
  --c-important: #7c3aed;
  --c-warning: #d97706;
  --c-caution: #dc2626;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #212121;
    --sidebar: #171717;
    --surface: #2f2f2f;
    --surface-2: #2a2a2a;
    --hover: #2f2f2f;
    --text: #ececec;
    --text-2: #b4b4b4;
    --muted: #8a8a8a;
    --border: #3a3a3a;
    --border-strong: #4a4a4a;
    --accent: #34c3b1;
    --accent-soft: #1f3b37;
    --user-bubble: #303030;
    --code-bg: #171717;
    --code-head: #2b2b2b;
    --danger: #f97066;
    --warn: #fdb022;
    --shadow: 0 8px 28px rgba(0, 0, 0, 0.5);
    --composer-shadow: 0 0 0 1px rgba(255, 255, 255, 0.08);
    --h-accent: #5eead4;
    --h1-from: #5eead4;
    --h1-to: #93c5fd;
    --strong: #a7f3d0;
    --link: #7dd3fc;
    --code-inline-bg: #3b1f2e;
    --code-inline: #f9a8d4;
    --mark: #4a3b10;
    --c-note: #60a5fa;
    --c-tip: #4ade80;
    --c-important: #c4b5fd;
    --c-warning: #fbbf24;
    --c-caution: #f87171;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 16px/1.65 ui-sans-serif, -apple-system, "Segoe UI", system-ui, Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: 0.45; }
svg { width: 20px; height: 20px; flex: none; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.hidden { display: none !important; }
.muted { color: var(--text-2); }
.error { color: var(--danger); min-height: 1.2em; margin: 0; font-size: 14px; }
.grow { flex: 1; }
code { font: 0.875em/1.5 ui-monospace, "SF Mono", "Cascadia Code", Consolas, monospace; }

.btn-primary {
  background: var(--text);
  color: var(--bg);
  border: 0;
  border-radius: 999px;
  padding: 9px 18px;
  font-weight: 600;
}
.btn-primary:hover { opacity: 0.85; }
.btn-ghost { background: transparent; border: 1px solid var(--border); border-radius: 999px; padding: 6px 14px; font-size: 14px; }
.btn-ghost:hover { background: var(--hover); }
.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  background: transparent;
  border: 0;
  border-radius: 8px;
  color: var(--text-2);
}
.icon-btn:hover { background: var(--hover); color: var(--text); }

input, select, textarea {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 9px 12px;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--border-strong); }

/* ---------- login ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: min(360px, 100%);
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: center;
}
.login-card h1 { margin: 4px 0 0; font-size: 28px; letter-spacing: -0.02em; }
.login-card p { margin: 0 0 8px; }
.login-card input { border-radius: 999px; padding: 12px 18px; }
.login-card .btn-primary { padding: 12px; }
.login-logo { width: 56px; height: 56px; margin: 0 auto; }

/* ---------- layout ---------- */
.app { display: flex; height: 100%; height: 100dvh; overflow: hidden; }
.sidebar {
  width: 260px;
  flex: none;
  background: var(--sidebar);
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  gap: 2px;
}
.sidebar-top { display: flex; align-items: center; justify-content: space-between; padding: 4px 4px 8px 8px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; font-size: 16px; }
.brand img { width: 24px; height: 24px; }
.side-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 14px;
}
.side-item svg { width: 18px; height: 18px; color: var(--text-2); }
.side-item:hover { background: var(--hover); }
.side-item.strong { font-weight: 500; }
.side-search { display: flex; align-items: center; gap: 8px; padding: 0 10px; margin: 2px 0 6px; border-radius: 10px; }
.side-search svg { width: 17px; height: 17px; color: var(--muted); }
.side-search input { border: 0; background: transparent; padding: 7px 0; font-size: 14px; width: 100%; }
.side-search:focus-within { background: var(--hover); }
.conversation-list { flex: 1; overflow-y: auto; min-height: 0; padding-bottom: 8px; }
.conv-group { font-size: 12px; font-weight: 600; color: var(--muted); padding: 14px 10px 4px; }
.conv-item {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  border-radius: 10px;
  padding: 7px 10px;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.conv-item:hover { background: var(--hover); }
.conv-item.active { background: var(--hover); font-weight: 500; }
.sidebar-bottom { border-top: 1px solid var(--border); padding-top: 6px; display: flex; flex-direction: column; gap: 1px; }
.badge { margin-left: auto; font-size: 12px; color: var(--muted); }
.mode-note { font-size: 12px; color: var(--muted); margin: 6px 10px 2px; }
.backdrop { display: none; }

.limit-mini {
  display: grid;
  gap: 6px;
  width: 100%;
  background: transparent;
  border: 0;
  border-radius: 10px;
  padding: 8px 10px;
  text-align: left;
}
.limit-mini:hover { background: var(--hover); }
.limit-row { display: grid; grid-template-columns: 44px 1fr 38px; align-items: center; gap: 8px; font-size: 12px; color: var(--text-2); }
.limit-row span:last-child { text-align: right; }
.bar { height: 5px; border-radius: 999px; background: var(--border); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: inherit; transition: width 0.4s ease; }
.bar.warn > i { background: var(--warn); }
.bar.full > i { background: var(--danger); }

.main { flex: 1; min-width: 0; min-height: 0; display: flex; flex-direction: column; position: relative; }
.view { flex: 1; display: flex; flex-direction: column; min-height: 0; position: relative; }
.chat-header {
  display: flex;
  align-items: center;
  gap: 4px;
  height: 56px;
  padding: 0 10px;
  padding-top: env(safe-area-inset-top);
  flex: none;
}
.page-title { margin: 0 0 0 6px; font-size: 18px; font-weight: 600; }
.only-mobile { display: none !important; }

/* ---------- dropdown menus ---------- */
.dropdown { position: relative; }
.model-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: 0;
  border-radius: 10px;
  padding: 7px 10px;
  font-size: 17px;
}
.model-btn:hover { background: var(--hover); }
.model-title { font-weight: 600; }
.model-sub { color: var(--text-2); }
.chev { width: 16px; height: 16px; color: var(--muted); }
.menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 30;
  min-width: 300px;
  max-width: min(380px, 92vw);
  max-height: 70vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 6px;
}
.menu.right { left: auto; right: 0; min-width: 200px; }
.menu.up { top: auto; bottom: calc(100% + 8px); }
.menu-label { font-size: 12px; color: var(--muted); padding: 8px 10px 4px; }
.menu-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 14px;
}
.menu-item:hover { background: var(--hover); }
.menu-item.danger { color: var(--danger); }
.menu-item .mi-text { flex: 1; display: grid; }
.menu-item .mi-desc { font-size: 12.5px; color: var(--text-2); line-height: 1.4; }
.menu-item .mi-check { width: 18px; height: 18px; color: var(--text); visibility: hidden; margin-top: 2px; }
.menu-item.selected .mi-check { visibility: visible; }
.tag { display: inline-block; white-space: nowrap; font-size: 11px; line-height: 1.6; color: var(--text-2); border: 1px solid var(--border); border-radius: 999px; padding: 0 6px; margin-left: 6px; }
.menu-sep { height: 1px; background: var(--border); margin: 4px 6px; }

/* ---------- thread ---------- */
.scroller { flex: 1; overflow-y: auto; min-height: 0; scroll-behavior: auto; }
.thread { max-width: var(--thread); margin: 0 auto; padding: 8px 20px 40px; }
.hero { display: none; }
.chat-view.empty .scroller { display: flex; flex-direction: column; justify-content: flex-end; }
.chat-view.empty .hero { display: block; text-align: center; padding: 0 20px 28px; }
.hero h1 { font-size: 28px; font-weight: 600; letter-spacing: -0.02em; margin: 0 0 18px; }
.suggestions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; max-width: 640px; margin: 0 auto; }
.suggestions button {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 14px;
  color: var(--text-2);
}
.suggestions button:hover { background: var(--hover); color: var(--text); }
.chat-view.empty .composer-wrap { margin-bottom: 18vh; }

.msg { margin: 0 0 28px; }
.msg.user { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.msg.user .bubble {
  background: var(--user-bubble);
  border-radius: 22px;
  padding: 10px 18px;
  max-width: 80%;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.msg.user .msg-actions { opacity: 0; }
.msg.user:hover .msg-actions { opacity: 1; }

.att-row { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 8px; justify-content: flex-end; max-width: 80%; }
.att-thumb { width: 140px; height: 140px; object-fit: cover; border-radius: 14px; border: 1px solid var(--border); display: block; }
.file-card {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  max-width: 260px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 8px 12px 8px 8px;
  text-decoration: none;
  color: inherit;
}
.file-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: #e8590c;
  color: #fff;
  flex: none;
}
.file-icon.pdf { background: #e03131; }
.file-icon.doc { background: #1971c2; }
.file-icon.sheet { background: #2f9e44; }
.file-icon.code { background: #6741d9; }
.file-icon.txt { background: #868e96; }
.file-icon svg { width: 18px; height: 18px; }
.file-meta { min-width: 0; display: grid; line-height: 1.3; }
.file-name { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-sub { font-size: 12px; color: var(--text-2); }

/* assistant */
.msg.assistant { position: relative; }
.thinking { margin: 0 0 10px; }
.thinking summary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-2);
  font-size: 14px;
  cursor: pointer;
  list-style: none;
  user-select: none;
}
.thinking summary::-webkit-details-marker { display: none; }
.thinking summary::after { content: "›"; transform: rotate(90deg); transition: transform 0.15s; font-size: 16px; }
.thinking[open] summary::after { transform: rotate(-90deg); }
.thinking.live summary { background: linear-gradient(90deg, var(--text-2), var(--border-strong), var(--text-2)); background-size: 200% 100%; -webkit-background-clip: text; background-clip: text; color: transparent; animation: shimmer 1.6s linear infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }
.thinking-body {
  margin: 8px 0 4px 4px;
  padding: 2px 0 2px 14px;
  border-left: 2px solid var(--border);
  color: var(--text-2);
  font-size: 14px;
  white-space: pre-wrap;
  max-height: 320px;
  overflow-y: auto;
}

.md { overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 14px; }
.md h1, .md h2, .md h3, .md h4 { line-height: 1.3; margin: 24px 0 10px; font-weight: 650; }
.md h1 { font-size: 1.5em; }
.md h2 { font-size: 1.3em; }
.md h3 { font-size: 1.15em; }
.md h4 { font-size: 1em; }
.md ul, .md ol { margin: 0 0 14px; padding-left: 26px; }
.md li { margin: 4px 0; }
.md li > p { margin: 0 0 6px; }
.md li::marker { color: var(--text-2); }
.md strong { font-weight: 650; }
.md a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.md hr { border: 0; border-top: 1px solid var(--border); margin: 22px 0; }
.md blockquote { margin: 0 0 14px; padding: 2px 0 2px 16px; border-left: 3px solid var(--border-strong); color: var(--text-2); }
.md :not(pre) > code { background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: 1px 5px; }
.md img { max-width: 100%; border-radius: 12px; }
.code-block { margin: 0 0 16px; border-radius: 12px; overflow: hidden; border: 1px solid var(--border); background: var(--code-bg); }
.code-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--code-head);
  padding: 4px 6px 4px 14px;
  font-size: 12px;
  color: var(--text-2);
}
.code-head button {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: transparent;
  border: 0;
  border-radius: 6px;
  padding: 3px 8px;
  font-size: 12px;
  color: var(--text-2);
}
.code-head button:hover { background: var(--hover); color: var(--text); }
.code-head svg { width: 14px; height: 14px; }
.code-block pre { margin: 0; padding: 14px 16px; overflow-x: auto; }
.code-block pre code, .code-block pre code.hljs { background: transparent; padding: 0; font-size: 13.5px; line-height: 1.6; }
.table-wrap { overflow-x: auto; margin: 0 0 16px; border: 1px solid var(--border); border-radius: 12px; }
.md table { border-collapse: collapse; width: 100%; font-size: 14.5px; }
.md th, .md td { padding: 9px 12px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--border); }
.md th { background: var(--surface-2); font-weight: 600; }
.md tr:last-child td { border-bottom: 0; }
.md tbody tr:hover { background: var(--surface-2); }

.cursor::after { content: ""; display: inline-block; width: 10px; height: 10px; margin-left: 4px; border-radius: 50%; background: var(--text); vertical-align: middle; animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(0.6); opacity: 0.5; } }

.msg-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 2px; margin-top: 6px; color: var(--text-2); }
.msg-actions .icon-btn { width: 32px; height: 32px; }
.msg-actions .icon-btn svg { width: 17px; height: 17px; }
.msg-meta { font-size: 12.5px; color: var(--muted); margin-left: 6px; }
.msg-memories { font-size: 12.5px; color: var(--muted); margin-left: 6px; }
.msg-memories summary { cursor: pointer; }
.msg-memories ul { margin: 6px 0 0; padding-left: 18px; color: var(--text-2); }

.to-bottom {
  position: absolute;
  left: 50%;
  bottom: 150px;
  transform: translateX(-50%);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  display: grid;
  place-items: center;
  box-shadow: var(--shadow-sm);
  z-index: 5;
}
.to-bottom svg { width: 18px; height: 18px; }

/* ---------- composer ---------- */
.composer-wrap { flex: none; padding: 0 16px calc(6px + env(safe-area-inset-bottom)); }
.composer {
  max-width: var(--thread);
  margin: 0 auto;
  background: var(--surface);
  border-radius: 28px;
  box-shadow: var(--composer-shadow);
  padding: 10px 10px 8px;
  display: flex;
  flex-direction: column;
}
.composer textarea {
  border: 0;
  background: transparent;
  resize: none;
  padding: 6px 10px 4px;
  max-height: 38vh;
  min-height: 28px;
  overflow-y: hidden;
  line-height: 1.5;
}
.composer-bar { display: flex; align-items: center; gap: 6px; padding-top: 4px; }
.round-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: transparent;
  display: grid;
  place-items: center;
  color: var(--text);
}
.round-btn:hover { background: var(--hover); }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: transparent;
  padding: 0 12px;
  font-size: 14px;
  color: var(--text-2);
}
.chip svg { width: 17px; height: 17px; }
.chip:hover { background: var(--hover); color: var(--text); }
.chip.on { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.send-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 0;
  background: var(--text);
  color: var(--bg);
  display: grid;
  place-items: center;
}
.send-btn:disabled { opacity: 0.25; }
.send-btn svg { width: 19px; height: 19px; }
.disclaimer { text-align: center; font-size: 12px; color: var(--muted); margin: 8px 0 2px; }
.chat-view.empty .disclaimer { visibility: hidden; }

.attach-list { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 8px; padding: 2px 4px 6px; }
.attach-list:empty { display: none; }
.pending { position: relative; }
.pending .att-thumb { width: 60px; height: 60px; border-radius: 12px; }
.pending .file-card { max-width: 230px; }
.pending .remove {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 0;
  background: var(--text);
  color: var(--bg);
  display: grid;
  place-items: center;
  padding: 0;
}
.pending .remove svg { width: 12px; height: 12px; }
.pending.uploading .file-card, .pending.uploading .att-thumb { opacity: 0.55; }
.pending.failed .file-card { border-color: var(--danger); }
.spinner { width: 16px; height: 16px; border: 2px solid var(--border); border-top-color: var(--text); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.limit-banner {
  max-width: var(--thread);
  margin: 0 auto 8px;
  border-radius: 14px;
  padding: 9px 14px;
  font-size: 14px;
  background: var(--accent-soft);
}
.limit-banner.warn { background: color-mix(in srgb, var(--warn) 14%, transparent); }
.limit-banner.full { background: color-mix(in srgb, var(--danger) 14%, transparent); }

.drop-overlay {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(2px);
  pointer-events: none;
}
.drop-overlay > div {
  border: 2px dashed var(--border-strong);
  border-radius: 24px;
  padding: 36px 48px;
  text-align: center;
  color: var(--text-2);
}
.drop-overlay svg { width: 40px; height: 40px; }
.drop-overlay p { margin: 8px 0 0; font-weight: 500; }

/* ---------- panels ---------- */
.panel { flex: 1; overflow-y: auto; padding: 8px 20px 40px; width: 100%; max-width: 820px; margin: 0 auto; }
.panel h3 { font-size: 16px; margin: 26px 0 8px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 14px 16px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row > input, .row > select { flex: 1; min-width: 140px; }
.memory-form { display: flex; flex-direction: column; gap: 8px; margin: 12px 0 18px; }
.memory-form textarea { width: 100%; resize: vertical; }
.memory-toolbar { margin-bottom: 12px; }
.memory-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.memory-item { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 10px 14px; }
.memory-item.profile { border-left: 4px solid var(--accent); }
.memory-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.memory-item textarea { width: 100%; resize: vertical; }
.memory-meta { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; margin-top: 6px; font-size: 12px; color: var(--text-2); }
.memory-meta .spacer { flex: 1; }
.memory-meta button { background: transparent; border: 1px solid var(--border); border-radius: 999px; padding: 2px 10px; font-size: 12px; }
.memory-meta button:hover { background: var(--hover); }
.kind-tag { background: var(--accent-soft); border-radius: 999px; padding: 1px 8px; }
.empty-note { color: var(--muted); text-align: center; padding: 24px 0; }
.conv-empty { color: var(--muted); font-size: 13px; padding: 12px 10px; }

.limit-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 10px; }
.limit-card .big { font-size: 22px; font-weight: 650; margin: 2px 0 8px; }
.limit-card .bar { height: 8px; }
.limit-card p { margin: 8px 0 0; font-size: 13px; color: var(--text-2); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; font-size: 14px; }
.kv dt { color: var(--text-2); }
.kv dd { margin: 0; }

.usage-table { width: 100%; border-collapse: collapse; margin: 6px 0 20px; font-size: 14px; }
.usage-table th, .usage-table td { border-bottom: 1px solid var(--border); padding: 8px 10px; text-align: right; }
.usage-table th:first-child, .usage-table td:first-child { text-align: left; }
.usage-table th { font-size: 13px; color: var(--text-2); font-weight: 600; }
.usage-table tr.total td { font-weight: 650; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(120px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 14px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  max-width: calc(100% - 32px);
  text-align: center;
  z-index: 50;
}
.toast.show { opacity: 1; }

/* ---------- v3: lists, selection, skills, personalization ---------- */
.list-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 10px 0; font-size: 12px; font-weight: 600; color: var(--muted); }
.link-btn { background: transparent; border: 0; color: var(--text-2); font-size: 13px; padding: 2px 6px; border-radius: 6px; }
.link-btn:hover { background: var(--hover); color: var(--text); }
.danger-btn {
  display: inline-flex; align-items: center; gap: 4px;
  background: transparent; border: 1px solid color-mix(in srgb, var(--danger) 45%, transparent);
  color: var(--danger); border-radius: 999px; padding: 4px 10px; font-size: 13px;
}
.danger-btn svg { width: 15px; height: 15px; }
.danger-btn:not(:disabled):hover { background: color-mix(in srgb, var(--danger) 10%, transparent); }
.select-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 6px 8px; margin: 4px 0; border-radius: 10px; background: var(--hover); font-size: 13px; }
#select-count { white-space: nowrap; color: var(--text-2); }
.select-bar label { display: inline-flex; align-items: center; gap: 4px; }
input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); margin: 0; padding: 0; }

.conv-row { display: flex; align-items: center; border-radius: 10px; position: relative; }
.conv-row:hover, .conv-row.active { background: var(--hover); }
.conv-row .conv-item { flex: 1; min-width: 0; background: transparent; }
.conv-row .conv-item:hover { background: transparent; }
.conv-row .conv-check { margin-left: 10px; }
.conv-more { width: 28px; height: 28px; margin-right: 4px; visibility: hidden; }
.conv-more svg { width: 16px; height: 16px; }
.conv-row:hover .conv-more, .conv-row.active .conv-more, .conv-more.open { visibility: visible; }
.selecting .conv-more { display: none; }
.conv-row.checked { background: var(--accent-soft); }
.menu.floating { position: fixed; min-width: 170px; }

.menu-search { position: sticky; top: -6px; background: var(--surface); padding: 4px 4px 6px; z-index: 1; }
.menu-search input { width: 100%; border-radius: 10px; padding: 7px 10px; font-size: 14px; }
.menu-note { font-size: 12.5px; color: var(--text-2); padding: 4px 10px 8px; line-height: 1.45; }
.menu-item.locked { opacity: 0.55; cursor: not-allowed; }
.menu-item.locked:hover { background: transparent; }
.tag.free { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 40%, transparent); }
.tag.lock { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, transparent); }
.menu-empty { padding: 12px 10px; color: var(--muted); font-size: 14px; }

.bulk-bar { align-items: center; margin-bottom: 10px; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; color: var(--text-2); }
.btn-ghost { display: inline-flex; align-items: center; gap: 4px; }
.btn-ghost svg { width: 16px; height: 16px; }
.memory-item { display: flex; gap: 10px; align-items: flex-start; }
.memory-item > input[type="checkbox"] { margin-top: 5px; flex: none; }
.memory-body { flex: 1; min-width: 0; }
.memory-item.checked { background: var(--accent-soft); }

.cleanup-panel { margin-bottom: 14px; display: grid; gap: 10px; }
.cleanup-panel h4 { margin: 4px 0 0; font-size: 14px; }
.suggestion { display: flex; gap: 10px; align-items: flex-start; padding: 8px 10px; border: 1px solid var(--border); border-radius: 12px; }
.suggestion > input { margin-top: 5px; flex: none; }
.suggestion .why { font-size: 12.5px; color: var(--text-2); }
.suggestion .orig { font-size: 13px; color: var(--text-2); margin: 4px 0 0; padding-left: 16px; }
.suggestion textarea { width: 100%; margin-top: 6px; resize: vertical; }
.suggestion .grow-col { flex: 1; min-width: 0; }

.personal-form, .skill-form { display: grid; gap: 8px; margin: 12px 0 16px; }
.personal-form label { font-weight: 600; font-size: 14px; margin-top: 6px; }
.personal-form textarea, .skill-form textarea { width: 100%; resize: vertical; }
.counter { font-size: 12px; color: var(--muted); text-align: right; margin-top: -4px; }
.skill-list { display: grid; gap: 10px; margin-top: 12px; }
.skill-card { display: grid; gap: 6px; }
.skill-card h4 { margin: 0; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.skill-card h4 svg { width: 18px; height: 18px; color: var(--accent); }
.skill-card .desc { color: var(--text-2); font-size: 14px; }
.skill-card pre {
  margin: 0; white-space: pre-wrap; font-family: inherit; font-size: 13px; line-height: 1.5; color: var(--text-2);
  max-height: 4.5em; overflow: hidden; background: var(--surface-2); border-radius: 10px; padding: 8px 10px;
}
.skill-card .actions { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
.skill-card .actions button { font-size: 13px; }
.panel a { color: var(--accent); }


/* ---------- v4: colorful answers ---------- */
.md h1 { background: linear-gradient(90deg, var(--h1-from), var(--h1-to)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.md h2 { color: var(--h-accent); padding-bottom: 6px; border-bottom: 1px solid color-mix(in srgb, var(--h-accent) 25%, transparent); }
.md h3 { color: var(--h-accent); }
.md h4 { color: var(--text); }
.md strong { color: var(--strong); }
.md em { color: var(--text-2); }
.md a { color: var(--link); }
.md li::marker { color: var(--h-accent); font-weight: 600; }
.md ol > li::marker { color: var(--h-accent); }
.md :not(pre) > code { background: var(--code-inline-bg); color: var(--code-inline); border-color: transparent; }
.md mark { background: var(--mark); color: inherit; border-radius: 4px; padding: 0 3px; }
.md hr { height: 2px; border: 0; background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--h-accent) 55%, transparent), transparent); }
.md blockquote { border-left: 3px solid var(--h-accent); background: color-mix(in srgb, var(--h-accent) 6%, transparent); border-radius: 0 10px 10px 0; padding: 8px 14px; color: var(--text); }
.md input[type="checkbox"] { margin-right: 6px; vertical-align: -2px; }
.md li:has(> input[type="checkbox"]) { list-style: none; margin-left: -20px; }
.table-wrap { border-color: color-mix(in srgb, var(--h-accent) 25%, var(--border)); }
.md th { background: color-mix(in srgb, var(--h-accent) 12%, var(--surface)); color: var(--text); }
.md tbody tr:nth-child(even) { background: color-mix(in srgb, var(--h-accent) 3%, transparent); }
.md tbody tr:hover { background: color-mix(in srgb, var(--h-accent) 8%, transparent); }

.code-block { background: #282c34; border: 0; box-shadow: var(--shadow-sm); }
.code-head { background: #21252b; color: #abb2bf; }
.code-head span:first-child { color: #61afef; font-weight: 600; text-transform: lowercase; }
.code-head button { color: #abb2bf; }
.code-head button:hover { background: #2c313a; color: #ffffff; }
.code-block pre code, .code-block pre code.hljs { color: #abb2bf; }

.callout { --c: var(--c-note); margin: 0 0 16px; padding: 10px 14px; border-radius: 12px; border: 1px solid color-mix(in srgb, var(--c) 35%, transparent); border-left: 4px solid var(--c); background: color-mix(in srgb, var(--c) 9%, transparent); }
.callout-title { display: flex; align-items: center; gap: 6px; font-weight: 650; color: var(--c); margin-bottom: 4px; }
.callout-title svg { width: 18px; height: 18px; }
.callout > :last-child { margin-bottom: 0; }
.callout.tip { --c: var(--c-tip); }
.callout.important { --c: var(--c-important); }
.callout.warning { --c: var(--c-warning); }
.callout.caution { --c: var(--c-caution); }

/* ---------- v4: dialogs ---------- */
.modal { border: 0; padding: 0; border-radius: 20px; background: var(--surface); color: var(--text); box-shadow: var(--shadow); width: min(440px, 92vw); }
.modal::backdrop { background: rgba(0, 0, 0, 0.45); backdrop-filter: blur(2px); }
.modal-card { padding: 20px 20px 16px; display: grid; gap: 12px; }
.modal-card h3 { margin: 0; font-size: 18px; }
.modal-body { color: var(--text-2); font-size: 15px; display: grid; gap: 10px; }
.modal-body input[type="text"] { width: 100%; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.btn-danger { background: var(--danger); color: #fff; border: 0; border-radius: 999px; padding: 9px 18px; font-weight: 600; }
.btn-danger:hover { filter: brightness(1.08); }
.choice { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--border); border-radius: 14px; cursor: pointer; color: var(--text); }
.choice:hover { background: var(--hover); }
.choice:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.choice input { margin-top: 4px; accent-color: var(--accent); }
.choice small { display: block; color: var(--text-2); font-size: 13px; }
.choice.disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- v4: personalization preview, memory import ---------- */
.personal-saved { margin: 0 0 16px; display: grid; gap: 10px; }
.personal-saved h3 { margin: 6px 0 0; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.personal-saved .when { font-size: 12.5px; color: var(--muted); font-weight: 400; }
.saved-card { border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--border)); background: color-mix(in srgb, var(--accent) 5%, var(--surface)); border-radius: 14px; padding: 10px 14px; }
.saved-card b { display: block; font-size: 13px; color: var(--accent); margin-bottom: 2px; }
.saved-card p { margin: 0; white-space: pre-wrap; }
.import-box { margin-bottom: 14px; }
.import-box summary { cursor: pointer; font-size: 14px; color: var(--text-2); }
.import-box[open] summary { margin-bottom: 8px; }

/* ---------- mobile ---------- */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(300px, 85vw);
    z-index: 20;
    transform: translateX(-102%);
    transition: transform 0.2s ease;
    padding-top: calc(8px + env(safe-area-inset-top));
  }
  .app.sidebar-open .sidebar { transform: none; box-shadow: var(--shadow); }
  .app.sidebar-open .backdrop { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, 0.4); z-index: 10; }
  .only-mobile { display: inline-grid !important; }
  .thread { padding: 8px 14px 32px; }
  .msg.user .bubble, .att-row { max-width: 90%; }
  .composer-wrap { padding: 0 10px calc(4px + env(safe-area-inset-bottom)); }
  .hero h1 { font-size: 24px; }
  .chat-view.empty .composer-wrap { margin-bottom: 8vh; }
  .model-btn { font-size: 16px; }
  .msg.user .msg-actions { opacity: 1; }
  .conv-more { visibility: visible; }
  .composer-bar { flex-wrap: wrap; }
  .chip { padding: 0 10px; }
  .chip-prefix { display: none; }
  .composer-bar { flex-wrap: nowrap; }
  #skill-label { max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

/* ---------- AI provider settings ---------- */
.provider-mode { display: grid; gap: 10px; }
.mode-option { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--border); border-radius: 12px; cursor: pointer; }
.mode-option.selected { border-color: var(--accent); background: var(--accent-soft); }
.mode-option input { margin-top: 4px; accent-color: var(--accent); }
.mode-option > span { display: grid; gap: 2px; font-size: 14px; }
.mode-sub { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: -2px 0 4px 34px; font-size: 14px; }
.mode-sub.column { flex-direction: column; align-items: flex-start; }
.mode-sub select { width: auto; min-width: 240px; }
.check-row { display: flex; flex-wrap: wrap; gap: 6px 16px; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; }
.check input { accent-color: var(--accent); }
.list-title { align-items: center; margin-top: 18px; }
.list-title h3 { margin: 0; }
.provider-list { display: grid; gap: 12px; margin-top: 12px; }
.provider-card { display: grid; gap: 10px; }
.provider-card.disabled { opacity: 0.62; }
.provider-head { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; }
.provider-head svg { width: 18px; height: 18px; color: var(--accent); }
.provider-head b { font-size: 15px; }
.provider-card code { font-size: 13px; word-break: break-all; }
.provider-card .actions { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
.provider-card .actions button { font-size: 13px; }
.provider-card .actions button:disabled { opacity: 0.4; cursor: default; }
.tag.on { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 45%, transparent); background: var(--accent-soft); }
.tag.off { color: var(--muted); }
.status { font-size: 13px; }
.status.good, .test-result.good { color: var(--accent); }
.status.bad, .test-result.bad { color: var(--danger); }
.provider-form { display: grid; gap: 10px; margin-top: 12px; border-color: var(--accent); }
.provider-form h4 { margin: 0; font-size: 15px; }
.provider-form .field { display: grid; gap: 4px; font-size: 14px; }
.provider-form .field > span:first-child { color: var(--text-2); }
.provider-form .small { font-size: 12px; }
.provider-form input:disabled { opacity: 0.6; }
.test-result { font-size: 14px; min-height: 1.2em; }

/* ---------- memory recall preview ---------- */
.recall-result { display: grid; gap: 4px; font-size: 14px; }
.recall-result h4 { margin: 8px 0 0; font-size: 14px; }
.recall-result ul { margin: 0; padding-left: 20px; }
.recall-sum { margin: 6px 0 0; color: var(--accent); font-weight: 600; }
.memory-meta .hits { color: var(--accent); }

/* ---------- password ---------- */
.password-form { display: grid; gap: 10px; max-width: 520px; }
.password-form .field { display: grid; gap: 4px; font-size: 14px; }
.password-form .field > span { color: var(--text-2); }
.password-form .small { font-size: 12px; margin: 0; }
.pw-strength { font-size: 13px; min-height: 1.2em; }
#forgot-btn { margin-top: 4px; justify-self: center; }

.login-show { justify-content: flex-start; font-size: 14px; color: var(--text-2); }
