﻿/* =========================================================
   GRID / DOMINO TABLES (Leaders + Tournament + Stats)
   Cleaned: one consistent stats block, no duplicates.
   ========================================================= */

/* ========================================================= VARIABLES ========================================================= */

:root {
    --teamnum-w: 44px;
    --team-w: 140px;
    --team-min: 100px;
    --total-w: 64px;
    --bonus-w: 64px;
    --grid-font: 15px;
    --cell-font: 14px;
    /* default domino column width (leaders/tournament) */
    --domino-w: 30px;
}

/* ========================= TABLE WRAP ========================= */

.table-wrap {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 10px;
}

/* ========================= TABLE BASE ========================= */

table.grid {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
    font-size: var(--grid-font);
    border-bottom: 1px solid var(--line);
}

    table.grid.grid-wide {
        min-width: 900px;
    }

/* colgroup widths */

.col-teamnum {
    width: var(--teamnum-w);
}

.col-team {
    width: var(--team-w);
}

.col-total {
    width: var(--total-w);
}

/* bonus column */
.col-bonus {
    width: var(--bonus-w);
}

/* domino/task columns (everything except sticky №/team/total/bonus) */
table.grid col:not(.col-teamnum):not(.col-team):not(.col-total):not(.col-bonus) {
    width: var(--domino-w);
}

/* ========================= CELLS (base) ========================= */

table.grid th,
table.grid td {
    padding: 6px 6px;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    border-bottom: 1px solid var(--line);
}

table.grid th {
    background: #fafbff;
    font-weight: 800;
}

table.grid td {
    background: #fff;
    font-weight: 600;
}

/* ========================= HEADER (panel) ========================= */

.panel-title {
    padding: 10px 12px;
    border-bottom: 1px solid var(--line);
}

.panel-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
}

.panel-title-text {
    font-weight: 800;
    font-size: 16px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    flex: 1 1 auto;
}

.header-action-panel {
    display: flex;
    gap: 8px;
}

.filter-counter {
    color: #666;
    font-weight: 400;
    font-size: 13px;
}

.filter-icon {
    cursor: pointer;
    font-size: 16px;
    user-select: none;
}

/* ========================= COLUMNS (leaders/tournament) ========================= */

.teamNum {
    width: var(--teamnum-w);
    min-width: var(--teamnum-w);
    text-align: center;
}

.team {
    width: var(--team-w);
    min-width: var(--team-min);
    text-align: left;
}

.total {
    width: var(--total-w);
    min-width: var(--total-w);
    text-align: center;
}

/* bonus */
.bonus {
    width: var(--bonus-w);
    min-width: var(--bonus-w);
    text-align: center;
}

/* ========================= TEAM NAME (2 lines) ========================= */

.team-name {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    white-space: normal;
    word-break: break-word;
    line-height: 1.15;
    overflow: hidden;
}

/* ========================= NUMBERS: remove ellipsis (global) ========================= */

table.grid td:not(.team),
table.grid th:not(.team) {
    text-overflow: clip;
}

/* ========================= DOMINO CELLS (leaders/tournament) ========================= */

.cell {
    border-radius: 6px;
    font-weight: 800;
    padding: 2px;
    font-size: var(--cell-font);
    line-height: 1.05;
    white-space: nowrap;
    overflow: visible;
    text-overflow: clip;
}

    .cell.ok {
        background: var(--ok);
    }

    .cell.ok.appeal-ok {
        background: #2f8f55;
        color: #fff;
    }

    .cell.zero {
        background: var(--zero);
    }

    .cell.empty {
        background: var(--empty);
    }

    .cell.pending {
        background: #fff3a6;
    }

    .cell.fail {
        background: #f2b0b0;
    }

    .cell.wait {
        background: #e9f7ea;
        color: #1f9d55;
        font-weight: 900;
    }

    .cell.appeal {
        background: #dfe9ff;
        color: #1f3a7a;
        font-weight: 900;
    }

    .cell.question {
        background: #fef4d6;
        color: #7a4b00;
        font-weight: 900;
    }

    .cell.appeal-fail {
        box-shadow: 0 0 0 2px #c62828 inset;
    }

    .cell.question-answered {
        box-shadow: 0 0 0 2px #d9a400 inset;
    }

/* ========================= STICKY COLUMNS № + Team + Total (leaders/tournament) ========================= */

/* № */
table.grid th.teamNum,
table.grid td.teamNum {
    position: sticky;
    left: 0;
    z-index: 6;
    background: #fff;
}

/* Team */
table.grid th.team,
table.grid td.team {
    position: sticky;
    left: var(--teamnum-w);
    z-index: 5;
    background: #fff;
    box-shadow: 2px 0 0 rgba(0,0,0,0.06);
}

/* Total */
table.grid th.total,
table.grid td.total {
    position: sticky;
    left: calc(var(--teamnum-w) + var(--team-w));
    z-index: 4;
    background: #fff;
    box-shadow: 2px 0 0 rgba(0,0,0,0.06);
}

/* Bonus */
table.grid th.bonus,
table.grid td.bonus {
    position: sticky;
    left: calc(var(--teamnum-w) + var(--team-w) + var(--total-w));
    z-index: 3;
    background: #fff;
    box-shadow: 2px 0 0 rgba(0,0,0,0.06);
}

/* sticky headers on these columns */
table.grid thead th.teamNum,
table.grid thead th.team,
table.grid thead th.total,
table.grid thead th.bonus {
    background: #fafbff;
    z-index: 7;
}

/* ========================= DOMINO HEADER KEY ========================= */

.domino-key {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    line-height: 1;
    gap: 1px;
}

/* ========================= MODAL (min) ========================= */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.35);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    padding: 16px;
}

.modal-overlay[hidden] {
    display: none !important;
}

.modal {
    width: min(720px, 95vw);
    max-height: 85vh;
    overflow: auto;
    background: #fff;
    border-radius: 12px;
    padding: 14px 14px 16px;
}

/* ========================= CONTEXT MENU (appeal) ========================= */

.ctx-menu {
    position: fixed;
    z-index: 10000;
    background: #fff;
    border: 1px solid rgba(0,0,0,.12);
    border-radius: 10px;
    padding: 6px;
    box-shadow: 0 8px 20px rgba(0,0,0,.18);
}

.ctx-menu button {
    border: 0;
    background: #fff;
    padding: 6px 10px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
}

.ctx-menu button:hover {
    background: #f2f4f8;
}

/* ========================= APPEAL MODAL ========================= */

.appeal-modal .appeal-info {
    display: grid;
    gap: 6px;
    margin: 8px 0 10px;
    font-size: 14px;
}

.appeal-modal .appeal-line {
    display: grid;
    grid-template-columns: 110px minmax(0, 1fr);
    gap: 10px;
    align-items: start;
}

.appeal-modal .label {
    color: #666;
    font-weight: 600;
}

.appeal-label {
    display: block;
    font-size: 13px;
    color: #666;
    margin: 6px 0 6px;
}

.appeal-textarea {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    display: block;
    min-width: 0;
    min-height: 90px;
    resize: vertical;

}

.appeal-error {
    color: #b00;
    font-size: 13px;
    margin-top: 6px;
}



/* ========================= 🎥 PROJECTOR 1024×768 (leaders/tournament) ========================= */

@media (max-width: 1040px) and (max-height: 800px) {
    :root {
        --teamnum-w: 40px;
        --team-w: 140px;
        --team-min: 100px;
        --total-w: 56px;
        --bonus-w: 56px;
        --grid-font: 12px;
        --cell-font: 9px;
        --domino-w: 24px;
    }

    table.grid th,
    table.grid td {
        padding: 2px 2px;
    }

    .cell {
        padding: 2px;
    }
}

/* =========================================================
   STATS TABLE (only)
   Requires markup:
     <table class="grid stats-grid"> ... colgroup uses:
     <col class="stats-col-label" />
     <col class="stats-col-attempt" />
   ========================================================= */

/* Scroll container for stats */
.stats-wrap {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Stats table: let columns size by content, never clip digits */
table.grid.stats-grid {
    width: max-content; /* grow to fit content */
    min-width: 100%; /* but at least full container width */
    table-layout: auto; /* IMPORTANT: allow content-based sizing */
    position: relative;
    isolation: isolate;
    /* Perfect visual column alignment for numbers */
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum" 1;
    line-height: 1.1;
}

/* col widths for stats */
.stats-grid col.stats-col-label {
    width: 100px;
}

/* attempts columns: no fixed width (content decides), only minimum */
.stats-grid col.stats-col-attempt {
    width: auto;
    min-width: 27px;
}

/* Make first column always visible and never clipped */
.stats-grid th.stats-col-label,
.stats-grid td.stats-col-label {
    position: sticky;
    left: 0;
    z-index: 50;
    background: #fff;
    text-align: left;
    font-weight: 800;
    white-space: nowrap;
    overflow: visible; /* never hide label text */
    text-overflow: clip;
    box-shadow: 2px 0 0 rgba(0,0,0,0.06);
}

.stats-grid thead th.stats-col-label {
    background: #fafbff;
}

/* Ensure header/body paddings match exactly in stats */
table.grid.stats-grid th,
table.grid.stats-grid td {
    padding: 2px 2px;
    vertical-align: middle;
    text-overflow: clip;
}

/* Attempts cells: show full numbers, never clip */
.stats-grid th.attempt,
.stats-grid td.attempt {
    white-space: nowrap;
    overflow: visible; /* never hide digits */
    text-overflow: clip;
    text-align: center;
    font-weight: 400;
    position: relative;
    z-index: 1; /* stays under sticky label */
}

    /* Domino header: stabilize height so it doesn't "float" */
    .stats-grid th.attempt .domino-key {
        min-height: 27px;
    }

/* Headers above digits can be slightly bolder if desired */
.stats-grid thead th.attempt {
    font-weight: 600;
}

/* projector / small screen stats tuning */
@media (max-width: 1040px) and (max-height: 800px) {
    table.grid.stats-grid {
        font-size: 10px;
    }

    .stats-grid col.stats-col-label {
        width: 100px;
    }

    .stats-grid col.stats-col-attempt {
        min-width: 27px;
    }

    table.grid.stats-grid th,
    table.grid.stats-grid td {
        padding: 2px 2px;
    }
}

/* very small width stats tuning */
@media (max-width: 640px) {
    .stats-grid col.stats-col-label {
        width: 100px;
    }

    .stats-grid col.stats-col-attempt {
        min-width: 26px;
        font-size: 8px;
    }
}

/* ========================= MOBILE (leaders/tournament) ========================= */

@media (max-width: 640px) {
    :root {
        --team-w: 140px;
        --team-min: 100px;
        --domino-w: 24px;
    }

    .panel-title-text {
        font-size: 14px;
    }

    .header-action-panel--mobile-hidden {
        display: none;
    }

    table.grid {
        width: max(100%, 680px);
    }
}


