/* ==========================================================
   Frojin Chat — one stylesheet.
   Colours at the top: light theme first, then dark.
   Fonts: Sora (headings), Plus Jakarta Sans (text), JetBrains Mono (code).
   Buttons: blue #1f6fd6. Same family as refoundspace.
   ========================================================== */

:root {
  --blue: #1f6fd6;
  --blue-hover: #2a82ea;
  --orange: #ff7a3d;
  --font-head: "Sora", system-ui, sans-serif;
  --font-body: "Plus Jakarta Sans", system-ui, sans-serif;
  --font-code: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --side-w: 280px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

/* Light (warm off-white, like the old Frojin) */
:root, [data-theme="light"] {
  --bg: #f4f2ed;
  --side: #eceae5;
  --side-border: #dcd9d2;
  --surface: #ffffff;
  --surface-2: #e3e0d9;
  --field: #e5e2db;
  --bubble: #e6e3dc;
  --card: #f7f6f2;
  --sheet: #fbfaf7;
  --code: #ffffff;
  --border: #cfcdc6;
  --line: #dedbd4;
  --header-line: #e3e0d9;
  --text: #11120f;
  --body: #2a2b27;
  --soft: #4f524b;
  --muted: #63665f;
  --faint: #6e716a;
  --label: #3a3c37;
  --link: #1f5fbf;
  --logo-sq: #11120f;
  --logo-dot: #f4f2ed;
  --dots: rgba(17, 18, 15, 0.09);
  --shadow: 0 12px 30px rgba(30, 29, 26, 0.08);
  --pop-shadow: 0 18px 50px rgba(30, 29, 26, 0.18);
  --pill: #ffffff;
  --pill-shadow: 0 1px 3px rgba(30, 29, 26, 0.12);
  --scrim: rgba(17, 18, 15, 0.3);
  --on-bg: rgba(31, 111, 214, 0.07);
  --on-border: rgba(31, 111, 214, 0.35);
  --ok: #1f5fbf;
  --ok-bg: rgba(31, 111, 214, 0.1);
  --bad: #b3261e;
  --bad-bg: rgba(179, 38, 30, 0.08);
  --glow: 0.22;
  --hl-kw: #c24e14; --hl-str: #2f7d32; --hl-num: #1f5fbf; --hl-cmt: #8b8e87; --hl-fn: #6f42c1;
  color-scheme: light;
}

/* Dark (refoundspace colours) */
[data-theme="dark"] {
  --bg: #050608;
  --side: #0a0b0e;
  --side-border: #1a1d25;
  --surface: #111318;
  --surface-2: #171a21;
  --field: #111318;
  --bubble: #171a21;
  --card: #0b0d11;
  --sheet: #0e1014;
  --code: #0b0d11;
  --border: #262a34;
  --line: #1f232c;
  --header-line: #12151b;
  --text: #f3f4f8;
  --body: #e3e6ee;
  --soft: #b4bacb;
  --muted: #8f96a8;
  --faint: #7d8497;
  --label: #c9cedb;
  --link: #7fb0ff;
  --logo-sq: #f4f2ed;
  --logo-dot: #050608;
  --dots: rgba(243, 244, 248, 0.08);
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
  --pop-shadow: 0 18px 50px rgba(0, 0, 0, 0.6);
  --pill: #1f232c;
  --pill-shadow: none;
  --scrim: rgba(0, 0, 0, 0.6);
  --on-bg: rgba(31, 111, 214, 0.12);
  --on-border: rgba(79, 146, 235, 0.45);
  --ok: #8dbbff;
  --ok-bg: rgba(31, 111, 214, 0.2);
  --bad: #ff8a80;
  --bad-bg: rgba(255, 138, 128, 0.1);
  --glow: 0.38;
  --hl-kw: #ff9a6b; --hl-str: #9fd39a; --hl-num: #7fb0ff; --hl-cmt: #6b7285; --hl-fn: #c5a3ff;
  color-scheme: dark;
}

/* ---------- basics ---------- */
* { box-sizing: border-box; }
html, body { height: 100%; }
html, * { scrollbar-width: none; }
::-webkit-scrollbar { display: none; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:disabled { cursor: default; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
[hidden] { display: none !important; }
.grow { flex: 1; min-width: 0; text-align: left; }
.muted { color: var(--muted); }
.faint { color: var(--faint); font-size: 12px; font-weight: 500; }
.phone-only { display: none !important; }

.icon-btn {
  display: grid; place-items: center;
  width: 40px; height: 40px; flex-shrink: 0;
  border: 0; border-radius: 10px;
  background: transparent; color: var(--muted);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.logo {
  display: grid; place-items: center;
  width: 32px; height: 32px; flex-shrink: 0;
  border-radius: 9px; background: var(--logo-sq);
}
.logo > span { width: 13px; height: 13px; border-radius: 50%; background: var(--logo-dot); }

/* model / provider icons */
.mi { display: inline-block; flex-shrink: 0; object-fit: contain; }
.mi.mono { background: currentColor; -webkit-mask: var(--src) center / contain no-repeat; mask: var(--src) center / contain no-repeat; }

/* ---------- layout ---------- */
.app { height: 100%; height: 100dvh; display: flex; }

.side {
  width: var(--side-w); flex-shrink: 0;
  display: flex; flex-direction: column;
  padding: 20px 16px 16px;
  background: var(--side);
  border-right: 1px solid var(--side-border);
  transition: margin-left 0.3s var(--ease);
}
.app.side-hidden .side { margin-left: calc(var(--side-w) * -1); }
.side-view { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 16px; }
.side-view.in-fwd { animation: page-fwd 0.34s var(--ease); }
.side-view.in-back { animation: page-back 0.34s var(--ease); }
@keyframes page-fwd { from { opacity: 0; transform: translateX(28px); } }
@keyframes page-back { from { opacity: 0; transform: translateX(-28px); } }

.brand { display: flex; align-items: center; gap: 12px; padding: 0 6px; }
.brand-name { flex: 1; font-family: var(--font-head); font-weight: 600; font-size: 18px; letter-spacing: -0.3px; }

.new-row { display: flex; gap: 8px; }
.btn {
  display: flex; align-items: center; gap: 10px;
  height: 44px; padding: 0 14px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); font-size: 14px; font-weight: 600;
}
.btn:hover { border-color: var(--muted); }
.new-chat { flex: 1; }
.new-chat span { flex: 1; text-align: left; }
.new-chat kbd { font-family: inherit; font-size: 12px; color: var(--faint); }
.btn.square { width: 44px; padding: 0; justify-content: center; flex-shrink: 0; }

.search {
  display: flex; align-items: center; gap: 10px;
  height: 40px; padding: 0 12px;
  border-radius: 10px; background: var(--field); color: var(--faint);
}
.search input { flex: 1; min-width: 0; border: 0; background: transparent; color: var(--text); font-size: 14px; outline: none; }
.search input::placeholder { color: var(--faint); }

/* chat list */
.chat-list { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; margin: 0 -4px; padding: 0 4px; }
.frow { display: flex; align-items: center; min-height: 38px; border-radius: 10px; }
.frow:hover, .frow.drop { background: var(--surface-2); }
.frow.drop { outline: 2px dashed var(--blue); outline-offset: -2px; }
.fbtn {
  flex: 1; min-width: 0;
  display: flex; align-items: center; gap: 8px;
  height: 38px; padding: 0 6px 0 8px;
  border: 0; background: transparent; font-size: 14px; font-weight: 600; text-align: left;
}
.fbtn .chev { color: var(--muted); flex-shrink: 0; transition: transform 0.2s var(--ease); }
.fbtn[aria-expanded="true"] .chev { transform: rotate(90deg); }
.fbtn .name { flex: 1; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.fbtn .count { font-size: 12px; font-weight: 500; color: var(--faint); }
.acts { display: none; gap: 2px; padding-right: 4px; }
.frow:hover .acts, .frow:focus-within .acts { display: flex; }
.acts button { display: grid; place-items: center; width: 30px; height: 30px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); }
.acts button:hover { color: var(--text); background: var(--field); }
.folder-chats { display: flex; flex-direction: column; gap: 2px; padding: 2px 0 2px 22px; }
.collapse { display: grid; grid-template-rows: 0fr; transition: grid-template-rows 0.32s var(--ease); }
.collapse.open { grid-template-rows: 1fr; }
.collapse-inner { min-height: 0; overflow: hidden; }
.collapse:not(.open) .collapse-inner { visibility: hidden; transition: visibility 0s 0.32s; }
.rename-input {
  flex: 1; min-width: 0; height: 32px; margin: 0 4px;
  padding: 0 8px; border: 1px solid var(--blue); border-radius: 8px;
  background: var(--surface); color: var(--text); font-size: 14px; font-weight: 600; outline: none;
}
.crow {
  display: flex; align-items: center; gap: 10px;
  min-height: 36px; padding: 0 10px;
  border: 0; border-radius: 10px; background: transparent;
  color: var(--soft); font-size: 14px; font-weight: 500; text-align: left;
  content-visibility: auto; contain-intrinsic-size: auto 36px;
}
.crow:hover { background: var(--surface-2); color: var(--text); }
.crow.on { background: var(--surface-2); color: var(--text); font-weight: 600; }
.crow .t { flex: 1; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.crow.dragging { opacity: 0.35; }
.crow.appear { animation: row-in 0.45s var(--ease); }
@keyframes row-in { from { opacity: 0; transform: translateX(-10px); background: var(--on-bg); } }
.drag-ghost {
  position: fixed; z-index: 70; margin: 0; pointer-events: none;
  background: var(--surface); color: var(--text); font-weight: 600;
  box-shadow: var(--pop-shadow); border: 1px solid var(--border);
  transform: scale(1.04) rotate(-1.5deg); animation: lift 0.18s var(--ease);
}
@keyframes lift { from { transform: none; box-shadow: none; } }
.list-sep { height: 1px; margin: 8px 8px; background: var(--side-border); flex-shrink: 0; }
.list-sep.drop { height: 3px; background: var(--blue); }
.list-empty { padding: 10px; font-size: 13px; color: var(--muted); }

/* sidebar footer: keys + theme */
.side-foot { display: flex; flex-direction: column; gap: 10px; padding-top: 12px; border-top: 1px solid var(--side-border); }
.keys-row {
  display: flex; align-items: center; gap: 10px;
  height: 40px; padding: 0 10px;
  border: 0; border-radius: 10px; background: transparent; font-size: 14px; font-weight: 600;
}
.keys-row:hover { background: var(--surface-2); }
.keys-row .chev { color: var(--muted); transition: transform 0.3s var(--ease); }
.keys-row[aria-expanded="true"] .chev { transform: rotate(180deg); }

.theme-switch { position: relative; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; padding: 4px; border-radius: 12px; background: var(--field); }
.theme-switch button { position: relative; height: 32px; border: 0; border-radius: 9px; background: transparent; color: var(--muted); font-size: 13px; font-weight: 600; transition: color 0.25s var(--ease); }
.theme-switch button[aria-checked="true"] { color: var(--text); }
.theme-pill {
  position: absolute; top: 4px; bottom: 4px; left: 4px;
  width: calc((100% - 16px) / 3);
  border-radius: 9px; background: var(--pill); box-shadow: var(--pill-shadow);
  transform: translateX(calc(var(--i, 0) * (100% + 4px)));
  transition: transform 0.38s cubic-bezier(0.34, 1.4, 0.64, 1);
}
/* the light/dark circle reveal (see setTheme in app.js) */
::view-transition-old(root), ::view-transition-new(root) { animation: none; mix-blend-mode: normal; }

/* keys view */
.back {
  align-self: flex-start;
  display: inline-flex; align-items: center; gap: 6px;
  height: 36px; padding: 0 10px 0 4px; margin: -4px 0 -6px -4px;
  border: 0; border-radius: 9px; background: transparent;
  color: var(--muted); font-size: 14px; font-weight: 600;
}
.back:hover { color: var(--text); background: var(--surface-2); }
.view-title { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.view-title h2 { margin: 0; font-family: var(--font-head); font-weight: 600; font-size: 20px; letter-spacing: -0.2px; }
.slots { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; }
.keys-inline { display: flex; flex-direction: column; gap: 8px; max-height: 46vh; overflow-y: auto; padding-bottom: 2px; }
.slot { display: flex; flex-direction: column; padding: 6px 8px 6px 12px; border: 1px solid var(--line); border-radius: 14px; background: var(--card); }
.slot-head { display: flex; align-items: center; gap: 10px; min-height: 40px; }
.slot-head .who { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.slot-head .who b { font-size: 14px; }
.slot-head .who code { font-family: var(--font-code); font-size: 11px; color: var(--muted); }
.slot-sep { height: 1px; margin: 4px 4px 4px 0; background: var(--line); }
.slot-model { display: flex; align-items: center; gap: 10px; min-height: 34px; font-size: 14px; color: var(--soft); }
.slot-model .t { flex: 1; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.slot-model .rm { opacity: 0; }
.slot-model:hover .rm, .slot-model .rm:focus-visible { opacity: 1; }
.small-btn { display: grid; place-items: center; width: 32px; height: 32px; flex-shrink: 0; border: 0; border-radius: 8px; background: transparent; color: var(--muted); }
.small-btn:hover { color: var(--text); background: var(--field); }
.link-btn { align-self: flex-start; min-height: 34px; padding: 0; border: 0; background: transparent; color: var(--link); font-size: 13px; font-weight: 700; }
.add-key { min-height: 48px; flex-shrink: 0; border: 1px dashed var(--border); border-radius: 14px; background: transparent; font-size: 14px; font-weight: 700; }
.add-key:hover { border-color: var(--muted); }
.slot-empty { font-size: 13px; color: var(--muted); padding: 2px 0 6px; }

/* ---------- chat ---------- */
.chat { position: relative; flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--bg); overflow: hidden; }
.dots {
  position: absolute; inset: 0; pointer-events: none;
  background-image: radial-gradient(circle, var(--dots) 1px, transparent 1.4px);
  background-size: 22px 22px;
  -webkit-mask-image: linear-gradient(0deg, #000 0%, #000 15%, transparent 60%);
  mask-image: linear-gradient(0deg, #000 0%, #000 15%, transparent 60%);
}
.top { position: relative; height: 64px; flex-shrink: 0; display: flex; align-items: center; gap: 8px; padding: 0 20px; border-bottom: 1px solid var(--header-line); }
.title { flex: 1; min-width: 0; margin: 0 0 0 4px; font-family: var(--font-head); font-weight: 600; font-size: 16px; letter-spacing: -0.2px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.title-input { flex: 1; min-width: 0; height: 36px; padding: 0 10px; border: 1px solid var(--blue); border-radius: 9px; background: var(--surface); font-family: var(--font-head); font-weight: 600; font-size: 16px; outline: none; }

.scroll { position: relative; flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.msgs { width: min(760px, 100% - 64px); margin: 0 auto; padding: 40px 0 32px; display: flex; flex-direction: column; gap: 32px; }
.msg { content-visibility: auto; contain-intrinsic-size: auto 120px; }
.msg:nth-last-child(-n+2) { content-visibility: visible; } /* the latest messages always draw, so following the reply never slips */
.msg.user.appear .bubble { transform-origin: bottom right; animation: bubble-in 0.42s cubic-bezier(0.34, 1.3, 0.64, 1); }
.msg.ai.appear:not(.settled) { animation: reply-in 0.4s 0.1s var(--ease) both; }
@keyframes bubble-in { from { opacity: 0; transform: translateY(18px) scale(0.94); } }
@keyframes reply-in { from { opacity: 0; transform: translateY(8px); } }
.msg.user { display: flex; justify-content: flex-end; }
.bubble { max-width: min(520px, 85%); padding: 13px 18px; border-radius: 18px 18px 6px 18px; background: var(--bubble); font-size: 15px; line-height: 1.55; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.ai { display: flex; gap: 14px; }
.ai-icon { display: grid; place-items: center; width: 30px; height: 30px; flex-shrink: 0; margin-top: 1px; }
.ai-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 10px; }
.ai-name { font-size: 12px; font-weight: 600; color: var(--muted); line-height: 1; margin-top: 2px; }
.ai-actions { display: flex; gap: 4px; margin-left: -8px; }
.ai-actions button { display: grid; place-items: center; width: 34px; height: 34px; border: 0; border-radius: 9px; background: transparent; color: var(--faint); }
.ai-actions button:hover { background: var(--surface-2); color: var(--text); }
.msg.streaming .ai-actions { visibility: hidden; }
.err { padding: 10px 14px; border-radius: 12px; background: var(--bad-bg); color: var(--bad); font-size: 14px; line-height: 1.5; }
.typing-dots { display: inline-flex; gap: 5px; padding: 8px 0; }
.typing-dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite ease-in-out; }
.typing-dots i:nth-child(2) { animation-delay: 0.15s; }
.typing-dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }
.jump {
  position: absolute; left: 50%; bottom: calc(100% + 4px); z-index: 5;
  display: grid; place-items: center; width: 40px; height: 40px;
  border: 1px solid var(--border); border-radius: 50%;
  background: var(--surface); color: var(--text); box-shadow: var(--shadow);
  opacity: 0; pointer-events: none;
  transform: translate(-50%, 10px) scale(0.9);
  transition: opacity 0.2s var(--ease), transform 0.3s var(--ease);
}
.jump.show { opacity: 1; pointer-events: auto; transform: translate(-50%, 0); }
.jump:hover { border-color: var(--muted); }
.load-older { align-self: center; height: 34px; padding: 0 14px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--muted); font-size: 13px; font-weight: 600; }

/* reply text */
.md { font-size: 15px; line-height: 1.7; color: var(--body); overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p, .md ul, .md ol, .md blockquote, .md table { margin: 0 0 14px; }
.md ul, .md ol { padding-left: 22px; }
.md li + li { margin-top: 4px; }
.md strong { color: var(--text); }
.md a { color: var(--link); }
.md h1, .md h2, .md h3, .md h4 { margin: 22px 0 10px; font-family: var(--font-head); font-weight: 600; color: var(--text); line-height: 1.3; }
.md h1 { font-size: 22px; } .md h2 { font-size: 19px; } .md h3 { font-size: 17px; } .md h4 { font-size: 15px; }
.md blockquote { padding-left: 14px; border-left: 3px solid var(--line); color: var(--soft); }
.md hr { border: 0; height: 1px; background: var(--line); margin: 20px 0; }
.md table { border-collapse: collapse; display: block; overflow-x: auto; }
.md th, .md td { padding: 8px 12px; border: 1px solid var(--line); text-align: left; }
.md th { background: var(--card); }
.md :not(pre) > code { padding: 2px 6px; border-radius: 6px; background: var(--field); font-family: var(--font-code); font-size: 0.88em; }
.md img { max-width: 100%; }
.code { margin: 0 0 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--code); overflow: hidden; }
.code-head { display: flex; align-items: center; justify-content: space-between; height: 38px; padding: 0 8px 0 16px; border-bottom: 1px solid var(--line); font-size: 12px; font-weight: 600; color: var(--muted); }
.code-copy { display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); font-size: 12px; font-weight: 600; }
.code-copy:hover { background: var(--field); color: var(--text); }
.code pre { margin: 0; padding: 16px 18px; overflow-x: auto; font-family: var(--font-code); font-size: 13px; line-height: 1.7; color: var(--body); }
.code pre code { font-family: inherit; }
.hljs-keyword, .hljs-built_in, .hljs-selector-tag, .hljs-literal { color: var(--hl-kw); }
.hljs-string, .hljs-attr, .hljs-template-string, .hljs-regexp { color: var(--hl-str); }
.hljs-number, .hljs-variable.constant_, .hljs-type { color: var(--hl-num); }
.hljs-comment, .hljs-meta, .hljs-quote { color: var(--hl-cmt); font-style: italic; }
.hljs-title, .hljs-title.function_, .hljs-section { color: var(--hl-fn); }

/* empty / welcome */
.welcome { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; min-height: 55vh; text-align: center; }
.welcome .logo { width: 64px; height: 64px; border-radius: 18px; }
.welcome .logo > span { width: 26px; height: 26px; }
.welcome h2 { margin: 0; font-family: var(--font-head); font-weight: 600; font-size: 28px; letter-spacing: -0.5px; }
.welcome p { margin: 0; color: var(--muted); }
.primary {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 48px; padding: 0 20px;
  border: 0; border-radius: 12px; background: var(--blue); color: #fff; font-size: 15px; font-weight: 700;
}
.primary:hover:not(:disabled) { background: var(--blue-hover); }
.primary:disabled { opacity: 0.5; }

/* ---------- composer + glow ---------- */
.composer-area { position: relative; flex-shrink: 0; display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 12px 32px 18px; }
.composer-wrap { position: relative; width: min(760px, 100%); }
.glow {
  position: absolute; inset: 6px 10px -2px; border-radius: 22px;
  background: linear-gradient(90deg, var(--orange), var(--blue), var(--orange), var(--blue));
  background-size: 300% 100%;
  filter: blur(22px);
  --base: 0.55;
  opacity: min(1, calc(var(--glow) * (var(--base) + var(--energy, 0) * 1.1)));
  scale: calc(1 + var(--energy, 0) * 0.03);
  pointer-events: none;
  transition: opacity 0.35s var(--ease);
}
.composer-wrap[data-glow="typing"] .glow { --base: 1; }
.composer-wrap[data-glow="responding"] .glow { --base: 1.25; animation: glow-flow 2.4s linear infinite, glow-pulse 1.6s ease-in-out infinite; }
@keyframes glow-flow { from { background-position: 0% 50%; } to { background-position: 100% 50%; } }
@keyframes glow-pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.025); } }

.composer { position: relative; display: flex; flex-direction: column; gap: 10px; padding: 14px 14px 12px 18px; border: 1px solid var(--border); border-radius: 18px; background: var(--surface); box-shadow: var(--shadow); }
.composer textarea { width: 100%; max-height: 40vh; padding: 2px 0; border: 0; background: transparent; color: var(--text); font-size: 15px; line-height: 1.5; resize: none; outline: none; }
.composer textarea::placeholder { color: var(--faint); }
.composer-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.model-btn { display: inline-flex; align-items: center; gap: 8px; min-width: 0; max-width: calc(100% - 50px); height: 34px; padding: 0 10px; margin-left: -10px; border: 0; border-radius: 10px; background: transparent; font-size: 13px; font-weight: 600; }
.model-btn:hover { background: var(--field); }
.model-btn .t { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.model-btn .p { font-weight: 500; color: var(--muted); white-space: nowrap; }
.model-btn .chev { color: var(--muted); flex-shrink: 0; }
.send { display: grid; place-items: center; width: 40px; height: 40px; flex-shrink: 0; border: 0; border-radius: 10px; background: var(--blue); color: #fff; }
.send:hover:not(:disabled) { background: var(--blue-hover); }
.send:disabled { opacity: 0.45; }
.send { transition: background 0.25s var(--ease), color 0.25s var(--ease), transform 0.15s var(--ease); }
.send:active:not(:disabled) { transform: scale(0.92); }
.send svg { grid-area: 1 / 1; transition: opacity 0.2s var(--ease), transform 0.3s var(--ease); }
.send .i-stop { opacity: 0; transform: scale(0.4) rotate(-90deg); }
.composer-wrap[data-glow="responding"] .send { background: var(--text); color: var(--bg); opacity: 1; }
.composer-wrap[data-glow="responding"] .send .i-send { opacity: 0; transform: translateY(-8px) scale(0.6); }
.composer-wrap[data-glow="responding"] .send .i-stop { opacity: 1; transform: none; }
.fine { margin: 0; font-size: 12px; color: var(--faint); text-align: center; }

/* model picker (drops up) */
.model-menu {
  position: absolute; left: 8px; bottom: calc(100% + 8px); z-index: 20;
  width: min(360px, calc(100vw - 32px)); max-height: min(420px, 60vh); overflow-y: auto;
  padding: 6px; border: 1px solid var(--border); border-radius: 14px;
  background: var(--surface); box-shadow: var(--pop-shadow);
  transform-origin: 16px 100%;
  animation: menu-up 0.22s var(--ease);
}
@keyframes menu-up { from { opacity: 0; transform: translateY(6px) scale(0.96); } }
.mm-group { padding: 10px 10px 4px; display: flex; align-items: center; gap: 8px; font-family: var(--font-head); font-size: 12px; font-weight: 600; color: var(--label); }
.mm-item { width: 100%; display: flex; align-items: center; gap: 10px; min-height: 40px; padding: 0 10px; border: 0; border-radius: 9px; background: transparent; font-size: 14px; text-align: left; }
.mm-item:hover, .mm-item:focus-visible { background: var(--field); outline: none; }
.mm-item .t { flex: 1; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.mm-item .tick { color: var(--blue); }
.mm-foot { margin-top: 4px; padding-top: 4px; border-top: 1px solid var(--line); }

/* ---------- Add a key / Add model panels ---------- */
.panel { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 16px; }
.panel-head { display: flex; align-items: flex-start; gap: 12px; }
.panel-head > div { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.panel-head h2 { margin: 0; font-family: var(--font-head); font-weight: 600; font-size: 20px; letter-spacing: -0.2px; }
.panel-sub { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; color: var(--muted); }
.panel-close { display: grid; place-items: center; width: 40px; height: 40px; flex-shrink: 0; border: 0; border-radius: 50%; background: var(--field); color: var(--muted); }
.label-row { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.label { font-family: var(--font-head); font-size: 13px; font-weight: 600; color: var(--label); }
.keybox { display: flex; align-items: center; gap: 12px; min-height: 60px; padding: 0 10px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); }
.keybox:focus-within { border-color: var(--blue); }
.keybox .badge { display: grid; place-items: center; width: 40px; height: 40px; flex-shrink: 0; border-radius: 10px; background: var(--field); color: var(--muted); }
.keybox .badge.checking { animation: breathe 1s ease-in-out infinite; }
.keybox .badge.found { animation: badge-flip 0.5s cubic-bezier(0.34, 1.5, 0.64, 1); }
@keyframes breathe { 50% { opacity: 0.45; } }
@keyframes badge-flip { from { transform: rotateY(90deg) scale(0.8); } }
.keybox .who { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.keybox .who b { font-size: 14px; }
.keybox input { width: 100%; padding: 0; border: 0; background: transparent; color: var(--muted); font-size: 13px; outline: none; }
.keybox input::placeholder { color: var(--faint); }
.tag { display: inline-flex; align-items: center; gap: 5px; height: 28px; padding: 0 10px; flex-shrink: 0; border-radius: 999px; font-size: 12px; font-weight: 700; }
.tag.ok { background: var(--ok-bg); color: var(--ok); animation: pop 0.4s cubic-bezier(0.34, 1.6, 0.64, 1); }
@keyframes pop { from { transform: scale(0.6); opacity: 0; } }
.tag.bad { background: var(--bad-bg); color: var(--bad); }
.tag.wait { background: var(--field); color: var(--muted); }
.key-error { margin: -8px 0 0; font-size: 13px; color: var(--bad); }
.panel .search { height: 48px; flex-shrink: 0; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); }
.picks { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 8px; }
.vlist { flex: 1; min-height: 0; overflow-y: auto; position: relative; }
.vlist-inner { position: relative; }
.pick {
  position: absolute; left: 0; right: 0; height: 54px;
  display: flex; align-items: center; gap: 12px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface); text-align: left;
}
.pick:hover { border-color: var(--border); }
.pick[aria-checked="true"] { background: var(--on-bg); border-color: var(--on-border); }
.pick.added { opacity: 0.55; cursor: default; }
.pick .txt { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.pick .txt b { font-size: 14px; font-weight: 600; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.pick .txt small { font-size: 12px; color: var(--muted); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.box { display: grid; place-items: center; width: 24px; height: 24px; flex-shrink: 0; border: 2px solid var(--border); border-radius: 7px; color: #fff; }
.box svg { opacity: 0; }
.pick[aria-checked="true"] .box { border: 0; background: var(--blue); }
.pick[aria-checked="true"] .box svg { opacity: 1; }
.pick.full { opacity: 0.5; }
.pick.nope { animation: nope 0.35s var(--ease); }
@keyframes nope { 20%, 60% { transform: translateX(-5px); } 40%, 80% { transform: translateX(5px); } }
.pick.pop .box { animation: pop 0.3s cubic-bezier(0.34, 1.6, 0.64, 1); }
.pick .added-t { font-size: 12px; font-weight: 600; color: var(--muted); }
.panel .primary { flex-shrink: 0; height: 52px; }
.panel-note { font-size: 13px; color: var(--muted); padding: 8px 0; }

/* phone sheets */
.sheet-layer { position: fixed; inset: 0; z-index: 40; }
.sheet-scrim { position: absolute; inset: 0; background: var(--scrim); animation: fade 0.2s ease; }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0;
  height: min(88dvh, 700px);
  display: flex; flex-direction: column;
  padding: 10px 18px calc(20px + env(safe-area-inset-bottom));
  border-radius: 22px 22px 0 0; background: var(--sheet); box-shadow: var(--pop-shadow);
  animation: sheet-in 0.32s var(--ease);
}
.sheet::before { content: ""; align-self: center; width: 40px; height: 5px; margin-bottom: 12px; border-radius: 3px; background: var(--border); flex-shrink: 0; }
@keyframes sheet-in { from { transform: translateY(100%); } }
.sheet-layer.closing .sheet { animation: sheet-out 0.22s ease-in forwards; }
.sheet-layer.closing .sheet-scrim { animation: fade 0.22s ease-in reverse forwards; }
@keyframes sheet-out { to { transform: translateY(100%); } }
@keyframes fade { from { opacity: 0; } }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 60; transform: translateX(-50%);
  padding: 10px 16px; border-radius: 12px; background: var(--text); color: var(--bg);
  font-size: 14px; font-weight: 600; box-shadow: var(--pop-shadow);
  pointer-events: none; opacity: 0; translate: 0 14px;
  transition: opacity 0.25s var(--ease), translate 0.35s var(--ease);
}
.toast.show { opacity: 1; translate: 0 0; }

/* ---------- phones ---------- */
@media (max-width: 760px) {
  .phone-only { display: grid !important; }
  .desk-only { display: none !important; }
  .side {
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 30;
    width: min(330px, 86vw); padding: 14px 14px calc(16px + env(safe-area-inset-bottom));
    transform: translateX(-102%); transition: transform 0.3s var(--ease);
    box-shadow: var(--pop-shadow);
  }
  .app.side-hidden .side { margin-left: 0; }
  .app.menu-open .side { transform: none; }
  .scrim { position: fixed; inset: 0; z-index: 25; background: var(--scrim); animation: fade 0.2s ease; }
  .brand { padding-left: 6px; }
  .brand .icon-btn { width: 44px; height: 44px; }
  .btn { height: 46px; font-size: 15px; }
  .btn.square { width: 46px; }
  .search { height: 42px; }
  .search input { font-size: 16px; }
  .frow, .fbtn, .crow { min-height: 44px; }
  .crow { font-size: 15px; }
  .acts { display: flex; }
  .acts button { width: 40px; height: 40px; }
  .keys-row { height: 44px; font-size: 15px; }
  .theme-switch button { height: 38px; font-size: 14px; }
  .top { height: 60px; padding: 0 8px; gap: 4px; }
  .top .icon-btn { width: 44px; height: 44px; color: var(--text); }
  .title { font-size: 15px; }
  .msgs { width: calc(100% - 32px); padding-top: 24px; gap: 24px; }
  .msg.ai { gap: 10px; }
  .ai-icon { width: 26px; height: 26px; }
  .code pre { font-size: 12px; padding: 14px; }
  .composer-area { padding: 10px 12px calc(12px + env(safe-area-inset-bottom)); }
  .composer { padding: 12px 10px 10px 14px; }
  .composer textarea { font-size: 16px; }
  .model-btn .p { display: none; }
  .send { width: 44px; height: 44px; }
  .fine { display: none; }
  .panel .search input { font-size: 16px; }
  .keybox input { font-size: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
