/* Custom CSS para la plataforma */

/* Logo de la empresa en el sidebar */
.brand-link {
    border-bottom: 1px solid #4b545c;
}

.brand-image {
    opacity: .8;
}

/* Ajustes para formularios */
.form-group label {
    font-weight: 500;
}

/* Botones personalizados */
.btn-app {
    margin: 5px;
}

/* Tablas responsivas */
.table-responsive {
    overflow-x: auto;
}

/* Alerts personalizados */
.alert {
    border-radius: 0.25rem;
}

/* Loading spinner */
.htmx-indicator {
    display: none;
}

.htmx-request .htmx-indicator {
    display: inline-block;
}

.htmx-request.htmx-indicator {
    display: inline-block;
}

/* Fade transitions para HTMX */
.htmx-swapping {
    opacity: 0;
    transition: opacity 200ms ease-out;
}

/* Fondo para la página de login */
.login-page {
    background-image: url('../img/fondo1.png');
    background-size: cover;
    background-position: center center;
    background-repeat: no-repeat;
    background-attachment: fixed;
    min-height: 100vh;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Mejorar la visibilidad del card de login sobre el fondo */
.login-page .card {
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.5);
    background-color: rgba(255, 255, 255, 0.25);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.login-page .card-header {
    background-color: rgba(255, 255, 255, 0.2) !important;
    border-color: rgba(255, 255, 255, 0.3) !important;
    backdrop-filter: blur(5px);
}

.login-page .card-header a {
    color: rgba(255, 255, 255, 0.95) !important;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}

.login-page .card-body {
    background-color: rgba(255, 255, 255, 0.3);
}

.login-page .login-box-msg {
    color: rgba(0, 0, 0, 0.8);
    font-weight: 500;
}

.login-page .form-control {
    background-color: rgba(255, 255, 255, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.5);
}

.login-page .form-control::placeholder {
    color: rgba(0, 0, 0, 0.5);
}

.login-page .input-group-text {
    background-color: rgba(255, 255, 255, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.5);
}

.login-page label {
    color: rgba(0, 0, 0, 0.8);
    font-weight: 500;
}

.login-page .text-muted {
    color: rgba(0, 0, 0, 0.6) !important;
}

/* ============================================ */
/* RESPONSIVIDAD GLOBAL PARA TODO EL SITIO */
/* ============================================ */

/* Tablets y pantallas medianas (768px - 1024px) */
@media (max-width: 1024px) {
    /* Reducir tamaños de fuente */
    body {
        font-size: 0.9rem;
    }

    h1 { font-size: 1.75rem; }
    h2 { font-size: 1.5rem; }
    h3 { font-size: 1.25rem; }
    h4 { font-size: 1.1rem; }
    h5 { font-size: 1rem; }

    /* Cards más compactas */
    .card-body {
        padding: 1rem;
    }

    .card-header {
        padding: 0.75rem 1rem;
    }

    /* Botones más compactos */
    .btn {
        padding: 0.375rem 0.75rem;
        font-size: 0.875rem;
    }

    .btn-lg {
        padding: 0.5rem 1rem;
        font-size: 1rem;
    }

    /* Tablas más compactas */
    .table {
        font-size: 0.85rem;
    }

    .table th,
    .table td {
        padding: 0.5rem;
    }
}

/* Móviles y pantallas pequeñas (hasta 768px) */
@media (max-width: 768px) {
    /* Login page */
    .login-page {
        background-attachment: scroll;
        background-size: cover;
    }

    .login-box {
        width: 90%;
        margin: 2rem auto;
    }

    /* Reducir más los tamaños de fuente */
    body {
        font-size: 0.85rem;
    }

    h1 { font-size: 1.5rem; }
    h2 { font-size: 1.3rem; }
    h3 { font-size: 1.15rem; }
    h4 { font-size: 1rem; }
    h5 { font-size: 0.9rem; }

    /* Content header más compacto */
    .content-header {
        padding: 10px 0.5rem;
    }

    .content-header h1 {
        font-size: 1.3rem;
        margin: 0;
    }

    /* Contenido principal con menos padding */
    .content {
        padding: 0.5rem;
    }

    /* Cards aún más compactas */
    .card-body {
        padding: 0.75rem;
    }

    .card-header {
        padding: 0.5rem 0.75rem;
        font-size: 0.9rem;
    }

    /* Botones más pequeños */
    .btn {
        padding: 0.25rem 0.5rem;
        font-size: 0.8rem;
    }

    .btn-lg {
        padding: 0.4rem 0.8rem;
        font-size: 0.9rem;
    }

    /* Form controls más compactos */
    .form-control {
        padding: 0.375rem 0.5rem;
        font-size: 0.85rem;
    }

    .form-group {
        margin-bottom: 0.75rem;
    }

    .form-group label {
        font-size: 0.85rem;
        margin-bottom: 0.25rem;
    }

    /* Tablas muy compactas */
    .table {
        font-size: 0.75rem;
    }

    .table th,
    .table td {
        padding: 0.3rem;
    }

    /* Widget headers más pequeños */
    .widget-header {
        padding: 0.5rem;
        font-size: 0.9rem;
    }

    /* Grid más compacto */
    .row {
        margin-left: -5px;
        margin-right: -5px;
    }

    .row > [class*="col-"] {
        padding-left: 5px;
        padding-right: 5px;
    }

    /* Gráficos con altura mínima reducida */
    .widget-chart-container,
    .chart-container {
        min-height: 250px !important;
    }

    /* Paginación más compacta */
    .pagination {
        font-size: 0.75rem;
    }

    .page-link {
        padding: 0.25rem 0.5rem;
    }

    /* Sidebar más estrecho cuando está abierto */
    .main-sidebar {
        width: 220px;
    }

    /* Navbar items más compactos */
    .navbar-nav .nav-link {
        padding: 0.5rem;
    }
}

/* Móviles pequeños (hasta 480px) */
@media (max-width: 480px) {
    .login-page .card {
        background-color: rgba(255, 255, 255, 0.3);
    }

    /* Fuentes aún más pequeñas */
    body {
        font-size: 0.8rem;
    }

    h1 { font-size: 1.25rem; }
    h2 { font-size: 1.15rem; }
    h3 { font-size: 1rem; }
    h4 { font-size: 0.95rem; }
    h5 { font-size: 0.85rem; }

    /* Cards súper compactas */
    .card-body {
        padding: 0.5rem;
    }

    .card-header {
        padding: 0.4rem 0.5rem;
        font-size: 0.85rem;
    }

    /* Botones muy pequeños */
    .btn {
        padding: 0.2rem 0.4rem;
        font-size: 0.75rem;
    }

    .btn-lg {
        padding: 0.3rem 0.6rem;
        font-size: 0.85rem;
    }

    /* Form controls muy compactos */
    .form-control {
        padding: 0.3rem 0.4rem;
        font-size: 0.8rem;
    }

    .form-group {
        margin-bottom: 0.5rem;
    }

    .form-group label {
        font-size: 0.8rem;
        margin-bottom: 0.2rem;
    }

    /* Inputs de fecha más pequeños */
    input[type="date"],
    input[type="time"],
    input[type="datetime-local"] {
        font-size: 0.75rem;
    }

    /* Tablas súper compactas */
    .table {
        font-size: 0.7rem;
    }

    .table th,
    .table td {
        padding: 0.25rem;
    }

    /* Ocultar columnas menos importantes en tablas */
    .table .d-none-mobile {
        display: none !important;
    }

    /* Content con padding mínimo */
    .content {
        padding: 0.25rem;
    }

    .content-header {
        padding: 8px 0.25rem;
    }

    /* Gráficos con altura mínima muy reducida */
    .widget-chart-container,
    .chart-container {
        min-height: 200px !important;
    }

    /* Grid súper compacto */
    .row {
        margin-left: -3px;
        margin-right: -3px;
    }

    .row > [class*="col-"] {
        padding-left: 3px;
        padding-right: 3px;
    }

    /* Ocultar breadcrumbs en móviles pequeños */
    .breadcrumb {
        font-size: 0.7rem;
        padding: 0.3rem 0.5rem;
    }

    /* Sidebar colapsa por defecto */
    .main-sidebar {
        width: 200px;
    }
}

/* ============================================ */
/* AJUSTES ESPECÍFICOS PARA DASHBOARDS Y WIDGETS */
/* ============================================ */

/* Widgets responsivos */
@media (max-width: 768px) {
    /* GridStack widgets más pequeños */
    .grid-stack-item-content {
        overflow: hidden;
    }

    /* Widget body con scroll si necesario */
    .widget-body {
        overflow-x: auto;
        font-size: 0.85rem;
    }

    /* Info boxes más compactos */
    .info-box {
        min-height: 70px;
    }

    .info-box-icon {
        width: 70px;
        font-size: 2rem;
    }

    .info-box-content {
        padding: 5px 10px;
    }

    .info-box-text {
        font-size: 0.75rem;
    }

    .info-box-number {
        font-size: 1.2rem;
    }

    /* Dashboard date filters en móviles */
    .dashboard-date-filter {
        flex-direction: column;
    }

    .dashboard-date-filter .form-group {
        width: 100%;
        margin-bottom: 0.5rem;
    }
}

@media (max-width: 480px) {
    /* Info boxes súper compactos */
    .info-box {
        min-height: 60px;
    }

    .info-box-icon {
        width: 60px;
        font-size: 1.5rem;
    }

    .info-box-text {
        font-size: 0.7rem;
    }

    .info-box-number {
        font-size: 1rem;
    }
}

/* ============================================ */
/* AJUSTES PARA MODALES EN MÓVILES */
/* ============================================ */

@media (max-width: 768px) {
    .modal-dialog {
        margin: 0.5rem;
        max-width: calc(100% - 1rem);
    }

    .modal-header {
        padding: 0.75rem;
    }

    .modal-body {
        padding: 0.75rem;
    }

    .modal-footer {
        padding: 0.5rem;
    }

    .modal-title {
        font-size: 1rem;
    }
}

@media (max-width: 480px) {
    .modal-dialog {
        margin: 0.25rem;
        max-width: calc(100% - 0.5rem);
    }

    .modal-header {
        padding: 0.5rem;
    }

    .modal-body {
        padding: 0.5rem;
    }

    .modal-footer {
        padding: 0.4rem;
        flex-wrap: wrap;
    }

    .modal-footer .btn {
        margin: 0.2rem;
        flex: 1 1 auto;
    }
}

/* ============================================ */
/* AJUSTES PARA ALERTAS Y NOTIFICACIONES */
/* ============================================ */

@media (max-width: 768px) {
    .alert {
        padding: 0.5rem 0.75rem;
        font-size: 0.85rem;
    }

    .alert .close {
        padding: 0.5rem;
        font-size: 1.2rem;
    }

    /* Toastr notifications más pequeñas */
    #toast-container > div {
        padding: 10px;
        width: 280px;
    }
}

@media (max-width: 480px) {
    .alert {
        padding: 0.4rem 0.5rem;
        font-size: 0.8rem;
    }

    #toast-container > div {
        padding: 8px;
        width: 240px;
        font-size: 0.8rem;
    }
}

/* Navigation Tree Styles */
/* Dashboard icons in navigation */
.nav-treeview .nav-icon.text-info {
    color: #17a2b8 !important;
}

/* Form icons in navigation */
.nav-treeview .nav-icon.text-success {
    color: #28a745 !important;
}

/* Nested treeview indentation */
.nav-treeview .nav-treeview {
    padding-left: 1rem;
}

/* Module tree item spacing */
.nav-item.has-treeview > .nav-link .right {
    transition: transform 0.3s ease;
}

.nav-item.has-treeview.menu-open > .nav-link .right {
    transform: rotate(-90deg);
}

/* ============================================ */
/* QUERY BUILDER STYLES */
/* ============================================ */

/* Query Builder Wrapper */
.query-builder-wrapper {
    background-color: #f8f9fa;
    padding: 1.5rem;
    border-radius: 0.25rem;
    border: 1px solid #dee2e6;
}

/* Rules Container */
.qb-rules-container {
    margin-top: 1rem;
    min-height: 80px;
}

.qb-rules-container:empty::before {
    content: 'No hay reglas. Haz clic en "Agregar Regla" para comenzar.';
    display: block;
    text-align: center;
    color: #6c757d;
    font-style: italic;
    padding: 2rem;
    border: 2px dashed #dee2e6;
    border-radius: 0.25rem;
    background-color: #fff;
}

/* Individual Rule Card */
.qb-rule {
    transition: all 0.2s ease;
}

.qb-rule:hover {
    box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
}

.qb-rule .card-body {
    background-color: #fff;
}

/* Rule Inputs */
.qb-column-select,
.qb-operator-select,
.qb-value-single,
.qb-value-min,
.qb-value-max,
.qb-value-list {
    font-size: 0.9rem;
}

.qb-value-input {
    min-height: 38px;
    display: flex;
    align-items: center;
}

.qb-value-input em {
    font-size: 0.85rem;
}

/* Remove Rule Button */
.qb-remove-rule {
    width: 32px;
    height: 32px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.qb-remove-rule:hover {
    background-color: #c82333;
    border-color: #bd2130;
}

/* Logic Selector */
#qb-logic-selector {
    font-weight: 500;
}

/* Add Rule Button */
#qb-add-rule-btn {
    font-weight: 500;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .query-builder-wrapper {
        padding: 1rem;
    }

    .qb-rule .row {
        margin: 0;
    }

    .qb-rule .row > div {
        padding: 0.25rem;
    }

    .qb-rule .col-md-3,
    .qb-rule .col-md-5,
    .qb-rule .col-md-1 {
        flex: 0 0 100%;
        max-width: 100%;
        margin-bottom: 0.5rem;
    }

    .qb-rule .col-md-1 {
        text-align: left !important;
    }

    .qb-remove-rule {
        width: 100%;
        display: block;
    }

    .qb-value-input input[type="text"] {
        width: 100% !important;
        display: block !important;
        margin-bottom: 0.5rem;
    }

    .qb-value-input span {
        display: none;
    }
}

@media (max-width: 480px) {
    .query-builder-wrapper {
        padding: 0.75rem;
    }

    .qb-rules-container:empty::before {
        padding: 1rem;
        font-size: 0.85rem;
    }

    .qb-rule .card-body {
        padding: 0.75rem;
    }

    .qb-column-select,
    .qb-operator-select,
    .qb-value-single,
    .qb-value-min,
    .qb-value-max,
    .qb-value-list {
        font-size: 0.85rem;
    }

    #qb-logic-selector {
        max-width: 100% !important;
        font-size: 0.85rem;
    }

    #qb-add-rule-btn {
        width: 100%;
        font-size: 0.85rem;
    }
}

/* ========================================
   RESPONSIVE PREVIEW MODAL
   ======================================== */

.modal-fullscreen .modal-content {
    height: 100vh;
}

.modal-fullscreen .modal-body {
    overflow-y: auto;
}

.preview-toolbar {
    padding: 15px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.preview-container {
    min-height: 500px;
    padding: 20px;
    overflow: auto;
    max-height: calc(100vh - 200px);
}

.preview-viewport {
    transition: width 0.3s ease, height 0.3s ease;
    box-shadow: 0 10px 40px rgba(0,0,0,0.15);
    border: 1px solid #ddd;
    border-radius: 8px;
    overflow: hidden;
    background: white;
    position: relative;
}

.preview-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    z-index: 10;
}

.device-btn.active {
    background-color: #007bff;
    color: white;
}

#overflowWarning {
    animation: slideInDown 0.3s ease;
}

@keyframes slideInDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Responsive para móviles que usan el previsualizador */
@media (max-width: 768px) {
    .preview-viewport {
        max-width: 100% !important;
        max-height: calc(100vh - 250px) !important;
    }

    .preview-toolbar {
        flex-wrap: wrap;
    }

    .preview-toolbar .btn-group {
        margin-bottom: 10px;
    }

    .preview-toolbar .badge {
        display: block;
        margin: 5px auto;
    }
}

@media (max-width: 480px) {
    .preview-toolbar {
        padding: 10px;
    }

    .device-btn {
        font-size: 0.7rem;
        padding: 0.2rem 0.4rem;
    }

    .device-btn i {
        display: block;
        margin-bottom: 2px;
    }

    #rotateBtn {
        font-size: 0.7rem;
        padding: 0.2rem 0.4rem;
    }

    #dimensionInfo,
    #orientationInfo {
        font-size: 0.7rem;
    }
}
