table.pg-table-tools {
    position: relative;
}

.pg-table-auto-scroll {
    overflow-x: auto;
}

.pg-table-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin: 0 0 8px;
    padding: 8px;
    border: 1px solid #d6dbe0;
    border-radius: 7px;
    background: #f8fafc;
    overflow: visible;
}

.pg-table-mode-label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: #475569;
    font-size: 12px;
    font-weight: 700;
}

.pg-table-mode,
.pg-builder-row select {
    width: auto !important;
    min-width: 130px;
    padding: 6px 8px !important;
    border-radius: 6px !important;
}

.pg-table-global-query {
    display: none;
    flex: 1 1 280px;
    min-width: 220px;
    max-width: none !important;
    padding: 7px 9px !important;
    border: 1px solid #cbd5e1 !important;
    border-radius: 6px !important;
}

.pg-table-toolbar[data-mode="sql"] .pg-table-global-query,
.pg-table-toolbar[data-mode="natural"] .pg-table-global-query {
    display: block;
}

table[data-pg-filter-mode="sql"] .pg-table-filter-row,
table[data-pg-filter-mode="builder"] .pg-table-filter-row {
    display: none;
}

.pg-table-button {
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    padding: 7px 9px;
    background: #fff;
    color: #334155;
    font-weight: 700;
    cursor: pointer;
}

.pg-table-button:hover {
    background: #e8f0f6;
}

.pg-add-condition {
    display: none;
}

.pg-mobile-filter-toggle {
    display: none;
}

.pg-mobile-details-toggle {
    display: none;
}

.pg-table-toolbar[data-mode="builder"] .pg-add-condition {
    display: inline-block;
}

.pg-builder-panel {
    display: none;
    flex: 1 0 100%;
    gap: 6px;
}

.pg-table-toolbar[data-mode="builder"] .pg-builder-panel {
    display: grid;
}

.pg-builder-row {
    display: grid;
    grid-template-columns: 82px minmax(130px, 1fr) minmax(130px, 1fr) minmax(140px, 1fr) auto;
    gap: 6px;
    align-items: center;
}

.pg-builder-row input {
    width: 100%;
    max-width: none !important;
    padding: 7px 8px !important;
    border: 1px solid #cbd5e1 !important;
    border-radius: 6px !important;
}

.pg-filter-legend {
    position: relative;
    display: inline-block;
    color: #075985;
    font-size: 12px;
    font-weight: 800;
    cursor: help;
    outline: none;
}

.pg-filter-legend-label {
    border-bottom: 1px dotted currentColor;
}

.pg-filter-legend-popup {
    display: none;
    position: absolute;
    z-index: 100;
    right: 0;
    top: calc(100% + 7px);
    width: min(390px, 84vw);
    padding: 12px;
    border: 1px solid #94a3b8;
    border-radius: 7px;
    background: #fff;
    color: #1e293b;
    box-shadow: 0 12px 28px rgba(15, 23, 42, .18);
    font-size: 12px;
    font-weight: 400;
    line-height: 1.7;
}

.pg-filter-legend:hover .pg-filter-legend-popup,
.pg-filter-legend:focus-within .pg-filter-legend-popup,
.pg-filter-legend:focus .pg-filter-legend-popup {
    display: block;
}

.pg-filter-legend-popup code {
    padding: 1px 4px;
    border-radius: 4px;
    background: #eef2f7;
}

.pg-filter-legend-popup a {
    color: #0369a1;
    font-weight: 800;
}

.pg-table-error {
    flex: 1 0 100%;
    color: #b91c1c;
    font-size: 12px;
    font-weight: 700;
}

table.pg-table-tools th.pg-sortable {
    cursor: pointer;
    user-select: none;
    padding-right: 26px;
    position: relative;
}

table.pg-table-tools th.pg-sortable:hover {
    background: #e2e8f0;
}

.pg-sort-indicator {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    color: #64748b;
    font-size: 11px;
    line-height: 1;
}

th.pg-sort-asc .pg-sort-indicator,
th.pg-sort-desc .pg-sort-indicator {
    color: var(--primary, #003256);
}

.pg-table-filter-row th {
    padding: 5px 4px;
    background: #f8fafc;
    vertical-align: top;
}

.pg-table-filter {
    box-sizing: border-box;
    display: block;
    width: 100%;
    min-width: 74px;
    max-width: none !important;
    padding: 6px 7px !important;
    border: 1px solid #cbd5e1 !important;
    border-radius: 6px !important;
    background: #fff !important;
    color: var(--text, #102030);
    font: inherit;
    font-size: 12px !important;
    font-weight: 400;
}

.pg-table-filter:focus {
    outline: 2px solid #7dd3fc;
    border-color: var(--accent, #00a9ff) !important;
}

.pg-table-filter-active {
    background: #eff6ff !important;
    border-color: #60a5fa !important;
}

.pg-table-no-results td {
    text-align: center;
    color: var(--muted, #6b7280);
    font-style: italic;
    background: #f8fafc;
}

@media (max-width: 720px) {
    .pg-table-filter {
        min-width: 88px;
    }

    .pg-table-toolbar {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto auto;
        align-items: center;
        gap: 6px;
        padding: 6px;
    }

    .pg-table-mode-label {
        min-width: 0;
        font-size: 0;
    }

    .pg-table-mode,
    .pg-table-global-query {
        width: 100% !important;
        min-width: 0;
        min-height: 34px;
        font-size: 12px;
    }

    .pg-table-button {
        min-height: 34px;
        padding: 5px 7px;
        font-size: 11px;
    }

    .pg-filter-legend,
    .pg-table-error,
    .pg-builder-panel,
    .pg-table-global-query {
        grid-column: 1 / -1;
    }

    .pg-builder-row {
        grid-template-columns: 1fr;
    }

    .pg-mobile-filter-toggle {
        display: inline-block;
    }

    .pg-table-toolbar[data-mode="sql"] .pg-mobile-filter-toggle,
    .pg-table-toolbar[data-mode="builder"] .pg-mobile-filter-toggle {
        display: none;
    }

    .pg-mobile-card-scroll,
    .pg-mobile-card-scroll.table-scroll,
    .pg-mobile-card-scroll.pg-table-auto-scroll {
        overflow: visible !important;
    }

    table.pg-mobile-compact {
        display: block;
        width: 100%;
        background: transparent;
    }

    table.pg-mobile-compact thead {
        display: block;
    }

    table.pg-mobile-compact thead tr:not(.pg-table-filter-row) {
        display: flex;
        flex-wrap: nowrap;
        gap: 5px;
        overflow-x: auto;
        padding: 5px;
        border: 1px solid #d6dbe0;
        border-radius: 7px;
        background: #f8fafc;
    }

    table.pg-mobile-compact thead tr:not(.pg-table-filter-row) th {
        display: inline-flex;
        width: auto !important;
        flex: 0 0 auto;
        align-items: center;
        min-height: 32px;
        padding: 6px 23px 6px 8px;
        border: 1px solid #cbd5e1;
        border-radius: 6px;
        background: #fff;
        font-size: 12px;
        white-space: nowrap;
    }

    table.pg-mobile-compact .pg-table-filter-row {
        display: none;
        grid-template-columns: 1fr;
        gap: 6px;
        padding: 8px;
        border: 1px solid #d6dbe0;
        border-top: 0;
        background: #f8fafc;
    }

    table.pg-mobile-compact.pg-mobile-filters-open .pg-table-filter-row {
        display: grid;
    }

    table.pg-mobile-compact .pg-table-filter-row th {
        display: block;
        width: 100% !important;
        padding: 0;
        border: 0;
    }

    table.pg-mobile-compact .pg-table-filter {
        min-width: 0;
        width: 100%;
    }

    table.pg-mobile-compact tbody {
        display: grid;
        gap: 7px;
        margin-top: 7px;
    }

    table.pg-mobile-compact tbody tr {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0 8px;
        padding: 6px 9px;
        border: 1px solid #d6dbe0;
        border-radius: 8px;
        background: #fff;
        box-shadow: 0 2px 7px rgba(15, 23, 42, .05);
    }

    table.pg-mobile-compact tbody td {
        width: 100% !important;
        min-width: 0 !important;
        white-space: normal !important;
        overflow-wrap: anywhere;
        text-align: left !important;
    }

    table.pg-mobile-compact tbody td.pg-mobile-primary {
        display: block;
        width: 100% !important;
        min-height: 0 !important;
        padding: 6px 4px;
        border-bottom: 1px solid #e5e7eb;
        font-size: 14px;
    }

    table.pg-mobile-compact tbody td.pg-mobile-primary::before {
        display: block;
        margin-bottom: 2px;
        content: attr(data-mobile-label);
        color: #64748b;
        font-size: 10px;
        font-weight: 800;
        line-height: 1.2;
        text-transform: uppercase;
    }

    table.pg-mobile-compact tbody td.pg-mobile-secondary {
        display: none;
        grid-column: 1 / -1;
        grid-template-columns: minmax(92px, 30%) minmax(0, 1fr);
        gap: 8px;
        align-items: start;
        padding: 7px 4px;
        border-bottom: 1px solid #e5e7eb;
    }

    table.pg-mobile-compact tbody tr.pg-mobile-expanded td.pg-mobile-secondary {
        display: grid;
    }

    table.pg-mobile-compact tbody td.pg-mobile-secondary::before {
        content: attr(data-mobile-label);
        color: #64748b;
        font-size: 10px;
        font-weight: 800;
        line-height: 1.35;
        text-transform: uppercase;
    }

    table.pg-mobile-compact tbody td.pg-mobile-details-toggle {
        display: block;
        grid-column: 1 / -1;
        padding: 6px 4px 2px;
        border: 0;
        text-align: right !important;
    }

    table.pg-mobile-compact tbody td.pg-mobile-details-toggle button {
        min-height: 32px;
        padding: 5px 9px;
        font-size: 12px;
    }

    table.pg-mobile-compact tbody td input,
    table.pg-mobile-compact tbody td select,
    table.pg-mobile-compact tbody td textarea {
        width: 100% !important;
        max-width: none !important;
    }

    table.pg-mobile-compact tbody td .button,
    table.pg-mobile-compact tbody td button {
        white-space: normal;
    }

    table.pg-mobile-compact .pg-table-no-results {
        display: block;
    }

    table.pg-mobile-compact .pg-table-no-results td {
        display: block;
        padding: 12px;
    }

    table.pg-mobile-match-table tbody tr {
        grid-template-columns: minmax(0, 1fr) 70px minmax(0, 1fr);
        align-items: center;
        padding: 7px 8px;
    }

    table.pg-mobile-match-table tbody td.pg-mobile-primary::before {
        display: none;
    }

    table.pg-mobile-match-table tbody td.pg-match-meta,
    table.pg-mobile-match-table tbody td.pg-match-date,
    table.pg-mobile-match-table tbody td.pg-match-stage {
        min-height: 0 !important;
        padding: 3px 4px;
        border-bottom: 1px solid #eef2f7;
        color: #64748b;
        font-size: 11px;
    }

    table.pg-mobile-match-table tbody td.pg-match-meta {
        grid-column: 1;
        grid-row: 1;
        font-weight: 800;
    }

    table.pg-mobile-match-table tbody td.pg-match-date {
        grid-column: 2 / 4;
        grid-row: 1;
        text-align: right !important;
    }

    table.pg-mobile-match-table tbody td.pg-match-stage {
        display: block;
        grid-column: 1 / -1;
        grid-row: 3;
        padding: 3px 4px;
        border-top: 1px solid #eef2f7;
        border-bottom: 0;
        text-align: center !important;
        font-size: 10px;
        text-transform: uppercase;
    }

    table.pg-mobile-match-table tbody td.pg-match-home,
    table.pg-mobile-match-table tbody td.pg-match-away {
        grid-row: 2;
        padding: 9px 4px;
        border: 0;
        font-size: 13px;
        font-weight: 700;
    }

    table.pg-mobile-match-table tbody td.pg-match-home {
        grid-column: 1;
    }

    table.pg-mobile-match-table tbody td.pg-match-away {
        grid-column: 3;
    }

    table.pg-mobile-match-table tbody td.pg-match-away .team-cell {
        justify-content: flex-end;
        text-align: right;
    }

    table.pg-mobile-match-table tbody td.pg-match-score {
        grid-column: 2;
        grid-row: 2;
        padding: 5px 2px;
        border: 0;
        text-align: center !important;
        font-weight: 900;
    }

    table.pg-mobile-match-table .team-cell {
        min-width: 0;
        gap: 5px;
        white-space: normal;
    }

    table.pg-mobile-match-table .team-cell span:last-child {
        min-width: 0;
        overflow-wrap: normal;
        word-break: normal;
    }

    table.pg-mobile-match-table .team-code {
        display: none;
    }

    table.pg-mobile-match-table .team-flag {
        width: 22px;
        height: 16px;
    }

    table.pg-mobile-match-table .time-chip {
        margin: 2px 2px 0 0;
        padding: 2px 5px;
        font-size: 10px;
    }

    table.pg-mobile-match-results .result-score-cell {
        min-width: 0;
    }

    table.pg-mobile-match-results .result-score-box {
        grid-template-columns: 30px 8px 30px;
        gap: 1px;
    }

    table.pg-mobile-match-results .result-score-input {
        width: 30px !important;
        min-height: 36px;
        padding: 4px 2px !important;
    }

    table.pg-mobile-match-results .readonly-value {
        min-width: 0;
        font-size: 16px;
    }

    table.pg-mobile-match-prediction tbody tr {
        grid-template-columns: minmax(0, 1fr) 42px 42px minmax(0, 1fr);
    }

    table.pg-mobile-match-prediction tbody td.pg-match-meta {
        grid-column: 1 / 2;
    }

    table.pg-mobile-match-prediction tbody td.pg-match-home {
        grid-column: 1;
        grid-row: 2;
    }

    table.pg-mobile-match-prediction tbody td.pg-match-score-home,
    table.pg-mobile-match-prediction tbody td.pg-match-score-away {
        grid-row: 2;
        padding: 5px 2px;
        border: 0;
    }

    table.pg-mobile-match-prediction tbody td.pg-match-score-home {
        grid-column: 2;
    }

    table.pg-mobile-match-prediction tbody td.pg-match-score-away {
        grid-column: 3;
    }

    table.pg-mobile-match-prediction tbody td.pg-match-away {
        grid-column: 4;
        grid-row: 2;
    }

    table.pg-mobile-match-prediction .score-input {
        width: 38px !important;
        min-height: 38px;
        padding: 4px 2px !important;
    }

    table.pg-mobile-match-prediction tbody td.pg-match-score-home::after {
        content: ":";
        position: absolute;
        margin: 10px 0 0 4px;
        color: #64748b;
        font-weight: 900;
    }

    table.pg-mobile-match-knockout .score-pair {
        gap: 3px;
    }

    table.pg-mobile-match-knockout .score-input {
        width: 29px !important;
        min-height: 36px;
        padding: 4px 2px !important;
    }

    table.pg-mobile-match-comparison tbody tr {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    table.pg-mobile-match-comparison tbody td.pg-match-meta {
        grid-column: 1 / -1;
        grid-row: 1;
    }

    table.pg-mobile-match-comparison tbody td.pg-match-home,
    table.pg-mobile-match-comparison tbody td.pg-match-away {
        grid-row: 2;
        min-height: 48px !important;
    }

    table.pg-mobile-match-comparison tbody td.pg-match-home {
        grid-column: 1 / 2;
    }

    table.pg-mobile-match-comparison tbody td.pg-match-away {
        grid-column: 2 / 4;
    }

    table.pg-mobile-match-comparison tbody td.pg-match-predicted,
    table.pg-mobile-match-comparison tbody td.pg-match-actual,
    table.pg-mobile-match-comparison tbody td.pg-match-points {
        display: block;
        grid-row: 3;
        min-height: 58px !important;
        padding: 7px 4px;
        border: 1px solid #dbe3eb;
        background: #f8fafc;
        text-align: center !important;
        font-size: 16px;
        font-weight: 900;
    }

    table.pg-mobile-match-comparison tbody td.pg-match-predicted {
        grid-column: 1;
        border-radius: 7px 0 0 7px;
    }

    table.pg-mobile-match-comparison tbody td.pg-match-actual {
        grid-column: 2;
    }

    table.pg-mobile-match-comparison tbody td.pg-match-points {
        grid-column: 3;
        border-radius: 0 7px 7px 0;
        color: var(--primary, #003256);
    }

    table.pg-mobile-match-comparison tbody td.pg-match-predicted::before,
    table.pg-mobile-match-comparison tbody td.pg-match-actual::before,
    table.pg-mobile-match-comparison tbody td.pg-match-points::before {
        display: block;
        margin-bottom: 3px;
        content: attr(data-mobile-label);
        color: #64748b;
        font-size: 9px;
        font-weight: 800;
        line-height: 1.15;
        text-transform: uppercase;
    }

    table.pg-mobile-match-comparison .team-fifa-code {
        display: none;
    }

    table.pg-mobile-match-comparison .points-cell {
        cursor: pointer;
        touch-action: manipulation;
    }

    table.pg-mobile-match-table tbody td.pg-mobile-details-toggle {
        padding-top: 3px;
    }

    table.pg-mobile-match-table tbody td.pg-mobile-details-toggle button {
        border: 0;
        background: #eef2f7;
        color: var(--primary, #003256);
    }
}
