/* ========================================
   UNIFIED CARD STYLES - Based on view_deck_v2.html
   ======================================== */

/* CSS Variables for consistent sizing */
:root {
    --card-width: 160px;
    --card-height: calc(var(--card-width) * 1.447);
    --card-min-width: min(var(--card-width), 30vw);
    --card-min-height: calc(var(--card-min-width) * 1.447);
    
    /* Unified colors */
    --card-bg: white;
    --card-border: #e2e8f0;
    --card-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    --card-shadow-hover: 0 8px 32px rgba(0, 0, 0, 0.15);
    --card-border-radius: 12px;
    --card-transition: all 0.3s ease;
    --card-hover-transform: translateY(-4px);
    
    /* Typography */
    --card-title-size: 1.1rem;
    --card-title-weight: 600;
    --card-meta-size: 0.875rem;
    --card-meta-color: #6b7280;
    
    /* Spacing */
    --card-padding: 0rem;
    --card-gap: 24px;
}

/* ========================================
   BASE CARD STYLES
   ======================================== */

/* Unified card base styles - EXCLUDE cards.html cards */
.deck-card,
.binder-card,
.collection-card {
    background: var(--card-bg);
    border-radius: var(--card-border-radius);
    overflow: hidden;
    transition: var(--card-transition);
    box-shadow: none;
    text-decoration: none;
    color: inherit;
    display: block;
    position: relative;
    border: none;
    cursor: pointer;
}

.deck-card:hover,
.binder-card:hover,
.collection-card:hover {
    transform: var(--card-hover-transform);
    box-shadow: none;
    text-decoration: none;
    color: inherit;
}

/* ========================================
   CARD IMAGE CONTAINERS
   ======================================== */

.card-image {
    position: relative;
    width: 100%;
    height: var(--card-min-height);
    overflow: hidden;
    background: #f3f4f6;
    display: flex;
    align-items: center;
    justify-content: center;
}

.card-image img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    transition: transform 0.3s ease;
}

.deck-card:hover .card-image img,
.binder-card:hover .card-image img,
.collection-card:hover .card-image img {
    transform: scale(1.05);
}

/* ========================================
   CARD PLACEHOLDERS
   ======================================== */

.card-placeholder {
    color: #6b7280;
    font-size: 48px;
    opacity: 0.7;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #f3f4f6 0%, #e5e7eb 100%);
    border-radius: 8px;
}

/* Removed binder-color-bar - now all cards have unified structure */

/* ========================================
   CARD IMAGE BACKGROUNDS
   ======================================== */

.deck-card .card-image {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.binder-card .card-image {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
}

.collection-card .card-image {
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
}

.card-placeholder i {
    color: rgba(255, 255, 255, 0.9);
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    font-size: 48px;
}

/* ========================================
   SPECIFIC PLACEHOLDER STYLES
   ======================================== */

.deck-card .card-placeholder {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.binder-card .card-placeholder {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
}

.collection-card .card-placeholder {
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
}

/* ========================================
   DARK MODE PLACEHOLDERS
   ======================================== */

body.dark-mode .card-placeholder {
    background: linear-gradient(135deg, #374151 0%, #4b5563 100%);
}

body.dark-mode .deck-card .card-placeholder {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

body.dark-mode .binder-card .card-placeholder {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
}

body.dark-mode .collection-card .card-placeholder {
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
}

/* ========================================
   CARD CONTENT AREAS
   ======================================== */

.card-info,
.deck-info,
.binder-header,
.collection-info {
    padding: var(--card-padding);
    position: relative;
}

/* ========================================
   CARD TITLES
   ======================================== */

.card-name,
.deck-name,
.binder-name,
.collection-name,
.deck-info h3,
.binder-header h3 {
    font-size: var(--card-title-size);
    font-weight: var(--card-title-weight);
    margin: 0 0 8px 0;
    color: #1f2937;
    line-height: 1.3;
}

/* ========================================
   CARD META INFORMATION
   ======================================== */

.card-meta,
.deck-author,
.binder-meta,
.collection-meta {
    color: var(--card-meta-color);
    font-size: var(--card-meta-size);
    margin-bottom: 12px;
}

/* ========================================
   CARD DESCRIPTIONS
   ======================================== */

.deck-description,
.binder-description,
.collection-description {
    color: var(--card-meta-color);
    font-size: var(--card-meta-size);
    line-height: 1.4;
    margin-bottom: 12px;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

@media (min-width: 1138px) {
    .deck-description{
        max-width: 60%;
    }
}

/* ========================================
   CARD STATS - UNIFIED LAYOUT
   ======================================== */

.card-stats,
.deck-stats,
.binder-stats,
.collection-stats {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.stat,
.binder-stat,
.collection-stat {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--card-meta-color);
    font-size: var(--card-meta-size);
    background: rgba(96, 165, 250, 0.05);
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid rgba(96, 165, 250, 0.1);
    transition: all 0.2s ease;
    flex: 1;
    min-width: 0;
    min-height: 32px;
}

.stat:hover,
.binder-stat:hover,
.collection-stat:hover {
    background: rgba(96, 165, 250, 0.08);
    border-color: rgba(96, 165, 250, 0.2);
    transform: translateY(-1px);
}

.stat i,
.binder-stat i,
.collection-stat i {
    color: #3b82f6;
    font-size: 14px;
    width: 16px;
    text-align: center;
}

.stat span,
.binder-stat span,
.collection-stat span {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ========================================
   CARD GRIDS
   ======================================== */

.deck-grid,
.binders-grid,
.collections-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(var(--card-min-width), 1fr));
    gap: var(--card-gap);
    min-height: 240px;
    contain: layout;
}

/* ========================================
   CARD OVERLAYS
   ======================================== */

.card-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(59, 130, 246, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s ease;
    color: white;
    font-size: 24px;
}

.deck-card:hover .card-overlay,
.binder-card:hover .card-overlay,
.collection-card:hover .card-overlay {
    opacity: 1;
}

/* ========================================
   CARD ACTIONS
   ======================================== */

.card-actions,
.deck-actions,
.binder-actions,
.collection-actions {
    display: flex;
    gap: 12px;
    align-items: center;
    margin-top: 16px;
    flex-wrap: wrap;
}

.btn-primary,
.btn-secondary,
.btn-outline {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 6px;
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s ease;
    border: none;
    cursor: pointer;
    min-height: 36px;
    white-space: nowrap;
}

.btn-primary {
    background: #3b82f6;
    color: white;
}

.btn-primary:hover {
    background: #2563eb;
    transform: translateY(-1px);
}

.btn-secondary {
    background: #10b981;
    color: white;
}

.btn-secondary:hover {
    background: #059669;
    transform: translateY(-1px);
}

.btn-outline {
    background: transparent;
    color: #6b7280;
    border: 1px solid #e2e8f0;
    min-width: 36px;
    padding: 8px;
    justify-content: center;
}

.btn-outline:hover {
    background: #f9fafb;
    color: #374151;
    border-color: #d1d5db;
}

/* ========================================
   CARD QUANTITY BADGES
   ======================================== */

.card-quantity-badge,
.deck-quantity-badge,
.binder-quantity-badge {
    position: absolute;
    top: -10px;
    right: -10px;
    background: #dc3545;
    color: white;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    border: 2px solid white;
}

.card-quantity-badge.owned,
.deck-quantity-badge.owned,
.binder-quantity-badge.owned {
    background: #28a745;
}

/* When user owns copies but current displayed variant is not in collection */
.card-quantity-badge.mismatch,
.deck-quantity-badge.mismatch,
.binder-quantity-badge.mismatch {
    background: #f1c40f; /* yellow */
    color: #111;
}

/* ========================================
   CARD COLOR VARIANTS
   ======================================== */

.card-image-container.red,
.deck-image.red,
.binder-color-bar.red {
    background: linear-gradient(135deg, #ff6b6b 0%, #ee5a52 100%);
}

.card-image-container.blue,
.deck-image.blue,
.binder-color-bar.blue {
    background: linear-gradient(135deg, #4ecdc4 0%, #44a08d 100%);
}

.card-image-container.green,
.deck-image.green,
.binder-color-bar.green {
    background: linear-gradient(135deg, #56ab2f 0%, #a8e6cf 100%);
}

.card-image-container.white,
.deck-image.white,
.binder-color-bar.white {
    background: linear-gradient(135deg, #f7f7f7 0%, #d4d4d4 100%);
    color: #333;
}

.card-image-container.colorless,
.deck-image.colorless,
.binder-color-bar.colorless {
    background: linear-gradient(135deg, #636363 0%, #a2a2a2 100%);
}

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

@media (max-width: 1366px) {
    .deck-grid,
    .binders-grid,
    .collections-grid {
        grid-template-columns: repeat(auto-fit, minmax(var(--card-min-width), 1fr));
        gap: 20px;
    }
}

@media (max-width: 1024px) {
    .deck-grid,
    .binders-grid,
    .collections-grid {
        grid-template-columns: repeat(auto-fit, minmax(var(--card-min-width), 1fr));
        gap: 18px;
    }
    
    .card-info,
    .deck-info,
    .binder-header,
    .collection-info {
        padding: 1.25rem;
    }
}

@media (max-width: 768px) {
    .deck-grid,
    .binders-grid,
    .collections-grid {
        grid-template-columns: repeat(auto-fit, minmax(var(--card-min-width), 1fr));
        gap: 16px;
    }
    
    .card-info,
    .deck-info,
    .binder-header,
    .collection-info {
        padding: 1rem;
    }
    
    .card-name,
    .deck-name,
    .binder-name,
    .collection-name {
        font-size: 1rem;
    }
    
    .card-stats,
    .deck-stats,
    .binder-stats,
    .collection-stats {
        gap: 12px;
    }
}

@media (max-width: 480px) {
    .deck-grid,
    .binders-grid,
    .collections-grid {
        grid-template-columns: repeat(auto-fit, minmax(var(--card-min-width), 1fr));
        gap: 12px;
    }
    
    .card-info,
    .deck-info,
    .binder-header,
    .collection-info {
        padding: 0.875rem;
    }
    
    .card-name,
    .deck-name,
    .binder-name,
    .collection-name {
        font-size: 0.9rem;
    }
    
    .card-stats,
    .deck-stats,
    .binder-stats,
    .collection-stats {
        gap: 8px;
        flex-direction: column;
    }
}

/* ========================================
   DARK MODE SUPPORT
   ======================================== */

body.dark-mode .deck-card,
body.dark-mode .binder-card,
body.dark-mode .collection-card {
    background: #374151;
    border-color: #4a5568;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

body.dark-mode .deck-card:hover,
body.dark-mode .binder-card:hover,
body.dark-mode .collection-card:hover {
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

body.dark-mode .card-image-container,
body.dark-mode .deck-image,
body.dark-mode .binder-color-bar,
body.dark-mode .collection-image {
    background: #4a5568;
}

body.dark-mode .card-name,
body.dark-mode .deck-name,
body.dark-mode .binder-name,
body.dark-mode .collection-name {
    color: #f1f5f9;
}

body.dark-mode .card-meta,
body.dark-mode .deck-author,
body.dark-mode .binder-meta,
body.dark-mode .collection-meta {
    color: #94a3b8;
}

body.dark-mode .stat,
body.dark-mode .binder-stat,
body.dark-mode .collection-stat {
    color: #94a3b8;
}

body.dark-mode .stat i,
body.dark-mode .binder-stat i,
body.dark-mode .collection-stat i {
    color: #60a5fa;
}

body.dark-mode .btn-outline {
    background: transparent;
    color: #94a3b8;
    border-color: #4a5568;
}

body.dark-mode .btn-outline:hover {
    background: #374151;
    color: #e2e8f0;
    border-color: #60a5fa;
}

body.dark-mode .deck-description,
body.dark-mode .binder-description,
body.dark-mode .collection-description {
    color: #94a3b8;
}

body.dark-mode .collection-binders strong {
    color: #e2e8f0;
}

body.dark-mode .card-empty h3 {
    color: #e2e8f0;
}

/* ========================================
   SPECIFIC OVERRIDES FOR EXISTING STYLES
   ======================================== */

/* Override existing deck card styles */
.deck-card {
    min-height: var(--card-min-height);
}

.deck-card .deck-image {
    height: var(--card-min-height);
}

/* Override existing binder card styles */
.binder-card {
    min-height: var(--card-min-height);
}

/* Override existing collection card styles */
.collection-card {
    min-height: var(--card-min-height);
}

/* Override existing card item styles - REMOVED to avoid affecting cards.html */

/* ========================================
   FORCE UNIFIED LAYOUT
   ======================================== */

/* Ensure all cards have the same structure - EXCLUDE cards.html cards */
.deck-card,
.binder-card,
.collection-card {
    display: flex;
    flex-direction: column;
    min-height: 300px;
    padding: 20px;
}

.card-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

/* Ensure consistent button styling */
.btn-primary,
.btn-secondary,
.btn-outline {
    min-height: 36px;
    font-size: 14px;
    font-weight: 500;
}

.btn-outline {
    min-width: 36px;
    padding: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ========================================
   CARD COLORS AND VALIDITY
   ======================================== */

.card-colors {
    display: flex;
    gap: 6px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.color-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 500;
    color: white;
    text-decoration: none;
}

.color-badge.red { background: rgba(255, 107, 107, 0.9); }
.color-badge.blue { background: rgba(78, 205, 196, 0.9); }
.color-badge.green { background: rgba(86, 171, 47, 0.9); }
.color-badge.white { background: rgba(160, 160, 160, 0.9); color: #333; }
.color-badge.colorless { background: rgba(99, 99, 99, 0.9); }

.card-validity {
    font-size: 0.75rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 4px;
    margin-bottom: 12px;
    padding: 6px 10px;
    border-radius: 6px;
    background: rgba(0, 0, 0, 0.05);
}

.card-validity.valid { 
    color: #10b981;
    background: rgba(16, 185, 129, 0.1);
}

.card-validity.invalid { 
    color: #ef4444;
    background: rgba(239, 68, 68, 0.1);
}

.card-public {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 500;
    color: white;
    background: #10b981;
    margin-bottom: 8px;
}

/* ========================================
   BINDER TAGS AND SPECIAL ELEMENTS
   ======================================== */

.binder-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}

.binder-tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 500;
    color: white;
    text-decoration: none;
}

.collection-binders {
    margin-top: 12px;
}

.collection-binders strong {
    font-size: 0.875rem;
    color: #374151;
    display: block;
    margin-bottom: 6px;
}

.collection-default {
    display: inline-block;
    background: #10b981;
    color: white;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 500;
    margin-left: 8px;
}

.binder-public {
    display: inline-block;
    background: #3b82f6;
    color: white;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 500;
    margin-left: 8px;
}

/* ========================================
   ADD-CARDS FILTERS: COST CIRCLES (All pill)
   ======================================== */

.cost-circles {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.cost-circle[data-cost=""] {
    width: auto;
    padding: 0 10px;
    border-radius: 14px;
    white-space: nowrap;
}

@media (max-width: 1024px) {
    .cost-circle:not([data-cost=""]) { width: 24px; height: 24px; font-size: 10px; }
    .cost-circle[data-cost=""] { padding: 0 8px; }
}

@media (max-width: 768px) {
    .cost-circles { 
        flex-wrap: nowrap; 
        overflow-x: auto; 
        -webkit-overflow-scrolling: touch; 
        gap: 4px; 
        justify-content: flex-start;
    }
    .cost-circle:not([data-cost=""]) { width: 24px; height: 24px; font-size: 9px; }
}

/* ========================================
   UTILITY CLASSES
   ======================================== */

.card-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: var(--card-min-height);
    color: var(--card-meta-color);
}

.card-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: var(--card-min-height);
    color: var(--card-meta-color);
    text-align: center;
    padding: var(--card-padding);
}

.card-empty i {
    font-size: 2rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.card-empty h3 {
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
    color: #374151;
}

.card-empty p {
    font-size: 0.875rem;
    margin: 0;
}

/* ========================================
   ANCHORED MODAL (Cards page)
   ======================================== */

/* Scope to the specific modal to avoid affecting others */
#addToCollectionModal.modal--anchored {
    /* keep overlay behavior */
}

#addToCollectionModal.modal--anchored .modal-content {
    position: absolute;
    margin: 0; /* override centered margin */
    top: var(--anchor-top, 0px);
    left: var(--anchor-left, 50%);
    transform: translateX(-50%);
    max-height: min(80vh, 520px);
    overflow: auto;
}

/* Ensure it stays usable on narrow screens */
@media (max-width: 768px) {
    #addToCollectionModal.modal--anchored .modal-content {
        left: 50%;
        top: 12vh;
        transform: translateX(-50%);
        width: 92%;
        max-height: 76vh;
    }
}

/* ========================================
   ADD-CARDS FILTERS: LEVEL CIRCLES
   ======================================== */

.level-circles {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.level-circle {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.5);
    background: rgba(255, 255, 255, 0.1);
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
    color: white;
    backdrop-filter: blur(10px);
}

.level-circle:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
}

.level-circle.active {
    background: rgba(255, 255, 255, 0.3);
    border-color: #ffd700;
    box-shadow: 0 0 0 2px rgba(255, 215, 0, 0.3);
}

.level-circle[data-level=""] {
    width: auto;
    padding: 0 10px;
    border-radius: 14px;
    white-space: nowrap;
}

@media (max-width: 1024px) {
    .level-circle:not([data-level=""]) { width: 24px; height: 24px; font-size: 10px; }
    .level-circle[data-level=""] { padding: 0 8px; }
}

@media (max-width: 768px) {
    .level-circles { 
        flex-wrap: nowrap; 
        overflow-x: auto; 
        -webkit-overflow-scrolling: touch; 
        gap: 4px; 
        justify-content: flex-start;
    }
    .level-circle:not([data-level=""]) { width: 24px; height: 24px; font-size: 9px; }
}