/* ============================================================
   Lista giocatori
   ============================================================
   Namespace .lst-* costruito sulle primitive. Le vecchie .pool-* restano
   dove sono: sono usate anche da Calendario, Consigliati e Serie A, e
   ristilizzarle in place romperebbe quelle viste.
   ============================================================ */

/* ---- Impianto a due colonne --------------------------------------------
   La catena di altezze e' vincolante: .lst-scroll deve avere un'altezza
   misurabile, altrimenti la finestra scorrevole calcola zero righe visibili
   e la tabella appare bianca. Ogni anello della catena porta min-height: 0,
   perche' un figlio flex non scende sotto il proprio contenuto finche' resta
   ad auto. Il min-height su .lst-scroll e' la rete di sicurezza se un giorno
   la catena si spezza. */
.lst-wrap {
    display: grid;
    flex: 1;
    gap: var(--sp-4);
    grid-template-columns: minmax(0, 1fr) 320px;
    min-height: 0;
}

.lst-main {
    display: flex;
    flex-direction: column;
    gap: var(--sp-3);
    min-height: 0;
    min-width: 0;
}

.lst-aside {
    display: flex;
    flex-direction: column;
    gap: var(--sp-3);
    min-width: 0;
    overflow-y: auto;
}

@media (max-width: 1279px) {
    .lst-wrap { grid-template-columns: minmax(0, 1fr); }
    .lst-aside { flex-direction: row; flex-wrap: wrap; overflow: visible; }
    .lst-aside > * { flex: 1 1 280px; }
}

/* ---- Testata di pagina -------------------------------------------------- */
.lst-head {
    align-items: flex-end;
    display: flex;
    gap: var(--sp-3);
    justify-content: space-between;
}

.lst-title {
    color: var(--ink-1);
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    margin: 0;
}

.lst-sub {
    color: var(--ink-3);
    font-size: var(--fs-base);
    margin: 2px 0 0;
}

/* ---- Barra di contesto asta -------------------------------------------- */
.lst-context {
    align-items: center;
    background: var(--bg-surface);
    border: 1px solid var(--line-strong);
    border-radius: var(--r-md);
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-wrap: wrap;
    gap: var(--sp-5);
    padding: var(--sp-3) var(--sp-4);
}

/* Quando tocca a te la barra si accende: e' l'unico momento in cui devi agire. */
.lst-context.is-mine {
    border-color: color-mix(in srgb, var(--brand) 45%, var(--line-strong));
    box-shadow: var(--shadow-sm), inset 3px 0 0 var(--brand);
}

.lst-ctx-turn {
    align-items: center;
    display: flex;
    gap: var(--sp-3);
    min-width: 0;
}

.lst-ctx-team {
    color: var(--ink-1);
    font-size: var(--fs-md);
    font-weight: 700;
}

.lst-ctx-crown { color: var(--brand); font-size: .75em; }

.lst-ctx-item {
    align-items: center;
    border-left: 1px solid var(--line);
    display: flex;
    gap: var(--sp-2);
    min-width: 0;
    padding-left: var(--sp-5);
}

.lst-ctx-val {
    align-items: center;
    color: var(--ink-1);
    display: flex;
    font-size: var(--fs-md);
    font-variant-numeric: tabular-nums;
    font-weight: 700;
    gap: 6px;
}

/* "Ti serve" e' uno slot di reparto vuoto, non una persona in astratto: il
   badge del ruolo con un piu' accanto lo dice senza metafore. */
.lst-ctx-slot {
    align-items: center;
    display: inline-flex;
    flex-shrink: 0;
    gap: 1px;
}

.lst-ctx-slot .role-badge { opacity: .55; }

.lst-ctx-piu {
    color: var(--ink-3);
    font-size: .8rem;
    font-weight: 700;
}

.lst-ctx-need {
    color: var(--ink-2);
    font-size: var(--fs-sm);
    font-weight: 500;
}

.lst-timer-bar {
    background: var(--bg-raised);
    border-radius: var(--r-full);
    height: 4px;
    margin-top: 4px;
    overflow: hidden;
    width: 92px;
}

.lst-timer-bar > i {
    background: var(--brand);
    display: block;
    height: 100%;
    transition: width var(--t-base) linear;
}

.lst-ctx-timer.is-urgent .lst-ctx-val { color: var(--negative-ink); }
.lst-ctx-timer.is-urgent .lst-timer-bar > i { background: var(--negative); }

/* ---- Toolbar ------------------------------------------------------------ */
.lst-toolbar {
    align-items: center;
    background: var(--bg-surface);
    border: 1px solid var(--line-strong);
    border-radius: var(--r-md);
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-wrap: wrap;
    gap: var(--sp-2);
    padding: var(--sp-3);
}

.lst-search {
    flex: 1 1 200px;
    max-width: 280px;
    min-width: 0;
    position: relative;
}

.lst-search-ico {
    color: var(--ink-3);
    font-size: .9rem;
    left: 12px;
    pointer-events: none;
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
}

.lst-search-input {
    background: var(--bg-sunken);
    border: 1px solid var(--line-strong);
    border-radius: var(--r-xs);
    color: var(--ink-1);
    font-family: var(--font-ui);
    font-size: var(--fs-sm);
    height: 36px;
    padding: 0 var(--sp-3) 0 34px;
    width: 100%;
}

.lst-search-input:focus {
    background: var(--bg-surface);
    border-color: var(--navy);
    box-shadow: 0 0 0 3px var(--navy-tint);
    outline: none;
}

.lst-team { max-width: 190px; width: auto; }

.lst-toggle {
    align-items: center;
    color: var(--ink-2);
    cursor: pointer;
    display: inline-flex;
    font-size: var(--fs-sm);
    font-weight: 500;
    gap: 6px;
    white-space: nowrap;
}

.lst-adv-btn { white-space: nowrap; }
.lst-density { margin-left: auto; }
.lst-density .fw-seg-item { padding: 4px 10px; }

/* ---- Drawer dei filtri avanzati ---------------------------------------- */
.lst-drawer {
    background: var(--bg-sunken);
    border: 1px solid var(--line-strong);
    border-radius: var(--r-md);
    padding: var(--sp-3) var(--sp-4);
}

.lst-adv-grid {
    display: grid;
    gap: var(--sp-3);
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}

.lst-adv-field {
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
}

.lst-adv-check {
    align-items: center;
    align-self: end;
    cursor: pointer;
    flex-direction: row;
    gap: 8px;
    font-size: var(--fs-sm);
    min-height: 36px;
}

.lst-adv-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: var(--sp-3);
}

/* ---- La tabella --------------------------------------------------------- */
.lst-card {
    background: var(--bg-surface);
    border: 1px solid var(--line-strong);
    border-radius: var(--r-md);
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.lst-scroll {
    /* L'altezza la impone lstFitHeight(): la catena flex sopra ha solo
       min-height, quindi da sola lascerebbe crescere lo scroller fino a
       contenere tutte le righe. Il min-height qui e' la rete di sicurezza. */
    min-height: 280px;
    overflow: auto;
}

/* table-layout: fixed non e' negoziabile con la finestra scorrevole. Senza,
   ogni frazione di righe renderizzata ricalcola le larghezze dal proprio
   sottoinsieme e le colonne ballano durante lo scroll. */
.lst-table {
    border-collapse: separate;
    border-spacing: 0;
    font-size: var(--fs-sm);
    /* Sotto questa larghezza le colonne a misura fissa non ci stanno e il
       contenuto si sovrappone: meglio far scorrere la tabella in orizzontale
       dentro il proprio contenitore, che e' l'unico a scorrere. */
    min-width: 940px;
    table-layout: fixed;
    width: 100%;
}

.lst-table thead th {
    background: var(--bg-sunken);
    border-bottom: 1px solid var(--line-strong);
    color: var(--ink-3);
    font-size: var(--fs-micro);
    font-weight: 600;
    letter-spacing: var(--tracking-micro);
    padding: var(--sp-2) var(--sp-2);
    position: sticky;
    text-align: left;
    text-transform: uppercase;
    top: 0;
    white-space: nowrap;
    z-index: 2;
}

.lst-table td {
    border-bottom: 1px solid var(--line);
    color: var(--ink-1);
    height: var(--lst-row-h, 38px);
    overflow: hidden;
    padding: 0 var(--sp-2);
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Le righe devono essere isoaltezza: la finestra calcola quante ne stanno
   moltiplicando per --lst-row-h. Una riga a due linee sfalsa tutto. */
.lst-row td { line-height: 1.2; }
.lst-pad td { border: 0; padding: 0; }

.lst-row:hover td { background: var(--bg-raised); }
.lst-row-sel td { background: var(--navy-tint); }
.lst-row-live td { background: var(--brand-tint); }
.lst-row-taken td { color: var(--ink-3); }

/* Il giocatore assegnato si smorza col colore, non con l'opacity: l'opacity
   crea uno stacking context sulla riga e rende traslucide le celle sticky. */
.lst-row-taken .lst-name { color: var(--ink-2); font-weight: 500; }
.lst-row-taken .lst-face { filter: grayscale(1); opacity: .7; }

/* Colonne ferme a sinistra: hanno bisogno di sfondo proprio, altrimenti si
   vede scorrere sotto il contenuto delle altre. */
.lst-c-pick, .lst-c-star {
    background: var(--bg-surface);
    position: sticky;
    z-index: 1;
}

.lst-c-pick { left: 0; }
.lst-c-star { left: 40px; }

.lst-table thead .lst-c-pick,
.lst-table thead .lst-c-star { background: var(--bg-sunken); z-index: 3; }

.lst-row:hover .lst-c-pick,
.lst-row:hover .lst-c-star { background: var(--bg-raised); }

.lst-row-sel .lst-c-pick,
.lst-row-sel .lst-c-star { background: var(--navy-tint); }

.lst-row-live .lst-c-pick,
.lst-row-live .lst-c-star { background: var(--brand-tint); }

.lst-c-pick, .lst-c-star, .lst-c-call { padding: 0; text-align: center; }

.lst-check { cursor: pointer; }

.lst-star, .lst-call {
    background: none;
    border: 0;
    color: var(--ink-3);
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
    padding: 6px;
}

.lst-star:hover { color: var(--gold); }
.lst-star.on { color: var(--brand); }
.lst-call:hover { color: var(--navy); }

.lst-c-name {
    align-items: center;
    display: flex;
    gap: var(--sp-2);
    min-width: 0;
}

.lst-face {
    background: var(--bg-sunken);
    border-radius: 50%;
    flex-shrink: 0;
    height: calc(var(--lst-row-h, 38px) - 12px);
    max-height: 34px;
    object-fit: cover;
    object-position: top center;
    width: calc(var(--lst-row-h, 38px) - 12px);
    max-width: 34px;
}

.lst-name {
    color: var(--ink-1);
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
}

.lst-c-team { color: var(--ink-2); }
.lst-c-role, .lst-c-stato { white-space: nowrap; }

.lst-foot {
    border-top: 1px solid var(--line);
    color: var(--ink-3);
    font-size: var(--fs-sm);
    padding: var(--sp-2) var(--sp-4);
}

/* ---- Sidebar: griglia degli insight ------------------------------------ */
.lst-insight-grid {
    display: grid;
    gap: var(--sp-2);
    grid-template-columns: repeat(3, minmax(0, 1fr));
    padding: 0 var(--sp-3) var(--sp-3);
}

.lst-insight-cell .fw-insight-meta { white-space: normal; }

.lst-insight-cell {
    background: var(--bg-sunken);
    border: 1px solid var(--line);
    border-radius: var(--r-xs);
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: var(--sp-2);
}

.lst-insight-n {
    color: var(--ink-1);
    font-size: 1.35rem;
    font-variant-numeric: tabular-nums;
    font-weight: 700;
    line-height: 1.1;
}

.lst-star-mini { color: var(--brand); flex-shrink: 0; }

/* ---- Barra di confronto ------------------------------------------------- */
.lst-sel-close { padding-inline: 8px; }

.fw-actionbar .btn-outline-light {
    --bs-btn-color: #fff;
    --bs-btn-border-color: rgba(255, 255, 255, .4);
    --bs-btn-hover-bg: rgba(255, 255, 255, .12);
    --bs-btn-hover-border-color: rgba(255, 255, 255, .7);
    --bs-btn-hover-color: #fff;
}

/* ---- Modale di confronto ------------------------------------------------ */
.lst-cmp-modal .modal-dialog,
.modal-dialog.lst-cmp-modal { max-width: 760px; }

.lst-cmp-wrap { overflow-x: auto; }

.lst-cmp-table {
    border-collapse: collapse;
    width: 100%;
}

.lst-cmp-table th,
.lst-cmp-table td {
    border-bottom: 1px solid var(--line);
    padding: var(--sp-2) var(--sp-3);
    text-align: center;
}

.lst-cmp-table thead th {
    border-bottom: 1px solid var(--line-strong);
    vertical-align: bottom;
}

.lst-cmp-table thead th > * { display: block; margin-inline: auto; }

.lst-cmp-table tbody th {
    color: var(--ink-3);
    font-size: var(--fs-sm);
    font-weight: 500;
    text-align: left;
    white-space: nowrap;
}

.lst-cmp-name {
    color: var(--ink-1);
    font-weight: 700;
    margin-top: 4px;
}

.lst-cmp-best {
    background: var(--positive-tint);
    color: var(--positive-ink);
    font-weight: 700;
}

/* ---- Schermo stretto ---------------------------------------------------- */
@media (max-width: 767px) {
    .lst-title { font-size: 1.4rem; }
    .lst-toolbar { gap: var(--sp-2); }
    .lst-search { flex-basis: 100%; max-width: none; }
    .lst-density { margin-left: 0; }
    .lst-context { gap: var(--sp-3); }
    .lst-ctx-item { border-left: 0; padding-left: 0; }
    .lst-insight-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ============================================================
   Su telefono la tabella diventa una lista di card
   ============================================================
   Dodici colonne su 390px non si leggono. La specifica dice quali contano:
   giocatore, squadra, ruolo, quotazione, fantamedia, stato. Le altre restano
   nella scheda del giocatore, a un tocco di distanza.

   Ogni cella ha un'area di griglia sua. Il primo tentativo ne metteva quattro
   nella stessa area scostandole con i margini: si sovrapponevano, e a schermo
   ne restava visibile una sola.

   La card ha altezza fissa (--lst-row-h, che in modalita' card vale 104px):
   la finestra scorrevole conta le righe moltiplicando per quell'altezza, e
   una card piu' alta delle altre sfalserebbe il calcolo.
   ============================================================ */

@media (max-width: 767px) {
    .lst-table,
    .lst-table > tbody,
    .lst-table > tbody > tr,
    .lst-table > tbody > tr > td {
        display: block;
    }

    .lst-table { min-width: 0; }
    .lst-table > thead,
    .lst-table > colgroup { display: none; }

    .lst-table > tbody > tr.lst-row {
        align-content: center;
        border-bottom: 1px solid var(--line);
        column-gap: var(--sp-2);
        display: grid;
        grid-template-areas:
            "pick star nome  nome  nome"
            "pick star ruolo squadra squadra"
            "pick star qt    mf    stato";
        grid-template-columns: 26px 28px auto auto 1fr;
        height: var(--lst-row-h);
        padding: var(--sp-2) var(--sp-3);
        row-gap: 1px;
    }

    .lst-row > td {
        align-items: center;
        border: 0;
        display: flex;
        height: auto;
        min-width: 0;
        padding: 0;
    }

    .lst-row > .lst-c-pick { grid-area: pick; justify-content: center; position: static; }
    .lst-row > .lst-c-star { grid-area: star; justify-content: center; position: static; }
    .lst-row > .lst-col-nome { grid-area: nome; }
    .lst-row > .lst-col-ruolo_quota { grid-area: ruolo; }
    .lst-row > .lst-col-squadra { grid-area: squadra; }
    .lst-row > .lst-col-quota_attuale_classic { grid-area: qt; }
    .lst-row > .lst-col-media_fanta { grid-area: mf; }
    .lst-row > .lst-col-stato { grid-area: stato; justify-content: flex-end; }

    .lst-row > .lst-col-squadra {
        color: var(--ink-2);
        font-size: var(--fs-sm);
        margin-left: var(--sp-2);
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .lst-row > .lst-col-quota_attuale_classic,
    .lst-row > .lst-col-media_fanta {
        color: var(--ink-1);
        font-size: var(--fs-sm);
        font-weight: 700;
        gap: 3px;
        margin-right: var(--sp-3);
    }

    /* Senza intestazione di colonna il numero da solo non dice cosa sia. */
    .lst-row > .lst-col-quota_attuale_classic::before,
    .lst-row > .lst-col-media_fanta::before {
        color: var(--ink-3);
        font-size: var(--fs-micro);
        font-weight: 600;
        /* Il gap del contenitore non separa un pseudo-elemento da un nodo di
           testo nudo: senza margine si legge "QT6 K". */
        margin-right: 4px;
    }
    .lst-row > .lst-col-quota_attuale_classic::before { content: "QT"; }
    .lst-row > .lst-col-media_fanta::before { content: "MF"; }

    /* Tutto il resto vive nella scheda giocatore. */
    .lst-row > .lst-col-voto_medio,
    .lst-row > .lst-col-partite_disputate,
    .lst-row > .lst-col-gol_totali,
    .lst-row > .lst-col-assist_totali,
    .lst-row > .lst-col-rigore_falliti_totali,
    .lst-row > .lst-col-gol_subiti_totali,
    .lst-row > .lst-col-imbattuti_totali,
    .lst-row > .lst-col-rigore_procurati_totali,
    .lst-row > .lst-col-ammonizioni_totali,
    .lst-row > .lst-col-espulsioni_totali,
    .lst-row > .lst-c-call {
        display: none;
    }

    .lst-row .lst-name {
        font-size: var(--fs-base);
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .lst-row .lst-face { height: 30px; max-height: 30px; max-width: 30px; width: 30px; }

    /* Le righe spaziatrici tengono comunque l'altezza del blocco non reso. */
    .lst-table > tbody > tr.lst-pad { display: block; }
    .lst-table > tbody > tr.lst-pad > td { display: block; height: inherit; }

    /* Con le card la densita' non ha effetto: si nasconde il comando invece
       di lasciarne uno che non fa niente. */
    .lst-density { display: none; }
}
