/* =====================================================================
 * Análisis de Rendimiento — tab del módulo Despacho
 *
 * MP del Inventario (mass balance) vs Producción real (Σ produccion_productos)
 * desglosada por estado_producto (PT-Primera / PT-Segunda / Chatarra).
 * Muestra rendimiento %, Δ, gráficos de distribución y top productos.
 * ===================================================================== */

.dr-wrap {
    padding: 1rem 1.25rem 2rem;
    background: linear-gradient(180deg, #f8fafc 0%, #ffffff 240px);
    border-radius: 8px;
    min-height: 60vh;
}

/* ----- Banner del período ----- */
.dr-period-banner {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-left: 4px solid #6366f1;
    border-radius: 8px;
    padding: 0.6rem 0.95rem;
    margin-bottom: 1.1rem;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.04);
}

.dr-period-banner .dr-period-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #64748b;
    font-weight: 600;
}

.dr-period-banner .dr-period-value {
    font-family: 'Roboto Mono', monospace;
    font-weight: 700;
    color: #0f172a;
}

.dr-period-banner .dr-period-context {
    margin-left: auto;
    color: #64748b;
    font-size: 0.82rem;
}

/* ----- KPI Hero (4 cards) ----- */
.dr-hero {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.85rem;
    margin-bottom: 1.25rem;
}

.dr-hero-card {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 0.85rem 1rem;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.04);
    position: relative;
    overflow: hidden;
}

.dr-hero-card::before {
    content: '';
    position: absolute;
    inset: 0 0 auto 0;
    height: 3px;
    background: currentColor;
}

.dr-hero-card.is-mp     { color: #0ea5e9; }
.dr-hero-card.is-prod   { color: #6366f1; }
.dr-hero-card.is-rend   { color: #10b981; }
.dr-hero-card.is-rend.is-warn { color: #f59e0b; }
.dr-hero-card.is-rend.is-err  { color: #dc2626; }
.dr-hero-card.is-chat   { color: #f97316; }

.dr-hero-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    font-weight: 700;
    letter-spacing: 0.05em;
    color: #64748b;
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.dr-hero-val {
    font-size: 1.5rem;
    font-weight: 700;
    color: #0f172a;
    font-family: 'Roboto Mono', monospace;
    margin-top: 0.25rem;
    line-height: 1.1;
}

.dr-hero-val small {
    font-size: 0.65rem;
    color: #94a3b8;
    font-weight: 600;
    margin-left: 0.2rem;
}

.dr-hero-sub {
    font-size: 0.72rem;
    color: #64748b;
    margin-top: 0.25rem;
}

.dr-hero-card.is-rend .dr-hero-val   { color: inherit; }
.dr-hero-card.is-chat .dr-hero-val   { color: inherit; }

/* ----- Layout dos columnas (MP + Producción) ----- */
.dr-row-2col {
    display: grid;
    grid-template-columns: 1fr 1.2fr;
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.dr-card {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 1rem 1.15rem;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.04);
}

.dr-card-head {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 700;
    color: #0f172a;
    margin-bottom: 0.7rem;
    padding-bottom: 0.55rem;
    border-bottom: 1px solid #e2e8f0;
}

.dr-card-head .dr-card-head-tag {
    margin-left: auto;
    font-size: 0.68rem;
    background: #f1f5f9;
    color: #475569;
    padding: 0.1rem 0.5rem;
    border-radius: 999px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* Líneas en card MP */
.dr-line {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 0.85rem;
    padding: 0.35rem 0;
    align-items: center;
    font-size: 0.92rem;
}

.dr-line-key {
    color: #475569;
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.dr-line-key .dr-op {
    display: inline-block;
    width: 1.2rem;
    text-align: center;
    color: #94a3b8;
    font-weight: 600;
}

.dr-line-val {
    text-align: right;
    font-family: 'Roboto Mono', monospace;
    font-weight: 600;
    color: #0f172a;
}

.dr-line-val small {
    font-size: 0.7rem;
    color: #94a3b8;
    margin-left: 0.2rem;
    font-weight: 500;
}

.dr-line-total {
    margin-top: 0.4rem;
    padding-top: 0.6rem;
    border-top: 2px dashed #cbd5e1;
    font-weight: 700;
    font-size: 1rem;
}

.dr-line-total .dr-line-key,
.dr-line-total .dr-line-val { font-weight: 700; color: #0f172a; }

/* Bloque de fórmula explicativa */
.dr-formula {
    background: linear-gradient(135deg, #f1f5f9, #e2e8f0);
    border-radius: 6px;
    padding: 0.4rem 0.65rem;
    font-family: 'Roboto Mono', monospace;
    font-size: 0.78rem;
    color: #475569;
    margin-top: 0.5rem;
    border: 1px dashed #94a3b8;
}

/* ----- Barras de PT-1 / PT-2 / Chatarra ----- */
.dr-cat-row {
    display: grid;
    grid-template-columns: 130px 1fr 120px 60px;
    gap: 0.85rem;
    align-items: center;
    padding: 0.55rem 0;
}

.dr-cat-row + .dr-cat-row { border-top: 1px solid #f1f5f9; }

.dr-cat-label {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    font-weight: 600;
    color: #1e293b;
    font-size: 0.88rem;
}

.dr-cat-icon {
    width: 22px;
    height: 22px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    color: #fff;
    font-size: 0.65rem;
}

.dr-cat-row.is-pt1 .dr-cat-icon { background: #4f46e5; }
.dr-cat-row.is-pt2 .dr-cat-icon { background: #f59e0b; }
.dr-cat-row.is-chat .dr-cat-icon { background: #ef4444; }

.dr-bar-track {
    height: 16px;
    background: #f1f5f9;
    border-radius: 999px;
    overflow: hidden;
    position: relative;
}

.dr-bar-fill {
    height: 100%;
    border-radius: 999px;
    transition: width 0.4s ease;
    background: currentColor;
}

.dr-cat-row.is-pt1 .dr-bar-fill { background: linear-gradient(90deg, #4f46e5, #6366f1); }
.dr-cat-row.is-pt2 .dr-bar-fill { background: linear-gradient(90deg, #f59e0b, #fbbf24); }
.dr-cat-row.is-chat .dr-bar-fill { background: linear-gradient(90deg, #ef4444, #f87171); }

.dr-cat-val {
    text-align: right;
    font-family: 'Roboto Mono', monospace;
    font-weight: 700;
    color: #0f172a;
}

.dr-cat-val small {
    display: block;
    font-size: 0.7rem;
    color: #94a3b8;
    font-weight: 500;
    margin-top: 0.1rem;
}

.dr-cat-pct {
    text-align: right;
    font-family: 'Roboto Mono', monospace;
    font-weight: 700;
    font-size: 1rem;
    color: #475569;
}

.dr-cat-row-total {
    border-top: 2px solid #cbd5e1;
    margin-top: 0.5rem;
    padding-top: 0.65rem;
    background: #f0fdf4;
    border-radius: 6px;
    padding-left: 0.6rem;
    padding-right: 0.6rem;
}

.dr-cat-row-total .dr-cat-label { color: #15803d; }
.dr-cat-row-total .dr-bar-fill  { background: linear-gradient(90deg, #16a34a, #22c55e); }
.dr-cat-row-total .dr-cat-val,
.dr-cat-row-total .dr-cat-pct   { color: #15803d; }

/* ----- Sección Rendimiento ----- */
.dr-rend {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 1rem 1.15rem;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.04);
    margin-bottom: 1.25rem;
}

.dr-rend-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 2fr;
    gap: 1.1rem;
    align-items: center;
}

.dr-rend-stat {
    text-align: center;
}

.dr-rend-stat-label {
    font-size: 0.72rem;
    text-transform: uppercase;
    font-weight: 600;
    color: #64748b;
    letter-spacing: 0.05em;
}

.dr-rend-stat-val {
    font-size: 1.55rem;
    font-weight: 700;
    color: #0f172a;
    font-family: 'Roboto Mono', monospace;
    margin-top: 0.2rem;
    line-height: 1.1;
}

.dr-rend-stat-val small { font-size: 0.65rem; color: #94a3b8; font-weight: 500; margin-left: 0.15rem; }

.dr-rend-delta-positive { color: #16a34a; }
.dr-rend-delta-negative { color: #dc2626; }

/* Barra de rendimiento con semáforo */
.dr-rend-gauge {
    text-align: center;
}

.dr-rend-gauge-pct {
    font-size: 2.2rem;
    font-weight: 800;
    font-family: 'Roboto Mono', monospace;
    line-height: 1;
}

.dr-rend-gauge.is-ok   .dr-rend-gauge-pct { color: #16a34a; }
.dr-rend-gauge.is-warn .dr-rend-gauge-pct { color: #f59e0b; }
.dr-rend-gauge.is-err  .dr-rend-gauge-pct { color: #dc2626; }

.dr-rend-gauge-bar {
    height: 12px;
    background: #f1f5f9;
    border-radius: 999px;
    margin-top: 0.5rem;
    overflow: hidden;
    position: relative;
}

.dr-rend-gauge-bar-fill {
    height: 100%;
    border-radius: 999px;
    transition: width 0.5s ease;
}

.dr-rend-gauge.is-ok   .dr-rend-gauge-bar-fill { background: linear-gradient(90deg, #16a34a, #22c55e); }
.dr-rend-gauge.is-warn .dr-rend-gauge-bar-fill { background: linear-gradient(90deg, #f59e0b, #fbbf24); }
.dr-rend-gauge.is-err  .dr-rend-gauge-bar-fill { background: linear-gradient(90deg, #dc2626, #ef4444); }

.dr-rend-gauge-target {
    position: absolute;
    top: -2px;
    bottom: -2px;
    width: 2px;
    background: #0f172a;
    opacity: 0.4;
}

.dr-rend-gauge-msg {
    font-size: 0.8rem;
    color: #64748b;
    margin-top: 0.4rem;
}

/* ----- Top productos ----- */
.dr-top-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
}

.dr-top-table thead th {
    background: #f1f5f9;
    color: #1e293b;
    padding: 0.55rem 0.7rem;
    text-align: left;
    font-weight: 700;
    border-bottom: 2px solid #cbd5e1;
}

.dr-top-table thead th.text-end { text-align: right; }

.dr-top-table tbody td {
    padding: 0.55rem 0.7rem;
    border-bottom: 1px solid #e2e8f0;
    color: #475569;
}

.dr-top-table tbody td.text-end {
    text-align: right;
    font-family: 'Roboto Mono', monospace;
    font-weight: 600;
    color: #0f172a;
}

.dr-top-table tbody tr:hover {
    background: #f8fafc;
}

.dr-top-rank {
    width: 32px;
    text-align: center;
    font-weight: 700;
    color: #6366f1;
}

/* ----- Empty / Loading ----- */
.dr-empty {
    background: #fff;
    border: 1px dashed #cbd5e1;
    border-radius: 10px;
    padding: 3rem 1.5rem;
    text-align: center;
    color: #94a3b8;
}

.dr-empty i {
    font-size: 2.5rem;
    color: #cbd5e1;
    margin-bottom: 0.5rem;
    display: block;
}

.dr-empty h5 {
    color: #475569;
    font-weight: 600;
    margin: 0.4rem 0;
}

.dr-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    color: #64748b;
    padding: 2rem;
    font-style: italic;
}

/* ----- Responsive ----- */
@media (max-width: 1100px) {
    .dr-hero       { grid-template-columns: repeat(2, 1fr); }
    .dr-row-2col   { grid-template-columns: 1fr; }
    .dr-rend-grid  { grid-template-columns: 1fr; gap: 0.8rem; }
    .dr-cat-row    { grid-template-columns: 100px 1fr 90px 50px; }
}
