:root {
    --bg-main: #131314;
    --bg-side: #1e1f20;
    --bg-input: #1e1f20;
    --accent-blue: #4d91ff;
    --text-main: #e3e3e3;
    --text-sub: #b4b4b4;
    --hover-bg: #2d2f31;
    --avatar-user: #555;
    --avatar-ai: linear-gradient(135deg, #4285f4, #9b72cb);
}

* { box-sizing: border-box; transition: background 0.2s ease; }

body { 
    margin: 0; 
    background: var(--bg-main); 
    color: var(--text-main); 
    font-family: 'Outfit', sans-serif; 
    display: flex; 
    height: 100vh;
    overflow: hidden;
}

/* --- SIDEBAR --- */
.sidebar { 
    width: 280px; 
    min-width: 280px;
    background: var(--bg-side); 
    display: flex; 
    flex-direction: column; 
    padding: 16px;
    border-right: 1px solid #333;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
    white-space: nowrap;
    z-index: 1000;
}

.sidebar.collapsed {
    width: 0px;
    min-width: 0px;
    padding: 0;
    margin: 0;
    border: none;
    opacity: 0;
    pointer-events: none;
}

.top-side {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 20px;
    padding-top: env(safe-area-inset-top); /* Respeta el notch en horizontal */
}

.menu-btn, .menu-toggle-alt {
    background: transparent;
    border: none;
    color: var(--text-main);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent; /* Quita el recuadro gris feo al tocar */
    touch-action: manipulation; /* Optimiza el toque */
}

.menu-btn:hover, .menu-toggle-alt:hover { background: var(--hover-bg); }

/* El botón alternativo solo aparece cuando el sidebar está cerrado */
.menu-toggle-alt { display: none; }
.sidebar.collapsed + .main-content .menu-toggle-alt { display: flex; }



.new-chat-btn {
    background: #1a1b1c;
    border: 1px solid #444;
    color: var(--text-main);
    padding: 12px 20px;
    border-radius: 50px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.9rem;
    width: 100%;
}

/* --- MAIN CONTENT --- */
.main-content { flex: 1; display: flex; flex-direction: column; position: relative; width: 100%; }

.top-bar { 
    display: flex; 
    justify-content: space-between; 
    padding: 12px 24px; 
    align-items: center;
}

select#modelSelect {
    background: var(--bg-side);
    color: var(--text-main);
    border: 1px solid #444;
    padding: 8px 12px;
    border-radius: 8px;
    outline: none;
}

/* --- CHAT VIEWPORT --- */
.chat-viewport { 
    flex: 1; 
    overflow-y: auto; 
    padding: 20px 15%;
    display: flex;
    flex-direction: column;
}

.welcome-screen {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.gradient-text {
    font-size: 3.2rem;
    font-weight: 600;
    background: linear-gradient(90deg, #4285f4, #9b72cb, #d96570);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* --- MENSAJES --- */
.msg { 
    display: flex; 
    gap: 16px; 
    margin-bottom: 32px; 
    width: 100%;
    animation: fadeIn 0.4s ease forwards;
}

.avatar { 
    width: 36px; 
    height: 36px; 
    border-radius: 50%; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    font-size: 12px; 
    font-weight: bold;
    flex-shrink: 0;
    color: white;
}

.msg.assistant .avatar { background: var(--avatar-ai); }
.msg.user .avatar { background: var(--avatar-user); order: 2; }

.txt { 
    line-height: 1.6; 
    font-size: 1rem; 
    padding-top: 6px;
    word-break: break-word;
}

.msg.user { justify-content: flex-end; }
.msg.user .txt { 
    background: #2b2c2f; 
    padding: 12px 20px; 
    border-radius: 22px; 
    max-width: 75%;
    order: 1;
}

/* --- INPUT AREA --- */
.input-area { padding: 10px 15% 30px 15%; }
.input-container {
    background: var(--bg-input);
    border-radius: 32px;
    display: flex;
    align-items: flex-end;
    padding: 10px 20px;
    border: 1px solid #444;
}

textarea {
    flex: 1;
    background: transparent;
    border: none;
    color: white;
    padding: 10px 0;
    resize: none;
    font-size: 1rem;
    outline: none;
}

.send-button { background: transparent; border: none; cursor: pointer; color: var(--accent-blue); }

@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.pulse { animation: pulseAni 1.5s infinite; }
@keyframes pulseAni { 0%, 100% { opacity: 0.3; } 50% { opacity: 1; } }

/* --- RESPONSIVE OPTIMIZADO PARA IPHONE --- */
@media (max-width: 768px) {
    body {
        /* dvh ajusta el alto real ignorando las barras de Safari */
        height: 100dvh; 
    }

    .sidebar { 
        position: absolute; 
        z-index: 100; 
        height: 100%; 
        box-shadow: 10px 0 15px rgba(0,0,0,0.5);
    }

    /* Reducimos el padding lateral drásticamente para que no se vea aplastado */
    .chat-viewport { 
        padding: 20px 15px; 
    }

    .input-area { 
        padding: 10px 10px 25px 10px; 
    }

    .input-container {
        padding: 8px 15px;
    }

    .gradient-text { 
        font-size: 2.5rem; 
    }

    /* Evita que Safari haga zoom automático al enfocar el textarea */
    textarea {
        font-size: 16px; 
    }
}

/* Ajuste extra para iPhones muy pequeños (iPhone SE, etc) */
@media (max-width: 380px) {
    .gradient-text {
        font-size: 2rem;
    }
    .top-bar {
        padding: 8px 15px;
    }
}