/**
 * MotionFy Gallery Page Styles
 * 
 * Grid layout for projects with detail modal.
 * Follows the same design tokens as create.css.
 */

/* ============================================================
   CRITICAL: Ensure hidden attribute always works
   ============================================================ */
[hidden] {
    display: none !important;
}

/* ============================================================
   Gallery Layout
   ============================================================ */

.mf-gallery {
    max-width: 1200px;
    margin: 0 auto;
    padding: 32px 20px;
}

.mf-gallery__header {
    margin-bottom: 32px;
}

.mf-gallery__title {
    margin: 0;
    font-size: 28px;
    font-weight: 600;
    color: var(--text-primary);
}

.mf-gallery__subtitle {
    margin: 8px 0 0;
    font-size: 15px;
    color: var(--text-secondary);
}

/* Active navigation link */
.mf-header__link--active {
    color: var(--text-primary);
    font-weight: 500;
}

/* ============================================================
   Empty State
   ============================================================ */

/* CRITICAL: hidden attribute must work - never show unless explicitly visible */
.mf-gallery__empty[hidden] {
    display: none !important;
}

.mf-gallery__empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 80px 20px;
    text-align: center;
}

.mf-gallery__empty-icon {
    width: 80px;
    height: 80px;
    color: var(--text-muted);
    margin-bottom: 24px;
}

.mf-gallery__empty-icon svg {
    width: 100%;
    height: 100%;
}

.mf-gallery__empty-title {
    margin: 0 0 8px;
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
}

.mf-gallery__empty-desc {
    margin: 0 0 24px;
    font-size: 15px;
    color: var(--text-secondary);
}

/* ============================================================
   Gallery Grid
   ============================================================ */

.mf-gallery__grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 24px;
}

/* CRITICAL: hidden attribute must work */
.mf-gallery__more[hidden] {
    display: none !important;
}

.mf-gallery__more {
    display: flex;
    justify-content: center;
    margin-top: 40px;
}

/* ============================================================
   Project Card (Tile)
   ============================================================ */

.mf-project-card {
    position: relative;
    background: var(--surface);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-md);
    overflow: hidden;
    cursor: pointer;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.mf-project-card:hover {
    border-color: #CBD5E1;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.mf-project-card__preview {
    position: relative;
    aspect-ratio: 16 / 9;
    background: #0a0a0a; /* Dark background for letterboxing */
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Light mode background for letterboxing */
html:not(.theme-dark) .mf-project-card__preview,
body:not(.theme-dark) .mf-project-card__preview {
    background: #e8eaed;
}

.mf-project-card__image {
    width: 100%;
    height: 100%;
    object-fit: contain; /* Show full image, letterbox/pillarbox as needed */
    transition: transform 0.3s ease;
}

.mf-project-card:hover .mf-project-card__image {
    transform: scale(1.02);
}

/* Video badge */
.mf-project-card__badge {
    position: absolute;
    bottom: 8px;
    right: 8px;
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    font-size: 11px;
    font-weight: 500;
    border-radius: 4px;
    backdrop-filter: blur(4px);
}

.mf-project-card__badge-icon {
    width: 12px;
    height: 12px;
}

.mf-project-card__info {
    padding: 14px 16px;
}

.mf-project-card__type {
    margin: 0;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
}

.mf-project-card__date {
    margin: 4px 0 0;
    font-size: 12px;
    color: var(--text-muted);
}

/* ============================================================
   Modal
   ============================================================ */

.mf-modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.mf-modal[hidden] {
    display: none;
}

.mf-modal__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
}

.mf-modal__container {
    position: relative;
    width: 100%;
    max-width: 900px;
    max-height: calc(100vh - 40px);
    background: var(--surface);
    border-radius: var(--radius-lg);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.mf-modal__content {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

/* ============================================================
   Project Detail (Modal Content)
   ============================================================ */

.mf-detail {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.mf-detail__header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}

.mf-detail__title {
    margin: 0;
    font-size: 24px;
    font-weight: 600;
    color: var(--text-primary);
}

.mf-detail__close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: transparent;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    color: var(--text-muted);
    transition: background var(--transition-fast), color var(--transition-fast);
}

.mf-detail__close:hover {
    background: var(--bg-subtle);
    color: var(--text-primary);
}

.mf-detail__close svg {
    width: 20px;
    height: 20px;
}

/* Preview Section */
.mf-detail__preview {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.mf-detail__media {
    position: relative;
    aspect-ratio: 16 / 9;
    background: #0a0a0a; /* Dark background for letterboxing */
    border-radius: var(--radius-md);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Light mode background for letterboxing in detail view */
html:not(.theme-dark) .mf-detail__media,
body:not(.theme-dark) .mf-detail__media {
    background: #e8eaed;
}

.mf-detail__image,
.mf-detail__video {
    width: 100%;
    height: 100%;
    object-fit: contain; /* Show full content, letterbox/pillarbox as needed */
    background: transparent;
}

.mf-detail__video-select {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.mf-detail__video-thumb {
    position: relative;
    width: 80px;
    height: 45px;
    background: var(--bg-subtle);
    border: 2px solid var(--border-soft);
    border-radius: var(--radius-sm);
    overflow: hidden;
    cursor: pointer;
    transition: border-color var(--transition-fast);
}

.mf-detail__video-thumb:hover {
    border-color: #CBD5E1;
}

.mf-detail__video-thumb--active {
    border-color: var(--brand-accent);
}

.mf-detail__video-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.mf-detail__video-thumb-label {
    position: absolute;
    bottom: 2px;
    left: 2px;
    right: 2px;
    padding: 2px 4px;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    font-size: 9px;
    text-align: center;
    border-radius: 2px;
}

/* Recipe Section */
.mf-detail__recipe {
    background: var(--bg-subtle);
    border-radius: var(--radius-md);
    padding: 20px;
}

.mf-detail__recipe-title {
    margin: 0 0 16px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.mf-detail__recipe-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
}

@media (min-width: 600px) {
    .mf-detail__recipe-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

.mf-detail__recipe-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.mf-detail__recipe-label {
    font-size: 11px;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.mf-detail__recipe-value {
    font-size: 14px;
    color: var(--text-primary);
    font-weight: 500;
}

/* Starter plan notice */
.mf-detail__plan-notice {
    padding: 16px;
    background: var(--bg-subtle);
    border-radius: var(--radius-md);
    text-align: center;
}

.mf-detail__plan-notice p {
    margin: 0;
    font-size: 13px;
    color: var(--text-secondary);
}

/* Actions Section */
.mf-detail__actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding-top: 16px;
    border-top: 1px solid var(--border-soft);
}

.mf-detail__action {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 16px;
    background: var(--surface);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-md);
    cursor: pointer;
    text-align: left;
    transition: border-color var(--transition-fast), background var(--transition-fast);
}

.mf-detail__action:hover:not(:disabled) {
    border-color: #CBD5E1;
    background: var(--bg-subtle);
}

.mf-detail__action:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.mf-detail__action-icon {
    width: 24px;
    height: 24px;
    color: var(--brand-accent);
    flex-shrink: 0;
}

.mf-detail__action-content {
    flex: 1;
}

.mf-detail__action-title {
    margin: 0;
    font-size: 15px;
    font-weight: 500;
    color: var(--text-primary);
}

.mf-detail__action-desc {
    margin: 4px 0 0;
    font-size: 13px;
    color: var(--text-secondary);
}

.mf-detail__action-cost {
    font-size: 13px;
    font-weight: 500;
    color: var(--brand-accent);
    margin-left: auto;
    white-space: nowrap;
}

/* ============================================================
   Dark Mode - Complete Coverage
   ============================================================ */

/* Gallery titles and text */
html.theme-dark .mf-gallery__title,
body.theme-dark .mf-gallery__title {
    color: #f2f2f2;
}

html.theme-dark .mf-gallery__subtitle,
body.theme-dark .mf-gallery__subtitle {
    color: #a0a0a0;
}

/* Project cards */
html.theme-dark .mf-project-card,
body.theme-dark .mf-project-card {
    background: #1a1a1a;
    border-color: #3a3a3a;
}

html.theme-dark .mf-project-card:hover,
body.theme-dark .mf-project-card:hover {
    border-color: #505050;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

html.theme-dark .mf-project-card__preview,
body.theme-dark .mf-project-card__preview {
    background: #252525;
}

html.theme-dark .mf-project-card__type,
body.theme-dark .mf-project-card__type {
    color: #f2f2f2;
}

html.theme-dark .mf-project-card__date,
body.theme-dark .mf-project-card__date {
    color: #888;
}

/* Modal */
html.theme-dark .mf-modal__backdrop,
body.theme-dark .mf-modal__backdrop {
    background: rgba(0, 0, 0, 0.7);
}

html.theme-dark .mf-modal__container,
body.theme-dark .mf-modal__container {
    background: #1a1a1a;
}

html.theme-dark .mf-detail__title,
body.theme-dark .mf-detail__title {
    color: #f2f2f2;
}

html.theme-dark .mf-detail__close,
body.theme-dark .mf-detail__close {
    color: #888;
}

html.theme-dark .mf-detail__close:hover,
body.theme-dark .mf-detail__close:hover {
    background: #252525;
    color: #f2f2f2;
}

html.theme-dark .mf-detail__media,
body.theme-dark .mf-detail__media {
    background: #0a0a0a;
}

html.theme-dark .mf-detail__recipe,
body.theme-dark .mf-detail__recipe {
    background: #252525;
}

html.theme-dark .mf-detail__recipe-title,
body.theme-dark .mf-detail__recipe-title {
    color: #f2f2f2;
}

html.theme-dark .mf-detail__recipe-label,
body.theme-dark .mf-detail__recipe-label {
    color: #888;
}

html.theme-dark .mf-detail__recipe-value,
body.theme-dark .mf-detail__recipe-value {
    color: #f2f2f2;
}

html.theme-dark .mf-detail__plan-notice,
body.theme-dark .mf-detail__plan-notice {
    background: #252525;
}

html.theme-dark .mf-detail__actions,
body.theme-dark .mf-detail__actions {
    border-top-color: #3a3a3a;
}

html.theme-dark .mf-detail__action,
body.theme-dark .mf-detail__action {
    background: #1a1a1a;
    border-color: #3a3a3a;
}

html.theme-dark .mf-detail__action:hover:not(:disabled),
body.theme-dark .mf-detail__action:hover:not(:disabled) {
    background: #252525;
    border-color: #505050;
}

html.theme-dark .mf-detail__action-title,
body.theme-dark .mf-detail__action-title {
    color: #f2f2f2;
}

html.theme-dark .mf-detail__action-desc,
body.theme-dark .mf-detail__action-desc {
    color: #a0a0a0;
}

/* Video thumbnails */
html.theme-dark .mf-detail__video-thumb,
body.theme-dark .mf-detail__video-thumb {
    background: #252525;
    border-color: #3a3a3a;
}

html.theme-dark .mf-detail__video-thumb:hover,
body.theme-dark .mf-detail__video-thumb:hover {
    border-color: #505050;
}

/* Loading states */
html.theme-dark .mf-spinner,
body.theme-dark .mf-spinner {
    border-color: #3a3a3a;
    border-top-color: var(--brand-accent, #6366f1);
}

html.theme-dark .mf-detail__loading-text,
body.theme-dark .mf-detail__loading-text {
    color: #a0a0a0;
}

html.theme-dark .mf-detail__error-icon,
body.theme-dark .mf-detail__error-icon {
    color: #666;
}

/* Empty state */
html.theme-dark .mf-gallery__empty,
body.theme-dark .mf-gallery__empty {
    color: #a0a0a0;
}

html.theme-dark .mf-gallery__empty-icon,
body.theme-dark .mf-gallery__empty-icon {
    color: #555;
}

html.theme-dark .mf-gallery__empty-title,
body.theme-dark .mf-gallery__empty-title {
    color: #f2f2f2;
}

html.theme-dark .mf-gallery__empty-desc,
body.theme-dark .mf-gallery__empty-desc {
    color: #a0a0a0;
}

/* ============================================================
   Loading Spinner
   ============================================================ */

.mf-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-soft, #e2e8f0);
    border-top-color: var(--brand-accent, #6366f1);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.mf-spinner--large {
    width: 48px;
    height: 48px;
    border-width: 4px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.mf-gallery__loading {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 80px 20px;
    grid-column: 1 / -1;
}

/* Modal Loading State - Full centered */
.mf-detail--loading {
    min-height: 400px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.mf-detail__close--loading {
    position: absolute;
    top: 16px;
    right: 16px;
    z-index: 10;
}

.mf-detail__loading-center {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    text-align: center;
}

.mf-detail__loading-text {
    margin: 0;
    font-size: 14px;
    color: var(--text-secondary);
}

.mf-detail__error-icon {
    width: 48px;
    height: 48px;
    color: var(--text-muted);
}

.mf-detail__loading {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 80px 20px;
}

.mf-detail__error {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 40px 20px;
    color: var(--text-secondary);
}

/* ============================================================
   Empty State (updated for state machine)
   ============================================================ */

.mf-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 40px 20px;
}

.mf-empty__title {
    margin: 0;
    font-size: 18px;
    font-weight: 500;
    color: var(--text-primary);
}

.mf-empty__text {
    margin: 8px 0 24px;
    font-size: 14px;
    color: var(--text-secondary);
}

/* ============================================================
   Responsive
   ============================================================ */

@media (min-width: 768px) {
    .mf-gallery {
        padding: 48px 32px;
    }
    
    .mf-gallery__title {
        font-size: 32px;
    }
    
    .mf-modal__container {
        max-width: 1000px;
    }
    
    .mf-detail__actions {
        flex-direction: row;
    }
    
    .mf-detail__action {
        flex: 1;
    }
}
