/* ============================================
   DECK PANEL
   Deck header, entries, controls, stack/grid views
   ============================================ */

/* Deck Content Wrapper */
.deck-content-inner {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
    width: 100%;
    height: 100%;
    /* CRITICAL: Propagate height */
}

/* Deck Header: Preview + Controls */
.deck-header {
    display: flex;
    align-items: stretch;
    gap: 12px;
    padding: 8px;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: 8px;
    margin-bottom: 8px;
    flex-shrink: 0;
}

/* Deck Toolbar (Collapsible Toggle) */
.deck-toolbar {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0;
    margin-bottom: 8px;
    border-bottom: 1px solid var(--divider-border);
    min-height: 24px;
}

.collapse-controls-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 0.8em;
    font-style: italic;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 12px;
    border-radius: 12px;
    transition: all 0.2s ease;
}

.collapse-controls-btn:hover {
    color: var(--accent-color);
    text-decoration: underline;
    background: transparent;
}

/* Format Selector */
.format-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    background: var(--input-bg);
    border-radius: 8px;
    margin-bottom: 10px;
}

.format-label {
    color: #888;
    font-size: 0.9em;
}

.format-selector {
    flex: 1;
}

/* Deck Preview Column */
.deck-preview-column {
    flex-shrink: 0;
    width: 33%;
    min-width: 120px;
    max-width: 220px;
    aspect-ratio: 488 / 680;
    position: relative;
}

.deck-preview-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
    position: absolute;
    top: 0;
    left: 0;
}

.deck-preview-placeholder {
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #666;
    font-size: 0.85em;
    font-style: italic;
    position: absolute;
    top: 0;
    left: 0;
}

.commander-crown {
    position: absolute;
    top: -6px;
    left: 4px;
    font-size: 1.5em;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.6);
    z-index: 1;
}

/* Commander/Partner toggle button */
.crown-btn {
    background: transparent;
    border: none;
    font-size: 14px;
    cursor: pointer;
    padding: 2px 4px;
    opacity: 0.4;
    transition: opacity 0.2s, transform 0.2s;
}

.crown-btn:hover {
    opacity: 0.8;
    transform: scale(1.1);
}

.crown-btn.active {
    opacity: 1;
    filter: drop-shadow(0 0 2px gold);
}

.crown-placeholder {
    width: 22px;
    display: inline-block;
}

/* Companion toggle button */
.companion-btn {
    background: transparent;
    border: none;
    font-size: 14px;
    cursor: pointer;
    padding: 2px 4px;
    opacity: 0.4;
    transition: opacity 0.2s, transform 0.2s;
    color: #a855f7;
}

.companion-btn:hover {
    opacity: 0.8;
    transform: scale(1.1);
}

.companion-btn.active {
    opacity: 1;
    filter: drop-shadow(0 0 3px #a855f7);
}

/* Deck Controls */
.deck-controls {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-self: stretch;
    gap: 8px;
    min-width: 0;
    padding: 10px 0;
}

.deck-controls-top {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.deck-search-row {
    width: 100%;
}

.deck-search-input {
    width: 100%;
    padding: 8px 12px;
}

.deck-sort-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.deck-sort-label {
    color: #888;
    font-size: 0.85em;
}

.deck-sort-dropdown {
    flex: 1;
}

/* Renamed to avoid conflicts */
.deck-action-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    /* Increasing gap slightly */
    margin-top: auto;
    width: 100%;
}

.deck-action-grid>button {
    /* Resetting width constraints */
    width: 100% !important;
    max-width: none !important;
    min-width: 0 !important;

    /* Internal layout */
    display: flex !important;
    justify-content: center;
    align-items: center;
    gap: 6px;
    padding: 8px 4px;
    height: 100%;

    /* overriding forms.css flex:1 if present */
    flex: none !important;
}

/* Preserve base visual styles from classes but override layout */
.deck-action-grid .action-btn {
    font-size: 0.8em;
}

/* Deck List */
.deck-list {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
    /* overflow: auto;  <-- REMOVED to prevent nested scroll */
    width: 100%;
    margin-bottom: 20px;
    padding-right: 6px;
    box-sizing: border-box;
}

/* Grouped Deck List */
.deck-list-grouped {
    display: flex;
    flex-direction: column;
    gap: 12px;
    flex: 1;
    /* overflow-y: auto; <-- REMOVED to prevent nested scroll */
    min-height: 0;
}

.deck-group {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 6px;
    overflow: hidden;
}

.deck-group-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 10px;
    background: rgba(158, 158, 255, 0.15);
    color: var(--accent-color);
    font-size: 0.85em;
    font-weight: 600;
    border-bottom: 1px solid rgba(158, 158, 255, 0.2);
}

.group-label {
    flex: 1;
}

.group-badge {
    background: rgba(158, 158, 255, 0.3);
    color: #fff;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.9em;
    font-weight: 500;
}

/* Deck Entry */
.deck-entry {
    display: flex;
    align-items: center;
    padding: 6px 12px;
    gap: 12px;
    min-height: 40px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    font-size: 0.9em;
    background: transparent;
    transition: background 0.2s;
    position: relative;
    color: var(--text-color);
}

.deck-entry:hover {
    background: rgba(255, 255, 255, 0.05);
}

.deck-entry.invalid {
    opacity: 0.7;
    background: rgba(255, 0, 0, 0.1);
    border-left: 3px solid #ff4444;
}

.deck-entry.invalid .entry-name {
    color: #ff6b6b;
}

.deck-entry.filtered-out {
    opacity: 0.25;
    pointer-events: none;
}

.deck-entry.has-validation-errors {
    background: linear-gradient(90deg, rgba(220, 53, 69, 0.25) 0%, rgba(220, 53, 69, 0.1) 100%);
    border-left: 3px solid #dc3545;
}

.deck-entry.has-validation-errors:hover {
    background: linear-gradient(90deg, rgba(220, 53, 69, 0.35) 0%, rgba(220, 53, 69, 0.15) 100%);
}

.deck-entry.has-validation-errors .entry-name {
    color: #ff6b6b;
}

.entry-count {
    font-weight: bold;
    color: var(--accent-color);
    min-width: 24px;
    text-align: right;
}

.entry-name {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.entry-controls {
    display: flex;
    align-items: center;
    gap: 12px;
    opacity: 0.9;
    transition: opacity 0.2s;
}

.deck-entry:hover .entry-controls {
    opacity: 1;
}

.entry-buttons {
    display: flex;
    gap: 4px;
}

.validation-icon {
    color: #ff4444;
    font-size: 0.9em;
    margin-left: 6px;
}

/* Deck Actions */
.deck-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
    flex-shrink: 0;
    padding-top: 16px;
}

.clear-deck-btn {
    flex: 1;
    padding: 10px;
    background: transparent;
    border: 1px solid #e74c3c;
    color: #e74c3c;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85em;
    transition: all 0.2s ease;
}

.clear-deck-btn:hover {
    background: rgba(231, 76, 60, 0.1);
}

/* Empty Deck State */
.empty-deck {
    text-align: center;
    padding: 40px 20px;
    color: #666;
}

.empty-deck .hint {
    font-size: 0.85em;
    color: #555;
}

.empty-import-btn {
    margin-top: 16px;
    padding: 12px 24px;
}

/* Commander Button in Deck Entry */
.cmdr-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 0.9em;
    padding: 2px 6px;
    margin-left: 6px;
    border-radius: 4px;
    opacity: 0.6;
    transition: all 0.2s ease;
}

.cmdr-btn:hover {
    opacity: 1;
    background: rgba(255, 215, 0, 0.2);
    transform: scale(1.2);
}

.cmdr-menu {
    cursor: pointer;
    font-size: 1.2em;
    color: #ffd700;
    margin-left: 4px;
}

/* Stack View */
.deck-stack-view {
    display: flex;
    gap: 16px;
    padding: 16px;
    overflow-x: auto;
    height: 100%;
    align-items: flex-start;
}

.stack-column {
    display: flex;
    flex-direction: column;
    min-width: 200px;
    max-width: 200px;
    width: 200px;
    gap: 8px;
    background: var(--entry-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 12px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2);
    margin-right: 4px;
}

.stack-header {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    gap: 8px;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--border-color);
    font-weight: bold;
    color: var(--text-color);
    font-size: 0.9rem;
    height: 36px;
    margin-bottom: 4px;
}

.stack-icon {
    width: 20px;
    height: 20px;
    display: block;
}

.stack-label {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex-grow: 1;
}

.stack-count {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-color);
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.8rem;
    min-width: 24px;
    text-align: center;
    border: 1px solid var(--border-color);
}

.stack-cards {
    display: flex;
    flex-direction: column;
    padding-bottom: 100px;
}

.stack-card {
    position: relative;
    margin-bottom: -216px;
    transition: transform 0.2s ease, z-index 0s;
    cursor: pointer;
    z-index: 0;
    width: 100%;
    aspect-ratio: 63/88;
}

.stack-card:last-child {
    margin-bottom: 0;
}

.stack-card img {
    width: 100%;
    border-radius: 9px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.5);
    transition: box-shadow 0.2s;
}

.stack-card:hover,
.stack-card.hover-active {
    z-index: 100;
    transform: translateY(-5px) scale(1.05);
}

.stack-card:hover img,
.stack-card.hover-active img {
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.8);
}

.stack-card-count {
    position: absolute;
    top: -8px;
    right: -8px;
    background: var(--accent-color);
    color: white;
    font-weight: bold;
    font-size: 0.8rem;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
    z-index: 20;
}

.stack-flip-btn {
    position: absolute;
    top: -8px;
    left: -8px;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    border: 1px solid var(--accent-color);
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: none;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 21;
    font-size: 0.8rem;
    padding: 0;
    transition: all 0.2s ease;
}

.stack-card:hover .stack-flip-btn {
    display: flex;
}

.stack-flip-btn:hover {
    background: var(--accent-color);
    transform: scale(1.1);
}

.stack-add-btn,
.stack-remove-btn {
    position: absolute;
    bottom: -8px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: none;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 21;
    font-size: 0.8rem;
    padding: 0;
    transition: all 0.2s ease;
    border: none;
    color: white;
    font-weight: bold;
}

.stack-add-btn {
    right: -8px;
    background: rgba(46, 204, 113, 0.9);
}

.stack-remove-btn {
    left: -8px;
    background: rgba(231, 76, 60, 0.9);
}

.stack-card:hover .stack-add-btn,
.stack-card:hover .stack-remove-btn {
    display: flex;
}

.stack-add-btn:hover {
    background: #27ae60;
    transform: scale(1.1);
}

.stack-remove-btn:hover {
    background: #c0392b;
    transform: scale(1.1);
}

/* Command Zone Section */
.command-zone-section {
    margin-bottom: 12px;
    border-bottom: 1px solid var(--divider-border);
    padding-bottom: 8px;
}

.command-zone-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
    padding: 4px 8px;
    background: rgba(138, 43, 226, 0.15);
    border-radius: 6px;
}

.command-zone-label {
    font-size: 0.85em;
    font-weight: 600;
    color: var(--accent-color);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.command-zone-count {
    background: var(--accent-color);
    color: white;
    font-size: 0.7em;
    font-weight: bold;
    padding: 2px 6px;
    border-radius: 10px;
    min-width: 18px;
    text-align: center;
}

.command-zone-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.command-zone-entry {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    background: rgba(138, 43, 226, 0.08);
    border-radius: 6px;
    border-left: 3px solid var(--accent-color);
    transition: background 0.2s ease;
    cursor: pointer;
}

.command-zone-entry:hover {
    background: rgba(138, 43, 226, 0.15);
}

.cz-badge {
    font-size: 14px;
    flex-shrink: 0;
}

.cz-name {
    flex: 1;
    font-weight: 500;
    color: var(--text-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cz-mana {
    font-family: monospace;
    font-size: 0.85em;
    color: var(--text-muted);
    flex-shrink: 0;
}

.cz-mana-symbols {
    display: flex;
    align-items: center;
    gap: 2px;
    flex-shrink: 0;
}

.cz-remove-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 18px;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
    opacity: 0;
    transition: opacity 0.2s, color 0.2s;
}

.command-zone-entry:hover .cz-remove-btn {
    opacity: 1;
}

.cz-remove-btn:hover {
    color: #ff4444;
}

/* Companion Section */
.companion-section {
    margin-bottom: 12px;
    border-bottom: 1px solid var(--divider-border);
    padding-bottom: 8px;
}

.companion-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
    padding: 4px 8px;
    background: rgba(234, 179, 8, 0.15);
    border-radius: 6px;
}

.companion-label {
    font-size: 0.85em;
    font-weight: 600;
    color: #eab308;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.companion-count {
    background: #eab308;
    color: white;
    font-size: 0.7em;
    font-weight: bold;
    padding: 2px 6px;
    border-radius: 10px;
    min-width: 18px;
    text-align: center;
}

.companion-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.companion-entry {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    background: rgba(234, 179, 8, 0.08);
    border-radius: 6px;
    border-left: 3px solid #eab308;
    transition: background 0.2s ease;
    cursor: pointer;
}

.companion-entry:hover {
    background: rgba(234, 179, 8, 0.15);
}

.companion-entry:hover .cz-remove-btn {
    opacity: 1;
}

/* Stack View Overlay Controls */
.stack-cmd-btn-overlay {
    position: absolute;
    bottom: 75px;
    left: 0;
    width: 100%;
    display: flex;
    justify-content: center;
    gap: 8px;
    z-index: 25;
    pointer-events: none;
}

.stack-crown-btn,
.stack-companion-btn {
    pointer-events: auto;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(2px);
    border-radius: 50%;
    padding: 4px;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(255, 255, 255, 0.2);
    transition: all 0.2s ease;
    opacity: 0;
    transform: translateY(10px);
}

.stack-card:hover .stack-crown-btn,
.stack-card:hover .stack-companion-btn {
    opacity: 1;
    transform: translateY(0);
}

.stack-crown-btn:hover,
.stack-companion-btn:hover {
    transform: scale(1.1) translateY(0);
    background: rgba(0, 0, 0, 0.8);
    border-color: var(--accent-color);
}

.stack-crown-btn.active {
    opacity: 1;
    transform: translateY(0);
    background: rgba(138, 43, 226, 0.8);
    border-color: #8a2be2;
    box-shadow: 0 0 8px rgba(138, 43, 226, 0.4);
}

.stack-companion-btn.active {
    opacity: 1;
    transform: translateY(0);
    background: rgba(234, 179, 8, 0.8);
    border-color: #eab308;
    box-shadow: 0 0 8px rgba(234, 179, 8, 0.4);
}

/* Deck Control Section */
.deck-control-section {
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 12px;
    display: flex;
    flex-direction: column;
}

.deck-control-section .deck-section-header {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 0.05em;
    margin-bottom: 2px;
}

/* Mobile Deck Overrides */
@media (max-width: 768px) {
    .deck-header {
        flex-direction: column;
        align-items: center;
    }

    /* Keep preview but make it smaller */
    .deck-preview-column {
        width: 120px;
        margin-bottom: 8px;
    }

    .deck-controls {
        width: 100%;
    }

    /* Compact format row */
    .format-row {
        flex-direction: row;
        align-items: center;
        padding: 6px;
        margin-bottom: 6px;
    }

    /* Compact control sections */
    .deck-control-section {
        padding: 6px;
        margin-bottom: 6px;
    }

    .deck-control-section .deck-section-header {
        margin-bottom: 2px;
        font-size: 0.65rem;
    }

    .deck-stack-view {
        /* Mobile: Single column stacking with proper scroll constraint */
        display: flex;
        flex-direction: column;
        gap: 12px;
        padding: 12px 4px;
        /* Let parent handle scrolling - DO NOT set overflow or height here */
    }

    .stack-column {
        /* Full width columns on mobile */
        min-width: 0;
        width: 100%;
        max-width: none;
        /* Let parent handle scrolling - DO NOT set overflow or height here */
    }

    /* Make deck entries easier to tap */
    .deck-entry {
        padding: 10px 12px;
    }

    .deck-action-buttons {
        flex-wrap: wrap;
    }

    .deck-info-stats {
        /* Assuming there's a stats row, ensure it wraps */
        flex-wrap: wrap;
    }

    /* CRITICAL: Don't clip content - let parent tab-panel handle scrolling */
    .deck-content-inner {
        overflow: visible !important;
    }
}