/* ============================================================
   LINARQ REGISTRADOR — RESPONSIVE & DESIGN SYSTEM
   Cubre: móvil portrait, móvil landscape, tablet y desktop.
   Las reglas de impresión preservan formato carta vertical.
   ============================================================ */

/* ------- VARIABLES DE DISEÑO ------- */
:root {
    --primary-color: #1D525B;
    --secondary-color: #088A68;
    --bg-light: #f8f9fc;
    --sidebar-width: 224px;
    --topbar-height: 4.375rem;
    --radius: 1rem;
    --shadow: 0 0.15rem 1.75rem 0 rgba(58, 59, 69, 0.12);
}

/* ------- BASE GLOBAL ------- */
body {
    font-family: 'Nunito', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    color: #3a3b45;
    -webkit-text-size-adjust: 100%; /* evita zoom automático en iOS */
}

/* ------- CARDS ------- */
.card {
    border: none;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 1.5rem;
}
.card-header {
    background-color: #fff;
    border-bottom: 1px solid #f2f4f6;
    padding: 1rem 1.5rem;
}

/* ------- BOTONES ------- */
.btn-primary {
    background-color: var(--primary-color);
    border: none;
    box-shadow: 0 4px 6px rgba(29, 82, 91, 0.2);
    transition: all 0.3s ease;
}
.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 12px rgba(29, 82, 91, 0.3);
    background-color: var(--primary-color);
    opacity: 0.92;
}

/* ------- SIDEBAR ------- */
.bg-gradient-primary {
    background-color: var(--primary-color) !important;
    background-image: linear-gradient(180deg, #1D525B 10%, #0e3038 100%) !important;
}
.sidebar-dark .sidebar-brand {
    color: #fff;
    background: rgba(0, 0, 0, 0.08);
    height: auto !important;
    padding: 1rem 0;
}
.sidebar-brand-icon img {
    max-height: 45px;
    width: auto !important;
}
.sidebar-dark .nav-item .nav-link {
    color: rgba(255, 255, 255, 0.82);
    font-weight: 600;
    padding: 0.75rem 1rem;
    border-radius: 0.5rem;
    margin: 0.1rem 0.5rem;
    transition: background 0.2s;
    white-space: nowrap;        /* texto en una sola línea siempre */
    overflow: hidden;
    text-overflow: ellipsis;
}
.sidebar-dark .nav-item .nav-link span {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: inline-block;
    max-width: calc(100% - 2rem); /* deja espacio al icono */
}
.sidebar-dark .nav-item.active .nav-link,
.sidebar-dark .nav-item .nav-link:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.12);
}

/* ------- SCROLLBAR PREMIUM ------- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: #f1f1f1; }
::-webkit-scrollbar-thumb { background: #c4c4c4; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #999; }
body { scrollbar-width: thin; scrollbar-color: #ccc transparent; }

/* ------- TARJETAS DE SERVICIO (dashboard) ------- */
.btn-card {
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}
.btn-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 14px 28px rgba(0,0,0,0.12), 0 10px 10px rgba(0,0,0,0.08) !important;
}
.btn-card .opacity-50 { opacity: 0.3; }
.btn-card:hover .opacity-50 { opacity: 1; transform: scale(1.1); transition: all 0.3s ease; }

/* ------- INDICADORES / GAUGES (actual.html) ------- */
#registro_actual {
    width: 100% !important;
    padding: 10px 0;
    display: flex !important;
    flex-wrap: wrap;
    align-items: stretch !important;
    justify-content: center;
    gap: 1.5rem;
}
#registro_actual .card {
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    border: none;
    min-width: 160px;
    max-width: 220px;
    flex: 1 1 160px;
    display: flex !important;
    flex-direction: column;
    height: auto !important;
}
#registro_actual .card:hover {
    transform: translateY(-4px);
    box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15) !important;
}
#registro_actual h6 {
    font-size: 0.8rem;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

/* ------- TABLAS RESPONSIVAS ------- */
.table-responsive {
    -webkit-overflow-scrolling: touch;
    border-radius: 0.5rem;
}
.table th, .table td {
    vertical-align: middle;
    word-break: break-word;
}

/* --- SIDEBAR TOGGLE DESKTOP: Desaparecer completamente --- */
#sidebarToggleTop {
    display: flex !important; /* Siempre visible, incluso en PC */
    align-items: center;
    justify-content: center;
    color: var(--primary-color) !important;
    font-size: 1.2rem;
    transition: all 0.2s ease;
}
#sidebarToggleTop:hover {
    background-color: rgba(0,0,0,0.05);
}

@media (min-width: 768px) {
    /* Cuando se activa el toggle en PC, ocultamos la barra totalmente */
    .sidebar.toggled {
        width: 0 !important;
        overflow: hidden;
        margin: 0 !important;
        padding: 0 !important;
        opacity: 0;
        pointer-events: none;
        transition: all 0.3s ease;
    }
    
    /* El contenedor de contenido se expande al 100% */
    #wrapper #content-wrapper {
        width: 100%;
        margin-left: 0;
        transition: all 0.3s ease;
    }

    /* Evitar que items del sidebar sigan ocupando espacio invisible */
    .sidebar.toggled .nav-item, 
    .sidebar.toggled .sidebar-brand,
    .sidebar.toggled .sidebar-divider {
        display: none !important;
    }
}

/* ============================================================
   DESKTOP (≥ 992px)
   ============================================================ */
@media (min-width: 992px) {
    #wrapper #content-wrapper {
        background-color: var(--bg-light);
    }
    .container-fluid {
        padding-left: 2rem;
        padding-right: 2rem;
    }
}

/* ============================================================
   TABLET (576px – 991px)
   ============================================================ */
@media (min-width: 576px) and (max-width: 991.98px) {
    .container-fluid {
        padding-left: 1rem;
        padding-right: 1rem;
    }

    /* Sidebar colapsado por defecto en tablet */
    #accordionSidebar {
        width: var(--sidebar-width);
    }

    /* Formularios en historial: apilar campos */
    #search .form-group .col-sm-3,
    #search .form-group .col-sm-2 {
        flex: 0 0 50%;
        max-width: 50%;
        margin-bottom: 0.5rem;
    }

    /* Notificaciones: ocultar columnas pesadas */
    #dataTableNotificaciones thead th:nth-child(6),
    #dataTableNotificaciones tbody td:nth-child(6) {
        display: none;
    }

    /* Indicadores más pequeños */
    #registro_actual .card { min-width: 140px; max-width: 200px; }
}

/* ============================================================
   MÓVIL — AMBAS ORIENTACIONES (≤ 767px)
   ============================================================ */
@media (max-width: 767.98px) {

    /* === LAYOUT BASE === */
    body { font-size: 0.9rem; }
    .container-fluid {
        padding-left: 0.6rem;
        padding-right: 0.6rem;
    }

    /* === WRAPPER: forzar flujo sin sidebar fijo === */
    #wrapper {
        display: flex;
        flex-direction: column;
    }
    #content-wrapper {
        width: 100% !important;
        margin-left: 0 !important;
    }

    /* === SIDEBAR: oculta fuera de pantalla — usa transform, NO width:0 para evitar
       conflicto con SB Admin 2 que aplica 'width:0 !important' a .sidebar.toggled === */
    .sidebar {
        display: flex !important;
        position: fixed !important;
        top: 0;
        left: 0;
        height: 100dvh;
        height: 100vh; /* fallback */
        z-index: 9999;
        width: 85vw !important;
        max-width: 320px;
        overflow-x: hidden !important;
        overflow-y: auto !important;
        transform: translateX(-110%);
        transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
        padding-bottom: 4rem !important;
    }

    /*SIDEBAR Brand en móvil */
    .sidebar .sidebar-brand {
        margin: 0 !important;
        padding: 10px 0 !important;
        display: flex !important;
        justify-content: center !important;
    }
    .sidebar .sidebar-brand-icon {
        margin: 0 !important;
        width: 80% !important;
    }
    .sidebar .sidebar-brand-icon img {
        max-height: 35px !important;
    }

    /* SIDEBAR ABIERTA en móvil — usando clase propia para evitar el conflicto de SB Admin 2 */
    body.sidebar-mobile-open .sidebar {
        transform: translateX(0) !important;
        /* Evita explícitamente que SB Admin 2 cierre con width:0 */
        width: 85vw !important;
        max-width: 320px;
        overflow-y: auto !important;
        padding-bottom: 80px !important; /* Espacio para barras de sistema/navegador */
    }

    /* Overlay semitransparente — visible solo cuando sidebar está abierta */
    #sidebar-overlay {
        display: none;
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        background: rgba(0, 0, 0, 0.6) !important;
        z-index: 9998 !important;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }
    body.sidebar-mobile-open #sidebar-overlay {
        display: block !important;
    }

    /* Nav links en móvil: 90% de ancho, alineación horizontal para ahorrar espacio */
    .sidebar-dark .nav-item {
        width: 100% !important;
        display: flex !important;
        justify-content: center !important;
        margin: 4px 0 !important;
    }
    .sidebar-dark .nav-item .nav-link {
        width: 90% !important; /* 90% del nav-item */
        display: flex !important;
        flex-direction: row !important; /* Icono y texto lado a lado */
        align-items: center !important;
        justify-content: flex-start !important;
        padding: 0.8rem 1rem !important;
        white-space: normal !important;
        overflow: visible !important;
        text-overflow: clip !important;
        background: rgba(255, 255, 255, 0.05);
        border-radius: 8px !important;
    }
    .sidebar-dark .nav-item .nav-link i {
        margin-right: 0.75rem !important;
        font-size: 1rem !important;
        width: 20px !important;
        text-align: center !important;
    }
    .sidebar-dark .nav-item .nav-link span {
        font-size: 0.9rem !important;
        line-height: 1.2 !important;
        white-space: normal !important;
        overflow: visible !important;
        text-overflow: clip !important;
        max-width: 100% !important;
        display: inline !important;
        text-align: left !important;
    }

    /* Dividers en móvil: siempre visibles y más suaves */
    .sidebar-divider {
        display: block !important;
        margin: 0.5rem 1rem !important;
        opacity: 0.15;
    }


    /* === TOPBAR === */
    .topbar {
        height: var(--topbar-height);
        padding: 0 0.75rem;
        position: sticky;
        top: 0;
        z-index: 1040;
    }
    .topbar h6 {
        font-size: 0.82rem;
        line-height: 1.2;
        max-width: 55vw;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    #sidebarToggleTop {
        min-width: 44px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
        flex-shrink: 0;
    }
    /* Nombre de usuario visible en móvil (quitar d-none d-lg-inline) */
    #user_name {
        display: inline !important;
        font-size: 0.78rem;
        max-width: 80px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    /* === BOTONES: área de toque mínima 44px === */
    .btn {
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        font-size: 0.85rem;
    }
    .btn-sm { min-height: 36px; font-size: 0.8rem; }
    .nav-link, .dropdown-item { min-height: 44px; }
    .sidebar .nav-item .nav-link { justify-content: flex-start; }

    /* === CARDS === */
    .card { border-radius: 0.75rem; }
    .card-body { padding: 1rem !important; }
    .card-header { padding: 0.75rem 1rem; }

    /* === INDICADORES (Gauges) === */
    #registro_actual {
        flex-direction: row !important;
        flex-wrap: wrap !important;
        gap: 0.75rem !important;
        justify-content: center;
    }
    #registro_actual .card {
        min-width: calc(50% - 0.75rem) !important;
        max-width: calc(50% - 0.75rem) !important;
        flex: 1 1 calc(50% - 0.75rem) !important;
        margin: 0 !important;
    }

    /* === FORMULARIO BÚSQUEDA (historial) === */
    #search .form-group { flex-direction: column; }
    #search .form-group > div {
        flex: 0 0 100%;
        max-width: 100%;
        margin-bottom: 0.5rem;
    }
    #search .btn { width: 100%; }

    /* === SELECTOR DE DECIMALES === */
    #DecimalChange .row {
        flex-wrap: nowrap;
        gap: 4px;
        overflow-x: auto;
        padding-bottom: 4px;
    }
    #DecimalChange .col-1 {
        flex: 0 0 auto;
        width: auto;
        padding: 0 4px;
    }
    #DecimalChange input[type="radio"].form-control {
        width: 20px;
        height: 20px;
        padding: 0;
        min-height: unset;
    }

    /* === TABLAS === */
    .table-responsive { overflow-x: auto; border: 0; }
    .table { font-size: 0.78rem; }
    .table th, .table td { padding: 0.4rem 0.5rem; white-space: nowrap; }

    /* === TABLA NOTIFICACIONES: ocultar cols pesadas === */
    #dataTableNotificaciones thead th:nth-child(6),
    #dataTableNotificaciones tbody td:nth-child(6),
    #dataTableNotificaciones thead th:nth-child(7),
    #dataTableNotificaciones tbody td:nth-child(7) {
        display: none;
    }

    /* === FILTROS DE NOTIFICACIONES === */
    #form_filter_notificaciones .form-row > div {
        flex: 0 0 100%;
        max-width: 100%;
        margin-bottom: 0.4rem;
    }

    /* === GRÁFICOS === */
    #graficas { gap: 10px; }
    #graficas .card { margin-bottom: 0.5rem; }

    /* === BARRA DE PROGRESO === */
    #progress { min-height: 20px; }

    /* === BOTONES DE ACCIÓN (print, back) === */
    .container-fluid .row .col-xl-6 {
        flex: 0 0 50%;
        max-width: 50%;
    }
    
    /* === FOOTER === */
    .sticky-footer .footer-content {
        flex-direction: column;
        gap: 6px !important;
        font-size: 0.78rem !important;
        text-align: center;
    }
    .sticky-footer .divider { display: none !important; }
}

/* ============================================================
   MÓVIL PORTRAIT ESPECÍFICO (≤ 480px)
   Pantallas muy pequeñas (iPhone SE, etc.)
   ============================================================ */
@media (max-width: 480px) {
    .topbar h6 { font-size: 0.75rem; max-width: 44vw; }

    /* Gauges en columna única en pantallas muy pequeñas */
    #registro_actual .card {
        min-width: 100% !important;
        max-width: 100% !important;
        flex: 0 0 100% !important;
    }

    /* Tabla historial: mostrar solo fecha + primera variable */
    .table { font-size: 0.72rem; }
    .table th, .table td { padding: 0.3rem 0.35rem; }

    /* Modal responsive */
    .modal-dialog { margin: 0.5rem; }
    .modal-content { border-radius: 0.75rem; }

    /* Botones de navegación (Registro Actual / Histórico) */
    .btn-primary.btn-user.btn-block { font-size: 0.8rem; padding: 0.5rem; }
}

/* ============================================================
   MÓVIL LANDSCAPE (alto ≤ 500px, ancho ≥ 576px)
   ============================================================ */
@media (max-height: 500px) and (min-width: 576px) and (orientation: landscape) {

    /* Topbar compacta */
    .topbar { height: 3.25rem; }
    .topbar h6 { font-size: 0.8rem; }

    /* Sidebar: altura completa y scroll */
    .sidebar {
        height: 100dvh;
        overflow-y: auto;
    }
    /* Reducir padding de items de sidebar */
    .sidebar-dark .nav-item .nav-link { padding: 0.5rem 1rem; }

    /* Indicadores en fila horizontal */
    #registro_actual {
        flex-direction: row !important;
        flex-wrap: nowrap !important;
        overflow-x: auto;
        justify-content: flex-start;
        gap: 0.75rem !important;
    }
    #registro_actual .card {
        min-width: 160px !important;
        max-width: 180px !important;
        flex: 0 0 160px !important;
    }

    /* Reducir padding de cards */
    .card-body { padding: 0.75rem !important; }

    /* Formulario en fila horizontal */
    #search .form-group { flex-direction: row; flex-wrap: wrap; }
    #search .form-group > div {
        flex: 0 0 48%;
        max-width: 48%;
        margin-bottom: 0.4rem;
    }
}

/* ============================================================
   TABLET LANDSCAPE / DESKTOP PEQUEÑO (768px – 991px landscape)
   ============================================================ */
@media (min-width: 768px) and (max-width: 991.98px) {
    .container-fluid { padding-left: 1.25rem; padding-right: 1.25rem; }
    #registro_actual .card { min-width: 150px; max-width: 210px; }
}

/* ============================================================
   IMPRESIÓN — CARTA VERTICAL (siempre, sin importar pantalla)
   ============================================================ */
@media print {
    /* Forzar orientación y tamaño carta vertical */
    @page {
        size: letter portrait;
        margin: 1.5cm 1.5cm 1.5cm 1.5cm;
    }

    /* Ocultar elementos que no deben imprimirse */
    .sidebar,
    #accordionSidebar,
    .topbar,
    #topbarload,
    #sidebarToggleTop,
    .no_print-2,
    .no-print,
    .btn,
    .scroll-to-top,
    .sticky-footer,
    #foot,
    .progress,
    #progress,
    #barra,
    #reloj,
    #downloadlink,
    #txt,
    #sidebar-overlay,
    #collapseSearch,
    .card-header .btn,
    nav.topbar {
        display: none !important;
    }

    /* Resetear layout para impresión */
    body {
        font-size: 11pt;
        color: #000 !important;
        background: #fff !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    #wrapper, #content-wrapper, #content {
        display: block !important;
        width: 100% !important;
        padding: 0 !important;
        margin: 0 !important;
    }
    .container-fluid {
        padding: 0 !important;
        margin: 0 !important;
        max-width: 100% !important;
    }

    /* Cards sin sombra en impresión */
    .card {
        border: 1px solid #ccc !important;
        box-shadow: none !important;
        border-radius: 0 !important;
        break-inside: avoid;
        margin-bottom: 0.5cm;
    }
    .card-header {
        background-color: #1D525B !important;
        color: #fff !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    .card-body { padding: 0.4cm !important; }

    /* Tablas: evitar cortes de fila */
    .table { font-size: 9pt; border-collapse: collapse !important; width: 100%; }
    .table th, .table td {
        border: 1px solid #999 !important;
        padding: 0.2cm 0.3cm;
        white-space: normal !important;
        word-break: break-word;
    }
    .table thead tr th {
        background-color: #e8f4f4 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    tr { break-inside: avoid; }
    .table-responsive { overflow: visible !important; }

    /* Gráficos: permitir que se escalen al ancho de la página */
    #graficas, #graficas .card, svg, canvas {
        max-width: 100% !important;
        width: 100% !important;
        height: auto !important;
    }

    /* Indicadores en grilla 3 columnas para impresión */
    #registro_actual {
        display: grid !important;
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 0.3cm !important;
    }
    #registro_actual .card {
        min-width: unset !important;
        max-width: unset !important;
        page-break-inside: avoid;
    }

    /* Logo visible en impresión */
    #logo_print { display: block !important; max-height: 2cm; }

    /* Colores primarios conservados */
    .bg-primary { background-color: #1D525B !important; }
    .text-primary { color: #1D525B !important; }
    .badge-success { background-color: #28a745 !important; color: #fff !important; }
    .badge-secondary { background-color: #6c757d !important; color: #fff !important; }

    /* Forzar ancho completo en columnas Bootstrap */
    .col-xl-12, .col-xl-6, .col-sm-12, .col-sm-6, .col-md-12 {
        flex: 0 0 100% !important;
        max-width: 100% !important;
    }
}
