
    /* Paleta inspirada en ThingsBoard (solo frontend) */
    .dashboard-container,
    .dashboard-container ~ * {
        --dashboard-bg: #f5f5f5;
        --widget-bg: #ffffff;
        --widget-border: #e0e0e0;
        --widget-radius: 8px;
        --toolbar-bg: #ffffff;
        --toolbar-border: #e8e8e8;
        --dashboard-accent: #2c7be5;
        --dashboard-accent-hover: #1e5bb8;
        --dashboard-title: #1a1d21;
        --dashboard-meta: #6c757d;
    }

    /* En móvil, contenedor principal sin overflow horizontal */
    @media (max-width: 768px) {
        #main.content:has(.dashboard-container),
        #main.content .dashboard-container {
            padding-left: 12px !important;
            padding-right: 12px !important;
            max-width: 100% !important;
            overflow-x: hidden !important;
        }
    }
    
    {% if is_public %}
    /* Estilos para modo público - sin navegación */
    body {
        overflow-x: hidden;
        margin: 0;
        padding: 0;
    }
    
    .content--public {
        padding: 0 !important;
        margin: 0 !important;
        max-width: 100% !important;
    }
    
    .dashboard-container {
        min-height: 100vh;
        background: var(--dashboard-bg);
        padding: 20px;
        width: 100%;
        max-width: 100%;
    }
    {% else %}
    .dashboard-container {
        min-height: calc(100vh - 200px);
        background: var(--dashboard-bg);
        padding: 20px;
    }
    {% endif %}
    
    .dashboard-header {
        background: var(--toolbar-bg);
        padding: 20px 24px;
        border-radius: var(--widget-radius);
        margin-bottom: 20px;
        border: 1px solid var(--toolbar-border);
        box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    }
    
    .dashboard-header-row {
        display: flex;
        flex-wrap: wrap;
        justify-content: space-between;
        align-items: flex-start;
        gap: 16px;
        margin-bottom: 16px;
    }
    
    .dashboard-header-title {
        min-width: 0;
    }
    
    .dashboard-header-toolbar {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: 12px;
    }
    
    .dashboard-periodo-wrap {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: 8px;
    }
    
    .dashboard-periodo-label {
        font-size: 13px;
        font-weight: 600;
        color: var(--dashboard-meta);
        white-space: nowrap;
    }
    
    .dashboard-periodo-btns .periodo-selector {
        font-size: 13px;
    }
    
    .dashboard-periodo-custom-wrap {
        position: relative;
        display: inline-block;
    }
    .dashboard-range-input-anchor {
        position: absolute;
        left: 0;
        top: 100%;
        width: 100%;
        height: 1px;
        margin: 0;
        padding: 0;
        border: 0;
        opacity: 0;
        pointer-events: none;
        font-size: 0;
    }
    .dashboard-range-input-anchor.range-visible {
        position: static;
        width: auto;
        min-width: 160px;
        max-width: 200px;
        height: auto;
        opacity: 1;
        pointer-events: auto;
        font-size: 12px;
        padding: 4px 8px;
        margin-left: 4px;
    }
    
    .dashboard-public-badge {
        margin: 0;
        padding: 8px 16px;
        display: inline-block;
    }
    
    .dashboard-title {
        font-size: 24px;
        font-weight: 600;
        color: var(--dashboard-title);
        margin: 0;
    }
    
    .dashboard-meta {
        color: var(--dashboard-meta);
        font-size: 14px;
        margin-top: 5px;
    }
    
    .dashboard-meta span + span {
        margin-left: 1rem;
    }
    
    .dashboard-meta span i {
        margin-right: 4px;
    }
    
    .dashboard-actions {
        margin-top: 15px;
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
        align-items: center;
    }
    
    .dashboard-actions .btn-primary.dashboard-save-pending {
        animation: dashboard-save-pulse 1.5s ease-in-out infinite;
        box-shadow: 0 0 0 0 rgba(40, 167, 69, 0.5);
    }
    
    @keyframes dashboard-save-pulse {
        0%, 100% { box-shadow: 0 0 0 0 rgba(40, 167, 69, 0.4); }
        50%  { box-shadow: 0 0 0 6px rgba(40, 167, 69, 0); }
    }
    
    /* ✅ Estilos para el selector de período global */
    .btn-group .periodo-selector {
        transition: all 0.2s ease;
        border: 1px solid #dee2e6;
    }
    
    .btn-group .periodo-selector:hover {
        background-color: #e9ecef;
        border-color: #adb5bd;
        transform: translateY(-1px);
    }
    
    .btn-group .periodo-selector.active,
    .btn-group .periodo-selector.btn-primary {
        background-color: var(--dashboard-accent);
        border-color: var(--dashboard-accent);
        color: white;
        font-weight: 600;
        box-shadow: 0 2px 4px rgba(44, 123, 229, 0.3);
    }
    
    .btn-group .periodo-selector.active:hover,
    .btn-group .periodo-selector.btn-primary:hover {
        background-color: var(--dashboard-accent-hover);
        border-color: var(--dashboard-accent-hover);
        transform: translateY(-1px);
    }
    
    /* Fuente digital Handjet para KPI e indicadores (desktop y móvil) */
    .widget-value-digital,
    .widget-value-digital.kpi-indicator-value,
    span.widget-value-digital,
    span.kpi-indicator-value,
    .kpi-widget .widget-value-digital,
    .kpi-widget .kpi-indicator-value,
    .kpi-widget .kpi-indicator-card .widget-value-digital {
        font-family: "Handjet", sans-serif !important;
        font-optical-sizing: auto;
        font-style: normal;
        font-variation-settings: "ELGR" 1, "ELSH" 2;
        font-variant-numeric: tabular-nums;
    }
    .kpi-widget {
        position: relative;
        min-height: 120px;
        flex: 1;
        min-height: 0;
        display: flex;
        flex-direction: column;
        container-type: size;
        container-name: kpi-widget;
    }
    .widget-content > .kpi-widget {
        flex: 1;
        min-height: 0;
    }
    /* Tarjeta KPI ocupa todo el contenedor; fuentes dinámicas según tamaño del widget (cqw = % ancho contenedor) */
    .kpi-indicator-card {
        width: 100%;
        height: 100%;
        min-height: 0;
    }
    .kpi-indicator-card .kpi-indicator-icon {
        font-size: clamp(1.25rem, 8cqw, 3.5rem);
        height: 1em;
        width: 1em;
    }
    .kpi-indicator-card .kpi-indicator-value {
        font-size: clamp(20px, 8cqw, 60px);
    }
    .kpi-indicator-card .kpi-unit {
        font-size: clamp(0.65rem, 2.2cqw, 1rem);
    }
    .kpi-indicator-card .kpi-channel {
        font-size: clamp(0.6rem, 2cqw, 0.9rem);
    }
    .kpi-indicator-card .kpi-meta {
        font-size: clamp(0.5rem, 1.5cqw, 0.75rem);
    }
    
    .widget-grid {
        min-height: 400px;
    }
    
    .grid-stack {
        background: transparent;
    }
    
    .grid-stack-item {
        background: transparent;
    }
    
    .grid-stack-item-content {
        background: var(--widget-bg);
        border: 1px solid var(--widget-border);
        border-radius: var(--widget-radius);
        box-shadow: 0 1px 2px rgba(0,0,0,0.04);
        padding: 15px;
        position: relative;
        cursor: move;
        transition: box-shadow 0.2s ease;
        min-height: 200px;
        overflow: hidden;
    }
    
    /* ✅ Permitir arrastre desde el header, pero no desde el canvas del gráfico */
    .widget-header {
        cursor: move;
        user-select: none;
        position: relative;
        z-index: 10;
    }
    
    .widget-title {
        cursor: move;
        user-select: none;
    }
    
    .chart-container {
        pointer-events: auto;
        position: relative;
        z-index: 1;
    }
    /* Alerta visual: fondo rojo suave cuando se supera umbral (CO2, Ruido, Voltaje) */
    .grid-stack-item-content.widget-alert-bg {
        background: linear-gradient(135deg, #fff5f5 0%, #ffe5e5 100%);
        border-left-color: rgba(220, 53, 69, 0.5) !important;
    }
    
    .chart-container canvas {
        pointer-events: auto;
    }
    
    /* Cuando se está arrastrando, deshabilitar interacción con el gráfico */
    .grid-stack-item.ui-draggable-dragging .chart-container,
    .grid-stack-item.ui-draggable-dragging .chart-container canvas {
        pointer-events: none;
    }
    
    /* ✅ Asegurar que los controles del widget no bloqueen el arrastre */
    .widget-controls {
        position: relative;
        z-index: 20;
    }
    
    .grid-stack-item-content:hover {
        box-shadow: 0 4px 8px rgba(0,0,0,0.15);
    }
    
    .grid-stack-item.ui-draggable-dragging .grid-stack-item-content {
        opacity: 0.7;
        transform: rotate(2deg);
    }
    
    .widget {
        background: white;
        border-radius: 8px;
        box-shadow: 0 2px 4px rgba(0,0,0,0.1);
        padding: 15px;
        position: relative;
        cursor: move;
        transition: box-shadow 0.2s ease;
        min-height: 200px;
        overflow: hidden;
    }
    
    .widget:hover {
        box-shadow: 0 4px 8px rgba(0,0,0,0.15);
    }
    
    .widget.dragging {
        opacity: 0.7;
        transform: rotate(2deg);
    }
    
    .widget-header {
        display: flex;
        flex-wrap: wrap;
        justify-content: space-between;
        align-items: center;
        gap: 8px;
        margin-bottom: 15px;
        padding-bottom: 10px;
        border-bottom: 1px solid #eee;
        min-width: 0;
    }
    .widget-header > div:first-child {
        min-width: 0;
        flex: 1 1 120px;
    }
    .widget-title {
        font-size: clamp(14px, 2vw, 18px);
        font-weight: 600;
        color: #333;
        margin: 0;
        line-height: 1.3;
        word-break: break-word;
    }
    .widget-controls {
        display: flex;
        flex-wrap: wrap;
        gap: 4px;
        align-items: center;
        flex-shrink: 0;
    }
    .widget-control-btn {
        background: none;
        border: none;
        color: #666;
        cursor: pointer;
        padding: clamp(4px, 1vw, 6px) clamp(6px, 1.2vw, 8px);
        border-radius: 4px;
        transition: background-color 0.2s;
        flex-shrink: 0;
    }
    .widget-control-btn i {
        font-size: clamp(12px, 1.8vw, 16px);
    }
    
    .widget-control-btn:hover {
        background: #f0f0f0;
        color: #333;
    }
    
    .widget-content {
        height: calc(100% - 50px);
        position: relative;
        overflow: hidden;
        display: flex;
        flex-direction: column;
    }
    
    .chart-container {
        flex: 1;
        position: relative;
        width: 100%;
        height: 100%;
        min-height: 260px;
        overflow: hidden;
        display: flex;
        flex-direction: column;
    }
    /* Termómetro: rellenar y adaptar al contenedor sin cortes; contenido centrado y escalado */
    .chart-container:has(.widget-thermometer-wrap) {
        display: flex;
        align-items: center;
        justify-content: center;
        overflow: hidden;
        min-height: 0;
    }
    .chart-container:has(.widget-thermometer-wrap) .widget-chart {
        display: flex;
        width: 100%;
        height: 100%;
        min-height: 0;
        align-items: center;
        justify-content: center;
    }
    .widget-thermometer-wrap {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        width: 100%;
        height: 100%;
        max-width: 100%;
        max-height: 100%;
        min-height: 0;
        min-width: 200px;
        min-height: 220px;
        overflow: hidden;
        box-sizing: border-box;
        padding: clamp(8px, 2vw, 20px);
    }
    .widget-thermometer-container {
        flex: 1 1 auto;
        min-height: 200px;
        min-width: 180px;
        max-width: 100%;
        max-height: 100%;
        display: flex;
        align-items: center;
        justify-content: center;
        position: relative;
    }
    .widget-thermometer-marker-value {
        font-size: clamp(14px, 2.5vw, 20px);
        font-weight: 600;
    }
    .widget-thermometer-container svg {
        max-width: 100%;
        max-height: 100%;
        min-width: 160px;
        min-height: 140px;
        width: auto;
        height: auto;
        display: block;
        flex-shrink: 1;
    }
    
    .chart-container.pan-enabled canvas {
        cursor: grab !important;
    }
    
    .chart-container.pan-enabled canvas:active {
        cursor: grabbing !important;
    }
    
    .chart-container[data-hint]::after {
        content: attr(data-hint);
        position: absolute;
        bottom: 8px;
        right: 12px;
        font-size: 10px;
        color: #495057;
        background: rgba(255, 255, 255, 0.88);
        border-radius: 999px;
        padding: 2px 8px;
        box-shadow: 0 1px 4px rgba(0,0,0,0.15);
        opacity: 0;
        transition: opacity 0.2s ease;
        pointer-events: none;
    }
    
    .chart-container[data-hint]:hover::after {
        opacity: 1;
    }
    
    /* ✅ Estilos para hacer Plotly más accesible */
    .plotly-help-panel {
        position: absolute;
        top: 10px;
        right: 10px;
        background: rgba(255, 255, 255, 0.95);
        border: 2px solid #007bff;
        border-radius: 8px;
        padding: 12px;
        box-shadow: 0 4px 12px rgba(0,0,0,0.15);
        z-index: 100;
        max-width: 280px;
        font-size: 12px;
        display: none;
    }
    
    .plotly-help-panel.show {
        display: block;
        animation: slideInRight 0.3s ease;
    }
    
    @keyframes slideInRight {
        from {
            transform: translateX(100%);
            opacity: 0;
        }
        to {
            transform: translateX(0);
            opacity: 1;
        }
    }
    
    .plotly-help-panel h5 {
        margin: 0 0 8px 0;
        color: #007bff;
        font-size: 14px;
        display: flex;
        align-items: center;
        gap: 6px;
    }
    
    .plotly-help-header {
        display: flex;
        align-items: center;
        gap: 6px;
    }
    
    .plotly-help-panel .help-item {
        margin: 6px 0;
        padding: 4px 0;
        border-bottom: 1px solid #e9ecef;
    }
    
    .plotly-help-panel .help-item:last-child {
        border-bottom: none;
    }
    
    .plotly-help-panel .help-item strong {
        color: #495057;
        display: block;
        margin-bottom: 2px;
    }
    
    .plotly-help-panel .help-item span {
        color: #6c757d;
        font-size: 11px;
    }
    
    .plotly-help-panel .plotly-help-close {
        background: none;
        border: none;
        color: #6c757d;
        font-size: 16px;
        cursor: pointer;
        padding: 0;
        margin-left: auto;
    }
    
    .plotly-help-panel .plotly-help-close:hover {
        color: #343a40;
    }
    
    
    .plotly-instruction-overlay {
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.7);
        display: none;
        align-items: center;
        justify-content: center;
        z-index: 1000;
        border-radius: 8px;
    }
    
    .plotly-instruction-overlay.show {
        display: flex;
    }
    
    .plotly-instruction-box {
        background: white;
        border-radius: 12px;
        padding: 24px;
        max-width: 500px;
        box-shadow: 0 8px 32px rgba(0,0,0,0.3);
    }
    
    .plotly-instruction-box h3 {
        color: #007bff;
        margin: 0 0 16px 0;
    }
    
    .plotly-instruction-box .instruction-step {
        margin: 12px 0;
        padding: 12px;
        background: #f8f9fa;
        border-radius: 6px;
        border-left: 4px solid #007bff;
    }
    
    .plotly-instruction-box .instruction-step strong {
        color: #007bff;
        display: block;
        margin-bottom: 4px;
    }
    
    .save-hint {
        position: fixed;
        bottom: 24px;
        right: 24px;
        background: #212529;
        color: #f8f9fa;
        padding: 14px 18px;
        border-radius: 12px;
        box-shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
        display: flex;
        align-items: center;
        gap: 10px;
        font-size: 14px;
        line-height: 1.3;
        z-index: 1200;
        opacity: 0;
        transform: translateY(20px);
        pointer-events: none;
        transition: opacity 0.25s ease, transform 0.25s ease;
    }
    
    .save-hint.visible {
        opacity: 0.95;
        transform: translateY(0);
    }
    
    .save-hint .hint-icon {
        font-size: 18px;
    }
    
    .widget-chart {
        width: 100% !important;
        height: 100% !important;
        min-height: 260px;
        flex: 1;
        position: relative;
    }
    
    .widget-chart canvas {
        width: 100% !important;
        height: 100% !important;
        display: block !important;
    }
    
    /* Asegurar que Plotly use el espacio completo */
    .widget-chart .js-plotly-plot {
        width: 100% !important;
        height: 100% !important;
    }
    
    /* Asegurar que los widgets mantengan su tamaño en el grid */
    .widget[style*="grid-column"] {
        min-height: 200px !important;
    }
    
    /* Estilos específicos para diferentes tamaños de widgets */
    .widget[style*="span 3"] { min-height: 150px; }
    .widget[style*="span 4"] { min-height: 180px; }
    .widget[style*="span 6"] { min-height: 200px; }
    .widget[style*="span 8"] { min-height: 220px; }
    .widget[style*="span 12"] { min-height: 250px; }
    
    /* Handles de resize mejorados */
    .ui-resizable-handle {
        background: linear-gradient(-45deg, transparent 30%, #007bff 30%, #007bff 50%, transparent 50%);
        border-radius: 0 0 8px 0;
        opacity: 0;
        transition: opacity 0.2s ease;
        z-index: 10;
    }
    
    .grid-stack-item:hover .ui-resizable-handle {
        opacity: 1;
    }
    
    .ui-resizable-handle:hover {
        background: linear-gradient(-45deg, transparent 30%, #0056b3 30%, #0056b3 50%, transparent 50%);
    }
    
    .ui-resizable-se {
        width: 20px;
        height: 20px;
        bottom: 0;
        right: 0;
        cursor: se-resize;
    }
    
    .ui-resizable-s {
        height: 8px;
        bottom: 0;
        left: 50%;
        transform: translateX(-50%);
        width: 40px;
        background: #007bff;
        border-radius: 4px;
        cursor: s-resize;
    }
    
    .ui-resizable-e {
        width: 8px;
        right: 0;
        top: 50%;
        transform: translateY(-50%);
        height: 40px;
        background: #007bff;
        border-radius: 4px;
        cursor: e-resize;
    }
    
    .loading-spinner {
        display: flex;
        justify-content: center;
        align-items: center;
        height: 200px;
        color: transparent;
        background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
        background-size: 200% 100%;
        animation: skeleton-loading 1.5s infinite;
        border-radius: var(--widget-radius, 8px);
    }
    
    @keyframes skeleton-loading {
        0% { background-position: 200% 0; }
        100% { background-position: -200% 0; }
    }
    
    .error-message {
        color: #dc3545;
        text-align: center;
        padding: 20px;
    }
    
    .last-update {
        position: absolute;
        top: 5px;
        right: 5px;
        font-size: 10px;
        color: #999;
        background: rgba(255,255,255,0.8);
        padding: 2px 5px;
        border-radius: 3px;
        z-index: 10;
    }
    
    .empty-dashboard {
        text-align: center;
        padding: 60px 20px;
        color: #666;
    }
    
    .empty-dashboard h3 {
        margin-bottom: 15px;
    }
    
    .btn {
        padding: 8px 16px;
        border: none;
        border-radius: 4px;
        text-decoration: none;
        font-size: 14px;
        cursor: pointer;
        transition: background-color 0.2s;
        display: inline-flex;
        align-items: center;
        gap: 5px;
    }
    
    .btn-primary {
        background: #007bff;
        color: white;
    }
    
    .btn-primary:hover {
        background: #0056b3;
        color: white;
    }
    
    .btn-success {
        background: #28a745;
        color: white;
    }
    
    .btn-success:hover {
        background: #1e7e34;
        color: white;
    }
    
    .btn-secondary {
        background: #6c757d;
        color: white;
    }
    
    .btn-secondary:hover {
        background: #545b62;
        color: white;
    }
    
    .btn-danger {
        background: #dc3545;
        color: white;
    }
    
    .btn-danger:hover {
        background: #c82333;
        color: white;
    }
    
    /* Mejoras visuales para widgets */
    .grid-stack-item {
        transition: all 0.2s ease;
        border-radius: 12px;
        overflow: hidden;
        box-shadow: 0 2px 8px rgba(0,0,0,0.08);
        border: 1px solid #e9ecef;
        position: relative;
        z-index: 1;
        min-height: 200px;  /* Altura mínima para widgets */
        min-width: 300px;   /* Ancho mínimo para widgets */
    }
    
    .grid-stack-item.ui-draggable-dragging {
        z-index: 1000 !important;
    }
    
    .grid-stack-item:hover {
        box-shadow: 0 4px 16px rgba(0,0,0,0.12);
        transform: translateY(-1px);
    }
    
    .grid-stack-item.ui-draggable-dragging {
        z-index: 1000;
        transform: rotate(2deg);
        box-shadow: 0 8px 32px rgba(0,0,0,0.2);
    }
    
    .grid-stack-item.ui-resizable-resizing {
        z-index: 1000;
        box-shadow: 0 4px 16px rgba(0, 123, 255, 0.3);
    }
    
    .grid-stack-item-content {
        background: white;
        border-radius: 12px;
        padding: 0;
        position: relative;
        cursor: move;
        transition: box-shadow 0.2s ease;
        min-height: 200px;
        overflow: hidden;
        height: 100%;
        display: flex;
        flex-direction: column;
    }
    
    .grid-stack-item-content:hover {
        box-shadow: 0 4px 8px rgba(0,0,0,0.15);
    }
    
    /* Widget header mejorado */
    .widget-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 16px 20px;
        border-bottom: 1px solid #e9ecef;
        background: #f8f9fa;
        font-weight: 600;
        font-size: 16px;
        color: #495057;
        transition: background-color 0.2s ease;
        cursor: move;
        user-select: none;
        min-height: 60px;
    }
    
    .widget-header:hover {
        background: #e9ecef;
    }
    
    .widget-title {
        font-size: 16px;
        font-weight: 600;
        color: #333;
        margin: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    
    .widget-controls {
        display: flex;
        gap: 8px;
        align-items: center;
    }
    
    .widget-control-btn {
        background: rgba(255, 255, 255, 0.95);
        border: 1px solid #dee2e6;
        color: #6c757d;
        cursor: pointer;
        padding: 8px 10px;
        border-radius: 6px;
        transition: all 0.2s ease;
        font-size: 14px;
        min-width: 36px;
        min-height: 36px;
        display: flex;
        align-items: center;
        justify-content: center;
        box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    }
    
    .widget-control-btn:hover {
        background: #f8f9fa;
        color: #495057;
        transform: translateY(-1px);
        box-shadow: 0 4px 8px rgba(0,0,0,0.15);
    }
    
    .widget-control-btn.danger:hover {
        background: #dc3545;
        color: white;
    }
    
    
    .widget-content {
        flex: 1;
        min-height: 0;
        position: relative;
        overflow: hidden;
        padding: 16px;
    }
    
    /* Responsive */
    @media (max-width: 768px) {
        .dashboard-container {
            padding: 8px;
        }
        
        .dashboard-header {
            padding: 16px;
        }
        
        .dashboard-title {
            font-size: 20px;
        }
        
        .dashboard-actions {
            flex-direction: column;
            align-items: stretch;
        }
        
        .btn {
            justify-content: center;
        }
        
        .widget-header {
            padding: 8px 12px;
            font-size: 13px;
        }
        
        .widget-control-btn {
            padding: 3px 6px;
            font-size: 11px;
        }
    }
    
    /* Modal de confirmación para eliminar widget */
    .modal-overlay-widget {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.6);
        z-index: 9999;
        align-items: center;
        justify-content: center;
    }
    
    .modal-overlay-widget.active {
        display: flex;
    }
    
    .modal-confirm-widget {
        background: white;
        border-radius: 12px;
        padding: 30px;
        max-width: 500px;
        width: 90%;
        box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
        animation: slideIn 0.3s ease;
    }
    
    @keyframes slideIn {
        from {
            transform: translateY(-50px);
            opacity: 0;
        }
        to {
            transform: translateY(0);
            opacity: 1;
        }
    }
    
    .modal-confirm-widget h3 {
        margin: 0 0 15px 0;
        color: #dc3545;
        font-size: 22px;
        display: flex;
        align-items: center;
        gap: 10px;
    }
    
    .modal-confirm-widget p {
        color: #666;
        margin-bottom: 20px;
        line-height: 1.5;
    }
    
    .modal-confirm-widget .confirm-input {
        width: 100%;
        padding: 12px;
        border: 2px solid #ddd;
        border-radius: 6px;
        font-size: 15px;
        margin-bottom: 20px;
        transition: border-color 0.2s;
    }
    
    .modal-confirm-widget .confirm-input:focus {
        outline: none;
        border-color: #dc3545;
    }
    
    .modal-confirm-widget .modal-actions {
        display: flex;
        gap: 10px;
        justify-content: flex-end;
    }
    
    .modal-confirm-widget .btn-cancel {
        background: #6c757d;
        color: white;
        padding: 8px 16px;
        border-radius: 4px;
        border: none;
        cursor: pointer;
    }
    
    .modal-confirm-widget .btn-cancel:hover {
        background: #5a6268;
    }
    
    .modal-confirm-widget .btn-danger {
        padding: 8px 16px;
    }
    
    .modal-loading-overlay {
        position: absolute;
        inset: 0;
        background: rgba(255,255,255,0.85);
        border-radius: 12px;
        display: none;
        align-items: center;
        justify-content: center;
        flex-direction: column;
        gap: 10px;
        z-index: 10;
        font-size: 14px;
        color: #0d6efd;
    }
    
    .modal-loading-overlay.active {
        display: flex;
    }
    
    /* Estilos para el modal de información del canal */
    .swal2-popup-custom {
        font-family: 'Inter', sans-serif;
    }
    
    .swal2-popup-custom h6 {
        font-weight: 600;
        font-size: 14px;
        margin-bottom: 8px;
        display: flex;
        align-items: center;
        gap: 6px;
    }
    
    .swal2-popup-custom p {
        font-size: 13px;
        line-height: 1.6;
        color: #495057;
    }
    
    /* ✅ Responsive Design para Pantallas Medianas (Tablets) */
    @media (min-width: 769px) and (max-width: 992px) {
        .dashboard-container {
            padding: 12px;
        }
        
        .dashboard-header {
            padding: 18px;
        }
        
        .dashboard-title {
            font-size: 24px;
        }
        
        .dashboard-actions {
            flex-wrap: wrap;
            gap: 10px;
        }
        
        .dashboard-actions .btn {
            font-size: 14px;
            padding: 10px 16px;
            min-width: 140px;
        }
        
        .widget-header {
            padding: 12px 16px;
            font-size: 15px;
        }
        
        .widget-title {
            font-size: 17px;
        }
        
        .widget-control-btn {
            width: 38px;
            height: 38px;
            font-size: 14px;
        }
        
        .grid-stack-item-content {
            padding: 14px;
            min-height: 250px;
        }
        
        .chart-container {
            min-height: 250px;
        }
        
        /* Ajustar GridStack para tablets */
        .grid-stack {
            margin: 10px 0;
        }
        
        .grid-stack-item {
            margin-bottom: 10px;
        }
    }
    
    /* ✅ Responsive Design para Pantallas Medianas-Grandes (Tablets horizontales / Pantallas pequeñas) */
    @media (min-width: 993px) and (max-width: 1200px) {
        .dashboard-container {
            padding: 15px;
        }
        
        .dashboard-header {
            padding: 20px;
        }
        
        .dashboard-title {
            font-size: 26px;
        }
        
        .dashboard-actions {
            gap: 12px;
        }
        
        .dashboard-actions .btn {
            font-size: 15px;
            padding: 11px 18px;
        }
        
        .widget-header {
            padding: 14px 18px;
            font-size: 16px;
        }
        
        .widget-title {
            font-size: 18px;
        }
        
        .grid-stack-item-content {
            padding: 16px;
        }
        
        .chart-container {
            min-height: 280px;
        }
    }
    
    /* ✅ Responsive Design para Móviles Pequeños (iPhone SE, etc.) */
    @media (max-width: 375px) {
        .dashboard-container {
            padding: 8px;
        }
        
        .dashboard-header {
            padding: 12px;
        }
        
        .dashboard-title {
            font-size: 18px;
            line-height: 1.3;
        }
        
        .dashboard-actions {
            display: flex;
            flex-wrap: wrap;
            gap: 6px;
        }
        
        .dashboard-actions .btn {
            flex: 1 1 calc(50% - 3px);
            min-width: 0;
            font-size: 12px;
            padding: 8px 10px;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }
        
        .dashboard-actions .btn i {
            font-size: 11px;
        }
        
        /* ✅ WIDGETS COMO TARJETAS CLICKEABLES EN MÓVILES PEQUEÑOS */
        .grid-stack-item {
            cursor: pointer;
            transition: transform 0.2s ease, box-shadow 0.2s ease;
        }
        
        .grid-stack-item:active {
            transform: scale(0.98);
        }
        
        .grid-stack-item-content {
            padding: 12px;
            min-height: 200px;
            position: relative;
        }
        
        /* Ocultar controles de widget en móviles pequeños - solo mostrar título y gráfico mini */
        .widget-controls {
            display: none !important;
        }
        
        .widget-header {
            padding: 10px 12px;
            font-size: 13px;
            border-bottom: 2px solid #e9ecef;
            margin-bottom: 10px;
        }
        
        .widget-title {
            font-size: 14px;
            line-height: 1.3;
            margin: 0;
        }
        
        /* Gráficos mini en tarjetas - altura reducida */
        .chart-container {
            min-height: 150px !important;
            max-height: 150px !important;
            height: 150px !important;
            width: 100% !important;
            max-width: 100% !important;
            overflow: hidden;
            position: relative;
        }
        
        /* Indicador de "Toca para ver más" */
        .grid-stack-item-content::after {
            content: "👆 Toca para ver gráfico completo";
            position: absolute;
            bottom: 8px;
            right: 8px;
            font-size: 10px;
            color: #6c757d;
            background: rgba(255, 255, 255, 0.9);
            padding: 4px 8px;
            border-radius: 4px;
            pointer-events: none;
        }
        
        /* Forzar que Plotly use el ancho completo pero altura reducida */
        .js-plotly-plot,
        .widget-chart,
        .plotly {
            width: 100% !important;
            max-width: 100% !important;
            height: 150px !important;
            min-height: 150px !important;
            max-height: 150px !important;
            overflow: hidden;
        }
        
        /* Canvas de Chart.js también */
        canvas {
            max-width: 100% !important;
            height: 150px !important;
        }
        
        /* Ajustar textos pequeños */
        .text-muted, small {
            font-size: 10px;
        }
        
        /* Ajustar badges */
        .badge {
            font-size: 10px;
            padding: 2px 6px;
        }
        
        /* Modal de gráfico en móviles pequeños - pantalla completa */
        .modal-dialog {
            margin: 0;
            max-width: 100%;
            height: 100vh;
        }
        
        .modal-content {
            height: 100vh;
            border-radius: 0;
        }
        
        .modal-body {
            padding: 10px;
            overflow-y: auto;
            height: calc(100vh - 120px);
        }
        
        /* Forzar que los gráficos en modales se ajusten */
        #grafico-canal {
            width: 100% !important;
            height: calc(100vh - 250px) !important;
            min-height: 400px !important;
        }
    }
    
    /* Cuando el servidor detecta móvil: mismos gráficos que desktop, sin arrastre */
    .dashboard--mobile .widget-header,
    .dashboard--mobile .widget-title,
    .dashboard--mobile .grid-stack-item-content {
        cursor: default;
    }
    .dashboard--mobile .dashboard-container {
        overflow-x: hidden;
        max-width: 100vw;
    }
    
    /* ✅ Layout móvil: evitar que se corte nada - misma especificidad que GridStack */
    .dashboard--mobile .dashboard-container,
    .dashboard-container.dashboard--mobile {
        padding: 12px !important;
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        overflow-x: hidden !important;
        box-sizing: border-box !important;
    }
    .dashboard--mobile #widget-grid,
    .dashboard--mobile .widget-grid.grid-stack {
        display: block !important;
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        overflow-x: hidden !important;
        position: relative !important;
        padding: 0 !important;
        margin: 0 !important;
    }
    .dashboard--mobile .grid-stack-item {
        position: relative !important;
        left: auto !important;
        top: auto !important;
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        margin-bottom: 16px !important;
        display: block !important;
        visibility: visible !important;
        opacity: 1 !important;
        transform: none !important;
        float: none !important;
        clear: both !important;
        box-sizing: border-box !important;
    }
    .dashboard--mobile .grid-stack-item-content {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        height: auto !important;
        min-height: 260px !important;
        box-sizing: border-box !important;
        overflow: hidden !important;
    }
    .dashboard--mobile .chart-container,
    .dashboard--mobile .widget-content {
        max-width: 100% !important;
        min-width: 0 !important;
        overflow: hidden !important;
        box-sizing: border-box !important;
    }
    .dashboard--mobile .chart-container .js-plotly-plot,
    .dashboard--mobile .chart-container .plotly,
    .dashboard--mobile .chart-container canvas,
    .dashboard--mobile .widget-chart {
        max-width: 100% !important;
        width: 100% !important;
        min-width: 0 !important;
    }
    
    /* ✅ Responsive Design para Móviles - widgets visibles y sin scroll horizontal */
    @media (max-width: 768px) {
        body, html {
            overflow-x: hidden !important;
            max-width: 100vw;
        }
        
        .dashboard-container {
            padding: 10px;
            overflow-x: hidden !important;
            max-width: 100% !important;
            width: 100% !important;
            box-sizing: border-box;
        }
        
        .dashboard-header {
            padding: 15px;
            max-width: 100%;
        }
        
        .dashboard-title {
            font-size: 20px;
            word-break: break-word;
        }
        
        .dashboard-actions {
            display: flex;
            flex-wrap: wrap;
            gap: 8px;
        }
        
        .dashboard-actions .btn {
            flex: 1 1 auto;
            min-width: 0;
            max-width: 100%;
            font-size: 13px;
            padding: 10px 12px;
        }
        
        .widget-controls {
            flex-wrap: wrap;
            gap: 5px;
        }
        
        .widget-control-btn {
            width: 36px;
            height: 36px;
            font-size: 14px;
            padding: 0;
        }
        
        .widget-title {
            font-size: 16px;
            word-break: break-word;
        }
        
        .grid-stack-item-content {
            padding: 12px;
            min-height: 250px;
            max-width: 100% !important;
            overflow: hidden;
            box-sizing: border-box;
        }
        
        .chart-container {
            min-height: 280px;
            max-width: 100% !important;
            overflow: hidden;
        }
        
        /* Contenedor del termómetro (mismo estilo en preview y dashboard) */
        .widget-thermometer-wrap {
            box-sizing: border-box;
        }
        
        /* Gráficos Plotly/Chart.js responsivos en móvil */
        .chart-container .js-plotly-plot,
        .chart-container .plotly,
        .chart-container canvas {
            max-width: 100% !important;
            width: 100% !important;
        }
        
        /* Ocultar algunos botones en móvil */
        .dashboard-actions .btn-secondary:not(.mobile-visible) {
            display: none;
        }
        
        /* Botón QR siempre visible en móvil */
        .btn-qr-mobile {
            display: inline-flex !important;
        }
        
        .mobile-visible {
            display: none !important;
        }
        
        /* ✅ Forzar layout vertical en móvil - todos los widgets visibles, sin overflow */
        .grid-stack {
            display: block !important;
            position: relative !important;
            height: auto !important;
            width: 100% !important;
            max-width: 100% !important;
            min-width: 0 !important;
            overflow-x: hidden !important;
            box-sizing: border-box !important;
        }
        
        .grid-stack-item {
            position: relative !important;
            width: 100% !important;
            max-width: 100% !important;
            min-width: 0 !important;
            left: 0 !important;
            top: auto !important;
            margin-bottom: 15px !important;
            float: none !important;
            display: block !important;
            visibility: visible !important;
            opacity: 1 !important;
            transform: none !important;
            box-sizing: border-box !important;
        }
        
        .grid-stack-item-content {
            width: 100% !important;
            max-width: 100% !important;
            min-width: 0 !important;
            height: auto !important;
            min-height: 280px;
            max-height: none !important;
            box-sizing: border-box !important;
            overflow: hidden !important;
        }
        
        .widget-grid {
            display: flex !important;
            flex-direction: column !important;
            overflow-x: hidden !important;
            max-width: 100% !important;
            width: 100% !important;
            min-width: 0 !important;
            padding: 0 !important;
        }
        
        .chart-container,
        .widget-content {
            max-width: 100% !important;
            min-width: 0 !important;
            overflow: hidden !important;
            box-sizing: border-box !important;
        }
        
        .chart-container .js-plotly-plot,
        .chart-container .plotly,
        .chart-container .widget-chart,
        .chart-container canvas {
            max-width: 100% !important;
            width: 100% !important;
            min-width: 0 !important;
        }
        
        .kpi-widget,
        .progress-widget,
        .table-widget {
            max-width: 100% !important;
            overflow-x: auto !important;
        }
        
        /* Indicador KPI: tarjeta centrada con borde de color, icono + valor + unidad */
        .kpi-widget {
            position: relative !important;
            min-height: 120px;
        }
        .kpi-indicator-shell {
            box-sizing: border-box;
        }
        .kpi-indicator-card {
            box-sizing: border-box;
        }
        .kpi-indicator-value {
            font-variant-numeric: tabular-nums;
        }
    }
    
    @media (min-width: 769px) {
        .btn-qr-mobile {
            display: none !important;
        }
        
        .mobile-visible {
            display: inline-flex !important;
        }
    }
    
    /* Modal QR */
    /* ✅ Modal QR Mejorado - Diseño Premium */
    .modal-qr {
        display: none !important;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: linear-gradient(135deg, rgba(67, 97, 238, 0.95) 0%, rgba(76, 201, 240, 0.95) 100%);
        backdrop-filter: blur(10px);
        z-index: 10000;
        align-items: center;
        justify-content: center;
        padding: 20px;
        overflow-y: auto;
        animation: fadeIn 0.3s ease;
    }
    
    @keyframes fadeIn {
        from { opacity: 0; }
        to { opacity: 1; }
    }
    
    .modal-qr.active {
        display: flex !important;
    }
    
    .modal-qr-content {
        background: white;
        border-radius: 20px;
        padding: 0;
        max-width: 600px;
        width: 100%;
        max-height: 90vh;
        overflow-y: auto;
        box-shadow: 0 20px 60px rgba(0,0,0,0.4);
        animation: slideUp 0.4s ease;
        position: relative;
    }
    
    @keyframes slideUp {
        from {
            transform: translateY(30px);
            opacity: 0;
        }
        to {
            transform: translateY(0);
            opacity: 1;
        }
    }
    
    .modal-qr-content::before {
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        height: 5px;
        background: linear-gradient(90deg, #4361ee 0%, #4cc9f0 100%);
        border-radius: 20px 20px 0 0;
    }
    
    .modal-qr-header {
        text-align: center;
        padding: 30px 30px 20px;
        background: linear-gradient(135deg, #f8f9ff 0%, #ffffff 100%);
        border-radius: 20px 20px 0 0;
    }
    
    .modal-qr-header h3 {
        margin: 0 0 10px 0;
        color: #333;
        font-size: 28px;
        font-weight: 700;
        background: linear-gradient(135deg, #4361ee 0%, #4cc9f0 100%);
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
        background-clip: text;
    }
    
    .modal-qr-header p {
        color: #666;
        font-size: 15px;
        margin: 0;
    }
    
    .qr-code-container {
        text-align: center;
        padding: 30px;
        background: linear-gradient(135deg, #f8f9ff 0%, #ffffff 100%);
        margin: 0 20px 20px;
        border-radius: 16px;
        border: 2px dashed #e0e7ff;
        position: relative;
    }
    
    .qr-code-container::before {
        content: '📱';
        position: absolute;
        top: -15px;
        left: 50%;
        transform: translateX(-50%);
        background: white;
        padding: 5px 15px;
        border-radius: 20px;
        font-size: 24px;
        box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    }
    
    .qr-code-container canvas,
    .qr-code-container img {
        max-width: 100%;
        height: auto;
        border: 4px solid white;
        border-radius: 12px;
        box-shadow: 0 8px 24px rgba(0,0,0,0.15);
        background: white;
        padding: 10px;
    }
    
    .qr-features {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
        gap: 15px;
        padding: 0 20px 20px;
    }
    
    .qr-feature {
        text-align: center;
        padding: 15px;
        background: #f8f9ff;
        border-radius: 12px;
        border: 1px solid #e0e7ff;
        transition: all 0.3s ease;
    }
    
    .qr-feature:hover {
        transform: translateY(-3px);
        box-shadow: 0 4px 12px rgba(67, 97, 238, 0.2);
        border-color: #4361ee;
    }
    
    .qr-feature-icon {
        font-size: 32px;
        margin-bottom: 8px;
        display: block;
    }
    
    .qr-feature-title {
        font-size: 13px;
        font-weight: 600;
        color: #333;
        margin: 0;
    }
    
    .qr-instructions {
        background: linear-gradient(135deg, #e7f3ff 0%, #f0f9ff 100%);
        border-left: 5px solid #4361ee;
        padding: 20px;
        margin: 0 20px 20px;
        border-radius: 12px;
        position: relative;
    }
    
    .qr-instructions::before {
        content: '💡';
        position: absolute;
        top: -12px;
        left: 20px;
        background: white;
        padding: 5px 12px;
        border-radius: 20px;
        font-size: 20px;
        box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    }
    
    .qr-instructions h5 {
        margin: 10px 0 15px 0;
        color: #4361ee;
        font-size: 18px;
        font-weight: 700;
    }
    
    .qr-instructions ol {
        margin: 0;
        padding-left: 25px;
        color: #495057;
    }
    
    .qr-instructions li {
        margin-bottom: 12px;
        line-height: 1.6;
        font-size: 14px;
    }
    
    .qr-instructions li strong {
        color: #4361ee;
    }
    
    .modal-qr-actions {
        display: flex;
        gap: 12px;
        justify-content: center;
        padding: 0 20px 30px;
        flex-wrap: wrap;
    }
    
    .btn-copy-link {
        background: linear-gradient(135deg, #28a745 0%, #20c997 100%);
        color: white;
        border: none;
        padding: 12px 24px;
        border-radius: 10px;
        cursor: pointer;
        font-size: 14px;
        display: flex;
        align-items: center;
        gap: 8px;
    }
    
    .btn-copy-link:hover {
        background: #218838;
    }
    
    .btn-close-qr {
        background: linear-gradient(135deg, #6c757d 0%, #5a6268 100%);
        color: white;
        border: none;
        padding: 12px 24px;
        border-radius: 10px;
        cursor: pointer;
        font-size: 14px;
        display: flex;
        align-items: center;
        gap: 8px;
        transition: all 0.3s ease;
    }
    
    .btn-close-qr:hover {
        background: linear-gradient(135deg, #5a6268 0%, #495057 100%);
        transform: translateY(-2px);
        box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    }
    
    .btn-copy-link:hover {
        transform: translateY(-2px);
        box-shadow: 0 4px 12px rgba(40, 167, 69, 0.3);
    }
    
    .btn-close-qr:hover {
        background: #5a6268;
    }
    
    /* Estilos para pestañas */
    .qr-tabs {
        display: flex;
        gap: 8px;
        padding: 0 20px 20px;
        border-bottom: 2px solid #e0e7ff;
    }
    
    .qr-tab {
        flex: 1;
        padding: 12px 20px;
        background: #f8f9fa;
        border: none;
        border-radius: 10px 10px 0 0;
        cursor: pointer;
        font-size: 14px;
        font-weight: 600;
        color: #666;
        transition: all 0.3s ease;
        position: relative;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
    }
    
    .qr-tab:hover {
        background: #e9ecef;
        color: #4361ee;
    }
    
    .qr-tab.active {
        background: white;
        color: #4361ee;
        border-bottom: 3px solid #4361ee;
    }
    
    .qr-tab-content {
        display: none;
    }
    
    .qr-tab-content.active {
        display: block;
    }
    
    .qr-widget-selector {
        padding: 0 20px 20px;
    }
    
    .qr-widget-selector select {
        width: 100%;
        padding: 12px;
        border: 2px solid #e0e7ff;
        border-radius: 8px;
        font-size: 14px;
        background: white;
        cursor: pointer;
    }
    
    .qr-widget-selector select:focus {
        outline: none;
        border-color: #4361ee;
        box-shadow: 0 0 0 3px rgba(67, 97, 238, 0.1);
    }
    
    .qr-widget-selector label {
        display: block;
        margin-bottom: 8px;
        font-weight: 600;
        color: #333;
        font-size: 14px;
    }
