:root {
    --dark-bg: #1a1a1a;
    --darker-bg: #0d0d0d;
    --light-text: #ffffff;
    --accent-blue: #074e96;
    --accent-green: #25D366;
    --accent-red: #FF3333;
    --border-color: #333333;
    --item-bg: #2a2a2a;
    --radio-borde: 8px;
    --espaciado: 12px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Roboto', sans-serif;
    background-color: var(--dark-bg);
    color: var(--light-text);
    line-height: 1.6;
    padding: 10px;
}

.contenedor-principal {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: var(--espaciado);
    position: relative;
}

/* Barra superior */
.barra-superior {
    background-color: var(--darker-bg);
    padding: 10px;
    border-radius: var(--radio-borde);
    border: 1px solid var(--border-color);
    position: sticky;
    top: 0;
}

.controles-superiores {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 10px;
}

.fila-botones {
    display: flex;
    gap: 8px;
    width: 100%;
}

.fila-botones button {
    flex: 1;
}

.total-global {
    font-weight: bold;
    font-size: 1.25em;
    text-align: center;
    padding: 5px 0;
}

/* Botones */
button {
    border: none;
    border-radius: var(--radio-borde);
    padding: 10px;
    cursor: pointer;
    transition: background-color 0.3s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    font-weight: 500;
    color: white;
    font-family: inherit;
    font-size: 1em;
}

button i {
    font-size: 1.2em;
}

button span {
    font-size: 1em;
    text-align: center;
}

.boton-primario { background-color: var(--accent-blue); }
.boton-primario:hover { background-color: #1a7fd9; }

.boton-whatsapp { background-color: var(--accent-green); }
.boton-whatsapp:hover { background-color: #1ea851; }

.boton-importar { background-color: #555; }
.boton-importar:hover { background-color: #666; }

.boton-historial { background-color: #9c27b0; }
.boton-historial:hover { background-color: #7b1fa2; }

.boton-guardar-todo { background-color: #ff9800; }
.boton-guardar-todo:hover { background-color: #f57c00; }

.boton-aceptar { background-color: var(--accent-green); }
.boton-aceptar:hover { background-color: #1ea851; }

.boton-cancelar { background-color: var(--accent-red); }
.boton-cancelar:hover { background-color: #d93636; }


/* Botón copiar */
.boton-copiar { 
    background-color: #0723c2; 
}
.boton-copiar:hover { 
    background-color: #0906ac; 
}

/* Botones del historial */
.botones-historial {
    display: flex;
    gap: 8px;
    margin-top: 10px;
    justify-content: flex-end;
    flex-wrap: wrap;
}

.boton-copiar-historial,
.boton-compartir-historial,
.boton-eliminar-historial {
    padding: 6px 10px;
    font-size: 0.8em;
    border: none;
    border-radius: var(--radio-borde);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
}

.boton-copiar-historial {
    background-color: #0723c2;
    color: white;
}

.boton-copiar-historial:hover {
    background-color: #0906ac;
}

.boton-compartir-historial {
    background-color: var(--accent-green);
    color: white;
}

.boton-compartir-historial:hover {
    background-color: #1ea851;
}

.boton-eliminar-historial {
    background-color: var(--accent-red);
    color: white;
}

.boton-eliminar-historial:hover {
    background-color: #d93636;
}

/* Áreas de importación e historial */
.contenedor-importacion, .contenedor-historial {
    background-color: var(--darker-bg);
    padding: var(--espaciado);
    border-radius: var(--radio-borde);
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: var(--espaciado);
    animation: aparecer 0.3s ease-out;
}

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

.contenedor-textarea {
    width: 100%;
}

#areaTextoImportar {
    width: 100%;
    padding: var(--espaciado);
    border: 1px solid var(--border-color);
    border-radius: var(--radio-borde);
    min-height: 100px;
    resize: vertical;
    font-family: inherit;
    background-color: var(--dark-bg);
    color: var(--light-text);
}

.controles-importacion, .controles-historial {
    display: flex;
    justify-content: flex-end;
    gap: var(--espaciado);
}

/* Listas de compras */
.contenedor-listas {
    display: flex;
    flex-direction: column;
    gap: var(--espaciado);
    position: relative;
    isolation: isolate;
}

.lista-compras {
    background-color: var(--darker-bg);
    border-radius: var(--radio-borde);
    border: 1px solid var(--border-color);
    overflow: visible;
    position: relative;
}

.cabecera-lista {
    padding: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    background-color: rgba(0, 0, 0, 0.1);
    gap: 10px;
    min-height: 44px;
}

.flecha-lista {
    flex-shrink: 0;
    transition: transform 0.3s ease;
    color: #ccc;
    margin-right: 5px;
}

.titulo-lista {
    font-weight: 500;
    flex: 1;
    outline: none;
    background-color: transparent;
    color: var(--light-text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
    padding: 2px 0;
    border: 1px solid transparent;
    border-radius: 3px;
    transition: border-color 0.2s;
}

.titulo-lista:focus {
    border-color: var(--accent-blue);
    background-color: rgba(43, 150, 255, 0.1);
}

.controles-lista {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.boton-incluir {
    padding: 6px;
    font-size: 0.8em;
    width: auto;
    flex-direction: row;
    min-height: auto;
    flex-shrink: 0;
}

.boton-incluir.incluido { background-color: var(--accent-green); }
.boton-incluir.excluido { background-color: var(--accent-red); }

.boton-menu {
    padding: 6px;
    font-size: 0.8em;
    width: auto;
    flex-direction: row;
    min-height: auto;
    flex-shrink: 0;
    background-color: var(--item-bg);
    color: white;
    border-radius: 4px;
    transition: background-color 0.3s ease;
}

.boton-menu:hover {
    background-color: #3a3a3a;
}

.suma-lista {
    font-weight: bold;
    min-width: 70px;
    text-align: right;
    margin-right: 5px;
    font-size: 1em;
    flex-shrink: 0;
}

.contenido-lista {
    padding: var(--espaciado);
}

.lista-cerrada .contenido-lista {
    display: none;
}

.contenedor-agregar {
    display: flex;
    gap: var(--espaciado);
    margin-bottom: var(--espaciado);
}

.input-producto {
    flex-grow: 1;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: var(--radio-borde);
    background-color: var(--dark-bg);
    color: var(--light-text);
    font-family: inherit;
}

.input-producto:focus {
    outline: none;
    border-color: var(--accent-blue);
}

.boton-agregar {
    background-color: var(--accent-blue);
    padding: 10px;
    width: auto;
    flex-direction: row;
}

.lista-productos {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: var(--espaciado);
}

/* PRODUCTOS - SISTEMA GRID PARA PANTALLA GRANDE (UNA FILA) */
.producto {
    display: grid;
    grid-template-columns: 1fr auto auto auto auto auto auto;
    align-items: center;
    padding: 10px;
    border-radius: var(--radio-borde);
    background-color: var(--item-bg);
    border-left: 3px solid var(--accent-blue);
    gap: 10px;
}

.producto-marcado {
    opacity: 0.7;
    text-decoration: line-through;
    border-left-color: var(--accent-green);
}

/* Nombre del producto editable */
.nombre-producto {
    font-size: 1.2em;
    line-height: 1.4;
    word-break: break-word;
    padding: 8px;
    border: 1px solid transparent;
    border-radius: 4px;
    background-color: transparent;
    color: var(--light-text);
    outline: none;
    transition: border-color 0.2s;
    min-height: 38px;
    display: flex;
    align-items: center;
}

.nombre-producto:focus {
    border-color: var(--accent-blue);
    background-color: rgba(43, 150, 255, 0.1);
}

/* Botón quitar de la suma */
.boton-quitar {
    background: none;
    border: none;
    color: var(--accent-green);
    cursor: pointer;
    font-size: 1em;
    padding: 8px;
    transition: color 0.3s;
    justify-self: center;
    border-radius: 4px;
}

.boton-quitar.quitado {
    color: var(--accent-red);
}

.boton-quitar:hover {
    background-color: rgba(255, 51, 51, 0.1);
}

.boton-carrito {
    background: none;
    border: none;
    color: #ccc;
    cursor: pointer;
    font-size: 1.2em;
    padding: 8px;
    transition: color 0.3s;
    justify-self: center;
    border-radius: 4px;
}

.boton-carrito.activo {
    color: var(--accent-green);
}

.boton-carrito:hover {
    background-color: rgba(37, 211, 102, 0.1);
}

/* Campos de entrada alineados a la derecha */
.input-cantidad, .input-precio, .input-total {
    padding: 4px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background-color: var(--dark-bg);
    color: var(--light-text);
    text-align: right;
    font-family: inherit;
    -moz-appearance: textfield;
    appearance: textfield;
    height: 38px;
    box-sizing: border-box;
}

.input-cantidad {
    width: 50px;
}

.input-precio {
    width: 135px;
}

.input-total {
    width: 165px;
    background-color: #3a3a3a;
    font-weight: bold;
    cursor: not-allowed;
}

.input-cantidad::-webkit-outer-spin-button,
.input-cantidad::-webkit-inner-spin-button,
.input-precio::-webkit-outer-spin-button,
.input-precio::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.boton-eliminar-item {
    background-color: var(--accent-red);
    padding: 8px 12px;
    border: none;
    border-radius: 4px;
    color: white;
    cursor: pointer;
    justify-self: end;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.boton-eliminar-item:hover {
    background-color: #d93636;
}

/* Eliminamos las estructuras de producto-superior e inferior para desktop */
.producto-superior,
.producto-inferior {
    display: contents;
}

/* Menú desplegable */
.menu-desplegable {
    display: inline-block;
    position: relative;
    flex-shrink: 0;
}

.opciones-menu {
    display: none;
    position: absolute;
    background-color: var(--darker-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radio-borde);
    min-width: 160px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.7);
    overflow: hidden;
    right: 0;
    top: 100%;
    z-index: 1000;
    transform: translateZ(0);
}

.opciones-menu.mostrado {
    display: block;
}

.opcion-menu {
    width: 100%;
    text-align: center;
    padding: 10px 5px;
    border-radius: 0;
    border-bottom: 1px solid var(--border-color);
    font-size: 1em;
    justify-content: flex-start;
    flex-direction: row;
    gap: 8px;
    display: block;
    color: var(--light-text);
    background-color: var(--darker-bg);
    transition: background-color 0.2s ease;
}

.opcion-menu:last-child {
    border-bottom: none;
}

.opcion-menu:hover {
    background-color: var(--dark-bg);
}

/* Historial */
.lista-historial {
    max-height: 400px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: var(--espaciado);
}

.item-historial {
    background-color: var(--item-bg);
    padding: var(--espaciado);
    border-radius: var(--radio-borde);
    border: 1px solid var(--border-color);
}

.cabecera-historial {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    margin-bottom: 8px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-color);
}

.nombre-historial {
    font-weight: bold;
    font-size: 1em;
}

.fecha-historial {
    color: #ccc;
    font-size: 1em;
}

.contenido-historial {
    color: #ccc;
    font-size: 1em;
}

.boton-eliminar-historial {
    background-color: var(--accent-red);
    padding: 6px 10px;
    font-size: 0.7em;
}

.productos-historial {
    margin-top: 10px;
    border-top: 1px solid var(--border-color);
    padding-top: 10px;
}

.producto-item-historial {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid #333;
    font-size: 1em;
}

.producto-item-historial:last-child {
    border-bottom: none;
}

.producto-item-historial.marcado {
    opacity: 0.6;
    text-decoration: line-through;
}

.producto-item-historial.en-carrito {
    background-color: rgba(37, 211, 102, 0.1);
}

.estado-producto {
    width: 30px;
    text-align: center;
    font-size: 1em;
}

.nombre-producto-historial {
    flex: 1;
    margin: 0 10px;
    word-break: break-word;
}

.detalles-producto {
    min-width: 120px;
    text-align: right;
    color: #ccc;
    font-size: 1em;
}

.total-historial {
    text-align: right;
    margin-bottom: 10px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border-color);
}

/* Estados */
.oculto {
    display: none !important;
}


@media (max-width: 768px) {
    .producto {
        display: flex;
        flex-direction: column;
        align-items: stretch;
        padding: 5px;
        gap: 10px;
    }
    
    /* PRIMERA FILA: Nombre editable y botones de acción */
    .producto-superior {
        display: grid;
        grid-template-columns: 1fr auto auto auto;
        align-items: center;
        width: 100%;
        gap: 8px;
        order: 1;
    }
    
    .nombre-producto {
        font-size: 1em;
        min-height: 40px;
        grid-column: 1 / 2;
        margin: 0;
    }
    
    .boton-quitar, 
    .boton-carrito,
    .boton-eliminar-item {
        font-size: 1.1em;
        padding: 10px;
        width: 44px;
        height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    /* SEGUNDA FILA: Campos de entrada */
    .producto-inferior {
        display: grid;
        grid-template-columns: 1fr 1fr 1fr;
        align-items: center;
        width: 100%;
        gap: 4px;
        order: 2;
    }
    
    .input-cantidad, 
    .input-precio, 
    .input-total {
        padding: 5px;
        font-size: 1em;
        text-align: center;
        height: 40px;
        width: 100%;
        box-sizing: border-box;
    }
    
    .input-cantidad {
        width: 55px;
    }
    
    .input-precio {
        width: 160px;
    }
    
    .input-total {
        width: 185px;
        background-color: #3a3a3a;
    }
    
    /* Ajustes para la cabecera de lista */
    .cabecera-lista {
        flex-wrap: nowrap;
        gap: 8px;
        padding: 10px;
    }
    
    .titulo-lista {
        font-size: 1em;
        min-width: 0;
    }
    
    .suma-lista {
        min-width: 60px;
        font-size: 1em;
        text-align: right;
    }
    
    .controles-lista {
        gap: 4px;
        flex-shrink: 0;
    }
    
    /* Ajustes para el historial */
    .producto-item-historial {
        flex-direction: column;
        align-items: flex-start;
        gap: 5px;
        padding: 8px 0;
    }
    
    .detalles-producto {
        align-self: flex-end;
        font-size: 1em;
        text-align: right;
    }
    
    .estado-producto {
        align-self: flex-start;
        font-size: 1em;
    }
}

@media (max-width: 480px) {
    /* Ajustes para pantallas muy pequeñas */
    button span {
        font-size: 1em;
    }
    
    .producto-superior, 
    .producto-inferior {
        gap: 2px;
    }
    
    .input-cantidad, 
    .input-precio, 
    .input-total {
        padding: 0;
        font-size: 1em;
        height: 36px;
    }
    
    .input-cantidad {
        max-width: 40px;
    }
    
    .input-precio {
        width: 115px;
    }
    
    .input-total {
        width: 140px;
    }
    
    .boton-quitar, 
    .boton-carrito,
    .boton-eliminar-item {
        padding: 8px;
        width: 40px;
        height: 40px;
        font-size: 1em;
    }
    
    .cabecera-lista {
        padding: 8px;
        gap: 5px;
    }
    
    .titulo-lista {
        font-size: 1em;
    }
    
    .suma-lista {
        min-width: 70px;
        font-size: 1em;
        margin-right: 3px;
    }
    
    .boton-incluir, 
    .boton-menu {
        padding: 5px;
        min-width: 30px;
    }
    
    .flecha-lista {
        margin-right: 3px;
        font-size: 1em;
    }
    
    /* Layout para pantallas muy pequeñas - CORREGIDO */
    .producto-superior {
        grid-template-columns: 1fr auto auto auto;
        gap: 5px;
    }
    
    .producto-inferior {
        grid-template-columns: 1fr 1fr 1fr;
        gap: 2px;
    }
    
    .nombre-producto {
        font-size: 1em;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
}