:root {
    --bg-color: #0f111a;
    --sidebar-bg: #161b22;
    --chat-bg: #0d1117;
    --primary: #58a6ff;
    --accent: #bc8cff;
    --text-primary: #c9d1d9;
    --text-secondary: #8b949e;
    --input-bg: #21262d;
    --border: #30363d;
    --msg-user: #1f6feb;
    --msg-ai: #21262d;
    
    --font-heading: 'Space Grotesk', sans-serif;
    --font-body: 'Outfit', sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    font-family: var(--font-body);
    height: 100vh;
    overflow: hidden;
}

/* Layout con Bootstrap (row/col) */
.app-container {
    height: 100%;
}

/* Sidebar */
.sidebar {
    background-color: var(--sidebar-bg);
    border-right: 1px solid var(--border);
    padding: 20px;
    display: flex;
    flex-direction: column;
    height: 100%;
}

.brand {
    font-family: var(--font-heading);
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 2rem;
    display: flex;
    align-items: center;
    gap: 10px;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 20px;
}

.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}
.dot.online { background-color: #2ea043; box-shadow: 0 0 8px #2ea043; }

.doc-info {
    padding: 15px;
    background: rgba(255,255,255,0.05);
    border-radius: 8px;
    font-size: 0.85rem;
}
.doc-info code {
    background: rgba(0,0,0,0.3);
    padding: 2px 5px;
    border-radius: 4px;
    color: var(--accent);
}

/* Main Chat */
.chat-interface {
    height: 100%;
    display: flex;
    flex-direction: column;
    background-color: var(--chat-bg);
    position: relative;
}

.chat-container {
    flex: 1;
    padding: 40px;
    /* espacio extra para que no tapen los mensajes el área de entrada fija */
    padding-bottom: 140px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    scroll-behavior: smooth;
    /* Scrollbar visible cuando sea necesario */
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
    /* Asegurar que ocupa todo el viewport disponible */
    max-height: calc(100vh - 140px);
}

.chat-container::-webkit-scrollbar {
    width: 8px;
}
.chat-container::-webkit-scrollbar-track {
    background: transparent;
}
.chat-container::-webkit-scrollbar-thumb {
    background-color: var(--border);
    border-radius: 4px;
}
.chat-container::-webkit-scrollbar-thumb:hover {
    background-color: var(--text-secondary);
}

.message {
    display: flex;
    gap: 15px;
    max-width: 80%;
    animation: fadeIn 0.3s ease;
}

.message.user-message {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.avatar {
    width: 35px;
    height: 35px;
    border-radius: 50%;
    background: var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
}
.ai-message .avatar { background: var(--border); color: var(--primary); }
.user-message .avatar { background: var(--msg-user); color: white; }

.bubble {
    background-color: var(--msg-ai);
    padding: 12px 18px;
    border-radius: 12px;
    line-height: 1.5;
    border: 1px solid var(--border);
    white-space: pre-wrap;
}

.user-message .bubble {
    background-color: var(--msg-user);
    color: white;
    border: none;
    border-bottom-right-radius: 2px;
}

.ai-message .bubble {
    border-top-left-radius: 2px;
}

/* Input Area */
.input-area {
    padding: 20px 40px;
    background-color: var(--sidebar-bg);
    border-top: 1px solid var(--border);
    /* fijar el área de entrada al fondo de la ventana de chat */
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
}

.input-wrapper {
    background-color: var(--input-bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px;
    display: flex;
    align-items: center;
    gap: 10px;
    position: relative;
}

.input-wrapper textarea {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: 1rem;
    resize: none;
    outline: none;
    max-height: 100px;
}

.action-btn {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    font-size: 1.1rem;
    transition: all 0.2s;
    background: transparent;
    color: var(--text-secondary);
}

.action-btn:hover { background: rgba(255,255,255,0.1); color: var(--text-primary); }

.mic-btn.listening {
    color: #f78166;
    animation: pulse 1.5s infinite;
}

.send-btn { color: var(--primary); }
.send-btn:hover { background: var(--primary); color: white; }

.icon-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1rem;
    padding: 5px;
}
.icon-btn:hover { color: var(--text-primary); }
.icon-btn.active { color: var(--accent); }

.voice-status {
    position: absolute;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(247, 129, 102, 0.2);
    color: #f78166;
    padding: 5px 15px;
    border-radius: 20px;
    font-size: 0.8rem;
    border: 1px solid #f78166;
    animation: fadeIn 0.2s;
}

.voice-status.hidden { display: none; }

/* PWA Install Button */
.install-section {
    margin-top: auto;
    padding-top: 20px;
}

.install-btn {
    width: 100%;
    padding: 12px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: white;
    border: none;
    border-radius: 8px;
    font-family: var(--font-body);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-bottom: 10px;
}

.install-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(88, 166, 255, 0.3);
}

.install-btn:active {
    transform: translateY(0);
}

.install-btn i {
    font-size: 1rem;
}

.install-status {
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-align: center;
    padding: 5px;
}

.install-status.success {
    color: #2ea043;
}

.install-status.error {
    color: #f78166;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes pulse {
    0% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.1); opacity: 0.7; }
    100% { transform: scale(1); opacity: 1; }
}

/* Responsive Design */
@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
    }
    
    #sidebar {
        width: 100%;
        height: 70px;
        padding: 15px;
        border-right: none;
        border-bottom: 1px solid var(--border);
        position: sticky;
        top: 0;
        z-index: 10;
        background-color: var(--sidebar-bg);
    }
    
    .brand {
        font-size: 1.2rem;
        margin-bottom: 1rem;
    }
    
    .status-indicator {
        font-size: 0.8rem;
        margin-bottom: 10px;
    }
    
    .doc-info {
        font-size: 0.75rem;
        padding: 10px;
        display: none; /* Ocultar en móvil */
    }
    
    .chat-container {
        padding: 20px;
        gap: 15px;
        max-height: calc(100vh - 240px); /* Más espacio en móvil */
    }
    
    .message {
        max-width: 90%;
    }
    
    .input-area {
        padding: 15px 20px;
    }
    
    .input-wrapper {
        padding: 8px;
        gap: 8px;
    }
    
    .action-btn {
        width: 36px;
        height: 36px;
        font-size: 1rem;
    }
    
    .input-wrapper textarea {
        font-size: 0.9rem;
    }
}

@media (max-width: 480px) {
    #sidebar {
        padding: 10px;
        height: 70px;
    }
    
    .brand {
        font-size: 1.1rem;
    }
    
    .brand span {
        display: none;
    }
    
    .brand::after {
        content: "A²I";
        font-size: 1.1rem;
    }
    
    .status-indicator {
        display: none; /* Ocultar también el status-indicator en móvil pequeño */
    }
    
    .doc-info {
        display: none; /* Mantener oculto */
    }
    
    .chat-container {
        padding: 15px;
        max-height: calc(100vh - 200px); /* Ajuste para pantallas pequeñas */
    }
    
    .message {
        max-width: 95%;
        gap: 10px;
    }
    
    .avatar {
        width: 30px;
        height: 30px;
    }
    
    .bubble {
        padding: 10px 14px;
        font-size: 0.9rem;
    }
    
    .input-area {
        padding: 10px 15px;
    }
    
    .input-wrapper {
        padding: 6px;
        gap: 6px;
    }
    
    .action-btn {
        width: 32px;
        height: 32px;
        font-size: 0.9rem;
    }
    
    .input-wrapper textarea {
        font-size: 0.85rem;
    }
}

@media (orientation: landscape) and (max-height: 500px) {
    #sidebar {
        padding: 8px;
        height: 60px;
    }
    
    .brand {
        font-size: 1rem;
        margin-bottom: 0.5rem;
    }
    
    .status-indicator {
        margin-bottom: 5px;
    }
    
    .doc-info {
        display: none;
    }
    
    .chat-container {
        padding: 10px;
        gap: 10px;
        max-height: calc(100vh - 160px); /* Ajuste para modo landscape */
    }
    
    .bubble {
        padding: 8px 12px;
        font-size: 0.85rem;
    }
    
    .input-area {
        padding: 8px 15px;
    }
}
