/* ==========================================================================
   Truchas El Manantial — sistema de diseño
   --------------------------------------------------------------------------
   Un solo archivo para todo el sistema. Las vistas no traen CSS propio: si
   algo se necesita en dos pantallas, vive aquí.

   El criterio de todo lo que sigue: la pantalla se queda quieta y el dato se
   lee sin esfuerzo. Nada de fondos en movimiento ni paneles translúcidos,
   porque compiten con la cifra que el capturista está tratando de leer.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Tokens
   -------------------------------------------------------------------------- */
:root {
    /* Azul marino de la marca, para la barra superior */
    --marino-900: #0b2038;
    --marino-800: #12304f;
    --marino-700: #1a4068;
    --marino-600: #235080;

    /* Azul de acción */
    --azul-700: #1743a8;
    --azul-600: #1d4ed8;
    --azul-500: #3b82f6;
    --azul-100: #dbe6fe;
    --azul-50: #eff5ff;

    /* Grises */
    --gris-0: #ffffff;
    --gris-25: #fbfcfd;
    --gris-50: #f5f7f9;
    --gris-100: #eef1f4;
    --gris-200: #e2e6eb;
    --gris-300: #cfd5dd;
    --gris-400: #9aa3b0;
    --gris-500: #6b7480;
    --gris-600: #4b5563;
    --gris-800: #24303f;
    --gris-900: #111a26;

    /* Estados */
    --verde-600: #047857;
    --verde-100: #d1fae5;
    --verde-50: #ecfdf5;
    --rojo-600: #b91c1c;
    --rojo-100: #fee2e2;
    --rojo-50: #fef2f2;
    --ambar-600: #b45309;
    --ambar-100: #fef3c7;
    --ambar-50: #fffbeb;
    --morado-600: #6d28d9;
    --morado-100: #ede9fe;

    /* Medidas */
    --radio: 8px;
    --radio-sm: 6px;
    --radio-lg: 12px;
    --sombra-sm: 0 1px 2px rgba(16, 24, 40, .06);
    --sombra: 0 1px 3px rgba(16, 24, 40, .08), 0 1px 2px rgba(16, 24, 40, .04);
    --sombra-md: 0 4px 12px rgba(16, 24, 40, .08);
    --sombra-lg: 0 12px 32px rgba(16, 24, 40, .14);
    --borde: 1px solid var(--gris-200);
    --alto-topbar: 56px;
    --alto-subnav: 44px;
    --ancho-max: 1600px;

    --fuente: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --fuente-num: ui-monospace, "SF Mono", "Cascadia Mono", "Segoe UI Mono", Menlo, Consolas, monospace;
}

/* --------------------------------------------------------------------------
   2. Base
   -------------------------------------------------------------------------- */
*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    font-family: var(--fuente);
    font-size: 14px;
    line-height: 1.5;
    color: var(--gris-900);
    background: var(--gris-50);
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
    margin: 0;
    font-weight: 600;
    color: var(--gris-900);
    line-height: 1.3;
}

h1 { font-size: 20px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }

p { margin: 0 0 10px; }
p:last-child { margin-bottom: 0; }

a {
    color: var(--azul-600);
    text-decoration: none;
}

a:hover { text-decoration: underline; }

/* Números: tabulares y alineados a la derecha, para que las columnas
   se puedan comparar de un vistazo sin contar dígitos. */
.num {
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum" 1;
    text-align: right;
    white-space: nowrap;
}

.mudo { color: var(--gris-500); }
.fuerte { font-weight: 600; }
.chico { font-size: 12px; }
.centro { text-align: center; }
.derecha { text-align: right; }
.nowrap { white-space: nowrap; }
.oculto { display: none !important; }

.positivo { color: var(--verde-600); font-weight: 600; }
.negativo { color: var(--rojo-600); font-weight: 600; }

/* --------------------------------------------------------------------------
   3. Barra superior
   -------------------------------------------------------------------------- */
.topbar {
    position: sticky;
    top: 0;
    z-index: 100;
    height: var(--alto-topbar);
    background: var(--marino-900);
    color: #fff;
    display: flex;
    align-items: center;
    padding: 0 16px;
    gap: 8px;
}

.topbar-marca {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #fff;
    text-decoration: none;
    padding-right: 12px;
    margin-right: 4px;
    flex-shrink: 0;
}

.topbar-marca:hover { text-decoration: none; }

.topbar-logo {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    background: rgba(255, 255, 255, .1);
    flex-shrink: 0;
}

.topbar-nombre {
    display: flex;
    flex-direction: column;
    line-height: 1.15;
}

.topbar-nombre strong {
    font-size: 13px;
    font-weight: 700;
    letter-spacing: .04em;
}

.topbar-nombre span {
    font-size: 10px;
    color: rgba(255, 255, 255, .6);
    letter-spacing: .06em;
}

.topbar-nav {
    display: flex;
    align-items: center;
    gap: 2px;
    height: 100%;
    flex: 1;
    min-width: 0;
    overflow-x: auto;
    scrollbar-width: none;
}

.topbar-nav::-webkit-scrollbar { display: none; }

.topbar-nav a {
    display: flex;
    align-items: center;
    height: 100%;
    padding: 0 13px;
    color: rgba(255, 255, 255, .78);
    font-size: 13.5px;
    font-weight: 500;
    text-decoration: none;
    white-space: nowrap;
    border-bottom: 2px solid transparent;
    transition: color .12s, background-color .12s;
}

.topbar-nav a:hover {
    color: #fff;
    background: rgba(255, 255, 255, .07);
    text-decoration: none;
}

.topbar-nav a.activo {
    color: #fff;
    font-weight: 600;
    border-bottom-color: var(--azul-500);
    background: rgba(255, 255, 255, .06);
}

.topbar-usuario {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
    padding-left: 12px;
    border-left: 1px solid rgba(255, 255, 255, .14);
}

.topbar-usuario .quien {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
    text-align: right;
}

.topbar-usuario .quien strong {
    font-size: 12.5px;
    font-weight: 600;
}

.topbar-usuario .quien span {
    font-size: 10.5px;
    color: rgba(255, 255, 255, .55);
}

.topbar-salir {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 11px;
    border-radius: var(--radio-sm);
    border: 1px solid rgba(255, 255, 255, .2);
    color: rgba(255, 255, 255, .9);
    font-size: 12.5px;
    text-decoration: none;
    transition: background-color .12s, border-color .12s;
}

.topbar-salir:hover {
    background: rgba(239, 68, 68, .22);
    border-color: rgba(239, 68, 68, .5);
    color: #fff;
    text-decoration: none;
}

.topbar-menu {
    display: none;
    background: none;
    border: 1px solid rgba(255, 255, 255, .22);
    color: #fff;
    border-radius: var(--radio-sm);
    padding: 6px 10px;
    font-size: 17px;
    line-height: 1;
    cursor: pointer;
}

/* --------------------------------------------------------------------------
   4. Subnavbar
   -------------------------------------------------------------------------- */
.subnav {
    position: sticky;
    top: var(--alto-topbar);
    z-index: 90;
    height: var(--alto-subnav);
    background: var(--gris-0);
    border-bottom: var(--borde);
    display: flex;
    align-items: stretch;
    padding: 0 16px;
    gap: 2px;
    overflow-x: auto;
    scrollbar-width: none;
    box-shadow: var(--sombra-sm);
}

.subnav::-webkit-scrollbar { display: none; }

.subnav a {
    display: flex;
    align-items: center;
    padding: 0 13px;
    color: var(--gris-600);
    font-size: 13px;
    font-weight: 500;
    text-decoration: none;
    white-space: nowrap;
    border-bottom: 2px solid transparent;
    transition: color .12s, border-color .12s;
}

.subnav a:hover {
    color: var(--gris-900);
    text-decoration: none;
    border-bottom-color: var(--gris-300);
}

.subnav a.activo {
    color: var(--azul-700);
    font-weight: 600;
    border-bottom-color: var(--azul-600);
}

/* --------------------------------------------------------------------------
   5. Contenido y encabezado de página
   -------------------------------------------------------------------------- */
.contenido {
    max-width: var(--ancho-max);
    margin: 0 auto;
    padding: 20px 16px 48px;
}

.page-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 18px;
}

.page-head .titulo h1 {
    display: flex;
    align-items: center;
    gap: 10px;
}

.page-head .sub {
    margin-top: 3px;
    font-size: 13px;
    color: var(--gris-500);
}

.page-head .acciones {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

/* --------------------------------------------------------------------------
   6. Tarjetas
   -------------------------------------------------------------------------- */
.card {
    background: var(--gris-0);
    border: var(--borde);
    border-radius: var(--radio);
    box-shadow: var(--sombra);
    margin-bottom: 16px;
    overflow: hidden;
}

.card:last-child { margin-bottom: 0; }

.card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    padding: 13px 16px;
    border-bottom: var(--borde);
    background: var(--gris-25);
}

.card-head h2 {
    font-size: 14px;
    font-weight: 600;
}

.card-head .sub {
    font-size: 12px;
    color: var(--gris-500);
    margin-top: 2px;
}

.card-body { padding: 16px; }
.card-body.sin-padding { padding: 0; }

.card-pie {
    padding: 12px 16px;
    border-top: var(--borde);
    background: var(--gris-25);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    flex-wrap: wrap;
}

/* --------------------------------------------------------------------------
   7. Tablas de datos
   -------------------------------------------------------------------------- */
.tabla-scroll {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

table.data {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

table.data thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--gris-100);
    color: var(--gris-600);
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .045em;
    text-align: left;
    padding: 9px 12px;
    border-bottom: 1px solid var(--gris-200);
    white-space: nowrap;
}

table.data thead th.num { text-align: right; }

table.data tbody td {
    padding: 9px 12px;
    border-bottom: 1px solid var(--gris-100);
    vertical-align: middle;
}

table.data tbody tr:last-child td { border-bottom: none; }

table.data tbody tr:hover td { background: var(--azul-50); }

table.data tbody tr.resaltada td { background: var(--ambar-50); }
table.data tbody tr.apagada td { color: var(--gris-400); }

table.data tfoot td {
    padding: 11px 12px;
    background: var(--gris-100);
    font-weight: 700;
    border-top: 2px solid var(--gris-300);
}

table.data .acciones-fila {
    display: flex;
    gap: 6px;
    justify-content: flex-end;
}

/* Tabla compacta para captura masiva */
table.data.compacta tbody td { padding: 5px 10px; }
table.data.compacta thead th { padding: 7px 10px; }

table.data input[type="number"],
table.data input[type="text"] {
    width: 100%;
    min-width: 70px;
    padding: 5px 8px;
    font-size: 13px;
}

/* --------------------------------------------------------------------------
   8. Botones
   -------------------------------------------------------------------------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 8px 14px;
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    line-height: 1.2;
    border-radius: var(--radio-sm);
    border: 1px solid var(--gris-300);
    background: var(--gris-0);
    color: var(--gris-800);
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
    transition: background-color .12s, border-color .12s, box-shadow .12s;
}

.btn:hover {
    background: var(--gris-50);
    border-color: var(--gris-400);
    text-decoration: none;
}

.btn:active { box-shadow: inset 0 1px 2px rgba(16, 24, 40, .1); }

.btn:disabled,
.btn.desactivado {
    opacity: .5;
    cursor: not-allowed;
    pointer-events: none;
}

.btn-primario {
    background: var(--azul-600);
    border-color: var(--azul-600);
    color: #fff;
}

.btn-primario:hover {
    background: var(--azul-700);
    border-color: var(--azul-700);
    color: #fff;
}

.btn-peligro {
    background: var(--gris-0);
    border-color: var(--gris-300);
    color: var(--rojo-600);
}

.btn-peligro:hover {
    background: var(--rojo-50);
    border-color: var(--rojo-600);
    color: var(--rojo-600);
}

.btn-exito {
    background: var(--verde-600);
    border-color: var(--verde-600);
    color: #fff;
}

.btn-exito:hover {
    background: #036249;
    border-color: #036249;
    color: #fff;
}

.btn-sm {
    padding: 5px 10px;
    font-size: 12px;
    gap: 5px;
}

.btn-bloque {
    width: 100%;
}

/* --------------------------------------------------------------------------
   9. Insignias
   -------------------------------------------------------------------------- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11.5px;
    font-weight: 600;
    line-height: 1.6;
    white-space: nowrap;
    background: var(--gris-100);
    color: var(--gris-600);
    border: 1px solid transparent;
}

.badge-azul { background: var(--azul-100); color: var(--azul-700); }
.badge-verde { background: var(--verde-100); color: var(--verde-600); }
.badge-rojo { background: var(--rojo-100); color: var(--rojo-600); }
.badge-ambar { background: var(--ambar-100); color: var(--ambar-600); }
.badge-morado { background: var(--morado-100); color: var(--morado-600); }
.badge-gris { background: var(--gris-200); color: var(--gris-600); }

.badge-punto::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}

/* --------------------------------------------------------------------------
   10. Formularios
   -------------------------------------------------------------------------- */
label {
    display: block;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--gris-600);
    margin-bottom: 5px;
}

input[type="text"],
input[type="number"],
input[type="date"],
input[type="password"],
input[type="email"],
input[type="search"],
select,
textarea {
    width: 100%;
    padding: 8px 11px;
    font-family: inherit;
    font-size: 13.5px;
    color: var(--gris-900);
    background: var(--gris-0);
    border: 1px solid var(--gris-300);
    border-radius: var(--radio-sm);
    transition: border-color .12s, box-shadow .12s;
    appearance: none;
}

input[type="number"] {
    font-variant-numeric: tabular-nums;
    text-align: right;
}

select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%236b7480' d='M6 8 0 0h12z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 11px center;
    padding-right: 30px;
}

textarea {
    min-height: 80px;
    resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--azul-500);
    box-shadow: 0 0 0 3px var(--azul-100);
}

input:disabled,
select:disabled,
textarea:disabled {
    background: var(--gris-100);
    color: var(--gris-500);
    cursor: not-allowed;
}

input[type="checkbox"],
input[type="radio"] {
    width: 16px;
    height: 16px;
    accent-color: var(--azul-600);
    cursor: pointer;
}

.campo { margin-bottom: 14px; }
.campo:last-child { margin-bottom: 0; }

.campo .ayuda {
    margin-top: 4px;
    font-size: 11.5px;
    color: var(--gris-500);
}

.campo .error {
    margin-top: 4px;
    font-size: 11.5px;
    color: var(--rojo-600);
}

.campo.con-error input,
.campo.con-error select {
    border-color: var(--rojo-600);
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 14px;
}

.form-grid.dos { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }

.campo-inline {
    display: flex;
    align-items: center;
    gap: 8px;
}

.campo-inline label { margin-bottom: 0; }

/* Barra de filtros */
.filtros {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    flex-wrap: wrap;
}

.filtros .campo {
    margin-bottom: 0;
    min-width: 150px;
}

.filtros .crece { flex: 1; min-width: 200px; }

/* --------------------------------------------------------------------------
   11. Avisos
   -------------------------------------------------------------------------- */
.alerta {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 11px 14px;
    border-radius: var(--radio);
    border: 1px solid;
    font-size: 13px;
    margin-bottom: 16px;
}

.alerta strong { font-weight: 700; }

.alerta-exito {
    background: var(--verde-50);
    border-color: var(--verde-100);
    color: #065f46;
}

.alerta-error {
    background: var(--rojo-50);
    border-color: var(--rojo-100);
    color: #991b1b;
}

.alerta-aviso {
    background: var(--ambar-50);
    border-color: var(--ambar-100);
    color: #92400e;
}

.alerta-info {
    background: var(--azul-50);
    border-color: var(--azul-100);
    color: var(--azul-700);
}

.alerta ul {
    margin: 4px 0 0;
    padding-left: 18px;
}

/* --------------------------------------------------------------------------
   12. Indicadores
   -------------------------------------------------------------------------- */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.stat {
    background: var(--gris-0);
    border: var(--borde);
    border-radius: var(--radio);
    box-shadow: var(--sombra);
    padding: 14px 16px;
    position: relative;
    overflow: hidden;
}

.stat .etiqueta {
    font-size: 11.5px;
    font-weight: 600;
    color: var(--gris-500);
    text-transform: uppercase;
    letter-spacing: .04em;
    margin-bottom: 6px;
}

.stat .valor {
    font-size: 24px;
    font-weight: 700;
    color: var(--gris-900);
    font-variant-numeric: tabular-nums;
    line-height: 1.15;
}

.stat .detalle {
    margin-top: 5px;
    font-size: 12px;
    color: var(--gris-500);
}

.stat.acento-azul { border-left: 3px solid var(--azul-600); }
.stat.acento-verde { border-left: 3px solid var(--verde-600); }
.stat.acento-rojo { border-left: 3px solid var(--rojo-600); }
.stat.acento-ambar { border-left: 3px solid var(--ambar-600); }

/* --------------------------------------------------------------------------
   12b. Gráficas
   -------------------------------------------------------------------------- */
.grafica {
    position: relative;
    height: 260px;
}

.grafica.alta { height: 320px; }

/* --------------------------------------------------------------------------
   13. Estado vacío
   -------------------------------------------------------------------------- */
.vacio {
    padding: 44px 20px;
    text-align: center;
    color: var(--gris-500);
}

.vacio .icono {
    font-size: 30px;
    opacity: .35;
    margin-bottom: 10px;
}

.vacio h3 {
    font-size: 14px;
    color: var(--gris-600);
    margin-bottom: 5px;
}

.vacio p {
    font-size: 13px;
    max-width: 380px;
    margin: 0 auto 14px;
}

/* --------------------------------------------------------------------------
   14. Rejillas auxiliares
   -------------------------------------------------------------------------- */
.grid-2 {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 16px;
}

.grid-3 {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 16px;
}

.fila {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.fila.entre { justify-content: space-between; }
.fila.fin { justify-content: flex-end; }

.separador {
    height: 1px;
    background: var(--gris-200);
    border: none;
    margin: 16px 0;
}

/* Lista de definiciones para pantallas de detalle */
.datos {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 14px 20px;
}

.datos .dato .etiqueta {
    font-size: 11.5px;
    font-weight: 600;
    color: var(--gris-500);
    text-transform: uppercase;
    letter-spacing: .04em;
    margin-bottom: 3px;
}

.datos .dato .valor {
    font-size: 14px;
    color: var(--gris-900);
}

/* --------------------------------------------------------------------------
   15. Pantalla de acceso
   -------------------------------------------------------------------------- */
.login-pantalla {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: linear-gradient(160deg, var(--marino-900) 0%, var(--marino-700) 100%);
}

.login-caja {
    width: 100%;
    max-width: 380px;
    background: var(--gris-0);
    border-radius: var(--radio-lg);
    box-shadow: var(--sombra-lg);
    padding: 32px 28px;
}

.login-marca {
    text-align: center;
    margin-bottom: 24px;
}

.login-marca img {
    width: 68px;
    height: 68px;
    border-radius: 50%;
    object-fit: cover;
    margin-bottom: 12px;
}

.login-marca h1 {
    font-size: 19px;
    letter-spacing: .04em;
}

.login-marca p {
    font-size: 12px;
    color: var(--gris-500);
    letter-spacing: .06em;
    margin: 2px 0 0;
}

/* --------------------------------------------------------------------------
   16. Impresión
   -------------------------------------------------------------------------- */
@media print {
    .topbar,
    .subnav,
    .page-head .acciones,
    .card-pie,
    .no-imprimir {
        display: none !important;
    }

    body { background: #fff; }

    .contenido { padding: 0; max-width: none; }

    .card {
        border: 1px solid #ccc;
        box-shadow: none;
        break-inside: avoid;
    }

    table.data thead th { background: #eee !important; }
}

/* --------------------------------------------------------------------------
   17. Pantallas chicas
   -------------------------------------------------------------------------- */
@media (max-width: 900px) {
    .topbar-nombre { display: none; }

    .topbar-usuario .quien { display: none; }

    .topbar-menu { display: block; }

    .topbar-nav {
        position: fixed;
        top: var(--alto-topbar);
        left: 0;
        right: 0;
        flex-direction: column;
        align-items: stretch;
        height: auto;
        max-height: calc(100vh - var(--alto-topbar));
        overflow-y: auto;
        background: var(--marino-800);
        padding: 6px 0;
        box-shadow: var(--sombra-lg);
        display: none;
    }

    .topbar-nav.abierto { display: flex; }

    .topbar-nav a {
        height: auto;
        padding: 12px 18px;
        border-bottom: none;
        border-left: 3px solid transparent;
    }

    .topbar-nav a.activo {
        border-bottom-color: transparent;
        border-left-color: var(--azul-500);
    }

    .contenido { padding: 16px 12px 40px; }

    .subnav { padding: 0 12px; }

    .page-head {
        flex-direction: column;
        align-items: stretch;
    }

    .page-head .acciones .btn { flex: 1; }
}

@media (max-width: 560px) {
    .stat .valor { font-size: 20px; }

    .card-head {
        flex-direction: column;
        align-items: stretch;
    }
}
