:root {
  --bg:           #ffffff;
  --sidebar-bg:   #f7f7f8;
  --surface:      #f0f0f2;
  --surface-2:    #e8e8ec;
  --border:       rgba(0,0,0,0.08);
  --border-2:     rgba(0,0,0,0.13);
  --text:         #1a1a1a;
  --muted:        #8a8a9a;
  --active-color: #ef4444;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

.hidden { display: none !important; }

/* ── LOGIN ──────────────────────────────────── */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: #f5f5f7;
}

.login-card {
  background: #ffffff;
  border: 1px solid var(--border-2);
  border-radius: 16px;
  padding: 44px 40px;
  width: 320px;
  text-align: center;
  box-shadow: 0 4px 24px rgba(0,0,0,0.08), 0 1px 4px rgba(0,0,0,0.04);
}

.login-logo {
  font-size: 30px;
  font-weight: 800;
  letter-spacing: 10px;
  background: linear-gradient(135deg, #1a1a1a, #555566);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 6px;
}

.login-sub {
  font-size: 10px;
  color: var(--muted);
  letter-spacing: 3px;
  text-transform: uppercase;
  margin-bottom: 36px;
}

#login-form input {
  width: 100%;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: 10px;
  color: var(--text);
  font-size: 14px;
  margin-bottom: 10px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
#login-form input:focus {
  border-color: var(--active-color);
  box-shadow: 0 0 0 3px rgba(239,68,68,0.1);
}

#login-form button {
  width: 100%;
  padding: 12px;
  background: var(--active-color);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  letter-spacing: 1px;
  transition: filter 0.2s, transform 0.1s;
}
#login-form button:hover { filter: brightness(1.07); }
#login-form button:active { transform: scale(0.98); }

.error-msg {
  color: #ef4444;
  font-size: 12px;
  margin-top: 10px;
  min-height: 16px;
}

/* ── APP LAYOUT ─────────────────────────────── */
#app-screen {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* ── HEADER ─────────────────────────────────── */
.app-header {
  height: 54px;
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 16px;
  flex-shrink: 0;
  position: relative;
  z-index: 10;
}

.header-brand {
  font-weight: 800;
  font-size: 13px;
  letter-spacing: 6px;
  color: var(--text);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
  text-decoration: none;
}

.brand-name {
  text-decoration: none;
  color: var(--text);
  letter-spacing: 6px;
  font-weight: 800;
  white-space: nowrap;
}

.billing-link {
  font-size: 9px;
  font-weight: 500;
  letter-spacing: 1.5px;
  color: var(--muted);
  text-decoration: none;
  text-transform: uppercase;
  transition: color 0.2s;
}
.billing-link:hover { color: var(--active-color); }

.agent-tabs {
  display: flex;
  gap: 6px;
  flex: 1;
  justify-content: center;
}

.agent-tab {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 16px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}
.agent-tab:hover { color: var(--text); border-color: var(--border-2); background: var(--surface); }

.agent-tab[data-agent="agente86"].active { border-color: rgba(239,68,68,0.4); color: #ef4444; background: rgba(239,68,68,0.07); }
.agent-tab[data-agent="agente99"].active { border-color: rgba(124,58,237,0.4); color: #7c3aed; background: rgba(124,58,237,0.07); }
.agent-tab[data-agent="jefe"].active     { border-color: rgba(217,119,6,0.4);  color: #d97706; background: rgba(217,119,6,0.07); }

.dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

.header-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
  justify-content: flex-end;
  align-items: center;
}

.header-actions button {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 8px;
  padding: 5px 12px;
  cursor: pointer;
  font-size: 12px;
  transition: all 0.2s;
  white-space: nowrap;
}
.header-actions button:hover { color: var(--text); border-color: var(--border-2); background: var(--surface); }

/* ── BODY ───────────────────────────────────── */
.app-body {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* ── SIDEBAR ────────────────────────────────── */
.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

#sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}
#sidebar-content::-webkit-scrollbar { width: 3px; }
#sidebar-content::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 3px; }

.sidebar-section { margin-bottom: 4px; }

.sidebar-agent-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px 5px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 2.5px;
  text-transform: uppercase;
  color: var(--muted);
  user-select: none;
}
.sidebar-agent-header[data-agent="agente86"] { color: rgba(239,68,68,0.7); }
.sidebar-agent-header[data-agent="agente99"] { color: rgba(124,58,237,0.7); }
.sidebar-agent-header[data-agent="jefe"]     { color: rgba(217,119,6,0.7); }

.conv-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  margin: 1px 6px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  color: var(--muted);
  transition: background 0.15s, color 0.15s;
  position: relative;
  user-select: none;
}
.conv-item:hover { background: var(--surface); color: var(--text); }
.conv-item.active {
  background: var(--surface);
  color: var(--text);
  border-left: 2px solid var(--active-color);
  padding-left: 10px;
}

.drag-handle {
  opacity: 0;
  cursor: grab;
  color: var(--muted);
  font-size: 13px;
  flex-shrink: 0;
  transition: opacity 0.15s;
  line-height: 1;
}
.conv-item:hover .drag-handle { opacity: 1; }
.conv-item.dragging { opacity: 0.4; }
.conv-item.drag-over::before {
  content: '';
  position: absolute;
  left: 6px; right: 6px; top: -1px;
  height: 2px;
  background: var(--active-color);
  border-radius: 1px;
}

.conv-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12.5px;
}

.conv-delete {
  opacity: 0;
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 14px;
  padding: 0 2px;
  line-height: 1;
  flex-shrink: 0;
  transition: opacity 0.15s, color 0.15s;
  border-radius: 4px;
}
.conv-delete:hover { color: #ef4444; }
.conv-item:hover .conv-delete { opacity: 1; }

.conv-rename {
  opacity: 0;
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  padding: 0 2px;
  line-height: 1;
  flex-shrink: 0;
  transition: opacity 0.15s, color 0.15s;
  border-radius: 4px;
}
.conv-rename:hover { color: var(--active-color); }
.conv-item:hover .conv-rename { opacity: 1; }

.conv-rename-input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--active-color);
  border-radius: 5px;
  color: var(--text);
  font-size: 12.5px;
  padding: 2px 6px;
  outline: none;
  box-shadow: 0 0 0 2px rgba(239,68,68,0.12);
  min-width: 0;
}
.conv-item.editing { cursor: default; }

.conv-cost {
  font-size: 10px;
  color: var(--muted);
  flex-shrink: 0;
  opacity: 0.65;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0;
}

.agent-total-cost {
  margin-left: auto;
  font-size: 9.5px;
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
  opacity: 0.65;
  font-variant-numeric: tabular-nums;
}

.sidebar-footer {
  flex-shrink: 0;
  padding: 10px 8px;
  border-top: 1px solid var(--border);
}

#new-conv-btn {
  width: 100%;
  padding: 9px;
  background: transparent;
  border: 1px dashed var(--border-2);
  border-radius: 8px;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
}
#new-conv-btn:hover {
  color: var(--text);
  border-color: var(--active-color);
  background: var(--surface);
}

/* ── CHAT MAIN ──────────────────────────────── */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  background: var(--bg);
}

/* ── DROP OVERLAY ───────────────────────────── */
#drop-overlay {
  position: absolute;
  inset: 0;
  z-index: 50;
  background: rgba(255,255,255,0.88);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px dashed var(--active-color);
  pointer-events: none;
}
.drop-box {
  text-align: center;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.drop-icon { font-size: 48px; }

/* ── CHAT MESSAGES ──────────────────────────── */
#chat-container {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px 16px;
  scroll-behavior: smooth;
}
#chat-container::-webkit-scrollbar { width: 4px; }
#chat-container::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 4px; }

#messages-list {
  max-width: 800px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.empty-state {
  text-align: center;
  padding: 80px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.empty-state .empty-agent {
  width: 52px; height: 52px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 800;
  margin-bottom: 8px;
}
.empty-state .empty-title { font-size: 16px; font-weight: 600; color: var(--text); }
.empty-state .empty-hint  { font-size: 13px; color: var(--muted); }

/* Messages */
.message {
  display: flex;
  gap: 10px;
  max-width: 85%;
}
.message.user      { align-self: flex-end; flex-direction: row-reverse; }
.message.assistant { align-self: flex-start; }

.msg-avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700;
  flex-shrink: 0;
  margin-top: 2px;
  background: var(--surface);
  border: 1px solid var(--border-2);
  color: var(--muted);
}
.message.assistant[data-agent="agente86"] .msg-avatar { background: rgba(239,68,68,.1); border-color: rgba(239,68,68,.25); color: #ef4444; }
.message.assistant[data-agent="agente99"] .msg-avatar { background: rgba(124,58,237,.1); border-color: rgba(124,58,237,.25); color: #7c3aed; }
.message.assistant[data-agent="jefe"]     .msg-avatar { background: rgba(217,119,6,.1);  border-color: rgba(217,119,6,.25);  color: #d97706; }

.msg-body { display: flex; flex-direction: column; gap: 4px; min-width: 0; }

.msg-images {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 4px;
}
.msg-images img {
  max-width: 200px;
  max-height: 160px;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid var(--border-2);
  cursor: pointer;
}

.msg-bubble {
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
}
.message.user .msg-bubble {
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-bottom-right-radius: 4px;
  color: var(--text);
}
.message.assistant .msg-bubble {
  background: #ffffff;
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
  border-left: 3px solid var(--active-color);
  box-shadow: 0 1px 4px rgba(0,0,0,0.04);
}
.message.assistant[data-agent="agente86"] .msg-bubble { border-left-color: #ef4444; }
.message.assistant[data-agent="agente99"] .msg-bubble { border-left-color: #7c3aed; }
.message.assistant[data-agent="jefe"]     .msg-bubble { border-left-color: #d97706; }

.msg-time { font-size: 10px; color: var(--muted); padding: 0 4px; }
.message.user .msg-time { text-align: right; }

/* Typing indicator */
#typing-indicator {
  max-width: 800px;
  margin: 4px auto 0;
  padding-left: 40px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.typing-label {
  font-size: 13px;
  color: var(--muted);
}
.typing-bubble {
  display: inline-flex;
  gap: 5px;
  padding: 12px 16px;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.04);
}
.typing-bubble span {
  width: 6px; height: 6px;
  background: var(--muted);
  border-radius: 50%;
  animation: bounce 1.2s infinite;
}
.typing-bubble span:nth-child(2) { animation-delay: .2s; }
.typing-bubble span:nth-child(3) { animation-delay: .4s; }
@keyframes bounce {
  0%,80%,100% { transform: translateY(0); opacity:.4; }
  40%          { transform: translateY(-6px); opacity:1; }
}
.msg-bubble.streaming::after {
  content: '▋';
  animation: cursor-blink 0.7s step-end infinite;
  color: var(--muted);
  margin-left: 1px;
}
@keyframes cursor-blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0; }
}

/* ── INPUT ──────────────────────────────────── */
#input-area {
  flex-shrink: 0;
  background: rgba(255,255,255,0.95);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  padding: 12px 20px 16px;
}

#image-previews {
  max-width: 800px;
  margin: 0 auto 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
#image-previews:empty { display: none; }

/* ── Previews en el input (imágenes, docs, videos) ── */
.fp { position: relative; flex-shrink: 0; border-radius: 10px; border: 1px solid var(--border-2); overflow: hidden; }

/* Imagen */
.fp.img-preview { width: 64px; height: 64px; }
.fp.img-preview img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* Documento */
.fp.doc-preview {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--surface);
  max-width: 240px;
  min-width: 160px;
}
.fp.doc-preview.fp-loading { opacity: 0.7; }
.fp.doc-preview.fp-error   { border-color: #ef4444; background: rgba(239,68,68,0.05); }
.fp-icon  { font-size: 20px; flex-shrink: 0; line-height: 1; }
.fp-info  { flex: 1; min-width: 0; }
.fp-name  { font-size: 12px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fp-meta  { font-size: 10px; color: var(--muted); margin-top: 2px; }

/* Video */
.fp.video-preview {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: var(--surface);
  max-width: 220px;
}
.fp.video-preview video {
  width: 56px; height: 40px;
  object-fit: cover;
  border-radius: 5px;
  flex-shrink: 0;
}

/* Botón quitar (unificado) */
.rm-fp {
  position: absolute; top: 4px; right: 4px;
  width: 18px; height: 18px;
  background: rgba(0,0,0,0.55);
  border: none; border-radius: 50%;
  color: #fff; font-size: 11px; line-height: 1;
  cursor: pointer; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}

/* ── Adjuntos en mensajes del chat ── */
.msg-file-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: 8px;
  font-size: 12.5px;
  margin-bottom: 6px;
  max-width: 100%;
}
.msg-file-badge strong { color: var(--text); }
.msg-file-badge small  { color: var(--muted); }

.msg-video-wrap {
  margin-bottom: 6px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border-2);
  background: #000;
  max-width: 320px;
}
.msg-video-player {
  width: 100%;
  max-height: 220px;
  display: block;
  border-radius: 0;
}
.msg-video-meta {
  padding: 6px 10px;
  font-size: 12px;
  color: var(--muted);
  background: var(--surface);
}

.input-row {
  max-width: 800px;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.icon-btn {
  width: 38px; height: 38px;
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: 10px;
  font-size: 16px;
  cursor: pointer;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  color: var(--muted);
  transition: all 0.2s;
}
.icon-btn:hover { color: var(--text); border-color: var(--active-color); background: var(--surface-2); }
.icon-btn:disabled { opacity: 0.3; cursor: not-allowed; }

/* Estado: siempre-escuchando (VAD activo, esperando voz) */
#mic-btn.listening {
  color: #16a34a;
  border-color: #16a34a;
  background: rgba(22,163,74,0.07);
  animation: listen-breathe 2.2s ease-in-out infinite;
  position: relative;
}
@keyframes listen-breathe {
  0%,100% { box-shadow: 0 0 0 0 rgba(22,163,74,0.25); }
  50%      { box-shadow: 0 0 0 6px rgba(22,163,74,0); }
}

/* Estado: grabando (voz detectada) */
#mic-btn.recording {
  color: #ef4444;
  border-color: #ef4444;
  background: rgba(239,68,68,0.08);
  animation: mic-pulse 1s ease-in-out infinite;
  position: relative;
}
@keyframes mic-pulse {
  0%,100% { box-shadow: 0 0 0 0 rgba(239,68,68,0.35); }
  50%      { box-shadow: 0 0 0 7px rgba(239,68,68,0); }
}

/* Badge countdown (3→2→1) */
#mic-btn.recording::after {
  content: attr(data-countdown);
  position: absolute;
  top: -6px; right: -6px;
  width: 16px; height: 16px;
  background: #ef4444;
  color: #fff;
  border-radius: 50%;
  font-size: 9px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  line-height: 1;
}

#message-input {
  flex: 1;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: 12px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  resize: none;
  outline: none;
  max-height: 130px;
  overflow-y: auto;
  line-height: 1.55;
  transition: border-color 0.2s, box-shadow 0.2s;
}
#message-input:focus {
  border-color: var(--active-color);
  box-shadow: 0 0 0 3px rgba(239,68,68,0.08);
  background: #ffffff;
}
#message-input::placeholder { color: var(--muted); }

#send-btn {
  width: 38px; height: 38px;
  background: var(--active-color);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 20px;
  cursor: pointer;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  transition: filter 0.2s, transform 0.1s;
  line-height: 1;
}
#send-btn:hover:not(:disabled) { filter: brightness(1.1); }
#send-btn:active:not(:disabled) { transform: scale(0.93); }
#send-btn:disabled { opacity: 0.35; cursor: not-allowed; }

/* TTS active state */
.icon-btn.tts-active {
  color: var(--active-color);
  border-color: var(--active-color);
  background: rgba(239,68,68,0.06);
}

/* ── TOOL CALLS ─────────────────────────────── */
.tool-call {
  margin-bottom: 6px;
  border: 1px solid var(--border-2);
  border-radius: 8px;
  overflow: hidden;
  font-size: 12.5px;
}

.tool-call-summary {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 11px;
  background: var(--surface);
  cursor: pointer;
  user-select: none;
  list-style: none;
  flex-wrap: wrap;
}
.tool-call-summary::-webkit-details-marker { display: none; }
.tool-call[open] .tool-call-summary { border-bottom: 1px solid var(--border); }

.tc-icon { font-size: 13px; flex-shrink: 0; }
.tc-name {
  font-weight: 700;
  color: var(--text);
  flex-shrink: 0;
  font-family: 'SF Mono', 'Fira Code', monospace;
}
.tc-args {
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}
.tc-preview {
  color: var(--muted);
  font-size: 11px;
  margin-left: auto;
  flex-shrink: 0;
  opacity: 0.7;
}
.tool-call[open] .tc-preview { display: none; }

.tool-call-result {
  padding: 10px 12px;
  font-size: 12px;
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  white-space: pre-wrap;
  word-break: break-all;
  overflow-x: auto;
  background: #fff;
  color: var(--text);
  max-height: 320px;
  overflow-y: auto;
  line-height: 1.5;
}

/* ── BUILD ──────────────────────────────────── */
.build-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  padding: 6px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-radius: 8px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  transition: all 0.2s;
}
.build-btn:hover:not(:disabled) {
  border-color: #ef4444;
  color: #ef4444;
  background: rgba(239,68,68,0.06);
}
.build-btn:disabled { opacity: 0.65; cursor: default; }
.build-btn.build-done { color: #16a34a; border-color: #16a34a; background: rgba(22,163,74,0.06); }
.build-btn.build-error { color: #ef4444; border-color: #ef4444; background: rgba(239,68,68,0.06); }

.build-output-msg .msg-bubble {
  background: #0d1117;
  border: 1px solid #30363d;
  border-left: 3px solid #ef4444;
  color: #e6edf3;
  padding: 12px 14px;
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 12px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 420px;
  overflow-y: auto;
}

/* ── MOBILE NAV (sidebar dots) ──────────────── */
.sidebar-mobile-nav {
  display: none;
}

.mob-agent-btn {
  width: 40px; height: 40px;
  border: none;
  border-radius: 50%;
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  cursor: pointer;
  opacity: 0.5;
  transition: opacity 0.2s, transform 0.15s, box-shadow 0.2s;
  flex-shrink: 0;
}
.mob-agent-btn.active {
  opacity: 1;
  box-shadow: 0 0 0 3px rgba(255,255,255,0.9), 0 0 0 5px currentColor;
}
.mob-agent-btn:active { transform: scale(0.9); }

/* ── PANEL MANDAMIENTOS ─────────────────────── */
#mandamientos-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  z-index: 200;
  backdrop-filter: blur(2px);
}

#mandamientos-panel {
  position: fixed;
  top: 0; right: 0;
  width: 480px;
  max-width: 100vw;
  height: 100vh;
  background: var(--bg);
  border-left: 1px solid var(--border-2);
  z-index: 201;
  display: flex;
  flex-direction: column;
  box-shadow: -4px 0 24px rgba(0,0,0,0.1);
}
#mandamientos-panel.hidden { display: none; }
#mandamientos-overlay.hidden { display: none; }

.mand-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.mand-title {
  font-weight: 700;
  font-size: 14px;
  color: var(--text);
  letter-spacing: 0.5px;
}
#mandamientos-close {
  background: transparent;
  border: none;
  font-size: 20px;
  color: var(--muted);
  cursor: pointer;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 6px;
  transition: color 0.2s, background 0.2s;
}
#mandamientos-close:hover { color: var(--text); background: var(--surface); }

.mand-tabs {
  display: flex;
  gap: 4px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.mand-tab {
  padding: 5px 12px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 16px;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.2s;
}
.mand-tab:hover { color: var(--text); border-color: var(--border-2); }
.mand-tab.active {
  background: var(--active-color);
  border-color: var(--active-color);
  color: #fff;
}

.mand-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 16px;
  gap: 10px;
  overflow: hidden;
}

#mand-textarea {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: 10px;
  color: var(--text);
  font-size: 13px;
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  line-height: 1.6;
  padding: 14px;
  resize: none;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
#mand-textarea:focus {
  border-color: var(--active-color);
  box-shadow: 0 0 0 3px rgba(239,68,68,0.08);
  background: #fff;
}

.mand-status {
  font-size: 11px;
  color: var(--muted);
  min-height: 16px;
  text-align: right;
  transition: color 0.3s;
}
.mand-status.saved { color: #16a34a; }
.mand-status.saving { color: var(--active-color); }

/* ── Cost badges ───────────────────────────── */
.cost-badge { font-size: 11px; font-weight: 500; padding: 3px 8px; border-radius: 4px; }
.cost-today { background: #dcfce7; color: #166534; }
.cost-today.cost-mid { background: #fef9c3; color: #854d0e; }
.cost-month { background: #dbeafe; color: #1e40af; }
.cost-month.cost-mid { background: #fef9c3; color: #854d0e; }
.cost-month.cost-high { background: #fee2e2; color: #991b1b; }

/* ── More dropdown ─────────────────────────── */
.header-dropdown { position: relative; display: flex; gap: 4px; }
.more-btn { font-size: 18px; padding: 0 6px; }
.more-menu { position: absolute; right: 0; top: 100%; background: var(--bg); border: 0.5px solid #ddd; border-radius: 8px; padding: 4px; display: flex; flex-direction: column; gap: 2px; z-index: 100; min-width: 120px; }
.more-menu button { text-align: left; padding: 6px 10px; border-radius: 4px; }
.more-menu button:hover { background: #f5f5f5; }

.daily-limit-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: 8px;
  flex-shrink: 0;
}
.daily-limit-label {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}
.daily-limit-prefix {
  font-size: 12px;
  color: var(--muted);
}
#daily-limit-input {
  width: 72px;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border-2);
  color: var(--text);
  font-size: 13px;
  padding: 1px 4px;
  outline: none;
  font-variant-numeric: tabular-nums;
}
#daily-limit-input:focus { border-color: var(--active-color); }
.daily-spent-label {
  margin-left: auto;
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.daily-spent-label.over { color: #ef4444; font-weight: 600; }

/* ── 14) SELECTOR DE MODELO ─────────────────── */
#model-select {
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: 8px;
  color: var(--text);
  font-size: 11px;
  padding: 4px 8px;
  cursor: pointer;
  outline: none;
  transition: border-color 0.2s;
  max-width: 110px;
}
#model-select:hover, #model-select:focus { border-color: var(--active-color); }

/* ── 16) BÚSQUEDA EN SIDEBAR ────────────────── */
.sidebar-search {
  padding: 8px 8px 4px;
  flex-shrink: 0;
}
#search-input {
  width: 100%;
  padding: 6px 10px;
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: 8px;
  color: var(--text);
  font-size: 12px;
  outline: none;
  transition: border-color 0.2s;
}
#search-input:focus { border-color: var(--active-color); }
#search-input::placeholder { color: var(--muted); }

/* ── 15) BOTÓN ARCHIVOS EN FOOTER ───────────── */
.sidebar-footer {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
#filetree-btn {
  width: 100%;
  padding: 7px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--muted);
  font-size: 11px;
  cursor: pointer;
  transition: all 0.2s;
}
#filetree-btn:hover { color: var(--text); border-color: var(--active-color); background: var(--surface); }

/* ── 15) PANEL ÁRBOL DE ARCHIVOS ────────────── */
#filetree-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  z-index: 200;
  backdrop-filter: blur(2px);
}
#filetree-overlay.hidden { display: none; }

#filetree-panel {
  position: fixed;
  top: 0; right: 0;
  width: 520px;
  max-width: 100vw;
  height: 100vh;
  background: var(--bg);
  border-left: 1px solid var(--border-2);
  z-index: 201;
  display: flex;
  flex-direction: column;
  box-shadow: -4px 0 24px rgba(0,0,0,0.1);
}
#filetree-panel.hidden { display: none; }

.filetree-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}
.filetree-body::-webkit-scrollbar { width: 4px; }
.filetree-body::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 4px; }

#filetree-content {
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 12px;
  line-height: 1.7;
  color: var(--text);
  white-space: pre;
  background: var(--surface);
  border-radius: 10px;
  padding: 14px 16px;
}

#filetree-close {
  background: transparent;
  border: none;
  font-size: 20px;
  color: var(--muted);
  cursor: pointer;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 6px;
  transition: color 0.2s, background 0.2s;
}
#filetree-close:hover { color: var(--text); background: var(--surface); }

/* ── 17) COSTO DE SESIÓN ────────────────────── */
.session-cost {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: 8px;
  padding: 4px 9px;
  white-space: nowrap;
  transition: color 0.3s;
}
.session-cost.cost-low  { color: #16a34a; border-color: rgba(22,163,74,0.3); background: rgba(22,163,74,0.06); }
.session-cost.cost-mid  { color: #d97706; border-color: rgba(217,119,6,0.3);  background: rgba(217,119,6,0.06); }
.session-cost.cost-high { color: #ef4444; border-color: rgba(239,68,68,0.3);  background: rgba(239,68,68,0.06); }

/* ── @media mobile ≤600px ───────────────────── */
@media (max-width: 600px) {

  /* Header */
  .agent-tabs { display: none; }
  .header-brand { width: auto; }
  .header-actions { width: auto; }
  .app-header { padding: 0 12px; gap: 10px; }

  /* Sidebar: colapsa a tira de puntitos */
  .sidebar {
    width: 54px;
    flex-shrink: 0;
    align-items: center;
    overflow: hidden;
  }
  #sidebar-content { display: none; }
  .sidebar-footer   { display: none; }
  .sidebar-mobile-nav {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    gap: 14px;
    padding: 14px 0;
    flex: 1;
    width: 100%;
  }

  /* Chat: full width, sin cortes */
  #chat-container {
    padding: 14px 10px 10px;
  }
  #messages-list {
    max-width: 100%;
    gap: 14px;
  }
  .message {
    max-width: 94%;
  }
  #typing-indicator {
    max-width: 100%;
    padding-left: 10px;
  }

  /* Input */
  #input-area {
    padding: 8px 10px 12px;
  }
  .input-row {
    max-width: 100%;
    gap: 5px;
  }
  #image-previews {
    max-width: 100%;
  }
}
/* ── Panel AI ─────────────────────────────── */
#ai-panel {
  position: fixed;
  top: 0; right: 0;
  width: 480px;
  max-width: 100vw;
  height: 100vh;
  background: var(--bg);
  border-left: 1px solid var(--border-2);
  z-index: 201;
  display: flex;
  flex-direction: column;
  box-shadow: -4px 0 24px rgba(0,0,0,0.1);
}
#ai-panel.hidden { display: none; }
#ai-overlay { position: fixed; inset: 0; z-index: 200; background: rgba(0,0,0,0.2); }
#ai-overlay.hidden { display: none; }
#ai-close { background: transparent; border: none; font-size: 20px; color: var(--muted); cursor: pointer; line-height: 1; padding: 2px 6px; border-radius: 6px; }
#ai-close:hover { color: var(--text); background: var(--surface); }
.ai-tab { padding: 5px 12px; background: transparent; border: 1px solid var(--border); border-radius: 16px; font-size: 12px; color: var(--muted); cursor: pointer; transition: all 0.2s; }
.ai-tab.active { background: var(--active-color); border-color: var(--active-color); color: #fff; }
.ai-body { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 16px; }
.ai-provider-block { border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.ai-provider-label { font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; padding: 8px 12px; background: var(--surface); border-bottom: 1px solid var(--border); }
.ai-model-row { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--border); }
.ai-model-row:last-of-type { border-bottom: none; }
.ai-model-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.ai-model-name { font-size: 13px; font-weight: 500; color: var(--text); flex: 1; }
.ai-mode-badge { font-size: 10px; padding: 2px 7px; border-radius: 20px; font-weight: 500; white-space: nowrap; }
.ai-mode-plan { background: #E6F1FB; color: #185FA5; }
.ai-mode-code { background: #FAEEDA; color: #854F0B; }
.ai-score { font-size: 12px; color: var(--muted); min-width: 32px; text-align: center; }
.ai-price { font-size: 11px; color: var(--muted); min-width: 68px; text-align: right; }
.ai-toggle { width: 34px; height: 18px; border-radius: 9px; position: relative; cursor: pointer; border: none; transition: background .2s; flex-shrink: 0; }
.ai-toggle.on { background: #1D9E75; }
.ai-toggle.off { background: var(--border-2); }
.ai-toggle::after { content: ''; position: absolute; width: 14px; height: 14px; background: white; border-radius: 50%; top: 2px; transition: left .2s; }
.ai-toggle.on::after { left: 18px; }
.ai-toggle.off::after { left: 2px; }
.ai-key-row { display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: var(--surface); }
.ai-key-label { font-size: 11px; color: var(--muted); white-space: nowrap; }
.ai-key-input { flex: 1; font-size: 12px; font-family: monospace; background: transparent; border: none; color: var(--muted); outline: none; }
.ai-key-btn { font-size: 11px; padding: 3px 10px; border: 1px solid var(--border-2); border-radius: 6px; background: transparent; color: var(--muted); cursor: pointer; }
.ai-add-btn { padding: 8px; border: 1px dashed var(--border-2); border-radius: 10px; background: transparent; color: var(--muted); font-size: 13px; cursor: pointer; text-align: center; }
.ai-add-btn:hover { color: var(--text); border-color: var(--text); }
.ai-modo-card { background: var(--surface); border-radius: 10px; padding: 14px; border: 1px solid var(--border); }
.ai-modo-title { font-size: 14px; font-weight: 600; color: var(--text); margin-bottom: 4px; }
.ai-modo-desc { font-size: 12px; color: var(--muted); margin-bottom: 12px; }
.ai-modo-row { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.ai-modo-label { font-size: 12px; color: var(--muted); min-width: 110px; }
.ai-select { flex: 1; font-size: 12px; padding: 4px 8px; border: 1px solid var(--border-2); border-radius: 6px; background: var(--bg); color: var(--text); }
.ai-modo-note { font-size: 12px; color: var(--muted); text-align: center; padding: 8px; }
.msg-model-label {
  font-size: 10px;
  color: var(--muted);
  text-align: center;
  margin-top: 2px;
  font-weight: 500;
  white-space: nowrap;
}
.msg-avatar-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  flex-shrink: 0;
  width: 36px;
}
.limite-card { background: var(--surface); border-radius: 10px; padding: 14px; border: 1px solid var(--border); margin-bottom: 12px; }
.limite-titulo { font-size: 14px; font-weight: 600; color: var(--text); margin-bottom: 4px; }
.limite-desc { font-size: 12px; color: var(--muted); margin-bottom: 12px; }
.limite-row { display: flex; align-items: center; gap: 8px; }
.limite-label { font-size: 12px; color: var(--muted); min-width: 90px; }
.limite-prefix { font-size: 13px; color: var(--muted); }
.limite-input { width: 80px; font-size: 14px; font-weight: 500; padding: 5px 8px; border: 1px solid var(--border-2); border-radius: 6px; background: var(--bg); color: var(--text); text-align: center; }
.limite-save { font-size: 12px; padding: 5px 14px; border: none; border-radius: 6px; background: #1D9E75; color: white; cursor: pointer; }
.progress-bar { height: 8px; border-radius: 4px; background: var(--border); margin-top: 10px; overflow: hidden; }
.progress-fill { height: 100%; border-radius: 4px; background: #1D9E75; transition: width .3s; }
.progress-fill.warn { background: #f59e0b; }
.progress-fill.danger { background: #ef4444; }
.progress-labels { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 4px; }
.groq-usage { background:#EAF3DE; color:#3B6D11; border:0.5px solid #C0DD97; }
.groq-usage.warn { background:#FAEEDA; color:#854F0B; }
.groq-usage.danger { background:#FCEBEB; color:#A32D2D; }

.build-bloqueado-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(239,68,68,0.08);
  border: 1px solid #ef4444;
  border-radius: 8px;
  padding: 10px 14px;
  margin: 6px 0;
}
.build-autorizar-btn {
  background: #ef4444;
  color: white;
  border: none;
  border-radius: 6px;
  padding: 8px 16px;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  letter-spacing: 0.5px;
}
.build-autorizar-btn:hover { background: #dc2626; }
.build-autorizar-btn:disabled { opacity: 0.6; cursor: default; }
