/* --- ESTILOS GENERALES (Pensado para Celulares) --- */
body {
    font-family: Arial, sans-serif;
    margin: 15px;
    font-size: 13px;
    color: #000;
    background-color: #f9f9f9;
}

/* Contenedor de Botones: Centrado y elástico en móviles */
.btn-container {
    margin: 40px 0 0 240px;
    display: flex;
    gap: 10px;
    justify-content: center; /* Centra los botones en la pantalla del celular */
    flex-wrap: wrap;        /* Si no caben, saltan a la siguiente línea */
}

.btn {
    background: #1d117a;
    color: white;
    border: none;
    padding: 12px 18px;    /* Un poco más de relleno para que sea fácil de tocar */
    border-radius: 5px;
    cursor: pointer;
    font-size: 14px;
    flex: 1 1 auto;        /* Se estiran para ocupar el ancho en pantallas chicas */
    text-align: center;
}

.btn-danger { background: #8b0000; }
.btn-warning { background: #e67e22; }

/* Encabezado en Celulares (Todo centrado y apilado hacia abajo) */
.header {
    display: flex;
    flex-direction: column; 
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
    background: #fff;
    padding: 15px;
    border: 1px solid #ddd;
    border-radius: 6px;
}

.logo {
    width: 140px;
    height: auto;
    object-fit: contain;
}

.info-empresa {
    text-align: center;
    line-height: 1.5;
    font-size: 12px;
}

.info-empresa strong {
    font-size: 13px;
}

/* Tablas del Formulario */
table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 20px;
    background: #fff;
}

td, th {
    border: 1px solid #000;
    padding: 8px 6px;
    text-align: center;
    vertical-align: middle;
}

/* --- MAGIA PARA CELULARES (Pantallas menores a 600px) --- */
@media (max-width: 600px) {
    /* Forzamos a la tabla de datos a volverse una lista vertical */
    table:not(#tablaItems), 
    table:not(#tablaItems) tbody, 
    table:not(#tablaItems) tr, 
    table:not(#tablaItems) td {
        display: block;
        width: 100%;
        box-sizing: border-box;
    }
    
    table:not(#tablaItems) tr {
        margin-bottom: 15px;
        border: 1px solid #000;
        border-radius: 4px;
        background: #fff;
    }
    
    table:not(#tablaItems) td {
        border: none;
        border-bottom: 1px dashed #ddd;
        text-align: left; /* El texto se alinea a la izquierda para leerse mejor */
        padding: 10px;
    }
    
    table:not(#tablaItems) td:nth-child(odd) {
        background: #f2f2f2; /* Color gris suave para los títulos (CLIENTE, OC, etc.) */
        font-weight: bold;
    }

    table:not(#tablaItems) td:last-child {
        border-bottom: none;
    }

    /* La tabla de ítems mantiene su estructura pero permite scroll horizontal si es muy ancha */
    #tablaItems {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
    }
}

/* Controles de texto adaptables */
input, textarea {
    width: 100%;
    border: none;
    outline: none;
    font-family: Arial;
    font-size: 13px;
    box-sizing: border-box;
    background: transparent;
}

input {
    min-height: 30px; /* Altura cómoda para escribir en teclados móviles */
}

textarea {
    resize: none;
    min-height: 30px;
    overflow: hidden;
    line-height: 1.4;
}

.texto-largo {
    min-height: 45px;
    white-space: pre-wrap;
    overflow-wrap: break-word;
}

.observaciones {
    min-height: 90px;
    background: #fff;
    padding: 8px;
    border: 1px solid #000;
}

/* Firmas en Celulares (Una debajo de la otra) */
.firmas {
    margin-top: 30px;
    display: flex;
    flex-direction: column; 
    gap: 35px;
}

.firma-box {
    width: 100%;
}

.signature-pad {
    display: block;
    width: 100%;
    height: 120px; /* Un poco más alta para que el dedo dibuje cómodo */
    border: 1px solid #000;
    cursor: crosshair;
    touch-action: none;
    background: #fff;
    box-sizing: border-box;
}

.firma-label {
    margin-top: 8px;
    text-align: center;
    border-top: 1px solid #000;
    padding-top: 6px;
    font-weight: bold;
}

.borrar-firma {
    margin-top: 10px;
    background: #8b0000;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    padding: 10px 14px;
    font-size: 13px;
    width: 100%; /* Botón ancho para evitar errores al pulsar */
}

.accion-btn {
    background: #8b0000;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    padding: 8px 12px;
}

/* --- ESTILOS PARA COMPUTADORA (Pantallas grandes) --- */
@media (min-width: 768px) {
    body {
        margin: 30px 50px;
        background-color: #fff;
    }

    .header {
        flex-direction: row; 
        justify-content: space-between;
        border: none;
        padding: 0;
    }

    .logo {
        width: 150px;
    }

    .info-empresa {
        flex: 1;
        text-align: center;
        padding-right: 150px; 
    }

    .btn-container {
        justify-content: flex-start; /* Alineación limpia a la izquierda en PC */
    }

    .btn {
        flex: initial;
    }

    .firmas {
        flex-direction: row; /* Firmas lado a lado en PC */
        gap: 50px;
    }

    .firma-box {
        width: 45%;
    }

    .borrar-firma {
        width: auto;
    }
}

/* --- REGLAS DE IMPRESIÓN Y PDF --- */
@media print {
    body {
        margin: 0;
        padding: 0;
        background: #fff;
    }
    .btn-container,
    .col-accion,
    .accion-celda,
    .borrar-firma {
        display: none !important;
    }
    .header, .firmas {
        flex-direction: row !important;
    }
    .firma-box {
        width: 45% !important;
    }
}