/* =========================================================
   UPCrm — Estilos base mobile-first
   ========================================================= */

:root {
    --azul:    #1e40af;
    --azul-cl: #3b82f6;
    --gris-9:  #0f172a;
    --gris-7:  #334155;
    --gris-5:  #64748b;
    --gris-3:  #cbd5e1;
    --gris-1:  #f1f5f9;
    --verde:   #16a34a;
    --rojo:    #dc2626;
    --amar:    #f59e0b;
    --radio:   10px;
    --sombra:  0 1px 3px rgba(0,0,0,.08);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: var(--gris-1);
    color: var(--gris-9);
    font-size: 16px;
    line-height: 1.5;
    -webkit-text-size-adjust: 100%;
}

a { color: var(--azul); text-decoration: none; }
a:hover { text-decoration: underline; }

/* =========================================================
   TOPBAR
   ========================================================= */
.topbar {
    background: var(--gris-9);
    color: #fff;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 10;
}
.topbar .marca {
    color: #fff;
    font-weight: 700;
    font-size: 18px;
    letter-spacing: .5px;
}
.topbar .menu {
    display: flex;
    gap: 14px;
    align-items: center;
    flex-wrap: wrap;
}
.topbar .menu a {
    color: #e2e8f0;
    font-size: 14px;
}
.topbar .menu a.salir {
    color: #fca5a5;
}

/* =========================================================
   CONTENIDO
   ========================================================= */
.contenido {
    max-width: 900px;
    margin: 0 auto;
    padding: 16px;
}
h1 {
    font-size: 22px;
    margin: 8px 0 16px;
}
h2 {
    font-size: 18px;
    margin: 20px 0 10px;
}

.pie {
    text-align: center;
    padding: 20px;
    color: var(--gris-5);
    font-size: 12px;
}

/* =========================================================
   TARJETAS DASHBOARD
   ========================================================= */
.tarjetas {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-top: 12px;
}
.tarjeta {
    background: #fff;
    border-radius: var(--radio);
    padding: 18px 16px;
    box-shadow: var(--sombra);
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.tarjeta .num {
    font-size: 28px;
    font-weight: 700;
    color: var(--azul);
}
.tarjeta .eti {
    font-size: 13px;
    color: var(--gris-5);
}
.tarjeta .delta {
    font-size: 11px;
    font-weight: 600;
    margin-top: 4px;
}
.tarjeta .delta.ok    { color: var(--verde); }
.tarjeta .delta.error { color: var(--rojo); }

/* =========================================================
   LOGIN
   ========================================================= */
.pagina-login {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
    background: linear-gradient(180deg, var(--gris-9), var(--gris-7));
}
.login-caja {
    background: #fff;
    padding: 28px 22px;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0,0,0,.3);
    width: 100%;
    max-width: 380px;
}
.login-caja h1 {
    text-align: center;
    margin: 0 0 4px;
    color: var(--azul);
}
.login-caja .subtitulo {
    text-align: center;
    color: var(--gris-5);
    font-size: 14px;
    margin: 0 0 20px;
}

/* =========================================================
   FORMULARIOS
   ========================================================= */
form label {
    display: block;
    margin-bottom: 12px;
    font-size: 14px;
    color: var(--gris-7);
    font-weight: 500;
}
form input,
form select,
form textarea {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--gris-3);
    border-radius: var(--radio);
    font-size: 16px;
    margin-top: 4px;
    background: #fff;
    font-family: inherit;
    color: var(--gris-9);
}
form input:focus,
form select:focus,
form textarea:focus {
    outline: 2px solid var(--azul-cl);
    outline-offset: -1px;
    border-color: var(--azul-cl);
}

/* =========================================================
   BOTONES
   ========================================================= */
.btn-primario,
button.btn-primario {
    background: var(--azul);
    color: #fff;
    border: 0;
    padding: 13px 18px;
    border-radius: var(--radio);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    width: 100%;
    margin-top: 6px;
    font-family: inherit;
}
.btn-primario:hover { background: var(--azul-cl); }

.btn-secundario,
button.btn-secundario {
    background: #fff;
    color: var(--azul);
    border: 1px solid var(--azul);
    padding: 10px 14px;
    border-radius: var(--radio);
    font-size: 15px;
    cursor: pointer;
    font-family: inherit;
    display: inline-block;
    line-height: 1.5;
    text-align: center;
    box-sizing: border-box;
    vertical-align: middle;
    text-decoration: none;
}
.btn-secundario:hover { background: #eff6ff; }

.btn-inline {
    display: inline-block;
    margin-bottom: 12px;
    width: auto;
}

.btn-mini {
    font-size: 12px;
    padding: 5px 10px;
    border-radius: 6px;
    cursor: pointer;
    font-family: inherit;
    border: 1px solid var(--gris-3);
    background: #fff;
    color: var(--gris-7);
    display: inline-block;
    margin-left: 4px;
    line-height: 1.4;
}
.btn-mini:hover {
    background: var(--gris-1);
    border-color: var(--azul-cl);
    color: var(--azul);
}
.btn-mini.btn-secundario {
    background: #fff;
}

/* Botón WhatsApp */
.btn-wa {
    background: #25D366;
    color: #fff !important;
    border: 1px solid #1ebe5a;
    font-weight: 600;
    padding: 10px 14px;
    border-radius: var(--radio);
    font-size: 15px;
    display: inline-block;
    line-height: 1.5;
    text-align: center;
    box-sizing: border-box;
    vertical-align: middle;
    text-decoration: none;
}
.btn-wa:hover {
    background: #1ebe5a;
    text-decoration: none;
}
.acciones-compartir {
    margin-bottom: 16px;
}

/* =========================================================
   ALERTAS / FLASH
   ========================================================= */
.alerta {
    padding: 10px 14px;
    border-radius: var(--radio);
    margin-bottom: 14px;
    font-size: 14px;
}
.alerta-ok    { background: #dcfce7; color: #166534; }
.alerta-error { background: #fee2e2; color: #991b1b; }
.alerta-info  { background: #dbeafe; color: #1e40af; }

/* =========================================================
   BADGES DE ESTADO
   ========================================================= */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    color: #fff;
    background: var(--gris-5);
}
.badge-gray   { background: #64748b; }
.badge-blue   { background: #2563eb; }
.badge-indigo { background: #4f46e5; }
.badge-yellow { background: #d97706; }
.badge-orange { background: #ea580c; }
.badge-green  { background: #16a34a; }
.badge-red    { background: #dc2626; }

/* =========================================================
   RESPONSIVE
   ========================================================= */
@media (min-width: 640px) {
    .tarjetas { grid-template-columns: repeat(4, 1fr); }
    h1 { font-size: 26px; }
}

/* =========================================================
   FORMULARIOS DE ORDEN
   ========================================================= */
.formulario fieldset {
    border: 1px solid var(--gris-3);
    border-radius: var(--radio);
    padding: 14px;
    margin-bottom: 16px;
    background: #fff;
}
.formulario legend {
    padding: 0 8px;
    font-weight: 600;
    color: var(--azul);
    font-size: 14px;
}
.ayuda {
    font-size: 13px;
    color: var(--gris-5);
    margin: 0 0 10px;
}

.firma-canvas {
    width: 100%;
    height: 180px;
    background: #fafafa;
    border: 2px dashed var(--gris-3);
    border-radius: var(--radio);
    touch-action: none;
    display: block;
    margin-bottom: 8px;
    cursor: crosshair;
}

/* =========================================================
   FILTROS
   ========================================================= */
.filtros {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    background: #fff;
    padding: 12px;
    border-radius: var(--radio);
    box-shadow: var(--sombra);
    margin-bottom: 14px;
}
.filtros input,
.filtros select { margin-top: 0; }
.filtros label {
    display: block;
    font-size: 12px;
    color: var(--gris-5);
    margin: 0;
}
@media (min-width: 640px) {
    .filtros { grid-template-columns: 2fr 1.5fr 1fr 1fr auto; align-items: end; }
}

/* =========================================================
   LISTA DE ÓRDENES
   ========================================================= */
.lista-ordenes {
    list-style: none;
    padding: 0;
    margin: 0;
    display: grid;
    gap: 10px;
}
.lista-ordenes li a {
    display: block;
    background: #fff;
    padding: 14px;
    border-radius: var(--radio);
    box-shadow: var(--sombra);
    color: inherit;
    text-decoration: none;
}
.lista-ordenes .fila-1 {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}
.lista-ordenes .fila-2 { font-size: 14px; }
.lista-ordenes .fila-3 { font-size: 13px; color: var(--gris-7); }
.lista-ordenes .fila-4 { font-size: 12px; color: var(--gris-5); margin-top: 4px; }
.lista-ordenes .punto { color: var(--azul); }
.vacio {
    text-align: center;
    padding: 30px;
    color: var(--gris-5);
}

/* =========================================================
   FICHA / DETALLE
   ========================================================= */
.ficha {
    background: #fff;
    padding: 14px;
    border-radius: var(--radio);
    box-shadow: var(--sombra);
    margin-bottom: 12px;
}
.ficha h2 {
    font-size: 13px;
    text-transform: uppercase;
    color: var(--gris-5);
    margin: 0 0 8px;
    letter-spacing: 1px;
}
.ficha p { margin: 4px 0; font-size: 14px; }

.timeline {
    list-style: none;
    padding: 0;
    margin: 0;
}
.timeline li {
    border-left: 3px solid var(--azul-cl);
    padding: 8px 12px;
    background: #fff;
    margin-bottom: 8px;
    border-radius: 0 var(--radio) var(--radio) 0;
}
.timeline li small {
    display: block;
    color: var(--gris-5);
    font-size: 12px;
    margin: 4px 0;
}
.timeline li p { margin: 4px 0; font-size: 14px; }

.galeria {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 12px;
}
.galeria img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    border-radius: var(--radio);
    display: block;
}

.galeria-firmas {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
}
.firma-item {
    background: #fff;
    padding: 10px;
    border-radius: var(--radio);
    box-shadow: var(--sombra);
}
.firma-item small {
    display: block;
    color: var(--gris-5);
    font-size: 11px;
    text-transform: uppercase;
    margin-bottom: 6px;
}
.firma-item small.fecha {
    margin-top: 6px;
    margin-bottom: 0;
    text-transform: none;
}
.firma-item img {
    max-height: 100px;
    border-bottom: 1px solid var(--gris-3);
}

.acciones-orden {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 14px;
}

/* =========================================================
   PRESUPUESTO Y GARANTÍA
   ========================================================= */
.ficha-presupuesto .precio {
    font-size: 28px;
    font-weight: 700;
    color: var(--azul);
    margin: 4px 0 8px;
}
.ficha-garantia { border-left: 4px solid var(--verde); }
.ficha-presupuesto { border-left: 4px solid var(--amar); }
.ok    { color: var(--verde); font-weight: 600; }
.error { color: var(--rojo); font-weight: 600; }

/* =========================================================
   FORMULARIOS EN FICHA
   ========================================================= */
.formulario-inline {
    background: #f8fafc;
    padding: 12px;
    border-radius: var(--radio);
    margin-top: 10px;
}
.formulario-inline label { margin-bottom: 10px; }
.formulario-inline h3 { margin-top: 16px; }

/* =========================================================
   MODAL
   ========================================================= */
.modal {
    border: 0;
    border-radius: var(--radio);
    padding: 20px;
    max-width: 420px;
    width: 90%;
    box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.modal::backdrop { background: rgba(0,0,0,.5); }
.modal h2 { margin-top: 0; }
.modal-botones {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}
.modal-botones button { flex: 1; }

/* =========================================================
   TABS (admin)
   ========================================================= */
.tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 16px;
    border-bottom: 2px solid var(--gris-3);
    overflow: visible;
    flex-wrap: wrap;
}
.tabs a {
    padding: 10px 14px;
    color: var(--gris-5);
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;
    text-decoration: none;
}
.tabs a.activo {
    color: var(--azul);
    border-bottom-color: var(--azul);
}

/* Solo en pantallas muy pequeñas permitimos scroll horizontal */
@media (max-width: 420px) {
    .tabs {
        overflow-x: auto;
        flex-wrap: nowrap;
        scrollbar-width: none;
        -ms-overflow-style: none;
    }
    .tabs::-webkit-scrollbar {
        display: none;
    }
}

/* =========================================================
   CHECKBOX
   ========================================================= */
label.check {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 500;
}
label.check input {
    width: auto;
    margin: 0;
}

/* =========================================================
   BARRA DE ACCIONES (encima de tablas)
   ========================================================= */
.barra-acciones {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    font-size: 14px;
    color: var(--gris-5);
}

/* =========================================================
   TABLA CON ACCIONES
   ========================================================= */
.tabla-acciones {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
    border-radius: var(--radio);
    overflow: hidden;
    box-shadow: var(--sombra);
    font-size: 13px;
}
.tabla-acciones th,
.tabla-acciones td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--gris-1);
    vertical-align: middle;
}
.tabla-acciones th {
    background: var(--gris-1);
    color: var(--gris-7);
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .5px;
}
.tabla-acciones tr:last-child td { border-bottom: 0; }
.tabla-acciones .col-acciones {
    text-align: right;
    white-space: nowrap;
    width: 1%;
}

/* En móvil, apilar las acciones de la tabla */
@media (max-width: 640px) {
    .tabla-acciones thead { display: none; }
    .tabla-acciones,
    .tabla-acciones tbody,
    .tabla-acciones tr,
    .tabla-acciones td { display: block; width: 100%; }
    .tabla-acciones tr {
        border-bottom: 2px solid var(--gris-1);
        padding: 8px 0;
    }
    .tabla-acciones td {
        border: 0;
        padding: 4px 12px;
        text-align: left;
    }
    .tabla-acciones .col-acciones {
        text-align: left;
        padding-top: 8px;
    }
    .btn-mini { margin-left: 0; margin-right: 4px; }
}

/* =========================================================
   BARRAS VERTICALES (por mes)
   ========================================================= */
.barras {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    height: 180px;
    padding: 10px;
    background: #fff;
    border-radius: var(--radio);
    box-shadow: var(--sombra);
    overflow-x: auto;
}
.barra {
    flex: 1 0 40px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    height: 100%;
}
.barra-valor {
    width: 100%;
    background: linear-gradient(180deg, var(--azul-cl), var(--azul));
    border-radius: 4px 4px 0 0;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    padding-top: 3px;
    min-height: 4px;
}
.barra-etiqueta {
    font-size: 10px;
    color: var(--gris-5);
    margin-top: 4px;
    white-space: nowrap;
    transform: rotate(-45deg);
    transform-origin: center;
    padding: 8px 0 4px;
}

/* =========================================================
   BARRAS HORIZONTALES (marcas, modelos, tipos)
   ========================================================= */
.barras-horiz {
    background: #fff;
    border-radius: var(--radio);
    box-shadow: var(--sombra);
    padding: 12px;
    margin-bottom: 14px;
}
.barra-h {
    display: grid;
    grid-template-columns: 140px 1fr;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
    font-size: 13px;
}
.barra-h:last-child { margin-bottom: 0; }
.etiqueta-h {
    color: var(--gris-7);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.barra-h-fondo {
    background: var(--gris-1);
    border-radius: 4px;
    height: 22px;
    overflow: hidden;
}
.barra-h-valor {
    background: var(--azul);
    color: #fff;
    height: 100%;
    display: flex;
    align-items: center;
    padding-left: 8px;
    font-size: 11px;
    font-weight: 700;
    border-radius: 4px;
    min-width: 26px;
}

@media (max-width: 480px) {
    .barra-h { grid-template-columns: 100px 1fr; }
}

/* =========================================================
   TABLA GENÉRICA
   ========================================================= */
.tabla {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
    border-radius: var(--radio);
    overflow: hidden;
    box-shadow: var(--sombra);
    font-size: 13px;
    margin-bottom: 14px;
}
.tabla th,
.tabla td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--gris-1);
}
.tabla th {
    background: var(--gris-1);
    color: var(--gris-7);
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .5px;
}
.tabla tr:last-child td { border-bottom: 0; }

/* =========================================================
   INFO ECONÓMICA (interna)
   ========================================================= */
.ficha-economica .grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}
.ficha-economica small {
    display: block;
    font-size: 11px;
    color: var(--gris-5);
    text-transform: uppercase;
    letter-spacing: .5px;
    margin-bottom: 2px;
}
.ficha-economica .precio-linea {
    font-size: 18px;
    font-weight: 700;
    color: var(--gris-9);
    margin: 0;
}
.ficha-economica .precio-linea.ok {
    color: var(--verde);
}

/* =========================================================
   PÁGINA DE VERIFICACIÓN PÚBLICA
   ========================================================= */
.pagina-verificar {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
    background: linear-gradient(180deg, var(--gris-9), var(--gris-7));
}
.verificar-caja {
    background: #fff;
    border-radius: 16px;
    padding: 28px 22px;
    max-width: 440px;
    width: 100%;
    box-shadow: 0 20px 60px rgba(0,0,0,.3);
    text-align: center;
}
.verificar-logo {
    margin-bottom: 16px;
}
.verificar-logo strong {
    display: block;
    font-size: 20px;
    color: var(--azul);
    letter-spacing: .5px;
}
.verificar-logo small {
    color: var(--gris-5);
    font-size: 12px;
}
.verificar-caja h1 {
    margin: 10px 0 12px;
    font-size: 24px;
    letter-spacing: 1px;
    color: var(--gris-9);
}
.verificar-estado {
    font-size: 14px;
    padding: 6px 14px;
    margin-bottom: 20px;
}
.verificar-bloque {
    background: var(--gris-1);
    border-radius: var(--radio);
    padding: 14px;
    margin-bottom: 16px;
    text-align: left;
    font-size: 14px;
}
.verificar-bloque p {
    margin: 4px 0;
}
.verificar-resultado {
    padding: 14px;
    border-radius: var(--radio);
    font-weight: 600;
    margin-bottom: 16px;
    font-size: 15px;
}
.verificar-resultado.ok        { background: #dcfce7; color: #166534; }
.verificar-resultado.ko        { background: #fee2e2; color: #991b1b; }
.verificar-resultado.en-proceso{ background: #dbeafe; color: #1e40af; }
.verificar-resultado small {
    display: block;
    font-weight: 400;
    font-size: 12px;
    margin-top: 4px;
}
.verificar-pie {
    color: var(--gris-5);
    font-size: 11px;
    margin-top: 8px;
    line-height: 1.4;
}