:root {
  color-scheme: dark;
  --bg: #212121;
  --bg-deep: #171717;
  --surface: #2f2f2f;
  --surface-2: #3a3a3a;
  --surface-3: #262626;
  --text: #ececec;
  --muted: #b4b4b4;
  --muted-2: #8b8b8b;
  --border: rgba(255, 255, 255, 0.11);
  --accent: #10a37f;
  --accent-soft: rgba(16, 163, 127, 0.16);
  --danger: #ef4444;
  --shadow: 0 28px 90px rgba(0, 0, 0, 0.38);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}
button, input, textarea { font: inherit; }
button { color: inherit; }

.app-shell {
  height: 100dvh;
  display: grid;
  grid-template-columns: 286px minmax(0, 1fr);
  background:
    radial-gradient(circle at 70% 0%, rgba(16, 163, 127, .08), transparent 34%),
    var(--bg);
}

.sidebar {
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 14px;
  background: var(--bg-deep);
  border-right: 1px solid rgba(255,255,255,.08);
}
.sidebar-top, .brand, .topbar-left, .topbar-actions, .side-label-row, .composer-meta {
  display: flex;
  align-items: center;
}
.sidebar-top, .topbar { justify-content: space-between; gap: 12px; }
.brand { gap: 11px; min-width: 0; }
.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 13px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #10a37f, #68e6cf);
  color: #041b16;
  font-weight: 950;
  box-shadow: 0 12px 32px rgba(16, 163, 127, .26);
}
.brand strong { display: block; font-size: 16px; letter-spacing: -.02em; }
.brand span { display: block; color: var(--muted-2); font-size: 12px; margin-top: 1px; }

button {
  border: 0;
  border-radius: 12px;
  background: transparent;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease, transform .08s ease, opacity .15s ease;
}
button:active { transform: translateY(1px); }
button:disabled { opacity: .55; cursor: not-allowed; transform: none; }

.new-chat, .prompt-chip, .ghost-btn, .icon-btn, .round-btn, .suggestion, .copy-btn {
  border: 1px solid var(--border);
}
.new-chat:hover, .prompt-chip:hover, .ghost-btn:hover, .icon-btn:hover, .round-btn:hover, .copy-btn:hover {
  background: rgba(255,255,255,.07);
}
.new-chat {
  width: 100%;
  padding: 12px 13px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 650;
  text-align: left;
}
.new-chat span { font-size: 19px; line-height: 1; }

.side-section {
  display: grid;
  gap: 8px;
  padding-top: 14px;
  border-top: 1px solid rgba(255,255,255,.08);
}
.side-label {
  margin: 0 0 2px;
  color: var(--muted-2);
  font-size: 12px;
  letter-spacing: .04em;
  text-transform: uppercase;
}
.side-label-row { justify-content: space-between; }
.prompt-chip {
  padding: 10px 11px;
  display: flex;
  align-items: center;
  gap: 9px;
  text-align: left;
  color: #e7e7e7;
  background: rgba(255,255,255,.035);
}
.prompt-chip span { width: 22px; text-align: center; }

.recent-card, .settings-card {
  background: rgba(255,255,255,.035);
  border: 1px solid rgba(255,255,255,.075);
  border-radius: 16px;
  padding: 13px;
}
.settings-card { margin-top: auto; }
.mini-stat {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
  padding: 4px 0;
}
.mini-stat strong { color: var(--text); }
.status-dot, .pulse {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 0 14px var(--accent);
}
.settings-card label { display: grid; gap: 7px; color: var(--muted); font-size: 13px; }
input {
  width: 100%;
  border: 1px solid var(--border);
  background: #242424;
  color: var(--text);
  border-radius: 11px;
  padding: 10px 11px;
  outline: none;
}
input:focus, textarea:focus { border-color: rgba(16, 163, 127, .68); box-shadow: 0 0 0 3px var(--accent-soft); }
.tiny { margin: 2px 0 0; color: var(--muted-2); font-size: 12px; line-height: 1.45; }
.sidebar-footer { color: var(--muted-2); font-size: 12px; display: flex; align-items: center; gap: 8px; padding: 4px 2px; }

.chat-panel {
  min-width: 0;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  position: relative;
}
.topbar {
  min-height: 64px;
  display: flex;
  padding: 12px 22px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  background: rgba(33,33,33,.82);
  backdrop-filter: blur(18px);
  z-index: 2;
}
.topbar-left { gap: 12px; min-width: 0; }
h1 { margin: 0; font-size: 18px; font-weight: 720; letter-spacing: -.02em; }
.topbar p { margin: 3px 0 0; color: var(--muted-2); font-size: 13px; }
.topbar-actions { gap: 9px; }
.mode-pill, .ghost-btn {
  padding: 8px 11px;
  border-radius: 999px;
  color: var(--muted);
  background: rgba(255,255,255,.04);
  font-size: 13px;
  white-space: nowrap;
}
.ghost-btn { border-radius: 12px; }
.mobile-only { display: none; }

.messages {
  min-height: 0;
  overflow-y: auto;
  padding: 24px 18px 18px;
  scroll-behavior: smooth;
}
.messages-inner, .composer-zone > * { width: min(850px, 100%); margin-left: auto; margin-right: auto; }

.welcome {
  width: min(820px, 100%);
  margin: clamp(34px, 11vh, 104px) auto 0;
  text-align: center;
}
.welcome-logo {
  width: 58px;
  height: 58px;
  margin: 0 auto 18px;
  border-radius: 19px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--accent), #70ead2);
  color: #041b16;
  font-size: 26px;
  font-weight: 950;
}
.welcome h2 { margin: 0; font-size: clamp(28px, 4vw, 42px); letter-spacing: -.045em; }
.welcome p { color: var(--muted); margin: 10px auto 24px; line-height: 1.6; max-width: 660px; }
.suggestions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 11px; margin-top: 22px; }
.suggestion {
  min-height: 92px;
  text-align: left;
  background: rgba(255,255,255,.035);
  padding: 15px;
  color: var(--text);
}
.suggestion:hover { background: rgba(255,255,255,.075); }
.suggestion strong { display: block; margin-bottom: 5px; }
.suggestion span { color: var(--muted-2); font-size: 13px; line-height: 1.45; }

.msg-row {
  width: min(850px, 100%);
  margin: 0 auto;
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 14px;
  padding: 18px 0;
}
.msg-row + .msg-row { border-top: 1px solid rgba(255,255,255,.06); }
.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 850;
  font-size: 13px;
}
.msg-row.user .avatar { background: linear-gradient(135deg, #656565, #4a4a4a); }
.msg-row.assistant .avatar { background: var(--accent); color: #031b15; }
.msg-row.error .avatar { background: var(--danger); color: white; }
.msg-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 5px; }
.msg-meta { color: var(--muted-2); font-size: 12px; }
.copy-btn { padding: 5px 8px; color: var(--muted-2); font-size: 12px; opacity: 0; }
.msg-row:hover .copy-btn { opacity: 1; }
.msg {
  min-width: 0;
  white-space: pre-wrap;
  line-height: 1.72;
  color: #f1f1f1;
  word-break: break-word;
}
.msg p { margin: 0 0 12px; }
.msg p:last-child { margin-bottom: 0; }
.msg code {
  background: rgba(255,255,255,.09);
  border: 1px solid rgba(255,255,255,.09);
  border-radius: 6px;
  padding: 1px 5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .92em;
}
.msg pre {
  white-space: pre-wrap;
  overflow-x: auto;
  background: #121212;
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 14px;
  padding: 13px 14px;
  margin: 10px 0;
}
.msg pre code { background: transparent; border: 0; padding: 0; }
.msg.error { color: #fecaca; background: rgba(239,68,68,.1); border: 1px solid rgba(239,68,68,.28); border-radius: 14px; padding: 12px 14px; }
.typing { display: inline-flex; align-items: center; gap: 5px; padding-top: 5px; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: bounce 1s infinite ease-in-out; }
.typing i:nth-child(2) { animation-delay: .14s; }
.typing i:nth-child(3) { animation-delay: .28s; }
@keyframes bounce { 0%, 80%, 100% { transform: translateY(0); opacity: .35; } 40% { transform: translateY(-5px); opacity: 1; } }

.composer-zone { padding: 12px 18px max(16px, env(safe-area-inset-bottom)); background: linear-gradient(180deg, rgba(33,33,33,0), var(--bg) 28%); }
.attachments { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.file-chip { display: inline-flex; align-items: center; gap: 7px; border: 1px solid var(--border); background: var(--surface); color: var(--muted); border-radius: 999px; padding: 7px 11px; font-size: 13px; }
.remove-file { border: 0; padding: 0 2px; color: var(--muted-2); }
.composer {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: end;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 28px;
  padding: 8px;
  box-shadow: var(--shadow);
}
textarea {
  width: 100%;
  max-height: 220px;
  min-height: 42px;
  resize: none;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--text);
  padding: 10px 6px;
  line-height: 1.5;
  overflow-y: auto;
}
textarea::placeholder { color: #aaa; }
.round-btn, .icon-btn, .send-btn { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 50%; font-weight: 850; }
.icon-btn, .round-btn { color: var(--muted); background: transparent; }
.send-btn { border: 0; background: var(--text); color: #171717; }
.send-btn.ready { background: var(--accent); color: white; }
.composer-meta { justify-content: space-between; gap: 10px; margin-top: 8px; color: var(--muted-2); font-size: 12px; }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.overlay { display: none; }
.toast { position: fixed; left: 50%; bottom: 92px; transform: translateX(-50%) translateY(8px); opacity: 0; pointer-events: none; z-index: 30; background: #101010; border: 1px solid var(--border); color: var(--text); padding: 10px 13px; border-radius: 999px; box-shadow: var(--shadow); transition: opacity .16s ease, transform .16s ease; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 820px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(88vw, 326px); z-index: 10; transform: translateX(-105%); transition: transform .18s ease; box-shadow: 24px 0 70px rgba(0,0,0,.45); }
  .sidebar.open { transform: translateX(0); }
  .overlay.open { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.48); z-index: 9; }
  .mobile-only { display: grid; }
  .topbar { padding: 10px 12px; min-height: 58px; }
  .topbar p, .mode-pill { display: none; }
  .ghost-btn { padding: 8px 10px; font-size: 13px; }
  .messages { padding: 14px 12px 10px; }
  .msg-row { grid-template-columns: 30px minmax(0, 1fr); gap: 10px; padding: 15px 0; }
  .avatar { width: 30px; height: 30px; }
  .copy-btn { opacity: 1; }
  .suggestions { grid-template-columns: 1fr; }
  .composer-zone { padding: 10px 10px max(12px, env(safe-area-inset-bottom)); }
  .composer { border-radius: 24px; }
  .composer-meta { font-size: 11px; }
}
