:root {
  /* Surfaces — layered from deepest to most elevated */
  --bg: #080a12; --bg-2: #0c0f1d; --panel: #141928; --panel-2: #1d2440;
  --elev: #232c4c; --border: #29314e; --border-soft: #1e2640;
  /* Text */
  --text: #edf0fb; --muted: #95a1c2;
  /* Brand + state */
  --primary: #6f8bff; --primary-2: #a472ff;
  --accent: #34d6e6; --danger: #ff6b85; --ok: #2fe0a4; --warn: #ffce5c;
  /* Shape */
  --radius: 16px; --radius-sm: 11px; --radius-lg: 22px;
  /* Effects */
  --grad: linear-gradient(135deg, #6f8bff 0%, #a472ff 100%);
  --grad-soft: linear-gradient(135deg, rgba(111,139,255,0.16), rgba(164,114,255,0.16));
  --user-bubble: linear-gradient(135deg, #6f8bff, #a472ff);
  --code-bg: #0a0e1b;
  --shadow: 0 16px 44px -20px rgba(0,0,0,0.72);
  --shadow-sm: 0 4px 16px -8px rgba(0,0,0,0.6);
  --shadow-lg: 0 32px 72px -26px rgba(0,0,0,0.78);
  --glow: 0 0 0 3px rgba(111,139,255,0.22);
  --on-brand: #fff; /* readable text on brand-gradient surfaces (auto-contrast) */
}
[data-theme="light"] {
  --bg: #eef1fa; --bg-2: #ffffff; --panel: #ffffff; --panel-2: #f2f5fd;
  --elev: #ffffff; --border: #e2e7f3; --border-soft: #eef1f8;
  --text: #161d33; --muted: #5c6788;
  --primary: #5868f5; --primary-2: #8b5cf6;
  --accent: #0ea5b7; --danger: #e23d5b; --ok: #14a97c; --warn: #c98a12;
  --grad-soft: linear-gradient(135deg, rgba(88,104,245,0.10), rgba(139,92,246,0.10));
  --code-bg: #0d1320;
  --shadow: 0 18px 44px -22px rgba(40,60,120,0.30);
  --shadow-sm: 0 4px 16px -8px rgba(40,60,120,0.22);
  --shadow-lg: 0 34px 72px -28px rgba(40,60,120,0.34);
  --glow: 0 0 0 3px rgba(88,104,245,0.18);
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background:
    radial-gradient(1000px 560px at 8% -10%, rgba(111,139,255,0.10), transparent 60%),
    radial-gradient(900px 540px at 100% -6%, rgba(164,114,255,0.08), transparent 58%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text); line-height: 1.55; -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }
body, .panel, .card, .btn, .bubble, .conv-item, .stat, input, textarea, select { transition: background .25s, color .25s, border-color .2s, transform .12s, box-shadow .2s; }
.hidden { display: none !important; }
/* Visually hidden but available to screen readers. */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.muted { color: var(--muted); font-size: 0.9rem; }
.error { color: var(--danger); min-height: 1.2em; margin: 0.4rem 0 0; }
.warn { color: var(--warn); }
.only-mobile { display: none; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); background-clip: padding-box; }

.icon { width: 20px; height: 20px; display: inline-block; vertical-align: middle; flex: none; }
.gradient-text { background: var(--grad); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }

button { font: inherit; cursor: pointer; }
/* Clear keyboard-focus indicator for accessibility (mouse users unaffected). */
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 6px; }
a:focus-visible, .btn:focus-visible, .icon-btn:focus-visible, .tab:focus-visible, .subtab:focus-visible,
input:focus-visible, textarea:focus-visible, select:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.btn { border: 1px solid var(--border); background: var(--panel-2); color: var(--text);
  padding: 0.6rem 1.05rem; border-radius: var(--radius-sm); display: inline-flex; align-items: center; gap: 0.45rem; font-weight: 600; letter-spacing: -0.01em; }
.btn:hover { border-color: var(--primary); background: var(--elev); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn.primary { background: var(--grad); border: none; color: #fff; box-shadow: 0 8px 22px -8px rgba(111,139,255,0.65); }
.btn.primary:hover { filter: brightness(1.06); box-shadow: 0 12px 28px -8px rgba(111,139,255,0.75); }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: var(--panel-2); }
.btn.tiny { padding: 0.3rem 0.65rem; font-size: 0.78rem; border-radius: 8px; }
.btn.danger { color: var(--danger); border-color: transparent; background: transparent; }
.btn.danger:hover { border-color: var(--danger); background: color-mix(in srgb, var(--danger) 12%, transparent); }
.btn.block { width: 100%; justify-content: center; }
.icon-btn { background: transparent; border: none; color: var(--muted); padding: 0.45rem; border-radius: 10px; display: inline-flex; align-items: center; transition: background .15s, color .15s, transform .12s; }
.icon-btn:hover { color: var(--text); background: var(--panel-2); }
.icon-btn.send { color: #fff; background: var(--grad); box-shadow: 0 6px 18px -6px rgba(111,139,255,0.8); }
.icon-btn.send:hover { filter: brightness(1.08); transform: translateY(-1px); }
.icon-btn.send:disabled { opacity: 0.5; filter: grayscale(0.3); }
.icon-btn.recording { color: #fff; background: var(--danger); animation: pulse 1.1s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 8px rgba(255,107,133,0.18); } }

input, textarea, select { width: 100%; background: var(--bg-2); border: 1px solid var(--border);
  color: var(--text); border-radius: var(--radius-sm); padding: 0.62rem 0.8rem; font: inherit; }
input::placeholder, textarea::placeholder { color: color-mix(in srgb, var(--muted) 80%, transparent); }
input:hover, textarea:hover, select:hover { border-color: color-mix(in srgb, var(--primary) 45%, var(--border)); }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--primary); box-shadow: var(--glow); }
select { appearance: none; -webkit-appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: right 0.95rem center, right 0.7rem center; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; padding-right: 2rem; }
textarea { resize: vertical; }
label { display: block; margin: 0.7rem 0; font-size: 0.9rem; font-weight: 500; }
label small { font-weight: 400; }
label.checkbox { display: flex; align-items: center; gap: 0.5rem; font-weight: 500; }
label.checkbox input { width: auto; }
input[type="color"] { height: 40px; padding: 3px; cursor: pointer; }
input[type="range"] { accent-color: var(--primary); padding: 0; }

.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.35rem 1.5rem; margin-bottom: 1.1rem; box-shadow: var(--shadow); position: relative; }
.card h2 { margin-top: 0; margin-bottom: 0.4rem; font-size: 1.06rem; font-weight: 700; letter-spacing: -0.01em; display: flex; align-items: center; gap: 0.45rem; }
.card h2 .icon { color: var(--primary); }
.card > .muted:first-of-type, .card h2 + .muted { margin-top: 0; }
.card-subhead { font-size: 0.98rem; font-weight: 700; margin: 1.2rem 0 0.2rem; padding-top: 1rem; border-top: 1px solid var(--border-soft); display: flex; align-items: center; gap: 0.4rem; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0.6rem; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 1.2rem; }
@media (max-width: 760px) { .grid-2, .grid-3, .two-col { grid-template-columns: 1fr; } }

/* Login */
.login-view { display: flex; align-items: center; justify-content: center; padding: 2rem 1.5rem; min-height: 100%; overflow-y: auto;
  background: radial-gradient(1200px 600px at 20% -10%, rgba(106,141,255,0.25), transparent 60%),
              radial-gradient(1000px 600px at 100% 0%, rgba(155,107,255,0.22), transparent 55%), var(--bg); }
.login-wrap { display: grid; grid-template-columns: 1.15fr minmax(340px, 400px); gap: 2.6rem; align-items: center; max-width: 1080px; width: 100%; }
.login-card { width: 100%; justify-self: end; box-shadow: var(--shadow-lg); animation: rise .5s ease both; }
.login-card .btn.block { margin-top: 0.4rem; padding: 0.7rem 1rem; }
.brand { margin: 0 0 0.3rem; display: flex; align-items: center; gap: 0.6rem; font-size: 1.55rem; font-weight: 800; letter-spacing: -0.02em; }
.brand-icon { width: 34px; height: 34px; color: #fff; background: var(--grad); border-radius: 10px; padding: 6px; box-shadow: 0 10px 22px -8px rgba(111,139,255,0.8); }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } }

/* Login sales pitch */
.pitch { animation: rise .55s ease both; min-width: 0; }
.pitch-brand { display: flex; align-items: center; gap: 0.55rem; font-size: 1.45rem; font-weight: 800; margin-bottom: 1.1rem; }
.pitch-brand .brand-icon { width: 34px; height: 34px; }
.pitch-headline { font-size: clamp(1.9rem, 3.6vw, 2.8rem); line-height: 1.08; font-weight: 800; letter-spacing: -0.02em; margin: 0.2rem 0 0.8rem; }
.pitch-sub { color: var(--muted); font-size: 1.02rem; line-height: 1.6; max-width: 48ch; margin: 0 0 1.6rem; }
.pitch-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.7rem; margin-bottom: 1.4rem; }
.pitch-card { display: flex; gap: 0.7rem; align-items: flex-start; border: 1px solid var(--border); border-radius: 14px; padding: 0.9rem 0.95rem;
  background: color-mix(in srgb, var(--panel) 60%, transparent); backdrop-filter: blur(8px); box-shadow: var(--shadow-sm); transition: border-color .15s, transform .12s; }
.pitch-card:hover { border-color: color-mix(in srgb, var(--primary) 45%, var(--border)); transform: translateY(-2px); }
.pitch-card .icon { width: 22px; height: 22px; color: var(--primary); flex: none; margin-top: 2px; }
.pitch-card strong { display: block; font-size: 0.92rem; margin-bottom: 0.15rem; }
.pitch-card p { margin: 0; color: var(--muted); font-size: 0.82rem; line-height: 1.4; }
.pitch-pills { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.pitch-pills .pill { font-size: 0.78rem; color: var(--muted); background: var(--panel-2); border: 1px solid var(--border); border-radius: 999px; padding: 0.3rem 0.7rem; }

@media (max-width: 940px) {
  .login-view { align-items: flex-start; }
  .login-wrap { grid-template-columns: 1fr; gap: 1.6rem; max-width: 460px; }
  .login-card { order: -1; justify-self: stretch; }   /* form first on small screens */
  .pitch-brand { display: none; }                      /* the card already shows the brand */
  .pitch-headline { font-size: 1.7rem; }
}
@media (max-width: 460px) {
  .pitch-grid { grid-template-columns: 1fr; }
}

/* App shell */
.app-view { display: flex; height: 100vh; height: 100dvh; }
.sidebar { width: 282px; background: color-mix(in srgb, var(--bg-2) 92%, transparent); border-right: 1px solid var(--border-soft);
  display: flex; flex-direction: column; padding: 0.9rem; gap: 0.65rem; flex: none; }
.sidebar-head { padding: 0.15rem 0.15rem 0.35rem; }
.sidebar-brand { display: flex; align-items: center; gap: 0.6rem; font-size: 1.12rem; font-weight: 800; letter-spacing: -0.02em; }
.sidebar-brand .badge-icon { width: 32px; height: 32px; color: #fff; background: var(--grad); border-radius: 10px; padding: 6px; box-shadow: 0 8px 18px -8px rgba(111,139,255,0.8); }
.conv-search { position: relative; }
.conv-search input { padding-left: 0.85rem; font-size: 0.88rem; background: var(--bg); }
.conversation-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 0.1rem; margin-top: 0.1rem; }
.conv-item { display: flex; align-items: center; gap: 0.3rem; padding: 0.55rem 0.65rem; border-radius: 10px; cursor: pointer; color: var(--text); position: relative; border: 1px solid transparent; }
.conv-item:hover { background: var(--panel-2); }
.conv-item.active { background: color-mix(in srgb, var(--primary) 14%, transparent); border-color: color-mix(in srgb, var(--primary) 35%, transparent); }
.conv-item.active::before { content: ""; position: absolute; left: 0; top: 20%; bottom: 20%; width: 3px; border-radius: 3px; background: var(--grad); }
.conv-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.9rem; }
.conv-item .icon-btn { padding: 0.22rem; opacity: 0; }
.conv-item:hover .icon-btn { opacity: 1; }
/* A conversation with an active public link keeps its share icon visible & tinted. */
.conv-item .icon-btn.shared { opacity: 1; color: var(--primary); }
.conv-item .icon { width: 15px; height: 15px; }
.sidebar-foot { border-top: 1px solid var(--border-soft); padding-top: 0.7rem; font-size: 0.8rem; color: var(--muted); display: flex; align-items: center; gap: 0.5rem; }
.avatar-mini { width: 28px; height: 28px; border-radius: 9px; background: var(--grad); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-size: 0.78rem; font-weight: 800; flex: none; }
/* Solid translucent (no backdrop-filter): a blurred full-screen overlay stacked
   over the topbar blur + fixed body gradient caused heavy repaints that could
   lock up the pane on mobile. z-index sits above the topbar (3) and content. */
.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 8; -webkit-tap-highlight-color: transparent; animation: fade .2s ease both; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 0.6rem; padding: 0.6rem 1rem; background: color-mix(in srgb, var(--bg-2) 72%, transparent);
  backdrop-filter: blur(14px) saturate(1.2); border-bottom: 1px solid var(--border-soft); position: sticky; top: 0; z-index: 3; }
.topbar-nav { display: flex; gap: 0.3rem; background: var(--panel); border: 1px solid var(--border-soft); border-radius: 12px; padding: 0.2rem; }
.topbar-right { display: flex; align-items: center; gap: 0.15rem; margin-left: auto; }
.tab { background: transparent; border: none; color: var(--muted); padding: 0.42rem 0.95rem; border-radius: 9px; font-weight: 600; letter-spacing: -0.01em; }
.tab:hover { color: var(--text); }
.tab.active { background: var(--grad); color: #fff; box-shadow: 0 6px 16px -8px rgba(111,139,255,0.7); }

.tab-panel { flex: 1; overflow-y: auto; }
.chat-panel { display: flex; flex-direction: column; background:
  radial-gradient(1000px 560px at 50% -8%, rgba(111,139,255,0.07), transparent 62%); }
.admin-panel { padding: 1.4rem 1.3rem 3rem; max-width: 1060px; width: 100%; margin: 0 auto; }

/* Chat messages */
.messages { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 1.1rem; padding: 1.4rem; max-width: 880px; width: 100%; margin: 0 auto; }
.msg { display: flex; gap: 0.7rem; align-items: flex-start; max-width: 100%; animation: pop .28s ease both; }
.msg.user { flex-direction: row-reverse; }
@keyframes pop { from { opacity: 0; transform: translateY(8px); } }
.avatar { width: 34px; height: 34px; border-radius: 11px; flex: none; display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 0.8rem; }
.avatar.bot { background: var(--grad); color: #fff; box-shadow: 0 8px 18px -8px rgba(111,139,255,0.85); }
.avatar.bot .icon { width: 20px; height: 20px; }
.avatar.user { background: var(--panel-2); border: 1px solid var(--border); color: var(--text); }
.bubble { padding: 0.8rem 1.05rem; border-radius: 18px; max-width: 78%; word-wrap: break-word; overflow-wrap: anywhere; }
.msg.user .bubble { background: var(--user-bubble); color: #fff; border-bottom-right-radius: 6px; white-space: pre-wrap; box-shadow: 0 10px 24px -14px rgba(111,139,255,0.85); }
.msg.assistant .bubble { background: var(--panel); border: 1px solid var(--border); border-bottom-left-radius: 6px; box-shadow: var(--shadow-sm); }
.msg.assistant.error .bubble { border-color: var(--danger); background: color-mix(in srgb, var(--danger) 7%, var(--panel)); }
.msg-actions { display: flex; gap: 0.15rem; margin-top: 0.5rem; align-items: center; flex-wrap: wrap; }
.msg-actions .icon-btn { padding: 0.28rem; }
.msg-actions .icon { width: 16px; height: 16px; }
.badge { display: inline-flex; align-items: center; gap: 0.35rem; font-size: 0.72rem; color: var(--muted);
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 999px; padding: 0.18rem 0.6rem; margin-left: auto; }
.badge .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }
.badge.sheriff .dot { background: var(--warn); }
.typing-dots span { display: inline-block; width: 8px; height: 8px; margin: 0 2px; background: var(--primary); border-radius: 50%; animation: blink 1.2s infinite both; }
.typing-dots span:nth-child(2) { animation-delay: .2s; } .typing-dots span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; transform: scale(.8); } 40% { opacity: 1; transform: scale(1); } }

/* Markdown */
.md p { margin: 0 0 0.6rem; } .md p:last-child { margin-bottom: 0; }
.md h1, .md h2, .md h3 { margin: 0.5rem 0 0.4rem; line-height: 1.25; }
.md h1 { font-size: 1.25rem; } .md h2 { font-size: 1.12rem; } .md h3 { font-size: 1.02rem; }
.md ul, .md ol { margin: 0.3rem 0 0.6rem; padding-left: 1.3rem; } .md li { margin: 0.15rem 0; }
.md a { color: var(--primary); }
.md code { background: var(--code-bg); color: #d7e0ff; padding: 0.1rem 0.4rem; border-radius: 6px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.86em; }
.md pre { background: var(--code-bg); border: 1px solid var(--border); border-radius: 12px; padding: 0.85rem 0.9rem; overflow-x: auto; position: relative; margin: 0.6rem 0; }
.md pre code { background: none; padding: 0; color: #d7e0ff; }
.md pre .copy-code { position: absolute; top: 7px; right: 7px; color: #8e9bc7; }
.md pre .copy-code:hover { color: #fff; background: rgba(255,255,255,0.08); }
.md blockquote { border-left: 3px solid var(--primary); margin: 0.5rem 0; padding: 0.1rem 0.9rem; color: var(--muted); }
/* Syntax highlighting */
.tok-kw { color: #c792ea; } .tok-str { color: #c3e88d; } .tok-com { color: #6b7596; font-style: italic; }
.tok-num { color: #f78c6c; } .tok-fn { color: #82aaff; }

/* Compare */
.modal-card.compare-card { max-width: 860px; width: 100%; }
.compare-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 0.8rem; margin-top: 0.8rem; }
.compare-col { border: 1px solid var(--border); border-radius: 12px; background: var(--bg-2); overflow: hidden; display: flex; flex-direction: column; }
.compare-head { padding: 0.5rem 0.8rem; font-size: 0.82rem; font-weight: 600; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 0.4rem; }
.compare-head .lat { margin-left: auto; font-weight: 500; color: var(--muted); font-size: 0.75rem; }
.cmp-out { padding: 0.8rem; max-height: 46vh; overflow-y: auto; min-height: 80px; }
@media (max-width: 620px) { .compare-cols { grid-template-columns: 1fr; } }

/* Share view */
.share-view { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
.share-view .messages { flex: 1; }
.share-foot { text-align: center; padding: 0.8rem; border-top: 1px solid var(--border); margin: 0; }

/* Hero empty state */
.hero { margin: auto; text-align: center; padding: 2.4rem 1rem; animation: rise .5s ease both; }
.hero-avatar { width: 88px; height: 88px; margin: 0 auto 1.1rem; border-radius: 24px; background: var(--grad); color: #fff;
  display: flex; align-items: center; justify-content: center; box-shadow: 0 24px 56px -18px rgba(111,139,255,0.85); position: relative; }
.hero-avatar .icon { width: 48px; height: 48px; }
.hero-avatar::after { content: ""; position: absolute; inset: -10px; border-radius: 30px; background: var(--grad); filter: blur(30px); opacity: 0.45; z-index: -1; }
.hero-title { font-size: 2rem; margin: 0.2rem 0; font-weight: 800; letter-spacing: -0.025em; }
.hero-sub { color: var(--muted); margin: 0 0 1.5rem; font-size: 1.02rem; }
.suggest-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.7rem; max-width: 640px; margin: 0 auto; }
.suggest-card { display: flex; align-items: center; gap: 0.65rem; text-align: left; background: var(--panel); border: 1px solid var(--border);
  border-radius: 14px; padding: 0.9rem 1.05rem; color: var(--text); font-size: 0.92rem; font-weight: 500; box-shadow: var(--shadow-sm); transition: border-color .15s, transform .12s, box-shadow .2s; }
.suggest-card:hover { border-color: var(--primary); transform: translateY(-2px); box-shadow: 0 14px 30px -16px rgba(111,139,255,0.5); }
.suggest-card .icon { color: var(--primary); width: 18px; height: 18px; }
@media (max-width: 560px) { .suggest-grid { grid-template-columns: 1fr; } .hero-title { font-size: 1.6rem; } }

.suggestions { display: flex; flex-wrap: wrap; gap: 0.5rem; padding: 0 1.4rem; max-width: 880px; width: 100%; margin: 0 auto; }
.suggestion { background: var(--panel); border: 1px solid var(--border); color: var(--text); border-radius: 999px; padding: 0.4rem 0.85rem; font-size: 0.84rem; }
.suggestion:hover { border-color: var(--primary); }

/* Composer */
.composer { padding: 0.6rem 1rem 1.1rem; max-width: 880px; width: 100%; margin: 0 auto; }
.composer-row { display: flex; gap: 0.4rem; align-items: flex-end; background: var(--panel); border: 1px solid var(--border);
  border-radius: 20px; padding: 0.4rem 0.5rem; box-shadow: var(--shadow); }
.composer-row:focus-within { border-color: var(--primary); box-shadow: var(--glow), var(--shadow); }
.composer textarea { max-height: 180px; border: none; background: transparent; box-shadow: none; padding: 0.5rem; }
.composer textarea:focus { box-shadow: none; }
.speak-toggle { display: flex; align-items: center; margin: 0; color: var(--muted); padding: 0.4rem; }
.speak-toggle input { width: auto; margin-right: 4px; }
.attach-list { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 0.5rem; }
.attach-chip { display: inline-flex; align-items: center; gap: 0.4rem; background: var(--panel-2); border: 1px solid var(--border); border-radius: 999px; padding: 0.25rem 0.7rem; font-size: 0.8rem; }
.attach-chip button { background: transparent; border: none; color: var(--muted); padding: 0; }

/* Admin */
.admin-tabs { display: flex; gap: 0.4rem; margin-bottom: 1.4rem; flex-wrap: wrap; }
.subtab { background: var(--panel); border: 1px solid var(--border); color: var(--muted); padding: 0.55rem 0.9rem; border-radius: 11px; font-weight: 600; letter-spacing: -0.01em; display: inline-flex; align-items: center; gap: 0.45rem; transition: color .15s, border-color .15s, background .15s; }
.subtab:hover { color: var(--text); border-color: color-mix(in srgb, var(--primary) 45%, var(--border)); }
.subtab.active { color: #fff; background: var(--grad); border-color: transparent; box-shadow: 0 8px 20px -8px rgba(111,139,255,0.7); }
.subtab .icon { width: 16px; height: 16px; }
.sticky-save { position: sticky; bottom: 0; background: color-mix(in srgb, var(--panel) 88%, transparent); backdrop-filter: blur(8px); padding: 0.9rem 0 0.2rem; margin-top: 0.4rem; display: flex; gap: 0.8rem; align-items: center; }
.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.1rem; gap: 0.5rem; flex-wrap: wrap; }
.section-head h1 { font-size: 1.45rem; font-weight: 800; letter-spacing: -0.02em; margin: 0; }

/* Onboarding nudge banner */
.nudge { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
  border: 1px solid color-mix(in srgb, var(--primary) 45%, var(--border)); border-radius: var(--radius); padding: 1rem 1.2rem; margin-bottom: 1.3rem;
  background: var(--grad-soft); box-shadow: var(--shadow-sm); }
.nudge .btn { flex: none; }
.company-progress { font-size: 0.78rem; color: var(--muted); background: var(--panel-2);
  border: 1px solid var(--border); border-radius: 999px; padding: 0.2rem 0.7rem; white-space: nowrap; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(155px, 1fr)); gap: 0.9rem; margin-bottom: 1.3rem; }
.stat { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.15rem 1.2rem; position: relative; overflow: hidden; box-shadow: var(--shadow-sm); }
.stat::after { content: ""; position: absolute; right: -24px; top: -24px; width: 88px; height: 88px; border-radius: 50%; background: var(--grad); opacity: 0.14; }
.stat .v { font-size: 2.1rem; font-weight: 800; letter-spacing: -0.03em; } .stat .k { color: var(--muted); font-size: 0.82rem; }
.bar-chart { display: flex; align-items: flex-end; gap: 5px; height: 150px; }
.bar-wrap { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; height: 100%; }
.bar { background: var(--grad); border-radius: 5px 5px 0 0; min-height: 3px; position: relative; transition: height .5s ease; }
.bar span { position: absolute; bottom: -18px; left: 0; right: 0; text-align: center; font-size: 0.58rem; color: var(--muted); }
.usage-row { display: flex; align-items: center; gap: 0.6rem; margin: 0.5rem 0; }
.usage-row .label { width: 120px; font-size: 0.85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.usage-bar { flex: 1; height: 10px; background: var(--panel-2); border-radius: 6px; overflow: hidden; }
.usage-bar > div { height: 100%; background: var(--grad); transition: width .5s ease; }
.recent-item { font-size: 0.85rem; padding: 0.5rem 0; border-bottom: 1px solid var(--border); }
.recent-item .who { color: var(--muted); }

.users-table { width: 100%; border-collapse: collapse; }
.users-table th, .users-table td { text-align: left; padding: 0.55rem; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
.role-pill { padding: 0.12rem 0.6rem; border-radius: 999px; font-size: 0.74rem; font-weight: 600; border: 1px solid var(--border); color: var(--muted); }
.role-pill.admin { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 55%, transparent); background: color-mix(in srgb, var(--warn) 12%, transparent); }
.kb-item, .key-row, .dept-row { border: 1px solid var(--border-soft); border-radius: 13px; padding: 1.05rem 1.1rem; margin-bottom: 0.8rem; background: var(--bg-2); }
.dept-row .dept-name { font-weight: 700; }
.dept-row label { margin: 0.5rem 0 0; font-size: 0.85rem; color: var(--muted); }
.kb-head { display: flex; align-items: center; gap: 0.5rem; justify-content: space-between; }
.kb-title-wrap { display: flex; align-items: center; gap: 0.4rem; min-width: 0; }
.gated-pill { font-size: 0.7rem; color: var(--warn); border: 1px solid var(--warn); border-radius: 999px; padding: 0.05rem 0.5rem; white-space: nowrap; }
.kb-vis { display: flex; align-items: center; gap: 0.5rem; margin-top: 0.6rem; flex-wrap: wrap; }
.kb-vis .kb-vis-select { width: auto; min-width: 180px; padding: 0.3rem 0.55rem; font-size: 0.85rem; }
.kb-img-row { display: flex; align-items: center; gap: 0.5rem; margin-top: 0.6rem; flex-wrap: wrap; }
.kb-img-row .btn { flex: none; }
.kb-thumb { width: 56px; height: 56px; object-fit: cover; border-radius: 10px; border: 1px solid var(--border); background: var(--bg-2); }
.logo-row .kb-thumb.hidden { display: none; }
.key-head { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.key-status { font-size: 0.78rem; font-weight: 600; padding: 0.2rem 0.65rem; border-radius: 999px; border: 1px solid transparent; }
.key-status.set { background: color-mix(in srgb, var(--ok) 16%, transparent); border-color: color-mix(in srgb, var(--ok) 40%, transparent); color: var(--ok); }
.key-status.unset { background: color-mix(in srgb, var(--danger) 12%, transparent); border-color: color-mix(in srgb, var(--danger) 35%, transparent); color: var(--danger); }
.key-guide { font-size: 0.85rem; color: var(--muted); margin: 0.5rem 0; }
.key-guide ol { margin: 0.3rem 0 0; padding-left: 1.1rem; } .key-guide a { color: var(--primary); }
.key-pricing { font-size: 0.82rem; color: var(--muted); margin: 0.4rem 0 0.6rem; }
.key-pricing small { display: block; margin: 0.1rem 0 0.3rem; opacity: 0.85; }
.price-row { display: flex; justify-content: space-between; gap: 1rem; padding: 0.1rem 0; border-top: 1px solid var(--border); }
.price-model { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.76rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.price-val { color: var(--text); white-space: nowrap; }
.key-input-row { display: flex; gap: 0.5rem; }
.icon-preview-row { display: flex; align-items: center; gap: 0.7rem; margin: 0.9rem 0; }
.icon-preview { border-radius: 18px; border: 1px solid var(--border); box-shadow: var(--shadow); }

/* Brand-colour preset swatches */
.brand-presets { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0.2rem 0 0.3rem; }
.brand-swatch { width: 34px; height: 34px; border-radius: 9px; border: 2px solid var(--border); cursor: pointer; padding: 0; position: relative; transition: transform .12s, border-color .15s; }
.brand-swatch:hover { transform: translateY(-2px) scale(1.05); }
.brand-swatch.active { border-color: var(--text); box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--primary); }
.brand-swatch.active::after { content: "✓"; position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: #fff; font-size: 0.85rem; font-weight: 800; text-shadow: 0 1px 2px rgba(0,0,0,0.5); }

/* PWA display-mode preview cards */
.display-modes { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.6rem; margin: 0.35rem 0 0.4rem; }
@media (max-width: 640px) { .display-modes { grid-template-columns: 1fr 1fr; } }
.display-mode { text-align: left; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 0.55rem 0.55rem 0.65rem;
  display: flex; flex-direction: column; gap: 0.35rem; cursor: pointer; color: var(--text); transition: border-color .15s, transform .12s, box-shadow .2s; }
.display-mode:hover { border-color: color-mix(in srgb, var(--primary) 45%, var(--border)); transform: translateY(-2px); }
.display-mode.active { border-color: var(--primary); box-shadow: var(--glow); }
.display-mode strong { font-size: 0.82rem; font-weight: 700; }
.display-mode .muted { font-size: 0.72rem; line-height: 1.25; }
/* Outlined device mockup */
.dm-device { aspect-ratio: 5 / 4; border: 1.5px solid var(--muted); border-radius: 8px; background: var(--bg-2); overflow: hidden; display: flex; flex-direction: column; }
.display-mode.active .dm-device { border-color: var(--primary); }
.dm-status { height: 18%; display: flex; align-items: center; justify-content: flex-end; gap: 2px; padding: 0 5px; }
.dm-chrome { height: 28%; border-bottom: 1.5px solid var(--muted); display: flex; align-items: center; gap: 3px; padding: 0 5px; }
.dm-chrome-min { height: 20%; }
.dm-dot { width: 3.5px; height: 3.5px; border-radius: 50%; background: var(--muted); flex: none; }
.dm-tick { width: 4px; height: 3px; border-radius: 1px; background: var(--muted); }
.dm-batt { width: 8px; height: 4px; border: 1px solid var(--muted); border-radius: 1.5px; }
.dm-back { width: 5px; height: 5px; border-left: 1.5px solid var(--muted); border-bottom: 1.5px solid var(--muted); transform: rotate(45deg); flex: none; margin-left: 2px; }
.dm-url { flex: 1; height: 6px; border-radius: 4px; background: color-mix(in srgb, var(--muted) 32%, transparent); }
.dm-screen { flex: 1; background: var(--grad-soft); position: relative; }
.dm-screen::after { content: ""; position: absolute; left: 16%; right: 16%; top: 30%; height: 8%; border-radius: 3px; background: color-mix(in srgb, var(--primary) 40%, transparent); box-shadow: 0 9px 0 color-mix(in srgb, var(--muted) 22%, transparent), 0 18px 0 color-mix(in srgb, var(--muted) 22%, transparent); }
.dm-screen-full::before { content: ""; position: absolute; inset: 0; border: 1px dashed color-mix(in srgb, var(--primary) 45%, transparent); border-radius: 5px; margin: 3px; }
output { font-size: 0.8rem; color: var(--muted); }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(4,6,14,0.62); backdrop-filter: blur(6px); display: flex; align-items: center; justify-content: center; padding: 1rem; z-index: 20; animation: fade .18s ease both; }
.modal-card { width: 100%; max-width: 420px; box-shadow: var(--shadow-lg); border-color: var(--border); animation: rise .28s ease both; }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.3rem; }
.modal-head h2 { margin-bottom: 0; }
.modal-actions { display: flex; gap: 0.5rem; justify-content: flex-end; margin-top: 0.7rem; }
@keyframes fade { from { opacity: 0; } }

/* Toasts */
#toast-host { position: fixed; bottom: 1.4rem; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 0.5rem; z-index: 50; align-items: center; }
.toast { background: var(--elev); border: 1px solid var(--border); color: var(--text); padding: 0.65rem 1.05rem; border-radius: 12px; box-shadow: var(--shadow-lg); font-size: 0.88rem; font-weight: 500; animation: rise .25s ease both; transition: opacity .25s; }
.toast.ok { border-color: color-mix(in srgb, var(--ok) 55%, var(--border)); }

@media (max-width: 860px) {
  .only-mobile { display: inline-flex; }
  .sidebar { position: fixed; z-index: 10; height: 100%; transform: translateX(-100%); transition: transform 0.25s; box-shadow: var(--shadow); }
  .sidebar.open { transform: translateX(0); }
  .bubble { max-width: 84%; }
}

/* Auto-contrast: text/glyph colour on brand-gradient surfaces. Defaults to
   white; applyBrandColors() flips it to dark for light brand colours. */
.btn.primary, .icon-btn.send, .brand-icon, .sidebar-brand .badge-icon, .avatar-mini,
.tab.active, .subtab.active, .avatar.bot, .msg.user .bubble, .hero-avatar { color: var(--on-brand); }
.gradient-text { color: var(--primary); }

/* Brand logo (replaces the icon glyph in brand spots when set) */
.has-logo .brand-icon, .has-logo .sidebar-brand .badge-icon, .has-logo .hero-avatar,
.has-logo .avatar.bot, .has-logo #share-bot .badge-icon {
  background: var(--bg-2) var(--logo, none) center / cover no-repeat;
  box-shadow: var(--shadow-sm); padding: 0;
}
.has-logo .brand-icon .icon, .has-logo .sidebar-brand .badge-icon .icon, .has-logo .hero-avatar .icon, .has-logo .avatar.bot .icon { display: none; }
.has-logo .hero-avatar::after { opacity: 0.25; }
.logo-row { display: flex; align-items: center; gap: 0.7rem; margin: 0.3rem 0 0; }
.logo-row img { width: 44px; height: 44px; object-fit: contain; border-radius: 9px; border: 1px solid var(--border); background: var(--bg-2); padding: 3px; }

/* Reply feedback (thumbs) */
.msg-actions .icon-btn.fb-on[data-fb="up"] { color: var(--ok); }
.msg-actions .icon-btn.fb-on[data-fb="down"] { color: var(--danger); }

/* Respect users who prefer reduced motion: drop animations and transitions. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}
