:root {
    --bg-primary: #667eea;
    --bg-secondary: #764ba2;
    --bg-light: white;
    --bg-dark: #1a1a1a;
    --text-light: #333;
    --text-dark: #f0f0f0;
    --message-user-bg: #667eea;
    --message-bot-bg: #f0f0f0;
    --message-bot-text: #333;
    --input-border: #ddd;
    --input-focus: #667eea;
    --header-bg: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --shadow: 0 10px 40px rgba(0,0,0,0.2);
    --border: #eee;
}

.dark-mode {
    --bg-light: #1a1a1a;
    --bg-dark: white;
    --text-light: #f0f0f0;
    --text-dark: #333;
    --message-bot-bg: #2d2d2d;
    --message-bot-text: #e0e0e0;
    --input-border: #444;
    --input-focus: #667eea;
    --header-bg: linear-gradient(135deg, #4a55d9 0%, #5a3a8a 100%);
    --shadow: 0 10px 40px rgba(0,0,0,0.4);
    --border: #333;
}

.chat-container {
    width: 100%;
    max-width: 800px;
    background: var(--bg-light);
    border-radius: 15px;
    box-shadow: var(--shadow);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    height: 90vh;
    transition: background 0.3s ease;
}

.chat-header {
    background: var(--header-bg);
    color: white;
    padding: 15px 20px;
    text-align: center;
    font-size: 18px;
    font-weight: bold;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.theme-toggle {
    background: rgba(255,255,255,0.2);
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 18px;
    transition: all 0.3s ease;
    flex-shrink: 0;
}

.chat-messages {
    flex: 1 1 auto;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 15px;
    background: var(--bg-light);
    transition: background 0.3s ease;
    min-height: 0;
}

.message {
    max-width: 80%;
    padding: 12px 40px 12px 15px;
    border-radius: 18px;
    position: relative;
    animation: fadeIn 0.3s ease;
    overflow-wrap: break-word;
    word-break: break-word;
    hyphens: auto;
    -webkit-hyphens: auto;
    box-sizing: border-box;
    min-width: 0;
    width: fit-content;
    width: -moz-fit-content;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.user-message {
    background: var(--message-bot-bg);
    color: var(--message-bot-text);
    align-self: flex-end;
    border-bottom-right-radius: 5px;
    max-width: min(80%, 600px);
}

.bot-message {
    background: var(--message-bot-bg);
    color: var(--message-bot-text);
    align-self: flex-start;
    border-bottom-left-radius: 5px;
    white-space: pre-wrap;
    line-height: 1.5;
    transition: background 0.3s ease, color 0.3s ease;
    max-width: min(80%, 600px);
}

.bot-message > * {
    max-width: 100% !important;
    overflow-wrap: break-word !important;
    word-break: break-word !important;
}

.bot-message ul,
.bot-message ol {
    margin: 8px 0;
    padding-left: 1.5em;
    max-width: 100%;
    box-sizing: border-box;
    overflow: visible;
}

.bot-message li {
    margin-bottom: 6px;
    line-height: 1.5;
    max-width: 100%;
    overflow-wrap: break-word;
    word-break: break-word;
}

.bot-message pre,
.bot-message code {
    max-width: 100%;
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: break-all;
    background: rgba(0,0,0,0.05);
    padding: 8px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
}

.dark-mode .bot-message pre,
.dark-mode .bot-message code {
    background: rgba(255,255,255,0.05);
}

.bot-message strong {
    font-weight: bold;
}

.copy-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(0,0,0,0.1);
    border: none;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: inherit;
    font-size: 14px;
    opacity: 0;
    transition: all 0.3s ease;
    padding: 0;
    z-index: 10;
}

.dark-mode .copy-btn {
    background: rgba(255,255,255,0.1);
}

.message:hover .copy-btn {
    opacity: 1;
}

.copy-btn:hover {
    background: rgba(0,0,0,0.2);
    transform: scale(1.1);
}

.dark-mode .copy-btn:hover {
    background: rgba(255,255,255,0.2);
}

.copy-btn.copied {
    background: #4CAF50;
    color: white;
}

.loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255,255,255,0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.chat-input {
    padding: 15px;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: var(--bg-light);
    transition: background 0.3s ease;
    flex-shrink: 0;
}

.chat-input button {
    background: var(--header-bg);
    border: none;
    padding: 12px 25px;
    border-radius: 25px;
    cursor: pointer;
    font-weight: bold;
    transition: transform 0.2s;
    flex-shrink: 0;
    font-size: 16px;
    width: 100%;
    color: #fff;
}

.chat-input button:hover {
    transform: translateY(-2px);
}

.chat-input button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.welcome {
    text-align: center;
    color: #666;
    padding: 0;
}

.welcome h2 {
    margin-bottom: 10px;
    color: var(--text-light);
}

.welcome p {
    color: var(--text-light);
    opacity: 0.7;
    font-size: 14px;
}

.chat-messages::-webkit-scrollbar {
    width: 8px;
}

.chat-messages::-webkit-scrollbar-track {
    background: var(--bg-light);
}

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--bg-primary);
    border-radius: 4px;
}

.dark-mode .chat-messages::-webkit-scrollbar-thumb {
    background: var(--message-bot-bg);
}

/* ✅ Responsive para móviles */
@media (max-width: 600px) {
    .chat-input button {
        font-size: 20px !important;
        padding: 10px 20px !important;
    }
    
    .chat-input textarea {
        min-height: 24px !important;
        max-height: 30px !important;
    }
    
    .chat-container {
        padding: 10px;
        height: 100vh;
        overflow: hidden;
    }
    
    .chat-container {
        height: 100vh;
        max-height: -webkit-fill-available;
        border-radius: 10px;
    }
    
    .message {
        max-width: 90% !important;
        padding: 10px 35px 10px 12px;
        font-size: 0.95em;
    }
    
    .bot-message ul,
    .bot-message ol {
        padding-left: 1.2em;
        font-size: 0.9em;
    }
    
    .theme-toggle {
        width: 35px;
        height: 35px;
        font-size: 16px;
    }
    
    .chat-header {
        padding: 12px 15px;
        font-size: 16px;
    }
    
    .chat-input {
        padding: 12px;
    }
    
    .bot-message,
    .user-message {
        max-width: 95% !important;
    }
    
    .bot-message pre,
    .bot-message code {
        font-size: 0.8em;
        padding: 6px;
    }
    
    .copy-btn {
        width: 24px;
        height: 24px;
        font-size: 12px;
        top: 6px;
        right: 6px;
    }
}

@media (max-width: 400px) {
    .message {
        max-width: 95% !important;
    }
    
    .bot-message ul,
    .bot-message ol {
        padding-left: 1em;
    }
}

@-moz-document url-prefix() {
    .message {
        width: fit-content;
        max-width: 80%;
    }
}

.chat-input textarea {
    flex: 1;
    min-width: 0;
    padding: 12px 15px;
    border: 2px solid var(--input-border);
    border-radius: 25px;
    font-size: 16px;
    outline: none;
    transition: all 0.3s;
    background: var(--bg-light);
    color: var(--text-light);
    margin: 0;
    resize: none;
    line-height: 1.4;
    overflow: hidden;
    box-sizing: border-box;
    width: 100%;
}

.chat-input textarea:focus {
    border-color: var(--input-focus);
}

.chat-input textarea {
    min-height: 48px;
    max-height: 120px;
}

.chat-input textarea:not(:placeholder-shown) {
    height: auto;
}

.bot-message {
    line-height: 1.6;
    white-space: pre-line;
}

.bot-message p {
    margin: 0 0 1em 0;
}

.bot-message p:last-child {
    margin-bottom: 0;
}

/* ✅ Responsive compacto para móviles */
@media (max-width: 768px) {
    .chat-container {
        max-height: 600px !important;
        height: auto !important;
        border-radius: 10px !important;
    }
    
    .chat-messages {
        max-height: 350px !important;
        min-height: 350px !important;
        padding: 12px !important;
        gap: 8px !important;
    }
    
    .message {
        max-width: 85% !important;
        padding: 10px 35px 10px 12px !important;
        font-size: 14px !important;
        border-radius: 16px !important;
    }
    
    .bot-message,
    .user-message {
        max-width: 90% !important;
    }
    
    .copy-btn {
        width: 24px !important;
        height: 24px !important;
        font-size: 12px !important;
        top: 6px !important;
        right: 6px !important;
    }
    
    .chat-header {
        padding: 10px 15px !important;
        font-size: 16px !important;
    }
    
    .theme-toggle {
        width: 32px !important;
        height: 32px !important;
        font-size: 16px !important;
    }
    
    .chat-input {
        padding: 8px 12px !important;
        gap: 8px !important;
    }
    
    .chat-input textarea {
        font-size: 14px !important;
        padding: 8px 12px !important;
        min-height: 40px !important;
        max-height: 60px !important;
        border-radius: 20px !important;
    }
    
    .chat-input button {
        padding: 8px 16px !important;
        border-radius: 20px !important;
        font-size: 14px !important;
    }
    
    .welcome {
        padding: 15px 10px !important;
    }
    
    .welcome h2 {
        font-size: 18px !important;
        margin-bottom: 5px !important;
    }
    
    .welcome p {
        font-size: 13px !important;
        opacity: 0.8 !important;
    }
    
    .bot-message ul,
    .bot-message ol {
        padding-left: 1.2em !important;
        font-size: 0.9em !important;
    }
    
    .bot-message pre,
    .bot-message code {
        font-size: 0.85em !important;
        padding: 6px !important;
    }
}

@media (max-width: 480px) {
    .chat-container {
        max-height: 500px !important;
    }
    
    .chat-messages {
        max-height: 300px !important;
        min-height: 300px !important;
    }
    
    .message {
        max-width: 95% !important;
        font-size: 13px !important;
    }
    
    .chat-input textarea {
        min-height: 35px !important;
        max-height: 50px !important;
    }
    
    .chat-input button {
        font-size: 15px !important;
        padding: 10px !important;
    }
}

/* ✅ Botón del chat en la navbar */
.chatia-nav-button {
    position: relative;
    margin-left: 10px;
    margin-right: 10px;
}

.chatia-nav-btn {
    background: transparent;
    color: white;
    border: none;
    padding: 0;
    border-radius: 0;
    cursor: pointer;
    font-weight: 600;
    font-size: 15px;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.3s ease;
    box-shadow: none;
    white-space: nowrap;
}

.chatia-nav-btn:hover {
    transform: translateY(-2px);
    box-shadow: none;
    background: transparent;
}

.chatia-nav-btn:active {
    transform: translateY(0);
}

/* ✅ Badge contador en navbar */
.chatia-nav-btn .chatia-badge {
    position: relative;
    top: auto;
    right: auto;
    background: #ff4444;
    color: white;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    font-size: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    display: none;
    margin-left: 6px;
}

/* ✅ Responsive - botón más compacto en móvil */
@media (max-width: 768px) {
    .chatia-nav-btn {
        padding: 6px 12px;
        font-size: 14px;
		background-color: transparent;
    color: #08010f;
  }
    }
    
    .chatia-nav-btn span:first-child {
        display: none; /* Ocultar texto "Chat IA" en móvil */
    }
    
    .chatia-nav-btn .chatia-badge {
        width: 18px;
        height: 18px;
        font-size: 10px;
    }
}

/* ✅ Eliminar estilos del botón flotante antiguo */
.chatia-floating-btn {
    display: none !important;
}

/* ✅ Badge contador */
.chatia-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #ff4444;
    color: white;
    border-radius: 50%;
    width: 22px;
    height: 22px;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    display: none;
}

/* ✅ Modal */
.chatia-modal {
    display: none;
    position: fixed;
    z-index: 10000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
    animation: fadeInModal 0.3s ease;
}

@keyframes fadeInModal {
    from { opacity: 0; }
    to { opacity: 1; }
}

.chatia-modal-content {
    background: transparent;
    margin: 0;
    padding: 0;
    border: none;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* ✅ Botón cerrar */
.close-btn {
    background: rgba(255,255,255,0.2);
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 20px;
    transition: all 0.3s ease;
    flex-shrink: 0;
    margin-left: 10px;
}

.close-btn:hover {
    background: rgba(255,255,255,0.3);
    transform: rotate(90deg);
}

/* ✅ Responsive modal */
@media (max-width: 768px) {
    .chatia-modal .chat-container {
        max-height: 90vh !important;
        height: 90vh !important;
        border-radius: 15px !important;
    }
    
    .chatia-floating-btn {
        bottom: 20px;
        right: 20px;
        width: 55px;
        height: 55px;
        font-size: 22px;
    }
}

@media (max-width: 480px) {
    .chatia-modal .chat-container {
        max-height: 85vh !important;
        height: 85vh !important;
        margin: 0 10px !important;
    }
    
    .chatia-floating-btn {
        bottom: 15px;
        right: 15px;
        width: 50px;
        height: 50px;
        font-size: 20px;
    }
}

/* ✅ Animación slide up para el modal */
@media (min-width: 769px) {
    .chatia-modal-content {
        animation: slideUp 0.4s ease;
    }
    
    @keyframes slideUp {
        from {
            transform: translateY(100%);
            opacity: 0;
        }
        to {
            transform: translateY(0);
            opacity: 1;
        }
    }
}