/* Magazine Cards Pro Styles */

.magazine-card {
    width: 100%;
    min-width: 280px; /* open width with a sensible minimum */
    min-height: 380px; /* minimum height as a baseline */
    height: var(--mc-card-height, auto); /* open height */
    margin: 20px auto;
    background: var(--mc-bg, #fff);
    border-radius: var(--mc-radius, 12px);
    box-shadow: var(--mc-shadow, 0 4px 16px rgba(0, 0, 0, 0.1));
    overflow: hidden;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    font-family: var(--mc-font, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif);
}

.magazine-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}

.magazine-card-inner {
    display: flex;
    flex-direction: column;
}

.magazine-cover {
    position: relative;
    width: 100%;
    height: var(--mc-cover-height, auto);
    aspect-ratio: 3 / 4; /* balanced portrait, not exaggerated */
    overflow: hidden;
    background: #f5f5f5;
}

.magazine-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.magazine-card:hover .magazine-cover img {
    transform: scale(1.05);
}

.magazine-info {
    padding: 20px;
    padding-bottom: 22px !important; /* fixed space to bottom */
    text-align: center;
    display: flex !important; /* enforce flex even if older CSS exists */
    flex-direction: column;
    flex: 1 1 auto;
}

.magazine-title {
    margin: 0 0 10px 0;
    font-size: 18px;
    font-weight: 600;
    color: var(--mc-fg, #333);
    line-height: 1.4;
    /* Reserve exactly two lines of space; clamp overflow to 2 lines */
    min-height: calc(1.4em * 2);
    max-height: calc(1.4em * 2);
    display: -webkit-box;
    line-clamp: 2;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.magazine-date {
    margin: 0 0 15px 0;
    font-size: 14px;
    color: var(--mc-fg, #666);
    font-style: italic;
}

.magazine-button {
    display: inline-block;
    padding: 12px 24px;
    background: var(--mc-btn-bg, linear-gradient(135deg, #667eea 0%, #764ba2 100%));
    color: var(--mc-btn-fg, #fff);
    text-decoration: none;
    border-radius: 25px;
    font-weight: 500;
    font-size: 14px;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
    margin-bottom: 0 !important; /* anchor button to bottom of info */
}

.magazine-button:hover {
    background: linear-gradient(135deg, #5a6fd8 0%, #6a4190 100%);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
    color: #fff;
    text-decoration: none;
}

.magazine-button:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.3);
}

/* Arabic-specific styles */
.magazine-card-ar {
    direction: rtl;
}

.magazine-card-ar .magazine-title {
    font-family: 'Segoe UI', 'Tahoma', 'Arial', sans-serif;
    font-weight: 700;
}

.magazine-card-ar .magazine-button {
    font-family: 'Segoe UI', 'Tahoma', 'Arial', sans-serif;
    direction: rtl;
}

/* French-specific styles */
.magazine-card-fr {
    direction: ltr;
}

.magazine-card-fr .magazine-title {
    font-weight: 600;
}

/* Magazine Grid Layout */
.magazine-cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 30px;
    padding: 20px 0;
    justify-items: center;
}

/* Full width for single card */
.magazine-cards-grid .magazine-card {
    width: 100%;
    max-width: none;
    margin: 0;
}

/* Responsive design */
@media (max-width: 768px) {
    .magazine-cards-grid {
        grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
        gap: 20px;
        padding: 15px;
    }
    
    .magazine-cover {
        height: var(--mc-cover-height, auto);
        aspect-ratio: 3 / 4;
    }
    
    .magazine-info {
        padding: 15px;
    }
    
    .magazine-title {
        font-size: 16px;
        margin-bottom: 8px;
    }
    
    .magazine-date {
        font-size: 13px;
        margin-bottom: 12px;
    }
    
    .magazine-button {
        padding: 10px 20px;
        font-size: 13px;
    }
}

@media (max-width: 480px) {
    .magazine-cards-grid {
        grid-template-columns: 1fr;
        gap: 15px;
        padding: 10px;
    }
    
    .magazine-card {
        max-width: 100%;
    }
    
    .magazine-cover {
        height: 160px;
    }
}

/* Large grid layout for multiple magazines */
@media (min-width: 1200px) {
    .magazine-cards-grid {
        grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
        max-width: 1200px;
        margin: 0 auto;
    }
}

/* Animation for loading */
.magazine-card.loading .magazine-cover {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading 2s infinite;
}

@keyframes loading {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

/* No magazines message */
.no-magazines-message {
    text-align: center;
    padding: 40px 20px;
    color: #666;
    font-style: italic;
    background: #f9f9f9;
    border-radius: 8px;
    margin: 20px 0;
}

/* Magazine categories filter */
.magazine-filter {
    text-align: center;
    margin: 20px 0;
}

.magazine-filter select {
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 5px;
    background: #fff;
    font-size: 14px;
}

/* Language indicator */
.magazine-language-badge {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(0, 0, 0, 0.7);
    color: #fff;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
}

.magazine-card-ar .magazine-language-badge {
    right: auto;
    left: 10px;
}

/* Print styles */
@media print {
    .magazine-card {
        break-inside: avoid;
        box-shadow: none;
        border: 1px solid #ddd;
        margin-bottom: 20px;
    }
    
    .magazine-button {
        background: #333 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    
    .magazine-cards-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 20px;
    }
}

/* Admin styles */
.magazine-upload-section {
    background: #f9f9f9;
    padding: 20px;
    border-radius: 5px;
    margin-top: 20px;
}

.selected-media {
    margin-top: 10px;
    padding: 10px;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 3px;
    display: none;
}

.selected-media.has-selection {
    display: block;
}

.selected-file {
    display: flex;
    align-items: center;
    gap: 10px;
}

.selected-file img {
    max-width: 60px;
    height: auto;
    border-radius: 3px;
}

.selected-file .dashicons {
    font-size: 40px;
    color: #666;
}

.selected-file .file-info {
    flex: 1;
}

.selected-file .file-info strong {
    display: block;
    margin-bottom: 5px;
}

.selected-file .file-id,
.selected-file .file-size {
    font-size: 12px;
    color: #666;
}

/* Magazine library table styles */
.magazine-library-table {
    margin-top: 20px;
}

.magazine-library-table .column-cover {
    width: 80px;
}

.magazine-library-table .column-language {
    width: 100px;
}

.magazine-library-table .column-date {
    width: 120px;
}

.magazine-library-table .column-actions {
    width: 100px;
}

/* Success/Error messages */
.magazine-notice {
    padding: 10px 15px;
    margin: 15px 0;
    border-radius: 4px;
    border-left: 4px solid;
}

.magazine-notice.success {
    background: #dff0d8;
    border-color: #5cb85c;
    color: #3c763d;
}

.magazine-notice.error {
    background: #f2dede;
    border-color: #d9534f;
    color: #a94442;
}

.magazine-notice.info {
    background: #d9edf7;
    border-color: #5bc0de;
    color: #31708f;
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .magazine-card {
        background: #2d2d2d;
        color: #fff;
    }
    
    .magazine-title {
        color: #fff;
    }
    
    .magazine-date {
        color: #ccc;
    }
    
    .no-magazines-message {
        background: #333;
        color: #ccc;
    }
}