/*
 * Copyright (c) 2026 Write Words - Make Magic, LLC. All rights reserved.
 * SPDX-License-Identifier: LicenseRef-Proprietary
 */

.scores-widget {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 24px;
    max-width: 960px;
    width: 100%;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.05), 0 8px 10px -6px rgba(0, 0, 0, 0.01);
}

.controls-row {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.controls-row .search-input-container {
    flex: 1;
    min-width: 220px;
}

select.team-dropdown {
    padding: 11px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 500;
    outline: none;
    background: var(--bg-card);
    color: var(--text);
    cursor: pointer;
    min-width: 180px;
    transition: border-color 0.15s, box-shadow 0.15s;
}

select.team-dropdown:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

/* Stats & Teams Grid */
.teams-grid {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.team-card {
    position: relative;
    background: var(--bg-sub);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    transition: box-shadow 0.15s, border-color 0.15s;
    isolation: isolate;
}

.team-card:hover {
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.08);
}

/* Team Body Layout */
.team-body {
    display: flex;
    align-items: stretch;
    position: relative;
    z-index: 1;
}

.team-logo-side {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    width: clamp(180px, 24vw, 270px);
    padding: 20px 16px;
    background: var(--bg-card);
    border-right: 1px solid var(--border);
    box-sizing: border-box;
}

.team-side-logo {
    width: 100%;
    max-width: clamp(150px, 21vw, 238px);
    max-height: 300px;
    object-fit: contain;
    border-radius: 8px;
    transition: transform 0.2s ease, filter 0.2s ease;
    filter: drop-shadow(0 3px 8px rgba(0, 0, 0, 0.1));
}

.team-card:hover .team-side-logo {
    transform: scale(1.04);
}

/* Header logo for small screens (hidden by default on wide desktop) */
.team-header-logo {
    display: none;
    height: 64px;
    max-height: 64px;
    max-width: 120px;
    object-fit: contain;
    border-radius: 6px;
    filter: drop-shadow(0 2px 5px rgba(0, 0, 0, 0.12));
    flex-shrink: 0;
}

.table-responsive {
    position: relative;
    z-index: 1;
    width: 100%;
    flex: 1;
    min-width: 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.team-header {
    position: relative;
    z-index: 1;
    padding: 14px 18px;
    background: var(--btn-secondary-bg);
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.team-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-strong);
    margin: 0;
}

.team-totals {
    display: flex;
    gap: 12px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
}

.team-totals span strong {
    color: var(--text-strong);
}

.scores-table {
    width: 100%;
    table-layout: fixed;
    border-collapse: collapse;
    font-size: 0.9rem;
    text-align: left;
}

.scores-table th {
    background: var(--table-header-bg);
    padding: 8px 8px;
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    border-bottom: 1px solid var(--border);
}

.scores-table td {
    padding: 8px 8px;
    border-bottom: 1px solid var(--border);
    color: var(--text);
    font-size: 1.4em;
}

.col-rank {
    width: 48px;
    color: var(--text-muted);
    font-weight: 600;
}

.col-player {
    width: auto;
    text-align: left;
}

.col-pts {
    width: clamp(45px, 5vw, 65px);
    padding-right: 18px;
}

td.col-pts {
    color: #38bdf8;
    font-weight: 700;
}

.col-w {
    width: clamp(45px, 5vw, 65px);
    text-align: center;
}

td.col-w {
    color: #4ade80;
    font-weight: 600;
}

.col-l {
    width: clamp(45px, 5vw, 65px);
}

td.col-l {
    color: #f87171;
    font-weight: 600;
}

.col-swp {
    width: clamp(45px, 5vw, 65px);
}

td.col-swp {
    color: #fbbf24;
    font-weight: 600;
}

.scores-table tbody tr:last-child td {
    border-bottom: none;
}

.scores-table tbody tr:hover {
    background: var(--table-row-hover);
}

.scores-table tbody tr.highlighted-row {
    background: var(--primary-light);
    box-shadow: inset 3px 0 0 var(--primary);
}

.scores-table tbody tr.highlighted-row:hover {
    background: var(--primary-light);
    filter: brightness(1.03);
}

.player-name {
    font-weight: 600;
    color: var(--text-strong);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: block;
}

.player-name.highlighted-player-name {
    color: var(--primary);
    font-weight: 700;
}

.points-col {
    font-weight: 700;
    color: var(--primary);
}

.num-cell {
    text-align: center;
    white-space: nowrap;
}

.num-header {
    text-align: center;
    white-space: nowrap;
}

/* .num-header .col-l {
    margin-right: 2px;
} */



.loading-state,
.empty-state {
    padding: 32px 16px;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.95rem;
    font-weight: 600;
}

.error-message {
    color: #ef4444;
}

/* Team Score Camera and Image Action Buttons (Visible when Ctrl is active) */
.team-title-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.team-actions-group {
    display: none;
    flex-direction: row;
    gap: 6px;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

body.ctrl-down .team-actions-group {
    display: inline-flex;
}

.btn-team-action {
    display: inline-flex;
    width: 26px;
    height: 26px;
    padding: 0;
    background: var(--bg-card, rgba(255, 255, 255, 0.08));
    border: 1px solid var(--border);
    color: var(--text-muted);
    border-radius: 5px;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.15s ease;
    box-sizing: border-box;
    flex-shrink: 0;
}

.btn-team-action:hover {
    background: var(--primary, #3b82f6);
    border-color: var(--primary, #3b82f6);
    color: #ffffff;
    transform: translateY(-1px);
}

.btn-team-action:active {
    transform: scale(0.95);
}

/* All Teams Gallery Banner (Centered directly above the first team card) */
.all-teams-gallery-banner {
    display: none;
    width: 100%;
    justify-content: center;
    align-items: center;
    margin-bottom: 16px;
}

body.ctrl-down .all-teams-gallery-banner {
    display: flex;
}

.btn-all-teams-gallery {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 7px 16px;
    background: var(--bg-surface, #1e293b);
    border: 1px solid var(--border, rgba(255, 255, 255, 0.15));
    border-radius: 8px;
    color: var(--text-main, #f8fafc);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    transition: all 0.15s ease;
}

.btn-all-teams-gallery:hover {
    background: var(--primary, #3b82f6);
    border-color: var(--primary, #3b82f6);
    color: #ffffff;
    transform: translateY(-1px);
    box-shadow: 0 4px 14px rgba(59, 130, 246, 0.3);
}

/* Standalone Image Viewer & Gallery Modes */
.image-viewer-container {
    width: 100%;
    max-width: 1300px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
    align-items: center;
    box-sizing: border-box;
}

.image-viewer-toolbar {
    width: 100%;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-surface, #1e293b);
    border: 1px solid var(--border, rgba(255, 255, 255, 0.1));
    border-radius: 12px;
    padding: 12px 18px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
    flex-wrap: wrap;
    gap: 10px;
}

.image-viewer-toolbar h4 {
    margin: 0;
    font-size: 1.05rem;
    color: var(--text-main, #f8fafc);
    font-weight: 600;
    word-break: break-word;
}

.image-viewer-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.btn-viewer-action {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    background: var(--bg-secondary, rgba(255, 255, 255, 0.08));
    border: 1px solid var(--border, rgba(255, 255, 255, 0.12));
    border-radius: 8px;
    color: var(--text-main, #f8fafc);
    font-size: 0.88rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.15s ease;
}

.btn-viewer-action:hover {
    background: var(--primary, #3b82f6);
    border-color: var(--primary, #3b82f6);
    color: #ffffff;
    transform: translateY(-1px);
}

.btn-viewer-primary {
    background: var(--primary, #3b82f6);
    border-color: var(--primary, #3b82f6);
    color: #ffffff;
}

.btn-viewer-primary:hover {
    background: #2563eb;
    border-color: #2563eb;
}

.image-card-display {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    display: flex;
    justify-content: center;
    align-items: center;
    background: rgba(10, 15, 29, 0.6);
    border: 1px solid var(--border, rgba(255, 255, 255, 0.08));
    border-radius: 16px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
    overflow: hidden;
}

.image-card-display canvas,
.image-card-display img {
    max-width: 100%;
    height: auto;
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    display: block;
}

/* Gallery Grid View */
.gallery-grid {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 480px), 1fr));
    gap: 20px;
}

.gallery-card-item {
    background: var(--bg-surface, #1e293b);
    border: 1px solid var(--border, rgba(255, 255, 255, 0.1));
    border-radius: 14px;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.2);
    transition: transform 0.15s ease, border-color 0.15s ease;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
    overflow: hidden;
}

.gallery-card-item:hover {
    border-color: var(--primary, #3b82f6);
    transform: translateY(-2px);
}

.gallery-card-preview {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    border-radius: 10px;
    overflow: hidden;
    background: #0a0f1d;
    display: flex;
    justify-content: center;
    align-items: center;
}

.gallery-card-preview canvas,
.gallery-card-preview img {
    max-width: 100%;
    width: 100%;
    height: auto;
    display: block;
    object-fit: contain;
}

.gallery-card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
}

.gallery-card-title {
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--text-main, #f8fafc);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
    flex: 1;
}



/* ── Responsive Mobile Optimizations (down to 640px) ─────────────────────── */
@media (max-width: 640px) {
    body {
        padding: 16px 6px;
    }

    .scores-widget {
        padding: 16px 10px;
        border-radius: 12px;
    }

    .widget-header h3 {
        font-size: 1.18rem;
    }

    .widget-header p {
        font-size: 0.85rem;
    }

    .controls-row {
        flex-direction: column;
        gap: 8px;
    }

    select.team-dropdown,
    .search-input-container,
    input[type="text"] {
        width: 100%;
        min-width: 0;
    }

    .team-header {
        padding: 8px 12px;
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        gap: 10px;
    }

    .team-header-logo {
        height: 60px;
        max-height: 60px;
        max-width: 90px;
    }

    .team-title {
        font-size: 0.98rem;
    }

    .team-totals {
        font-size: 0.76rem;
        gap: 6px 10px;
        flex-wrap: wrap;
    }

    .scores-table th {
        padding: 7px 4px;
        font-size: 0.68rem;
        letter-spacing: 0.01em;
    }

    .scores-table td {
        padding: 8px 4px;
        font-size: 0.8rem;
    }

    .col-rank {
        width: 36px;
    }

    .col-pts {
        width: 45px;
    }

    .col-w {
        width: 58px;
    }

    .col-l {
        width: 38px;
    }

    .col-swp {
        width: 44px;
    }
}

@media (max-width: 380px) {

    .scores-table th,
    .scores-table td {
        padding: 6px 2px;
        font-size: 0.74rem;
    }

    .col-rank {
        width: 28px;
    }

    .col-pts {
        width: 42px;
    }

    .col-w {
        width: 52px;
    }

    .col-l {
        width: 32px;
    }

    .col-swp {
        width: 38px;
    }
}

/* On screens < 640px, collapse side logo and show logo in header to the right of the name */
@media (max-width: 640px) {
    .team-logo-side {
        display: none;
    }

    .team-header-logo {
        display: block;
    }

    .team-header {
        padding: 10px 14px;
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
    }

    .team-actions-group {
        flex-direction: column;
        gap: 4px;
    }
}