/* ============================================================
   Ranking global — modal "¿dónde queda mi selección?"
   Compartido entre comparadores: se copia tal cual a cada carpeta.
   ============================================================ */

/* Extras de la etiqueta del botón que abre el ranking */
.btn-rank-open .brk-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 17px;
    height: 17px;
    border-radius: 2px;
    background: var(--primary-color);
    color: #fff;
    font-size: 0.66rem;
    font-weight: 800;
}
.btn-rank-open .brk-pos   { font-weight: 800; letter-spacing: 0.2px; }
.btn-rank-open .brk-total { opacity: 0.6; font-weight: 600; }

.rank-modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: rgba(0,0,0,0.78);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.6rem 1rem;
    backdrop-filter: blur(3px);
}
.light-theme .rank-modal-overlay { background: rgba(0,0,0,0.5); }

.rank-modal {
    background: #171717;
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 4px;
    width: 100%;
    max-width: 1020px;
    max-height: 88vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 18px 48px rgba(0,0,0,0.55);
    animation: rankModalIn 0.16s ease-out both;
}
.light-theme .rank-modal {
    background: #fff;
    border-color: rgba(0,0,0,0.14);
    box-shadow: 0 18px 48px rgba(0,0,0,0.16);
}
@keyframes rankModalIn {
    from { opacity: 0; transform: translateY(-8px); }
    to   { opacity: 1; transform: none; }
}

/* --- Cabecera --- */
.rank-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.9rem 1.2rem;
    border-bottom: 1px solid rgba(255,255,255,0.09);
    flex-shrink: 0;
}
.light-theme .rank-modal-header { border-bottom-color: rgba(0,0,0,0.1); }
.rank-modal-header-left { display: flex; align-items: center; gap: 0.7rem; }
.rank-modal-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: 3px;
    background: rgba(255,107,53,0.13);
    color: var(--primary-color);
    font-size: 0.86rem;
    flex-shrink: 0;
}
.rank-modal-header h2 {
    margin: 0;
    font-size: 0.92rem;
    font-weight: 700;
    letter-spacing: 0.3px;
    color: #fff;
}
.light-theme .rank-modal-header h2 { color: #111; }
.rank-modal-subtitle {
    margin: 0.12rem 0 0;
    font-size: 0.73rem;
    color: rgba(255,255,255,0.42);
}
.light-theme .rank-modal-subtitle { color: rgba(0,0,0,0.5); }
.rank-modal-subtitle #rank-count { color: var(--primary-color); font-weight: 700; }

.rank-modal-close {
    background: none;
    border: 1px solid transparent;
    border-radius: 3px;
    color: rgba(255,255,255,0.45);
    font-size: 1rem;
    cursor: pointer;
    padding: 4px 9px;
    transition: color 0.15s, background 0.15s, border-color 0.15s;
}
.rank-modal-close:hover { color: #fff; background: rgba(255,255,255,0.07); border-color: rgba(255,255,255,0.12); }
.light-theme .rank-modal-close { color: rgba(0,0,0,0.45); }
.light-theme .rank-modal-close:hover { color: #111; background: rgba(0,0,0,0.05); border-color: rgba(0,0,0,0.12); }

/* --- Barra de controles --- */
.rank-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.8rem;
    flex-wrap: wrap;
    padding: 0.6rem 1.2rem;
    border-bottom: 1px solid rgba(255,255,255,0.09);
    flex-shrink: 0;
}
.light-theme .rank-toolbar { border-bottom-color: rgba(0,0,0,0.1); }

/* Control segmentado para los tres modos */
.rank-modes {
    display: flex;
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 3px;
    overflow: hidden;
}
.light-theme .rank-modes { border-color: rgba(0,0,0,0.14); }
.rank-mode-btn {
    background: none;
    border: none;
    border-right: 1px solid rgba(255,255,255,0.12);
    padding: 0.4rem 0.95rem;
    font-family: inherit;
    font-size: 0.74rem;
    font-weight: 700;
    letter-spacing: 0.3px;
    color: rgba(255,255,255,0.5);
    cursor: pointer;
    white-space: nowrap;
    transition: color 0.14s, background 0.14s;
}
.rank-mode-btn:last-child { border-right: none; }
.light-theme .rank-mode-btn { border-right-color: rgba(0,0,0,0.14); color: rgba(0,0,0,0.48); }
.rank-mode-btn:hover { color: rgba(255,255,255,0.9); background: rgba(255,255,255,0.05); }
.light-theme .rank-mode-btn:hover { color: #111; background: rgba(0,0,0,0.04); }
.rank-mode-btn.active { color: #fff; background: var(--primary-color); }
.light-theme .rank-mode-btn.active { color: #fff; background: var(--primary-color); }

.rank-filters { display: flex; align-items: center; gap: 0.45rem; }

.rank-goto-sel {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    background: none;
    border: 1px solid rgba(255,255,255,0.14);
    border-radius: 3px;
    padding: 0.4rem 0.7rem;
    font-family: inherit;
    font-size: 0.74rem;
    font-weight: 600;
    color: rgba(255,255,255,0.6);
    cursor: pointer;
    white-space: nowrap;
    transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.rank-goto-sel:hover {
    color: #fff;
    border-color: rgba(255,255,255,0.3);
    background: rgba(255,255,255,0.05);
}
.light-theme .rank-goto-sel { border-color: rgba(0,0,0,0.16); color: rgba(0,0,0,0.6); }
.light-theme .rank-goto-sel:hover { color: #111; border-color: rgba(0,0,0,0.32); background: rgba(0,0,0,0.04); }

.rank-search { position: relative; display: flex; align-items: center; }
.rank-search i {
    position: absolute;
    left: 0.55rem;
    font-size: 0.7rem;
    color: rgba(255,255,255,0.32);
    pointer-events: none;
}
.light-theme .rank-search i { color: rgba(0,0,0,0.32); }
.rank-search input,
.rank-brand {
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 3px;
    color: #fff;
    font-family: inherit;
    font-size: 0.75rem;
    padding: 0.4rem 0.65rem;
    outline: none;
    transition: border-color 0.15s, background 0.15s;
}
.rank-search input { padding-left: 1.7rem; width: 180px; }
.rank-search input::placeholder { color: rgba(255,255,255,0.3); }
.rank-search input:focus,
.rank-brand:focus { border-color: var(--primary-color); background: rgba(255,255,255,0.07); }
.rank-brand { cursor: pointer; }
.rank-brand option { background: #171717; color: #fff; }
.light-theme .rank-search input,
.light-theme .rank-brand {
    background: rgba(0,0,0,0.02);
    border-color: rgba(0,0,0,0.16);
    color: #111;
}
.light-theme .rank-search input::placeholder { color: rgba(0,0,0,0.34); }
.light-theme .rank-brand option { background: #fff; color: #111; }

/* --- Cabecera de columnas --- */
.rank-list-head {
    display: grid;
    grid-template-columns: 66px 24px minmax(0,1fr) 180px 48px 68px;
    gap: 0.7rem;
    align-items: center;
    padding: 0.45rem 1.7rem;
    font-size: 0.63rem;
    font-weight: 700;
    letter-spacing: 0.9px;
    text-transform: uppercase;
    color: rgba(255,255,255,0.32);
    background: rgba(255,255,255,0.02);
    border-bottom: 1px solid rgba(255,255,255,0.09);
    flex-shrink: 0;
}
.light-theme .rank-list-head {
    color: rgba(0,0,0,0.4);
    background: rgba(0,0,0,0.02);
    border-bottom-color: rgba(0,0,0,0.1);
}
.rank-list-head .rkh-pos   { text-align: right; }
.rank-list-head .rkh-score { grid-column: 4 / 7; text-align: right; }

/* --- Lista --- */
.rank-list-wrap {
    position: relative;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 0 1.2rem;
}
.rank-list-wrap::-webkit-scrollbar { width: 8px; }
.rank-list-wrap::-webkit-scrollbar-track { background: transparent; }
.rank-list-wrap::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.16); border-radius: 0; }
.rank-list-wrap::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.26); }
.light-theme .rank-list-wrap::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.18); }

.rank-sentinel { height: 1px; }

.rk-row {
    display: grid;
    grid-template-columns: 66px 24px minmax(0,1fr) 180px 48px 68px;
    gap: 0.7rem;
    align-items: center;
    height: 40px;
    padding: 0 0.5rem;
    position: relative;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    /* Aunque las filas se cargan por tandas, al llegar abajo del todo pueden
       acumularse miles: saltarse el layout de lo que no se ve mantiene fluido
       el scroll. La altura fija hace que las posiciones estimadas sean exactas. */
    content-visibility: auto;
    contain-intrinsic-size: auto 40px;
}
.light-theme .rk-row { border-bottom-color: rgba(0,0,0,0.06); }
.rk-row:hover { background: rgba(255,255,255,0.04); }
.light-theme .rk-row:hover { background: rgba(0,0,0,0.03); }

.rk-row > * { position: relative; z-index: 1; }

.rk-pos {
    text-align: right;
    font-size: 0.75rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    color: rgba(255,255,255,0.34);
}
.light-theme .rk-pos { color: rgba(0,0,0,0.38); }
.rk-top1 .rk-pos { color: #e8c14a; font-weight: 800; }
.rk-top2 .rk-pos { color: #b9c2c7; font-weight: 800; }
.rk-top3 .rk-pos { color: #c48a55; font-weight: 800; }
.light-theme .rk-top1 .rk-pos { color: #a8811c; }
.light-theme .rk-top2 .rk-pos { color: #6d7a80; }
.light-theme .rk-top3 .rk-pos { color: #96603a; }

.rk-slot {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 19px;
    height: 19px;
    border-radius: 2px;
    font-size: 0.64rem;
    font-weight: 800;
    color: #fff;
}
.rk-sel .rk-slot { background: var(--rk-c); }

.rk-name {
    font-size: 0.8rem;
    font-weight: 500;
    color: rgba(255,255,255,0.76);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.light-theme .rk-name { color: rgba(0,0,0,0.76); }
.rk-sel .rk-name { color: #fff; font-weight: 700; }
.light-theme .rk-sel .rk-name { color: #111; }

.rk-bar {
    display: block;
    height: 5px;
    border-radius: 0;
    background: rgba(255,255,255,0.07);
    overflow: hidden;
}
.light-theme .rk-bar { background: rgba(0,0,0,0.07); }
.rk-bar i {
    display: block;
    height: 100%;
    background: rgba(255,107,53,0.75);
}
.rk-sel .rk-bar i { background: var(--rk-c); }

.rk-score {
    text-align: right;
    font-size: 0.8rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: rgba(255,255,255,0.85);
}
.light-theme .rk-score { color: rgba(0,0,0,0.8); }
.rk-sel .rk-score { color: var(--rk-c); }

.rk-pct {
    text-align: right;
    font-size: 0.68rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    color: rgba(255,255,255,0.28);
}
.light-theme .rk-pct { color: rgba(0,0,0,0.34); }
.rk-sel .rk-pct { color: rgba(255,255,255,0.58); }
.light-theme .rk-sel .rk-pct { color: rgba(0,0,0,0.52); }

/* Fila seleccionada: filo del color de su slot + tinte muy leve */
.rk-sel { box-shadow: inset 2px 0 0 var(--rk-c); }
.rk-sel::before {
    content: '';
    position: absolute;
    inset: 0;
    background: var(--rk-c);
    opacity: 0.1;
    pointer-events: none;
}
.light-theme .rk-sel::before { opacity: 0.08; }

@keyframes rkFlash {
    0%   { box-shadow: inset 2px 0 0 var(--rk-c), inset 0 0 0 1px var(--rk-c); }
    100% { box-shadow: inset 2px 0 0 var(--rk-c), inset 0 0 0 1px transparent; }
}
.rk-flash { animation: rkFlash 1.2s ease-out 1; }

.rank-empty {
    padding: 2.5rem 1rem;
    text-align: center;
    font-size: 0.8rem;
    color: rgba(255,255,255,0.34);
}
.light-theme .rank-empty { color: rgba(0,0,0,0.4); }

@media (max-width: 860px) {
    .rank-list-head,
    .rk-row { grid-template-columns: 56px 22px minmax(0,1fr) 48px 62px; }
    .rank-list-head .rkh-score { grid-column: 4 / 6; }
    .rk-bar { display: none; }
    .rank-search input { width: 130px; }
    .rank-goto-sel span { display: none; }
}
@media (max-width: 640px) {
    .rank-modal-overlay { padding: 0.5rem; }
    .rank-modal { max-height: 95vh; }
    .rank-modal-header { padding: 0.75rem 0.9rem; }
    .rank-toolbar { padding: 0.55rem 0.9rem; }
    .rank-list-head { padding-left: 1.4rem; padding-right: 1.4rem; }
    .rank-list-wrap { padding-left: 0.9rem; padding-right: 0.9rem; }
    .rank-filters { width: 100%; }
    .rank-search { flex: 1; }
    .rank-search input { width: 100%; }
    .rank-list-head,
    .rk-row { grid-template-columns: 50px 20px minmax(0,1fr) 46px; }
    .rank-list-head .rkh-score { grid-column: 4 / 5; }
    .rk-pct { display: none; }
}
