:root {
  --bg: #0b0b0f;
  --bg-elev: #14141b;
  --bg-elev-2: #1c1c25;
  --bg-elev-3: #252532;
  --border: #262633;
  --border-light: #34344a;
  --text: #ececf1;
  --text-dim: #9a9aac;
  --text-dim-2: #6e6e80;
  --accent: #ff6a3d;
  --accent-2: #ffb14a;
  --user-bubble: #2a2a36;
  --danger: #ff5c5c;
  --ok: #4ade80;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 10px 30px rgba(0,0,0,.45);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  --sidebar-w: 280px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; }
.dim { color: var(--text-dim); font-size: 13px; margin: 0; }

/* Layout */
.main {
  display: flex;
  flex-direction: column;
  height: 100vh;
  transition: padding-left .25s ease;
}
.sidebar {
  position: fixed; inset: 0 auto 0 0;
  width: var(--sidebar-w);
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  z-index: 30;
  transform: translateX(-100%);
  transition: transform .25s ease;
  padding-top: var(--safe-top);
}
.sidebar.open { transform: translateX(0); }
.backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 25;
  backdrop-filter: blur(2px);
}
.sidebar-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo {
  width: 36px; height: 36px; border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #1a0d00; font-weight: 800; font-size: 13px;
  display: flex; align-items: center; justify-content: center;
  letter-spacing: .5px; flex-shrink: 0;
}
.brand-title { font-weight: 700; font-size: 14px; }
.brand-sub { font-size: 11px; color: var(--text-dim); }
.close-sidebar { display: none; }
.sidebar-section { padding: 12px; }
.sidebar-section.sidebar-footer {
  margin-top: auto;
  border-top: 1px solid var(--border);
}
.section-title {
  font-size: 11px; text-transform: uppercase; letter-spacing: 1px;
  color: var(--text-dim-2); padding: 0 8px 8px;
}
.big-btn {
  display: flex; align-items: center; gap: 10px;
  width: 100%; background: var(--bg-elev-2);
  border: 1px solid var(--border); color: var(--text);
  padding: 10px 12px; border-radius: 10px;
  cursor: pointer; font-size: 14px; font-weight: 500;
  text-align: left; margin-bottom: 6px;
  transition: border-color .15s, background .15s;
}
.big-btn:hover { border-color: var(--border-light); background: var(--bg-elev-3); }
.big-btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #1a0d00; border: none; font-weight: 700;
}
.projects-list { display: flex; flex-direction: column; gap: 4px; }
.project-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px; border-radius: 10px;
  cursor: pointer; color: var(--text); font-size: 14px;
  border: 1px solid transparent;
}
.project-item:hover { background: var(--bg-elev-2); }
.project-item.active {
  background: var(--bg-elev-2);
  border-color: var(--accent);
}
.project-item .info { min-width: 0; flex: 1; }
.project-item .name {
  font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.project-item .type {
  font-size: 11px; color: var(--text-dim); margin-top: 2px;
}
.project-item .edit {
  background: transparent; border: none; color: var(--text-dim);
  cursor: pointer; padding: 4px; opacity: 0; transition: opacity .15s;
}
.project-item:hover .edit, .project-item.active .edit { opacity: 1; }
.project-item .edit:hover { color: var(--accent); }

/* Topbar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px;
  padding-top: calc(10px + var(--safe-top));
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
  gap: 8px;
}
.topbar-left { display: flex; align-items: center; gap: 8px; min-width: 0; flex: 1; }
.title-wrap { display: flex; flex-direction: column; min-width: 0; }
.topbar h1 {
  margin: 0; font-size: 15px; font-weight: 700; letter-spacing: .2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.mode-chip {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 11px; font-weight: 600;
  padding: 2px 8px; border-radius: 999px;
  cursor: pointer; margin-top: 2px; align-self: flex-start;
}
.mode-chip:hover { color: var(--text); }
.actions { display: flex; gap: 4px; flex-shrink: 0; }
.icon-btn {
  background: transparent; border: none; color: var(--text-dim);
  width: 40px; height: 40px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0;
}
.icon-btn:hover { background: var(--bg-elev-2); color: var(--text); }
.icon-btn.recording {
  color: var(--danger);
  animation: pulse 1.2s ease infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .5; }
}

/* Chat */
.chat {
  flex: 1; overflow-y: auto; padding: 16px 14px 24px;
  scroll-behavior: smooth;
  display: flex; flex-direction: column; gap: 14px;
}
.chat::-webkit-scrollbar { width: 8px; }
.chat::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.empty-state {
  margin: auto; max-width: 560px; text-align: center; padding: 24px;
  color: var(--text-dim);
}
.empty-state h2 { color: var(--text); font-size: 22px; margin: 0 0 10px; }
.empty-state .examples { display: grid; gap: 8px; margin-top: 16px; }
.example {
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 12px 14px; text-align: left;
  color: var(--text); cursor: pointer; font-size: 14px;
  font-family: inherit;
}
.example:hover { border-color: var(--accent); }
.example b { color: var(--accent-2); }

.msg { display: flex; gap: 10px; max-width: 100%; }
.msg .avatar {
  width: 28px; height: 28px; border-radius: 8px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700;
}
.msg.user .avatar { background: #3a3a4a; color: #fff; }
.msg.assistant .avatar {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #1a0d00;
}
.msg .bubble {
  background: var(--user-bubble);
  padding: 10px 14px; border-radius: var(--radius);
  max-width: calc(100% - 38px);
  word-wrap: break-word; overflow-wrap: anywhere;
}
.msg.assistant .bubble { background: transparent; padding: 6px 0; }
.msg .bubble img { max-width: 100%; border-radius: 10px; margin: 6px 0; display: block; }
.msg .bubble p { margin: 0 0 10px; }
.msg .bubble p:last-child { margin-bottom: 0; }
.msg .bubble h1, .msg .bubble h2, .msg .bubble h3, .msg .bubble h4 {
  margin: 14px 0 6px; line-height: 1.25;
}
.msg .bubble h1 { font-size: 20px; }
.msg .bubble h2 { font-size: 18px; color: var(--accent-2); }
.msg .bubble h3 { font-size: 16px; }
.msg .bubble ul, .msg .bubble ol { margin: 6px 0 10px; padding-left: 22px; }
.msg .bubble li { margin: 2px 0; }
.msg .bubble code {
  background: var(--bg-elev-2); padding: 1px 6px; border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px;
}
.msg .bubble pre {
  background: var(--bg-elev-2); padding: 12px; border-radius: 10px;
  overflow-x: auto; margin: 10px 0; border: 1px solid var(--border);
  position: relative;
}
.msg .bubble pre code { background: transparent; padding: 0; font-size: 13px; }
.msg .bubble pre .copy-pre {
  position: absolute; top: 6px; right: 6px;
  background: var(--bg-elev-3); border: 1px solid var(--border);
  color: var(--text-dim); padding: 3px 8px; border-radius: 6px;
  font-size: 11px; cursor: pointer;
}
.msg .bubble pre .copy-pre:hover { color: var(--text); }
.msg .bubble blockquote {
  border-left: 3px solid var(--accent); padding-left: 12px; color: var(--text-dim);
  margin: 10px 0;
}
.msg .bubble a { color: var(--accent-2); }
.msg .bubble hr { border: none; border-top: 1px solid var(--border); margin: 14px 0; }

.msg-actions {
  display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap;
}
.msg-actions button {
  background: var(--bg-elev); border: 1px solid var(--border);
  color: var(--text-dim); padding: 4px 10px; border-radius: 6px;
  font-size: 12px; cursor: pointer; font-family: inherit;
  display: inline-flex; align-items: center; gap: 4px;
}
.msg-actions button:hover { color: var(--text); border-color: var(--border-light); }
.msg-actions button.primary {
  background: var(--accent); color: #1a0d00; border-color: var(--accent);
}
.msg-actions button.primary:hover { color: #1a0d00; }

.typing { display: inline-flex; gap: 4px; align-items: center; padding: 6px 0; }
.typing span {
  width: 6px; height: 6px; border-radius: 50%; background: var(--text-dim);
  animation: blink 1.2s infinite;
}
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 60%, 100% { opacity: .25 } 30% { opacity: 1 } }

/* Composer */
.composer {
  background: var(--bg-elev);
  border-top: 1px solid var(--border);
  padding: 10px 12px calc(10px + var(--safe-bottom));
}
.attachments {
  display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px;
}
.attachments:empty { display: none; }
.attachment {
  position: relative; width: 60px; height: 60px; border-radius: 10px;
  overflow: hidden; border: 1px solid var(--border);
}
.attachment img { width: 100%; height: 100%; object-fit: cover; }
.attachment button {
  position: absolute; top: 2px; right: 2px; width: 20px; height: 20px;
  border-radius: 50%; border: none; background: rgba(0,0,0,.7); color: #fff;
  font-size: 14px; line-height: 1; cursor: pointer;
}
.composer-row {
  display: flex; align-items: flex-end; gap: 4px;
  background: var(--bg-elev-2); border: 1px solid var(--border);
  border-radius: 18px; padding: 6px 6px 6px 6px;
}
.composer-row:focus-within { border-color: var(--accent); }
#input {
  flex: 1; background: transparent; border: none; color: var(--text);
  font-size: 16px; line-height: 1.4; resize: none; outline: none;
  padding: 8px 6px; max-height: 180px; font-family: inherit;
  min-width: 0;
}
.send-btn {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #1a0d00; border: none; width: 40px; height: 40px;
  border-radius: 12px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.send-btn:disabled { opacity: .4; cursor: not-allowed; }
.send-btn.stop { background: var(--danger); color: #fff; }
.hint {
  text-align: center; font-size: 11px; color: var(--text-dim);
  margin-top: 6px;
}
.hint b { color: var(--accent-2); }

/* Modal */
.modal {
  border: none; padding: 0; background: transparent;
  max-width: 460px; width: calc(100% - 32px);
  border-radius: 16px;
  color: var(--text);
}
.modal.big { max-width: 720px; }
.modal::backdrop { background: rgba(0,0,0,.6); backdrop-filter: blur(4px); }
.modal-form {
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: 16px; padding: 20px;
  display: flex; flex-direction: column; gap: 14px;
  max-height: 90vh; overflow-y: auto;
}
.modal h2 { margin: 0 0 4px; font-size: 18px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field span { font-size: 13px; color: var(--text-dim); }
.field input, .field select, .field textarea {
  background: var(--bg-elev-2); border: 1px solid var(--border);
  color: var(--text); padding: 10px 12px; border-radius: 10px;
  font-size: 14px; font-family: inherit; resize: vertical;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--accent);
}
.field small { color: var(--text-dim); font-size: 11px; }
.field small a { color: var(--accent-2); }
.modal-actions {
  display: flex; justify-content: space-between; gap: 8px; margin-top: 6px;
  flex-wrap: wrap;
}
.modal-actions .btn:last-child { margin-left: auto; }
.btn {
  background: var(--bg-elev-2); border: 1px solid var(--border);
  color: var(--text); padding: 10px 16px; border-radius: 10px;
  cursor: pointer; font-size: 14px; font-weight: 600;
}
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #1a0d00; border: none; }
.btn.danger { color: var(--danger); border-color: rgba(255,92,92,.3); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.mode-card {
  background: var(--bg-elev-2); border: 1px solid var(--border);
  color: var(--text); padding: 12px 14px; border-radius: 12px;
  cursor: pointer; text-align: left;
  display: flex; flex-direction: column; gap: 2px;
  font-family: inherit;
}
.mode-card:hover { border-color: var(--accent); }
.mode-card.highlight {
  background: linear-gradient(135deg, rgba(255,106,61,.15), rgba(255,177,74,.08));
  border-color: var(--accent);
}
.mode-card b { font-size: 14px; }
.mode-card span { font-size: 12px; color: var(--text-dim); }

.wizards-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
}
.wizard-card {
  background: var(--bg-elev-2); border: 1px solid var(--border);
  color: var(--text); padding: 14px; border-radius: 12px;
  cursor: pointer; text-align: left;
  display: flex; flex-direction: column; gap: 4px;
  font-family: inherit; font-size: 14px;
}
.wizard-card:hover { border-color: var(--accent); }
.wizard-card .icon { font-size: 22px; margin-bottom: 4px; }
.wizard-card b { font-size: 14px; line-height: 1.2; }
.wizard-card span { font-size: 12px; color: var(--text-dim); }

/* Library */
.library-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.library-head input {
  flex: 1; max-width: 240px;
  background: var(--bg-elev-2); border: 1px solid var(--border);
  color: var(--text); padding: 8px 12px; border-radius: 10px;
  font-size: 14px; font-family: inherit;
}
.library-list {
  display: flex; flex-direction: column; gap: 8px;
  max-height: 60vh; overflow-y: auto;
}
.library-item {
  background: var(--bg-elev-2); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px;
}
.library-item .lib-head {
  display: flex; justify-content: space-between; align-items: center;
  gap: 8px; margin-bottom: 6px;
}
.library-item .lib-meta {
  font-size: 11px; color: var(--text-dim);
}
.library-item .lib-actions { display: flex; gap: 6px; }
.library-item .lib-actions button {
  background: transparent; border: 1px solid var(--border);
  color: var(--text-dim); padding: 3px 8px; border-radius: 6px;
  font-size: 11px; cursor: pointer;
}
.library-item .lib-actions button:hover { color: var(--text); }
.library-item pre {
  background: var(--bg); border: 1px solid var(--border);
  padding: 8px; border-radius: 6px; margin: 0;
  font-size: 12px; max-height: 200px; overflow: auto;
  white-space: pre-wrap; word-break: break-word;
}

.image-preview {
  display: flex; justify-content: center; min-height: 100px;
  background: var(--bg-elev-2); border: 1px solid var(--border);
  border-radius: 10px; padding: 8px;
}
.image-preview img { max-width: 100%; border-radius: 6px; }

/* Drop overlay */
.drop-overlay {
  position: fixed; inset: 0; background: rgba(255,106,61,.15);
  border: 3px dashed var(--accent); z-index: 100;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; font-weight: 700; color: var(--accent-2);
  pointer-events: none;
}

/* Toast */
.toast {
  position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%);
  background: var(--bg-elev-2); border: 1px solid var(--danger);
  color: var(--text); padding: 10px 14px; border-radius: 10px;
  font-size: 13px; max-width: calc(100% - 32px); z-index: 200;
  box-shadow: var(--shadow);
}

/* Desktop */
@media (min-width: 900px) {
  .sidebar { transform: translateX(0); }
  .main { padding-left: var(--sidebar-w); }
  #openSidebarBtn { display: none; }
  .backdrop { display: none !important; }
  .chat { padding: 24px 32px; }
  .composer { padding: 14px 32px calc(14px + var(--safe-bottom)); }
  .msg { max-width: 760px; margin: 0 auto; width: 100%; }
  .empty-state { padding: 60px 24px; }
}
@media (max-width: 899px) {
  .close-sidebar { display: flex; }
}
@media (max-width: 540px) {
  .wizards-grid { grid-template-columns: 1fr; }
}

/* Keyboard shortcuts hint */
kbd {
  background: var(--bg-elev-3); border: 1px solid var(--border);
  color: var(--text); padding: 1px 6px; border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 10px;
}

/* Attachment types */
.attachment.file {
  display: flex; align-items: center; gap: 6px;
  width: auto; min-width: 120px; max-width: 200px;
  padding: 6px 10px; background: var(--bg-elev-2);
}
.attachment.file .file-icon {
  font-size: 18px;
}
.attachment.file .file-info {
  flex: 1; min-width: 0; font-size: 11px;
}
.attachment.file .file-name {
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  color: var(--text); font-weight: 600;
}
.attachment.file .file-meta { color: var(--text-dim); font-size: 10px; }

/* Usage hint (tokens + cost) */
#usageHint {
  color: var(--accent-2);
  font-variant-numeric: tabular-nums;
}
.msg .usage {
  display: inline-block; font-size: 11px; color: var(--text-dim);
  background: var(--bg-elev-2); padding: 2px 8px; border-radius: 8px;
  margin-top: 6px; font-variant-numeric: tabular-nums;
}

/* Search modal */
.search-head {
  display: flex; align-items: center; gap: 10px;
  border-bottom: 1px solid var(--border); padding-bottom: 12px; margin-bottom: 4px;
  color: var(--text-dim);
}
.search-head input {
  flex: 1; background: transparent; border: none; color: var(--text);
  font-size: 18px; outline: none; font-family: inherit;
}
.esc-hint { font-size: 10px; }
.search-results {
  display: flex; flex-direction: column; gap: 6px;
  max-height: 60vh; overflow-y: auto;
}
.search-results:empty::before {
  content: "Escribe para buscar en todos tus chats...";
  color: var(--text-dim); font-size: 13px; padding: 20px; text-align: center; display: block;
}
.search-result {
  background: var(--bg-elev-2); border: 1px solid var(--border);
  padding: 10px 12px; border-radius: 10px; cursor: pointer;
}
.search-result:hover { border-color: var(--accent); }
.search-result .sr-meta {
  font-size: 11px; color: var(--text-dim); margin-bottom: 4px;
  display: flex; justify-content: space-between; align-items: center;
}
.search-result .sr-meta .sr-role {
  background: var(--bg-elev-3); padding: 1px 6px; border-radius: 4px;
  font-size: 10px;
}
.search-result .sr-snippet {
  font-size: 13px; line-height: 1.4; color: var(--text);
}
.search-result mark {
  background: var(--accent); color: #1a0d00; padding: 0 2px; border-radius: 2px;
}

/* Welcome */
.welcome { text-align: center; align-items: center; }
.welcome-icon { font-size: 56px; line-height: 1; }
.welcome h2 { font-size: 22px; }
.welcome-steps {
  display: flex; flex-direction: column; gap: 8px;
  width: 100%; margin: 12px 0;
  background: var(--bg-elev-2); border: 1px solid var(--border);
  border-radius: 12px; padding: 14px;
}
.welcome-step { font-size: 14px; text-align: left; }
.welcome-step b { color: var(--accent-2); margin-right: 6px; }

/* Edit/delete message buttons */
.msg .msg-actions button.icon-only {
  padding: 4px 6px;
}
