/* --- Variables y Estilos Globales --- */
:root {
    --color-primario: #6a11cb;
    --color-secundario: #2575fc;
    --color-error: #e74c3c;
    --color-exito: #2ecc71;
    --color-aviso: #f39c12;
    --color-fondo: #f4f7f6;
    --color-tarjeta: #ffffff;
    --color-texto: #333;
    --color-texto-secundario: #777;
    --gradiente: linear-gradient(135deg, var(--color-primario) 0%, var(--color-secundario) 100%);
    --sombra: 0 4px 12px rgba(0, 0, 0, 0.05);
    --sombra-hover: 0 6px 16px rgba(0, 0, 0, 0.1);
    --radio-borde: 12px;
}

body {
    font-family: 'Poppins', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--color-fondo);
    color: var(--color-texto);
    line-height: 1.6;
    margin: 0;
    padding: 20px;
}

.container {
    max-width: 900px;
    margin: 0 auto;
}

/* Asegurar padding lateral en pantallas pequeñas */
.container {
    padding: 0 20px;
}

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

/* --- NUEVO: Pantalla de Login --- */
#login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - 40px); /* Alto total menos el padding del body */
    animation: fadeIn 0.5s ease-out;
}

.login-card {
    width: 100%;
    max-width: 400px;
    text-align: center;
}
.login-card h2 {
    margin-top: 0;
    color: var(--color-primario);
}
.login-card p {
    margin-bottom: 25px;
    color: var(--color-texto-secundario);
}

.form-grupo-vertical {
    margin-bottom: 20px;
    text-align: left;
}
.form-grupo-vertical label {
    display: block;
    font-weight: 500;
    margin-bottom: 6px;
    font-size: 0.9rem;
}
/* Reutilizamos el estilo del input del formulario principal */
.form-grupo-vertical input {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    background-color: #f9f9f9;
    box-sizing: border-box;
    font-family: 'Poppins', sans-serif;
    font-size: 1rem;
    transition: all 0.2s ease;
}
.form-grupo-vertical input:focus {
    outline: none;
    border-color: var(--color-primario);
    background-color: var(--color-tarjeta);
    box-shadow: 0 0 0 3px rgba(106, 17, 203, 0.1);
}

#login-error {
    color: var(--color-error);
    font-size: 0.9rem;
    margin-top: -10px;
    margin-bottom: 15px;
}

.btn-full-width {
    width: 100%;
    padding: 14px;
}

/* --- NUEVO: Barra de Usuario --- */
.user-bar {
    position: absolute;
    top: 20px;
    right: 30px;
    z-index: 100;
}

.user-profile {
    position: relative;
    cursor: pointer;
}

.user-initials {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    background: var(--gradiente);
    color: white;
    border-radius: 50%;
    font-weight: 600;
    font-size: 1rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
    text-transform: uppercase;
}

.user-profile:hover .user-initials {
    box-shadow: var(--sombra-hover);
    transform: scale(1.05);
}

.user-dropdown {
    display: none; /* Oculto por defecto */
    position: absolute;
    top: 55px; /* Debajo del icono */
    right: 0;
    min-width: 180px;
    background-color: var(--color-tarjeta);
    border-radius: var(--radio-borde);
    box-shadow: var(--sombra-hover);
    overflow: hidden; /* Para que los 'a' respeten el borde redondeado */
    animation: fadeIn 0.3s ease-out; /* Reutilizamos tu animación */
}

/* Mostrar el dropdown al hacer hover sobre el perfil */
.user-profile:hover .user-dropdown {
    display: block;
}

.user-dropdown a {
    display: block;
    padding: 12px 18px;
    text-decoration: none;
    color: var(--color-texto);
    font-size: 0.95rem;
    transition: background-color 0.2s ease;
}

.user-dropdown a:hover {
    background-color: var(--color-fondo);
}

.user-dropdown hr {
    border: 0;
    height: 1px;
    background-color: #eee;
    margin: 5px 0;
}

#btn-logout:hover {
    background-color: #fdf2f2;
    color: var(--color-error);
}


/* --- Encabezado --- */
header {
    text-align: center;
    margin-bottom: 40px;
    margin-top: 30px; /* Damos espacio para el icono de perfil */
}

header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--color-primario);
    margin: 0;
}

header p {
    font-size: 1.1rem;
    color: var(--color-texto-secundario);
    margin-top: 5px;
}

/* --- Tarjetas (Cards) --- */
.card {
    background-color: var(--color-tarjeta);
    border-radius: var(--radio-borde);
    box-shadow: var(--sombra);
    padding: 25px 30px;
    transition: all 0.3s ease-out;
    margin-bottom: 40px;
}

/* No necesitamos :hover en la tarjeta del formulario */
.formulario-card:hover {
    transform: none;
    box-shadow: var(--sombra);
}

/* --- Formularios --- */
.form-inline {
    display: flex;
    gap: 10px;
    flex-wrap: wrap; /* permite que el input y el botón se apilen en pantallas pequeñas */
    align-items: center;
}

.form-grupo {
    flex: 1; /* El grupo del input ocupa todo el espacio */
    margin-bottom: 0;
    min-width: 0; /* evita overflow del input dentro de flex */
}

.form-grupo input[type="text"] {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    background-color: #f9f9f9;
    box-sizing: border-box;
    font-family: 'Poppins', sans-serif;
    font-size: 1rem;
    transition: all 0.2s ease;
}

.form-grupo input:focus {
    outline: none;
    border-color: var(--color-primario);
    background-color: var(--color-tarjeta);
    box-shadow: 0 0 0 3px rgba(106, 17, 203, 0.1);
}

/* --- Botones --- */
.btn {
    padding: 14px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    font-family: 'Poppins', sans-serif;
}

.form-inline .btn-primario {
    width: auto; /* Ancho automático */
    padding-left: 20px;
    padding-right: 20px;
}

.btn-primario {
    background: var(--gradiente);
    color: white;
    width: auto; 
    display: inline-block;
}

.btn-primario:hover {
    opacity: 0.9;
    box-shadow: 0 4px 15px rgba(106, 17, 203, 0.3);
}

.btn-secundario {
    background-color: transparent;
    color: var(--color-primario);
    border: 2px solid var(--color-primario);
    margin-top: 20px;
}

.btn-secundario:hover {
    background-color: var(--color-primario);
    color: white;
    box-shadow: 0 4px 15px rgba(106, 17, 203, 0.2);
}


/* --- Lista de Compras --- */
.lista-container h2 {
    font-weight: 600;
    color: var(--color-primario);
    border-bottom: 2px solid #eee;
    padding-bottom: 10px;
    margin-bottom: 20px;
}

#lista-compras {
    list-style: none;
    padding: 0;
    margin: 0;
}

.item-compra {
    background-color: var(--color-tarjeta);
    border-radius: var(--radio-borde);
    box-shadow: var(--sombra);
    padding: 15px 20px; 
    margin-bottom: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 15px;
    animation: fadeIn 0.5s ease-out;
    transition: all 0.3s ease-out;
}

.item-compra:hover {
    transform: translateY(-3px);
    box-shadow: var(--sombra-hover);
}

/* --- Checkbox Personalizado --- */
.checkbox-container {
    display: block;
    position: relative;
    padding-left: 30px; 
    cursor: pointer;
    font-size: 1rem;
    user-select: none;
    flex-shrink: 0; 
}

.checkbox-container input {
    position: absolute;
    opacity: 0;
    cursor: pointer;
    height: 0;
    width: 0;
}

.checkmark {
    position: absolute;
    top: 50%;
    left: 0;
    transform: translateY(-50%);
    height: 22px;
    width: 22px;
    background-color: #eee;
    border: 1px solid #ddd;
    border-radius: 50%; 
    transition: all 0.3s ease;
}

.checkbox-container:hover input ~ .checkmark {
    background-color: #ccc;
}

.checkbox-container input:checked ~ .checkmark {
    background-color: var(--color-primario);
    border-color: var(--color-primario);
}

.checkmark:after {
    content: "";
    position: absolute;
    display: none;
    left: 7px;
    top: 3px;
    width: 5px;
    height: 10px;
    border: solid white;
    border-width: 0 3px 3px 0;
    transform: rotate(45deg);
}

.checkbox-container input:checked ~ .checkmark:after {
    display: block;
}


/* --- Info y Acciones del Item --- */
.item-compra .info {
    flex: 1; 
    margin-left: 10px; 
}

.item-compra .info h4 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 500;
    transition: all 0.3s ease;
}

.item-compra .acciones {
    display: flex;
    gap: 10px;
}

.btn-eliminar {
    background: transparent;
    border: none;
    color: var(--color-texto-secundario);
    font-size: 1.5rem; 
    font-weight: 600;
    line-height: 1;
    padding: 0 5px;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    cursor: pointer;
    transition: all 0.3s ease;
}
.btn-eliminar:hover {
    background-color: #fdf2f2;
    color: var(--color-error);
}

/* --- Estilo para item Comprado --- */
.item-compra.comprado {
    opacity: 0.7;
    background-color: #fcfcfc;
}

.item-compra.comprado .info h4 {
    text-decoration: line-through;
    color: var(--color-texto-secundario);
}


/* --- Utilidades --- */
.hidden {
    display: none !important;
}

/* ----------------------------- */
/* Reglas responsivas (móvil/tablet) */
@media (max-width: 600px) {
    body {
        padding: 12px 10px;
    }
    
    #login-container {
        min-height: calc(100vh - 24px);
    }

    .container {
        padding: 0;
    }
    
    .user-bar {
        top: 15px;
        right: 15px;
    }

    header h1 {
        font-size: 1.8rem;
    }

    header p {
        font-size: 0.95rem;
    }

    .card {
        padding: 18px;
    }

    .form-inline {
        flex-direction: column;
        gap: 12px;
        align-items: stretch;
    }

    .form-inline .btn-primario {
        width: 100%;
    }

    .item-compra {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
        padding: 12px;
    }

    .item-compra .acciones {
        width: 100%;
        display: flex;
        justify-content: flex-end;
        gap: 8px;
    }

    .btn {
        padding: 12px;
        font-size: 0.95rem;
    }
}

@media (max-width: 400px) {
    header h1 {
        font-size: 1.5rem;
    }
    
    .login-card {
        padding: 15px;
    }

    .form-grupo input {
        padding: 10px;
        font-size: 0.95rem;
    }
    
    .form-grupo-vertical input {
        padding: 10px;
        font-size: 0.95rem;
    }

    .btn {
        padding: 10px;
        font-size: 0.95rem;
    }
}
