/* ============================================================
   📊 dashboard2-widgets.css — Estilos GLOBALES para widgets
   (no scoped) porque los gráficos se construyen con MarkupContent
   y el CSS scoped de Blazor no los alcanza.
   ============================================================ */

/* ── Card base ─────────────────────────────────────────────── */
.d2-card {
    background: var(--rg-bg-card);
    border: 1px solid var(--rg-border);
    border-radius: 0.75rem;
    padding: 1.1rem;
    transition: all 0.2s;
    animation: d2FadeIn 0.4s ease-out;
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 150px;
}
.d2-card:hover { box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08); transform: translateY(-2px); }
.d2-card:hover .d2-card-actions { opacity: 1; }

.d2-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 0.75rem;
    gap: 0.5rem;
}
.d2-card-title {
    font-size: 0.72rem; font-weight: 600;
    color: var(--rg-text-muted);
    text-transform: uppercase; letter-spacing: 0.04em;
    flex: 1; min-width: 0;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.d2-card-icon {
    width: 2rem; height: 2rem;
    border-radius: 0.5rem;
    display: flex; align-items: center; justify-content: center;
    font-size: 1rem; color: #fff;
    flex-shrink: 0;
}
.d2-card-empty { text-align: center; padding: 1rem; color: var(--rg-text-muted); font-size: 0.78rem; }

.color-blue   { background: linear-gradient(135deg, #3b82f6, #2563eb); }
.color-green  { background: linear-gradient(135deg, #10b981, #059669); }
.color-purple { background: linear-gradient(135deg, #8b5cf6, #7c3aed); }
.color-amber  { background: linear-gradient(135deg, #f59e0b, #d97706); }
.color-red    { background: linear-gradient(135deg, #ef4444, #dc2626); }

/* ── KPI ───────────────────────────────────────────────────── */
.d2-kpi-wrap { display: flex; flex-direction: column; gap: 0.25rem; }
.d2-kpi-value {
    font-size: 2.25rem;
    font-weight: 700;
    color: var(--rg-text-primary);
    letter-spacing: -0.03em;
    animation: d2CountUp 0.6s ease-out;
    font-variant-numeric: tabular-nums;
    line-height: 1;
}
.d2-kpi-label {
    font-size: 0.72rem;
    color: var(--rg-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* ── Progress ──────────────────────────────────────────────── */
.d2-progress-label { display: flex; justify-content: space-between; font-size: 0.82rem; font-weight: 600; color: var(--rg-text-primary); margin-bottom: 0.4rem; font-variant-numeric: tabular-nums; }
.d2-progress-bar { width: 100%; height: 10px; background: var(--rg-bg-subtle); border-radius: 999px; overflow: hidden; }
.d2-progress-fill { height: 100%; border-radius: 999px; background: linear-gradient(90deg, #4f46e5, #7c3aed); animation: d2FillBar 1.2s ease-out; transition: width 0.6s ease-out; }
.d2-progress-sub { font-size: 0.72rem; color: var(--rg-text-muted); margin-top: 0.3rem; }

/* ── Bar chart horizontal (con hover) ──────────────────────── */
.d2-bar-row {
    display: grid;
    grid-template-columns: minmax(70px, 110px) 1fr minmax(50px, auto);
    gap: 0.5rem;
    align-items: center;
    margin-bottom: 0.5rem;
    font-size: 0.78rem;
    padding: 0.25rem 0.35rem;
    border-radius: 4px;
    transition: background 0.15s;
    cursor: default;
}
.d2-bar-row:hover {
    background: rgba(79, 70, 229, 0.06);
}
.d2-bar-row:hover .d2-bar-fill {
    filter: brightness(1.15) saturate(1.2);
}
.d2-bar-label { color: var(--rg-text-secondary); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.d2-bar-track { height: 10px; background: var(--rg-bg-subtle); border-radius: 999px; overflow: hidden; position: relative; }
.d2-bar-fill {
    height: 100%;
    border-radius: 999px;
    background: linear-gradient(90deg, #3b82f6, #2563eb);
    animation: d2FillBar 1.3s ease-out;
    transition: filter 0.15s, width 0.3s ease-out;
    position: relative;
}
/* Variar colores por posición */
.d2-bar-row:nth-child(5n+1) .d2-bar-fill { background: linear-gradient(90deg, #3b82f6, #2563eb); }
.d2-bar-row:nth-child(5n+2) .d2-bar-fill { background: linear-gradient(90deg, #10b981, #059669); }
.d2-bar-row:nth-child(5n+3) .d2-bar-fill { background: linear-gradient(90deg, #8b5cf6, #7c3aed); }
.d2-bar-row:nth-child(5n+4) .d2-bar-fill { background: linear-gradient(90deg, #f59e0b, #d97706); }
.d2-bar-row:nth-child(5n+5) .d2-bar-fill { background: linear-gradient(90deg, #ef4444, #dc2626); }
.d2-bar-value { font-weight: 600; color: var(--rg-text-primary); text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ── Line chart SVG (con hover) ────────────────────────────── */
.d2-line-wrap { width: 100%; position: relative; }
.d2-line-svg { width: 100%; height: 140px; display: block; overflow: visible; }
.d2-line-path { transition: filter 0.2s; }
.d2-line-wrap:hover .d2-line-path { filter: drop-shadow(0 0 8px rgba(79, 70, 229, 0.4)); }
.d2-line-dot { transition: r 0.15s, fill 0.15s; cursor: pointer; }
.d2-line-dot:hover { r: 5; fill: #fff; stroke: #4f46e5; stroke-width: 2; }
.d2-line-dot title { display: none; }

/* Ejes */
.d2-line-axis { stroke: var(--rg-border); stroke-width: 1; }
.d2-line-axis-label { fill: var(--rg-text-muted); font-size: 10px; font-family: inherit; }

@keyframes d2DrawLine { to { stroke-dashoffset: 0; } }

/* ── Donut (con hover + leyenda clara) ─────────────────────── */
.d2-donut-wrap {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
    justify-content: center;
}
.d2-donut-svg { width: 150px; height: 150px; flex-shrink: 0; }
.d2-donut-slice {
    transition: stroke-width 0.15s, filter 0.15s;
    cursor: pointer;
}
.d2-donut-slice:hover {
    stroke-width: 22 !important;
    filter: brightness(1.15) drop-shadow(0 0 6px rgba(0,0,0,0.15));
}

.d2-donut-legend {
    flex: 1;
    min-width: 140px;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}
.d2-donut-item {
    display: grid;
    grid-template-columns: 12px 1fr auto;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.78rem;
    padding: 0.2rem 0.3rem;
    border-radius: 4px;
    transition: background 0.15s;
}
.d2-donut-item:hover { background: rgba(79, 70, 229, 0.08); }
.d2-donut-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
    display: inline-block;
}
.d2-donut-label {
    color: var(--rg-text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}
.d2-donut-value {
    font-weight: 700;
    color: var(--rg-text-primary);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}
.d2-donut-pct {
    display: block;
    font-size: 0.66rem;
    color: var(--rg-text-muted);
    font-weight: 400;
}

/* ── Gauge (velocímetro) ───────────────────────────────────── */
.d2-gauge-wrap { text-align: center; padding: 0.5rem 0; }
.d2-gauge-svg { width: 160px; height: 90px; }
.d2-gauge-value { font-size: 1.5rem; font-weight: 700; color: var(--rg-text-primary); margin-top: 0.25rem; font-variant-numeric: tabular-nums; }
.d2-gauge-sub { font-size: 0.72rem; color: var(--rg-text-muted); }

/* ── Tabla ─────────────────────────────────────────────────── */
.d2-table-wrap {
    overflow: auto;
    max-height: 320px;
    border: 1px solid var(--rg-border);
    border-radius: 6px;
}
.d2-mini-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.78rem;
}
.d2-mini-table thead th {
    text-align: left;
    padding: 0.5rem 0.7rem;
    background: var(--rg-bg-subtle);
    color: var(--rg-text-secondary);
    font-weight: 600;
    border-bottom: 1px solid var(--rg-border);
    text-transform: uppercase;
    font-size: 0.68rem;
    letter-spacing: 0.04em;
    white-space: nowrap;
    position: sticky;
    top: 0;
    z-index: 1;
}
.d2-mini-table tbody td {
    padding: 0.45rem 0.7rem;
    border-bottom: 1px solid var(--rg-border);
    color: var(--rg-text-primary);
    font-variant-numeric: tabular-nums;
}
.d2-mini-table tbody tr:hover { background: rgba(79, 70, 229, 0.05); }
.d2-mini-table tbody tr:last-child td { border-bottom: none; }

/* ── Botón "Ver detalle" + panel ───────────────────────────── */
.d2-details-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    margin-top: 0.75rem;
    padding: 0.3rem 0.65rem;
    background: transparent;
    border: 1px solid var(--rg-border);
    border-radius: 4px;
    color: var(--rg-text-secondary);
    font-size: 0.7rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
}
.d2-details-toggle:hover {
    background: var(--rg-bg-hover);
    color: var(--rg-accent, #4f46e5);
    border-color: var(--rg-accent, #4f46e5);
}
.d2-details-toggle i { font-size: 0.85rem; }

/* Panel de detalle amigable (reemplaza la vista técnica) */
.d2-details-container {
    margin-top: 0.5rem;
    animation: d2FadeIn 0.2s ease-out;
}

.d2-details-panel-friendly {
    background: var(--rg-bg-subtle);
    border: 1px solid var(--rg-border);
    border-radius: 6px;
    max-height: 280px;
    overflow: auto;
}

.d2-details-panel-friendly table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.78rem;
}

.d2-details-panel-friendly thead th {
    text-align: left;
    padding: 0.5rem 0.75rem;
    color: var(--rg-text-secondary);
    font-weight: 600;
    background: var(--rg-bg-card);
    border-bottom: 1px solid var(--rg-border);
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    position: sticky;
    top: 0;
    z-index: 1;
}

.d2-details-panel-friendly tbody td {
    padding: 0.4rem 0.75rem;
    color: var(--rg-text-primary);
    border-bottom: 1px solid var(--rg-border);
    font-variant-numeric: tabular-nums;
}

.d2-details-panel-friendly tbody tr:hover {
    background: rgba(79, 70, 229, 0.06);
}

.d2-details-panel-friendly tbody tr:last-child td {
    border-bottom: none;
}

/* Fila TOTAL de bar/donut */
.d2-details-total {
    background: var(--rg-bg-card);
    border-top: 2px solid var(--rg-border);
}
.d2-details-total td {
    font-weight: 700 !important;
}

/* Badge de porcentaje inline */
.d2-details-pct {
    color: var(--rg-text-muted);
    font-size: 0.72rem;
    margin-left: 0.25rem;
    font-weight: 400;
}

/* KPI detail — cards verticales */
.d2-details-kpi {
    padding: 0.5rem 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
}
.d2-details-kpi-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.45rem 0;
    border-bottom: 1px solid var(--rg-border);
    font-size: 0.8rem;
}
.d2-details-kpi-row:last-child { border-bottom: none; }
.d2-details-kpi-row span { color: var(--rg-text-muted); }
.d2-details-kpi-row strong { color: var(--rg-text-primary); font-variant-numeric: tabular-nums; }
.d2-details-kpi-value { color: var(--rg-accent, #4f46e5) !important; font-size: 0.95rem !important; }

/* ── Animaciones ───────────────────────────────────────────── */
@keyframes d2FadeIn  { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
@keyframes d2CountUp { from { opacity: 0; transform: scale(0.9); } to { opacity: 1; transform: scale(1); } }
@keyframes d2FillBar { from { width: 0; } }

/* ============================================================
   📝 SqlEditor (CodeMirror) — estilos globales
   ============================================================ */
.sql-editor-wrap {
    border: 1px solid var(--rg-border);
    border-radius: 6px;
    overflow: hidden;
    background: var(--rg-bg-input);
    transition: border-color 0.15s;
    position: relative;
}
.sql-editor-wrap:focus-within {
    border-color: var(--rg-accent, #4f46e5);
    box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.15);
}
.sql-editor { height: 100%; min-height: 200px; }
.sql-editor .CodeMirror {
    height: 100%;
    font-family: 'Cascadia Code', 'Fira Code', 'JetBrains Mono', ui-monospace, monospace;
    font-size: 13px;
    line-height: 1.5;
}
.sql-editor-hint {
    padding: 0.35rem 0.65rem;
    font-size: 0.7rem;
    color: var(--rg-text-muted);
    background: var(--rg-bg-subtle);
    border-top: 1px solid var(--rg-border);
    display: flex;
    align-items: center;
    gap: 0.35rem;
}
.sql-editor-hint i { color: var(--rg-accent, #4f46e5); }
