/* RA.FACTURADOR — sistema visual (Bootstrap 5.3, tema claro / oscuro) */

/* ---------------------------------------------------------------- Tokens */
:root {
    --app-font: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
    --app-sidebar-w: 264px;
    --app-radio: .75rem;
    --app-fondo: #f3f5f8;
    --app-superficie: #ffffff;
    --app-borde: rgba(11, 11, 11, .08);
    --app-sombra: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .06);
    --app-acento: #2a78d6;
    --app-acento-suave: #e8f1fc;

    --app-menu-fondo: #0f1b2d;
    --app-menu-texto: #c4cfdf;
    --app-menu-titulo: #6f819b;
    --app-menu-activo: rgba(255, 255, 255, .08);

    /* Gráficos (serie validada: azul slot 1 sobre las superficies de la app) */
    --viz-serie: #2a78d6;
    --viz-grid: #e1e0d9;
    --viz-eje: #c3c2b7;
    --viz-texto: #52514e;
    --viz-muted: #898781;
    --viz-pista: #cde2fb;
    --viz-alerta: #fab219;
    --viz-critico: #d03b3b;
}

[data-bs-theme="dark"] {
    --app-fondo: #12151a;
    --app-superficie: #1b1f25;
    --app-borde: rgba(255, 255, 255, .08);
    --app-sombra: 0 1px 2px rgba(0, 0, 0, .3);
    --app-acento: #3987e5;
    --app-acento-suave: rgba(57, 135, 229, .14);

    --app-menu-fondo: #0b1220;

    --viz-serie: #3987e5;
    --viz-grid: #2c2c2a;
    --viz-eje: #383835;
    --viz-texto: #c3c2b7;
    --viz-muted: #898781;
    --viz-pista: #184f95;
}

/* ---------------------------------------------------------------- Base */
body {
    font-family: var(--app-font);
    background: var(--app-fondo);
    -webkit-font-smoothing: antialiased;
}

.card {
    --bs-card-bg: var(--app-superficie);
    --bs-card-border-color: var(--app-borde);
    --bs-card-border-radius: var(--app-radio);
    --bs-card-inner-border-radius: calc(var(--app-radio) - 1px);
    --bs-card-cap-bg: transparent;
    box-shadow: var(--app-sombra);
}

.card-header {
    font-weight: 600;
    padding-top: .85rem;
    padding-bottom: .85rem;
}

.table {
    --bs-table-bg: transparent;
    margin-bottom: 0;
}

.table > thead th {
    font-size: .75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .03em;
    color: var(--bs-secondary-color);
    white-space: nowrap;
    border-bottom-width: 1px;
}

.table td.text-end, .table th.text-end, .num {
    font-variant-numeric: tabular-nums;
}

.table tfoot td {
    border-top: 2px solid var(--bs-border-color);
    border-bottom: 0;
}

.form-control, .form-select, .btn {
    border-radius: .5rem;
}

code {
    color: var(--app-acento);
}

/* ---------------------------------------------------------------- Estructura */
.app-shell {
    display: flex;
    min-height: 100vh;
}

.app-sidebar {
    background: var(--app-menu-fondo);
    color: var(--app-menu-texto);
}

@media (min-width: 992px) {
    .app-sidebar {
        width: var(--app-sidebar-w);
        flex-shrink: 0;
        position: sticky;
        top: 0;
        height: 100vh;
    }
}

.app-sidebar.offcanvas-lg {
    --bs-offcanvas-bg: var(--app-menu-fondo);
    --bs-offcanvas-color: var(--app-menu-texto);
    --bs-offcanvas-width: var(--app-sidebar-w);
}

.app-sidebar-cuerpo {
    background: var(--app-menu-fondo);
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
    padding: 1.1rem .85rem;
    overflow-y: auto;
}

.app-brand {
    display: flex;
    align-items: center;
    gap: .7rem;
    padding: .25rem .5rem 1.25rem;
    color: #fff;
    text-decoration: none;
}

.app-brand:hover {
    color: #fff;
}

.app-brand-logo {
    display: grid;
    place-items: center;
    width: 2.25rem;
    height: 2.25rem;
    border-radius: .6rem;
    background: linear-gradient(135deg, #3987e5, #1c5cab);
    font-size: 1.15rem;
    flex-shrink: 0;
}

.app-brand strong {
    display: block;
    font-size: .95rem;
    letter-spacing: .02em;
}

.app-brand small {
    display: block;
    font-size: .7rem;
    color: var(--app-menu-titulo);
}

.app-section {
    margin: 1.1rem .6rem .4rem;
    font-size: .68rem;
    font-weight: 600;
    letter-spacing: .09em;
    text-transform: uppercase;
    color: var(--app-menu-titulo);
}

.app-nav-link {
    position: relative;
    display: flex;
    align-items: center;
    gap: .65rem;
    padding: .5rem .7rem;
    margin-bottom: .15rem;
    border-radius: .5rem;
    color: var(--app-menu-texto);
    font-size: .875rem;
    text-decoration: none;
    transition: background-color .15s, color .15s;
}

.app-nav-link i {
    font-size: 1rem;
    opacity: .85;
}

.app-nav-link:hover {
    background: rgba(255, 255, 255, .05);
    color: #fff;
}

.app-nav-link.active {
    background: var(--app-menu-activo);
    color: #fff;
    font-weight: 500;
}

.app-nav-link.active::before {
    content: "";
    position: absolute;
    left: -.85rem;
    top: .45rem;
    bottom: .45rem;
    width: 3px;
    border-radius: 0 3px 3px 0;
    background: #3987e5;
}

/* Estado de conexión a la BD de cada opción del menú (lo pinta ra.js con api/conexiones). */
.app-nav-estado {
    flex: none;
    width: .5rem;
    height: .5rem;
    margin-left: auto;
    border-radius: 50%;
    background: #6b7280;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, .06);
}

.app-nav-estado[data-estado="probando"] { animation: app-nav-estado-pulso 1.2s ease-in-out infinite; }
.app-nav-estado[data-estado="ok"] { background: #22c55e; box-shadow: 0 0 0 2px rgba(34, 197, 94, .2); }
.app-nav-estado[data-estado="error"] { background: #ef4444; box-shadow: 0 0 0 2px rgba(239, 68, 68, .25); }

@keyframes app-nav-estado-pulso { 50% { opacity: .35; } }

@media (prefers-reduced-motion: reduce) {
    .app-nav-estado[data-estado="probando"] { animation: none; }
}

.app-sidebar-pie {
    margin-top: auto;
    padding: 1rem .6rem 0;
    font-size: .72rem;
    color: var(--app-menu-titulo);
}

.app-contenido {
    flex-grow: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.app-topbar {
    position: sticky;
    top: 0;
    z-index: 1020;
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .7rem 1.5rem;
    background: color-mix(in srgb, var(--app-fondo) 85%, transparent);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--app-borde);
}

.app-topbar .breadcrumb {
    --bs-breadcrumb-divider-color: var(--bs-secondary-color);
}

.app-topbar .breadcrumb a {
    color: var(--bs-secondary-color);
    text-decoration: none;
}

.app-main {
    flex-grow: 1;
    padding: 1.5rem;
}

@media (max-width: 575.98px) {
    .app-main {
        padding: 1rem;
    }

    .app-topbar {
        padding: .6rem 1rem;
    }
}

/* ---------------------------------------------------------------- Encabezado de página */
.pagina-encabezado {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.pagina-icono {
    display: grid;
    place-items: center;
    width: 3rem;
    height: 3rem;
    border-radius: .8rem;
    background: var(--app-acento-suave);
    color: var(--app-acento);
    font-size: 1.4rem;
    flex-shrink: 0;
}

.pagina-encabezado h1 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: .2rem;
}

.pagina-encabezado p {
    color: var(--bs-secondary-color);
    margin-bottom: 0;
    max-width: 62rem;
}

/* ---------------------------------------------------------------- Indicadores (stat tiles) */
.stat {
    height: 100%;
    padding: .9rem 1rem;
    border: 1px solid var(--app-borde);
    border-radius: var(--app-radio);
    background: var(--app-superficie);
}

.stat-etiqueta {
    font-size: .78rem;
    color: var(--bs-secondary-color);
    margin-bottom: .2rem;
}

.stat-valor {
    font-size: 1.5rem;
    font-weight: 600;
    line-height: 1.2;
}

.stat-detalle {
    font-size: .75rem;
    color: var(--bs-secondary-color);
    margin-top: .15rem;
}

/* ---------------------------------------------------------------- Tablas: orden y búsqueda */
th[data-orden] {
    cursor: pointer;
    user-select: none;
}

th[data-orden]::after {
    content: "↕";
    margin-left: .3rem;
    opacity: .35;
    font-size: .75rem;
}

th[data-orden].orden-asc::after {
    content: "▲";
    opacity: .9;
    font-size: .6rem;
}

th[data-orden].orden-desc::after {
    content: "▼";
    opacity: .9;
    font-size: .6rem;
}

.tabla-scroll {
    max-height: 32rem;
    overflow: auto;
}

.tabla-scroll thead th {
    position: sticky;
    top: 0;
    background: var(--app-superficie);
    z-index: 1;
}

.buscador {
    max-width: 15rem;
}

tr[role="button"]:hover td {
    background: var(--app-acento-suave);
}

/* ---------------------------------------------------------------- Inicio */
.modulo-card {
    transition: border-color .15s, transform .15s;
}

.modulo-card:hover {
    border-color: var(--app-acento);
}

.actividad-item {
    display: flex;
    gap: .75rem;
    padding: .75rem 1rem;
    border-bottom: 1px solid var(--app-borde);
}

.actividad-item:last-child {
    border-bottom: 0;
}

.actividad-icono {
    font-size: 1.1rem;
    line-height: 1.4;
}

.origen-punto {
    display: inline-block;
    width: .55rem;
    height: .55rem;
    border-radius: 50%;
    background: var(--viz-muted);
}

/* ---------------------------------------------------------------- Medidor (meter) */
.medidor {
    height: .6rem;
    border-radius: 99px;
    background: var(--viz-pista);
    overflow: hidden;
}

.medidor > span {
    display: block;
    height: 100%;
    border-radius: 99px;
    background: var(--viz-serie);
}

.medidor.alerta > span {
    background: var(--viz-alerta);
}

.medidor.critico > span {
    background: var(--viz-critico);
}

/* ---------------------------------------------------------------- Gráficos */
.viz {
    position: relative;
    width: 100%;
    transition: opacity .2s;
}

.viz.cargando {
    opacity: .45;
}

.viz svg {
    display: block;
    overflow: visible;
}

.viz text {
    font-family: var(--app-font);
    font-size: 11px;
    fill: var(--viz-muted);
    font-variant-numeric: tabular-nums;
}

.viz .viz-valor {
    fill: var(--viz-texto);
    font-weight: 600;
}

.viz .viz-grid {
    stroke: var(--viz-grid);
    stroke-width: 1;
    shape-rendering: crispEdges;
}

.viz .viz-base {
    stroke: var(--viz-eje);
    stroke-width: 1;
    shape-rendering: crispEdges;
}

.viz .viz-marca {
    fill: var(--viz-serie);
    transition: opacity .12s;
}

.viz .viz-hit {
    fill: transparent;
    cursor: default;
    outline: none;
}

.viz .viz-hit:hover + .viz-marca, .viz .viz-hit:focus + .viz-marca,
.viz-barra-fila:hover .viz-barra, .viz-barra-fila:focus .viz-barra {
    opacity: .78;
}

.viz-vacio {
    display: grid;
    place-items: center;
    min-height: 8rem;
    color: var(--bs-secondary-color);
    font-size: .875rem;
}

/* Barras horizontales (HTML): etiqueta | barra con el valor en la punta */
.viz-barras {
    display: grid;
    gap: .35rem;
}

.viz-barra-fila {
    display: grid;
    grid-template-columns: var(--ancho-etiqueta, minmax(6rem, 38%)) 1fr;
    align-items: center;
    gap: .6rem;
    outline: none;
    border-radius: .35rem;
}

.viz-barra-fila:focus-visible {
    box-shadow: 0 0 0 2px var(--app-acento);
}

.viz-barra-etiqueta {
    font-size: .8rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--bs-body-color);
}

.viz-barra-pista {
    display: flex;
    align-items: center;
    gap: .4rem;
    min-width: 0;
}

.viz-barra {
    flex: 0 0 auto;
    height: 14px;
    width: calc((100% - 4.5rem) * var(--p, 0));
    min-width: 2px;
    border-radius: 0 4px 4px 0;
    background: var(--viz-serie);
    transition: width .35s ease, opacity .12s;
}

.viz-barra-valor {
    font-size: .75rem;
    color: var(--viz-texto);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.viz-tooltip {
    position: fixed;
    z-index: 2000;
    pointer-events: none;
    padding: .45rem .65rem;
    border-radius: .5rem;
    background: var(--app-superficie);
    border: 1px solid var(--app-borde);
    box-shadow: 0 6px 18px rgba(0, 0, 0, .14);
    font-size: .78rem;
    opacity: 0;
    transform: translateY(4px);
    transition: opacity .1s, transform .1s;
}

.viz-tooltip.visible {
    opacity: 1;
    transform: none;
}

.viz-tooltip strong {
    display: block;
    font-size: .95rem;
}

.viz-tooltip span {
    color: var(--bs-secondary-color);
}

/* ---------------------------------------------------------------- Carga SMPP por día: grilla de días */
.smpp-dias {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(5.5rem, 1fr));
    gap: .4rem;
}

.smpp-dia {
    display: flex;
    flex-direction: column;
    align-items: center;
    line-height: 1.15;
    padding: .3rem .25rem;
}

.smpp-dia-num {
    font-weight: 600;
}

.smpp-dia-filas {
    font-size: .7rem;
    min-height: .8rem;
}

/* ---------------------------------------------------------------- Pasos de un proceso */
.paso {
    display: flex;
    align-items: center;
    gap: .6rem;
}

/* ---------------------------------------------------------------- Utilidades */
.min-w-0 {
    min-width: 0;
}

.badge-suave {
    background: var(--bs-tertiary-bg);
    color: var(--bs-body-color);
    border: 1px solid var(--app-borde);
    font-weight: 500;
}

/* Textos técnicos largos (nombres de SP, servidores) no deben ensanchar la página en pantallas chicas */
code {
    overflow-wrap: anywhere;
}

.pagina-encabezado > div {
    min-width: 0;
}

.app-main {
    max-width: 100%;
    overflow-x: clip;
}

/* ---------------------------------------------------------------- Pre-factura SMPP (FACTURACIÓN) */
.factura {
    max-width: 72rem;
    margin: 0 auto;
}

.factura-hoja {
    box-shadow: 0 4px 24px rgba(16, 24, 40, .08);
}

.factura-hoja .stat {
    background: var(--app-fondo);
}

.factura-hoja .table thead th {
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .03em;
    color: var(--bs-secondary-color);
    white-space: nowrap;
}

.factura-hoja .table tfoot td {
    border-top: 2px solid var(--bs-border-color);
}

.factura-hoja .accordion-button {
    gap: .5rem;
    padding: .7rem 1rem;
}

.factura-hoja .accordion-button:not(.collapsed) {
    background: var(--app-acento-suave);
    color: inherit;
}

.factura-hoja details summary {
    cursor: pointer;
}

/* Selección de filas en el resumen SMPP */
.smpp-sel,
#smpp-sel-todos {
    cursor: pointer;
}

/* ---------------------------------------------------------------- Dashboard */
/* Variación contra el periodo anterior: neutra (subir no siempre es bueno: ver "Error de envío"). */
.delta {
    display: inline-flex;
    align-items: center;
    gap: .2rem;
    font-size: .75rem;
    color: var(--bs-secondary-color);
    white-space: nowrap;
}

.delta i {
    font-size: .7rem;
}

/* Tarjetas en 2 columnas solo si cada una tiene ~620 px (si no, una debajo de otra). */
.db-rejilla {
    display: grid;
    gap: 1rem;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 620px), 1fr));
}

.db-rankings {
    display: grid;
    gap: 1rem 1.5rem;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr));
}

.db-tiles .stat-valor {
    font-size: 1.3rem;
    white-space: nowrap;
}
