:root {
    --chilexpress-yellow: #FFE600;
    --chilexpress-black: #000000;
    --background-color: #f4f4f4;
    --text-color: #333;
    --white: #fff;
    --border-radius: 8px;
}

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

body {
    font-family: Arial, sans-serif;
    background-color: var(--background-color);
    color: var(--text-color);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 20px;
}

.container {
    width: 100%;
    max-width: 500px;
    background: var(--white);
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
    border-radius: var(--border-radius);
    overflow: hidden;
}

header {
    background-color: var(--chilexpress-yellow);
    padding: 15px;
    text-align: center;
}

.logo {
    height: 40px;
    margin-bottom: 10px;
}

h1 {
    font-size: 1.5em;
    color: var(--chilexpress-black);
    margin: 0;
}

main {
    padding: 20px;
    text-align: center;
}

#scanner-container {
    margin-bottom: 20px;
}

#reader {
    width: 100%;
    border-radius: var(--border-radius);
    border: 2px dashed #ddd;
    aspect-ratio: 1 / 1;
    overflow: hidden;
    position: relative;
    background-color: #f0f0f0;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #666;
    font-size: 0.9em;
    transition: border-color 0.3s ease;
}

/* Oculta definitivamente la guía amarilla (qrbox) de la biblioteca */
#reader>div>canvas {
    display: none !important;
}

#reader::after {
    content: "Iniciando cámara...";
    position: absolute;
}

#reader.scanning {
    border-style: solid;
    border-color: transparent;
    background-color: transparent;
}

#reader.scanning::after {
    content: "" !important;
}

#reader.scanning>canvas {
    display: block !important;
}

#reader video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

#result-container {
    margin-bottom: 20px;
}

#result-container p {
    margin-bottom: 10px;
    color: var(--text-color);
}

#result {
    font-size: 1.2em;
    font-weight: bold;
    padding: 15px;
    background: #eee;
    border-radius: var(--border-radius);
    word-wrap: break-word;
}

#scan-button {
    width: 100%;
    padding: 15px;
    font-size: 1em;
    font-weight: bold;
    color: var(--chilexpress-yellow);
    background-color: var(--chilexpress-black);
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: background-color 0.3s;
}

#scan-button:hover {
    background-color: #333;
}

button:disabled {
    background-color: #555;
    cursor: not-allowed;
}

@media (max-width: 480px) {
    body {
        padding: 0;
    }

    .container {
        border-radius: 0;
        min-height: 100vh;
    }
}

/* Estilos del Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1000;
}

.modal-content {
    position: relative;
    background-color: #fff;
    margin: 15% auto;
    width: 90%;
    max-width: 500px;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    overflow: hidden;
}

.close-button {
    position: absolute;
    right: 15px;
    top: 15px;
    font-size: 24px;
    font-weight: bold;
    color: #666;
    cursor: pointer;
    z-index: 1;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: white;
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.close-button:hover {
    background: #f0f0f0;
}

/* Header del modal */
.modal-header {
    padding: 20px;
    background-color: #f8f9fa;
    border-bottom: 1px solid #eee;
}

.header-main {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-right: 30px;
    /* Espacio para el botón de cierre */
}

.header-main h2 {
    margin: 0;
    font-size: 1.5em;
    color: #333;
    flex: 1;
}

/* Estilos para el indicador de triage */
.triage {
    padding: 8px 16px;
    border-radius: 20px;
    font-weight: bold;
    text-align: center;
    min-width: 60px;
    margin-left: 15px;
}

.triage.C0 {
    background-color: #d9d9d9;
    color: black;
}

.triage.C1 {
    background-color: #ff4444;
    color: white;
}

.triage.C2 {
    background-color: #ffa700;
    color: white;
}

.triage.C3 {
    background-color: #ffdd00;
    color: black;
}

.triage.C4 {
    background-color: #00C851;
    color: white;
}

.triage.C5 {
    background-color: #42a5f5;
    color: white;
}

/* Cuerpo del modal */
.modal-body {
    padding: 20px;
}

/* Sección de estado y recomendación */
.status-section {
    margin-bottom: 20px;
}

.status-indicator {
    display: inline-flex;
    align-items: center;
    padding: 8px 16px;
    background-color: #fff4e5;
    border-radius: 20px;
    border: 1px solid #ffd700;
    margin-bottom: 15px;
}

.status-icon {
    margin-right: 8px;
    font-size: 18px;
}

.status-text {
    color: #ff9800;
    font-weight: bold;
}

.recomendacion-box {
    background-color: #f8f9fa;
    border-left: 4px solid #ffd700;
    padding: 15px;
    border-radius: 4px;
    font-size: 0.95em;
    line-height: 1.5;
    color: #555;
}

/* Información principal */
.main-info {
    background-color: #fff;
    border-radius: 8px;
}

.info-group {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
}

.info-item {
    display: flex;
    flex-direction: column;
}

.info-item label {
    font-size: 0.85em;
    color: #666;
    margin-bottom: 5px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.info-item span {
    font-size: 1.1em;
    color: #333;
    font-weight: 500;
}

.fecha-compromiso {
    grid-column: 1 / -1;
    padding-top: 10px;
    border-top: 1px solid #eee;
}

.fecha-compromiso span {
    color: #2196F3;
    font-weight: bold;
}

/* Responsive */
@media (max-width: 480px) {
    .modal-content {
        margin: 10% auto;
        width: 95%;
    }

    .info-group {
        grid-template-columns: 1fr;
        gap: 15px;
    }
}

/* --- Success Overlay --- */
.success-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease-in-out;
}

.success-overlay.visible {
    opacity: 1;
}

.success-checkmark .check-icon {
    width: 80px;
    height: 80px;
    position: relative;
    border-radius: 50%;
    box-sizing: content-box;
    border: 4px solid #4CAF50;
    transform: scale(0);
    transition: transform 0.2s ease-in-out;
}

.success-overlay.visible .check-icon {
    transform: scale(1);
}

.success-checkmark .check-icon::before,
.success-checkmark .check-icon::after {
    content: '';
    height: 100px;
    position: absolute;
    transform: rotate(-45deg);
}

.success-checkmark .icon-line {
    height: 5px;
    background-color: #4CAF50;
    display: block;
    border-radius: 2px;
    position: absolute;
    z-index: 10;
}

.success-checkmark .icon-line.line-tip {
    top: 46px;
    left: 14px;
    width: 25px;
    transform: rotate(45deg);
    animation: icon-line-tip 0.75s;
}

.success-checkmark .icon-line.line-long {
    top: 38px;
    right: 8px;
    width: 47px;
    transform: rotate(-45deg);
    animation: icon-line-long 0.75s;
}

@keyframes icon-line-tip {
    0% {
        width: 0;
        left: 1px;
        top: 19px;
    }

    54% {
        width: 0;
        left: 1px;
        top: 19px;
    }

    70% {
        width: 50px;
        left: -8px;
        top: 37px;
    }

    84% {
        width: 17px;
        left: 21px;
        top: 48px;
    }

    100% {
        width: 25px;
        left: 14px;
        top: 46px;
    }
}

@keyframes icon-line-long {
    0% {
        width: 0;
        right: 46px;
        top: 54px;
    }

    65% {
        width: 0;
        right: 46px;
        top: 54px;
    }

    84% {
        width: 55px;
        right: 0px;
        top: 35px;
    }

    100% {
        width: 47px;
        right: 8px;
        top: 38px;
    }
}

#reader::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 90%;
    height: 100px;
    border: 2px solid #aaa;
    border-radius: 5px;
    pointer-events: none;
    z-index: 1000;
    transition: border-color 0.3s ease;
}

/* Hide rectangle in batch mode */
#reader.batch-mode::before {
    display: none !important;
}

/* Estado activo del escáner */
#reader.scanning::before {
    border-color: var(--chilexpress-yellow);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(255, 230, 0, 0.7);
    }

    70% {
        box-shadow: 0 0 0 10px rgba(255, 230, 0, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(255, 230, 0, 0);
    }
}

/* Estilos para el campo de entrada manual */
.manual-input {
    margin-top: 20px;
    padding: 15px;
    border-top: 1px solid #eee;
    display: flex;
    gap: 10px;
}

.manual-input input {
    flex: 1;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: var(--border-radius);
    font-size: 16px;
    -moz-appearance: textfield;
    /* Firefox */
}

/* Ocultar flechas del input number */
.manual-input input::-webkit-outer-spin-button,
.manual-input input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.manual-input input:focus {
    outline: none;
    border-color: var(--chilexpress-yellow);
    box-shadow: 0 0 0 2px rgba(255, 230, 0, 0.2);
}

.manual-input button {
    padding: 10px 20px;
    background-color: var(--chilexpress-black);
    color: var(--chilexpress-yellow);
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    font-weight: bold;
    min-width: 100px;
    transition: all 0.3s ease;
}

.manual-input button:hover:not(:disabled) {
    background-color: #333;
}

.manual-input button:active:not(:disabled) {
    transform: translateY(1px);
}

.manual-input button:disabled {
    background-color: #666;
    cursor: not-allowed;
    opacity: 0.7;
}

/* Estilos para el contenedor de detalles */
.detalles-container {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 2px solid #eee;
}

.detalles-container .info-row {
    margin-bottom: 15px;
    display: flex;
    flex-direction: column;
}

.detalles-container .info-row label {
    font-size: 0.9em;
    color: #666;
    margin-bottom: 5px;
}

.detalles-container .info-row span {
    font-size: 1.1em;
    color: #333;
    font-weight: 500;
}

/* Ajustes responsivos */
@media (max-width: 480px) {
    .manual-input {
        flex-direction: column;
    }

    .manual-input input,
    .manual-input button {
        width: 100%;
    }
}

.popup-alert {
    position: fixed;
    top: 20px;
    right: 20px;
    background: #ff5555;
    color: white;
    padding: 12px 18px;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    font-size: 15px;
    z-index: 9999;
    opacity: 1;
    transition: opacity 0.5s ease-in-out;
}

.popup-alert.fade-out {
    opacity: 0;
}

/* Ajuste para móvil: el posicionamiento se hace dinámicamente en JavaScript */
@media (max-width: 480px) {
    .popup-alert {
        right: auto;
        width: calc(100% - 40px);
        max-width: 400px;
    }
}

.close-icon {
    font-size: 22px;
    color: #888;
    position: absolute;
    top: 30px;
    right: 35px;
    cursor: pointer;
    font-weight: bold;
    transition: color 0.2s ease, transform 0.2s ease;
    line-height: 1;
}

.close-icon:hover {
    color: #444;
    transform: scale(1.2);
}

.mode-switcher {
    display: flex;
    justify-content: center;
    margin: 15px 0;
    gap: 10px;
}

.mode-btn {
    background-color: #f0f0f0;
    border: 1px solid #ddd;
    padding: 10px 20px;
    border-radius: 20px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.3s ease;
}

.mode-btn.active {
    background-color: #FFDA00;
    color: #333;
    border-color: #e6c600;
}

/* Batch List Styles */
#batch-list-container {
    display: none;
    /* Hidden by default */
    margin-top: 20px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    padding: 15px;
    max-height: 300px;
    overflow-y: auto;
}

.batch-item {
    padding: 10px;
    border-bottom: 1px solid #eee;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

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

.batch-code {
    font-weight: bold;
}

.batch-status {
    font-size: 0.8em;
    padding: 2px 6px;
    border-radius: 4px;
}

.status-ok {
    background-color: #e8f5e8;
    color: #28a745;
}

.status-error {
    background-color: #ffebee;
    color: #f44336;
}

/* Batch notification animation */
@keyframes popIn {
    0% {
        transform: translate(-50%, -50%) scale(0.5);
        opacity: 0;
    }
    50% {
        transform: translate(-50%, -50%) scale(1.1);
    }
    100% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 1;
    }
}