/* ==========================================================================
   TGF Leaderboard
   ========================================================================== */

.tgf-lb {
    /* GradeIt brand palette */
    --tgf-lb-text:           #f4f5f7;
    --tgf-lb-muted:          rgba(244,245,247,0.65);
    --tgf-lb-accent:         #F15F51;  /* coral — primary brand */
    --tgf-lb-accent-2:       #60C7CB;  /* teal — secondary chips */
    --tgf-lb-accent-warm:    #F8AA4A;  /* orange — silver-podium accent */
    --tgf-lb-accent-yellow:  #FBCC0A;  /* yellow — gold-podium accent */
    --tgf-lb-bg:             rgba(255,255,255,0.04);
    --tgf-lb-border:         rgba(255,255,255,0.08);
    --tgf-lb-radius:         16px;
    color: var(--tgf-lb-text);
    margin: 32px auto;
    max-width: 1200px;
}

/* Claim the ink colour explicitly: themes set `h2 { color: … }` directly and
   an explicit rule beats the colour .tgf-lb passes down by inheritance, which
   would leave board titles near-black on the dark surface. */
.tgf-lb h1, .tgf-lb h2, .tgf-lb h3,
.tgf-lb h4, .tgf-lb h5, .tgf-lb h6 {
    color: var(--tgf-lb-text);
}
.tgf-lb__title {
    margin: 0 0 16px;
    font-size: 24px;
    font-weight: 800;
}

/* Filter pills — each filter is a trigger button that opens a popover with the chip options. */
.tgf-lb__filters {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 22px;
    padding: 14px 16px;
    background: var(--tgf-lb-bg);
    border: 1px solid var(--tgf-lb-border);
    border-radius: var(--tgf-lb-radius);
}
.tgf-lb__filter {
    position: relative;   /* anchor for the popover */
}
.tgf-lb__filter-trigger {
    appearance: none;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: rgba(255,255,255,0.05);
    color: var(--tgf-lb-text);
    border: 1px solid var(--tgf-lb-border);
    border-radius: 999px;
    padding: 8px 16px;
    font: inherit;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
.tgf-lb__filter-trigger:hover {
    border-color: var(--tgf-lb-accent);
    background: rgba(241, 95, 81, 0.10);
    transform: translateY(-1px);
}
.tgf-lb__filter.is-open .tgf-lb__filter-trigger {
    /* Open state uses the teal accent + charcoal — same readable scheme as the chip+slab. */
    background: var(--tgf-lb-accent-2);
    border-color: var(--tgf-lb-accent-2);
    color: #0D0908;
}
.tgf-lb__filter.is-open .tgf-lb__filter-chevron { transform: rotate(180deg); }
.tgf-lb__filter-chevron { transition: transform 0.15s ease; }
.tgf-lb__filter-label {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: inherit;
    opacity: 0.75;
    font-weight: 700;
    margin: 0;
}
.tgf-lb__filter-current { font-weight: 700; }

.tgf-lb__filter-popover {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    z-index: 50;
    background: #1d2127;
    border: 1px solid var(--tgf-lb-border);
    border-radius: 12px;
    padding: 10px 12px;
    box-shadow: 0 12px 30px -10px rgba(0,0,0,0.55), 0 4px 12px -6px rgba(0,0,0,0.35);
    min-width: 180px;
}
.tgf-lb__filter-popover[hidden] { display: none; }
.tgf-lb__filter-popover--grades {
    max-width: 360px;
}
.tgf-lb__filter-popover .tgf-lb__chip-row {
    flex-direction: column;
    align-items: stretch;
}
.tgf-lb__filter-popover--grades .tgf-lb__chip-row {
    flex-direction: row;
    flex-wrap: wrap;
}
.tgf-lb__filter-popover .tgf-lb__chip {
    text-align: left;
}
@media (max-width: 600px) {
    .tgf-lb__filter-popover {
        left: 0;
        right: 0;
        min-width: 0;
    }
}

.tgf-lb__chip-row { display: flex; flex-wrap: wrap; gap: 6px; }
.tgf-lb__chip {
    appearance: none;
    background: transparent;
    color: var(--tgf-lb-text);
    border: 1px solid var(--tgf-lb-border);
    border-radius: 999px;
    padding: 6px 14px;
    font: inherit;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
.tgf-lb__chip:hover {
    border-color: var(--tgf-lb-accent);
    transform: translateY(-1px);
}
.tgf-lb__chip.is-active {
    /* Teal + charcoal to match the brand readability fix applied across the plugin. */
    background: var(--tgf-lb-accent-2);
    border-color: var(--tgf-lb-accent-2);
    color: #0D0908;
}
.tgf-lb__chip--black-label.is-active {
    background: #000;
    color: #ffd700;
    border-color: #ffd700;
}
.tgf-lb__chip--pristine.is-active {
    background: linear-gradient(135deg, var(--tgf-lb-accent-yellow), var(--tgf-lb-accent));
    color: #1d2327;
    border-color: var(--tgf-lb-accent-yellow);
}

/* Results */
.tgf-lb__results { min-height: 80px; position: relative; }
.tgf-lb__results.is-loading::after {
    content: '';
    position: absolute; inset: 0;
    background: rgba(0,0,0,0.3);
    backdrop-filter: blur(2px);
    border-radius: var(--tgf-lb-radius);
}

.tgf-lb__empty {
    padding: 40px 0;
    text-align: center;
    color: var(--tgf-lb-muted);
    font-style: italic;
}

.tgf-lb__table-wrap {
    overflow-x: auto;
    background: var(--tgf-lb-bg);
    border: 1px solid var(--tgf-lb-border);
    border-radius: var(--tgf-lb-radius);
}
.tgf-lb__table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    min-width: 720px;
}
.tgf-lb__table th,
.tgf-lb__table td {
    padding: 10px 14px;
    text-align: left;
    border-bottom: 1px solid var(--tgf-lb-border);
    vertical-align: middle;
}
.tgf-lb__table thead th {
    text-transform: uppercase;
    font-size: 11px;
    letter-spacing: 0.08em;
    color: var(--tgf-lb-muted);
    font-weight: 700;
    background: rgba(255,255,255,0.04);
}
.tgf-lb__table tbody tr:last-child td { border-bottom: 0; }
.tgf-lb__col-rank { width: 50px; text-align: center; }
.tgf-lb__col-grade { width: 100px; }
.tgf-lb__col-date { white-space: nowrap; width: 110px; }
.tgf-lb__rank { font-weight: 700; color: var(--tgf-lb-muted); text-align: center; }
.tgf-lb__item strong { display: block; }
.tgf-lb__sub { color: var(--tgf-lb-muted); font-size: 12px; display: block; margin-top: 2px; }
.tgf-lb__grader { font-weight: 600; }

/* Grade pill */
.tgf-lb__grade-pill {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 999px;
    background: #1d2327;
    color: #fff;
    font-weight: 700;
    font-size: 13px;
}
.tgf-lb__grade-pill.is-perfect-10 {
    /* Brand sweep — coral → orange, matches the top-left arm of the logo star. */
    background: linear-gradient(135deg, var(--tgf-lb-accent), var(--tgf-lb-accent-warm));
}
.tgf-lb__grade-pill.is-pristine {
    /* Yellow → coral, the bottom arms of the logo star. */
    background: linear-gradient(135deg, var(--tgf-lb-accent-yellow), var(--tgf-lb-accent));
    color: #1d2327;
}
.tgf-lb__grade-pill.is-black-label {
    background: #000;
    color: var(--tgf-lb-accent-yellow);
    box-shadow: inset 0 0 0 1px var(--tgf-lb-accent-yellow);
}

/* Podium (users view) */
.tgf-lb__podium {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 14px;
    margin-bottom: 24px;
}
.tgf-lb__podium-card {
    background: var(--tgf-lb-bg);
    border: 1px solid var(--tgf-lb-border);
    border-radius: var(--tgf-lb-radius);
    padding: 22px 18px;
    text-align: center;
    position: relative;
}
/* Podium colours drawn from the logo so 1st/2nd/3rd feel branded
   rather than generic gold/silver/bronze. */
.tgf-lb__podium-card.is-place-1 { border-color: var(--tgf-lb-accent-yellow); }  /* logo yellow */
.tgf-lb__podium-card.is-place-2 { border-color: var(--tgf-lb-accent-2); }       /* logo teal */
.tgf-lb__podium-card.is-place-3 { border-color: var(--tgf-lb-accent-warm); }    /* logo orange */
.tgf-lb__podium-rank {
    width: 44px; height: 44px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center; justify-content: center;
    font-weight: 800;
    font-size: 18px;
    color: #1d2327;
    margin-bottom: 10px;
    background: silver;
}
.is-place-1 .tgf-lb__podium-rank { background: var(--tgf-lb-accent-yellow); color: #1d2327; }
.is-place-2 .tgf-lb__podium-rank { background: var(--tgf-lb-accent-2);      color: #0d0908; }
/* Dark ink on the orange — white only reaches 1.9:1 against it. */
.is-place-3 .tgf-lb__podium-rank { background: var(--tgf-lb-accent-warm);   color: #1f1410; }
.tgf-lb__podium-name { font-weight: 800; font-size: 17px; margin-bottom: 6px; }
.tgf-lb__podium-stats {
    display: flex;
    gap: 12px;
    justify-content: center;
    color: var(--tgf-lb-muted);
    font-size: 13px;
}
.tgf-lb__podium-stats strong { color: var(--tgf-lb-text); }

.tgf-lb__count {
    margin-top: 12px;
    color: var(--tgf-lb-muted);
    font-size: 13px;
    text-align: center;
}

/* ---- Disclaimer + opt-out ---- */
.tgf-lb__disclaimer {
    margin: 4px 0 0;
    color: var(--tgf-lb-muted);
    font-size: 12px;
    text-align: center;
}
.tgf-lb__disclaimer a { color: var(--tgf-lb-accent-2); }

/* ---- Grading totals strip ---- */
.tgf-lb__totals {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    margin-bottom: 18px;
}
.tgf-lb__total-chip {
    background: #1d2127;
    border: 1px solid var(--tgf-lb-border);
    border-radius: 12px;
    padding: 10px 16px;
    min-width: 104px;
    text-align: center;
}
.tgf-lb__total-chip strong {
    display: block;
    font-size: 20px;
    font-weight: 800;
    color: var(--tgf-lb-text);
}
.tgf-lb__total-chip span {
    display: block;
    font-size: 11px;
    color: var(--tgf-lb-muted);
    margin-top: 2px;
    letter-spacing: .03em;
    text-transform: uppercase;
}
.tgf-lb__total-chip--primary { border-color: var(--tgf-lb-accent); }
.tgf-lb__total-chip--primary strong { color: var(--tgf-lb-accent); }

/* ---- Most graded cards: top-3 podium variant ---- */
.tgf-lb__podium--cards .tgf-lb__podium-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 8px;
}
.tgf-lb__podium-thumb {
    width: 104px;
    border-radius: 8px;
    box-shadow: 0 10px 28px rgba(0, 0, 0, .45);
    background: #1d2127;
}
.tgf-lb__podium--cards .tgf-lb__sub {
    display: block;
    font-size: 12px;
    color: var(--tgf-lb-muted);
}
.tgf-lb__podium--cards .tgf-lb__podium-stats {
    display: flex;
    align-items: center;
    gap: 10px;
}
.tgf-lb__podium--cards .tgf-lb__grades-btn { margin-top: 2px; }

/* ---- Most graded cards ---- */
.tgf-lb__card-cell {
    display: flex;
    align-items: center;
    gap: 10px;
}
.tgf-lb__card-thumb {
    width: 34px;
    height: 48px;
    object-fit: cover;
    border-radius: 4px;
    flex: none;
    background: #1d2127;
}
.tgf-lb__count-cell { font-size: 16px; }
.tgf-lb__col-count, .tgf-lb__col-actions { width: 110px; }
.tgf-lb__grades-btn {
    background: transparent;
    border: 1px solid var(--tgf-lb-border);
    color: var(--tgf-lb-text);
    border-radius: 999px;
    padding: 5px 12px;
    font-size: 12px;
    cursor: pointer;
    white-space: nowrap;
}
.tgf-lb__grades-btn:hover {
    border-color: var(--tgf-lb-accent);
    color: var(--tgf-lb-accent);
}

/* ---- Grade distribution modal ---- */
/* display:flex below would defeat the UA's [hidden]{display:none} — make
   hidden always win or the modal can never close. */
.tgf-lb-drawer[hidden],
.tgf-lb-drawer__overlay[hidden] { display: none !important; }
.tgf-lb-drawer__overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .55);
    z-index: 100000;
}
.tgf-lb-drawer {
    /* The modal lives on <body>, outside any .tgf-lb root — redeclare the
       brand tokens here or every var() inside resolves to nothing. */
    --tgf-lb-text:           #f4f5f7;
    --tgf-lb-muted:          rgba(244,245,247,0.65);
    --tgf-lb-accent:         #F15F51;
    --tgf-lb-accent-2:       #60C7CB;
    --tgf-lb-accent-warm:    #F8AA4A;
    --tgf-lb-accent-yellow:  #FBCC0A;
    --tgf-lb-bg:             rgba(255,255,255,0.04);
    --tgf-lb-border:         rgba(255,255,255,0.08);
    --tgf-lb-radius:         16px;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: min(900px, 94vw);
    max-height: 90vh;
    background: #14171c;
    color: var(--tgf-lb-text, #fff);
    z-index: 100001;
    border: 1px solid rgba(255, 255, 255, .12);
    border-radius: 16px;
    box-shadow: 0 24px 64px rgba(0, 0, 0, .55);
    display: flex;
    flex-direction: column;
    padding: 26px;
    overflow: hidden;   /* desktop fits; inner list scrolls only if it must */
}
/* Two columns on desktop: card art beside the grade breakdown, so the
   whole dialog fits on screen without a page-length scrollbar. */
.tgf-lb-drawer__layout {
    display: grid;
    grid-template-columns: minmax(240px, 320px) 1fr;
    gap: 26px;
    align-items: start;
    min-height: 0;
    overflow: hidden;
}
.tgf-lb-drawer__media { min-width: 0; }
.tgf-lb-drawer__main {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    max-height: calc(90vh - 52px);
}
.tgf-lb-drawer__chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 12px;
}
/* Selected company chip: GradeIt coral, same highlight as the totals strip. */
.tgf-lb-drawer .tgf-lb__chip.is-active {
    background: var(--tgf-lb-accent);
    border-color: var(--tgf-lb-accent);
    color: #fff;
}
.tgf-lb-drawer__header {
    border-bottom: 1px solid rgba(255, 255, 255, .12);
    padding: 0 0 14px;
    margin-bottom: 14px;
}
.tgf-lb-drawer__thumb {
    display: block;
    width: 100%;
    height: auto;
    object-fit: contain;
    border-radius: 10px;
    background: #1d2127;
    box-shadow: 0 14px 36px rgba(0, 0, 0, .5);
}
.tgf-lb-drawer__head-text { min-width: 0; padding-right: 42px; }
.tgf-lb-drawer__title {
    margin: 0 0 4px;
    font-size: 20px;
    line-height: 1.3;
    color: inherit;
    text-transform: none;
}
.tgf-lb-drawer__sub { margin: 0; font-size: 12px; color: rgba(255, 255, 255, .6); }
/* Armored against theme button styling — the modal lives on <body> where
   global theme button rules (teal bg, full width) would otherwise win. */
.tgf-lb-drawer .tgf-lb-drawer__close {
    position: absolute;
    top: 10px;
    right: 12px;
    width: 38px !important;
    height: 38px !important;
    min-width: 0 !important;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, .08) !important;
    border: 0 !important;
    border-radius: 50% !important;
    box-shadow: none !important;
    color: rgba(255, 255, 255, .8) !important;
    font-size: 22px;
    line-height: 1 !important;
    cursor: pointer;
    padding: 0 !important;
    margin: 0 !important;
    z-index: 1;
}
.tgf-lb-drawer .tgf-lb-drawer__close:hover {
    background: rgba(255, 255, 255, .18) !important;
    color: #fff !important;
}
.tgf-lb__chip-logo {
    width: 30px;
    height: 30px;
    padding: 3px;
    box-sizing: border-box;   /* padding inside the plate = whole logo visible */
    object-fit: contain;
    border-radius: 6px;
    background: #fff;
    flex: none;
    margin-right: 9px;
}
.tgf-lb-drawer__chips .tgf-lb__chip {
    display: inline-flex;
    align-items: center;
    font-size: 14px;
    padding: 7px 16px 7px 7px;
}
.tgf-lb-drawer__close:hover { color: #fff; }
.tgf-lb-drawer__body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    scrollbar-width: thin;
}
.tgf-lb-drawer__row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
    border-bottom: 1px solid rgba(255, 255, 255, .07);
}
.tgf-lb-drawer__co {
    flex: 1;
    font-size: 13px;
    font-weight: 600;
}
.tgf-lb-drawer__count {
    font-size: 14px;
    font-weight: 700;
    min-width: 42px;
    text-align: right;
}
.tgf-lb-drawer__loading { color: rgba(255, 255, 255, .6); font-size: 13px; }
.tgf-lb-drawer__footer {
    border-top: 1px solid rgba(255, 255, 255, .12);
    padding-top: 12px;
    margin-top: 12px;
    font-size: 12px;
    color: rgba(255, 255, 255, .6);
    text-align: center;
}
body.tgf-lb-drawer-open { overflow: hidden; }

@media (max-width: 720px) {
    .tgf-lb__podium { grid-template-columns: 1fr; }
    .tgf-lb__table-wrap { font-size: 13px; }
}

/* ---- Mobile: filter bars collapse behind one "Filters" button ---- */
.tgf-lb__filters-toggle,
.tgf-lb__filters-head { display: none; }

@media (max-width: 860px) {
    /* Modal stacks: art above the breakdown, page-scroll allowed. */
    .tgf-lb-drawer { padding: 20px; overflow-y: auto; }
    .tgf-lb-drawer__layout { grid-template-columns: 1fr; gap: 16px; }
    .tgf-lb-drawer__media { max-width: 240px; margin: 0 auto; }
    .tgf-lb-drawer__main { max-height: none; }
    .tgf-lb-drawer__body { overflow: visible; }

    .tgf-lb__filters-toggle {
        display: inline-flex;
        align-items: center;
        gap: 8px;
        background: var(--tgf-lb-bg, rgba(255,255,255,.05));
        border: 1px solid var(--tgf-lb-border, rgba(255,255,255,.12));
        color: var(--tgf-lb-text, #f4f5f7);
        border-radius: 999px;
        padding: 10px 20px;
        font: inherit;
        font-size: 14px;
        font-weight: 700;
        cursor: pointer;
        margin-bottom: 16px;
    }
    .tgf-lb__filters-toggle .tgf-lb__filters-count {
        background: var(--tgf-lb-accent, #F15F51);
        color: #fff;
        border-radius: 999px;
        font-size: 12px;
        padding: 1px 8px;
    }

    .tgf-lb__filters {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 100004;
        display: none;
        /* stats.css sets a margin on .tgf-stats .tgf-lb__filters — it would
           otherwise float the sheet off the bottom edge. */
        margin: 0 !important;
        max-height: 82vh;
        overflow-y: auto;
        background: #14171c;
        border: 0;
        border-top: 1px solid rgba(255, 255, 255, .12);
        border-radius: 18px 18px 0 0;
        padding: 0 16px 20px;
        box-shadow: 0 -16px 48px rgba(0, 0, 0, .5);
    }
    .tgf-lb__filters.is-open { display: block; }
    .tgf-lb__filters-head {
        display: flex;
        align-items: center;
        justify-content: space-between;
        position: sticky;
        top: 0;
        background: #14171c;
        padding: 16px 0 12px;
        margin-bottom: 4px;
        font-weight: 800;
        font-size: 16px;
        border-bottom: 1px solid rgba(255, 255, 255, .10);
    }
    .tgf-lb__filters-done {
        background: var(--tgf-lb-accent, #F15F51) !important;
        color: #fff !important;
        border: 0 !important;
        border-radius: 999px !important;
        padding: 8px 22px !important;
        font: inherit;
        font-weight: 700;
        cursor: pointer;
    }
    /* Each filter becomes a full-width row; its popover flows inline so it
       can never be clipped by the sheet. */
    .tgf-lb__filters .tgf-lb__filter { width: 100%; margin-top: 10px; }
    .tgf-lb__filters .tgf-lb__filter-trigger { width: 100%; justify-content: space-between; }
    .tgf-lb__filters .tgf-lb__filter-popover {
        position: static;
        width: 100%;
        min-width: 0;
        margin-top: 8px;
        box-shadow: none;
        transform: none;
    }
    .tgf-lb__filters .tgf-stats__table-toggle { width: 100%; margin: 14px 0 0; }

    .tgf-lb-filters-backdrop {
        position: fixed;
        inset: 0;
        z-index: 100003;
        background: rgba(0, 0, 0, .55);
    }
    body.tgf-lb-filters-open { overflow: hidden; }
}

/* "of which" pills beside a grader's 10 count (Black Label / Pristine 10s are
   a subset of that umbrella total, never additional to it). */
.tgf-lb__tens-sub {
    display: inline-block;
    margin-left: 6px;
    padding: 1px 7px;
    border-radius: 999px;
    font-size: 10px;
    font-weight: 800;
    letter-spacing: .02em;
    vertical-align: 1px;
    background: rgba(255, 255, 255, .10);
    color: var(--tgf-lb-text, #f4f5f7);
}
.tgf-lb__tens-sub.is-black-label { background: #0d0908; color: var(--tgf-lb-accent-yellow, #FBCC0A); }
.tgf-lb__tens-sub.is-pristine    { background: var(--tgf-lb-accent-yellow, #FBCC0A); color: #0d0908; }
