/* ============================================
   CARDS
   Card grid, card view, popups, and card widgets
   ============================================ */

/* Card Grid */
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 16px;
    padding: 16px;
}

/* Card Item */
.card-item {
    position: relative;
    cursor: pointer;
    transition: transform 0.2s ease;
}

.card-item:hover {
    transform: scale(1.02);
    z-index: 10;
}

/* Card info section */
.card-info h3 {
    margin: 8px 0 4px 0;
    font-size: 0.95em;
}

.other-face-name {
    margin: 0;
    font-size: 0.75em;
    font-style: italic;
    color: #888;
}

/* Add to Deck Button */
.add-to-deck-btn {
    position: absolute;
    bottom: 8px;
    right: 8px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(46, 204, 113, 0.9);
    border: none;
    color: white;
    font-size: 20px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, background 0.2s ease;
    z-index: 5;
}

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

/* Remove from Deck Button */
.remove-from-deck-btn {
    position: absolute;
    bottom: 8px;
    left: 8px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(231, 76, 60, 0.9);
    border: none;
    color: white;
    font-size: 20px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, background 0.2s ease;
    z-index: 5;
}

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

/* Card Widget Item - used in Grid view */
.card-widget-item {
    display: flex;
    flex-direction: column;
    background: var(--entry-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 10px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2);
    height: auto !important;
}

.card-widget-item:hover {
    transform: scale(1.03);
    border-color: var(--accent-color);
    box-shadow: 0 8px 15px rgba(0, 0, 0, 0.4);
}

.card-widget-item img {
    width: 100%;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.card-widget-footer {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 10px;
}

.card-widget-info {
    display: flex;
    flex-direction: column;
    min-height: 2.2em;
    justify-content: center;
}

.card-widget-name {
    font-size: 0.9em;
    font-weight: 600;
    color: var(--text-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.card-widget-other-face {
    font-size: 0.75em;
    font-style: italic;
    color: var(--text-muted);
}

.card-widget-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    background: rgba(10, 10, 15, 0.9);
    border-radius: 8px;
    padding: 2px 8px;
    border: 1px solid var(--border-color);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.6);
    transition: all 0.2s ease;
    width: 130px;
    backdrop-filter: blur(8px);
    z-index: 10;
}

/* Positioning-only override for Stack View */
.stack-card .card-widget-controls {
    position: absolute;
    bottom: 12px;
    left: 50%;
    transform: translateX(-50%);
    opacity: 0;
    pointer-events: none;
    z-index: 20;
}

.stack-card:hover .card-widget-controls {
    opacity: 1;
    pointer-events: auto;
}

.widget-control-btn {
    width: 22px;
    height: 22px;
    border-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-color);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 14px;
    font-weight: 800;
    transition: all 0.15s ease;
}

.widget-control-btn:hover {
    transform: scale(1.1);
}

.widget-control-btn.add:hover {
    background: #2ecc71;
    border-color: #27ae60;
}

.widget-control-btn.remove:hover {
    background: #e74c3c;
    border-color: #c0392b;
}

.widget-count {
    font-size: 0.8em;
    font-weight: 800;
    color: var(--accent-light);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
    min-width: 20px;
    text-align: center;
}

/* Flip Button for double-faced cards */
.flip-button {
    position: absolute;
    top: -12px;
    right: -12px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.7);
    border: 2px solid var(--accent-color);
    color: white;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s ease, background 0.2s ease;
    z-index: 5;
}

.flip-button:hover {
    background: var(--accent-color);
    transform: rotate(180deg);
}

/* Card Details Popup */
.card-details-popup {
    width: 280px;
    min-height: 250px;
    background: var(--popup-bg);
    border: 1px solid var(--popup-border);
    border-radius: 12px;
    padding: 16px;
    box-shadow: 0 8px 32px var(--popup-shadow);
    z-index: 100;
}

.card-details-popup h4 {
    margin: 0 0 12px 0;
    color: var(--accent-color);
    font-size: 1.1em;
    border-bottom: 1px solid var(--popup-section-border);
    padding-bottom: 8px;
}

.popup-section {
    margin-bottom: 8px;
    font-size: 0.85em;
    color: #ddd;
}

.popup-section strong {
    color: #aaa;
    margin-right: 4px;
}

/* Prices Grid */
.prices-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
    margin-top: 4px;
}

.price-badge {
    display: flex;
    justify-content: space-between;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.8em;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
}

.price-label {
    color: var(--text-muted);
}

.price-value {
    font-weight: bold;
    color: var(--text-color);
}

.price-badge.unavailable {
    opacity: 0.5;
}

.price-badge.unavailable .price-value {
    color: var(--text-muted);
}

/* Legalities Grid */
.legalities-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 4px;
    margin-top: 4px;
}

.legality-badge {
    display: flex;
    justify-content: space-between;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.8em;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
}

.legality-badge .status-text {
    font-weight: bold;
}

.legality-badge.legality-legal .status-text {
    color: #2ecc71;
}

.legality-badge.legality-not-legal .status-text {
    color: #e74c3c;
}

.legality-badge.legality-banned .status-text {
    color: #e74c3c;
}

.legality-badge.legality-restricted .status-text {
    color: #f39c12;
}

.format-name {
    font-weight: bold;
}

.status-text {
    text-transform: capitalize;
}

/* Invalid Card Indicator */
.card-invalid {
    box-shadow: 0 0 15px 3px rgba(255, 0, 0, 0.6) !important;
    border: 2px solid #ff4444 !important;
}

/* Version Dropdown */
.version-dropdown {
    width: 100%;
    padding: 6px 8px;
    margin-top: 4px;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: 4px;
    color: var(--text-color);
    font-size: 0.8em;
    cursor: pointer;
}

.version-dropdown:focus {
    outline: none;
    border-color: var(--accent-color);
}

.version-dropdown option {
    background: #2a2a2a;
    color: #fff;
}

/* Context Menu */
.context-menu {
    position: fixed;
    background: #1a1a2e;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    padding: 4px 0;
    min-width: 180px;
    z-index: 2000;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

.context-menu-item {
    padding: 8px 16px;
    color: #ccc;
    cursor: pointer;
    font-size: 0.9em;
    display: flex;
    align-items: center;
    gap: 8px;
}

.context-menu-item:hover {
    background: rgba(158, 158, 255, 0.2);
    color: #fff;
}

.context-menu-item.disabled {
    color: #555;
    cursor: not-allowed;
}

.context-menu-item.disabled:hover {
    background: transparent;
}