[hidden] { display: none !important; }
/* ============ THEMES ============ */
:root, [data-theme="galaxy"] {
  --bg: #05030f;
  --side: rgba(12, 8, 30, 0.72);
  --panel: rgba(255, 255, 255, 0.06);
  --panel-2: rgba(255, 255, 255, 0.1);
  --border: rgba(255, 255, 255, 0.12);
  --text: #eef0ff;
  --muted: #a9aed0;
  --accent: #a66bff;
  --user-bg: linear-gradient(135deg, #4fd8ff, #a66bff 55%, #ff5fc8);
  --user-text: #fff;
  --code-bg: rgba(0, 0, 0, 0.45);
  --grad: linear-gradient(135deg, #4fd8ff, #a66bff 50%, #ff5fc8);
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}
[data-theme="dark"] {
  --bg: #141417;
  --side: #1b1b1f;
  --panel: #232328;
  --panel-2: #2c2c32;
  --border: #33333a;
  --text: #ececf1;
  --muted: #9a9aa5;
  --accent: #a66bff;
  --user-bg: #2f2f37;
  --user-text: #ececf1;
  --code-bg: #0e0e10;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
}
[data-theme="light"] {
  --bg: #f7f6fb;
  --side: #efedf6;
  --panel: #ffffff;
  --panel-2: #e9e6f3;
  --border: #dcd8ea;
  --text: #1b1830;
  --muted: #6b6787;
  --accent: #7b3fe4;
  --user-bg: #e6defa;
  --user-text: #1b1830;
  --code-bg: #1e1b2e;
  --shadow: 0 10px 40px rgba(40, 20, 90, 0.15);
}
:root { --font-scale: 1; --side-w: 280px; }

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: "Montserrat", "Segoe UI", system-ui, sans-serif;
  font-size: calc(15px * var(--font-scale));
  background: var(--bg); color: var(--text); overflow: hidden;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: none; }
a { color: inherit; text-decoration: none; }

/* galaxy background only in galaxy theme */
#stars { position: fixed; inset: 0; z-index: -1; }
[data-theme]:not([data-theme="galaxy"]) #stars { display: none; }
[data-theme="galaxy"] body::before {
  content: ""; position: fixed; inset: 0; z-index: -2;
  background:
    radial-gradient(ellipse at 20% 10%, rgba(123, 63, 228, 0.35), transparent 50%),
    radial-gradient(ellipse at 85% 80%, rgba(255, 95, 200, 0.18), transparent 50%),
    radial-gradient(ellipse at 60% 40%, rgba(79, 216, 255, 0.12), transparent 60%);
}

/* ============ LAYOUT ============ */
.layout { display: flex; height: 100dvh; }
.sidebar {
  width: var(--side-w); flex-shrink: 0; display: flex; flex-direction: column; gap: 4px;
  background: var(--side); border-right: 1px solid var(--border); padding: 12px 10px;
  backdrop-filter: blur(14px);
}
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.side-top { display: flex; align-items: center; justify-content: space-between; padding: 4px 6px 10px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.1rem; }
.brand img { width: 32px; height: 32px; }

.side-item {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  padding: 9px 10px; border-radius: 10px; color: var(--text);
}
.side-item:hover, .side-item.active { background: var(--panel-2); }
.side-item .ico { width: 20px; text-align: center; }
.side-item kbd { margin-left: auto; font-size: .68rem; color: var(--muted); font-family: inherit; }
.side-item.primary { font-weight: 700; }
.search { display: flex; align-items: center; gap: 8px; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 0 10px; margin: 4px 0 6px; }
.search .ico { color: var(--muted); }
.search input { flex: 1; background: none; border: none; outline: none; padding: 9px 0; }
.side-nav { display: flex; flex-direction: column; gap: 2px; margin-bottom: 8px; }

.side-section-title {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 10px 4px; font-weight: 700;
}
.chat-list { flex: 1; overflow-y: auto; margin: 0 -4px; padding: 0 4px; }
.group-label { font-size: .75rem; color: var(--muted); padding: 12px 10px 4px; text-transform: uppercase; letter-spacing: .05em; }
.chat-row {
  display: flex; align-items: center; border-radius: 10px; padding: 0 4px 0 10px; position: relative;
}
.chat-row:hover, .chat-row.active { background: var(--panel-2); }
.chat-row .name { flex: 1; padding: 8px 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; }
.chat-row .more { opacity: 0; padding: 4px 8px; border-radius: 6px; color: var(--muted); }
.chat-row:hover .more, .chat-row.active .more { opacity: 1; }
.chat-row .more:hover { background: var(--panel); color: var(--text); }
.chat-row input { flex: 1; background: var(--panel); border: 1px solid var(--accent); border-radius: 6px; padding: 6px 8px; outline: none; margin: 2px 0; }
.empty-list { color: var(--muted); padding: 14px 10px; font-size: .9rem; }

.side-bottom { border-top: 1px solid var(--border); padding-top: 10px; }
.brain-pill { display: flex; align-items: center; gap: 8px; font-size: .82rem; color: var(--muted); padding: 6px 10px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #f5b942; box-shadow: 0 0 8px currentColor; }
.dot.ready { background: #3ddc84; }
.dot.error { background: #ff5f5f; }

.icon-btn { padding: 6px 9px; border-radius: 8px; color: var(--muted); }
.icon-btn:hover { background: var(--panel-2); color: var(--text); }

/* ============ TOP BAR ============ */
.topbar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; min-height: 56px; }
.chat-title { font-weight: 700; padding: 6px 10px; border-radius: 8px; cursor: text; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 60%; }
.chat-title:hover { background: var(--panel); }
.chat-title input { background: var(--panel); border: 1px solid var(--accent); border-radius: 6px; padding: 4px 8px; outline: none; font-weight: 700; width: 100%; }
.top-actions { margin-left: auto; display: flex; gap: 6px; align-items: center; }
.project-chip { font-size: .8rem; background: var(--panel); border: 1px solid var(--border); padding: 4px 10px; border-radius: 99px; }
.progress-strip { height: 3px; background: var(--panel); }
.progress-strip > div { height: 100%; width: 0; background: var(--grad, var(--accent)); transition: width .3s; }

/* ============ MESSAGES ============ */
.messages { flex: 1; overflow-y: auto; padding: 10px 16px 30px; }
.thread { max-width: 780px; margin: 0 auto; display: flex; flex-direction: column; gap: 22px; }
.msg { display: flex; gap: 12px; }
.msg.user { justify-content: flex-end; }
.msg .avatar { width: 30px; height: 30px; flex-shrink: 0; margin-top: 2px; }
.bubble { line-height: 1.65; word-wrap: break-word; min-width: 0; }
.msg.user .bubble { background: var(--user-bg); color: var(--user-text); padding: 10px 16px; border-radius: 18px 18px 4px 18px; max-width: 80%; white-space: pre-wrap; }
.msg.bot .bubble { flex: 1; }
.msg.bot .content > * + * { margin-top: .7em; }
.content h1, .content h2, .content h3 { font-size: 1.1em; }
.content ul, .content ol { padding-left: 1.4em; }
.content a { color: var(--accent); text-decoration: underline; }
.content code { background: var(--panel-2); padding: 1px 6px; border-radius: 5px; font-family: Consolas, "Cascadia Code", monospace; font-size: .9em; }
.content pre { background: var(--code-bg); color: #e8e6f5; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.content pre .code-head { display: flex; justify-content: space-between; align-items: center; padding: 6px 12px; font-size: .75rem; color: #a9aed0; background: rgba(255,255,255,.05); }
.content pre .code-head button { color: #a9aed0; font-size: .75rem; }
.content pre .code-head button:hover { color: #fff; }
.content pre code { display: block; background: none; padding: 12px 14px; overflow-x: auto; white-space: pre; }
.content blockquote { border-left: 3px solid var(--accent); padding-left: 12px; color: var(--muted); }
.typing-dots span { display: inline-block; width: 7px; height: 7px; margin-right: 4px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing-dots span:nth-child(2) { animation-delay: .2s; } .typing-dots span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .2; } 40% { opacity: 1; } }

.msg-actions { display: flex; gap: 2px; margin-top: 6px; opacity: 0; transition: opacity .15s; }
.msg:hover .msg-actions, .msg:last-child .msg-actions { opacity: 1; }
.msg-actions button { font-size: .8rem; color: var(--muted); padding: 4px 8px; border-radius: 6px; }
.msg-actions button:hover { background: var(--panel-2); color: var(--text); }
.msg.user .msg-actions { justify-content: flex-end; }

/* empty state */
.hello { max-width: 720px; margin: 8vh auto 0; text-align: center; }
.hello img { width: 96px; filter: drop-shadow(0 0 25px rgba(166,107,255,.55)); }
.hello h1 { font-size: 1.9rem; margin: 14px 0 6px; }
.hello p { color: var(--muted); }
.chips { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; margin-top: 28px; text-align: left; }
.chip { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 14px; color: var(--text); }
.chip:hover { background: var(--panel-2); }
.chip b { display: block; margin-bottom: 2px; }
.chip span { color: var(--muted); font-size: .88rem; }

/* composer */
.composer-wrap { padding: 0 16px calc(10px + env(safe-area-inset-bottom)); }
.composer {
  max-width: 780px; margin: 0 auto; display: flex; align-items: flex-end; gap: 8px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 22px; padding: 8px 8px 8px 16px;
  box-shadow: var(--shadow);
}
.composer:focus-within { border-color: var(--accent); }
.composer textarea { flex: 1; resize: none; background: none; border: none; outline: none; padding: 8px 0; max-height: 200px; line-height: 1.5; }
.composer-actions { display: flex; gap: 6px; align-items: center; }
.send { width: 38px; height: 38px; border-radius: 50%; background: var(--grad, var(--accent)); color: #fff; font-size: 1.1rem; font-weight: 800; }
[data-theme="dark"] .send, [data-theme="light"] .send { background: var(--accent); }
.send:disabled { opacity: .4; cursor: default; }
.send.stop { background: var(--text); color: var(--bg); font-size: .8rem; }
.disclaimer { text-align: center; font-size: .72rem; color: var(--muted); margin-top: 8px; }

/* ============ MODAL / MENU / TOAST ============ */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal-card { background: var(--side); backdrop-filter: blur(20px); border: 1px solid var(--border); border-radius: 18px; width: min(560px, 100%); max-height: 88dvh; display: flex; flex-direction: column; box-shadow: var(--shadow); }
[data-theme="dark"] .modal-card { background: #1e1e23; } [data-theme="light"] .modal-card { background: #fff; }
[data-theme="galaxy"] .modal-card { background: rgba(18, 12, 42, .95); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 18px 20px 8px; }
.modal-body { padding: 8px 20px 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 18px; }
.field label { display: block; font-weight: 700; margin-bottom: 6px; }
.field small { display: block; color: var(--muted); margin-top: 4px; }
.field input[type=text], .field textarea, .field select {
  width: 100%; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; outline: none;
}
.field textarea { min-height: 90px; resize: vertical; }
.field input:focus, .field textarea:focus { border-color: var(--accent); }
.seg { display: flex; gap: 8px; flex-wrap: wrap; }
.seg button { flex: 1; min-width: 100px; padding: 12px; border-radius: 12px; background: var(--panel); border: 2px solid var(--border); }
.seg button.on { border-color: var(--accent); background: var(--panel-2); }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.switch { width: 44px; height: 24px; border-radius: 99px; background: var(--panel-2); border: 1px solid var(--border); position: relative; flex-shrink: 0; }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%; background: var(--muted); transition: .2s; }
.switch.on { background: var(--accent); } .switch.on::after { left: 22px; background: #fff; }
.btn { padding: 10px 16px; border-radius: 10px; background: var(--panel-2); border: 1px solid var(--border); font-weight: 600; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: #fff; border-color: transparent; }
.btn.danger { color: #ff6b6b; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.hr { height: 1px; background: var(--border); }
.project-card { display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: 12px; background: var(--panel); border: 1px solid var(--border); cursor: pointer; }
.project-card:hover { border-color: var(--accent); }
.project-card .emoji { font-size: 1.5rem; }
.project-card .info { flex: 1; min-width: 0; }
.project-card .info small { color: var(--muted); }

.menu { position: fixed; z-index: 60; background: var(--side); border: 1px solid var(--border); border-radius: 12px; padding: 6px; min-width: 190px; box-shadow: var(--shadow); backdrop-filter: blur(20px); }
[data-theme="galaxy"] .menu { background: rgba(18, 12, 42, .97); } [data-theme="light"] .menu { background: #fff; } [data-theme="dark"] .menu { background: #232328; }
.menu button { display: flex; gap: 10px; width: 100%; text-align: left; padding: 8px 10px; border-radius: 8px; }
.menu button:hover { background: var(--panel-2); }
.menu button.danger { color: #ff6b6b; }
.menu .sub { font-size: .75rem; color: var(--muted); padding: 6px 10px 2px; }

.toast { position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 99px; font-weight: 600; z-index: 70; font-size: .9rem; }

/* ============ MOBILE ============ */
.only-mobile { display: none; }
.scrim { display: none; }
@media (max-width: 800px) {
  .only-mobile { display: inline-block; }
  .sidebar { position: fixed; inset: 0 auto 0 0; z-index: 40; transform: translateX(-100%); transition: transform .25s; width: min(300px, 85vw); }
  [data-theme="galaxy"] .sidebar { background: rgba(10, 6, 26, .97); }
  .sidebar.open { transform: none; }
  .scrim.show { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 39; }
  .chat-row .more { opacity: 1; }
  .side-item kbd { display: none; }
  .msg .avatar { display: none; }
  .hello { margin-top: 4vh; }
}

/* ============ IMAGES ============ */
.attach-row { max-width: 780px; margin: 0 auto 8px; display: flex; gap: 8px; flex-wrap: wrap; }
.attach-row .thumb { position: relative; width: 64px; height: 64px; border-radius: 12px; overflow: hidden; border: 1px solid var(--border); }
.attach-row .thumb img { width: 100%; height: 100%; object-fit: cover; }
.attach-row .thumb button { position: absolute; top: 2px; right: 2px; width: 20px; height: 20px; border-radius: 50%; background: rgba(0,0,0,.7); color: #fff; font-size: .7rem; line-height: 20px; }
.composer .attach-btn { align-self: flex-end; margin-left: -8px; }
.composer-wrap.drag .composer { border-color: var(--accent); border-style: dashed; }
.msg-images { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; margin-bottom: 6px; }
.msg-images img { max-width: 220px; max-height: 220px; border-radius: 14px; border: 1px solid var(--border); cursor: zoom-in; object-fit: cover; }
.lightbox img { max-width: 100%; max-height: 75dvh; border-radius: 12px; display: block; margin: 0 auto; }

/* ============ VOICE ============ */
.icon-btn.recording { background: #e5484d; color: #fff; animation: pulse 1.2s infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(229,72,77,.6); } 50% { box-shadow: 0 0 0 8px rgba(229,72,77,0); } }
.voice { position: fixed; inset: 0; z-index: 80; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 22px; padding: 24px;
  background: radial-gradient(ellipse at 50% 40%, #3a1d7a, #05030f 70%); color: #fff; text-align: center; }
[data-theme="light"] .voice { background: radial-gradient(ellipse at 50% 40%, #e3d6ff, #f7f6fb 70%); color: var(--text); }
[data-theme="light"] .voice-btns button:not(.end) { background: rgba(0,0,0,.06); border-color: rgba(0,0,0,.12); }
.voice-orb { --level: 0; width: 200px; height: 200px; border-radius: 50%; cursor: pointer; display: grid; place-items: center;
  transform: scale(calc(1 + var(--level) * .35)); transition: transform .08s linear;
  box-shadow: 0 0 calc(40px + var(--level) * 120px) rgba(166,107,255,.8), 0 0 0 6px rgba(255,255,255,.08); }
.voice-orb img { width: 100%; height: 100%; }
.voice.thinking .voice-orb { animation: spin 2.4s linear infinite; }
.voice.speaking .voice-orb { animation: breathe 1.4s ease-in-out infinite; }
@keyframes spin { to { rotate: 360deg; } }
@keyframes breathe { 50% { transform: scale(1.12); } }
.voice-state { font-size: 1.4rem; font-weight: 800; }
.voice-text { max-width: 620px; min-height: 3em; opacity: .8; line-height: 1.5; max-height: 30dvh; overflow-y: auto; }
.voice-btns { display: flex; gap: 12px; }
.voice-btns button { padding: 14px 24px; border-radius: 99px; background: rgba(255,255,255,.12); border: 1px solid rgba(255,255,255,.2); color: inherit; font-weight: 700; }
.voice-btns button.on { background: #e5484d; }
.voice-btns .end { background: #e5484d; border-color: transparent; color: #fff; }
