:root {
  --bg: #0b0b0e;
  --bg-2: #111116;
  --bg-3: #171721;
  --panel: #141420;
  --border: #23232f;
  --border-soft: #1b1b26;
  --text: #e9e9f0;
  --text-dim: #a6a6b3;
  --text-faint: #6b6b78;
  --accent: #c084fc;
  --accent-2: #a855f7;
  --accent-ink: #0b0b0e;
  --user-bubble: #2a1f3d;
  --code-bg: #0a0a10;
  --danger: #ef4444;
  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 10px 30px rgba(0,0,0,.35);
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  font-size: 15px;
  line-height: 1.55;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  color: var(--text-dim);
  transition: background 0.15s, color 0.15s;
}
.icon-btn:hover { background: var(--bg-3); color: var(--text); }

/* ─── Landing ──────────────────────────────────────────────────────────── */
body.landing {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background: radial-gradient(1200px 600px at 70% -10%, rgba(168,85,247,0.15), transparent 60%),
              radial-gradient(900px 500px at -10% 30%, rgba(192,132,252,0.08), transparent 60%),
              var(--bg);
}

.landing-nav {
  padding: 22px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  color: var(--text);
  font-size: 17px;
  letter-spacing: 0.2px;
}
.brand:hover { text-decoration: none; }

.landing-hero {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
}
.hero-inner {
  max-width: 640px;
  text-align: center;
}
.hero-inner h1 {
  font-size: clamp(36px, 6vw, 56px);
  line-height: 1.05;
  margin: 0 0 16px;
  letter-spacing: -0.02em;
  background: linear-gradient(120deg, #fff 20%, var(--accent) 80%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.tagline {
  color: var(--text-dim);
  font-size: 18px;
  margin: 0 auto 32px;
  max-width: 520px;
}

.btn-google {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 12px 22px;
  background: #fff;
  color: #111;
  border-radius: 999px;
  font-weight: 600;
  font-size: 15px;
  transition: transform 0.08s ease, box-shadow 0.15s;
  box-shadow: 0 6px 20px rgba(0,0,0,0.3);
}
.btn-google:hover { transform: translateY(-1px); text-decoration: none; box-shadow: 0 10px 28px rgba(0,0,0,0.4); }
.btn-google:active { transform: translateY(0); }

.login-note {
  min-height: 1em;
  margin: 14px 0 0;
  color: var(--danger);
  font-size: 14px;
}

.feature-list {
  list-style: none;
  padding: 0;
  margin: 48px auto 0;
  max-width: 520px;
  text-align: left;
  color: var(--text-dim);
  font-size: 15px;
  display: grid;
  gap: 10px;
}
.feature-list li::before {
  content: "✓";
  color: var(--accent);
  margin-right: 10px;
  font-weight: 700;
}
.feature-list strong { color: var(--text); font-weight: 600; }

.landing-footer {
  padding: 18px 32px;
  color: var(--text-faint);
  font-size: 13px;
  text-align: center;
  border-top: 1px solid var(--border-soft);
}

/* ─── App shell ────────────────────────────────────────────────────────── */
body.app {
  display: grid;
  grid-template-columns: 280px 1fr;
  height: 100vh;
  overflow: hidden;
}
body.app.collapsed { grid-template-columns: 0 1fr; }
body.app.collapsed .sidebar { transform: translateX(-100%); }

.sidebar {
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: transform 0.2s ease;
}

.sidebar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 14px 10px;
}

.new-chat-group {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin: 0 12px 12px;
}
.btn-new {
  padding: 10px 10px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-weight: 500;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.btn-new:hover { background: #1e1e2a; border-color: #2f2f40; }
.btn-new.btn-code { color: #a7f3d0; }
.btn-new.btn-code:hover { border-color: #2f4f40; background: #18241e; }
.btn-new.btn-media { color: #fcd34d; }
.btn-new.btn-media:hover { border-color: #4a3f20; background: #24210f; }

.convo-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px 8px;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.convo-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--text-dim);
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  transition: background 0.1s, color 0.1s;
}
.convo-item:hover { background: var(--bg-3); color: var(--text); }
.convo-item.active { background: #1e1a29; color: var(--text); }
.convo-item .title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
}
.convo-icon {
  flex-shrink: 0;
  color: var(--text-faint);
}
.convo-item[data-mode="code"] .convo-icon { color: #6ee7b7; }
.convo-item[data-mode="media"] .convo-icon { color: #fcd34d; }
.convo-item.active .convo-icon { color: var(--text); }
.convo-item.active[data-mode="code"] .convo-icon { color: #6ee7b7; }
.convo-item.active[data-mode="media"] .convo-icon { color: #fcd34d; }
.convo-item .del {
  opacity: 0;
  transition: opacity 0.1s;
  color: var(--text-faint);
  padding: 2px 4px;
  border-radius: 4px;
}
.convo-item:hover .del { opacity: 1; }
.convo-item .del:hover { color: var(--danger); background: rgba(239,68,68,0.1); }

.convo-list-header {
  padding: 10px 14px 4px;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.user-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-top: 1px solid var(--border-soft);
}
.user-card img {
  border-radius: 50%;
  background: var(--bg-3);
}
.user-meta {
  flex: 1;
  min-width: 0;
  font-size: 13px;
}
.user-name { color: var(--text); font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-email { color: var(--text-faint); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ─── Main ─────────────────────────────────────────────────────────────── */
.main {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.main-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border-soft);
  min-height: 52px;
}
.current-title {
  font-size: 14px;
  color: var(--text-dim);
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}
.mode-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: rgba(192,132,252,0.14);
  color: var(--accent);
  border: 1px solid rgba(192,132,252,0.3);
  flex-shrink: 0;
}
.mode-badge[data-mode="code"] {
  background: rgba(110,231,183,0.12);
  color: #6ee7b7;
  border-color: rgba(110,231,183,0.3);
}
.mode-badge[data-mode="media"] {
  background: rgba(252,211,77,0.12);
  color: #fcd34d;
  border-color: rgba(252,211,77,0.3);
}
.show-when-collapsed { display: none; }
body.app.collapsed .show-when-collapsed { display: inline-flex; }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 0 140px;
  scroll-behavior: smooth;
}

.welcome {
  max-width: 780px;
  margin: 60px auto 0;
  padding: 0 24px;
  text-align: center;
  color: var(--text-dim);
}
.welcome h1 {
  font-size: 28px;
  margin: 18px 0 28px;
  color: var(--text);
  letter-spacing: -0.01em;
}
.suggestions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 10px;
  max-width: 700px;
  margin: 0 auto;
}
.suggest-card {
  padding: 14px 16px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 14px;
  text-align: left;
  transition: background 0.15s, border-color 0.15s, transform 0.08s;
}
.suggest-card:hover { background: var(--bg-3); border-color: #2f2f40; transform: translateY(-1px); }

.msg-row {
  max-width: 780px;
  margin: 0 auto;
  padding: 14px 24px;
}
.msg {
  display: flex;
  gap: 14px;
}
.msg .avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  margin-top: 2px;
}
.msg.user .avatar { background: var(--bg-3); color: var(--text); }
.msg.assistant .avatar {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: var(--accent-ink);
}
.msg .bubble {
  flex: 1;
  min-width: 0;
  color: var(--text);
}
.msg.user .bubble {
  background: var(--user-bubble);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  display: inline-block;
  max-width: 100%;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.msg.user .bubble-wrap {
  display: flex;
  justify-content: flex-end;
  flex: 1;
  min-width: 0;
}
.msg.assistant .bubble-col {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.msg.assistant .bubble {
  white-space: normal;
}

.msg-actions {
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.15s;
  margin-top: 2px;
}
.msg.assistant:hover .msg-actions,
.msg-actions:focus-within { opacity: 1; }
.msg-action {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: 6px;
  color: var(--text-faint);
  font-size: 12px;
  line-height: 1;
  transition: background 0.15s, color 0.15s;
}
.msg-action:hover { background: var(--bg-3); color: var(--text); }
.msg-action.copied { color: var(--accent); }
.copy-label { font-size: 12px; }
@media (max-width: 768px) {
  .msg-actions { opacity: 1; }
}

/* Markdown rendering */
.bubble p { margin: 0 0 12px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble h1, .bubble h2, .bubble h3 {
  margin: 18px 0 10px;
  line-height: 1.25;
  letter-spacing: -0.01em;
}
.bubble h1 { font-size: 1.35em; }
.bubble h2 { font-size: 1.2em; }
.bubble h3 { font-size: 1.05em; }
.bubble ul, .bubble ol { margin: 6px 0 12px; padding-left: 24px; }
.bubble li { margin: 4px 0; }
.bubble code {
  font-family: var(--mono);
  background: rgba(255,255,255,0.07);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 0.92em;
}
.bubble pre {
  margin: 10px 0;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  overflow-x: auto;
  font-size: 13px;
  line-height: 1.5;
}
.bubble pre code {
  background: transparent;
  padding: 0;
  font-size: inherit;
}
.bubble blockquote {
  margin: 8px 0;
  padding: 4px 12px;
  border-left: 3px solid var(--accent);
  color: var(--text-dim);
}
.bubble a { color: var(--accent); }
.bubble table {
  border-collapse: collapse;
  margin: 10px 0;
  font-size: 0.95em;
}
.bubble th, .bubble td {
  border: 1px solid var(--border);
  padding: 6px 10px;
  text-align: left;
}
.bubble th { background: var(--bg-3); }
.bubble hr { border: none; border-top: 1px solid var(--border); margin: 16px 0; }

/* Typing cursor */
.cursor {
  display: inline-block;
  width: 7px;
  height: 14px;
  background: var(--accent);
  vertical-align: -2px;
  margin-left: 2px;
  animation: blink 1s steps(2) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* ─── Composer ─────────────────────────────────────────────────────────── */
.composer {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 12px 20px 16px;
  background: linear-gradient(to top, var(--bg) 60%, transparent);
  pointer-events: none;
}
.composer > * { pointer-events: auto; }
body.app .composer { position: relative; padding: 12px 20px 16px; background: var(--bg); border-top: 1px solid var(--border-soft); }
.composer-inner {
  max-width: 780px;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 8px 8px 14px;
  transition: border-color 0.15s;
}
.composer-inner:focus-within { border-color: var(--accent); }
#input {
  flex: 1;
  resize: none;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  line-height: 1.5;
  max-height: 240px;
  padding: 8px 4px;
}
#input::placeholder { color: var(--text-faint); }
.send-btn {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, opacity 0.15s;
}
.send-btn:hover { background: var(--accent-2); }
.send-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.composer-footer {
  max-width: 780px;
  margin: 8px auto 0;
  text-align: center;
  color: var(--text-faint);
  font-size: 12px;
}

/* ─── Mobile ────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  body.app { grid-template-columns: 0 1fr; }
  body.app .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: 280px;
    z-index: 20;
    transform: translateX(-100%);
    box-shadow: var(--shadow);
  }
  body.app.mobile-open .sidebar { transform: translateX(0); }
  body.app.mobile-open::after {
    content: "";
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 10;
  }
  .show-when-collapsed { display: inline-flex !important; }
  .msg-row { padding: 12px 16px; }
  .welcome { margin-top: 32px; }
}

/* ─── Media mode ───────────────────────────────────────────────────────── */
.msg-media {
  max-width: 100%;
  max-height: 520px;
  width: auto;
  height: auto;
  border-radius: var(--radius-sm);
  display: block;
  margin-top: 8px;
  background: var(--bg-3);
}
.msg.user .msg-media {
  margin-top: 0;
  margin-bottom: 8px;
}
.msg-media.seed {
  max-height: 260px;
  opacity: 0.85;
  margin-bottom: 8px;
}
.msg-caption {
  margin-top: 8px;
  color: var(--text);
}

.attachment-row {
  max-width: 780px;
  margin: 0 auto 8px;
}
.attachment-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px 6px 6px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 13px;
  color: var(--text);
}
.attachment-chip img {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--bg-3);
}
.attachment-name {
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.media-kind-switch {
  display: inline-flex;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2px;
  gap: 2px;
  align-self: center;
  margin-bottom: 2px;
}
.kind-btn {
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-faint);
  transition: background 0.15s, color 0.15s;
}
.kind-btn.active {
  background: var(--bg-2);
  color: var(--text);
  box-shadow: inset 0 0 0 1px var(--border);
}
.kind-btn:hover { color: var(--text); }

.attach-btn {
  align-self: flex-end;
  margin-bottom: 2px;
  color: var(--text-faint);
}
.attach-btn:hover { color: #fcd34d; }

.media-progress-box {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 14px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  min-width: 240px;
  max-width: 360px;
}
.media-progress-bar {
  height: 6px;
  background: var(--bg-3);
  border-radius: 999px;
  overflow: hidden;
}
.media-progress-fill {
  height: 100%;
  width: 10%;
  background: linear-gradient(90deg, #fcd34d, #f59e0b);
  border-radius: 999px;
  transition: width 0.4s ease;
}
.media-progress-text {
  font-size: 12px;
  color: var(--text-dim);
}

/* Scrollbars */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #2a2a38; border-radius: 10px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: #38384a; }
