:root {
  --bg: #090d16; --panel: #0f1626; --card: #151e32; --card2: #1b2640;
  --accent: #6366f1; --accent-light: #818cf8; --text: #f8fafc; --muted: #94a3b8;
  --border: #1e293b; --danger: #f87171; --ok: #22c55e; --radius: 14px;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body { background: var(--bg); color: var(--text); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans Devanagari", sans-serif; overflow: hidden; }
button, select, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.layout { display: flex; height: 100vh; height: 100dvh; }

/* Sidebar */
.sidebar { width: 280px; flex-shrink: 0; background: #0b111e; border-right: 1px solid var(--border); display: flex; flex-direction: column; padding: 0.85rem; gap: 0.7rem; }
.side-top { display: flex; gap: 0.5rem; }
.new-chat { flex: 1; background: var(--accent); border: none; color: #fff; border-radius: 10px; padding: 0.65rem; font-weight: 600; display: flex; gap: 0.5rem; align-items: center; justify-content: center; }
.new-chat:hover { background: var(--accent-light); }
.search-box { display: flex; align-items: center; gap: 0.5rem; background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 0.5rem 0.7rem; color: var(--muted); }
.search-box input { flex: 1; background: none; border: none; outline: none; min-width: 0; }
.chat-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.chat-group { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); padding: 0.6rem 0.5rem 0.25rem; }
.chat-item { display: flex; align-items: center; gap: 0.3rem; border-radius: 8px; padding: 0.15rem 0.2rem 0.15rem 0.6rem; }
.chat-item:hover, .chat-item.active { background: var(--card); }
.chat-item.active { box-shadow: inset 2px 0 0 var(--accent); }
.chat-item .title { flex: 1; min-width: 0; background: none; border: none; text-align: left; padding: 0.45rem 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 0.88rem; }
.chat-item input { flex: 1; min-width: 0; background: var(--bg); border: 1px solid var(--accent); border-radius: 6px; padding: 0.3rem 0.4rem; font-size: 0.85rem; outline: none; }
.chat-item .mini { background: none; border: none; color: var(--muted); padding: 0.35rem; border-radius: 6px; opacity: 0; font-size: 0.8rem; }
.chat-item:hover .mini, .chat-item.active .mini { opacity: 1; }
.chat-item .mini:hover { color: var(--text); background: var(--card2); }
.empty-list { color: var(--muted); font-size: 0.85rem; padding: 0.6rem; }
.side-bottom { display: flex; flex-direction: column; gap: 0.5rem; border-top: 1px solid var(--border); padding-top: 0.7rem; }
.field { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.75rem; color: var(--muted); }
.field select, .mode-select, .tool-select { background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 0.45rem 0.5rem; color: var(--text); outline: none; }
.link-btn { background: none; border: none; color: var(--muted); text-decoration: none; font-size: 0.85rem; display: flex; gap: 0.5rem; align-items: center; padding: 0.35rem 0.2rem; text-align: left; }
.link-btn:hover { color: var(--text); }
.link-btn.danger:hover { color: var(--danger); }
.privacy { font-size: 0.72rem; color: var(--muted); line-height: 1.45; }
.scrim { display: none; }
.icon-only { background: var(--card); border: 1px solid var(--border); color: var(--muted); border-radius: 10px; width: 38px; height: 38px; display: inline-grid; place-items: center; flex-shrink: 0; }
.icon-only:hover { color: var(--text); border-color: var(--accent); }
.icon-only.accent { color: var(--accent-light); }
.close-side, #openSideBtn { display: none; }

/* Main */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--panel); }
.topbar { display: flex; align-items: center; gap: 0.7rem; padding: 0.7rem 1rem; border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 0.7rem; flex: 1; min-width: 0; }
.brand h1 { font-size: 1rem; }
.brand p { font-size: 0.75rem; color: var(--muted); display: flex; align-items: center; gap: 0.35rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.avatar { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; background: linear-gradient(135deg, var(--accent), var(--accent-light)); flex-shrink: 0; color: #fff; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex-shrink: 0; }
.dot.on { background: var(--ok); }
.dot.off { background: var(--danger); }

.feed { flex: 1; overflow-y: auto; padding: 1.25rem 1rem 0.5rem; }
.feed-inner { max-width: 820px; margin: 0 auto; display: flex; flex-direction: column; gap: 1.25rem; }
.welcome { text-align: center; padding: 3rem 0.5rem 1rem; }
.welcome .avatar { width: 64px; height: 64px; margin: 0 auto 1rem; font-size: 1.6rem; }
.welcome h2 { font-size: 1.5rem; margin-bottom: 0.4rem; }
.welcome p { color: var(--muted); font-size: 0.92rem; }
.starters { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0.6rem; margin-top: 1.5rem; text-align: left; }
.starter { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 0.75rem 0.85rem; font-size: 0.86rem; color: var(--text); }
.starter:hover { border-color: var(--accent); }
.starter i { color: var(--accent-light); margin-right: 0.4rem; }

.msg { display: flex; gap: 0.75rem; }
.msg.user { flex-direction: row-reverse; }
.msg .avatar { width: 30px; height: 30px; font-size: 0.8rem; }
.msg.user .avatar { background: var(--card2); }
.msg-body { min-width: 0; max-width: calc(100% - 42px); display: flex; flex-direction: column; }
.msg.user .msg-body { align-items: flex-end; }
.bubble { line-height: 1.65; font-size: 0.95rem; overflow-wrap: anywhere; }
.msg.user .bubble { background: var(--accent); color: #fff; padding: 0.65rem 0.95rem; border-radius: var(--radius); border-top-right-radius: 4px; white-space: pre-wrap; }
.msg.bot .bubble { padding-top: 0.25rem; }
.bubble p, .bubble ul, .bubble ol, .bubble pre, .bubble table, .bubble blockquote, .bubble h1, .bubble h2, .bubble h3, .bubble h4 { margin: 0 0 0.7rem; }
.bubble > *:last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { padding-left: 1.4rem; }
.bubble h1 { font-size: 1.3rem; } .bubble h2 { font-size: 1.15rem; } .bubble h3 { font-size: 1.05rem; }
.bubble a { color: var(--accent-light); }
.bubble blockquote { border-left: 3px solid var(--accent); padding-left: 0.8rem; color: var(--muted); }
.bubble table { border-collapse: collapse; display: block; overflow-x: auto; font-size: 0.88rem; }
.bubble th, .bubble td { border: 1px solid var(--border); padding: 0.4rem 0.6rem; }
.bubble th { background: var(--card); }
.bubble :not(pre) > code { background: var(--card2); padding: 0.1rem 0.35rem; border-radius: 5px; font-size: 0.86em; }
.bubble img { max-width: 100%; border-radius: 12px; }
.code-block { border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: #0d1117; margin: 0 0 0.7rem; }
.code-head { display: flex; justify-content: space-between; align-items: center; padding: 0.35rem 0.75rem; background: #111a2e; font-size: 0.75rem; color: var(--muted); }
.code-head button { background: none; border: none; color: var(--muted); font-size: 0.75rem; }
.code-head button:hover { color: var(--text); }
.code-block pre { margin: 0; padding: 0.8rem; overflow-x: auto; font-size: 0.85rem; }
.code-block code { font-family: "Fira Code", Consolas, Menlo, monospace; background: none !important; padding: 0 !important; }
.cursor::after { content: "▍"; animation: blinkc 1s steps(2) infinite; color: var(--accent-light); }
@keyframes blinkc { 50% { opacity: 0; } }
.status-pill { display: inline-flex; align-items: center; gap: 0.45rem; font-size: 0.82rem; color: var(--muted); }
.status-pill i { color: var(--accent-light); }
.err { color: var(--danger); background: rgba(248, 113, 113, 0.08); border: 1px solid rgba(248, 113, 113, 0.3); border-radius: 10px; padding: 0.55rem 0.8rem; font-size: 0.88rem; }

.msg-atts { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 0.4rem; justify-content: flex-end; }
.msg-atts img { width: 120px; height: 120px; object-fit: cover; border-radius: 10px; border: 1px solid var(--border); cursor: zoom-in; }
.file-chip { display: inline-flex; align-items: center; gap: 0.4rem; background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 0.35rem 0.6rem; font-size: 0.78rem; max-width: 220px; }
.file-chip span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-chip i { color: var(--accent-light); }
.gen-img { max-width: min(100%, 512px); border-radius: 12px; border: 1px solid var(--border); display: block; margin-bottom: 0.5rem; cursor: zoom-in; }
.sources { margin-top: 0.7rem; display: flex; flex-wrap: wrap; gap: 0.4rem; }
.sources-title { width: 100%; font-size: 0.75rem; color: var(--muted); }
.source { font-size: 0.76rem; background: var(--card); border: 1px solid var(--border); border-radius: 999px; padding: 0.25rem 0.65rem; color: var(--accent-light); text-decoration: none; max-width: 260px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.source:hover { border-color: var(--accent); }
.msg-actions { display: flex; gap: 0.15rem; margin-top: 0.35rem; align-items: center; flex-wrap: wrap; }
.msg-actions button { background: none; border: none; color: var(--muted); padding: 0.3rem 0.45rem; border-radius: 6px; font-size: 0.8rem; }
.msg-actions button:hover { color: var(--text); background: var(--card); }
.msg-actions .meta { font-size: 0.7rem; color: var(--muted); margin-left: 0.3rem; opacity: 0.8; }
.msg.user .msg-actions { opacity: 0; }
.msg.user:hover .msg-actions { opacity: 1; }
.edit-box { width: min(620px, 100%); display: flex; flex-direction: column; gap: 0.4rem; }
.edit-box textarea { width: 100%; min-height: 80px; background: var(--card); border: 1px solid var(--accent); border-radius: 10px; padding: 0.6rem; outline: none; resize: vertical; }
.edit-box div { display: flex; gap: 0.4rem; justify-content: flex-end; }

/* Composer */
.composer-wrap { padding: 0.4rem 1rem calc(0.6rem + env(safe-area-inset-bottom)); }
.composer, .attach-strip, .hint { max-width: 820px; margin: 0 auto; }
.composer { background: var(--card); border: 1px solid var(--border); border-radius: 18px; padding: 0.55rem 0.6rem 0.5rem; }
.composer:focus-within { border-color: var(--accent); }
.composer textarea { width: 100%; resize: none; background: none; border: none; outline: none; padding: 0.35rem 0.45rem; font-size: 0.97rem; max-height: 200px; line-height: 1.5; }
.composer-row { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.tools { display: flex; gap: 0.25rem; align-items: center; flex-wrap: wrap; }
.tool { background: none; border: 1px solid transparent; color: var(--muted); border-radius: 999px; height: 34px; min-width: 34px; padding: 0 0.55rem; display: inline-flex; align-items: center; gap: 0.35rem; font-size: 0.85rem; }
.tool:hover { color: var(--text); background: var(--card2); }
.tool.toggle[aria-pressed="true"] { color: var(--accent-light); border-color: var(--accent); background: rgba(99, 102, 241, 0.12); }
.tool.recording { color: #fff; background: var(--danger); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgba(248, 113, 113, 0.25); } }
.send { width: 36px; height: 36px; border-radius: 50%; border: none; background: var(--accent); color: #fff; flex-shrink: 0; }
.send:disabled { opacity: 0.4; cursor: not-allowed; }
.send.stop { background: var(--text); color: var(--bg); }
.attach-strip { display: flex; gap: 0.45rem; flex-wrap: wrap; padding-bottom: 0.45rem; }
.attach-strip:empty { display: none; }
.att { position: relative; }
.att img { width: 64px; height: 64px; object-fit: cover; border-radius: 10px; border: 1px solid var(--border); display: block; }
.att .file-chip { height: 64px; flex-direction: column; justify-content: center; align-items: flex-start; gap: 0.15rem; }
.att .file-chip small { color: var(--muted); font-size: 0.68rem; }
.att .rm { position: absolute; top: -6px; right: -6px; width: 20px; height: 20px; border-radius: 50%; border: none; background: var(--text); color: var(--bg); font-size: 0.65rem; display: grid; place-items: center; }
.att.loading { opacity: 0.6; }
.hint { text-align: center; font-size: 0.7rem; color: var(--muted); padding-top: 0.4rem; }

/* Dialogs */
.dlg { margin: auto; background: var(--panel); color: var(--text); border: 1px solid var(--border); border-radius: 18px; width: min(560px, 94vw); padding: 1rem; }
.dlg::backdrop { background: rgba(0, 0, 0, 0.7); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.8rem; }
.dlg-head h2 { font-size: 1.05rem; display: flex; gap: 0.5rem; align-items: center; }
.dlg-actions { display: flex; gap: 0.5rem; justify-content: center; flex-wrap: wrap; margin-top: 0.9rem; }
.btn { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 0.55rem 0.9rem; display: inline-flex; gap: 0.45rem; align-items: center; font-size: 0.9rem; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #111; }
.cam-stage { position: relative; background: #000; border-radius: 12px; overflow: hidden; aspect-ratio: 4 / 3; display: grid; place-items: center; }
.cam-stage video, .cam-stage img { width: 100%; height: 100%; object-fit: contain; }
.cam-msg { position: absolute; inset: auto 1rem; text-align: center; color: var(--muted); font-size: 0.88rem; }
.orb { width: 120px; height: 120px; margin: 0.5rem auto 0.8rem; border-radius: 50%; display: grid; place-items: center; font-size: 2.2rem; background: radial-gradient(circle, var(--accent-light), var(--accent)); color: #fff; transition: transform 0.15s; }
.orb.live { animation: breathe 2s infinite ease-in-out; }
@keyframes breathe { 50% { transform: scale(1.08); box-shadow: 0 0 40px rgba(129, 140, 248, 0.5); } }
.voice-status { text-align: center; color: var(--muted); font-size: 0.9rem; }
.voice-log { max-height: 200px; overflow-y: auto; margin-top: 0.8rem; display: flex; flex-direction: column; gap: 0.4rem; font-size: 0.86rem; }
.voice-log p { background: var(--card); border-radius: 8px; padding: 0.4rem 0.6rem; }
.voice-log p b { color: var(--accent-light); }
.toast { position: fixed; left: 50%; bottom: 6rem; transform: translateX(-50%) translateY(20px); background: var(--card2); border: 1px solid var(--border); padding: 0.6rem 1rem; border-radius: 10px; font-size: 0.88rem; opacity: 0; pointer-events: none; transition: 0.2s; z-index: 100; max-width: 90vw; }
.toast.show { opacity: 1; transform: translateX(-50%); }
.lightbox { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.9); display: grid; place-items: center; z-index: 90; cursor: zoom-out; }
.lightbox img { max-width: 95vw; max-height: 95vh; border-radius: 8px; }
[hidden] { display: none !important; }

@media (max-width: 860px) {
  .sidebar { position: fixed; inset: 0 auto 0 0; z-index: 50; transform: translateX(-100%); transition: transform 0.22s; width: min(300px, 86vw); }
  .sidebar.open { transform: none; }
  .scrim.show { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, 0.55); z-index: 40; }
  .close-side, #openSideBtn { display: inline-grid; }
  .chat-item .mini { opacity: 1; }
  .mode-select { max-width: 130px; }
  .brand p { display: none; }
}
@media (max-width: 480px) {
  .topbar { padding: 0.6rem; gap: 0.45rem; }
  .brand .avatar { display: none; }
  .tool span { display: none; }
  .feed { padding: 1rem 0.65rem 0.5rem; }
  .composer-wrap { padding-left: 0.5rem; padding-right: 0.5rem; }
}
