/* features/static/features/css/front/media.css */
/* =============================================================
   Media tab of the card (features/front/media.html + includes/media_card.html)
   One tile design for every file type, the same language as the Gallery tab:
   rounded tile, preview on top, title/meta below, actions at the bottom.
   Tiles are scoped to #media; the viewer (.mf-viewer) is appended to <body>.
   ============================================================= */

#media {
    --mx-accent: var(--primary-color, #0d6efd);
    --mx-accent-soft: color-mix(in srgb, var(--mx-accent) 12%, #fff);
    --mx-border: #e9ecef;
    --mx-muted: #6c757d;
    --mx-radius: 12px;
}

/* ---------- toolbar ---------- */
#media .section-title {
    flex-wrap: wrap;
    gap: 8px;
}

#media .media-controls {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-inline-start: auto;
}

#media .media-type-filter {
    width: auto;
    max-width: 160px;
    font-size: 0.78rem;
    padding-block: 0.3rem;
    padding-inline: 0.75rem 2rem;
    border-radius: 999px;
    border-color: var(--mx-border);
}

[dir="rtl"] #media .media-type-filter {
    background-position: left 0.6rem center;
}

/* ---------- category chips ---------- */
#media .media-chips {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    scrollbar-width: none;
    padding: 2px 0 10px;
}

#media .media-chips::-webkit-scrollbar {
    display: none;
}

#media .media-chip {
    flex: 0 0 auto;
    padding: 5px 12px;
    border: 1px solid var(--mx-border);
    border-radius: 999px;
    background: #fff;
    color: inherit;
    font-size: 0.78rem;
    white-space: nowrap;
}

#media .media-chip span {
    color: var(--mx-muted);
    font-size: 0.7rem;
}

#media .media-chip.active {
    border-color: var(--mx-accent);
    background: var(--mx-accent-soft);
    color: var(--mx-accent);
    font-weight: 600;
}

#media .media-chip:focus {
    outline: none;
}

#media .media-chip:focus-visible {
    outline: 2px solid var(--mx-accent);
    outline-offset: 2px;
}

/* ---------- grid ---------- */
#media .media-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

#media .media-item-wrapper[hidden] {
    display: none !important;
}

@media (max-width: 420px) {
    #media .media-grid {
        grid-template-columns: minmax(0, 1fr);
    }
}

/* ---------- tile ---------- */
#media .mf-card {
    position: relative;
    display: flex;
    flex-direction: column;
    height: 100%;
    border: 1px solid var(--mx-border);
    border-radius: var(--mx-radius);
    background: #fff;
    overflow: hidden;
    transition: box-shadow 0.2s ease, transform 0.2s ease;
}

#media .mf-card:hover {
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.08);
}

#media .mf-card.is-featured {
    border-color: #ffb648;
}

#media .mf-card.just-unlocked {
    animation: mf-pop 0.35s ease;
}

@keyframes mf-pop {
    from { transform: scale(0.97); opacity: 0.4; }
    to { transform: none; opacity: 1; }
}

/* preview */
#media .mf-preview {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    aspect-ratio: 16 / 10;
    padding: 0;
    border: 0;
    background: #f4f6f8;
    cursor: pointer;
    overflow: hidden;
}

#media .mf-preview:disabled,
#media div.mf-preview {
    cursor: default;
}

#media .mf-preview:focus {
    outline: none;
}

#media .mf-preview:focus-visible {
    outline: 2px solid var(--mx-accent);
    outline-offset: -2px;
}

#media .mf-preview img {
    position: absolute;
    inset: 0;
    z-index: 1;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

#media button.mf-preview:hover img {
    transform: scale(1.04);
}

#media .mf-type-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 52px;
    height: 52px;
    border-radius: 14px;
    font-size: 1.5rem;
    background: var(--mx-accent-soft);
    color: var(--mx-accent);
}

#media .mf-type-pdf { background: #fdecec; color: #d63939; }
#media .mf-type-video { background: #eaf1ff; color: #2f6fed; }
#media .mf-type-audio { background: #f3ecff; color: #7b4fe0; }
#media .mf-type-image { background: #e8f7ef; color: #1f9d55; }
#media .mf-type-spreadsheet { background: #e8f7ef; color: #1d7a46; }
#media .mf-type-presentation { background: #fff1e6; color: #e8590c; }
#media .mf-type-archive { background: #f1f3f5; color: #495057; }

#media .is-locked .mf-type-icon {
    background: #fff4db;
    color: #c88a00;
}

#media .mf-play,
#media .mf-zoom {
    position: absolute;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.55);
    color: #fff;
    font-size: 0.95rem;
    backdrop-filter: blur(4px);
    transition: transform 0.2s ease;
}

#media .mf-zoom {
    width: 34px;
    height: 34px;
    font-size: 0.8rem;
    opacity: 0;
}

#media .mf-preview:hover .mf-zoom,
#media .mf-preview:focus-visible .mf-zoom {
    opacity: 1;
}

#media .mf-preview:hover .mf-play {
    transform: scale(1.08);
}

#media .mf-play i {
    margin-inline-start: 2px;
}

#media .mf-type-badge,
#media .mf-unlocked-badge,
#media .mf-featured {
    position: absolute;
    z-index: 3;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 0.65rem;
    font-weight: 600;
    line-height: 1.6;
}

#media .mf-type-badge {
    top: 8px;
    inset-inline-start: 8px;
    background: rgba(255, 255, 255, 0.92);
    color: #343a40;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

#media .mf-unlocked-badge {
    top: 8px;
    inset-inline-end: 8px;
    background: #1f9d55;
    color: #fff;
}

#media .mf-featured {
    top: 8px;
    inset-inline-end: 8px;
    background: #ff9900;
    color: #fff;
}

#media .mf-unlocked-badge + .mf-featured,
#media .mf-card:has(.mf-unlocked-badge) .mf-featured {
    inset-inline-end: 40px;
}

/* body */
#media .mf-body {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 4px;
    padding: 10px 12px 12px;
}

#media .mf-title {
    margin: 0;
    font-size: 0.85rem;
    font-weight: 600;
    line-height: 1.35;
    color: var(--dark-color, #212529);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    unicode-bidi: plaintext;
}

#media .mf-desc {
    margin: 0;
    font-size: 0.75rem;
    line-height: 1.5;
    color: var(--mx-muted);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    unicode-bidi: plaintext;
}

#media .mf-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 2px 10px;
    font-size: 0.68rem;
    color: var(--mx-muted);
}

#media .mf-meta i,
#media .mf-expiry i,
#media .mf-unlock-title i,
#media .mf-hint i {
    margin-inline-end: 4px;
    opacity: 0.8;
}

#media .mf-expiry {
    font-size: 0.68rem;
    color: #b45309;
}

/* actions */
#media .mf-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    margin-top: auto;
    padding-top: 8px;
}

#media .mf-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 32px;
    padding: 5px 12px;
    border: 1px solid var(--mx-border);
    border-radius: 8px;
    background: #fff;
    color: #343a40;
    font-size: 0.75rem;
    font-weight: 500;
    line-height: 1.2;
    text-decoration: none;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

#media .mf-btn:hover {
    border-color: var(--mx-accent);
    color: var(--mx-accent);
}

#media .mf-btn-primary {
    flex: 1;
    border-color: var(--mx-accent);
    background: var(--mx-accent);
    color: var(--on-primary, #fff);
}

#media .mf-btn-primary:hover {
    background: color-mix(in srgb, var(--mx-accent) 88%, #000);
    color: var(--on-primary, #fff);
}

#media .mf-btn-icon {
    flex: 0 0 auto;
    width: 32px;
    padding: 0;
}

#media .mf-btn.copied {
    border-color: #1f9d55;
    color: #1f9d55;
}

#media .mf-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

#media .mf-note {
    font-size: 0.68rem;
    color: var(--mx-muted);
}

/* unlock form */
#media .mf-unlock {
    margin-top: auto;
    padding-top: 8px;
}

#media .mf-unlock-title {
    margin: 0 0 6px;
    font-size: 0.72rem;
    color: #8a6d00;
}

#media .mf-hint {
    margin: 0 0 6px;
    padding: 4px 8px;
    border-radius: 6px;
    background: #fff8e1;
    font-size: 0.7rem;
    color: #6d5a00;
}

#media .mf-unlock-row {
    display: flex;
    gap: 6px;
}

#media .mf-unlock-row .form-control {
    flex: 1;
    min-width: 0;
    border-radius: 8px;
    font-size: 0.8rem;
}

#media .mf-unlock-row .mf-btn-primary {
    flex: 0 0 auto;
}

#media .mf-error {
    margin-top: 6px;
    padding: 5px 8px;
    border-radius: 6px;
    background: #fdecec;
    color: #b42318;
    font-size: 0.7rem;
}

#media .mf-unlock.shake {
    animation: mf-shake 0.4s ease;
}

@keyframes mf-shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

/* ---------- list view ---------- */
#media .media-grid.list-view {
    grid-template-columns: minmax(0, 1fr);
}

#media .media-grid.list-view .mf-card {
    flex-direction: row;
}

#media .media-grid.list-view .mf-preview {
    flex: 0 0 120px;
    width: 120px;
    aspect-ratio: auto;
    min-height: 100%;
}

#media .media-grid.list-view .mf-type-badge,
#media .media-grid.list-view .mf-zoom {
    display: none;
}

/* ---------- viewer (appended to <body>) ---------- */
html.mf-viewer-open,
html.mf-viewer-open body {
    overflow: hidden;
}

.mf-viewer {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.mf-viewer[hidden] {
    display: none;
}

.mf-viewer-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(10, 12, 16, 0.85);
    backdrop-filter: blur(3px);
}

.mf-viewer-panel {
    position: relative;
    display: flex;
    flex-direction: column;
    width: min(960px, 100%);
    max-height: 100%;
    border-radius: 14px;
    background: #111;
    color: #fff;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.mf-viewer-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.mf-viewer-title {
    flex: 1;
    min-width: 0;
    margin: 0;
    font-size: 0.95rem;
    font-weight: 600;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    unicode-bidi: plaintext;
}

.mf-viewer-actions {
    display: flex;
    gap: 6px;
}

.mf-viewer-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 34px;
    padding: 0 12px;
    border: 0;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    font-size: 0.78rem;
    text-decoration: none;
    cursor: pointer;
}

.mf-viewer-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
}

.mf-viewer-btn[hidden] {
    display: none;
}

.mf-viewer-close {
    width: 34px;
    justify-content: center;
    padding: 0;
}

@media (max-width: 575px) {
    .mf-viewer {
        padding: 0;
    }

    .mf-viewer-panel {
        height: 100%;
        border-radius: 0;
    }

    .mf-viewer-btn span {
        display: none;
    }

    .mf-viewer-btn {
        width: 34px;
        justify-content: center;
        padding: 0;
    }
}

.mf-viewer-body {
    position: relative;
    display: flex;
    flex: 1;
    align-items: center;
    justify-content: center;
    min-height: 200px;
    background: #000;
    overflow: auto;
}

.mf-viewer-body video,
.mf-viewer-body img {
    display: block;
    max-width: 100%;
    max-height: calc(100vh - 120px);
    margin: auto;
}

.mf-viewer-body iframe {
    width: 100%;
    height: calc(100vh - 120px);
    border: 0;
    background: #fff;
}

.mf-viewer-body.kind-embed iframe {
    height: auto;
    aspect-ratio: 16 / 9;
    background: #000;
}

.mf-viewer-body.kind-audio {
    flex-direction: column;
    gap: 18px;
    padding: 32px 16px;
    background: linear-gradient(160deg, #2b1d52, #111);
}

.mf-viewer-audio-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 96px;
    height: 96px;
    border-radius: 24px;
    background: rgba(255, 255, 255, 0.1);
    font-size: 2.4rem;
}

.mf-viewer-body audio {
    width: min(480px, 100%);
}

.mf-viewer-body.kind-text {
    align-items: stretch;
    background: #fff;
}

.mf-viewer-body pre {
    width: 100%;
    max-height: calc(100vh - 120px);
    margin: 0;
    padding: 16px;
    color: #212529;
    font-size: 0.8rem;
    white-space: pre-wrap;
    word-break: break-word;
}

.mf-viewer-message {
    padding: 32px 20px;
    color: rgba(255, 255, 255, 0.8);
    text-align: center;
    font-size: 0.9rem;
}

/* PDF on phones: message + one big button instead of an empty frame */
.mf-viewer-body.kind-stack {
    flex-direction: column;
    gap: 6px;
    padding-bottom: 32px;
}

.mf-viewer-btn.mf-viewer-cta {
    height: 44px;
    width: auto;
    padding: 0 20px;
    background: var(--primary-color, #0d6efd);
}

.mf-viewer-btn.mf-viewer-cta span {
    display: inline;
}

/* share notice ("Link copied" / link to copy by hand), appended to <body> */
.mf-toast {
    position: fixed;
    inset-inline: 16px;
    bottom: calc(76px + env(safe-area-inset-bottom, 0px));  /* above the card's bottom navigation */
    z-index: 2100;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 420px;
    margin-inline: auto;
    padding: 12px 16px;
    border-radius: 12px;
    background: #1f2328;
    color: #fff;
    font-size: 0.85rem;
    text-align: center;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
    opacity: 0;
    transform: translateY(12px);
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.mf-toast.show {
    opacity: 1;
    transform: none;
    pointer-events: auto;
}

.mf-toast-link {
    width: 100%;
    padding: 6px 10px;
    border: 0;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    font-size: 0.8rem;
}
