/* =============================================================================
   MODAL COMPONENTS - Unified Modal System
   =============================================================================

   Uses semantic tokens from themes.css for automatic theme support.
   All modals across the application use these base styles.

   USAGE:
   - Always use CSS variables from themes.css
   - Extend these base styles for specialized modals (e.g., card details modal)
   - Dark theme support is automatic through CSS variables

   ============================================================================= */

/* ========================================
   BASE MODAL STYLES
   ======================================== */

/* Modal Overlay */
.modal {
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: var(--modal-overlay);
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Modal Content Container */
.modal-content {
    background: var(--modal-bg);
    border-radius: var(--radius-lg);
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: var(--shadow-xl);
    border: 1px solid var(--border-primary);
}

/* ========================================
   MODAL SIZE VARIANTS
   ======================================== */

/* Small Modal */
.small-modal {
    max-width: 400px;
    width: 90%;
}

/* Large Modal - For modals with more content (forms, lists) */
.modal-large {
    max-width: 800px;
    width: 90%;
}

/* Deck Modal - Wider for card lists */
.deck-modal-content {
    max-width: 1000px;
    width: 95%;
    max-height: 90vh;
    background: var(--modal-bg);
}

.deck-modal-content .modal-body {
    display: flex;
    gap: var(--spacing-2xl);
    padding: 0 var(--spacing-lg) var(--spacing-lg);
}

.deck-info-section {
    flex: 0 0 350px;
    border-bottom: none;
    border-right: 1px solid var(--border-primary);
    padding-right: var(--spacing-2xl);
    padding-bottom: var(--spacing-lg);
    margin-bottom: 0;
}

.deck-cards-section {
    flex: 1;
    min-width: 0;
}

/* ========================================
   MODAL HEADER
   ======================================== */

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--spacing-lg) var(--spacing-lg) 0;
    border-bottom: 1px solid var(--border-primary);
    margin-bottom: var(--spacing-lg);
}

.modal-header h3 {
    margin: 0;
    color: var(--text-primary);
    font-size: var(--font-size-xl);
    font-weight: 600;
}

/* Close Button */
.close {
    font-size: var(--font-size-2xl);
    color: var(--text-secondary);
    cursor: pointer;
    padding: var(--spacing-xs);
    line-height: 1;
    background: none;
    border: none;
    transition: color var(--transition-fast);
}

.close:hover {
    color: var(--text-primary);
}

/* Card Modal - Special header styling */
#cardModal .modal-header {
    padding: var(--spacing-lg) var(--spacing-xl);
    background: linear-gradient(135deg, var(--color-primary), var(--color-primary-dark));
    color: var(--text-inverse);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    border-bottom: none;
}

#cardModal .modal-header h3 {
    margin: 0;
    font-size: var(--font-size-xl);
    font-weight: 600;
    color: var(--text-inverse);
}

#cardModal .modal-header .close {
    color: var(--text-inverse);
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    line-height: 1;
    opacity: 0.8;
    transition: opacity var(--transition-fast);
}

#cardModal .modal-header .close:hover {
    opacity: 1;
    background-color: var(--overlay-light);
    border-radius: var(--radius-md);
}

/* Creator Modal - Enhanced close button */
#creatorModal .modal-header {
    position: relative;
    padding-right: 50px;
}

#creatorModal .modal-header .close {
    position: absolute;
    right: var(--spacing-lg);
    top: 15px;
    font-size: 28px;
    font-weight: bold;
    color: var(--text-tertiary);
    cursor: pointer;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-full);
    transition: all var(--transition-fast);
}

#creatorModal .modal-header .close:hover {
    color: var(--text-primary);
    background-color: var(--interactive-hover);
}

/* ========================================
   MODAL BODY & FOOTER
   ======================================== */

.modal-body {
    padding: 0 var(--spacing-lg) var(--spacing-lg);
}

.modal-footer {
    display: flex;
    gap: var(--spacing-md);
    justify-content: space-between;
    align-items: center;
    padding: var(--spacing-lg);
    padding-top: var(--spacing-xl);
    border-top: 1px solid var(--border-primary);
    margin-top: var(--spacing-lg);
    background: var(--surface-secondary);
}

.modal-footer-left,
.modal-footer-right {
    display: flex;
    gap: var(--spacing-md);
}

/* ========================================
   MODAL TABS
   ======================================== */

.cards-tabs {
    display: flex;
    border-bottom: 1px solid var(--border-primary);
    margin-bottom: var(--spacing-lg);
}

.tab-btn {
    padding: var(--spacing-sm) var(--spacing-lg);
    border: none;
    background: none;
    cursor: pointer;
    font-weight: 500;
    color: var(--text-secondary);
    border-bottom: 2px solid transparent;
    transition: all var(--transition-fast);
}

.tab-btn.active {
    color: var(--color-primary);
    border-bottom-color: var(--color-primary);
}

.tab-btn:hover:not(.active) {
    color: var(--text-primary);
    background: var(--interactive-hover);
}

.cards-list {
    display: none;
}

.cards-list.active {
    display: block;
}

/* ========================================
   CARD LISTS IN MODALS
   ======================================== */

.card-group {
    margin-bottom: var(--spacing-lg);
}

.card-group-header {
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: var(--spacing-sm);
    padding: var(--spacing-sm) 0;
    border-bottom: 1px solid var(--border-primary);
    font-size: var(--font-size-base);
}

.card-list-item {
    display: flex;
    align-items: center;
    padding: var(--spacing-sm) 0;
    border-bottom: 1px solid var(--border-secondary);
}

.card-quantity {
    font-weight: 600;
    color: var(--color-primary);
    min-width: 30px;
    margin-right: var(--spacing-md);
    text-align: center;
}

.card-name {
    flex: 1;
    color: var(--text-primary);
}

/* ========================================
   TRADING SECTIONS (Creator Modal)
   ======================================== */

.creator-trading-section {
    margin-top: var(--spacing-2xl);
    padding: var(--spacing-lg);
    background: var(--surface-secondary);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-primary);
}

.creator-trading-section h3 {
    margin: 0 0 var(--spacing-md) 0;
    color: var(--text-primary);
    font-size: var(--font-size-xl);
    font-weight: 600;
}

/* Trading Cards Grid */
.trading-cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: var(--spacing-md);
    max-height: 500px;
    overflow-y: auto;
    padding: var(--spacing-sm);
}

/* Custom scrollbar for trading grid */
.trading-cards-grid::-webkit-scrollbar {
    width: 8px;
}

.trading-cards-grid::-webkit-scrollbar-track {
    background: var(--scrollbar-track);
    border-radius: var(--radius-md);
}

.trading-cards-grid::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: var(--radius-md);
}

.trading-cards-grid::-webkit-scrollbar-thumb:hover {
    background: var(--scrollbar-thumb-hover);
}

/* Trading Card Thumbnail */
.trading-card-thumbnail {
    cursor: pointer;
    transition: all var(--transition-base);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.trading-card-thumbnail:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow-lg);
}

/* Image Wrapper with Quantity Badge */
.trading-card-image-wrapper {
    position: relative;
    width: 100%;
    aspect-ratio: 5/7;
    overflow: hidden;
    border-radius: var(--radius-lg);
    background: var(--surface-tertiary);
}

.trading-card-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* Quantity Badge */
.trading-card-quantity-badge {
    position: absolute;
    top: var(--spacing-sm);
    right: var(--spacing-sm);
    background: var(--overlay-heavy);
    color: var(--text-inverse);
    padding: calc(var(--spacing-xs) / 2) var(--spacing-sm);
    border-radius: var(--radius-full);
    font-size: var(--font-size-sm);
    font-weight: 700;
    box-shadow: var(--shadow-md);
    z-index: 2;
}

/* Card Info */
.trading-card-info {
    padding: var(--spacing-sm) var(--spacing-xs) var(--spacing-xs);
    text-align: center;
}

.trading-card-uuid {
    font-family: 'Courier New', monospace;
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: var(--text-primary);
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ========================================
   RESPONSIVE DESIGN
   ======================================== */

@media (max-width: 768px) {
    /* Deck Modal - Stack sections on mobile */
    .deck-modal-content .modal-body {
        flex-direction: column;
        gap: var(--spacing-lg);
    }

    .deck-info-section {
        flex: 1;
        border-right: none;
        border-bottom: 1px solid var(--border-primary);
        padding-right: 0;
        padding-bottom: var(--spacing-lg);
        margin-bottom: var(--spacing-lg);
    }

    .deck-modal-content {
        width: 95%;
        max-height: 95vh;
        margin: var(--spacing-sm);
    }

    /* Trading Cards - Smaller grid on mobile */
    .trading-cards-grid {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
        gap: var(--spacing-sm);
    }

    .trading-card-uuid {
        font-size: var(--font-size-xs);
    }

    .trading-card-quantity-badge {
        font-size: var(--font-size-xs);
        padding: calc(var(--spacing-xs) / 2) var(--spacing-xs);
    }

    /* Modal Footer - Stack on mobile */
    .modal-footer {
        flex-direction: column;
        gap: var(--spacing-sm);
    }

    /* Keep editDeckModal buttons in a row even on mobile */
    #editDeckModal .modal-footer {
        flex-direction: row;
        gap: var(--spacing-md);
    }

    #editDeckModal .modal-footer button {
        flex: 1;
        /* Ensure consistent height between primary and secondary buttons */
        min-height: 44px;
        line-height: 1.5;
        padding: var(--spacing-sm) var(--spacing-lg);
        box-sizing: border-box;
        /* Ensure no border for both buttons */
        border: none !important;
    }

    #editDeckModal .modal-footer button:hover,
    #editDeckModal .modal-footer button:active {
        /* Prevent any border, shadow, or transform on hover/active */
        border: none !important;
        box-shadow: none !important;
        transform: none !important;
    }

    .modal-footer-left,
    .modal-footer-right {
        width: 100%;
        justify-content: stretch;
    }

    .modal-footer-left > *,
    .modal-footer-right > * {
        flex: 1;
    }
}

/* ========================================
   ACCESSIBILITY
   ======================================== */

/* Focus states */
.modal:focus-within {
    outline: none;
}

.close:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

.tab-btn:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .trading-card-thumbnail {
        transition: none;
    }

    .tab-btn,
    .close {
        transition: none;
    }
}

/* ========================================
   THEME NOTES
   ========================================

   This file uses CSS variables from themes.css exclusively.
   Dark theme support is automatic - no body.dark-theme overrides needed!

   Variables used:
   - Surface: --modal-bg, --surface-secondary, --surface-tertiary
   - Text: --text-primary, --text-secondary, --text-tertiary, --text-inverse
   - Border: --border-primary, --border-secondary
   - Interactive: --interactive-hover, --overlay-light, --overlay-heavy
   - Shadows: --shadow-md, --shadow-lg, --shadow-xl
   - Colors: --color-primary, --color-primary-dark
   - Spacing: --spacing-xs through --spacing-2xl
   - Radius: --radius-sm through --radius-full
   - Scrollbar: --scrollbar-track, --scrollbar-thumb, --scrollbar-thumb-hover
   - Transitions: --transition-fast, --transition-base
   - Focus: --focus-ring

   To customize modals for a specific theme:
   1. Update the semantic tokens in themes.css
   2. All modals will update automatically
   3. No need for body.dark-theme overrides

   ======================================== */
