@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap');

/* Reset y Box-sizing global */
*, *::before, *::after {
    box-sizing: border-box;
}

body {
    font-family: 'Roboto', sans-serif;
    background-color: #f0f2f5;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 100vh;
    margin: 0;
    padding: 1rem;
}

.container {
    display: flex;
    gap: 2rem;
    padding: 2rem;
    max-width: 1300px;
    width: 100%;
    flex-wrap: wrap;
    align-items: flex-start;
}

.product-list {
    background-color: #ffffff;
    padding: 2rem;
    border-radius: 16px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    flex: 1;
    min-width: 400px;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
}

.product-list h2 {
    margin-top: 0;
    margin-bottom: 1.5rem;
}

.product-item {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    margin-bottom: 1rem;
    padding: 1rem;
    background-color: #f8f9fa;
    border-radius: 12px;
    gap: 1rem;
}

.product-details {
    display: none; /* Se mantiene oculto, es para datos internos */
}

/* --- ESTILOS PARA INPUTS Y BOTONES DENTRO DE LA FILA --- */

.input-with-icon,
.observation-container {
    display: flex;
    align-items: center;
    flex: 1 1 200px; /* Base de ancho flexible para los contenedores de input */
    gap: 8px;
    position: relative;
}

.input-with-icon .location-input,
.input-with-icon .qr-pallet-input,
.observation-container .observation-input {
    width: 100%;
    padding: 0.85rem;
    border: 1px solid #ced4da;
    border-radius: 8px;
    font-size: 1em;
}

.uppercase-input {
    text-transform: uppercase;
}

.input-with-icon .qr-pallet-input {
    padding-right: 3.2rem;
}

.icon-button.qr-scanner {
    position: absolute;
    right: 0.5rem;
    background: none;
    border: none;
    cursor: pointer;
    color: #f29200;
    font-size: 1.6em;
    padding: 0.25rem;
    transition: color 0.2s ease-in-out;
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-button.qr-scanner:hover {
    color: #9d9d9b;
}

/* INICIO: MODIFICACIÓN - Contenedor para botones de acción */
.actions-container {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-shrink: 0;
}
/* FIN: MODIFICACIÓN */

.delete-button {
    background-color: #dc3545;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    padding: 9px 13px;
    font-size: 1.1em;
    line-height: 1.2;
    transition: background-color 0.3s;
}

.delete-button:hover {
    background-color: #c82333;
}

.delete-button i {
    display: block;
}


/* INICIO: MODIFICACIÓN - Estilo para el nuevo botón de editar */
.edit-button {
    padding: 0.85rem;
    border: none;
    border-radius: 8px;
    background-color: #6c757d;
    color: white;
    font-size: 1em;
    cursor: pointer;
    transition: background-color 0.3s;
    display: none; /* Oculto por defecto */
}

.edit-button:hover {
    background-color: #5a6268;
}

.edit-button i {
    display: block; /* Asegura que el ícono llene el botón */
}
/* FIN: MODIFICACIÓN */


.send-button {
    padding: 0.85rem 1.2rem;
    border: none;
    border-radius: 8px;
    background-color: #007bff;
    color: white;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.3s;
    flex-shrink: 0;
}

.send-button:hover:not(:disabled) {
    background-color: #0056b3;
}

.send-button:disabled {
    background-color: #6c757d;
    cursor: not-allowed;
}

.product-item.success .send-button {
    background-color: #28a745;
}

.product-item.pending .send-button {
    background-color: #ffc107;
    color: #212529;
}

.product-item.pending .send-button:hover {
    background-color: #e0a800;
}

.add-product-button {
    width: 100%;
    padding: 0.85rem;
    border: none;
    border-radius: 8px;
    background-color: #f29200;
    color: white;
    font-size: 1em;
    font-weight: 500;
    cursor: pointer;
    margin-top: 1rem;
    transition: background-color 0.3s;
}

.add-product-button:hover {
    background-color: #9d9d9b;
}

/* --- Formulario de Checkout --- */

.checkout-form {
    background-color: #009a3f;
    color: white;
    padding: 2rem;
    border-radius: 16px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    flex: 0 1 400px;
    align-self: flex-start;
}

.checkout-form h2, .checkout-form label, .totals {
    text-shadow: 1px 1px 2px rgba(0,0,0,0.2);
}

.checkout-form h2 {
    margin-top: 0;
    text-align: center;
}

.checkout-form label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.checkout-form input,
.checkout-form select {
    width: 100%;
    padding: 0.85rem;
    border: none;
    border-radius: 8px;
    margin-bottom: 1rem;
    box-sizing: border-box;
    color: #333;
    font-size: 1em;
}

.totals {
    display: flex;
    justify-content: space-between;
    font-size: 1.1rem;
    margin-top: 1rem;
    font-weight: 500;
}

#checkoutButton {
    width: 100%;
    padding: 1rem;
    border: none;
    border-radius: 8px;
    background-color: #f29200;
    color: #1a1a1a;
    font-size: 1.2rem;
    font-weight: 700;
    cursor: pointer;
    margin-top: 2rem;
    transition: background-color 0.3s;
}

#checkoutButton:hover:not(:disabled) {
    background-color: #9d9d9b;
}

#checkoutButton:disabled {
    background-color: #cccccc;
    color: #666666;
    cursor: not-allowed;
    text-shadow: none;
}


/* ======================================================= */
/* --- 🎨 Estilos para el Modal de Confirmación --- */
/* ======================================================= */

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    z-index: 2000;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 1rem;
}

.modal-content {
    background-color: white;
    padding: 25px;
    border-radius: 16px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
    text-align: center;
    max-width: 90%;
    width: 400px;
}

.modal-content p {
    margin: 0 0 20px 0;
    font-size: 1.1em;
    line-height: 1.5;
    color: #333;
}

.modal-actions {
    display: flex;
    justify-content: space-around;
    gap: 1rem;
}

.modal-actions button {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: bold;
    font-size: 1em;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.modal-actions button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

.modal-button-confirm {
    background-color: #dc3545;
    color: white;
}

.modal-button-cancel {
    background-color: #6c757d;
    color: white;
}

/* ======================================================= */
/* --- 📷 Estilos para el Modal del Escáner --- */
/* ======================================================= */

#scanner-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.9);
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    padding: 1rem;
}

#scanner-video {
    width: 80%;
    max-width: 600px;
    border: 2px solid white;
    border-radius: 8px;
}

#scanned-code-display {
    color: white;
    margin-top: 15px;
    font-size: 1.2em;
    text-align: center;
    word-break: break-all;
    padding: 0 1rem;
}

.scanner-buttons {
    margin-top: 20px;
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
}

#add-scanned-code-button,
#close-scanner {
    padding: 10px 20px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-weight: 500;
    transition: background-color 0.3s;
}

#add-scanned-code-button {
    background-color: #28a745;
    color: white;
}

#add-scanned-code-button:hover {
    background-color: #218838;
}

#close-scanner {
    background-color: #dc3545;
    color: white;
}

#close-scanner:hover {
    background-color: #c82333;
}


/* ======================================================= */
/* --- 📱 Media Queries para Diseño Responsivo --- */
/* ======================================================= */

/* Tablets grandes y pantallas medianas */
@media (max-width: 1200px) {
    .container {
        max-width: 100%;
        padding: 1.5rem;
        gap: 1.5rem;
    }
    
    .product-list {
        min-width: 350px;
    }
}

/* Tablets */
@media (max-width: 1024px) {
    .container {
        padding: 1rem;
        gap: 1.5rem;
    }

    .product-list, .checkout-form {
        padding: 1.5rem;
    }

    .product-item {
        gap: 0.75rem;
        padding: 0.75rem;
    }

    .input-with-icon,
    .observation-container {
        flex-basis: calc(50% - 0.375rem);
        min-width: 150px;
    }
    
    .actions-container {
        flex-basis: 100%;
        justify-content: flex-end;
        margin-top: 0.5rem;
    }
}

/* Tablets pequeñas */
@media (max-width: 768px) {
    body {
        padding: 0.5rem;
    }

    .container {
        flex-direction: column;
        padding: 0.5rem;
        gap: 1rem;
    }

    .product-list,
    .checkout-form {
        width: 100%;
        flex: none;
        padding: 1rem;
        min-width: unset;
    }

    .product-item {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
        padding: 1rem;
    }

    .input-with-icon,
    .observation-container {
        flex-basis: 100%;
        min-width: unset;
    }
    
    .actions-container {
        flex-basis: 100%;
        justify-content: space-between;
        margin-top: 0.5rem;
    }
    
    .send-button {
        flex: 1;
        margin-left: 0.5rem;
    }
    
    .edit-button {
        padding: 0.75rem;
    }
    
    /* Estilos responsive para el modal del escáner */
    #scanner-video {
        width: 90%;
        max-width: 500px;
    }
    
    #scanned-code-display {
        font-size: 1.1em;
        padding: 0 0.5rem;
    }
    
    .scanner-buttons {
        margin-top: 15px;
    }
    
    #add-scanned-code-button,
    #close-scanner {
        padding: 8px 16px;
        font-size: 0.9rem;
    }
}

/* Móviles */
@media (max-width: 480px) {
    body {
        padding: 0.25rem;
    }
    
    .container {
        padding: 0.25rem;
        gap: 0.75rem;
    }
    
    .product-list,
    .checkout-form {
        padding: 0.75rem;
        border-radius: 12px;
    }
    
    .product-item {
        padding: 0.75rem;
        gap: 0.5rem;
        border-radius: 8px;
    }
    
    .input-with-icon .location-input,
    .input-with-icon .qr-pallet-input,
    .observation-container .observation-input {
        padding: 0.75rem;
        font-size: 0.9em;
    }
    
    .send-button,
    .edit-button,
    .delete-button {
        padding: 0.75rem;
        font-size: 0.9em;
    }
    
    .add-product-button {
        padding: 0.75rem;
        font-size: 0.9em;
    }
    
    .checkout-form input,
    .checkout-form select {
        padding: 0.75rem;
        font-size: 0.9em;
    }
    
    #checkoutButton {
        padding: 0.875rem;
        font-size: 1.1rem;
    }
    
    .modal-content {
        padding: 1rem;
        margin: 0.5rem;
        width: calc(100% - 1rem);
    }
    
    .modal-actions {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .modal-actions button {
        width: 100%;
        padding: 0.875rem;
    }
    
    /* Estilos responsive para el modal del escáner en móviles */
    #scanner-modal {
        padding: 0.5rem;
    }
    
    #scanner-video {
        width: 95%;
        max-width: none;
    }
    
    #scanned-code-display {
        font-size: 1rem;
        margin-top: 10px;
        padding: 0 0.25rem;
    }
    
    .scanner-buttons {
        margin-top: 10px;
        flex-direction: column;
        width: 100%;
        max-width: 300px;
    }
    
    #add-scanned-code-button,
    #close-scanner {
        width: 100%;
        padding: 10px;
        font-size: 0.85rem;
    }
}

/* Móviles muy pequeños */
@media (max-width: 320px) {
    .product-list h2,
    .checkout-form h2 {
        font-size: 1.25rem;
    }
    
    .input-with-icon .location-input,
    .input-with-icon .qr-pallet-input,
    .observation-container .observation-input {
        font-size: 0.85em;
    }
    
    .icon-button.qr-scanner {
        font-size: 1.4em;
    }
    
    .totals {
        font-size: 1rem;
    }
    
    /* Estilos responsive para el modal del escáner en pantallas muy pequeñas */
    #scanner-modal {
        padding: 0.25rem;
    }
    
    #scanner-video {
        width: 98%;
        border-width: 1px;
    }
    
    #scanned-code-display {
        font-size: 0.9rem;
        margin-top: 8px;
    }
    
    .scanner-buttons {
        margin-top: 8px;
    }
    
    #add-scanned-code-button,
    #close-scanner {
        padding: 8px;
        font-size: 0.8rem;
    }
}