:root {
  --bg: #070b16;
  --panel: rgba(17, 24, 42, 0.72);
  --panel-solid: #0d1324;
  --border: rgba(120, 140, 200, 0.16);
  --text: #e7ecf7;
  --muted: #93a0bd;
  --accent: #6d8cff;
  --accent2: #a06bff;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background:
    radial-gradient(1200px 700px at 80% -10%, rgba(109, 140, 255, 0.18), transparent 60%),
    radial-gradient(900px 600px at 0% 110%, rgba(160, 107, 255, 0.16), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Inter, sans-serif;
  overflow: hidden;
}
#app { display: flex; height: 100vh; }

/* Sidebar */
.sidebar {
  width: 268px; flex: 0 0 268px; display: flex; flex-direction: column;
  background: var(--panel); backdrop-filter: blur(16px);
  border-right: 1px solid var(--border); transition: margin-left .25s ease;
}
.sidebar.hidden { margin-left: -268px; }
.logo {
  width: 30px; height: 30px; display: grid; place-items: center; border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff; font-size: 15px; box-shadow: 0 6px 20px rgba(109,140,255,.45);
}
.new-chat {
  width: 100%; padding: 11px 14px; border-radius: 12px; cursor: pointer;
  background: linear-gradient(135deg, rgba(109,140,255,.22), rgba(160,107,255,.22));
  border: 1px solid var(--border); color: var(--text); font-weight: 600;
  transition: transform .1s ease, background .2s ease;
}
.new-chat:hover { transform: translateY(-1px); background: linear-gradient(135deg, rgba(109,140,255,.32), rgba(160,107,255,.32)); }
.chat-list { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 4px; }
.chat-item {
  padding: 9px 11px; border-radius: 10px; cursor: pointer; font-size: 13px;
  color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  border: 1px solid transparent;
}
.chat-item:hover { background: rgba(255,255,255,.05); color: var(--text); }
.chat-item.active { background: rgba(109,140,255,.16); color: var(--text); border-color: var(--border); }
.sidebar-foot { padding: 12px; border-top: 1px solid var(--border); }
.foot-btn { width: 100%; text-align: left; padding: 9px 11px; border-radius: 10px; color: var(--muted); background: transparent; border: none; cursor: pointer; }
.foot-btn:hover { background: rgba(255,255,255,.05); color: var(--text); }

/* Main */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: 56px; display: flex; align-items: center; gap: 10px; padding: 0 16px;
  border-bottom: 1px solid var(--border); backdrop-filter: blur(12px);
}
.icon-btn {
  width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center;
  background: transparent; border: 1px solid transparent; color: var(--muted);
  cursor: pointer; font-size: 16px;
}
.icon-btn:hover { background: rgba(255,255,255,.06); color: var(--text); }
.mode-select select {
  background: var(--panel-solid); color: var(--text); border: 1px solid var(--border);
  border-radius: 10px; padding: 8px 12px; font-size: 13px; outline: none; cursor: pointer;
}
.badge {
  font-size: 11px; padding: 4px 9px; border-radius: 999px;
  background: rgba(109,140,255,.16); border: 1px solid var(--border); color: #b9c6ee;
}

/* Messages */
.messages { flex: 1; overflow-y: auto; padding: 26px 18px 8px; scroll-behavior: smooth; }
.messages-inner { max-width: 820px; margin: 0 auto; display: flex; flex-direction: column; gap: 20px; }
.msg { display: flex; gap: 12px; }
.msg .avatar {
  width: 32px; height: 32px; flex: 0 0 32px; border-radius: 9px; display: grid; place-items: center; font-size: 15px;
}
.msg.user .avatar { background: rgba(255,255,255,.08); }
.msg.assistant .avatar { background: linear-gradient(135deg, var(--accent), var(--accent2)); color: #fff; }
.bubble { flex: 1; min-width: 0; }
.bubble .who { font-size: 12px; color: var(--muted); margin-bottom: 5px; }
.prose { font-size: 15px; line-height: 1.68; word-wrap: break-word; }
.prose p { margin: 0 0 10px; }
.prose h1,.prose h2,.prose h3 { margin: 16px 0 8px; font-weight: 700; }
.prose ul,.prose ol { padding-left: 22px; margin: 0 0 10px; }
.prose a { color: var(--accent); }
.prose code:not(pre code) {
  background: rgba(255,255,255,.08); padding: 2px 6px; border-radius: 6px; font-size: .88em;
}
.prose pre { position: relative; margin: 10px 0; border-radius: 12px; overflow: hidden; border: 1px solid var(--border); }
.prose pre code { display: block; padding: 14px; overflow-x: auto; font-size: 13px; background: #0a0f1e; }
.copy-code {
  position: absolute; top: 8px; right: 8px; font-size: 11px; padding: 4px 9px; border-radius: 7px;
  background: rgba(255,255,255,.1); color: #cdd6ee; border: 1px solid var(--border); cursor: pointer;
}
.copy-code:hover { background: rgba(255,255,255,.18); }
.msg-actions { display: flex; gap: 6px; margin-top: 8px; opacity: 0; transition: opacity .2s; }
.msg:hover .msg-actions { opacity: 1; }
.act { font-size: 12px; color: var(--muted); background: transparent; border: none; cursor: pointer; padding: 3px 7px; border-radius: 7px; }
.act:hover { background: rgba(255,255,255,.07); color: var(--text); }
.think { margin: 6px 0 10px; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: rgba(255,255,255,.02); }
.think summary { cursor: pointer; padding: 8px 12px; font-size: 12.5px; color: var(--muted); user-select: none; }
.think .think-body { padding: 4px 12px 12px; font-size: 13px; color: var(--muted); white-space: pre-wrap; border-top: 1px solid var(--border); }
.cursor::after { content: "▍"; color: var(--accent); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.msg-img { max-width: 420px; border-radius: 14px; border: 1px solid var(--border); display: block; margin-top: 6px; }
.note { font-size: 12px; color: #f0b37e; margin-top: 6px; }
.err { font-size: 13px; color: #ff9a9a; margin-top: 6px; }

/* Welcome */
.welcome { max-width: 720px; margin: 8vh auto 0; text-align: center; }
.welcome-logo {
  width: 62px; height: 62px; margin: 0 auto 16px; border-radius: 18px; display: grid; place-items: center;
  font-size: 28px; color: #fff; background: linear-gradient(135deg, var(--accent), var(--accent2));
  box-shadow: 0 14px 40px rgba(109,140,255,.4);
}
.welcome h1 { font-size: 30px; font-weight: 700; margin: 0 0 8px; }
.welcome p { color: var(--muted); margin: 0 0 22px; }
.chips { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.chip {
  padding: 10px 14px; border-radius: 12px; font-size: 13px; cursor: pointer;
  background: var(--panel); border: 1px solid var(--border); color: var(--text);
  backdrop-filter: blur(10px);
}
.chip:hover { border-color: var(--accent); transform: translateY(-1px); }

/* Composer */
.composer-wrap { padding: 10px 18px 14px; }
.attachments { max-width: 820px; margin: 0 auto 8px; display: flex; gap: 8px; flex-wrap: wrap; }
.attach {
  display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: 10px;
  background: var(--panel); border: 1px solid var(--border); font-size: 12px;
}
.attach img { width: 30px; height: 30px; object-fit: cover; border-radius: 6px; }
.attach .x { cursor: pointer; color: var(--muted); }
.composer {
  max-width: 820px; margin: 0 auto; display: flex; align-items: flex-end; gap: 8px;
  padding: 8px 10px; border-radius: 18px; background: var(--panel);
  border: 1px solid var(--border); backdrop-filter: blur(16px);
  box-shadow: 0 10px 40px rgba(0,0,0,.35);
}
.composer textarea {
  flex: 1; resize: none; border: none; outline: none; background: transparent; color: var(--text);
  font-size: 15px; line-height: 1.5; max-height: 200px; padding: 8px 4px; font-family: inherit;
}
.pills { display: flex; gap: 5px; align-items: center; padding-bottom: 6px; }
.pill {
  font-size: 12px; padding: 5px 9px; border-radius: 999px; cursor: pointer; white-space: nowrap;
  background: rgba(255,255,255,.05); border: 1px solid var(--border); color: var(--muted);
}
.pill.active { background: linear-gradient(135deg, var(--accent), var(--accent2)); color: #fff; border-color: transparent; }
.send-btn {
  width: 38px; height: 38px; border-radius: 12px; border: none; cursor: pointer; color: #fff; font-size: 16px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
}
.send-btn:disabled { opacity: .45; cursor: default; }
#micBtn.recording { color: #ff7a7a; animation: pulse 1s infinite; }
@keyframes pulse { 50% { transform: scale(1.12); } }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(3,6,14,.66); backdrop-filter: blur(6px); display: grid; place-items: center; z-index: 50; }
.modal-card { width: min(520px, 92vw); max-height: 88vh; overflow-y: auto; background: var(--panel-solid); border: 1px solid var(--border); border-radius: 18px; padding: 22px; }
.fld { display: block; margin-bottom: 12px; }
.fld span { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 5px; }
.fld em { opacity: .7; font-style: normal; }
.fld input { width: 100%; padding: 10px 12px; border-radius: 10px; background: #0a0f1e; border: 1px solid var(--border); color: var(--text); outline: none; }
.fld input:focus { border-color: var(--accent); }
.btn-primary { padding: 10px 18px; border-radius: 11px; border: none; cursor: pointer; color: #fff; background: linear-gradient(135deg, var(--accent), var(--accent2)); font-weight: 600; }
.btn-ghost { padding: 10px 14px; border-radius: 11px; cursor: pointer; color: var(--text); background: transparent; border: 1px solid var(--border); }
.hidden { display: none !important; }
@media (max-width: 768px) {
  .sidebar { position: fixed; z-index: 40; height: 100%; }
  .sidebar.hidden { margin-left: -268px; }
  .pills { display: none; }
}
