/* ============================================================
   invdkpis - Estilos del módulo de KPIs
   Compatible con Dolibarr v20+ (Bootstrap 5 base)
   ============================================================ */

/* --- Navegación de dashboards (tabs) --- */
.kpis-dashboard-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 16px;
    border-bottom: 2px solid #dee2e6;
    padding-bottom: 8px;
}

.kpis-tab {
    padding: 6px 16px;
    border-radius: 6px 6px 0 0;
    text-decoration: none;
    color: #495057;
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-bottom: none;
    font-size: 13px;
    transition: background 0.15s;
}

.kpis-tab:hover {
    background: #e9ecef;
    color: #212529;
    text-decoration: none;
}

.kpis-tab-active {
    background: #0d6efd;
    color: #fff !important;
    border-color: #0d6efd;
    font-weight: 600;
}

.kpis-tab-admin {
    margin-left: auto;
    background: #ffc107;
    color: #212529 !important;
    border-color: #ffc107;
}

/* --- Filtros globales --- */
.kpis-global-filters {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    padding: 10px 16px;
    margin-bottom: 20px;
    font-size: 13px;
}

.kpis-filter-label {
    font-weight: 600;
    color: #495057;
}

.kpis-filter-btn {
    padding: 4px 16px !important;
    font-size: 12px !important;
}

/* --- Grid de widgets (flexbox propio, no depende de Bootstrap) --- */
.kpis-grid {
    display: flex;
    flex-wrap: wrap;
    margin: 0 -8px;
}

.kpis-widget-col {
    padding: 8px;
    box-sizing: border-box;
}

/* Columnas tipo Bootstrap (1-12) para el grid de widgets */
.kpis-widget-col.col-md-1  { flex: 0 0 8.3333%;  max-width: 8.3333%;  }
.kpis-widget-col.col-md-2  { flex: 0 0 16.6667%; max-width: 16.6667%; }
.kpis-widget-col.col-md-3  { flex: 0 0 25%;      max-width: 25%;      }
.kpis-widget-col.col-md-4  { flex: 0 0 33.3333%; max-width: 33.3333%; }
.kpis-widget-col.col-md-5  { flex: 0 0 41.6667%; max-width: 41.6667%; }
.kpis-widget-col.col-md-6  { flex: 0 0 50%;      max-width: 50%;      }
.kpis-widget-col.col-md-7  { flex: 0 0 58.3333%; max-width: 58.3333%; }
.kpis-widget-col.col-md-8  { flex: 0 0 66.6667%; max-width: 66.6667%; }
.kpis-widget-col.col-md-9  { flex: 0 0 75%;      max-width: 75%;      }
.kpis-widget-col.col-md-10 { flex: 0 0 83.3333%; max-width: 83.3333%; }
.kpis-widget-col.col-md-11 { flex: 0 0 91.6667%; max-width: 91.6667%; }
.kpis-widget-col.col-md-12 { flex: 0 0 100%;     max-width: 100%;     }

/* --- Tarjeta de widget --- */
.kpis-widget-card {
    background: #fff;
    border: 1px solid #dee2e6;
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    overflow: hidden;
    height: 100%;
}

/* --- Encabezado del widget --- */
.kpis-widget-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: #f8f9fa;
    border-bottom: 1px solid #eee;
}

.kpis-widget-title {
    font-weight: 600;
    font-size: 13px;
    color: #343a40;
}

.kpis-widget-title i {
    margin-right: 6px;
    opacity: 0.7;
}

.kpis-widget-info {
    color: #6c757d;
    font-size: 13px;
    margin-left: 6px;
    cursor: help;
}

.kpis-widget-info:hover {
    color: #0d6efd;
}

.kpis-widget-actions {
    display: flex;
    gap: 6px;
}

.kpis-export-btn {
    font-size: 10px;
    padding: 2px 8px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    background: #fff;
    color: #495057;
    text-decoration: none;
    cursor: pointer;
    transition: background 0.15s;
}

.kpis-export-btn:hover {
    background: #e9ecef;
    text-decoration: none;
}

/* --- Cuerpo del widget --- */
.kpis-widget-body {
    padding: 14px;
}

/* --- KPI Card (valor único) --- */
.kpis-card {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px;
    border-radius: 8px;
    background: #fff;
}

.kpis-card-icon {
    font-size: 36px;
    opacity: 0.8;
    min-width: 48px;
    text-align: center;
}

.kpis-card-body {
    flex: 1;
}

.kpis-card-value {
    font-size: 28px;
    font-weight: 700;
    color: #212529;
    line-height: 1;
}

.kpis-card-unit {
    font-size: 14px;
    font-weight: 400;
    color: #6c757d;
}

.kpis-card-label {
    font-size: 12px;
    color: #6c757d;
    margin-top: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* --- Tabla de datos --- */
.kpis-table-wrapper {
    overflow-x: auto;
    max-height: 400px;
    overflow-y: auto;
}

.kpis-table {
    font-size: 12px;
    width: 100%;
}

.kpis-table thead th {
    background: #343a40;
    color: #fff;
    position: sticky;
    top: 0;
    z-index: 1;
    padding: 6px 10px;
    font-weight: 600;
    white-space: nowrap;
}

.kpis-table tbody td {
    padding: 4px 10px;
    border-bottom: 1px solid #f0f0f0;
    white-space: nowrap;
}

.kpis-table tbody tr:hover {
    background: #f0f4ff;
}

/* --- Mensajes --- */
.kpis-no-data {
    text-align: center;
    color: #6c757d;
    padding: 30px;
    font-style: italic;
    font-size: 13px;
}

.kpis-empty {
    text-align: center;
    color: #6c757d;
    padding: 60px 20px;
    font-size: 15px;
}

.kpis-error {
    background: #fff3f3;
    border: 1px solid #f5c6cb;
    border-radius: 6px;
    padding: 10px 14px;
    color: #721c24;
    font-size: 12px;
    font-family: monospace;
}

/* --- Filtros por widget --- */
.kpis-widget-filters {
    background: #fffbf0;
    border-bottom: 1px solid #ffeeba;
    padding: 8px 14px;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    font-size: 12px;
}

.kpis-filter-btn-sm {
    font-size: 11px !important;
    padding: 2px 10px !important;
}

/* --- Responsive --- */
/* ============================================================
   Métricas KPI — Estilos del sistema de indicadores
   ============================================================ */

/* --- Cabecera de Área --- */
.kpis-area-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    border-radius: 8px;
    margin: 24px 0 8px 0;
    color: #fff;
    font-size: 16px;
    font-weight: 700;
}

.kpis-area-header .fa {
    font-size: 20px;
    opacity: 0.9;
}

/* --- Cabecera de Categoría --- */
.kpis-category-header {
    font-size: 14px;
    font-weight: 600;
    color: #495057;
    padding: 6px 16px 4px 28px;
    margin-top: 10px;
    border-bottom: 1px solid #dee2e6;
}

/* --- Tarjeta de Métrica --- */
.kpis-metric-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px 10px 40px;
    border-bottom: 1px solid #f0f0f0;
    cursor: pointer;
    transition: background 0.12s;
}

.kpis-metric-card:hover {
    background: #f0f4ff;
}

.kpis-metric-card-label {
    flex: 1;
    font-size: 13px;
    font-weight: 500;
    color: #343a40;
}

.kpis-metric-card-value {
    font-size: 18px;
    font-weight: 700;
    min-width: 80px;
    text-align: right;
}

.kpis-metric-card-unit {
    font-size: 11px;
    color: #6c757d;
    margin-left: 3px;
    font-weight: 400;
}

.kpis-metric-card-date {
    font-size: 11px;
    color: #adb5bd;
    min-width: 90px;
    text-align: right;
}

.kpis-metric-card-sparkline {
    width: 80px;
    height: 28px;
}

/* --- Status Dot (semáforo pequeño) --- */
.kpis-status-dot {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
}

.kpis-status-dot-green  { background: #28a745; }
.kpis-status-dot-yellow { background: #ffc107; }
.kpis-status-dot-red    { background: #dc3545; }
.kpis-status-dot-gray   { background: #adb5bd; }

/* --- Status Badge (etiqueta con texto) --- */
.kpis-status-badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.kpis-status-badge-green  { background: #d4edda; color: #155724; }
.kpis-status-badge-yellow { background: #fff3cd; color: #856404; }
.kpis-status-badge-red    { background: #f8d7da; color: #721c24; }
.kpis-status-badge-gray   { background: #e9ecef; color: #495057; }

/* --- Colores de valor según estado --- */
.kpis-value-green  { color: #28a745; }
.kpis-value-yellow { color: #d39e00; }
.kpis-value-red    { color: #dc3545; }
.kpis-value-gray   { color: #6c757d; }

/* --- Panel de detalle (expandible) --- */
.kpis-metric-detail {
    display: none;
    padding: 12px 16px 12px 52px;
    background: #f8f9fa;
    border-bottom: 1px solid #dee2e6;
}

.kpis-metric-detail.open {
    display: block;
}

.kpis-metric-detail table {
    width: 100%;
    font-size: 12px;
    border-collapse: collapse;
}

.kpis-metric-detail table th {
    background: #e9ecef;
    padding: 4px 8px;
    text-align: left;
    font-weight: 600;
}

.kpis-metric-detail table td {
    padding: 4px 8px;
    border-bottom: 1px solid #eee;
}

.kpis-metric-detail-chart {
    margin-top: 10px;
    height: 120px;
}

/* --- Barra de preview de umbrales (admin) --- */
.kpis-threshold-preview {
    display: flex;
    height: 24px;
    border-radius: 6px;
    overflow: hidden;
    margin-top: 8px;
    border: 1px solid #dee2e6;
    font-size: 10px;
    font-weight: 600;
    color: #fff;
    text-align: center;
    line-height: 24px;
}

.kpis-threshold-preview-red {
    background: #dc3545;
    flex: 1;
}

.kpis-threshold-preview-yellow {
    background: #ffc107;
    color: #212529;
    flex: 1;
}

.kpis-threshold-preview-green {
    background: #28a745;
    flex: 1;
}

/* --- Contenedor de métricas vacío --- */
.kpis-metrics-empty {
    text-align: center;
    color: #6c757d;
    padding: 60px 20px;
    font-size: 15px;
}

.kpis-metrics-empty .fa {
    font-size: 48px;
    color: #dee2e6;
    display: block;
    margin-bottom: 16px;
}

/* --- Admin: panel de variables SQL --- */
.kpis-sql-vars-panel {
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    padding: 8px 12px;
    margin-top: 6px;
    font-size: 11px;
    color: #495057;
}

.kpis-sql-vars-panel code {
    background: #e9ecef;
    padding: 1px 4px;
    border-radius: 3px;
    font-size: 11px;
}

/* --- Responsive --- */
@media (max-width: 768px) {
    .kpis-card-value {
        font-size: 22px;
    }
    .kpis-widget-col,
    .kpis-widget-col[class*="col-md-"] {
        flex: 0 0 100% !important;
        max-width: 100% !important;
    }
    .kpis-metric-card {
        flex-wrap: wrap;
        padding-left: 16px;
    }
    .kpis-metric-card-sparkline {
        display: none;
    }
    .kpis-metric-detail {
        padding-left: 16px;
    }
}
