/* ─── Sinteca ─────────────────────────────────────────────────────────── */
@font-face { font-family: 'Sinteca'; src: url('fonts/Sinteca-Regular.woff') format('woff');  font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: 'Sinteca'; src: url('fonts/Sinteca-Medium.woff') format('woff');   font-weight: 500; font-style: normal; font-display: swap; }
@font-face { font-family: 'Sinteca'; src: url('fonts/Sinteca-SemiBold.woff') format('woff'); font-weight: 600; font-style: normal; font-display: swap; }
@font-face { font-family: 'Sinteca'; src: url('fonts/Sinteca-Bold.woff') format('woff');     font-weight: 700; font-style: normal; font-display: swap; }

:root {
  --purple: #4D56D1;
  --purple-soft: #D0CFF9;
  --lime: #C0E703;
  --ink: #08090A;
  --paper: #FAFAFB;
  --paper-2: #F1F1F4;
  --paper-3: #E8E9EE;
  --line: #E5E5EC;
  --line-strong: #C9C9D4;
  --text: #1A1B22;
  --text-muted: #6B6C7A;

  --bg: var(--paper);
  --bg-surface: #FFFFFF;
  --bg-input: #FFFFFF;
  --bg-user: var(--purple);
  --text-user: #FFFFFF;
  --bg-assistant: #FFFFFF;
  --border: var(--line);
  --accent: var(--purple);
  --accent-hover: #3D45B5;
  --accent-soft: var(--purple-soft);
  --code-bg: #0F1020;
  --code-text: #E8E9F5;
  --code-inline-bg: var(--paper-2);
  --code-inline-text: #4D2178;
  --scrollbar: var(--line-strong);
  --sidebar-bg: #F5F5F8;
  --sidebar-border: var(--line);
  --danger: #B91C1C;
  --success: #15803D;

  --radius: 14px;
  --radius-sm: 8px;
  --font: 'Sinteca', system-ui, -apple-system, 'Inter', sans-serif;
  --font-mono: ui-monospace, 'JetBrains Mono', 'Fira Code', monospace;
  --shadow-sm: 0 1px 2px rgba(15, 16, 32, 0.04);
  --shadow-md: 0 6px 24px -8px rgba(77, 86, 209, 0.18);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%;
  background:
    radial-gradient(900px 600px at 85% -10%, rgba(192,231,3,0.10), transparent 60%),
    radial-gradient(700px 500px at -5% 100%, rgba(77,86,209,0.10), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
button { font-family: var(--font); }

/* ─── Layout: sidebar + main ─────────────────────────────────────────── */
#app {
  display: grid;
  grid-template-columns: 280px 1fr;
  height: 100vh;
}
#sidebar {
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.sidebar-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--border);
}
.sidebar-head .logo-sm {
  width: 32px; height: 32px;
  object-fit: contain;
  display: block;
}
#new-conv-btn {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--purple);
  color: white;
  border: none;
  border-radius: 10px;
  padding: 8px 12px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
#new-conv-btn:hover { background: var(--accent-hover); }
#new-conv-btn:active { transform: scale(0.96); }
#new-conv-btn i { font-size: 14px; }

.sidebar-search {
  position: relative;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}
.sidebar-search > i {
  position: absolute;
  left: 24px; top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 15px;
  pointer-events: none;
}
#conv-search {
  width: 100%;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 7px 30px 7px 32px;
  font-family: var(--font);
  font-size: 13px;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
}
#conv-search:focus { border-color: var(--purple); }
.search-clear {
  position: absolute;
  right: 18px; top: 50%;
  transform: translateY(-50%);
  background: none; border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  font-size: 14px;
}
.search-clear:hover { color: var(--text); }

#conv-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}
#conv-list::-webkit-scrollbar { width: 6px; }
#conv-list::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 3px; }

.conv-item {
  display: flex;
  align-items: center;
  gap: 4px;
  border-radius: 8px;
  margin-bottom: 2px;
  position: relative;
  transition: background 0.12s;
}
.conv-item:hover { background: rgba(77,86,209,0.08); }
.conv-item.active { background: rgba(77,86,209,0.13); }
.conv-item.active .conv-title { color: var(--purple); }
.conv-open {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
  padding: 10px 12px;
  border: none;
  background: transparent;
  text-align: left;
  cursor: pointer;
  font-family: var(--font);
  font-size: 13.5px;
  color: var(--text);
  border-radius: 8px;
}
.conv-title {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 500;
}
.conv-date {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
}
.conv-controls {
  display: flex;
  gap: 2px;
  padding-right: 6px;
  opacity: 0;
  transition: opacity 0.15s;
}
.conv-item:hover .conv-controls,
.conv-item:focus-within .conv-controls { opacity: 1; }
.conv-ctrl {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: 6px;
  border-radius: 6px;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.12s;
}
.conv-ctrl:hover { background: rgba(77,86,209,0.12); color: var(--purple); }
.conv-ctrl.conv-delete:hover { background: rgba(185,28,28,0.1); color: var(--danger); }
.conv-rename-input {
  flex: 1;
  background: var(--bg-surface);
  border: 1px solid var(--purple);
  border-radius: 6px;
  padding: 6px 8px;
  font-family: var(--font);
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text);
  outline: none;
  width: 100%;
}
.empty { padding: 24px 16px; color: var(--text-muted); font-size: 13px; text-align: center; }

.sidebar-foot {
  border-top: 1px solid var(--border);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--sidebar-bg);
}
.sidebar-foot .avatar-img,
.sidebar-foot .avatar-initials {
  width: 36px; height: 36px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--purple-soft);
  color: var(--purple);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  flex-shrink: 0;
}
.sidebar-user { flex: 1; min-width: 0; }
.user-name-sm {
  font-size: 13px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.user-actions { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.user-actions a { color: var(--text-muted); text-decoration: none; }
.user-actions a:hover { color: var(--purple); }

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

/* ─── Header ──────────────────────────────────────────────────────────── */
header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: rgba(255,255,255,0.85);
  backdrop-filter: saturate(140%) blur(8px);
  flex-shrink: 0;
}
.icon-btn {
  width: 36px; height: 36px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-surface);
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}
.icon-btn:hover { color: var(--purple); border-color: var(--purple); }
#sidebar-toggle { display: none; }
.icon-btn i { font-size: 18px; line-height: 1; }
header .brand { display: flex; flex-direction: column; line-height: 1.1; gap: 2px; }
.brand-row { display: flex; align-items: center; gap: 8px; }
.brand-iso { width: 24px; height: 24px; object-fit: contain; transition: filter 0.2s; }
.brand-iso.thinking { animation: iso-pulse 1.4s ease-in-out infinite; }
@keyframes iso-pulse {
  0%, 100% { transform: scale(1); filter: drop-shadow(0 0 0 rgba(77,86,209,0)); }
  50%      { transform: scale(1.08); filter: drop-shadow(0 0 6px rgba(77,86,209,0.45)); }
}
header h1 { font-size: 22px; font-weight: 700; color: var(--text); letter-spacing: -0.3px; line-height: 1; }
header .brand-sub { font-size: 12px; font-weight: 500; color: var(--text-muted); letter-spacing: 0.4px; text-transform: lowercase; padding-left: 32px; }
header .status {
  margin-left: auto;
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; font-weight: 500; color: var(--text-muted);
}
.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--line-strong);
  transition: background 0.3s;
}
.status-dot.online { background: var(--lime); box-shadow: 0 0 0 3px rgba(192,231,3,0.25); }
.status-dot.thinking { background: var(--purple); box-shadow: 0 0 0 3px rgba(77,86,209,0.2); animation: pulse 1.2s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.45; } }

#user-chip {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 10px 4px 4px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 999px;
}
#user-chip .avatar-img,
#user-chip .avatar-initials {
  width: 28px; height: 28px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--purple-soft);
  color: var(--purple);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 11px;
}
#user-chip .user-name {
  font-size: 12.5px; font-weight: 500;
  max-width: 130px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ─── Welcome ─────────────────────────────────────────────────────────── */
#welcome {
  max-width: 620px;
  margin: 56px auto 24px;
  padding: 0 8px;
  text-align: center;
  animation: fadeUp 0.35s ease;
}
#welcome.hidden { display: none; }
#welcome .welcome-logo { width: 96px; height: 96px; object-fit: contain; margin-bottom: 20px; }
#welcome h2 { font-size: 30px; font-weight: 700; letter-spacing: -0.6px; margin-bottom: 10px; color: var(--text); }
#welcome p { color: var(--text-muted); font-size: 15px; max-width: 460px; margin: 0 auto; line-height: 1.55; }

/* ─── Messages ────────────────────────────────────────────────────────── */
#messages {
  flex: 1;
  overflow-y: auto;
  padding: 28px 24px 16px;
  scroll-behavior: smooth;
  max-width: 880px;
  width: 100%;
  margin: 0 auto;
}
#messages::-webkit-scrollbar { width: 6px; }
#messages::-webkit-scrollbar-thumb { background: var(--scrollbar); border-radius: 3px; }
.message { display: flex; gap: 12px; margin-bottom: 22px; animation: fadeUp 0.22s ease; align-items: flex-start; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
.message.user { flex-direction: row-reverse; }
.message.user .msg-body { align-items: flex-end; }
.message.assistant .msg-body { align-items: flex-start; }
.message.system { justify-content: center; }
.msg-avatar {
  width: 34px; height: 34px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  padding: 5px;
  object-fit: contain;
  box-shadow: var(--shadow-sm);
}
.msg-body {
  display: flex;
  flex-direction: column;
  min-width: 0;
  max-width: calc(100% - 50px);
}
.bubble {
  max-width: 100%;
  padding: 13px 17px;
  border-radius: var(--radius);
  line-height: 1.65;
  word-break: break-word;
  box-shadow: var(--shadow-sm);
}
.message.user .bubble { background: var(--bg-user); color: var(--text-user); border-bottom-right-radius: 4px; }
.message.assistant .bubble { background: var(--bg-assistant); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.message.system .bubble { background: transparent; color: var(--text-muted); font-size: 12px; font-style: italic; border: none; padding: 4px 0; box-shadow: none; }

.bubble p { margin-bottom: 10px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble h1, .bubble h2, .bubble h3 { font-weight: 700; margin: 16px 0 8px; line-height: 1.3; letter-spacing: -0.2px; }
.bubble h1 { font-size: 1.3em; } .bubble h2 { font-size: 1.15em; } .bubble h3 { font-size: 1em; }
.bubble ul, .bubble ol { padding-left: 22px; margin-bottom: 10px; }
.bubble li { margin-bottom: 4px; }
.bubble blockquote { border-left: 3px solid var(--lime); padding-left: 12px; color: var(--text-muted); margin: 10px 0; }
.bubble strong { font-weight: 700; }
.bubble em { font-style: italic; }
.message.user .bubble a { color: #FFFFFF; text-decoration: underline; }
.message.assistant .bubble a { color: var(--purple); text-decoration: none; font-weight: 500; }
.message.assistant .bubble a:hover { text-decoration: underline; }
.bubble hr { border: none; border-top: 1px solid var(--border); margin: 12px 0; }
.bubble code {
  background: var(--code-inline-bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 6px;
  font-family: var(--font-mono);
  font-size: 0.88em;
  color: var(--code-inline-text);
}
.message.user .bubble code {
  background: rgba(255,255,255,0.18);
  border-color: rgba(255,255,255,0.25);
  color: #FFFFFF;
}
.code-wrapper { position: relative; margin: 12px 0; border-radius: var(--radius-sm); overflow: hidden; border: 1px solid var(--code-bg); }
.code-header {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--code-bg); padding: 7px 12px;
  font-size: 11px; color: #A0A1B5; font-family: var(--font-mono);
  text-transform: uppercase; letter-spacing: 0.5px;
}
.copy-btn {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 4px;
  color: #C9C9D4; cursor: pointer;
  font-size: 11px; font-family: var(--font);
  padding: 2px 9px; transition: all 0.15s;
}
.copy-btn:hover { background: rgba(255,255,255,0.08); color: #FFFFFF; }
.copy-btn.copied { color: var(--lime); border-color: var(--lime); }
.bubble pre { margin: 0; background: var(--code-bg); overflow-x: auto; padding: 14px 16px; }
.bubble pre code { background: none; border: none; padding: 0; color: var(--code-text); font-size: 0.85em; }

/* ─── Message actions (feedback + copy + regen + edit) ──────────────── */
.msg-actions {
  display: flex; gap: 4px;
  margin-top: 6px;
  opacity: 0;
  transition: opacity 0.2s;
}
.message.assistant:hover .msg-actions,
.message.assistant .msg-actions:focus-within,
.message.user:hover .msg-actions,
.message.user .msg-actions:focus-within { opacity: 1; }
.msg-action {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 9px;
  font-size: 14px;
  cursor: pointer;
  color: var(--text-muted);
  font-family: var(--font);
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.msg-action:hover { border-color: var(--purple); color: var(--purple); }
.msg-action.voted { background: var(--purple-soft); color: var(--purple); border-color: var(--purple); }
.msg-actions-user { justify-content: flex-end; }

/* Edición inline de mensaje user */
.edit-textarea {
  width: 100%;
  min-width: 320px;
  background: rgba(255,255,255,0.18);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.35);
  border-radius: 8px;
  padding: 8px 10px;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  outline: none;
  resize: vertical;
}
.edit-textarea::placeholder { color: rgba(255,255,255,0.5); }
.edit-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }
.btn-primary-sm, .btn-secondary-sm {
  font-family: var(--font);
  font-weight: 600;
  font-size: 13px;
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s;
}
.btn-primary-sm { background: #fff; color: var(--purple); }
.btn-primary-sm:hover { background: var(--lime); color: var(--ink); }
.btn-secondary-sm { background: transparent; color: rgba(255,255,255,0.85); border-color: rgba(255,255,255,0.35); }
.btn-secondary-sm:hover { background: rgba(255,255,255,0.12); }

/* Attachments en mensajes */
.msg-attachments { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 6px; }
.att-chip {
  background: var(--paper-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  color: var(--text);
}
.att-chip .att-rm {
  background: none; border: none; cursor: pointer;
  margin-left: 4px; color: var(--text-muted);
  font-size: 14px; line-height: 1;
}
.att-chip .att-rm:hover { color: var(--danger); }

/* ─── Typing ──────────────────────────────────────────────────────────── */
.typing-indicator { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; padding: 0 0 4px; }
.typing-indicator .msg-avatar { animation: iso-pulse 1.4s ease-in-out infinite; }
.typing-dots {
  display: flex; gap: 4px;
  padding: 14px 16px;
  background: var(--bg-assistant);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  border-bottom-left-radius: 4px;
  box-shadow: var(--shadow-sm);
}
.typing-dots span { width: 6px; height: 6px; border-radius: 50%; background: var(--purple); animation: blink 1.4s infinite; opacity: 0.4; }
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
.typing-label {
  font-size: 13px;
  color: var(--text-muted);
  font-style: italic;
  animation: fade-in 0.25s ease;
}
@keyframes blink { 0%,80%,100% { opacity: 0.25; } 40% { opacity: 1; } }
@keyframes fade-in { from { opacity: 0; transform: translateY(2px); } to { opacity: 1; transform: none; } }

/* ─── Botón micro (grabación de voz) ─────────────────────────────────── */
#mic-btn { position: relative; }
#mic-btn.recording {
  color: #fff;
  background: var(--danger, #e23b3b);
  border-color: var(--danger, #e23b3b);
  animation: mic-pulse 1.2s ease-in-out infinite;
}
#mic-btn.recording::after {
  content: attr(data-timer);
  position: absolute;
  top: -6px; right: -6px;
  background: var(--danger, #e23b3b);
  color: #fff;
  font-size: 10px;
  padding: 2px 5px;
  border-radius: 8px;
  pointer-events: none;
}
#mic-btn.transcribing {
  color: var(--purple);
  border-color: var(--purple);
  animation: mic-spin 1s linear infinite;
}
@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(226,59,59,0.5); }
  50%      { box-shadow: 0 0 0 8px rgba(226,59,59,0); }
}
@keyframes mic-spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

/* ─── Input ───────────────────────────────────────────────────────────── */
#input-area {
  padding: 16px 24px 24px;
  border-top: 1px solid var(--border);
  background: rgba(255,255,255,0.85);
  backdrop-filter: saturate(140%) blur(8px);
  flex-shrink: 0;
  max-width: 880px;
  width: 100%;
  margin: 0 auto;
}
#attachments-bar {
  display: flex; flex-wrap: wrap; gap: 6px;
  margin-bottom: 8px;
}
#input-wrap {
  display: flex; align-items: flex-end; gap: 8px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 8px 8px 8px 8px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
#input-wrap:focus-within { border-color: var(--purple); box-shadow: var(--shadow-md); }
#upload-btn {
  border: none; background: transparent;
  width: 36px; height: 36px;
  border-radius: 10px;
  color: var(--text-muted);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: color 0.15s, background 0.15s;
  flex-shrink: 0;
}
#upload-btn:hover { color: var(--purple); background: var(--paper-2); }
#user-input {
  flex: 1;
  background: none; border: none; outline: none;
  color: var(--text); font-family: var(--font);
  font-size: 15px; line-height: 1.5;
  resize: none; min-height: 28px; max-height: 160px;
  padding: 6px 4px;
  overflow-y: auto;
}
#user-input::placeholder { color: var(--text-muted); }
#send-btn {
  width: 36px; height: 36px;
  border-radius: 10px; border: none;
  background: var(--purple); color: white;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; transition: all 0.15s;
}
#send-btn:hover:not(:disabled) { background: var(--accent-hover); box-shadow: var(--shadow-md); }
#send-btn:active:not(:disabled) { transform: scale(0.93); }
#send-btn:disabled { background: var(--paper-2); color: var(--line-strong); cursor: not-allowed; }
#send-btn i, #stop-btn i { font-size: 16px; }
#stop-btn {
  width: 36px; height: 36px;
  border-radius: 10px; border: none;
  background: var(--danger);
  color: white;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  animation: stop-pulse 1.6s ease-in-out infinite;
}
#stop-btn:hover { background: #991b1b; }
#stop-btn:active { transform: scale(0.93); }
@keyframes stop-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(185,28,28,0.4); }
  50%      { box-shadow: 0 0 0 6px rgba(185,28,28,0); }
}
#upload-btn i, #mic-btn i { font-size: 18px; }
.icon-btn-flat {
  width: 36px; height: 36px;
  border: none; background: transparent;
  border-radius: 10px;
  color: var(--text-muted);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: color 0.15s, background 0.15s;
  flex-shrink: 0;
}
.icon-btn-flat:hover { color: var(--purple); background: var(--paper-2); }
.input-hint { margin-top: 8px; font-size: 11px; color: var(--text-muted); text-align: center; letter-spacing: 0.2px; }

/* ─── Code header con icono ──────────────────────────────────────────── */
.code-header .code-lang { font-weight: 600; }
.copy-btn { display: inline-flex; align-items: center; gap: 4px; }
.copy-btn i { font-size: 12px; }

/* ─── Tabla en markdown ──────────────────────────────────────────────── */
.table-wrapper { overflow-x: auto; margin: 12px 0; border-radius: var(--radius-sm); border: 1px solid var(--border); }
.bubble table { border-collapse: collapse; width: 100%; font-size: 0.95em; }
.bubble thead { background: var(--paper-2); }
.bubble th, .bubble td { padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--border); }
.bubble th { font-weight: 700; color: var(--text); }
.bubble tbody tr:last-child td { border-bottom: none; }
.bubble tbody tr:hover { background: rgba(77,86,209,0.04); }

/* ─── Drag & drop overlay ────────────────────────────────────────────── */
#main.dragging::before {
  content: 'Suelta para adjuntar';
  position: absolute;
  inset: 0;
  background: rgba(77,86,209,0.10);
  border: 2px dashed var(--purple);
  border-radius: 12px;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 700;
  color: var(--purple);
  pointer-events: none;
}
#main { position: relative; }

/* ─── Sidebar backdrop (mobile) ──────────────────────────────────────── */
#sidebar-backdrop {
  position: fixed; inset: 0;
  background: rgba(8,9,10,0.45);
  z-index: 40;
  animation: fade-in 0.2s ease;
}

/* ─── Mobile ──────────────────────────────────────────────────────────── */
@media (max-width: 760px) {
  #app { grid-template-columns: 1fr; }
  #sidebar {
    position: fixed; inset: 0 auto 0 0;
    width: min(86vw, 320px);
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    z-index: 50;
    box-shadow: 8px 0 24px rgba(0,0,0,0.18);
  }
  #sidebar.open { transform: translateX(0); }
  #sidebar-toggle { display: flex; }
  #user-chip .user-name { display: none; }
  header { padding: 12px 14px; gap: 8px; }
  header h1 { font-size: 18px; }

  /* Tap targets ≥44px en móvil */
  .icon-btn, .icon-btn-flat, #send-btn, #stop-btn { width: 44px; height: 44px; }
  #upload-btn i, #mic-btn i, .icon-btn i { font-size: 20px; }
  .conv-ctrl { width: 36px; height: 36px; font-size: 16px; }
  .conv-controls { opacity: 1; } /* en móvil siempre visibles */

  /* Messages: avatar más pequeño, body más ancho */
  .msg-avatar { width: 30px; height: 30px; padding: 4px; }
  .msg-body { max-width: calc(100% - 42px); }

  /* Input: padding extra para no chocar con teclado iOS */
  #input-area { padding: 12px 14px max(20px, env(safe-area-inset-bottom)); }
  #messages { padding: 18px 14px 12px; }

  /* Welcome más compacto */
  #welcome { margin: 32px auto 16px; }
  #welcome .welcome-logo { width: 72px; height: 72px; }
  #welcome h2 { font-size: 24px; }

  /* Brand: ocultar sub en mobile para ahorrar espacio */
  header .brand-sub { display: none; }
  .brand-iso { width: 22px; height: 22px; }
}

/* ─── Dark mode auto ─────────────────────────────────────────────────── */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0E0F18;
    --bg-surface: #15161F;
    --bg-input: #1B1D2A;
    --bg-assistant: #15161F;
    --border: #252736;
    --line-strong: #3A3D52;
    --text: #ECECF1;
    --text-muted: #8E90A6;
    --paper-2: #20222F;
    --paper-3: #1B1D2A;
    --sidebar-bg: #11121B;
    --sidebar-border: #252736;
    --code-inline-bg: #20222F;
    --code-inline-text: #C0E703;
  }
  html, body {
    background:
      radial-gradient(900px 600px at 85% -10%, rgba(192,231,3,0.08), transparent 60%),
      radial-gradient(700px 500px at -5% 100%, rgba(77,86,209,0.18), transparent 60%),
      var(--bg);
  }
  header, #input-area { background: rgba(21,22,31,0.85); }
}

/* ─── LOGIN PAGE ──────────────────────────────────────────────────────── */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 40px;
  max-width: 420px;
  width: 100%;
  text-align: center;
  box-shadow: 0 24px 60px -20px rgba(77,86,209,0.25);
}
.login-card img.logo { width: 64px; height: 64px; margin-bottom: 18px; }
.login-card h1 { font-size: 24px; font-weight: 700; margin-bottom: 6px; letter-spacing: -0.4px; }
.login-card .sub { color: var(--text-muted); margin-bottom: 28px; font-size: 14px; }
.login-google {
  display: inline-flex; align-items: center; gap: 10px;
  background: var(--purple); color: white; border: none;
  border-radius: 12px; padding: 13px 22px;
  font-family: var(--font); font-weight: 600; font-size: 15px;
  text-decoration: none;
  transition: all 0.15s;
}
.login-google:hover { background: var(--accent-hover); box-shadow: var(--shadow-md); }
.login-google:active { transform: scale(0.97); }
.login-google svg { width: 18px; height: 18px; }
.login-error {
  background: rgba(239,68,68,0.08);
  border: 1px solid rgba(239,68,68,0.25);
  color: var(--danger);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 13px;
  margin-bottom: 18px;
}
.login-foot { margin-top: 24px; font-size: 12px; color: var(--text-muted); }

/* ─── ADMIN ───────────────────────────────────────────────────────────── */
.admin-body { background: var(--bg); }
.admin-wrap { max-width: 1200px; margin: 0 auto; padding: 24px; }
.admin-header {
  display: flex; align-items: center; gap: 16px;
  margin-bottom: 24px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--border);
}
.admin-back {
  display: flex; align-items: center; gap: 8px;
  text-decoration: none; color: var(--text);
  font-weight: 700;
}
.admin-back .logo-sm { width: 28px; height: 28px; }
.admin-header h1 {
  font-size: 22px; font-weight: 700;
  letter-spacing: -0.3px;
}
.admin-actions { margin-left: auto; }
.btn-secondary {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 16px;
  border-radius: 10px;
  font-weight: 500;
  font-size: 13px;
  cursor: pointer;
}
.btn-secondary:hover { border-color: var(--purple); color: var(--purple); }

.admin-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 24px;
}
@media (max-width: 760px) { .admin-grid { grid-template-columns: repeat(2, 1fr); } }

.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  box-shadow: var(--shadow-sm);
}
.card h2 { font-size: 14px; font-weight: 700; margin-bottom: 12px; letter-spacing: -0.1px; color: var(--text); text-transform: uppercase; letter-spacing: 0.5px; }
.card.kpi { padding: 18px 20px; }
.kpi-label { font-size: 11px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }
.kpi-value { font-size: 32px; font-weight: 700; margin-top: 6px; letter-spacing: -0.8px; }
.admin-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 24px; }
@media (max-width: 760px) { .admin-row { grid-template-columns: 1fr; } }

.users-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.users-table th { text-align: left; padding: 8px 6px; color: var(--text-muted); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.4px; border-bottom: 1px solid var(--border); }
.users-table td { padding: 9px 6px; border-bottom: 1px solid var(--border); }
.users-table tr:last-child td { border-bottom: none; }
.users-table .num { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.users-table .bar-cell { width: 30%; min-width: 80px; }
.users-table .bar { height: 6px; background: var(--purple); border-radius: 3px; }
.muted { color: var(--text-muted); font-size: 13px; }

.bar-chart { display: flex; align-items: flex-end; gap: 4px; height: 140px; padding: 8px 0; }
.bar-item { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 0; }
.bar-v { width: 100%; background: var(--purple); border-radius: 3px 3px 0 0; min-height: 2px; transition: height 0.2s; }
.bar-item:hover .bar-v { background: var(--accent-hover); }
.bar-label { font-size: 9px; color: var(--text-muted); white-space: nowrap; transform: rotate(-45deg); transform-origin: top left; }

.fb-item {
  padding: 14px;
  border-radius: 12px;
  margin-bottom: 10px;
  border: 1px solid var(--border);
  background: var(--paper-2);
}
.fb-item.up { border-left: 3px solid var(--success); }
.fb-item.down { border-left: 3px solid var(--danger); }
.fb-head { display: flex; align-items: center; gap: 10px; font-size: 13px; margin-bottom: 6px; }
.fb-icon { font-size: 16px; }
.fb-user { font-weight: 600; }
.fb-time { color: var(--text-muted); font-size: 11px; margin-left: auto; }
.fb-note { font-size: 14px; padding: 8px 12px; background: var(--bg-surface); border-radius: 8px; margin-top: 4px; }
.fb-msg { margin-top: 8px; font-size: 13px; }
.fb-msg summary { cursor: pointer; color: var(--text-muted); }
.fb-msg pre { background: var(--bg-surface); border-radius: 8px; padding: 10px; margin-top: 6px; font-family: var(--font); white-space: pre-wrap; word-break: break-word; font-size: 13px; }
