:root {
  --bg: #0d0c10;
  --surface: #15141b;
  --surface-2: #1c1a24;
  --border: #262433;
  --text: #eae7ee;
  --muted: #9a95a6;
  --gold: #d4a843;
  --gold-soft: rgba(212, 168, 67, 0.14);
  --gold-border: rgba(212, 168, 67, 0.42);
  --danger: #f87171;
  --ok: #4ecb8d;
  --sans: 'Archivo', system-ui, -apple-system, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, monospace;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

[hidden] { display: none !important; }

.muted { color: var(--muted); }
.error-text { color: var(--danger); font-size: 0.9rem; margin-top: 10px; }

.btn-gold {
  background: var(--gold);
  color: #14120c;
  border: none;
  border-radius: 10px;
  padding: 11px 16px;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  min-height: 44px;
}
.btn-gold.full { width: 100%; }

.btn-ghost {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 40px;
}
.btn-ghost.full { width: 100%; }
.btn-ghost.danger { color: var(--danger); border-color: rgba(248, 113, 113, 0.35); }

.icon-btn {
  width: 42px;
  height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 10px;
  color: var(--text);
  font-size: 1.35rem;
  cursor: pointer;
}
.icon-btn:active { background: var(--surface-2); }

/* Login */
.login-screen {
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 28px 22px;
  text-align: center;
}
.login-logo { width: 64px; height: 64px; border-radius: 14px; margin-bottom: 12px; }
.login-card h1 { margin: 0 0 6px; font-size: 1.4rem; }
.login-card p { margin: 0 0 18px; font-size: 0.9rem; line-height: 1.45; }
.login-card form { display: flex; flex-direction: column; gap: 10px; }
.login-card input {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 1rem;
  text-align: center;
  outline: none;
}
.login-card input:focus { border-color: var(--gold); }

/* App Shell */
.app-shell {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
  padding-top: env(safe-area-inset-top);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  background: rgba(13, 12, 16, 0.92);
  backdrop-filter: blur(10px);
  z-index: 20;
}
.topbar-center {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}
.chat-title {
  font-size: 0.9rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
.model-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--gold-soft);
  border: 1px solid var(--gold-border);
  color: var(--gold);
  font-size: 0.74rem;
  font-weight: 600;
  cursor: pointer;
}

/* Drawer */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 40;
}
.drawer {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: min(84vw, 320px);
  background: var(--surface);
  border-right: 1px solid var(--border);
  z-index: 50;
  display: flex;
  flex-direction: column;
  transform: translateX(-100%);
  transition: transform 0.2s ease;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}
.drawer.is-open { transform: translateX(0); }
.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.drawer-brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1rem; }
.brand-icon { width: 28px; height: 28px; border-radius: 8px; }
.drawer-actions { padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; }
.drawer-quick-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.drawer-search-wrap { padding: 0 14px 10px; }
.drawer-search-wrap input {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 0.88rem;
  outline: none;
}
.session-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.session-item {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text);
  border-radius: 10px;
  padding: 10px 10px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.session-item:hover, .session-item.is-active {
  background: var(--surface-2);
  border-color: var(--border);
}
.session-item.is-active { border-color: var(--gold-border); }
.session-item-title {
  font-size: 0.86rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.session-item-meta { font-size: 0.72rem; color: var(--muted); }
.drawer-foot { padding: 12px 14px; border-top: 1px solid var(--border); }

/* Chat Viewport */
.chat-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 14px 12px 20px;
  scroll-behavior: smooth;
}
.empty-state {
  max-width: 520px;
  margin: 40px auto 0;
  text-align: center;
  padding: 16px;
}
.empty-logo { width: 56px; height: 56px; border-radius: 14px; margin-bottom: 10px; }
.empty-state h2 { margin: 0 0 8px; font-size: 1.25rem; }
.empty-state p { margin: 0 0 18px; font-size: 0.92rem; line-height: 1.5; }
.quick-chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.chip-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 999px;
  padding: 8px 13px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}
.chip-btn:active { border-color: var(--gold); color: var(--gold); }

.messages {
  max-width: 780px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.msg { display: flex; flex-direction: column; gap: 6px; }
.msg.user { align-items: flex-end; }
.msg.assistant { align-items: flex-start; }

.bubble {
  max-width: 92%;
  border-radius: 14px;
  padding: 11px 14px;
  font-size: 0.94rem;
  line-height: 1.55;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.msg.user .bubble {
  background: var(--surface-2);
  border: 1px solid var(--gold-border);
  white-space: pre-wrap;
}
.msg.assistant .bubble {
  width: 100%;
  max-width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
}

.step-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.76rem;
  color: var(--gold);
  background: var(--gold-soft);
  border: 1px solid var(--gold-border);
  border-radius: 999px;
  padding: 3px 10px;
  margin-bottom: 6px;
}
.pulse-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--gold);
  animation: pulse 1.1s infinite ease-in-out;
}
@keyframes pulse {
  0%, 100% { opacity: 0.35; transform: scale(0.85); }
  50% { opacity: 1; transform: scale(1.1); }
}

.msg-meta {
  font-size: 0.72rem;
  color: var(--muted);
  padding: 0 4px;
}

.confirm-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 6px;
}
.confirm-btn {
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
}
.confirm-btn.approve {
  background: var(--gold);
  color: #14120c;
  border-color: var(--gold);
}
.confirm-btn.cancel { color: var(--danger); border-color: rgba(248, 113, 113, 0.38); }

/* Markdown formatting */
.bubble p { margin: 0 0 10px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { margin: 6px 0 10px; padding-left: 20px; }
.bubble code {
  font-family: var(--mono);
  font-size: 0.84em;
  background: rgba(255, 255, 255, 0.08);
  padding: 2px 5px;
  border-radius: 5px;
}
.code-wrap {
  position: relative;
  margin: 10px 0;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: #09090d;
}
.code-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  background: #13121a;
  border-bottom: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--muted);
}
.copy-code-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 3px 8px;
  font-size: 0.72rem;
  cursor: pointer;
}
.code-wrap pre {
  margin: 0;
  padding: 10px 12px;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 0.82rem;
  line-height: 1.45;
}
.code-wrap pre code { background: none; padding: 0; }
.bubble a { color: var(--gold); word-break: break-all; }

/* Composer & Slash Palette */
.composer-wrap {
  position: relative;
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: 8px 10px calc(10px + env(safe-area-inset-bottom));
}

.slash-palette {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 100%;
  margin-bottom: 8px;
  max-height: min(56dvh, 400px);
  background: var(--surface);
  border: 1px solid var(--gold-border);
  border-radius: 14px;
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.65);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 35;
}
.slash-tabs {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  overflow-x: auto;
}
.slash-tab {
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.slash-tab.is-active {
  background: var(--gold-soft);
  border-color: var(--gold-border);
  color: var(--gold);
}
.slash-count { margin-left: auto; font-size: 0.74rem; color: var(--muted); white-space: nowrap; }
.slash-list { overflow-y: auto; padding: 6px; display: flex; flex-direction: column; gap: 3px; }
.slash-item {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 9px 10px;
  color: var(--text);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.slash-item:hover, .slash-item.is-selected {
  background: var(--surface-2);
  border-color: var(--gold-border);
}
.slash-item-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.slash-cmd { font-family: var(--mono); font-size: 0.86rem; font-weight: 600; color: var(--gold); }
.slash-cat {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
}
.slash-desc {
  font-size: 0.78rem;
  color: var(--muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.attachment-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 2px 8px;
}
.att-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px 8px;
  font-size: 0.76rem;
}
.att-chip img { width: 28px; height: 28px; object-fit: cover; border-radius: 6px; }
.att-rm { background: none; border: none; color: var(--danger); cursor: pointer; font-size: 1rem; padding: 0 2px; }

.composer {
  max-width: 780px;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 6px;
}
.tool-btn {
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  cursor: pointer;
}
.tool-btn.slash-pill {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 1rem;
  color: var(--gold);
}
.composer textarea {
  flex: 1;
  min-height: 40px;
  max-height: 140px;
  resize: none;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 12px;
  padding: 10px 12px;
  font-family: var(--sans);
  font-size: 0.95rem;
  line-height: 1.35;
  outline: none;
}
.composer textarea:focus { border-color: var(--gold); }
.send-btn {
  width: 42px;
  height: 40px;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--gold);
  color: #14120c;
  border: none;
  border-radius: 10px;
  cursor: pointer;
}
.send-btn.is-stop {
  background: var(--danger);
  color: #fff;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
@media (min-width: 600px) { .modal { align-items: center; } }
.modal-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.65); }
.modal-card {
  position: relative;
  width: 100%;
  max-width: 460px;
  max-height: 82dvh;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px 16px 0 0;
  display: flex;
  flex-direction: column;
  z-index: 61;
  padding-bottom: env(safe-area-inset-bottom);
}
@media (min-width: 600px) { .modal-card { border-radius: 16px; } }
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.modal-head h3 { margin: 0; font-size: 1rem; }
.orch-box {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--surface-2);
}
.orch-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 0.85rem; }
.orch-row select {
  flex: 1;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 8px;
}
.model-list { overflow-y: auto; padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; }
.model-opt {
  width: 100%;
  text-align: left;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 11px 12px;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
}
.model-opt.is-active { border-color: var(--gold); color: var(--gold); background: var(--gold-soft); }
