/* ═══════════════════════════════════════════════
   DESIGN TOKENS
═══════════════════════════════════════════════ */

:root {
  /* Surfaces */
  --bg:          #08080f;
  --bg-sidebar:  #0e0e1a;
  --bg-surface:  #13131f;
  --bg-raised:   #1a1a28;
  --bg-hover:    rgba(255,255,255,0.04);
  --bg-active:   rgba(255,255,255,0.07);

  /* Borders */
  --border:      rgba(255,255,255,0.07);
  --border-med:  rgba(255,255,255,0.11);
  --border-hi:   rgba(255,255,255,0.18);

  /* Text */
  --fg:          #e4e4f0;
  --fg-2:        #9898b0;
  --fg-3:        #4a4a62;

  /* Accent – indigo/violet */
  --accent:      #6366f1;
  --accent-hi:   #818cf8;
  --accent-lo:   rgba(99,102,241,0.13);
  --accent-glow: rgba(99,102,241,0.25);
  --accent2:     #a855f7;
  --accent2-glow:rgba(168,85,247,0.20);

  /* Semantic */
  --danger:      #ef4444;
  --danger-lo:   rgba(239,68,68,0.15);

  /* User bubble */
  --user-bg:     #13132a;
  --user-border: rgba(99,102,241,0.28);

  /* Code */
  --code-bg:     #0d0d18;

  /* Misc */
  --focus:       rgba(99,102,241,0.35);
  --overlay:     rgba(0,0,0,0.72);
  --shadow-md:   0 4px 24px rgba(0,0,0,0.6);
  --shadow-lg:   0 16px 56px rgba(0,0,0,0.7);
  --glow-accent: 0 0 24px rgba(99,102,241,0.18);

  /* Layout */
  --sidebar-w:   262px;
  --content-w:   720px;  /* base: sobrescrito en breakpoints grandes */

  /* Radii */
  --r-sm:  6px;
  --r-md:  10px;
  --r-lg:  14px;
  --r-xl:  18px;
  --r-2xl: 24px;
}

[data-theme="light"] {
  --bg:          #f7f7f8;
  --bg-sidebar:  #efefef;
  --bg-surface:  #ffffff;
  --bg-raised:   #f9f9f9;
  --bg-hover:    rgba(0,0,0,0.04);
  --bg-active:   rgba(0,0,0,0.07);
  --border:      rgba(0,0,0,0.07);
  --border-med:  rgba(0,0,0,0.11);
  --border-hi:   rgba(0,0,0,0.18);
  --fg:          #18181b;
  --fg-2:        #52525b;
  --fg-3:        #a1a1aa;
  --accent:      #4f46e5;
  --accent-hi:   #6366f1;
  --accent-lo:   rgba(99,102,241,0.10);
  --user-bg:     #eef0fd;
  --user-border: rgba(99,102,241,0.22);
  --code-bg:     #f3f3f4;
  --overlay:     rgba(0,0,0,0.35);
  --shadow-md:   0 4px 24px rgba(0,0,0,0.10);
  --shadow-lg:   0 16px 56px rgba(0,0,0,0.15);
  --glow-accent: 0 0 24px rgba(99,102,241,0.08);
  --accent2:     #7c3aed;
  --accent2-glow:rgba(124,58,237,0.10);
  --user-bg:     #eef0fd;
  --code-bg:     #f3f3f4;
}

/* ═══════════════════════════════════════════════
   APP FADE-IN
═══════════════════════════════════════════════ */

@keyframes app-fadein {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.sidebar { animation: app-fadein 0.35s cubic-bezier(0.22,1,0.36,1) both; }
.main    { animation: app-fadein 0.40s cubic-bezier(0.22,1,0.36,1) 0.05s both; }

/* ═══════════════════════════════════════════════
   SIDEBAR COLAPSABLE (desktop)
═══════════════════════════════════════════════ */

/* Sidebar transition suave en ancho */
.sidebar {
  transition: transform 0.22s ease, width 0.24s cubic-bezier(0.4,0,0.2,1);
}

/* Botón contraer: solo visible en desktop */
.sidebar-collapse-btn { display: none; }
@media (min-width: 861px) {
  .sidebar-collapse-btn { display: grid; }
}

/* Estado colapsado */
body.sidebar-collapsed .sidebar {
  width: 60px;
}

/* Ocultar texto en estado colapsado */
body.sidebar-collapsed .brand-name,
body.sidebar-collapsed .chat-empty,
body.sidebar-collapsed .chat-actions,
body.sidebar-collapsed .user-name {
  display: none;
}

/* Header: centrar logo y botones en columna cuando está colapsado */
body.sidebar-collapsed .sidebar-header {
  flex-direction: column;
  align-items: center;
  padding: 12px 6px 8px;
  gap: 6px;
}

/* Brand: en columna, no crece en altura (evita que empuje botones fuera) */
body.sidebar-collapsed .brand {
  flex: none;
  justify-content: center;
}

/* Chat list: items como chips centrados */
body.sidebar-collapsed .chat-list {
  padding: 4px 6px;
  align-items: center;
}

body.sidebar-collapsed .chat-row {
  grid-template-columns: 1fr;
  width: 100%;
}

body.sidebar-collapsed .chat-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  width: 40px;
  height: 40px;
  border-radius: var(--r-lg);
  margin: 0 auto;
  font-size: 0;           /* oculta el texto */
  color: transparent;
}

/* Muestra la inicial de la conversación vía data-initial */
body.sidebar-collapsed .chat-btn::after {
  content: attr(data-initial);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--fg-3);
  transition: color 0.12s;
}

body.sidebar-collapsed .chat-btn:hover::after,
body.sidebar-collapsed .chat-btn.active::after {
  color: var(--fg);
}

body.sidebar-collapsed .chat-btn.active {
  background: linear-gradient(135deg, rgba(99,102,241,0.20), rgba(168,85,247,0.12));
}

/* Barra activa: ajustar posición en collapsed */
body.sidebar-collapsed .chat-btn.active::before {
  left: 50%;
  transform: translate(-50%, -50%);
  top: auto;
  bottom: 4px;
  width: 16px;
  height: 3px;
  border-radius: 999px;
}

/* Footer: centrar avatar y logout */
body.sidebar-collapsed .sidebar-footer {
  align-items: center;
}

body.sidebar-collapsed .user-row {
  flex-direction: column;
  gap: 4px;
  padding: 4px 0;
}

/* Rotar icono del botón collapse cuando está colapsado */
body.sidebar-collapsed #collapseBtn svg {
  transform: rotate(180deg);
}
#collapseBtn svg { transition: transform 0.24s cubic-bezier(0.4,0,0.2,1); }

/* Tooltip nativo (title) reforzado: ya lo gestiona el browser,
   pero añadimos cursor pointer para indicar que es interactivo */
body.sidebar-collapsed .chat-btn { cursor: pointer; }

/* ── Overrides de fondo y efectos para tema claro ── */
[data-theme="light"] body {
  background-image:
    radial-gradient(ellipse 80% 60% at 20% 0%,   rgba(99,102,241,0.04) 0%, transparent 60%),
    radial-gradient(ellipse 60% 50% at 80% 100%,  rgba(124,58,237,0.03) 0%, transparent 60%);
}

[data-theme="light"] .sidebar {
  background: linear-gradient(180deg, #ebebeb 0%, #f0f0f0 100%);
  border-right: 1px solid rgba(99,102,241,0.10);
  box-shadow: 4px 0 24px rgba(0,0,0,0.07);
}

[data-theme="light"] .composer-form {
  background: rgba(255,255,255,0.90);
  border-color: rgba(99,102,241,0.20);
  box-shadow: 0 4px 24px rgba(0,0,0,0.08), inset 0 1px 0 rgba(255,255,255,0.9);
}

[data-theme="light"] .composer-form:focus-within {
  border-color: rgba(99,102,241,0.45);
  box-shadow: 0 4px 24px rgba(0,0,0,0.08), 0 0 0 3px rgba(99,102,241,0.10);
}

[data-theme="light"] .msg-bubble {
  background: linear-gradient(135deg, #eceeff 0%, #eef0fd 100%);
  box-shadow: 0 2px 12px rgba(99,102,241,0.07);
}

[data-theme="light"] .msg-avatar {
  box-shadow: 0 0 0 1px rgba(99,102,241,0.20), 0 0 8px rgba(99,102,241,0.08);
}

[data-theme="light"] .chat-btn.active {
  background: linear-gradient(90deg, rgba(99,102,241,0.10), rgba(99,102,241,0.03));
  box-shadow: inset 0 0 0 1px rgba(99,102,241,0.14);
}

[data-theme="light"] .suggestion {
  background: rgba(255,255,255,0.80);
  backdrop-filter: blur(10px);
}

[data-theme="light"] .suggestion:hover {
  background: rgba(255,255,255,0.95);
  border-color: rgba(99,102,241,0.30);
  box-shadow: 0 8px 24px rgba(0,0,0,0.08), 0 0 0 1px rgba(99,102,241,0.12);
}

[data-theme="light"] .auth-screen {
  background-image:
    radial-gradient(ellipse 70% 60% at 50% 0%,   rgba(99,102,241,0.06) 0%, transparent 65%),
    radial-gradient(ellipse 50% 40% at 80% 100%,  rgba(124,58,237,0.04) 0%, transparent 60%);
}

[data-theme="light"] .auth-card {
  background: rgba(255,255,255,0.88);
  border-color: rgba(99,102,241,0.18);
  box-shadow: 0 24px 80px rgba(0,0,0,0.12), 0 0 0 1px rgba(99,102,241,0.06);
}

[data-theme="light"] .message + .message {
  border-top: 1px solid rgba(99,102,241,0.06);
}

/* ═══════════════════════════════════════════════
   RESET
═══════════════════════════════════════════════ */

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  /* Evita que iOS reescale el texto al rotar la pantalla */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  font-family: 'Space Grotesk', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  font-feature-settings: 'ss01', 'ss02';
  letter-spacing: -0.02em;
  line-height: 1.6;
  background: var(--bg);
  color: var(--fg);
  /* Mesh gradient animado de fondo */
  background-image:
    radial-gradient(ellipse 80% 60% at 20% 0%,   rgba(99,102,241,0.07) 0%, transparent 60%),
    radial-gradient(ellipse 60% 50% at 80% 100%,  rgba(168,85,247,0.05) 0%, transparent 60%);
  background-attachment: fixed;
  display: flex;
  transition: background 0.2s, color 0.2s;
}

button, textarea, input, select { font: inherit; }
button { cursor: pointer; border: none; background: none; }
button:disabled { cursor: not-allowed; opacity: 0.4; }

button:focus-visible,
textarea:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--focus);
  border-radius: var(--r-md);
}

/* ═══════════════════════════════════════════════
   SCROLLBARS
═══════════════════════════════════════════════ */

::-webkit-scrollbar          { width: 5px; height: 5px; }
::-webkit-scrollbar-track    { background: transparent; }
::-webkit-scrollbar-thumb    { background: rgba(99,102,241,0.25); border-radius: 999px; transition: background 0.2s; }
::-webkit-scrollbar-thumb:hover { background: rgba(99,102,241,0.5); }
*                            { scrollbar-width: thin; scrollbar-color: rgba(99,102,241,0.25) transparent; }

/* ═══════════════════════════════════════════════
   GENERIC ICON BUTTON
═══════════════════════════════════════════════ */

.btn-icon {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  color: var(--fg-2);
  border-radius: var(--r-md);
  flex-shrink: 0;
  transition: background 0.12s, color 0.12s;
}

.btn-icon:hover { background: var(--bg-hover); color: var(--fg); }

/* New chat CTA button */
#newChatBtn {
  background: linear-gradient(135deg, rgba(99,102,241,0.16), rgba(168,85,247,0.10));
  border: 1px solid rgba(99,102,241,0.28);
  color: var(--accent-hi);
  box-shadow: 0 0 10px rgba(99,102,241,0.15);
  transition: background 0.15s, box-shadow 0.15s, transform 0.12s, color 0.12s;
}

#newChatBtn:hover {
  background: linear-gradient(135deg, rgba(99,102,241,0.28), rgba(168,85,247,0.18));
  border-color: rgba(99,102,241,0.50);
  color: #fff;
  box-shadow: 0 0 18px rgba(99,102,241,0.30);
  transform: scale(1.06);
}

[data-theme="light"] #newChatBtn {
  background: rgba(99,102,241,0.09);
  border-color: rgba(99,102,241,0.22);
  box-shadow: none;
}

[data-theme="light"] #newChatBtn:hover {
  background: rgba(99,102,241,0.16);
  box-shadow: 0 0 10px rgba(99,102,241,0.12);
}

/* ═══════════════════════════════════════════════
   SIDEBAR
═══════════════════════════════════════════════ */

.sidebar {
  width: var(--sidebar-w);
  height: 100dvh;
  background: linear-gradient(180deg, var(--bg-sidebar) 0%, rgba(10,10,20,0.97) 100%);
  border-right: 1px solid rgba(99,102,241,0.12);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  z-index: 30;
  overflow: hidden;
  transition: transform 0.22s ease;
  box-shadow: 4px 0 32px rgba(0,0,0,0.4);
}

/* Header */
.sidebar-header {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 14px 12px 10px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  flex: 1;      /* empuja los botones a la derecha */
  min-width: 0; /* permite que el texto del nombre se trunque si es necesario */
}

.brand-mark {
  width: 27px;
  height: 27px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
}

.brand-name {
  font-size: 0.94rem;
  font-weight: 700;
  letter-spacing: -0.025em;
  background: linear-gradient(120deg, var(--fg) 40%, var(--accent-hi) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

[data-theme="light"] .brand-name {
  background: linear-gradient(120deg, #18181b 40%, var(--accent) 100%);
  -webkit-background-clip: text;
  background-clip: text;
}

/* Chat list */
.chat-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 4px 8px;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.chat-empty {
  padding: 16px 10px;
  font-size: 0.8rem;
  color: var(--fg-3);
  text-align: center;
}

.chat-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  border-radius: var(--r-lg);
  gap: 2px;
}

.chat-btn {
  background: transparent;
  color: var(--fg-2);
  text-align: left;
  padding: 9px 10px;
  border-radius: var(--r-lg);
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.855rem;
  position: relative;
  transition: background 0.12s, color 0.12s;
}

.chat-btn:hover,
.chat-row:focus-within .chat-btn { background: var(--bg-hover); color: var(--fg); }

.chat-btn.active {
  background: linear-gradient(90deg, rgba(99,102,241,0.15), rgba(99,102,241,0.05));
  color: var(--fg);
  box-shadow: inset 0 0 0 1px rgba(99,102,241,0.18);
}

.chat-btn.active::before {
  content: '';
  position: absolute;
  left: 2px;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 16px;
  background: linear-gradient(180deg, var(--accent-hi), var(--accent2));
  border-radius: 999px;
  box-shadow: 0 0 8px var(--accent-glow);
}

.chat-actions {
  display: flex;
  gap: 2px;
  padding-right: 4px;
  opacity: 0;
  transition: opacity 0.12s;
}

.chat-row:hover  .chat-actions,
.chat-row:focus-within .chat-actions { opacity: 1; }

.chat-action {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  color: var(--fg-3);
  border-radius: var(--r-sm);
  transition: background 0.12s, color 0.12s;
}

.chat-action:hover { background: var(--bg-hover); color: var(--fg-2); }

/* Sidebar footer */
.sidebar-footer {
  display: flex;
  flex-direction: column;
  padding: 8px;
  border-top: 1px solid transparent;
  background-image: linear-gradient(var(--bg-sidebar), var(--bg-sidebar)),
                    linear-gradient(90deg, transparent, rgba(99,102,241,0.25), transparent);
  background-origin: border-box;
  background-clip: padding-box, border-box;
  gap: 2px;
}

[data-theme="light"] .sidebar-footer {
  background-image: linear-gradient(var(--bg-sidebar), var(--bg-sidebar)),
                    linear-gradient(90deg, transparent, rgba(99,102,241,0.18), transparent);
}

/* Model selector — ahora en el topbar */
.topbar-model {
  position: relative;
  flex-shrink: 0;
}

.model-selector {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: var(--r-lg);
  border: 1px solid var(--border-med);
  background: var(--bg-raised);
  color: var(--fg-2);
  transition: background 0.12s, color 0.12s, border-color 0.12s;
  font-size: 0.78rem;
  max-width: 180px;
}

.model-selector:hover {
  background: var(--bg-hover);
  color: var(--fg);
  border-color: var(--border-hi);
}

.model-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
  text-align: left;
}

.chevron { flex-shrink: 0; transition: transform 0.15s; }
.model-selector[aria-expanded="true"] .chevron { transform: rotate(180deg); }

/* Model dropdown — ahora abre hacia abajo desde el topbar */
.model-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  left: auto;
  min-width: 200px;
  background: var(--bg-surface);
  border: 1px solid var(--border-med);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-md);
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  z-index: 50;
  max-height: 260px;
  overflow-y: auto;
}

.model-option {
  padding: 8px 10px;
  border-radius: var(--r-md);
  text-align: left;
  font-size: 0.84rem;
  color: var(--fg-2);
  transition: background 0.1s, color 0.1s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.model-option:hover   { background: var(--bg-hover); color: var(--fg); }
.model-option.active  { color: var(--accent-hi); background: var(--accent-lo); }

/* Mobile backdrop */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--overlay);
  z-index: 20;
  border: none;
}

/* ═══════════════════════════════════════════════
   MAIN
═══════════════════════════════════════════════ */

.main {
  flex: 1;
  min-width: 0;
  height: 100dvh;
  display: grid;
  grid-template-rows: 52px 1fr auto;
  overflow: hidden;
  position: relative;
}

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  gap: 10px;
  border-bottom: 1px solid var(--border);
  background: rgba(8,8,15,0.65);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  position: sticky;
  top: 0;
  z-index: 10;
}

[data-theme="light"] .topbar {
  background: rgba(247,247,248,0.72);
  border-bottom-color: rgba(0,0,0,0.06);
}

.topbar-title {
  flex: 1;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--fg-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Theme picker ─────────────────────────────── */

.theme-picker { position: relative; }

.theme-icon { display: none; }
[data-theme-mode="system"] .theme-icon--system { display: block; }
[data-theme-mode="light"]  .theme-icon--light  { display: block; }
[data-theme-mode="dark"]   .theme-icon--dark   { display: block; }

.theme-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 140px;
  background: var(--bg-surface);
  border: 1px solid var(--border-med);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-md);
  padding: 5px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  z-index: 50;
}

.theme-opt {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 10px;
  border-radius: var(--r-md);
  color: var(--fg-2);
  font-size: 0.84rem;
  text-align: left;
  transition: background 0.1s, color 0.1s;
}

.theme-opt:hover   { background: var(--bg-hover); color: var(--fg); }
.theme-opt.active  { color: var(--accent-hi); background: var(--accent-lo); }

.mobile-menu-btn { display: none; }

/* ═══════════════════════════════════════════════
   MESSAGES
═══════════════════════════════════════════════ */

.messages-wrap {
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0 16px 32px;
  overscroll-behavior: contain;
}

/* Welcome */
.welcome {
  min-height: calc(100dvh - 240px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  max-width: var(--content-w);
  margin: 0 auto;
  text-align: center;
}

.welcome-icon {
  width: 72px;
  height: 72px;
  border-radius: 22px;
  background: linear-gradient(135deg, rgba(99,102,241,0.15), rgba(168,85,247,0.10));
  border: 1px solid rgba(99,102,241,0.30);
  display: grid;
  place-items: center;
  color: var(--accent-hi);
  animation: breathe 3.8s ease-in-out infinite;
}

.welcome-icon img { width: 48px; height: 48px; object-fit: contain; }

@keyframes breathe {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(99,102,241,0.3), 0 0 32px rgba(99,102,241,0.08);
  }
  50% {
    box-shadow: 0 0 0 12px rgba(99,102,241,0), 0 0 48px rgba(99,102,241,0.18);
  }
}

.welcome-title {
  margin: 0;
  font-size: clamp(1.6rem, 3vw, 2.2rem);
  font-weight: 700;
  letter-spacing: -0.04em;
  background: linear-gradient(120deg, var(--fg) 30%, var(--accent-hi) 65%, var(--accent2) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.welcome-sub {
  margin: -6px 0 0;
  font-size: 0.82rem;
  color: var(--fg-3);
}

.welcome-sub span {
  color: var(--fg-2);
  font-weight: 500;
}

/* Suggestions */
.suggestions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  width: 100%;
  max-width: 580px;
}

.suggestion {
  display: flex;
  flex-direction: column;
  gap: 3px;
  text-align: left;
  padding: 13px 14px;
  background: rgba(19,19,31,0.7);
  border: 1px solid rgba(255,255,255,0.07);
  border-radius: var(--r-lg);
  color: var(--fg);
  transition: background 0.18s, border-color 0.18s, transform 0.18s, box-shadow 0.18s;
  backdrop-filter: blur(10px);
}

.suggestion:hover {
  background: rgba(26,26,40,0.9);
  border-color: rgba(99,102,241,0.35);
  transform: translateY(-3px);
  box-shadow: 0 8px 32px rgba(0,0,0,0.4), 0 0 0 1px rgba(99,102,241,0.15), 0 0 20px rgba(99,102,241,0.08);
}

.suggestion-title { font-size: 0.87rem; font-weight: 600; }
.suggestion-desc  { font-size: 0.77rem; color: var(--fg-2); line-height: 1.4; }

/* Thread */
.thread {
  width: 100%;
  max-width: var(--content-w);
  margin: 0 auto;
  padding-top: 12px;
}

/* Message entrance — sólo opacity, sin translateY para evitar que iOS Safari
   reajuste el viewport al detectar contenido fuera de límites durante la animación */
@keyframes msg-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.message {
  padding: 20px 0;
  animation: msg-in 0.25s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

/* Mensajes cargados del historial: nunca animan (evita el flash masivo
   al cargar una conversación y el reajuste de viewport en móvil) */
.message--static { animation: none; }

.message + .message {
  border-top: 1px solid rgba(99,102,241,0.07);
}

/* User message */
.message--user {
  display: flex;
  justify-content: flex-end;
}

.msg-user-wrap {
  max-width: 78%;
}

.msg-bubble {
  padding: 11px 15px;
  background: linear-gradient(135deg, #16163a 0%, #13132a 100%);
  border: 1px solid var(--user-border);
  border-radius: var(--r-xl) var(--r-xl) var(--r-sm) var(--r-xl);
  font-size: 0.935rem;
  line-height: 1.62;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--fg);
  box-shadow: 0 2px 16px rgba(99,102,241,0.10), inset 0 1px 0 rgba(255,255,255,0.04);
}

/* Assistant message */
.message--assistant {
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 13px;
  align-items: start;
}

.msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
  margin-top: 2px;
  box-shadow: 0 0 0 1px rgba(99,102,241,0.25), 0 0 12px rgba(99,102,241,0.15);
}

.msg-content { min-width: 0; }

/* Markdown body */
.msg-body {
  font-size: 0.935rem;
  line-height: 1.74;
  color: var(--fg);
  min-width: 0;
  word-break: break-word;
}

.msg-body p              { margin: 0 0 12px; }
.msg-body p:last-child   { margin-bottom: 0; }

.msg-body h1, .msg-body h2, .msg-body h3 {
  margin: 22px 0 8px;
  letter-spacing: -0.02em;
  line-height: 1.3;
}
.msg-body h1:first-child,
.msg-body h2:first-child,
.msg-body h3:first-child { margin-top: 0; }
.msg-body h1 { font-size: 1.14rem; }
.msg-body h2 {
  font-size: 1.05rem;
  padding-left: 10px;
  border-left: 2px solid var(--accent);
}
.msg-body h3 {
  font-size: 0.97rem;
  padding-left: 10px;
  border-left: 2px solid rgba(99,102,241,0.45);
}

.msg-body ul, .msg-body ol { margin: 0 0 12px; padding-left: 22px; }
.msg-body li + li { margin-top: 5px; }

.msg-body strong { font-weight: 600; }
.msg-body em     { font-style: italic; }

.msg-body a {
  color: var(--accent-hi);
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-color: rgba(129,140,248,0.4);
}
.msg-body a:hover { text-decoration-color: var(--accent-hi); }

.msg-body blockquote {
  border-left: 3px solid var(--accent);
  padding: 4px 0 4px 16px;
  margin: 14px 0;
  color: var(--fg-2);
  background: rgba(99,102,241,0.04);
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
}

[data-theme="light"] .msg-body blockquote {
  background: rgba(99,102,241,0.05);
}

/* ── Tablas markdown ──────────────────────────────── */
.msg-body .table-wrapper {
  width: 100%;
  overflow-x: auto;
  display: block;
  margin: 14px 0;
}
.msg-body table {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
  line-height: 1.5;
}
.msg-body thead {
  background: var(--bg-raised);
}
.msg-body th {
  padding: 8px 14px;
  text-align: left;
  font-weight: 600;
  font-size: 0.82rem;
  color: var(--fg);
  border-bottom: 2px solid var(--border-hi);
  white-space: normal;
  min-width: 80px;
}
.msg-body td {
  padding: 7px 14px;
  border-bottom: 1px solid var(--border-med);
  color: var(--fg-2);
  vertical-align: top;
  min-width: 80px;
}
.msg-body tr:last-child td {
  border-bottom: none;
}
.msg-body tbody tr:hover {
  background: var(--bg-raised);
}
.msg-body tr:nth-child(even) {
  background: var(--bg-surface);
}

.artifact-card {
  margin-top: 14px;
  padding: 14px 15px;
  border: 1px solid var(--border-med);
  border-radius: var(--r-lg);
  background: linear-gradient(180deg, var(--bg-surface), var(--bg-raised));
  box-shadow: var(--shadow-md);
}

.artifact-title {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--fg);
}

.artifact-copy {
  margin: 8px 0 0;
  font-size: 0.84rem;
  line-height: 1.55;
  color: var(--fg-2);
}

.artifact-meta {
  margin-top: 8px;
  font-size: 0.76rem;
  color: var(--fg-3);
}

.artifact-download {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-top: 12px;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid rgba(99,102,241,0.28);
  background: var(--accent-lo);
  color: var(--accent-hi);
  font-size: 0.8rem;
  font-weight: 600;
  text-decoration: none;
}

.artifact-download:hover {
  border-color: var(--accent);
  background: rgba(99,102,241,0.18);
}

/* Images inside messages */
.msg-images {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.msg-image {
  max-width: 320px;
  max-height: 260px;
  width: auto;
  height: auto;
  border-radius: var(--r-lg);
  border: 1px solid var(--border-med);
  object-fit: cover;
  display: block;
  cursor: zoom-in;
  transition: transform 0.22s cubic-bezier(0.22,1,0.36,1), box-shadow 0.22s, border-color 0.22s;
}

.msg-image:hover {
  transform: scale(1.025);
  border-color: rgba(99,102,241,0.40);
  box-shadow: 0 8px 32px rgba(0,0,0,0.4), 0 0 0 1px rgba(99,102,241,0.20);
}

.msg-files {
  display: grid;
  gap: 8px;
  margin-bottom: 10px;
}

.msg-file {
  display: grid;
  grid-template-columns: 44px 1fr;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border-radius: var(--r-md);
  border: 1px solid var(--border-med);
  background: rgba(255,255,255,0.04);
}

.msg-file-ext {
  display: grid;
  place-items: center;
  min-height: 38px;
  border-radius: 12px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--accent-hi);
  background: rgba(99,102,241,0.14);
  border: 1px solid rgba(99,102,241,0.24);
}

.msg-file-meta {
  min-width: 0;
}

.msg-file-meta strong,
.msg-file-meta span {
  display: block;
}

.msg-file-meta strong {
  font-size: 0.9rem;
  color: var(--fg);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.msg-file-meta span {
  margin-top: 2px;
  font-size: 0.76rem;
  color: var(--fg-3);
}

/* Inline code */
.msg-body :not(pre) > code {
  font-family: ui-monospace, 'Cascadia Code', SFMono-Regular, Menlo, monospace;
  font-size: 0.875em;
  background: var(--bg-surface);
  border: 1px solid var(--border-med);
  border-radius: var(--r-sm);
  padding: 1px 5px;
}

/* Code block */
.code-block {
  margin: 14px 0;
  border: 1px solid var(--border-med);
  border-radius: var(--r-lg);
  overflow: hidden;
  background: var(--code-bg);
}

.code-block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-bottom: 1px solid rgba(99,102,241,0.12);
  background: linear-gradient(90deg, rgba(99,102,241,0.08) 0%, rgba(13,13,24,0.9) 60%);
}

.code-block-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}

[data-theme="light"] .code-block-header {
  background: linear-gradient(90deg, rgba(99,102,241,0.07) 0%, rgba(240,240,245,0.8) 60%);
  border-bottom-color: rgba(99,102,241,0.12);
}

.code-lang {
  font-family: ui-monospace, monospace;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--accent-hi);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  background: rgba(99,102,241,0.12);
  border: 1px solid rgba(99,102,241,0.20);
  padding: 2px 7px;
  border-radius: 4px;
}

[data-theme="light"] .code-lang {
  background: rgba(99,102,241,0.08);
  color: var(--accent);
}

.copy-code-btn:hover,
.preview-code-btn:hover {
  color: var(--accent-hi);
  background: rgba(99,102,241,0.10);
}

.preview-code-btn { color: var(--accent-hi); }

.copy-code-btn.is-copied { color: #22c55e; }

.code-block pre {
  margin: 0;
  padding: 14px 16px;
  overflow-x: auto;
  line-height: 1.58;
  background: transparent !important;
}

.code-block pre code {
  font-family: ui-monospace, 'Cascadia Code', SFMono-Regular, Menlo, monospace;
  font-size: 0.865em;
  background: transparent !important;
  border: 0 !important;
  padding: 0 !important;
}

/* Message timestamp */
.msg-time {
  font-size: 0.7rem;
  color: var(--fg-3);
  padding: 4px 3px;
  align-self: center;
  flex-shrink: 0;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  user-select: none;
}

/* Message actions */
.msg-actions {
  display: flex;
  gap: 4px;
  margin-top: 10px;
  opacity: 0;
  transition: opacity 0.14s;
}

.msg-actions--user {
  justify-content: flex-end;
}

.message--assistant:hover .msg-actions { opacity: 1; }
.message--user:hover .msg-actions { opacity: 1; }

.msg-action {
  width: 28px;
  height: 28px;
  display: inline-grid;
  place-items: center;
  color: var(--fg-3);
  border-radius: var(--r-md);
  text-decoration: none;
  transition: color 0.15s, background 0.15s;
  flex-shrink: 0;
}

.msg-action:hover {
  color: var(--accent-hi);
  background: rgba(99,102,241,0.10);
}

.msg-action.is-copied { color: #22c55e; }
.msg-action.is-error  { color: var(--danger); }

/* Botones de copy/preview dentro del header del bloque de código */
.copy-code-btn,
.preview-code-btn {
  width: 26px;
  height: 26px;
  display: inline-grid;
  place-items: center;
  color: var(--fg-3);
  border-radius: var(--r-sm);
  transition: color 0.12s, background 0.12s;
}

/* Streaming text — texto plano mientras llegan tokens, antes del render markdown final */
.streaming-text {
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--fg);
}

/* Thinking indicator (3 pulsing dots while waiting for the full response) */
.thinking-dots {
  display: inline-flex;
  gap: 5px;
  align-items: center;
  padding: 6px 0;
}

.thinking-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  animation: thinking-wave 1.4s ease-in-out infinite;
  box-shadow: 0 0 6px rgba(99,102,241,0.5);
}

.thinking-dots span:nth-child(1) { animation-delay: 0s; }
.thinking-dots span:nth-child(2) { animation-delay: 0.18s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.36s; }

@keyframes thinking-wave {
  0%, 60%, 100% { opacity: 0.3; transform: scale(0.8); box-shadow: 0 0 4px rgba(99,102,241,0.3); }
  30%            { opacity: 1;   transform: scale(1);   box-shadow: 0 0 10px rgba(99,102,241,0.6); }
}

/* Thinking line — single subtle gray blinking line while model reasons */
.thinking-line {
  display: block;
  color: var(--fg-3);
  font-size: 0.85em;
  font-style: italic;
  animation: thinking-blink 1.2s ease-in-out infinite;
}

@keyframes thinking-blink {
  0%, 100% { opacity: 0.3; }
  50%       { opacity: 0.9; }
}

.searching-line {
  font-style: normal;
  color: var(--accent-hi);
  animation: searching-pulse 1.8s ease-in-out infinite;
}

@keyframes searching-pulse {
  0%, 100% { opacity: 0.6; }
  50%       { opacity: 1; }
}

/* ═══════════════════════════════════════════════
   COMPOSER
═══════════════════════════════════════════════ */

.composer-wrap {
  padding: 0 16px 18px;
  background: linear-gradient(to top, var(--bg) 65%, transparent);
  position: sticky;
  bottom: 0;
  z-index: 5;
}

.composer {
  max-width: var(--content-w);
  margin: 0 auto;
}

.composer-form {
  display: flex;
  flex-wrap: nowrap;
  align-items: flex-end;
  gap: 6px;
  background: rgba(19,19,31,0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(99,102,241,0.18);
  border-radius: var(--r-2xl);
  padding: 8px;
  transition: border-color 0.2s, box-shadow 0.2s;
  margin: 0;
  box-shadow: 0 4px 32px rgba(0,0,0,0.5), inset 0 1px 0 rgba(255,255,255,0.04);
}

/* Composer action buttons (attach, mic) */
.composer-btn {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  color: var(--fg-3);
  border-radius: 50%;
  flex-shrink: 0;
  transition: background 0.12s, color 0.12s;
}

.composer-btn:hover:not(:disabled) {
  background: var(--bg-hover);
  color: var(--fg-2);
}

/* Mic recording state */
.composer-btn .mic-stop-icon { display: none; }
.composer-btn.is-recording .mic-icon      { display: none; }
.composer-btn.is-recording .mic-stop-icon { display: block; }
.composer-btn.is-recording {
  color: #fff;
  background: var(--danger);
  animation: mic-pulse 1.4s ease-out infinite;
}

@keyframes mic-pulse {
  0%   { box-shadow: 0 0 0 0   rgba(239,68,68,0.5); }
  70%  { box-shadow: 0 0 0 8px rgba(239,68,68,0); }
  100% { box-shadow: 0 0 0 0   rgba(239,68,68,0); }
}

/* Image generation button — active state */
.composer-btn.is-img-mode {
  color: var(--accent2);
  background: var(--accent2-glow);
  animation: img-pulse 2s ease-out infinite;
}
.composer-btn.is-img-mode:hover:not(:disabled) {
  background: color-mix(in srgb, var(--accent2) 22%, transparent);
}
@keyframes img-pulse {
  0%   { box-shadow: 0 0 0 0   rgba(168,85,247,0.45); }
  70%  { box-shadow: 0 0 0 7px rgba(168,85,247,0); }
  100% { box-shadow: 0 0 0 0   rgba(168,85,247,0); }
}

/* PDF artifact card */
.pdf-artifact-card {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  padding: 11px 14px;
  background: linear-gradient(135deg, rgba(239,68,68,0.07), rgba(239,68,68,0.03));
  border: 1px solid rgba(239,68,68,0.22);
  border-radius: var(--r-lg);
  color: var(--fg-2);
  font-size: 0.84rem;
}

.pdf-artifact-card svg { color: #ef4444; flex-shrink: 0; }
.pdf-artifact-card span { flex: 1; min-width: 0; }

.pdf-artifact-dl {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px;
  border-radius: 999px;
  background: rgba(239,68,68,0.12);
  border: 1px solid rgba(239,68,68,0.28);
  color: #ef4444;
  font-size: 0.8rem;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background 0.15s, border-color 0.15s;
}

.pdf-artifact-dl:hover {
  background: rgba(239,68,68,0.20);
  border-color: rgba(239,68,68,0.50);
}

[data-theme="light"] .pdf-artifact-card {
  background: rgba(239,68,68,0.05);
  border-color: rgba(239,68,68,0.18);
}

/* Generated image in thread */
.gen-image-wrap { margin-top: 4px; }
.gen-image-wrap img {
  max-width: 100%;
  max-height: 520px;
  border-radius: var(--r-lg);
  display: block;
  cursor: zoom-in;
  border: 1px solid var(--border-med);
}
.gen-image-caption {
  font-size: 0.78rem;
  color: var(--fg-3);
  margin-top: 7px;
  font-style: italic;
  line-height: 1.45;
}
/* Attachment strip */
.attachment-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 6px 2px;
}

.attachment-thumb {
  position: relative;
  width: 72px;
  height: 72px;
  border-radius: var(--r-md);
  overflow: hidden;
  border: 1px solid var(--border-med);
  background: var(--bg-raised);
  flex-shrink: 0;
}

.attachment-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.attachment-doc {
  position: relative;
  width: min(210px, 100%);
  min-height: 72px;
  padding: 10px 34px 10px 12px;
  border-radius: var(--r-md);
  border: 1px solid var(--border-med);
  background: var(--bg-raised);
  flex-shrink: 0;
}

.attachment-doc-ext {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 48px;
  height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  background: rgba(99,102,241,0.14);
  border: 1px solid rgba(99,102,241,0.22);
  color: var(--accent-hi);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.attachment-doc-name {
  margin-top: 8px;
  color: var(--fg);
  font-size: 0.86rem;
  font-weight: 600;
  line-height: 1.35;
  word-break: break-word;
}

.attachment-doc-meta {
  margin-top: 4px;
  color: var(--fg-3);
  font-size: 0.74rem;
  line-height: 1.35;
}

.attachment-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: rgba(0,0,0,0.65);
  color: #fff;
  font-size: 13px;
  line-height: 1;
  display: grid;
  place-items: center;
  transition: background 0.12s;
}

.attachment-remove:hover { background: rgba(0,0,0,0.85); }

.composer-form:focus-within {
  border-color: rgba(99,102,241,0.55);
  box-shadow: 0 4px 32px rgba(0,0,0,0.5), 0 0 0 3px rgba(99,102,241,0.12), 0 0 24px rgba(99,102,241,0.10);
}

/* Drag & drop over composer */
.composer.dragover .composer-form {
  border-color: rgba(99,102,241,0.6);
  box-shadow: 0 0 0 4px rgba(99,102,241,0.12);
}

.composer-input {
  background: transparent;
  border: none;
  resize: none;
  color: var(--fg);
  font-size: 0.94rem;
  line-height: 1.52;
  padding: 7px 4px 7px;
  outline: none;
  flex: 1;
  min-width: 0;
  min-height: 36px;
  max-height: 200px;
}

.composer-input::placeholder { color: var(--fg-3); }
.composer-input:read-only    { opacity: 0.7; }

.send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent2) 100%);
  color: #fff;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  transition: opacity 0.14s, transform 0.14s, box-shadow 0.14s;
  box-shadow: 0 0 16px rgba(99,102,241,0.35);
}

.send-btn:hover:not(:disabled) {
  transform: scale(1.08);
  box-shadow: 0 0 24px rgba(99,102,241,0.55), 0 0 8px rgba(168,85,247,0.3);
}
.send-btn:disabled { opacity: 0.28; transform: none; box-shadow: none; }

/* Stop state */
.send-btn .icon-stop        { display: none; }
.send-btn.is-stop .icon-send { display: none; }
.send-btn.is-stop .icon-stop { display: block; }
.send-btn.is-stop            { background: var(--danger); }
.send-btn.is-stop:hover:not(:disabled) { background: #dc2626; }

.composer-note {
  max-width: var(--content-w);
  margin: 6px auto 0;
  font-size: 0.7rem;
  color: var(--fg-3);
  text-align: center;
}

/* ═══════════════════════════════════════════════
   USER ROW (sidebar footer)
═══════════════════════════════════════════════ */

.user-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 4px;
}

.user-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: linear-gradient(135deg, rgba(99,102,241,0.18), rgba(168,85,247,0.12));
  border: 1.5px solid transparent;
  background-clip: padding-box;
  box-shadow: 0 0 0 1.5px var(--accent), 0 0 10px rgba(99,102,241,0.25);
  color: var(--accent-hi);
  font-size: 11px;
  font-weight: 700;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  text-transform: uppercase;
}

[data-theme="light"] .user-avatar {
  box-shadow: 0 0 0 1.5px var(--accent), 0 0 6px rgba(99,102,241,0.15);
}

.user-name {
  flex: 1;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--fg-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.admin-link {
  text-decoration: none;
  color: var(--accent-hi);
}

/* ═══════════════════════════════════════════════
   AUTH SCREEN
═══════════════════════════════════════════════ */

.auth-screen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  background-image:
    radial-gradient(ellipse 70% 60% at 50% 0%,   rgba(99,102,241,0.12) 0%, transparent 65%),
    radial-gradient(ellipse 50% 40% at 80% 100%,  rgba(168,85,247,0.08) 0%, transparent 60%);
  display: grid;
  place-items: center;
  z-index: 200;
  padding: 16px;
}

.auth-card {
  width: 100%;
  max-width: 360px;
  background: rgba(19,19,31,0.80);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid rgba(99,102,241,0.22);
  border-radius: var(--r-xl);
  box-shadow: 0 24px 80px rgba(0,0,0,0.7), 0 0 0 1px rgba(99,102,241,0.08), 0 0 60px rgba(99,102,241,0.06);
  padding: 32px 28px 28px;
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: center;
  margin-bottom: 26px;
}

.auth-brand .brand-name {
  font-size: 1.1rem;
}

.auth-tabs {
  display: flex;
  gap: 3px;
  background: var(--bg-raised);
  border-radius: var(--r-md);
  padding: 3px;
  margin-bottom: 22px;
}

.auth-tab {
  flex: 1;
  padding: 8px 6px;
  border-radius: var(--r-sm);
  font-size: 0.855rem;
  font-weight: 500;
  color: var(--fg-2);
  transition: background 0.12s, color 0.12s, box-shadow 0.12s;
}

.auth-tab--active {
  background: var(--bg-surface);
  color: var(--fg);
  box-shadow: 0 1px 4px rgba(0,0,0,0.18);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.auth-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.auth-label {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--fg-2);
}

.auth-input {
  padding: 10px 13px;
  background: var(--bg-raised);
  border: 1px solid var(--border-med);
  border-radius: var(--r-md);
  color: var(--fg);
  font-size: 0.935rem;
  outline: none;
  transition: border-color 0.16s, box-shadow 0.16s;
}

.auth-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.auth-input::placeholder {
  color: var(--fg-3);
}

.auth-error {
  margin: 0;
  font-size: 0.82rem;
  color: var(--danger);
  background: var(--danger-lo);
  border-radius: var(--r-sm);
  padding: 9px 12px;
}

.auth-success {
  margin: 0;
  font-size: 0.82rem;
  color: #22c55e;
  background: rgba(34,197,94,0.13);
  border: 1px solid rgba(34,197,94,0.25);
  border-radius: var(--r-sm);
  padding: 9px 12px;
  line-height: 1.5;
}

.auth-submit {
  padding: 11px;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent2) 100%);
  color: #fff;
  border-radius: var(--r-md);
  font-size: 0.9rem;
  font-weight: 600;
  transition: opacity 0.14s, transform 0.12s, box-shadow 0.14s;
  margin-top: 2px;
  box-shadow: 0 0 18px rgba(99,102,241,0.30);
}

.auth-submit:hover:not(:disabled) {
  opacity: 0.92;
  transform: translateY(-1px);
  box-shadow: 0 4px 24px rgba(99,102,241,0.45), 0 0 8px rgba(168,85,247,0.25);
}

.auth-submit:disabled {
  opacity: 0.55;
  transform: none;
}

/* ═══════════════════════════════════════════════
   SCROLL TO BOTTOM BUTTON
═══════════════════════════════════════════════ */

.scroll-btn {
  position: absolute;
  bottom: 92px;
  right: 24px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, rgba(99,102,241,0.18), rgba(168,85,247,0.12));
  border: 1px solid rgba(99,102,241,0.30);
  color: var(--accent-hi);
  display: grid;
  place-items: center;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4), 0 0 12px rgba(99,102,241,0.20);
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.18s ease, transform 0.18s ease, box-shadow 0.14s;
  pointer-events: none;
  z-index: 10;
}

.scroll-btn:not([hidden]) { display: grid; }

.scroll-btn.visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.scroll-btn:hover {
  box-shadow: 0 4px 20px rgba(0,0,0,0.4), 0 0 20px rgba(99,102,241,0.35);
  border-color: rgba(99,102,241,0.55);
  color: #fff;
}

/* ═══════════════════════════════════════════════
   DELETE CONFIRM POPOVER
═══════════════════════════════════════════════ */

.confirm-popover {
  position: fixed;
  z-index: 200;
  background: var(--bg-surface);
  border: 1px solid var(--border-med);
  border-top: 2px solid var(--danger);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg), 0 0 0 1px rgba(239,68,68,0.08);
  padding: 14px 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 210px;
  animation: confirm-in 0.15s cubic-bezier(0.34,1.56,0.64,1) both;
}

@keyframes confirm-in {
  from { opacity: 0; transform: translateY(-6px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.confirm-popover-header {
  display: flex;
  align-items: center;
  gap: 7px;
}

.confirm-popover-icon {
  color: var(--danger);
  flex-shrink: 0;
}

.confirm-popover-title {
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--fg);
  line-height: 1.3;
}

.confirm-popover-msg {
  margin: 0;
  font-size: 0.79rem;
  color: var(--fg-3);
  line-height: 1.45;
}

.confirm-popover-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
  margin-top: 2px;
}

.confirm-cancel {
  font-size: 0.78rem;
  padding: 5px 13px;
  border: 1px solid var(--border-med);
  border-radius: 999px;
  color: var(--fg-2);
  transition: background 0.12s, color 0.12s;
}

.confirm-cancel:hover { background: var(--bg-hover); color: var(--fg); }

.confirm-delete {
  font-size: 0.78rem;
  font-weight: 600;
  padding: 5px 13px;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  transition: background 0.15s, transform 0.1s;
}

.confirm-delete:hover  { background: #dc2626; }
.confirm-delete:active { transform: scale(0.96); }

/* ═══════════════════════════════════════════════
   MODEL TOAST
═══════════════════════════════════════════════ */

.model-toast {
  position: fixed;
  bottom: 88px;
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  background: var(--bg-surface);
  border: 1px solid var(--border-med);
  color: var(--fg-2);
  font-size: 0.78rem;
  padding: 7px 14px;
  border-radius: 999px;
  box-shadow: var(--shadow-md);
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.18s ease, transform 0.18s ease;
  z-index: 80;
  pointer-events: none;
}

.model-toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ═══════════════════════════════════════════════
   HIGHLIGHT.JS LIGHT THEME FIX
═══════════════════════════════════════════════ */

[data-theme="light"] .hljs { background: transparent; }

/* ═══════════════════════════════════════════════
   TOUCH / MOBILE GLOBALS
═══════════════════════════════════════════════ */

/* Elimina el flash azul al tocar en Android/iOS */
* { -webkit-tap-highlight-color: transparent; }

/* Elimina el retraso de 300ms en taps (botones y enlaces) */
button, a, [role="button"] { touch-action: manipulation; }

/* ═══════════════════════════════════════════════
   RESPONSIVE — Desktop ancho (≥ 1280px)
═══════════════════════════════════════════════ */

@media (min-width: 1280px) {
  :root { --content-w: 900px; }
}

@media (min-width: 1600px) {
  :root { --content-w: 1080px; }
}

/* ═══════════════════════════════════════════════
   RESPONSIVE — Tablet/small desktop (≤ 860px)
═══════════════════════════════════════════════ */

@media (max-width: 860px) {
  /* background-attachment:fixed no funciona en iOS Safari */
  body {
    max-width: 100%;
    overflow-x: hidden;
    background-attachment: scroll;
  }

  /* En móvil el collapse no aplica — sidebar siempre full width */
  body.sidebar-collapsed .sidebar { width: var(--sidebar-w); }
  body.sidebar-collapsed .brand-name,
  body.sidebar-collapsed .chat-empty,
  body.sidebar-collapsed .chat-actions,
  body.sidebar-collapsed .user-name { display: revert; }
  body.sidebar-collapsed .sidebar-header { flex-direction: row; align-items: center; padding: 14px 12px 10px; gap: 4px; }
  body.sidebar-collapsed .brand { flex: 1; justify-content: flex-start; }
  body.sidebar-collapsed .chat-list { padding: 4px 8px; align-items: stretch; }
  body.sidebar-collapsed .chat-row { grid-template-columns: 1fr auto; }
  body.sidebar-collapsed .chat-btn { width: 100%; height: auto; padding: 9px 10px; font-size: 0.855rem; color: var(--fg-2); justify-content: flex-start; }
  body.sidebar-collapsed .chat-btn::after { display: none; }
  body.sidebar-collapsed .chat-btn.active::before { left: 2px; top: 50%; transform: translateY(-50%); bottom: auto; width: 3px; height: 16px; }
  body.sidebar-collapsed .user-row { flex-direction: row; gap: 8px; padding: 7px 4px; }
  body.sidebar-collapsed .sidebar-footer { align-items: stretch; }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
    will-change: transform; /* acelera la transición HW */
    animation: none; /* cancela app-fadein: su fill-mode sobreescribiría translateX(-100%) */
  }

  body.sidebar-open .sidebar          { transform: translateX(0); }
  body.sidebar-open .sidebar-backdrop { display: block; }

  /* Fondo difuminado al abrir sidebar */
  .sidebar-backdrop {
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
  }

  .mobile-menu-btn { display: grid; }
  .sidebar-collapse-btn { display: grid; }

  .main {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
  }

  /* Contener cualquier contenido más ancho que el viewport (código, tablas, URLs largas)
     para que iOS no escale el layout para encajarlo */
  .messages-wrap, .thread { overflow-x: hidden; }
  img, video, iframe, pre, table, .code-block { max-width: 100% !important; }
}

/* ═══════════════════════════════════════════════
   RESPONSIVE — Móvil (≤ 560px)
═══════════════════════════════════════════════ */

@media (max-width: 560px) {
  /* Contenedores principales: sin desbordamiento horizontal */
  .main, .messages-wrap, .composer-wrap, .thread { overflow-x: hidden; }
  /* Elementos que pueden sobresalir: limitados a su contenedor */
  img, video, iframe, pre, table, .code-block { max-width: 100% !important; }

  /* ── Notch / safe areas ── */
  .topbar {
    padding-top: env(safe-area-inset-top);
    height: calc(52px + env(safe-area-inset-top));
  }
  .main {
    grid-template-rows: calc(52px + env(safe-area-inset-top)) 1fr auto;
  }

  /* ── Welcome ── */
  .welcome {
    min-height: calc(100dvh - 220px - env(safe-area-inset-top));
    gap: 14px;
  }
  .welcome-icon { width: 60px; height: 60px; border-radius: 18px; }
  .welcome-icon img { width: 40px; height: 40px; }

  /* ── Sugerencias: 1 columna ── */
  .suggestions {
    grid-template-columns: 1fr;
    max-width: 100%;
    gap: 6px;
  }
  .suggestion { padding: 11px 12px; }

  /* ── Mensajes ── */
  .messages-wrap { padding-inline: 10px; }

  .msg-user-wrap { max-width: 92%; }

  .message--assistant {
    grid-template-columns: 22px 1fr;
    gap: 8px;
  }
  .msg-avatar { width: 22px; height: 22px; }
  .msg-body { font-size: 0.905rem; }

  /* Imágenes adjuntas en mensajes */
  .msg-image { max-width: min(300px, 100%); }

  /* ── Compositor ── */
  .composer-wrap {
    padding-inline: 10px;
    /* safe-area para el home bar de iPhone */
    padding-bottom: max(14px, env(safe-area-inset-bottom));
  }

  .composer-form {
    padding: 7px;
    gap: 4px;
  }

  .composer-btn { width: 32px; height: 32px; }
  .send-btn     { width: 36px; height: 36px; }

  /* ≥16px: evita el auto-zoom de Safari iOS al enfocar inputs */
  .composer-input { font-size: 16px; max-height: 120px; }
  .auth-input     { font-size: 16px; }

  /* Ocultar el aviso inferior en pantallas muy pequeñas */
  .composer-note { display: none; }

  /* ── Auth ── */
  .auth-card {
    padding: 24px 18px 20px;
    border-radius: var(--r-lg);
  }

  /* ── Model selector: ocultar nombre, solo icono + chevron ── */
  .model-name { display: none; }
  .model-selector { max-width: unset; padding: 5px 8px; gap: 4px; }

  /* ── Dropdown: alinear a la derecha para no salirse ── */
  .model-dropdown {
    right: 0;
    left: auto;
    min-width: 180px;
  }

  /* ── Scroll button: respetar safe-area ── */
  .scroll-btn {
    bottom: calc(84px + env(safe-area-inset-bottom));
    right: 16px;
  }

  /* ── Model toast ── */
  .model-toast {
    bottom: calc(80px + env(safe-area-inset-bottom));
  }
}

/* ═══════════════════════════════════════════════
   RESPONSIVE — Móvil muy pequeño (≤ 380px)
═══════════════════════════════════════════════ */

@media (max-width: 380px) {
  .welcome-title { font-size: 1.4rem; }
  .suggestion-desc { display: none; } /* solo mostrar título */
  .topbar-title { font-size: 0.8rem; }
  .composer-btn { width: 28px; height: 28px; }
  .composer-input { font-size: 16px; }
}
