/* ==========================================================
   DASHBOARD · INFORME DE ACTIVIDAD
   Mismo lenguaje que «Sobre mí» (hoja de papel con contorno,
   filetes y titulares en Bowlby One) en clave de informe:
   indicadores en una franja, gráfica con resumen al lado,
   ranking como tabla y distribución de puntuaciones.
   ========================================================== */

.analytics-layout .dashboard-main { min-width: 0; overflow: visible; }

.rp {
    --rp-visits: #3d7fc9;
    --rp-attempts: var(--sl-violet);
    display: grid;
    gap: 20px;
    max-width: 1400px;
    margin-inline: auto;
    padding: clamp(20px, 3vw, 40px);
    border: 1px solid var(--sl-carbon);
    border-radius: var(--radius-xl);
    background: var(--sl-card);
    color: var(--sl-carbon);
    font-family: var(--sl-sans);
    font-size: .9375rem;
    line-height: 1.5;
}

html[data-sl-theme="dark"] .rp { --rp-visits: var(--sl-blue); }

.rp :where(h1, h2, h3, p, dl, dd, figure) { margin: 0; }
.rp :where(ul, ol) { margin: 0; padding: 0; list-style: none; }
.rp a { color: inherit; text-decoration: none; }
.rp :focus-visible { outline: 3px solid var(--sl-violet); outline-offset: 3px; border-radius: 6px; }
.rp-sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

/* Puntos de color de cada serie (leyenda, indicadores y reparto). */
.rp-dot { display: inline-block; flex: 0 0 10px; width: 10px; height: 10px; border: 1px solid var(--sl-carbon); border-radius: 50%; }
.rp-dot--visits { background: var(--rp-visits); }
.rp-dot--attempts { background: var(--rp-attempts); }

/* ---------- Cabecera ---------- */

.rp-folio {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 6px 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--sl-carbon);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
}

.rp-title-row {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: 20px 32px;
    padding: 18px 0 20px;
    border-bottom: 3px solid var(--sl-carbon);
}

.rp-title { display: grid; gap: 10px; }

.rp-title h1 {
    font-family: var(--sl-display);
    font-size: clamp(2.3rem, 1rem + 3.6vw, 4.6rem);
    font-weight: 400;
    line-height: .86;
    text-transform: uppercase;
}

.rp-title p { max-width: 52ch; color: var(--sl-muted); font-size: 1rem; }

.rp-period { display: grid; justify-items: end; gap: 10px; }

.rp-periods {
    display: inline-grid;
    grid-auto-flow: column;
    gap: 2px;
    padding: 3px;
    border: 1px solid var(--sl-carbon);
    border-radius: var(--radius-pill);
}

.rp-periods a {
    display: grid;
    place-items: center;
    min-height: 38px;
    padding: 0 16px;
    border-radius: var(--radius-pill);
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    transition: background-color var(--duration) var(--ease-out), color var(--duration) var(--ease-out);
}

.rp-periods a:hover { background: var(--sl-sky); }
.rp-periods a[aria-current] { background: var(--sl-carbon); color: var(--sl-paper); }
.rp-range { color: var(--sl-muted); font-size: 13px; }
.rp-range strong { color: var(--sl-carbon); }

/* ---------- Indicadores: una franja dividida por filetes ---------- */

.rp-kpis {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    border: 1px solid var(--sl-carbon);
    border-radius: 24px;
}

.rp-kpi {
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-width: 0;
    padding: 20px 22px;
    border-left: 1px solid var(--sl-carbon);
}

.rp-kpi:first-child { border-left: 0; }

.rp-kpi h2 {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--sl-muted);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: .05em;
    text-transform: uppercase;
}

.rp-kpi h2 i:not(.rp-dot) { color: var(--sl-carbon); font-size: 14px; }

.rp-kpi strong {
    font-family: var(--sl-display);
    font-size: clamp(2.2rem, 1.6rem + 1.6vw, 3.2rem);
    font-weight: 400;
    font-variant-numeric: tabular-nums;
    line-height: .9;
}

.rp-kpi strong span { margin-left: 2px; font-size: .55em; }
.rp-kpi p { margin-top: auto; color: var(--sl-muted); font-size: 13px; }

.rp-meter { display: block; height: 10px; overflow: hidden; border: 1px solid var(--sl-carbon); border-radius: var(--radius-pill); background: var(--sl-mist); }
.rp-meter i { display: block; min-width: 4px; height: 100%; background: var(--sl-mint); border-right: 1px solid var(--sl-carbon); }

/* ---------- Paneles ---------- */

.rp-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.85fr) minmax(300px, 1fr);
    gap: 20px;
    align-items: stretch;
}

.rp-panel {
    display: flex;
    flex-direction: column;
    gap: 16px;
    min-width: 0;
    padding: 22px 24px 24px;
    border: 1px solid var(--sl-carbon);
    border-radius: 24px;
}

.rp-panel-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px 20px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--sl-carbon);
}

.rp-eyebrow { margin-bottom: 6px; color: var(--sl-muted); font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }

.rp-panel-head h2 {
    font-family: var(--sl-display);
    font-size: clamp(1.25rem, 1rem + .7vw, 1.6rem);
    font-weight: 400;
    line-height: .95;
    text-transform: uppercase;
}

.rp-sub { margin-top: 6px; color: var(--sl-muted); font-size: 13px; }

.rp-legend { display: flex; flex-wrap: wrap; gap: 6px; }
.rp-legend li { display: inline-flex; align-items: center; gap: 8px; padding: 5px 12px; border: 1px solid var(--sl-carbon); border-radius: var(--radius-pill); font-size: 12px; font-weight: 700; white-space: nowrap; }

.rp-pill-link,
.rp-link,
.rp-button {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
    font-weight: 700;
    transition: background-color var(--duration) var(--ease-out), color var(--duration) var(--ease-out);
}

.rp-pill-link { flex: 0 0 auto; padding: 7px 14px; border: 1px solid var(--sl-carbon); border-radius: var(--radius-pill); font-size: 13px; }
.rp-pill-link:hover { background: var(--sl-sun); color: var(--sl-on); }
.rp-link { min-height: 44px; text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 4px; }
.rp-link:hover { color: var(--sl-violet); }
.rp .rp-button { min-height: 46px; padding: 10px 20px; border: 1px solid var(--sl-carbon); border-radius: var(--radius-pill); background: var(--sl-carbon); color: var(--sl-paper); font-size: 14px; }
.rp .rp-button:hover { background: var(--sl-sun); color: var(--sl-on); }

.rp-note { display: flex; gap: 8px; color: var(--sl-muted); font-size: 12px; line-height: 1.6; }
.rp-chart-note { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px 16px; color: var(--sl-muted); font-size: 12px; }

/* ---------- Gráfica de evolución ---------- */

.rp-chart { position: relative; height: 280px; }
.rp-chart-svg { display: block; width: 100%; height: 100%; overflow: visible; touch-action: pan-y; }
.rp-chart-svg text { fill: var(--sl-muted); font: 500 11px var(--sl-sans); font-variant-numeric: tabular-nums; }
.rp-grid-line { stroke: var(--sl-line); stroke-dasharray: 3 5; stroke-width: 1; }
.rp-area { fill: var(--rp-visits); fill-opacity: .12; }
.rp-line { fill: none; stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.rp-line--visits { stroke: var(--rp-visits); }
.rp-line--attempts { stroke: var(--rp-attempts); stroke-dasharray: 6 5; }
.rp-point { stroke: var(--sl-card); stroke-width: 1.5; }
.rp-point--visits { fill: var(--rp-visits); }
.rp-point--attempts { fill: var(--rp-attempts); }
.rp-guide { stroke: var(--sl-carbon); stroke-dasharray: 3 3; }

.rp-tooltip {
    position: absolute;
    z-index: 3;
    min-width: 170px;
    padding: 10px 14px;
    border: 1px solid var(--sl-carbon);
    border-radius: 14px;
    background: var(--sl-paper);
    font-size: 12px;
    pointer-events: none;
}

.rp-tooltip strong { display: block; margin-bottom: 4px; font-size: 13px; }
.rp-tooltip span { display: block; color: var(--sl-muted); }

.rp-details { margin-top: auto; border-top: 1px solid var(--sl-line); }

.rp-details summary,
.rp-method summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    min-height: 46px;
    font-weight: 600;
    list-style: none;
    cursor: pointer;
}

.rp-details summary span,
.rp-method summary span { display: inline-flex; align-items: center; gap: 8px; }
.rp summary::-webkit-details-marker { display: none; }
.rp summary .bi-chevron-down { transition: transform var(--duration) var(--ease-out); }
.rp details[open] > summary .bi-chevron-down { transform: rotate(180deg); }
.rp summary:hover { color: var(--sl-violet); }
.rp-table-scroll { max-height: 260px; overflow: auto; border: 1px solid var(--sl-carbon); border-radius: 16px; }

/* ---------- Tablas ---------- */

.rp-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.rp-table th,
.rp-table td { padding: 12px 10px; border-bottom: 1px solid var(--sl-line); text-align: left; vertical-align: middle; }
.rp-table thead th { border-bottom: 1px solid var(--sl-carbon); color: var(--sl-muted); font-size: 12px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; }
.rp-table tbody tr:last-child > * { border-bottom: 0; }
.rp-table--compact { font-size: 13px; }
.rp-table--compact th,
.rp-table--compact td { padding: 8px 14px; }
.rp-table--compact td,
.rp-table--compact thead th:not(:first-child) { text-align: right; }
.rp-table--compact thead { position: sticky; top: 0; background: var(--sl-sky); }

/* Ranking */
.rp-ranking thead th:nth-child(3),
.rp-ranking thead th:nth-child(4) { width: 19%; }
.rp-ranking thead th:last-child { width: 1%; white-space: nowrap; }
.rp-ranking tbody th { min-width: 180px; }
.rp-ranking thead th:last-child,
.rp-ranking .rp-score { text-align: right; }

.rp-rank {
    width: 1%;
    color: var(--sl-muted);
    font-size: 13px;
    font-weight: 800;
}

.rp-ranking tbody th { font-weight: 700; }
.rp-ranking tbody th a { display: inline-flex; align-items: baseline; gap: 6px; }
.rp-ranking tbody th a i { color: var(--sl-muted); font-size: 11px; transition: transform var(--duration) var(--ease-out); }
.rp-ranking tbody th a:hover { color: var(--sl-violet); }
.rp-ranking tbody th a:hover i { transform: translate(2px, -2px); }

.rp-cell-bar { display: flex; align-items: center; gap: 10px; }
.rp-bar { flex: 1; height: 10px; overflow: hidden; border: 1px solid var(--sl-carbon); border-radius: var(--radius-pill); background: var(--sl-mist); }
.rp-bar-fill { display: block; height: 100%; }
.rp-bar-fill--visits { background: var(--rp-visits); }
.rp-bar-fill--attempts { background: var(--rp-attempts); }
.rp-cell-bar b { min-width: 30px; font-size: 13px; text-align: right; }
.rp-score strong { display: block; font-size: 1.15rem; font-weight: 800; }
.rp-score small { display: block; color: var(--sl-muted); font-size: 12px; white-space: nowrap; }

/* ---------- Resumen ---------- */

.rp-insight { font-size: 1rem; font-weight: 500; line-height: 1.65; }
.rp-block { display: grid; gap: 12px; padding-top: 16px; border-top: 1px solid var(--sl-line); }
.rp-block h3 { font-size: 12px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--sl-muted); }
.rp-share { display: flex; height: 14px; overflow: hidden; border: 1px solid var(--sl-carbon); border-radius: var(--radius-pill); background: var(--sl-mist); }
.rp-share span:first-child { background: var(--rp-visits); }
.rp-share span:last-child { background: var(--rp-attempts); }
.rp-share span + span { border-left: 1px solid var(--sl-carbon); }
.rp-share-list > div { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; }
.rp-share-list dt { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; }
.rp-share-list dd { font-weight: 800; font-variant-numeric: tabular-nums; }
.rp-share-list dd small { margin-left: 6px; color: var(--sl-muted); font-weight: 500; }

.rp-freshness { display: flex; gap: 10px; margin-top: auto; padding-top: 16px; border-top: 1px solid var(--sl-line); color: var(--sl-muted); font-size: 13px; }
.rp-freshness strong { display: block; color: var(--sl-carbon); }

/* ---------- Distribución ---------- */

.rp-hist { display: flex; gap: 10px; padding-top: 26px; }
.rp-hist-col { flex: 1; min-width: 0; text-align: center; }
.rp-hist-space { display: flex; align-items: flex-end; height: 170px; border-bottom: 1px solid var(--sl-carbon); background: repeating-linear-gradient(to top, var(--sl-line) 0 1px, transparent 1px 34px); }
.rp-hist-bar { position: relative; width: 100%; border: 1px solid var(--sl-carbon); border-bottom: 0; border-radius: 8px 8px 0 0; background: var(--sl-mint); }
.rp-hist-bar b { position: absolute; top: -22px; right: 0; left: 0; font-size: 12px; }
.rp-hist-col > span { display: block; margin-top: 10px; color: var(--sl-muted); font-size: 11px; font-weight: 600; white-space: nowrap; }

/* ---------- Estados vacíos ---------- */

.rp-empty { display: grid; justify-items: center; align-content: center; gap: 8px; min-height: 240px; padding: 24px 12px; text-align: center; }
.rp-empty > i { display: grid; place-items: center; width: 48px; height: 48px; margin-bottom: 6px; border: 1px solid var(--sl-carbon); border-radius: 50%; background: var(--sl-sky); font-size: 20px; }
.rp-empty h3 { font-family: var(--sl-display); font-size: 1.2rem; font-weight: 400; text-transform: uppercase; }
.rp-empty p { max-width: 32ch; color: var(--sl-muted); font-size: 14px; }
.rp-empty--small { min-height: 200px; }

/* ---------- Catálogo ---------- */

.rp-catalog {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 20px 32px;
    padding: 20px 24px;
    border: 1px solid var(--sl-carbon);
    border-radius: 24px;
    background: var(--sl-sky);
}

.rp-catalog-copy { flex: 1 1 240px; }
.rp-catalog h2 { font-family: var(--sl-display); font-size: 1.35rem; font-weight: 400; text-transform: uppercase; }
.rp-catalog p { color: var(--sl-muted); font-size: 13px; }
.rp-catalog-figures { display: flex; gap: 32px; }
.rp-catalog-figures > div { display: grid; gap: 2px; padding-left: 20px; border-left: 1px solid var(--sl-carbon); }
.rp-catalog-figures dt { color: var(--sl-muted); font-size: 12px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; }
.rp-catalog-figures dd { font-family: var(--sl-display); font-size: 2rem; line-height: 1; font-variant-numeric: tabular-nums; }

/* ---------- Metodología y pie ---------- */

.rp-method { padding: 4px 24px; border: 1px solid var(--sl-carbon); border-radius: 24px; }
.rp-method summary { padding: 10px 0; }
.rp-method summary > span:first-child i { color: var(--sl-ok); }
.rp-method summary > span:last-child { color: var(--sl-muted); font-size: 13px; }
.rp-method-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px 40px; padding: 20px 0 24px; border-top: 1px solid var(--sl-carbon); }
.rp-method h3 { margin-bottom: 4px; font-size: 14px; font-weight: 700; }
.rp-method p { color: var(--sl-muted); font-size: 14px; line-height: 1.65; }

.rp-foot { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px 16px; color: var(--sl-muted); font-size: 12px; }
.rp-foot i { margin-right: 4px; }

/* ---------- Efectos (dashboard.js añade .fx-ready con motion-ok) ---------- */

.rp.fx-ready :is(.rp-meter i, .rp-bar-fill, .rp-share span) {
    transform: scaleX(0);
    transform-origin: left center;
    transition: transform var(--duration-slow) var(--ease-out) var(--grow-delay, 120ms);
}

.rp.fx-ready .rp-hist-bar {
    transform: scaleY(0);
    transform-origin: center bottom;
    transition: transform var(--duration-slow) var(--ease-out) var(--grow-delay, 120ms);
}

.rp.fx-ready .is-live :is(.rp-meter i, .rp-bar-fill, .rp-share span, .rp-hist-bar) { transform: none; }

/* ---------- Adaptación ---------- */

@media (max-width: 1280px) {
    .rp-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .rp-kpi:nth-child(3) { border-left: 0; }
    .rp-kpi:nth-child(n + 3) { border-top: 1px solid var(--sl-carbon); }
    .rp-grid { grid-template-columns: minmax(0, 1fr); }
    .rp-summary { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); column-gap: 32px; }
    .rp-summary .rp-panel-head { grid-column: 1 / -1; }
    .rp-summary .rp-freshness { grid-column: 1 / -1; }
}

@media (max-width: 760px) {
    .rp-period { justify-items: start; }
    .rp-summary { display: flex; }
    .rp-method-grid { grid-template-columns: minmax(0, 1fr); }

    /* Ranking: cada fila pasa a ser una ficha. */
    .rp-ranking thead { display: none; }
    .rp-ranking tbody tr { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 8px 12px; padding: 14px 0; border-bottom: 1px solid var(--sl-line); }
    .rp-ranking tbody tr:last-child { border-bottom: 0; }
    .rp-ranking tbody :is(th, td) { padding: 0; border: 0; }
    .rp-ranking td[data-label] { grid-column: 2; display: grid; grid-template-columns: 82px minmax(0, 1fr); align-items: center; text-align: left; }
    .rp-ranking td[data-label]::before { content: attr(data-label); color: var(--sl-muted); font-size: 12px; font-weight: 700; }
    .rp-ranking .rp-score strong { display: inline; font-size: 1rem; }
    .rp-ranking .rp-score small { display: inline; margin-left: 8px; }
}

@media (max-width: 560px) {
    .rp { padding: 18px 14px; gap: 16px; border-radius: 24px; }
    .rp-folio span:last-child { display: none; }
    .rp-periods { width: 100%; grid-auto-columns: 1fr; }
    .rp-periods a { padding: 0 6px; }
    .rp-kpi { padding: 16px; }
    .rp-panel { padding: 18px 16px; }
    .rp-panel-head { flex-wrap: wrap; }
    .rp-chart { height: 230px; }
    .rp-hist { gap: 6px; }
    .rp-catalog-figures { width: 100%; }
    .rp-catalog-figures > div:first-child { padding-left: 0; border-left: 0; }
    .rp-button { width: 100%; justify-content: center; }
}

@media (prefers-reduced-motion: reduce) {
    .rp *, .rp *::before, .rp *::after { transition: none !important; animation: none !important; }
}
