* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
    --bg-color: #0f0f13; --surface: #1a1a24; --surface-light: #252532; --border: #2c2c3a;
    --text-primary: #f0f0f5; --text-secondary: #a0a0b0; --accent: #5b7eff;
    --accent-gradient: linear-gradient(135deg, #5b7eff 0%, #a855f7 100%);
    --bot-msg-bg: #252532; --user-msg-bg: var(--accent); --user-msg-text: white;
    --input-bg: #1a1a24; --code-bg: #0b0f17; --code-border: #2a2f3a;
    --button-hover: #3a3a4a; --sidebar-width: min(300px, 85vw); --warning-color: #f39c12;
    --font-size-multiplier: 1;
}
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter', Roboto, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    height: 100vh; height: 100dvh; overflow: hidden;
    touch-action: pan-x pan-y;
    font-size: calc(1rem * var(--font-size-multiplier));
    -webkit-text-size-adjust: 100%;
}
.app { display: flex; height: 100%; width: 100%; position: relative; }

/* Sidebar */
.sidebar-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.5); z-index: 15; display: none; }
.sidebar-overlay.show { display: block; }
.sidebar { width: var(--sidebar-width); background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; transition: transform 0.3s ease; z-index: 20; position: absolute; left: 0; top: 0; bottom: 0; transform: translateX(0); }
.sidebar.closed { transform: translateX(-100%); }
.sidebar-header { padding: 16px 12px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.sidebar-tabs { display: flex; gap: 8px; flex: 1; }
.sidebar-tab { background: transparent; border: none; color: var(--text-secondary); width: 40px; height: 40px; border-radius: 12px; display: flex; align-items: center; justify-content: center; cursor: pointer; transition: all 0.2s; }
.sidebar-tab:hover { background: var(--surface-light); color: var(--text-primary); }
.sidebar-tab.active { background: var(--accent); color: white; }
.close-sidebar-btn { background: transparent; border: none; color: var(--text-secondary); width: 40px; height: 40px; border-radius: 8px; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.close-sidebar-btn:hover { background: var(--surface-light); color: var(--text-primary); }
.sidebar-content { flex: 1; overflow-y: auto; padding: 16px 12px; }
.sidebar-section { margin-bottom: 24px; }
.section-header { display: flex; align-items: center; justify-content: space-between; padding: 8px 4px; color: var(--text-secondary); font-size: 0.7rem; font-weight: 600; letter-spacing: 0.5px; }
.new-chat-btn { background: transparent; border: none; color: var(--text-secondary); cursor: pointer; padding: 4px 8px; border-radius: 6px; font-size: 1.2rem; }
.new-chat-btn:hover { background: var(--surface-light); color: var(--text-primary); }
.chats-list { display: flex; flex-direction: column; gap: 4px; }
.chat-item { padding: 10px 12px; border-radius: 12px; cursor: pointer; display: flex; align-items: center; justify-content: space-between; transition: background 0.2s; color: var(--text-primary); font-size: 0.9rem; }
.chat-item:hover { background: var(--surface-light); }
.chat-item.active { background: var(--accent); color: white; }
.chat-item-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item-delete { opacity: 0; background: transparent; border: none; color: inherit; cursor: pointer; padding: 4px; border-radius: 4px; transition: opacity 0.2s; }
.chat-item:hover .chat-item-delete { opacity: 0.7; }
.chat-item-delete:hover { opacity: 1; background: rgba(0,0,0,0.2); }
.sidebar-footer { padding: 16px 12px; border-top: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.user-info-compact { display: flex; align-items: center; gap: 8px; flex: 1; }
.user-avatar-small { width: 28px; height: 28px; background: var(--accent); border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: bold; font-size: 0.8rem; }
.user-name-small { font-size: 0.9rem; font-weight: 500; }
.user-credits { font-size: 0.8rem; color: var(--text-secondary); }
.menu-dots-btn { background: transparent; border: none; color: var(--text-secondary); width: 36px; height: 36px; border-radius: 8px; display: flex; align-items: center; justify-content: center; cursor: pointer; }
.menu-dots-btn:hover { background: var(--surface-light); color: var(--text-primary); }
.menu-popup { position: absolute; bottom: 70px; left: 16px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 8px; min-width: 220px; z-index: 30; box-shadow: 0 8px 20px rgba(0,0,0,0.5); }
.menu-item { display: flex; align-items: center; gap: 12px; padding: 12px 16px; cursor: pointer; border-radius: 12px; color: var(--text-primary); font-size: 0.9rem; transition: background 0.2s; }
.menu-item:hover { background: var(--surface-light); }
.upgrade-sidebar-btn { background: var(--accent-gradient); border: none; color: white; padding: 10px 16px; border-radius: 30px; font-size: 0.9rem; font-weight: 600; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 6px; margin: 8px 12px; width: calc(100% - 24px); }
.upgrade-symbol { font-size: 1.2rem; }

/* Main chat */
.main-chat { flex: 1; display: flex; flex-direction: column; background: var(--bg-color); width: 100%; position: relative; }
.draven-nav { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--border); background: var(--bg-color); }
.nav-left, .nav-right { display: flex; align-items: center; }
.nav-center { display: flex; flex-direction: column; align-items: center; text-align: center; }
.nav-chat-title { font-size: 1.1rem; font-weight: 600; color: var(--text-primary); margin: 0; line-height: 1.2; }
.nav-chat-subtitle { font-size: 0.8rem; color: var(--text-secondary); }
.toggle-sidebar { background: transparent; border: none; color: var(--text-secondary); cursor: pointer; padding: 8px; border-radius: 8px; display: flex; align-items: center; justify-content: center; }
.toggle-sidebar:hover { background: var(--surface-light); color: var(--text-primary); }
.new-chat-nav-btn { background: transparent; border: none; color: var(--text-secondary); cursor: pointer; padding: 8px; border-radius: 8px; display: flex; align-items: center; justify-content: center; }
.new-chat-nav-btn:hover { background: var(--surface-light); color: var(--text-primary); }

/* Pantalla de bienvenida */
.chat-messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 20px; scroll-behavior: smooth; position: relative; }
.welcome-screen-inline { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 100%; width: 100%; padding: 20px; }
.welcome-screen-inline.hidden { display: none !important; }
.welcome-backdrop { text-align: center; }
.welcome-logo { font-size: clamp(2.5rem, 10vw, 3.5rem); font-weight: 700; background: var(--accent-gradient); background-clip: text; -webkit-background-clip: text; color: transparent; margin-bottom: 8px; }
.welcome-subtitle { color: var(--text-secondary); font-size: clamp(0.9rem, 4vw, 1.1rem); }

/* Botón flotante */
.scroll-to-bottom-btn { position: absolute; bottom: 100px; right: 20px; width: 44px; height: 44px; border-radius: 50%; background: var(--surface); border: 1px solid var(--border); color: var(--text-primary); display: flex; align-items: center; justify-content: center; cursor: pointer; box-shadow: 0 4px 12px rgba(0,0,0,0.3); transition: all 0.2s; z-index: 10; }
.scroll-to-bottom-btn:hover { background: var(--surface-light); border-color: var(--accent); transform: scale(1.05); }
.scroll-to-bottom-btn.hidden { display: none !important; }

/* Mensajes */
.message { display: flex; flex-direction: column; animation: fadeIn 0.2s ease; }
.message.user { align-items: flex-end; }
.message-content { max-width: 85%; padding: 12px 16px; border-radius: 20px; line-height: 1.5; font-size: 0.95rem; word-break: break-word; }
.user .message-content { background: var(--user-msg-bg); color: var(--user-msg-text); }
.bot .message-content { background: var(--bot-msg-bg); }
.message-content pre { position: relative; background: var(--code-bg); border: 1px solid var(--code-border); border-radius: 12px; padding: 16px; overflow-x: auto; margin: 12px 0; }
.message-content code { font-family: 'Fira Code', monospace; font-size: 0.9rem; }
.code-copy-btn { position: absolute; top: 8px; right: 8px; background: var(--surface-light); border: 1px solid var(--border); color: var(--text-secondary); width: 32px; height: 32px; border-radius: 8px; cursor: pointer; display: flex; align-items: center; justify-content: center; opacity: 0; transition: opacity 0.2s; }
.message-content pre:hover .code-copy-btn { opacity: 1; }
.message-actions { display: flex; gap: 8px; margin-top: 6px; margin-left: 12px; opacity: 0; transition: opacity 0.2s; }
.message:hover .message-actions { opacity: 1; }
.action-btn { background: var(--surface-light); border: none; color: var(--text-secondary); font-size: 1rem; padding: 4px 8px; border-radius: 16px; cursor: pointer; }
.action-btn:hover { background: var(--button-hover); color: var(--text-primary); }
.thinking-wrapper { background: var(--bot-msg-bg); border-radius: 20px; margin-bottom: 8px; width: fit-content; max-width: 85%; overflow: hidden; }
.thinking-header { background: var(--surface-light); padding: 6px 12px; font-size: 11px; font-family: monospace; color: var(--text-secondary); border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; }
.thinking-indicator { display: flex; gap: 6px; padding: 12px 18px; }
.thinking-indicator span { width: 8px; height: 8px; background: var(--text-secondary); border-radius: 50%; animation: bounce 1.4s infinite ease-in-out both; }
@keyframes bounce { 0%,80%,100% { transform: scale(0); opacity: 0.5; } 40% { transform: scale(1); opacity: 1; } }

/* Input área */
.input-area { padding: 12px 16px 16px; border-top: 1px solid var(--border); }
.model-dropdown { position: relative; display: inline-block; margin-bottom: 10px; }
.model-select-btn { background: var(--surface-light); border: 1px solid var(--border); color: var(--text-primary); padding: 8px 14px; border-radius: 30px; font-size: 0.9rem; font-weight: 500; cursor: pointer; display: flex; align-items: center; gap: 6px; }
.model-dropdown-content { display: none; position: absolute; bottom: 100%; left: 0; margin-bottom: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 8px; min-width: 280px; z-index: 100; box-shadow: 0 8px 20px rgba(0,0,0,0.5); max-height: 350px; overflow-y: auto; }
.model-dropdown-content.show { display: block; }
.model-option { padding: 10px 14px; cursor: pointer; border-radius: 12px; color: var(--text-primary); display: flex; align-items: center; justify-content: space-between; }
.model-option:hover { background: var(--surface-light); }
.model-option.disabled { opacity: 0.5; cursor: not-allowed; pointer-events: none; }
.model-option-left { display: flex; align-items: center; gap: 8px; }
.model-icon { display: none; }  /* <-- Iconos de modelos eliminados */
.model-info-btn { background: transparent; border: none; color: var(--text-secondary); cursor: pointer; padding: 4px; border-radius: 4px; opacity: 0.6; transition: opacity 0.2s; }
.model-info-btn:hover { opacity: 1; background: var(--button-hover); }
.pro-badge, .premium-badge, .credit-badge { padding: 2px 8px; border-radius: 12px; font-size: 0.7rem; font-weight: 600; }
.pro-badge { background: linear-gradient(135deg, #a855f7, #5b7eff); color: white; }
.premium-badge { background: linear-gradient(135deg, #fbbf24, #f97316); color: white; }
.credit-badge { background: #10b981; color: white; }
.input-wrapper { display: flex; gap: 6px; background: var(--input-bg); border-radius: 40px; padding: 4px 4px 4px 14px; border: 1px solid var(--border); align-items: flex-end; }
.input-wrapper textarea { flex: 1; background: transparent; border: none; padding: 10px 0; font-size: 1rem; resize: none; outline: none; color: var(--text-primary); max-height: 120px; }
.send-btn, .stop-btn, .web-search-btn, .attach-btn { background: transparent; border: none; color: var(--text-secondary); width: 40px; height: 40px; border-radius: 50%; cursor: pointer; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.send-btn { background: var(--accent); color: white; }
.web-search-btn.active { color: var(--accent); }
.attach-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.attach-wrapper { position: relative; }
.attach-menu { position: absolute; bottom: 100%; left: 0; margin-bottom: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 8px; min-width: 140px; z-index: 100; display: none; }
.attach-menu.show { display: block; }
.attach-option { display: flex; align-items: center; gap: 12px; padding: 10px 14px; cursor: pointer; border-radius: 12px; }
.attach-option:hover { background: var(--surface-light); }
.attachments-preview { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.attachment-item { background: var(--surface-light); padding: 8px 12px; border-radius: 12px; display: flex; align-items: center; gap: 8px; }
.attachment-item img { width: 40px; height: 40px; border-radius: 8px; }
.remove-attachment { background: transparent; border: none; color: var(--text-secondary); cursor: pointer; }

/* Modales */
.model-info-overlay, .warning-overlay, .credits-warning-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.8); display: flex; align-items: center; justify-content: center; z-index: 1000; padding: 16px; }
.model-info-modal, .warning-modal { background: var(--surface); border-radius: 24px; padding: 24px; width: 100%; max-width: 500px; position: relative; }
.close-modal { position: absolute; top: 16px; right: 16px; background: transparent; border: none; color: var(--text-secondary); font-size: 24px; cursor: pointer; }
.warning-modal h3 { color: var(--warning-color); margin-bottom: 12px; font-size: 1.2rem; }
.warning-details { background: var(--surface-light); border-radius: 12px; padding: 14px; margin: 16px 0; font-size: 0.9rem; }
.warning-actions { display: flex; gap: 10px; justify-content: flex-end; }
.warning-actions button { padding: 10px 18px; border-radius: 30px; border: 1px solid var(--border); background: var(--surface-light); color: var(--text-primary); cursor: pointer; font-size: 0.9rem; }
.primary-btn { background: var(--accent) !important; color: white !important; border: none !important; }
.message.system .message-content { background: var(--surface-light); color: var(--text-secondary); font-style: italic; border: 1px dashed var(--border); }
.message.system.limit-warning .message-content { background: rgba(243, 156, 18, 0.1); border-color: var(--warning-color); color: var(--warning-color); }
.hidden { display: none !important; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

@media (max-width: 480px) {
    .input-wrapper { padding: 2px 2px 2px 12px; }
    .send-btn, .web-search-btn, .attach-btn { width: 36px; height: 36px; }
}

/* ---------- MENÚ CONTEXTUAL DE CHATS (3 PUNTOS) ---------- */
.chat-menu-trigger {
    background: transparent; border: none; color: var(--text-secondary);
    font-size: 1.2rem; padding: 4px 8px; border-radius: 4px; cursor: pointer;
    opacity: 0; transition: opacity 0.2s;
}
.chat-item:hover .chat-menu-trigger { opacity: 1; }
.chat-menu-trigger:hover { background: var(--surface-light); }

.chat-menu-dropdown {
    background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
    padding: 6px; min-width: 160px; box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
.chat-menu-item {
    display: flex; align-items: center; gap: 10px; padding: 10px 14px;
    cursor: pointer; border-radius: 8px; color: var(--text-primary);
    font-size: 0.9rem; transition: background 0.2s;
}
.chat-menu-item:hover { background: var(--surface-light); }
.chat-menu-item.delete { color: #e74c3c; }
.chat-menu-item.delete:hover { background: rgba(231, 76, 60, 0.1); }