/* =====================================================================
   Dashboard de portada (v2.30.0). Prefijo hd- para no chocar con app.css.
   Reutiliza eq-card, eq-pill y tc-alert de los tableros de Consultas.
   ===================================================================== */

.hd-page {
    --hd-ink: #0f223e;
    --hd-muted: #5b6b83;
    --hd-line: #dbe4ef;
    gap: 16px;
}

/* ---------- Encabezado animado ---------- */

.hd-hero {
    position: relative;
    overflow: hidden;
    isolation: isolate;
    display: grid;
    grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
    align-items: end;
    gap: 22px 28px;
    padding: 28px 30px 58px;
    border-radius: 20px;
    color: #ffffff;
    background: radial-gradient(120% 160% at 85% 0%, #1e3a8a 0%, #0f223e 42%, #050b16 100%);
    box-shadow: 0 22px 50px -26px rgba(5, 11, 22, 0.85);
}

.hd-hero-bg {
    position: absolute;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    background-image:
        linear-gradient(rgba(148, 197, 255, 0.07) 1px, transparent 1px),
        linear-gradient(90deg, rgba(148, 197, 255, 0.07) 1px, transparent 1px);
    background-size: 34px 34px;
    animation: hd-grid 22s linear infinite;
}

.hd-orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(6px);
}

.hd-orb-a {
    width: 460px;
    height: 460px;
    right: -120px;
    top: -240px;
    background: radial-gradient(circle, rgba(245, 184, 61, 0.34), transparent 65%);
    animation: hd-drift 16s ease-in-out infinite alternate;
}

.hd-orb-b {
    width: 520px;
    height: 520px;
    left: -200px;
    bottom: -320px;
    background: radial-gradient(circle, rgba(59, 130, 246, 0.42), transparent 65%);
    animation: hd-drift 20s ease-in-out infinite alternate-reverse;
}

.hd-orb-c {
    width: 320px;
    height: 320px;
    left: 42%;
    top: -160px;
    background: radial-gradient(circle, rgba(45, 212, 191, 0.18), transparent 65%);
    animation: hd-drift 24s ease-in-out infinite alternate;
}

/* Rutas punteadas que avanzan, como flujos de carga. */
.hd-routes {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0.55;
}

.hd-routes path {
    fill: none;
    stroke-width: 1.4;
    stroke-dasharray: 3 9;
    animation: hd-dash 14s linear infinite;
}

.hd-routes path:nth-child(1) { stroke: rgba(245, 184, 61, 0.7); }
.hd-routes path:nth-child(2) { stroke: rgba(96, 165, 250, 0.7); animation-duration: 18s; }
.hd-routes path:nth-child(3) { stroke: rgba(45, 212, 191, 0.55); animation-duration: 22s; }

/* Haz de luz que barre el encabezado cada tanto. */
.hd-scan {
    position: absolute;
    inset: -20% -40%;
    background: linear-gradient(105deg, transparent 42%, rgba(147, 197, 253, 0.12) 49%, rgba(255, 255, 255, 0.08) 52%, transparent 60%);
    animation: hd-scan 9s ease-in-out infinite;
}

.hd-hero-text { display: grid; gap: 8px; min-width: 0; animation: eq-rise 520ms ease both; }

.hd-kicker {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    width: max-content;
    max-width: 100%;
    padding: 5px 12px;
    border-radius: 999px;
    background: rgba(45, 212, 191, 0.1);
    border: 1px solid rgba(45, 212, 191, 0.3);
    color: #99f6e4;
    font-size: 0.7rem;
    font-weight: 800;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.hd-kicker i {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #2dd4bf;
    animation: hd-pulse 1.8s ease-out infinite;
}

.hd-hero h1 {
    margin: 4px 0 0;
    font-size: clamp(1.7rem, 2.6vw, 2.4rem);
    font-weight: 800;
    letter-spacing: -0.02em;
    line-height: 1.1;
}

.hd-gold {
    background: linear-gradient(90deg, #f5b83d, #ffe29a 45%, #f59e0b);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.hd-hero p {
    margin: 0;
    max-width: 620px;
    color: rgba(220, 230, 246, 0.85);
    font-size: 0.92rem;
    line-height: 1.5;
}

.hd-hero-stats {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.hd-glass {
    position: relative;
    overflow: hidden;
    display: grid;
    gap: 4px;
    padding: 14px 16px;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.07);
    border: 1px solid rgba(255, 255, 255, 0.13);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    animation: eq-rise 520ms ease both;
    transition: transform 180ms ease, background 180ms ease;
}

.hd-glass:hover { transform: translateY(-2px); background: rgba(255, 255, 255, 0.11); }
.hd-glass:nth-child(2) { animation-delay: 60ms; }
.hd-glass:nth-child(3) { animation-delay: 120ms; }
.hd-glass:nth-child(4) { animation-delay: 180ms; }

.hd-glass > span {
    color: #a9b8d2;
    font-size: 0.66rem;
    font-weight: 800;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.hd-glass > strong {
    color: #f5b83d;
    font-size: 1.9rem;
    font-weight: 800;
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
}

.hd-glass > small { color: #b6c2d6; font-size: 0.74rem; }

/* El ▲▼ del periodo anterior, legible sobre fondo oscuro. */
.hd-glass .kpi-delta { border: 1px solid transparent; }
.hd-glass .kpi-delta small { opacity: 0.85; }
.hd-glass .kpi-delta.is-good { background: rgba(34, 197, 94, 0.16); border-color: rgba(74, 222, 128, 0.35); color: #86efac; }
.hd-glass .kpi-delta.is-bad { background: rgba(239, 68, 68, 0.16); border-color: rgba(248, 113, 113, 0.35); color: #fca5a5; }
.hd-glass .kpi-delta.is-flat { background: rgba(148, 163, 184, 0.16); border-color: rgba(203, 213, 225, 0.3); color: #cbd5e1; }

.hd-glass.is-alert { border-color: rgba(248, 113, 113, 0.45); background: rgba(220, 38, 38, 0.14); }
.hd-glass.is-alert > strong { color: #fca5a5; }
.hd-glass.is-ok > strong { color: #6ee7b7; }

/* ---------- Filtros flotantes ---------- */

.hd-filters {
    position: relative;
    z-index: 2;
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 12px;
    margin: -46px 18px 0;
    padding: 14px 16px;
    border-radius: 16px;
    border: 1px solid rgba(219, 228, 239, 0.9);
    background: rgba(255, 255, 255, 0.92);
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
    box-shadow: 0 18px 40px -22px rgba(15, 34, 62, 0.45);
    animation: eq-rise 560ms ease both;
}

.hd-field {
    display: grid;
    gap: 5px;
    min-width: 150px;
}

.hd-field-wide { flex: 1 1 240px; max-width: 340px; }

.hd-field > span {
    color: var(--hd-muted);
    font-size: 0.66rem;
    font-weight: 800;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.hd-field input {
    height: 38px;
    padding: 0 10px;
    border: 1px solid #cfd9e6;
    border-radius: 10px;
    background: #ffffff;
    color: var(--hd-ink);
    font: inherit;
    font-size: 0.85rem;
}

.hd-field input:focus { outline: none; border-color: #2563eb; box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15); }

.hd-seg {
    display: inline-flex;
    margin-left: auto;
    padding: 3px;
    border-radius: 11px;
    background: #eef2f8;
}

.hd-seg button {
    height: 32px;
    padding: 0 13px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--hd-muted);
    font: inherit;
    font-size: 0.8rem;
    font-weight: 700;
    cursor: pointer;
    transition: background 160ms ease, color 160ms ease;
}

.hd-seg button:hover { color: var(--hd-ink); }
.hd-seg button.is-active { background: #ffffff; color: var(--hd-ink); box-shadow: 0 2px 8px rgba(15, 34, 62, 0.14); }

.hd-refresh {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    height: 38px;
    padding: 0 16px;
    border: 0;
    border-radius: 10px;
    background: linear-gradient(135deg, #3b82f6, #1d4ed8);
    color: #ffffff;
    font: inherit;
    font-size: 0.82rem;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 10px 22px -10px rgba(37, 99, 235, 0.8);
    transition: transform 150ms ease;
}

.hd-refresh:hover { transform: translateY(-1px); }
.hd-refresh:disabled { opacity: 0.6; cursor: wait; transform: none; }
.hd-refresh svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.hd-refresh:disabled svg { animation: hd-spin 900ms linear infinite; }

/* ---------- Grilla de tarjetas ---------- */

.hd-grid {
    position: relative;
    display: grid;
    grid-template-columns: repeat(12, minmax(0, 1fr));
    gap: 16px;
    align-items: stretch;
}

.hd-span-4 { grid-column: span 4; }
.hd-span-5 { grid-column: span 5; }
.hd-span-7 { grid-column: span 7; }
.hd-span-8 { grid-column: span 8; }
.hd-span-12 { grid-column: span 12; }

.hd-grid > .eq-card { border-radius: 16px; padding: 18px 20px; transition: box-shadow 200ms ease; }
.hd-grid > .eq-card:hover { box-shadow: 0 16px 36px -24px rgba(15, 34, 62, 0.5); }
.hd-grid > .eq-card:nth-of-type(2) { animation-delay: 60ms; }
.hd-grid > .eq-card:nth-of-type(3) { animation-delay: 120ms; }
.hd-grid > .eq-card:nth-of-type(4) { animation-delay: 180ms; }
.hd-grid > .eq-card:nth-of-type(5) { animation-delay: 240ms; }
.hd-grid > .eq-card:nth-of-type(6) { animation-delay: 300ms; }
.hd-grid > .eq-card:nth-of-type(7) { animation-delay: 360ms; }
.hd-grid > .eq-card:nth-of-type(8) { animation-delay: 420ms; }
.hd-grid > .eq-card:nth-of-type(9) { animation-delay: 480ms; }

.hd-grid .eq-card h2 { display: inline-flex; align-items: center; gap: 10px; font-size: 1rem; }

.hd-ico {
    --c: #2563eb;
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    border-radius: 10px;
    background: color-mix(in srgb, var(--c) 13%, transparent);
}

.hd-ico svg { width: 17px; height: 17px; fill: none; stroke: var(--c); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.hd-page .tone-blue { --c: #2563eb; }
.hd-page .tone-green { --c: #16a34a; }
.hd-page .tone-amber { --c: #d97706; }
.hd-page .tone-red { --c: #dc2626; }
.hd-page .tone-violet { --c: #7c3aed; }
.hd-page .tone-teal { --c: #0d9488; }
.hd-page .tone-slate { --c: #475569; }

.hd-caption { margin: 0; color: var(--hd-muted); font-size: 0.78rem; line-height: 1.5; text-align: center; }
.hd-caption b { color: var(--hd-ink); }
.hd-cycle + .hd-caption { text-align: left; }

/* ---------- Barras ---------- */

.hd-bar {
    height: 6px;
    border-radius: 999px;
    background: #eef2f8;
    overflow: hidden;
}

.hd-bar > i {
    display: block;
    height: 100%;
    border-radius: 999px;
    background: linear-gradient(90deg, color-mix(in srgb, var(--c, #2563eb) 70%, #ffffff), var(--c, #2563eb));
    transform-origin: left;
    animation: hd-fill 1.1s cubic-bezier(.2, .7, .2, 1) both;
    transition: width 700ms cubic-bezier(.2, .8, .2, 1);
}

.hd-bar-thin { height: 4px; margin-top: 5px; --c: #f59e0b; }

/* ---------- Entradas ---------- */

.hd-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
}

.hd-stat {
    position: relative;
    display: grid;
    gap: 6px;
    padding: 14px 16px;
    border-radius: 14px;
    border: 1px solid #e6edf6;
    background: linear-gradient(165deg, color-mix(in srgb, var(--c) 8%, #ffffff), #ffffff 60%);
    transition: transform 180ms ease, box-shadow 180ms ease;
}

.hd-stat:hover { transform: translateY(-3px); box-shadow: 0 14px 28px -20px var(--c); }

.hd-stat::before {
    content: "";
    position: absolute;
    inset: 12px auto 12px 0;
    width: 3px;
    border-radius: 0 3px 3px 0;
    background: var(--c);
}

.hd-stat-label { color: var(--hd-muted); font-size: 0.66rem; font-weight: 800; letter-spacing: 0.1em; text-transform: uppercase; }
.hd-stat-value { color: var(--hd-ink); font-size: 1.9rem; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.hd-stat small { color: #64748b; font-size: 0.72rem; }

/* Barra apilada con el peso de cada estado. */
.hd-stack {
    display: flex;
    gap: 3px;
    height: 14px;
    padding: 3px;
    border-radius: 999px;
    background: #eef2f8;
    overflow: hidden;
}

.hd-stack > i {
    flex-basis: 0;
    min-width: 6px;
    border-radius: 999px;
    background: var(--c);
    transform-origin: left;
    animation: hd-fill 1.2s cubic-bezier(.2, .7, .2, 1) both;
}

.hd-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; color: var(--hd-muted); font-size: 0.74rem; font-weight: 600; }
.hd-legend span { display: inline-flex; align-items: center; gap: 6px; }
.hd-legend i { width: 9px; height: 9px; border-radius: 3px; background: var(--c); }

/* ---------- Flujo de salida ---------- */

.hd-pipeline {
    display: flex;
    align-items: stretch;
    gap: 0;
    min-height: 200px;
}

.hd-stage {
    position: relative;
    flex: 1 1 0;
    min-width: 0;
    display: grid;
    justify-items: center;
    align-content: center;
    gap: 3px;
    padding: 14px 8px;
    border-radius: 14px;
    text-align: center;
    background: linear-gradient(180deg, color-mix(in srgb, var(--c) 9%, #ffffff), #ffffff 75%);
    border: 1px solid color-mix(in srgb, var(--c) 22%, #e6edf6);
    transition: transform 180ms ease, box-shadow 180ms ease;
}

.hd-stage:hover { transform: translateY(-3px); box-shadow: 0 16px 30px -22px var(--c); }

.hd-ring { width: 54px; height: 54px; transform: rotate(-90deg); margin-bottom: 4px; }
.hd-ring circle { fill: none; stroke-width: 4.5; }
.hd-ring-track { stroke: color-mix(in srgb, var(--c) 14%, #eef2f8); }
.hd-ring-fill {
    stroke: var(--c);
    stroke-linecap: round;
    animation: hd-ring 1.3s cubic-bezier(.2, .7, .2, 1) both;
    transition: stroke-dasharray 700ms ease;
}

.hd-stage strong { color: var(--hd-ink); font-size: 1.7rem; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.hd-stage-name { color: var(--c); font-size: 0.68rem; font-weight: 800; letter-spacing: 0.1em; text-transform: uppercase; }
.hd-stage small { color: #64748b; font-size: 0.7rem; line-height: 1.3; min-height: 2.6em; }
.hd-stage b { color: var(--hd-ink); font-size: 0.74rem; padding: 2px 8px; border-radius: 999px; background: color-mix(in srgb, var(--c) 12%, #ffffff); }

/* Conector animado entre etapas: guiones que avanzan. */
.hd-flow {
    flex: 0 0 22px;
    align-self: center;
    height: 2px;
    background-image: repeating-linear-gradient(90deg, #94a3b8 0 6px, transparent 6px 11px);
    background-size: 22px 2px;
    animation: hd-flow 1.1s linear infinite;
}

/* ---------- Ciclo ---------- */

.hd-cycle {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
    align-items: stretch;
}

.hd-lead {
    display: grid;
    align-content: center;
    gap: 6px;
    padding: 16px;
    border-radius: 14px;
    background: linear-gradient(160deg, color-mix(in srgb, var(--c) 92%, #000000), var(--c));
    color: #ffffff;
    box-shadow: 0 16px 30px -20px var(--c);
}

.hd-lead-label { font-size: 0.66rem; font-weight: 800; letter-spacing: 0.1em; text-transform: uppercase; opacity: 0.85; }
.hd-lead strong { font-size: 2.1rem; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.hd-lead em { font-style: normal; font-size: 1rem; opacity: 0.8; }
.hd-lead small { font-size: 0.74rem; opacity: 0.85; }

.hd-gauge { display: grid; align-content: center; gap: 0; text-align: center; min-width: 0; }
.hd-gauge small { color: #64748b; font-size: 0.72rem; margin-top: -10px; }

/* ---------- Alertas ---------- */

.hd-alerts { max-height: none; }
.tc-alert.is-ok { --c: #16a34a; opacity: 0.78; }
.tc-alert.is-ok:hover { opacity: 1; }

/* ---------- Capacidad ---------- */

.hd-capacity { display: grid; gap: 14px; max-height: 270px; overflow-y: auto; padding-right: 4px; }
.hd-cap { display: grid; gap: 6px; }
.hd-cap-head { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.hd-cap-head strong { color: var(--hd-ink); font-size: 0.84rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hd-cap-head b { color: var(--c); font-size: 0.9rem; font-variant-numeric: tabular-nums; }
.hd-cap .hd-bar { height: 9px; }
.hd-cap small { color: #64748b; font-size: 0.72rem; }

/* ---------- Top materiales ---------- */

.hd-table-wrap { overflow-x: auto; }

.hd-table { width: 100%; border-collapse: collapse; font-size: 0.84rem; }

.hd-table thead th {
    padding: 10px 12px;
    background: #f5f8fc;
    color: var(--hd-muted);
    font-size: 0.68rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-align: left;
    text-transform: uppercase;
    white-space: nowrap;
}

.hd-table thead th:first-child { border-radius: 10px 0 0 10px; }
.hd-table thead th:last-child { border-radius: 0 10px 10px 0; }
.hd-table tbody td { padding: 10px 12px; border-top: 1px solid #eef2f8; vertical-align: middle; }
.hd-table tbody tr { transition: background 150ms ease; }
.hd-table tbody tr:hover { background: #f6f9fd; }
.hd-table td.numeric { text-align: right; font-variant-numeric: tabular-nums; min-width: 110px; }
.hd-table td strong { color: var(--hd-ink); }
.hd-table .material-name { display: block; color: #64748b; font-size: 0.74rem; }
.hd-rank-col { width: 44px; }

.hd-rank {
    display: inline-grid;
    place-items: center;
    width: 28px;
    height: 28px;
    border-radius: 9px;
    background: #eef2f8;
    color: var(--hd-muted);
    font-weight: 800;
    font-size: 0.78rem;
}

.hd-rank.is-top { background: linear-gradient(135deg, #f5b83d, #f59e0b); color: #1a1204; box-shadow: 0 6px 14px -6px rgba(245, 158, 11, 0.8); }

.hd-pct { display: inline-block; padding: 3px 10px; border-radius: 999px; font-weight: 800; font-size: 0.76rem; color: var(--c); background: color-mix(in srgb, var(--c) 12%, #ffffff); }

/* ---------- Animaciones ---------- */

@keyframes hd-grid { to { background-position: 68px 34px, 68px 34px; } }
@keyframes hd-drift { from { transform: translate(0, 0) scale(1); } to { transform: translate(-60px, 40px) scale(1.12); } }
@keyframes hd-dash { to { stroke-dashoffset: -240; } }
@keyframes hd-scan { 0% { transform: translateX(-30%); opacity: 0; } 45%, 55% { opacity: 1; } 100% { transform: translateX(30%); opacity: 0; } }
@keyframes hd-pulse { 0% { box-shadow: 0 0 0 0 rgba(45, 212, 191, 0.6); } 100% { box-shadow: 0 0 0 10px rgba(45, 212, 191, 0); } }
@keyframes hd-fill { from { transform: scaleX(0); } to { transform: scaleX(1); } }
@keyframes hd-ring { from { stroke-dasharray: 0 100; } }
@keyframes hd-flow { to { background-position: 22px 0; } }
@keyframes hd-spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
    .hd-hero-bg, .hd-orb, .hd-routes path, .hd-scan, .hd-kicker i, .hd-flow,
    .hd-bar > i, .hd-stack > i, .hd-ring-fill, .hd-glass, .hd-filters, .hd-hero-text {
        animation: none !important;
    }
}

/* ---------- Pantallas medianas y chicas ---------- */

@media (max-width: 1280px) {
    .hd-span-4, .hd-span-5 { grid-column: span 6; }
    .hd-span-7, .hd-span-8 { grid-column: span 12; }
}

@media (max-width: 980px) {
    .hd-hero { grid-template-columns: 1fr; padding: 22px 18px 58px; }
    .hd-span-4, .hd-span-5, .hd-span-7, .hd-span-8 { grid-column: span 12; }
    .hd-cycle { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .hd-seg { margin-left: 0; }
}

@media (max-width: 640px) {
    .hd-filters { margin: -46px 8px 0; }
    .hd-field, .hd-field-wide { flex: 1 1 100%; max-width: none; }
    .hd-pipeline { flex-direction: column; gap: 8px; }
    .hd-flow { flex-basis: 14px; width: 2px; height: 14px; background-image: repeating-linear-gradient(180deg, #94a3b8 0 5px, transparent 5px 9px); background-size: 2px 14px; }
    .hd-cycle { grid-template-columns: 1fr; }
}
