:root {
  --bg: #0B0912;
  --sidebar: #110E18;
  --card: #191421;
  --primary: #9747FF;
  --secondary: #397BFF;
  --text: #F5F0FA;
  --muted: #A49AAF;
  --border: #292132;
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 16px;
  --sidebar-w: 268px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; background: var(--bg); color: var(--text); font-family: 'Inter', system-ui, -apple-system, sans-serif; -webkit-font-smoothing: antialiased; }
a { color: var(--secondary); text-decoration: none; }
button, input, textarea, select { font: inherit; color: inherit; }

.app { display: flex; height: 100dvh; overflow: hidden; }

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: margin-left .22s ease, transform .22s ease;
  z-index: 30;
}
.sidebar.collapsed { margin-left: calc(var(--sidebar-w) * -1); }

.brand {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 14px 10px;
}
.brand-mark { display: flex; align-items: center; gap: 10px; font-weight: 600; letter-spacing: .08em; font-size: 14px; }
.infinity {
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--primary); font-size: 22px; line-height: 1;
  animation: neuralPulse 4.2s ease-in-out infinite;
}
.infinity.fast { animation-duration: 1.1s; }
@keyframes neuralPulse {
  0%, 100% { opacity: .72; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.07); }
}
@media (prefers-reduced-motion: reduce) {
  .infinity, .infinity.fast { animation: none; }
}

.icon-btn {
  background: transparent; border: 1px solid transparent; border-radius: var(--radius-sm);
  color: var(--muted); padding: 6px 8px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: var(--card); color: var(--text); border-color: var(--border); }

.sidebar-actions { padding: 4px 10px 8px; display: flex; flex-direction: column; gap: 6px; }
.new-chat-btn {
  width: 100%; text-align: left; padding: 9px 12px; border-radius: var(--radius-sm);
  background: var(--card); border: 1px solid var(--border); color: var(--text);
  cursor: pointer; font-size: 13.5px; font-weight: 500;
}
.new-chat-btn:hover { border-color: var(--primary); }
.search-input {
  width: 100%; padding: 8px 11px; border-radius: var(--radius-sm);
  background: var(--bg); border: 1px solid var(--border); font-size: 13px; color: var(--text);
}
.search-input::placeholder { color: var(--muted); }

.nav-scroll { flex: 1; overflow-y: auto; padding: 6px 10px; }
.nav-label { font-size: 11px; letter-spacing: .08em; color: var(--muted); padding: 12px 10px 5px; font-weight: 600; }
.nav-item {
  width: 100%; text-align: left; background: transparent; border: none;
  padding: 8px 10px; border-radius: var(--radius-sm); color: var(--muted);
  cursor: pointer; font-size: 13.5px; display: flex; align-items: center; justify-content: space-between;
}
.nav-item:hover, .nav-item.active { background: var(--card); color: var(--text); }
.recent-list { display: flex; flex-direction: column; gap: 2px; padding-left: 8px; margin-bottom: 4px; }
.recent-item {
  background: transparent; border: none; text-align: left; color: var(--muted);
  font-size: 12.5px; padding: 6px 8px; border-radius: 8px; cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.recent-item:hover, .recent-item.active { background: var(--card); color: var(--text); }

.nav-divider { height: 1px; background: var(--border); margin: 10px 4px; }

.account-bar {
  border-top: 1px solid var(--border); padding: 10px 12px;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.account-info { display: flex; align-items: center; gap: 10px; min-width: 0; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; background: var(--card);
  border: 1px solid var(--border); display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600; color: var(--primary); flex-shrink: 0;
}
.account-name { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.account-sub { font-size: 11px; color: var(--muted); }
.auth-link {
  font-size: 12px; padding: 6px 10px; border-radius: 8px; background: var(--card);
  border: 1px solid var(--border); color: var(--text); cursor: pointer; flex-shrink: 0;
}
.auth-link:hover { border-color: var(--primary); }

/* Main area */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; }
.topbar {
  height: 54px; border-bottom: 1px solid var(--border); padding: 0 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-shrink: 0;
}
.topbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.conv-title { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.model-pill {
  font-size: 12px; color: var(--muted); background: var(--card);
  border: 1px solid var(--border); padding: 4px 10px; border-radius: 999px;
}
.topbar-right { display: flex; align-items: center; gap: 6px; }

/* Chat stage */
.stage { flex: 1; overflow-y: auto; padding: 24px 16px; display: flex; flex-direction: column; }
.empty-state {
  margin: auto; text-align: center; max-width: 520px; padding: 24px 12px;
}
.empty-state .infinity { font-size: 46px; margin-bottom: 12px; }
.empty-state h1 { margin: 0 0 8px; font-size: 26px; font-weight: 600; letter-spacing: -.02em; }
.empty-state p { margin: 0; color: var(--muted); font-size: 14.5px; }

.messages { width: 100%; max-width: 780px; margin: 0 auto; display: flex; flex-direction: column; gap: 22px; }
.msg { display: flex; gap: 14px; align-items: flex-start; }
.msg.user { justify-content: flex-end; }
.msg.user .bubble {
  background: var(--card); border: 1px solid var(--border);
  padding: 12px 16px; border-radius: var(--radius-lg); max-width: 82%; white-space: pre-wrap; line-height: 1.55;
}
.msg.assistant .bubble { flex: 1; min-width: 0; line-height: 1.65; font-size: 15px; }
.msg-avatar {
  width: 28px; height: 28px; border-radius: 50%; background: var(--card); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0; margin-top: 2px;
}
.msg-actions { display: flex; gap: 8px; margin-top: 8px; }
.msg-action {
  background: transparent; border: 1px solid var(--border); border-radius: 8px;
  color: var(--muted); font-size: 11.5px; padding: 3px 8px; cursor: pointer;
}
.msg-action:hover { color: var(--text); border-color: var(--primary); }

/* Markdown & code */
.bubble pre {
  background: #14101D; border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: 12px; overflow-x: auto; position: relative; margin: 12px 0;
}
.bubble code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.bubble p code { background: var(--card); padding: 2px 6px; border-radius: 6px; border: 1px solid var(--border); }
.copy-code {
  position: absolute; top: 8px; right: 8px; background: var(--card); border: 1px solid var(--border);
  color: var(--muted); font-size: 11px; padding: 3px 8px; border-radius: 6px; cursor: pointer;
}
.copy-code:hover { color: var(--text); }

/* Composer */
.composer-wrap { padding: 12px 16px 18px; flex-shrink: 0; }
.composer {
  max-width: 780px; margin: 0 auto; background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 10px 12px; display: flex; flex-direction: column; gap: 8px;
}
.composer:focus-within { border-color: var(--primary); }
.composer textarea {
  width: 100%; background: transparent; border: none; outline: none; resize: none;
  max-height: 200px; min-height: 26px; line-height: 1.5; font-size: 15px;
}
.composer-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.composer-left, .composer-right { display: flex; align-items: center; gap: 6px; }
.mode-select {
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  padding: 5px 8px; font-size: 12.5px; color: var(--muted); cursor: pointer;
}
.send-btn {
  background: var(--primary); color: #fff; border: none; border-radius: var(--radius-sm);
  padding: 7px 14px; font-size: 13px; font-weight: 500; cursor: pointer;
}
.send-btn.stop { background: #3b2438; border: 1px solid var(--border); }
.composer-note { text-align: center; font-size: 11.5px; color: var(--muted); margin-top: 8px; }

/* Secondary workspace views */
.panel-view { max-width: 780px; width: 100%; margin: 0 auto; display: none; flex-direction: column; gap: 14px; }
.panel-view.active { display: flex; }
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 16px;
}
.card h2 { margin: 0 0 6px; font-size: 16px; }
.card p { margin: 0; color: var(--muted); font-size: 13.5px; line-height: 1.55; }

/* Mobile drawer */
.scrim { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 25; }
@media (max-width: 820px) {
  .sidebar { position: fixed; top: 0; bottom: 0; left: 0; transform: translateX(-100%); margin-left: 0 !important; }
  .sidebar.open { transform: translateX(0); }
  .scrim.show { display: block; }
}
