:root {
  --bg: #0a0b10;
  --bg-2: #11131b;
  --bg-3: #181b26;
  --bg-4: #1f2330;
  --border: #262a38;
  --border-2: #313748;
  --text: #eef0f6;
  --muted: #9099ad;
  --accent: #7c8bff;
  --grad: linear-gradient(135deg, #6366f1 0%, #8b5cf6 45%, #06b6d4 110%);
  --grad-soft: linear-gradient(135deg, rgba(99,102,241,.18), rgba(139,92,246,.14), rgba(6,182,212,.16));
  --danger: #f0616d;
  --pin: #f5b942;
  --rec: #ff4d5e;
  --radius: 14px;
  --shadow: 0 10px 40px -12px rgba(0,0,0,.6);
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 18px; font-size: 13px; margin: 8px 0 0; }
.ic { display: block; width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }

button { font: inherit; cursor: pointer; border: none; border-radius: 10px; color: var(--text); background: var(--bg-3); transition: all .16s ease; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
button:disabled { opacity: .45; cursor: default; }
.primary { background: var(--grad); color: #fff; padding: 10px 16px; font-weight: 600; box-shadow: 0 4px 16px -4px rgba(124,92,246,.5); }
.primary:hover:not(:disabled) { filter: brightness(1.08); transform: translateY(-1px); }
.glow { box-shadow: 0 6px 26px -6px rgba(124,92,246,.7); }
.ghost { background: transparent; color: var(--muted); padding: 8px 12px; }
.ghost:hover { background: var(--bg-3); color: var(--text); }
.icon-btn { background: transparent; color: var(--muted); width: 38px; height: 38px; border-radius: 10px; }
.icon-btn:hover { background: var(--bg-4); color: var(--text); }

input, textarea {
  font: inherit; color: var(--text); background: var(--bg-2);
  border: 1px solid var(--border); border-radius: 11px; padding: 12px 14px; width: 100%;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(124,139,255,.15); }
::placeholder { color: #5b6275; }

.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 20px; letter-spacing: -.02em; }
.brand .ic { width: 24px; height: 24px; fill: #8b5cf6; stroke: none; }
.brand span { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }

/* ---------- Auth ---------- */
.auth { display: flex; align-items: center; justify-content: center; height: 100vh; position: relative; overflow: hidden; }
.auth-bg { position: absolute; inset: 0; background:
  radial-gradient(60% 50% at 20% 10%, rgba(99,102,241,.22), transparent 60%),
  radial-gradient(50% 50% at 85% 90%, rgba(6,182,212,.18), transparent 60%),
  radial-gradient(40% 40% at 70% 20%, rgba(139,92,246,.18), transparent 60%); }
.auth-card { position: relative; width: 360px; background: rgba(17,19,27,.8); backdrop-filter: blur(16px); border: 1px solid var(--border-2); border-radius: 20px; padding: 32px; box-shadow: var(--shadow); }
.auth-card .brand { font-size: 26px; margin-bottom: 6px; }
.auth-card form { display: flex; flex-direction: column; gap: 11px; margin-top: 22px; }
.auth-card .primary { padding: 12px; }

/* ---------- App layout ---------- */
.app { display: grid; grid-template-columns: 288px 1fr; height: 100vh; }

.sidebar { background: var(--bg-2); border-right: 1px solid var(--border); display: flex; flex-direction: column; padding: 16px 12px; gap: 12px; }
.sidebar-brand { padding: 6px 8px 2px; font-size: 22px; }
.new-chat { width: 100%; padding: 11px; }
.chat-list { flex: 1; overflow-y: auto; margin: 0 -4px; padding: 0 4px; display: flex; flex-direction: column; gap: 3px; }
.chat-list::-webkit-scrollbar, .messages::-webkit-scrollbar { width: 8px; }
.chat-list::-webkit-scrollbar-thumb, .messages::-webkit-scrollbar-thumb { background: var(--bg-4); border-radius: 8px; }
.list-section { font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); padding: 14px 10px 5px; display: flex; align-items: center; gap: 6px; }
.list-section .ic { width: 12px; height: 12px; }

.chat-item { display: flex; align-items: center; gap: 8px; padding: 10px 11px; border-radius: 11px; cursor: pointer; position: relative; border: 1px solid transparent; }
.chat-item:hover { background: var(--bg-3); }
.chat-item.active { background: var(--grad-soft); border-color: var(--border-2); }
.chat-item .pin-ic { width: 13px; height: 13px; color: var(--pin); }
.chat-item .title { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
/* Actions float over the right edge on hover so the row never resizes. */
.chat-item .actions { position: absolute; right: 5px; top: 50%; transform: translateY(-50%); display: none; gap: 1px; }
.chat-item:hover .actions { display: flex; }
.chat-item:hover .title { padding-right: 92px; }
.chat-item .rename-input { width: 100%; padding: 3px 6px; font-size: 14px; border-radius: 7px; }
.chat-item .actions button { width: 27px; height: 27px; padding: 0; background: transparent; color: var(--muted); border-radius: 8px; }
.chat-item .actions button:hover { background: var(--bg-4); color: var(--text); }
.chat-item .actions .ic { width: 15px; height: 15px; }
.chat-item .actions .pinned { color: var(--pin); }

.sidebar-foot { border-top: 1px solid var(--border); padding-top: 12px; display: flex; flex-direction: column; gap: 6px; }
.row-btn { justify-content: flex-start; background: transparent; color: var(--muted); padding: 10px 11px; width: 100%; }
.row-btn:hover { background: var(--bg-3); color: var(--text); }
.user-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 2px 4px; }
.user-chip { display: flex; align-items: center; gap: 9px; font-size: 14px; font-weight: 500; min-width: 0; }
.mini-avatar { width: 28px; height: 28px; border-radius: 8px; background: var(--grad); display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 700; color: #fff; flex-shrink: 0; }

/* ---------- Main / topbar ---------- */
.main { display: flex; flex-direction: column; height: 100vh; min-width: 0; position: relative; }
.scroll-bottom {
  position: absolute; left: 50%; transform: translateX(-50%) translateY(8px);
  bottom: 104px; z-index: 20; width: 38px; height: 38px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  background: var(--bg-2); color: var(--text); border: 1px solid var(--border-2);
  box-shadow: 0 6px 20px rgba(0,0,0,.28); opacity: 0; pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
}
.scroll-bottom.show { opacity: 1; pointer-events: auto; transform: translateX(-50%) translateY(0); }
.scroll-bottom:hover { border-color: var(--accent); }
.scroll-bottom .ic { width: 18px; height: 18px; }
.topbar { height: 56px; flex-shrink: 0; display: flex; align-items: center; justify-content: space-between; padding: 0 24px; border-bottom: 1px solid var(--border); background: rgba(10,11,16,.7); backdrop-filter: blur(8px); }
.topbar-left { display: flex; align-items: center; gap: 8px; min-width: 0; }
.chat-title { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.menu-btn { display: none; font-size: 18px; }
.route-pill { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--accent); background: var(--grad-soft); border: 1px solid var(--border-2); padding: 6px 11px; border-radius: 20px; font-weight: 500; }
.route-pill .ic { width: 14px; height: 14px; fill: currentColor; stroke: none; }

/* ---------- Messages ---------- */
.messages { flex: 1; overflow-y: auto; padding: 28px 0 12px; }
.msg { max-width: 800px; margin: 0 auto 24px; padding: 0 24px; display: flex; gap: 14px; animation: rise .35s ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.msg.user { flex-direction: row-reverse; }
.avatar { width: 34px; height: 34px; border-radius: 10px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 700; }
.msg.user .avatar { background: var(--grad); color: #fff; }
.msg.assistant .avatar { background: var(--bg-4); border: 1px solid var(--border-2); }
.msg.assistant .avatar .ic { width: 19px; height: 19px; fill: #8b5cf6; stroke: none; }
.msg .body { min-width: 0; max-width: calc(100% - 48px); display: flex; flex-direction: column; }
.msg.user .body { align-items: flex-end; }

.meta { font-size: 12px; color: var(--muted); margin-bottom: 6px; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.meta .arrow { color: var(--border-2); }
.content { line-height: 1.65; word-wrap: break-word; padding: 13px 16px; border-radius: 16px; }
.msg.assistant .content { background: var(--bg-2); border: 1px solid var(--border); border-top-left-radius: 5px; }
.msg.user .content { background: var(--grad); color: #fff; border-top-right-radius: 5px; box-shadow: 0 4px 18px -6px rgba(124,92,246,.45); }
.content p { margin: 0 0 10px; } .content p:last-child { margin-bottom: 0; }
.content pre { background: #0a0c12; border: 1px solid var(--border); border-radius: 10px; padding: 13px; overflow-x: auto; margin: 10px 0; }
.content code { background: rgba(255,255,255,.08); padding: 2px 6px; border-radius: 5px; font-size: 13px; font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace; }
.msg.user .content code { background: rgba(0,0,0,.2); }
.content pre code { background: none; padding: 0; }
.content ul, .content ol { margin: 0 0 10px; padding-left: 22px; }
.content a { color: #a5b4ff; }
.msg.user .content a { color: #fff; text-decoration: underline; }

.badge { font-size: 11px; padding: 3px 9px; border-radius: 20px; background: var(--bg-3); border: 1px solid var(--border); white-space: nowrap; }
.badge.model { color: var(--accent); background: var(--grad-soft); border-color: var(--border-2); font-family: "SF Mono", ui-monospace, monospace; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.chip { font-size: 12px; padding: 5px 11px; border-radius: 16px; background: var(--bg-3); border: 1px solid var(--border-2); display: inline-flex; align-items: center; gap: 5px; }
.chip-x { background: transparent; border: none; color: var(--muted); padding: 0 0 0 3px; font-size: 12px; }
.chip-x:hover { color: var(--danger); }
.thumb-chip { padding: 0; overflow: hidden; border: 1px solid var(--border-2); }
.chips .thumb { width: 140px; height: 105px; max-width: 46vw; object-fit: cover; border-radius: 11px; display: block; }
.chip-audio { height: 38px; max-width: 260px; }

.sources { margin-top: 12px; font-size: 13px; padding: 11px 14px; background: var(--bg-2); border: 1px solid var(--border); border-radius: 12px; }
.sources .src-head { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; margin-bottom: 6px; }
.sources a { display: block; color: var(--muted); margin: 3px 0; text-decoration: none; }
.sources a:hover { color: var(--accent); }

.empty { text-align: center; color: var(--muted); margin-top: 16vh; padding: 0 24px; animation: rise .4s ease both; }
.empty .orb { width: 64px; height: 64px; border-radius: 20px; background: var(--grad); margin: 0 auto 20px; display: flex; align-items: center; justify-content: center; box-shadow: 0 12px 40px -8px rgba(124,92,246,.6); }
.empty .orb .ic { width: 32px; height: 32px; fill: #fff; stroke: none; }
.empty h2 { color: var(--text); font-weight: 700; font-size: 24px; letter-spacing: -.02em; margin: 0 0 8px; }

/* ---------- Composer ---------- */
.composer { padding: 8px 24px 18px; }
.route-badge { max-width: 820px; margin: 0 auto 8px; font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 9px; padding: 0 6px; }
.route-badge b, .route-badge .label { color: var(--text); font-weight: 500; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 10px var(--accent); animation: pulse 1.1s infinite; }
@keyframes pulse { 0%,100% { opacity: .35; transform: scale(.85); } 50% { opacity: 1; transform: scale(1.1); } }

.pending { max-width: 820px; margin: 0 auto 8px; display: flex; flex-wrap: wrap; gap: 7px; }
.pending .thumb { width: 46px; height: 46px; border-radius: 10px; object-fit: cover; border: 1px solid var(--border-2); }

.composer-box { max-width: 820px; margin: 0 auto; display: flex; align-items: flex-end; gap: 6px; background: var(--bg-2); border: 1px solid var(--border-2); border-radius: 20px; padding: 8px 8px 8px 10px; transition: border-color .15s, box-shadow .15s; }
.composer-box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(124,139,255,.12); }
.composer-actions { display: flex; gap: 2px; padding-bottom: 1px; }
.composer-actions .icon-btn { width: 36px; height: 36px; }
.composer textarea { resize: none; max-height: 200px; border: none; background: transparent; padding: 9px 4px; box-shadow: none !important; }
.composer textarea:focus { border: none; }
.send-btn { width: 40px; height: 40px; border-radius: 13px; background: var(--grad); color: #fff; flex-shrink: 0; box-shadow: 0 4px 14px -4px rgba(124,92,246,.6); }
.send-btn:hover:not(:disabled) { filter: brightness(1.1); transform: translateY(-1px) scale(1.03); }
.send-btn .ic { width: 19px; height: 19px; }
.composer-hint { max-width: 820px; margin: 9px auto 0; text-align: center; font-size: 11.5px; }

/* Recorder */
.recorder { max-width: 820px; margin: 0 auto 8px; display: flex; align-items: center; gap: 12px; background: var(--bg-2); border: 1px solid var(--rec); border-radius: 16px; padding: 12px 16px; }
.rec-dot { width: 11px; height: 11px; border-radius: 50%; background: var(--rec); box-shadow: 0 0 12px var(--rec); animation: pulse 1s infinite; }
.rec-label { font-weight: 600; color: var(--rec); }
.rec-time { font-family: "SF Mono", ui-monospace, monospace; color: var(--text); font-size: 15px; }
.rec-actions { margin-left: auto; display: flex; gap: 8px; }
.rec-actions .primary { padding: 8px 14px; background: var(--rec); box-shadow: none; }
.rec-actions .ic { width: 15px; height: 15px; fill: #fff; stroke: none; }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; background: rgba(5,6,10,.7); backdrop-filter: blur(4px); display: flex; align-items: center; justify-content: center; z-index: 50; animation: rise .2s ease; }
.modal-card { width: 540px; max-width: 92vw; background: var(--bg-2); border: 1px solid var(--border-2); border-radius: 18px; padding: 24px; max-height: 82vh; overflow-y: auto; box-shadow: var(--shadow); }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; }
.modal-head h2 { margin: 0; font-size: 19px; }
.add-user { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.add-user input { flex: 1 1 140px; width: auto; }
.add-user .check { display: flex; align-items: center; gap: 6px; white-space: nowrap; color: var(--muted); font-size: 13px; }
.add-user .check input { width: auto; flex: 0 0 auto; }
.add-user .primary { margin-left: auto; }
.plan-badge { display: inline-block; font-size: 12px; color: var(--accent); background: var(--grad-soft); border: 1px solid var(--border-2); padding: 5px 11px; border-radius: 20px; margin-bottom: 12px; font-weight: 500; }
/* Styled native dropdown */
.plan-select {
  appearance: none; -webkit-appearance: none; -moz-appearance: none;
  width: auto; padding: 8px 30px 8px 11px; font-size: 13px; border-radius: 9px; cursor: pointer;
  color: var(--text); background-color: var(--bg-2); border: 1px solid var(--border-2);
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="%239099ad" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="6 9 12 15 18 9"/></svg>');
  background-repeat: no-repeat; background-position: right 10px center;
}
.plan-select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(124,139,255,.15); }
.plan-select option { background: var(--bg-2); color: var(--text); }
.user-list { margin-top: 8px; display: flex; flex-direction: column; gap: 7px; }
.user-list .row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 14px; background: var(--bg-3); border: 1px solid var(--border); border-radius: 11px; }
.user-list .row > span:first-child { font-size: 14px; font-weight: 500; display: flex; align-items: center; min-width: 0; }
.user-list .row-right { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.user-list .row-right .ghost { color: var(--danger); padding: 6px 10px; font-size: 13px; }
.user-list .row-right .ghost:hover { background: rgba(240,97,109,.12); }
.user-list .row .tag { font-size: 10px; color: #fff; background: var(--grad); margin-left: 9px; padding: 2px 8px; border-radius: 12px; text-transform: uppercase; letter-spacing: .04em; }

/* ---------- Mobile ---------- */
.nav-overlay { display: none; }

@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 84vw; max-width: 320px; z-index: 40; transform: translateX(-100%); transition: transform .25s ease; box-shadow: var(--shadow); padding-top: calc(16px + env(safe-area-inset-top)); }
  .app.nav-open .sidebar { transform: none; }
  .nav-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 39; opacity: 0; pointer-events: none; transition: opacity .25s; }
  .app.nav-open .nav-overlay { display: block; opacity: 1; pointer-events: auto; }
  .menu-btn { display: inline-flex; }
  .topbar { padding: env(safe-area-inset-top) 14px 0; height: calc(56px + env(safe-area-inset-top)); }
  .route-pill { display: none; }
  .msg, .composer-box, .route-badge, .pending, .recorder, .composer-hint { padding-left: 14px; padding-right: 14px; }
  .msg { padding: 0 14px; }
  .composer { padding: 8px 10px calc(12px + env(safe-area-inset-bottom)); }
  .composer-hint { display: none; }
  .composer-actions .icon-btn { width: 34px; height: 34px; }
  /* 16px inputs stop iOS from zooming on focus */
  input, textarea { font-size: 16px; }
  /* bottom-sheet style modals */
  .modal { align-items: flex-end; }
  .modal-card { width: 100%; max-width: 100%; max-height: 90vh; border-radius: 20px 20px 0 0; padding: 20px 18px calc(20px + env(safe-area-inset-bottom)); }
}

/* App height tracks the VISUAL viewport (set in JS) so the keyboard doesn't shove the
   layout up; the body is locked so the page itself can never scroll/shift. */
body { position: fixed; inset: 0; width: 100%; }
.app, .auth { height: var(--app-h, 100dvh); }
.main { height: 100%; min-height: 0; }
.topbar { position: sticky; top: 0; z-index: 5; }
* { -webkit-tap-highlight-color: transparent; }

/* ===================== Phase 2/3 additions ===================== */
.svg-sprite { position: absolute; width: 0; height: 0; }

/* Light theme */
html[data-theme="light"] {
  --bg: #f6f7fb; --bg-2: #ffffff; --bg-3: #eef0f6; --bg-4: #e5e8f1;
  --border: #e3e6ef; --border-2: #d2d8e6; --text: #1a1d27; --muted: #6b7280;
  --shadow: 0 10px 40px -16px rgba(40,50,90,.25);
}
html[data-theme="light"] .auth-bg { opacity: .5; }
html[data-theme="light"] .content pre, html[data-theme="light"] .codeblock { background: #1a1d27; }
html[data-theme="light"] .content code { background: rgba(0,0,0,.06); }
/* Light theme: these elements had hard-coded dark translucent backgrounds */
html[data-theme="light"] .topbar { background: rgba(246,247,251,.82); }
html[data-theme="light"] .auth-card { background: rgba(255,255,255,.85); }
html[data-theme="light"] .toast { box-shadow: 0 8px 28px -10px rgba(40,50,90,.35); }

/* Custom confirm dialog */
#confirm-modal { z-index: 60; }
.confirm-card { width: 380px; max-width: 92vw; }
.confirm-title { font-size: 17px; font-weight: 600; margin: 0 0 8px; }
.confirm-msg { font-size: 14.5px; line-height: 1.55; color: var(--muted); margin: 0 0 22px; }
.confirm-actions { display: flex; gap: 10px; justify-content: flex-end; }
.primary.danger { background: var(--danger); box-shadow: 0 4px 16px -4px rgba(240,97,109,.5); }

/* Toasts */
.toasts { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: var(--bg-3); border: 1px solid var(--border-2); color: var(--text); padding: 10px 16px; border-radius: 12px; font-size: 13.5px; box-shadow: var(--shadow); opacity: 0; transform: translateY(-8px); transition: all .25s ease; }
.toast.show { opacity: 1; transform: none; }

/* Search box */
.search-box { display: flex; align-items: center; gap: 8px; background: var(--bg-3); border: 1px solid var(--border); border-radius: 11px; padding: 0 10px; }
.search-box .ic { width: 15px; height: 15px; color: var(--muted); }
.search-box input { border: none; background: transparent; padding: 9px 0; }
.search-box input:focus { box-shadow: none; }

/* Code blocks + highlighting */
.codeblock { margin: 10px 0; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: #0a0c12; }
.cb-head { display: flex; align-items: center; justify-content: space-between; padding: 6px 12px; background: rgba(255,255,255,.04); border-bottom: 1px solid var(--border); }
.cb-lang { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; font-family: "SF Mono", ui-monospace, monospace; }
.cb-copy { background: transparent; color: var(--muted); font-size: 12px; padding: 3px 8px; gap: 5px; }
.cb-copy:hover { color: #fff; background: rgba(255,255,255,.08); }
.cb-copy .ic { width: 13px; height: 13px; }
.codeblock pre { margin: 0; border: none; border-radius: 0; background: transparent; }
.tok-c { color: #6b7689; font-style: italic; }
.tok-s { color: #7ee787; }
.tok-n { color: #f0883e; }
.tok-k { color: #a5b4ff; font-weight: 600; }

/* Message hover actions */
.msg-actions { display: flex; gap: 2px; margin-top: 6px; opacity: 0; transition: opacity .15s; }
.msg:hover .msg-actions { opacity: 1; }
.msg.user .msg-actions { justify-content: flex-end; }
.msg-actions button { width: 30px; height: 30px; border-radius: 8px; background: transparent; color: var(--muted); }
.msg-actions button:hover { background: var(--bg-3); color: var(--text); }
.msg-actions .ic { width: 15px; height: 15px; }

/* Edit */
.edit-area { min-height: 80px; resize: vertical; }
.edit-row { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }

/* Generated images */
.gen-images { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 6px; }
.gen-img { max-width: 320px; max-height: 320px; border-radius: 12px; border: 1px solid var(--border); display: block; }

/* Topbar right */
.topbar-right { display: flex; align-items: center; gap: 10px; }

/* Send stop state */
.send-btn.stopping { background: var(--danger); box-shadow: 0 4px 14px -4px rgba(240,97,109,.6); }

/* Settings / usage fields */
.field-label { display: block; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin: 14px 0 6px; }
.modal-card textarea { resize: vertical; }
.modal-card .primary { margin-top: 12px; }
.sep { border: none; border-top: 1px solid var(--border); margin: 18px 0; }
.mem-add { display: flex; gap: 8px; }
.mem-add input { flex: 1; }
.mem-add .primary { margin-top: 0; }
.memory-list { margin-top: 12px; display: flex; flex-direction: column; gap: 6px; }
.mem-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 9px 12px; background: var(--bg-3); border-radius: 10px; font-size: 14px; }
.mem-row .icon-btn { width: 30px; height: 30px; }
.mem-row .ic { width: 15px; height: 15px; }

/* Usage dashboard */
.usage-summary { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 6px; }
.stat { background: var(--bg-3); border: 1px solid var(--border); border-radius: 12px; padding: 14px; display: flex; flex-direction: column; gap: 3px; }
.stat b { font-size: 22px; background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.stat span { font-size: 12px; color: var(--muted); }
.usage-models { display: flex; flex-direction: column; gap: 6px; }
.usage-row { display: grid; grid-template-columns: 1fr auto auto; gap: 12px; align-items: center; padding: 10px 13px; background: var(--bg-3); border-radius: 10px; font-size: 13.5px; }
.um-model { font-family: "SF Mono", ui-monospace, monospace; color: var(--accent); }
.um-calls { color: var(--muted); font-size: 12px; }
.um-cost { font-weight: 600; }
.row-btn .ic { width: 17px; height: 17px; }

/* Budget bars */
.usage-budget { display: flex; flex-direction: column; gap: 12px; margin-bottom: 4px; }
.budget-row { display: flex; flex-direction: column; gap: 5px; }
.budget-top { display: flex; justify-content: space-between; font-size: 13px; }
.budget-top span:first-child { color: var(--muted); text-transform: capitalize; }
.budget-bar { height: 8px; border-radius: 6px; background: var(--bg-4); overflow: hidden; }
.budget-fill { height: 100%; border-radius: 6px; background: var(--grad); transition: width .3s; }
.budget-fill.warn { background: linear-gradient(90deg, #f5a623, #f5b942); }
.budget-fill.danger { background: linear-gradient(90deg, #e5484d, #f0616d); }

/* Mic listening state */
.icon-btn.listening { color: var(--rec); background: rgba(255,77,94,.12); }
.icon-btn.listening .ic { animation: pulse 1.1s infinite; }

/* Install button — subtle accent to draw the eye */
.install-btn { color: var(--accent); }
.install-btn:hover { color: var(--accent); background: var(--grad-soft); }

/* In-bubble "thinking" indicator */
.thinking { display: flex; align-items: center; gap: 11px; padding: 3px 2px; }
.think-dots { display: inline-flex; gap: 5px; }
.think-dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: tdot 1.2s infinite ease-in-out both; }
.think-dots i:nth-child(1) { animation-delay: -0.24s; }
.think-dots i:nth-child(2) { animation-delay: -0.12s; }
@keyframes tdot { 0%, 80%, 100% { transform: scale(.5); opacity: .35; } 40% { transform: scale(1); opacity: 1; } }
.think-label { font-size: 14px; font-weight: 500; background: linear-gradient(90deg, var(--muted) 30%, var(--text) 50%, var(--muted) 70%); background-size: 200% 100%; -webkit-background-clip: text; background-clip: text; color: transparent; animation: shimmer 2.2s linear infinite; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* Code runner — Run/Preview button + result panel */
.cb-btns { display: flex; gap: 4px; }
.cb-run { background: transparent; color: var(--muted); font-size: 12px; padding: 3px 8px; gap: 5px; }
.cb-run:hover { color: #7ee787; background: rgba(126,231,135,.12); }
.cb-run .ic { width: 12px; height: 12px; fill: currentColor; stroke: none; }
.run-result { margin: 8px 0 4px; border: 1px solid var(--border-2); border-radius: 10px; overflow: hidden; background: var(--bg-2); }
.run-head { display: flex; align-items: center; justify-content: space-between; padding: 6px 12px; background: var(--bg-3); border-bottom: 1px solid var(--border); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.run-head button { background: transparent; color: var(--muted); padding: 2px 7px; font-size: 13px; border-radius: 6px; }
.run-head button:hover { background: var(--bg-4); color: var(--text); }
.run-frame { width: 100%; height: 440px; max-height: 70vh; border: 0; background: #fff; display: block; }
.run-output { margin: 0; padding: 13px 14px; font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace; font-size: 13px; line-height: 1.55; white-space: pre-wrap; word-break: break-word; max-height: 360px; overflow: auto; color: var(--text); }
.run-output.err { color: var(--danger); }

.edit-hint { font-size: 12px; margin: 6px 0 0; }
.edit-area { min-height: 90px; }
