/* =========================================
   1. VARIABLES: PALETA PASTEL & CONFIG
   ========================================= */
:root {
    /* Fondo General (Crema muy suave) */
    --bg-body: #7339a3dc;

    /* Contenedor Principal (Blanco puro) */
    --bg-card: #FFFFFF;

    /* Textos (Gris Carbón - más suave que el negro) */
    --text-primary: #4A4A4A;
    --text-secondary: #8C8C8C;

    --side-bar-card: rgba(79, 35, 161, 0.856);

    /* Acciones Pastel (Colores estilo "Macaron") */
    --color-primary: #A0C4FF;
    /* Azul Cielo suave (Crear) */
    --color-success: #6ed478;
    /* Menta (Completar) */
    --color-danger: #fa7b72;
    /* Rosa Salmón (Borrar) */
    --color-warning: #FDFFB6;
    /* Amarillo Vainilla (Editar) */


    /* UI Helpers */
    --radius: 16px;
    /* Bordes muy redondeados */
    --shadow-soft: 0 10px 40px rgba(0, 0, 0, 0.05);
    /* Sombra difusa */
    --shadow-hover: 0 15px 45px rgba(0, 0, 0, 0.08);
}

/* Reset Básico (Asegúrate de incluir el reset que te pasé antes al inicio) */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

ul {
    list-style: none;
}

button {
    border: none;
    outline: none;
    background: none;
    font-family: inherit;
}

/* =========================================
   2. CUERPO Y LAYOUT
   ========================================= */
body {
    background-color: var(--bg-body);
    color: var(--text-primary);
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    /* Centrado total en pantalla */
    padding: 20px;
    padding-left: 300px;
}

/* =========================================
   3. CONTENEDOR PRINCIPAL (La Tarjeta)
   ========================================= */
.todo-container {
    background-color: var(--bg-card);
    width: 100%;
    max-width: 750px;
    border-radius: var(--radius);
    padding: 2.5rem;
    box-shadow: var(--shadow-soft);
}

.header-main {
    text-align: center;
    margin-bottom: 2.5rem;
}

.titulo {
    font-size: 1.8rem;
    font-weight: 800;
    letter-spacing: -1px;
    /* Estilo moderno */
    color: var(--text-primary);
    position: relative;
    display: inline-block;
}

/* Pequeño adorno pastel debajo del título */
.titulo::after {
    content: '';
    position: absolute;
    bottom: 2px;
    left: 0;
    width: 100%;
    height: 8px;
    background-color: var(--color-primary);
    opacity: 0.3;
    z-index: -1;
    border-radius: 4px;
}

/* =========================================
   4. INPUT AREA
   ========================================= */
.input-container {
    display: flex;
    gap: 12px;
    margin-bottom: 2rem;
    /* Fondo gris muy tenue para el input group */
    padding: 8px;
    border-radius: var(--radius);
    text-align: center;
    width: 100%;
}

.input-container input {
    text-align: center;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
}

#todo-task-name {
    flex-grow: 0.3;
}

#todo-task-description {
    flex-grow: 0.7;
}

#todo-input {
    flex: 1;
    background: transparent;
    border: none;
    padding: 10px 15px;
    font-size: 1rem;
    color: var(--text-primary);
}

#todo-input::placeholder {
    color: #B0B0B0;
}

.btn-add {
    background-color: rgba(71, 139, 248, 0.658);
    color: white;
    /* Texto blanco en el botón principal */
    font-weight: 600;
    padding: 10px 24px;
    border-radius: 12px;
    /* Un poco menos redondeado que el container */
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 4px 10px rgba(160, 196, 255, 0.4);
}

.btn-add:hover {
    transform: translateY(-2px);
    background-color: #477bce;
}

/* =========================================
   5. LISTA DE ITEMS (Tarjetas Internas)
   ========================================= */
.todo-list {
    display: flex;
    flex-direction: column;
    gap: 18px;
    border-radius: 1;
    padding: 20px;
}

.todo-item {
    background-color: #FFFFFF;
    border: 1px solid #F0F0F0;
    /* Borde casi invisible */
    border-radius: var(--radius);
    padding: 20px;
    transition: all 0.3s ease;
    position: relative;
    border: 2px solid rgb(50, 50, 92);
}

.todo-item:hover {
    border-color: #2562c5;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.03);
    transform: translateY(-2px);
}

/* Header del Item */
.list-item-header {
    margin-bottom: 8px;
}

.list-item-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
}

/* Cuerpo del Item */
.list-item-body {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.list-item-description {
    font-size: 0.95rem;
    color: var(--text-secondary);
    line-height: 1.4;
    margin-right: 15px;
}

.list-item-completed {
    font-size: 0.75rem;
    font-weight: 600;
    padding: 4px 10px;
    background-color: #F0F2F5;
    color: var(--text-secondary);
    border-radius: 20px;
    white-space: nowrap;
    /* Evita que el texto baje */
}

/* =========================================
   6. BOTONES DE ACCIÓN (Estilo Pastel)
   ========================================= */
.acciones {
    display: flex;
    gap: 10px;
}

.todo-btn {
    border: none;
    outline: none;
    font-family: inherit;
    cursor: pointer;

    /* Estructura */
    display: inline-flex;
    justify-content: center;
    align-items: center;
    padding: 10px 16px;
    border-radius: 12px;
    /* Radio consistente */
    font-weight: 600;
    font-size: 0.95rem;

    /* Transiciones suaves para todos */
    transition: all 0.2s ease;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
    /* Sombra sutil base */
}

.btn-action {
    flex: 1;
    padding: 10px;
    border-radius: 10px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: filter 0.2s;

    /* En pastel, usamos texto oscuro para legibilidad */
    color: #555;
}

.btn-action:hover {
    /* Oscurece un poquito al pasar el mouse */
    filter: brightness(0.88);
}

/* Colores Específicos */
.btn-check {
    background-color: var(--color-success);
}

.btn-delete {
    background-color: var(--color-danger);
}

.btn-update {
    background-color: var(--color-warning);
}

/* =========================================
   7. FOOTER
   ========================================= */
.todo-footer {
    margin-top: 2.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top: 2px solid #fad2d281;
    padding-top: 1.5rem;
}

#contador {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.btn-clear-all {
    font-size: 0.9rem;
    color: white;
    background-color: var(--color-danger);
    font-weight: 500;
    cursor: pointer;
}

.btn-clear-all:hover {
    background-color: rgba(218, 11, 11, 0.589);
}

/* Clase que tu JS agrega */
.green-container {
    /* Aseguramos que el color cambie */
    background-color: #d4edda !important;
    border-color: #c3e6cb !important;

    /* ACTIVAMOS LA ANIMACIÓN */
    /* Dura 0.8s (800ms) para coincidir EXACTAMENTE con tu setTimeout */
    animation: completedExit 0.8s forwards;

    /* Opcional: deshabilitar interacción mientras se anima */
    pointer-events: none;
}

/* Definición de la animación */
@keyframes completedExit {
    0% {
        opacity: 1;
        transform: scale(1);
    }

    40% {
        /* Se mantiene visible un ratito para ver el check verde */
        opacity: 1;
        transform: scale(1);
    }

    100% {
        opacity: 0;
        /* Efecto visual: se achica y se va un poco a la izquierda (hacia el sidebar) */
        transform: scale(0.8) translateX(-50px);
    }
}

/* Animación de entrada para el sidebar */
.slide-in-left {
    animation: slideInLeft 0.5s ease-out;
}

@keyframes slideInLeft {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* =========================================
   8. MODAL
   ========================================= */

/* 1. El Contenedor Principal (El Overlay/Fondo oscuro) */
.modal-container {
    /* Oculto por defecto */
    display: none;

    /* Fijo en la pantalla, ignora el scroll */
    position: fixed;

    /* Siempre encima de todo */
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    /* Negro con transparencia */
    background-color: rgba(0, 0, 0, 0.5);

    /* Flexbox para centrar la caja perfectamente */
    justify-content: center;
    align-items: center;
}

/* Clase para mostrar el modal desde JS */
.modal-container.show {
    display: flex;
}

/* 2. La Caja del Modal (El contenido blanco) */
.modal-content {
    background-color: #fff;
    padding: 20px;
    border-radius: 8px;
    width: 90%;
    max-width: 400px;
    /* Que no sea gigante en PC */
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
    animation: modalFadeIn 0.3s;
    /* Pequeña animación de entrada */
}

/* Estilos internos del modal */
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.close-modal {
    cursor: pointer;
    font-size: 24px;
    font-weight: bold;
    color: #aaa;
}

.close-modal:hover {
    color: #000;
}

.modal-body {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 20px;
}

.modal-body input,
.modal-body textarea {
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
}


.modal-body textarea {
    height: 150px;
    resize: none;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    /* Botones a la derecha */
    gap: 10px;
}

/* Botones específicos del modal */
.btn-cancel {
    background-color: #ccc;
    color: #161616;
}

.btn-cancel:hover {
    background-color: #949494;
}

.btn-save {
    background-color: #28a745;
    /* Verde para guardar */
    color: white;
}

.btn-save:hover {
    background-color: #208137;
}

/* Animación simple */
@keyframes modalFadeIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}


/* =========================================
   9. SIDEBAR (Tareas Completadas)
   ========================================= */

.sidebar-container {
    position: fixed;
    /* Se queda quieto al scrollear */
    left: 0;
    top: 0;
    width: 300px;
    /* El 20% aprox, fijo en px para consistencia */
    height: 100vh;
    /* Ocupa todo el alto */

    background-color: var(--bg-card);
    box-shadow: 2px 0 20px rgba(0, 0, 0, 0.05);
    /* Sombra suave a la derecha */
    z-index: 500;
    /* Por debajo del Modal (que es 1000), pero encima del contenido */

    display: flex;
    flex-direction: column;
    padding: 2rem 1.5rem;
}

.sidebar-header {
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 2px solid #F5F7FA;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sidebar-title {
    font-size: 1.2rem;
    font-weight: 800;
    color: var(--text-primary);
}

.sidebar-counter {
    background-color: var(--color-success);
    color: white;
    font-size: 0.75rem;
    font-weight: bold;
    padding: 2px 8px;
    border-radius: 12px;
}

/* Área de Scroll Independiente */
.sidebar-scroll-area {
    flex: 1;
    /* Ocupa el espacio restante verticalmente */
    overflow-y: auto;
    /* Scroll solo si hace falta */
    padding-right: 5px;
    /* Espacio para que el scrollbar no pegue al texto */
}

/* Estilo del Scrollbar (Opcional, para que se vea bonito en Chrome/Edge) */
.sidebar-scroll-area::-webkit-scrollbar {
    width: 6px;
}

.sidebar-scroll-area::-webkit-scrollbar-thumb {
    background-color: #e0e0e0;
    border-radius: 4px;
}

/* --- Estilos de las "Cards Resumidas" --- */
.completed-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.completed-list-task {
    display: flex;
    justify-content: space-between;
    background: var(--side-bar-card);
    padding: 20px;
    border-radius: 12px;
}

/* El contenedor de la lista */
.sidebar-scroll-area {
    padding-right: 10px;
    /* Espacio para scroll */
    overflow-y: auto;
    max-height: calc(100vh - 100px);
    /* Ajuste para que no se salga */
}

/* El <li> wrapper que contendrá tu estructura */
.completed-card {
    background-color: #fff;
    border: 1px solid #f0f0f0;
    border-radius: 12px;
    padding: 12px;
    margin-bottom: 12px;

    /* Layout horizontal: Texto a la izquierda, Check a la derecha */
    display: flex;
    justify-content: space-between;
    align-items: center;

    transition: all 0.2s ease;
    border-left: 4px solid var(--color-success);
    /* Borde verde característico */
}

.completed-card:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    transform: translateX(2px);
}

/* --- Tu estructura interna --- */

/* 1. Contenedor de Texto (Título + Fecha) */
.completed-item-container {
    display: flex;
    flex-direction: column;
    gap: 4px;
    overflow: hidden;
    /* Para que el texto largo no rompa todo */
}

.completed-item-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: white;
    margin: 0;

    /* Puntos suspensivos si es muy largo */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 180px;
}

.completed-item-datetime {
    font-size: 0.8rem;
    color: #ccc;
    margin: 0;
    font-style: italic;
}

/* 2. El Icono del Check */
.completed-item-check {
    display: flex;
    align-items: center;
}

.completed-item-check span {
    font-size: 1.2rem;
    /* No hace falta color, el emoji ya tiene color. 
       Si usaras un icono SVG, aquí pondrías var(--color-success) */
}


/* =========================================
   10. RESPONSIVE DESIGN (Móviles)
   ========================================= */

@media (max-width: 600px) {

    /* 1. Ajustes Generales del Cuerpo */
    body {
        padding: 10px;       /* Quitamos el padding-left: 300px */
        flex-direction: column; /* Apilamos los elementos verticalmente */
        justify-content: flex-start; /* Alineación superior */
        height: auto; /* Permitir scroll en el body */
    }

    /* 2. REPARACIÓN DEL SIDEBAR */
    /* Lo convertimos de una barra lateral fija a un bloque al final de la página */
    .sidebar-container {
        position: relative; /* Ya no flota fijo */
        width: 100%;        /* Ancho completo del móvil */
        height: auto;       /* Altura automática, no 100vh */
        top: auto;
        left: auto;
        
        box-shadow: none;   /* Quitamos sombra lateral */
        border-top: 4px solid #e0e0e0; /* Separador visual arriba */
        
        /* Usamos 'order' para mandarlo al final, debajo de la App principal */
        order: 2; 
        margin-top: 2rem;
        border-radius: var(--radius);
        z-index: 1; /* Bajamos el nivel para que no tape modales */
    }

    /* Ajuste del área de scroll dentro del sidebar móvil */
    .sidebar-scroll-area {
        max-height: 300px; /* Altura máxima para que no sea eterno */
        overflow-y: auto;
    }

    /* 3. Contenedor Principal (La App de tareas) */
    .todo-container {
        order: 1; /* Aparece PRIMERO visualmente */
        padding: 1.5rem;
        width: 100%;
        margin-bottom: 20px;
    }

    .titulo {
        font-size: 1.5rem;
    }

    /* 4. Área de Inputs (Stacked/Apilada) */
    .input-container {
        flex-direction: column;
        gap: 10px;
        background: transparent;
        padding: 0;
    }

    .input-container input {
        width: 100%;
        background: #F5F7FA;
        border-radius: 12px;
        padding: 12px;
    }

    .btn-add {
        width: 100%;
        margin-top: 5px;
    }

    /* 5. Lista de Tareas */
    .todo-item {
        padding: 15px;
    }

    .list-item-body {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    .list-item-completed {
        align-self: flex-start;
        font-size: 0.7rem;
    }

    /* 6. Botones de Acción */
    .acciones {
        flex-wrap: wrap;
    }

    .btn-action {
        flex: 1 1 100%; /* Botones anchos para dedos */
        min-width: 80px;
        padding: 12px;
    }

    /* 7. Modal Responsive */
    .modal-content {
        width: 95%;
        padding: 15px;
        margin: 10px;
    }

    .modal-footer {
        flex-direction: column-reverse;
        gap: 10px;
    }

    .modal-footer button {
        width: 100%;
    }
}