/* =========================================================
   EVENTS PLAYER GAMES — GAMES DRAWER MODAL
   - Mimics scorecard-modal layout/behavior
   - Uses core.css theme engine (html.theme-light / theme-dark)
   ========================================================= */

/* ---------------------------------------------------------
   1. SHELL & TRANSITION
   --------------------------------------------------------- */

.epgm-games-modal-drawer {
    position: fixed;
    top: 0;
    left: 0; /* Left Drawer */
    width: 480px;
    max-width: 100vw;
    height: 100vh;
    display: flex;
    flex-direction: column;
    transform: translateX(-100%); /* Start off-screen left */
    transition: transform 0.3s cubic-bezier(0.25, 1, 0.5, 1);
    background: var(--bg-elev, #ffffff);
    color: var(--color-text, #111111);
    border-right: 1px solid rgba(0,0,0,0.15);
    box-shadow: 14px 0 40px rgba(0, 0, 0, 0.25);
    z-index: 2147483647; /* Highest priority */
}

.epgm-games-modal-drawer.active {
    transform: translateX(0);
}

/* Modal content container */
.epgm-games-modal-drawer .epgm-modal-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 1rem;
    -webkit-overflow-scrolling: touch;
}

/* ---------------------------------------------------------
   2b. RESULTS TABLE FIT (Nassau/Match) — prevent horizontal overflow
   Notes:
   - The drawer uses `overflow-x:hidden`, so wide tables get clipped.
   - Make match-play style tables use fixed layout + tighter spacing so all columns
     fit within the drawer width without requiring horizontal scroll.
   --------------------------------------------------------- */

.epgm-games-modal-drawer .epgm-table-container {
    max-width: 100%;
}

.epgm-games-modal-drawer .epgm-table-container.has-sticky-cols table.epgm-matchplay-table {
    width: 100% !important;
    table-layout: fixed !important;
    min-width: 0 !important;
}

.epgm-games-modal-drawer .epgm-table-container.has-sticky-cols table.epgm-matchplay-table th,
.epgm-games-modal-drawer .epgm-table-container.has-sticky-cols table.epgm-matchplay-table td {
    padding: 6px 6px !important;
    font-size: 12px !important;
    line-height: 1.15 !important;
    box-sizing: border-box;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Do not clip stacked press badges or circular hole badges in the drawer.
   The generic cell rule above uses overflow/ellipsis for long text, but badges need to remain visible. */
.epgm-games-modal-drawer td.epgm-press-col,
.epgm-games-modal-drawer td.epgm-hole-col {
    overflow: visible !important;
    text-overflow: clip !important;
    white-space: normal !important;
}

.epgm-games-modal-drawer td.epgm-press-col .epgm-press-stack {
    display: inline-flex;
    flex-direction: column;
    gap: 3px;
    align-items: center;
}

.epgm-games-modal-drawer td.epgm-hole-col .epgm-hole-badge {
    width: 20px;
    height: 20px;
    font-size: 12px;
}

/* Status/sticky columns are sized for full-width pages in `games.css`.
   In the drawer they waste horizontal space and can make the whole table feel shifted.
   Override to compact widths inside the modal only. */
.epgm-games-modal-drawer .epgm-table-container.has-sticky-cols .epgm-sticky-col-2 {
    width: 84px !important;
    min-width: 84px !important;
    max-width: 84px !important;
    padding: 6px 6px !important;
    text-align: center;
}

/* Running/status columns used by Team/Individual Nassau & match play renderers */
.epgm-games-modal-drawer .epgm-table-container.has-sticky-cols .epgm-run-col {
    width: 30px !important;
    min-width: 30px !important;
    max-width: 30px !important;
    padding: 0 2px !important;
}

/* Allow header labels to wrap instead of forcing wider columns */
.epgm-games-modal-drawer .epgm-table-container.has-sticky-cols table.epgm-matchplay-table thead th {
    white-space: normal !important;
}

/* Keep the hole column compact (uses existing `.epgm-sticky-col-1` sizing) */
.epgm-games-modal-drawer .epgm-table-container.has-sticky-cols table.epgm-matchplay-table th.epgm-sticky-col-1,
.epgm-games-modal-drawer .epgm-table-container.has-sticky-cols table.epgm-matchplay-table td.epgm-sticky-col-1 {
    padding: 6px 2px !important;
}

/* Light mode overrides if needed */
html.theme-light .epgm-games-modal-drawer {
    background: #ffffff;
    border-right-color: #e5e7eb;
}

/* Dark mode overrides */
html.theme-dark .epgm-games-modal-drawer,
body.theme-dark .epgm-games-modal-drawer,
[data-theme="dark"] .epgm-games-modal-drawer {
    background: var(--color-surface, #1f2937);
    color: var(--color-text, #e5e7eb);
    border-right-color: var(--color-border, #374151);
    box-shadow: 14px 0 40px rgba(0,0,0,0.5);
}

/* ---------------------------------------------------------
   2. HEADER
   --------------------------------------------------------- */

.epgm-games-modal-drawer .epgm-modal-header {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--color-border, #e5e7eb);
    background: #ffffff; /* Force opaque light */
    z-index: 10;
}

html.theme-dark .epgm-games-modal-drawer .epgm-modal-header,
[data-theme="dark"] .epgm-games-modal-drawer .epgm-modal-header {
    background: #1f2937; /* Force opaque dark */
    border-bottom-color: #374151;
}

/* Header Buttons Group */
.epgm-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Nav Pill Buttons (Games / Scores) */
.epgm-nav-btn {
    appearance: none;
    background: transparent;
    border: 1px solid var(--color-border, #d1d5db);
    color: var(--color-text, #111);
    padding: 6px 14px;
    border-radius: 999px;
    font-weight: 600;
    font-size: 0.85rem;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s;
    line-height: 1.2;
}

.epgm-nav-btn:hover {
    background: var(--color-accent, #3b82f6);
    border-color: var(--color-accent, #3b82f6);
    color: #fff;
}

/* Close Button - Matching Scorecard Modal */
#epgm-games-modal .epgm-close-btn {
    appearance: none;
    background: rgba(0,0,0,0.06);
    border: 0;
    border-radius: 50%;
    width: 32px; height: 32px;
    display: flex; align-items: center; justify-content: center;
    color: #333;
    font-size: 1.2rem;
    line-height: 1;
    cursor: pointer;
    transition: background 0.2s;
    padding: 0;
}

#epgm-games-modal .epgm-close-btn:hover {
    background: rgba(0,0,0,0.12);
    color: var(--color-error, #ef4444);
}

/* Dark Mode Overrides for Buttons */
html.theme-dark .epgm-nav-btn,
[data-theme="dark"] .epgm-nav-btn {
    border-color: #4b5563;
    color: #e5e7eb;
}
html.theme-dark .epgm-nav-btn:hover,
[data-theme="dark"] .epgm-nav-btn:hover {
    background: var(--color-accent, #3b82f6);
    border-color: var(--color-accent, #3b82f6);
    color: #fff;
}

html.theme-dark #epgm-games-modal .epgm-close-btn,
[data-theme="dark"] #epgm-games-modal .epgm-close-btn {
    background: rgba(255,255,255,0.1);
    color: #fff;
}
html.theme-dark #epgm-games-modal .epgm-close-btn:hover,
[data-theme="dark"] #epgm-games-modal .epgm-close-btn:hover {
    background: rgba(255,255,255,0.2);
    color: #fff; /* Keep white on hover, bg changes */
}

/* ---------------------------------------------------------
   3. GAME CONTENT WRAPPER
   --------------------------------------------------------- */

/* The wrapper handles visibility of the entire game block (title + body) */
.epgm-game-content-wrapper {
    display: none;
}

.epgm-game-content-wrapper.active {
    display: block;
    animation: epgmFadeIn 0.3s ease;
}

/* Reset inner game body display since wrapper controls it */
.epgm-games-modal-drawer .epgm-game-body {
    display: block;
    padding: 0;
}

@keyframes epgmFadeIn {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Mobile Constraints */
@media (max-width: 768px) {
    .epgm-games-modal-drawer {
        width: 100vw;
        border-right: none;
    }
    
    .epgm-games-modal-drawer .epgm-modal-content {
        padding: 0; /* Edge to edge on mobile */
    }
    
    /* Ensure content inside has some padding if needed, or rely on game-body structure */
    .epgm-games-modal-drawer .epgm-game-body {
        padding: 0;
    }
}
/* ---------------------------------------------------------
   4. MODAL TITLE BLOCK
   --------------------------------------------------------- */
.epgm-modal-title-block {
    padding: 16px;
    border-bottom: 1px solid var(--color-border, #e5e7eb);
    background: #f9fafb;
}
.epgm-modal-title {
    margin: 0 0 4px;
    font-size: 1.1rem;
    color: #111;
    font-weight: 700;
}
.epgm-modal-subtitle {
    font-weight: 600;
    font-size: 1rem;
    color: #374151;
}
.epgm-modal-meta {
    font-size: 0.9rem;
    color: #4b5563;
    margin-top: 2px;
    opacity: 0.8;
}

/* Dark Mode */
html.theme-dark .epgm-modal-title-block,
[data-theme='dark'] .epgm-modal-title-block {
    background: var(--bg-elev, #1f2937);
    border-bottom-color: var(--color-border, #374151);
}
html.theme-dark .epgm-modal-title,
[data-theme='dark'] .epgm-modal-title {
    color: #f9fafb;
}
html.theme-dark .epgm-modal-subtitle,
[data-theme='dark'] .epgm-modal-subtitle {
    color: #e5e7eb;
}
html.theme-dark .epgm-modal-meta,
[data-theme='dark'] .epgm-modal-meta {
    color: #9ca3af;
}
/* ---------------------------------------------------------
   4. MODAL TITLE BLOCK
   --------------------------------------------------------- */
.epgm-modal-title-block {
    padding: 16px;
    border-bottom: 1px solid var(--color-border, #e5e7eb);
    background: #f9fafb;
}
.epgm-modal-title {
    margin: 0 0 4px;
    font-size: 1.1rem;
    color: #111;
    font-weight: 700;
}
.epgm-modal-subtitle {
    font-weight: 600;
    font-size: 1rem;
    color: #374151;
}
.epgm-modal-meta {
    font-size: 0.9rem;
    color: #4b5563;
    margin-top: 2px;
    opacity: 0.8;
}

/* Dark Mode */
html.theme-dark .epgm-modal-title-block,
[data-theme='dark'] .epgm-modal-title-block {
    background: var(--bg-elev, #1f2937);
    border-bottom-color: var(--color-border, #374151);
}
html.theme-dark .epgm-modal-title,
[data-theme='dark'] .epgm-modal-title {
    color: #f9fafb;
}
html.theme-dark .epgm-modal-subtitle,
[data-theme='dark'] .epgm-modal-subtitle {
    color: #e5e7eb;
}
html.theme-dark .epgm-modal-meta,
[data-theme='dark'] .epgm-modal-meta {
    color: #9ca3af;
}


/* Force game body to be visible inside modal (overriding accordion hidden state) */
.epgm-game-content-wrapper .epgm-game-body {
    display: block !important;
}
