/* ── File thumbnail grid, dropzone and lightbox ─────────────────────────── */

/* Safari ignores clicks on display:none file inputs, so they are clipped
   off-screen (sr-only) instead of display:none. */
.hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
}

.files-grid {
    display: grid;
    gap: var(--space-2);
}

.files-dropzone {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-3);
    border: 1px dashed var(--border-color);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: border-color var(--transition), background-color var(--transition);
}

.files-dropzone:hover {
    border-color: var(--accent);
}

[data-controller='files-dropzone'].is-dragover .files-dropzone {
    border-color: var(--accent);
    background-color: var(--primary-bg);
}

/* Inline tile variant: sits in the file grid among the file tiles, ready to
   take the place of the next added file. */
.files-dropzone--tile {
    flex-direction: column;
    justify-content: center;
    gap: var(--space-1);
    width: 100%;
    height: 100%;
    padding: var(--space-1);
}

.files-dropzone-icon {
    display: grid;
    place-items: center;
}

.files-dropzone-icon svg {
    width: 34px;
    height: 34px;
}

.files-dropzone-text {
    color: var(--text-muted);
    font-size: 0.85rem;
}

.file-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    grid-auto-rows: 120px;
    gap: var(--space-2);
}

.file-tile {
    position: relative;
}

.file-tile-name {
    position: absolute;
    right: 0;
    bottom: 0;
    left: 0;
    padding: var(--space-2);
    border-radius: 0 0 var(--radius-sm) var(--radius-sm);
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.78));
    color: var(--text-main);
    font-size: 0.75rem;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition);
}

.file-tile:hover .file-tile-name,
.file-tile:focus-within .file-tile-name {
    opacity: 1;
}

.file-thumb {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    padding: var(--space-1);
    border: none;
    border-radius: var(--radius-sm);
    overflow: hidden;
    background-color: var(--bg-panel);
    color: var(--text-muted);
    cursor: pointer;
    transition: opacity var(--transition);
}

a.file-thumb {
    text-decoration: none;
}

.file-thumb:hover {
    background-color: var(--bg-panel);
    opacity: 0.85;
}

.file-thumb-remove {
    position: absolute;
    top: var(--space-1);
    right: var(--space-1);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.5em;
    height: 1.5em;
    padding: 0;
    line-height: 1;
    color: var(--danger);
    background-color: var(--bg-panel);
    border: 1px solid var(--danger-border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    opacity: 0.85;
}

.file-thumb-remove:hover {
    background-color: var(--bg-panel);
    opacity: 1;
}

.file-thumb-remove svg {
    width: 0.9em;
    height: 0.9em;
    display: block;
}

.file-thumb-img {
    display: block;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.file-thumb-icon {
    display: grid;
    place-items: center;
    width: 100%;
    height: 100%;
}

.file-thumb-icon svg {
    width: 34px;
    height: 34px;
}

/* ── Lightbox ───────────────────────────────────────────────────────────── */

.file-lightbox {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1000;
    padding: var(--space-8);
    background-color: var(--shadow-backdrop);
    align-items: center;
    justify-content: center;
}

.file-lightbox.is-open {
    display: flex;
}

.file-lightbox-frame {
    position: relative;
    max-width: min(1100px, 94vw);
    max-height: 92vh;
    background-color: var(--bg-card);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    box-shadow: 0 20px 60px var(--shadow-dropdown);
}

.file-lightbox-bar {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2);
    border-bottom: 1px solid var(--border-color);
}

.file-lightbox-name {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-main);
    font-size: 0.9rem;
}

.file-lightbox-close {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    padding: 0;
    border: none;
    border-radius: 50%;
    background-color: var(--bg-hover);
    color: var(--text-main);
    cursor: pointer;
}

.file-lightbox-close:hover {
    background-color: var(--bg-accent);
}

.file-lightbox-close svg {
    width: 18px;
    height: 18px;
}

.file-lightbox-download {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background-color: var(--bg-panel);
    color: var(--text-main);
    text-decoration: none;
    font-size: 0.85rem;
}

.file-lightbox-download:hover {
    border-color: var(--primary);
    color: var(--primary-light);
}

/* The JS hides the download link when the trigger carries no URL. The
   author display rule above would otherwise override the UA's
   [hidden] { display: none }, leaving a dead '#' link visible. */
.file-lightbox-download[hidden] {
    display: none;
}

.file-lightbox-download svg {
    width: 16px;
    height: 16px;
}

.file-lightbox-body {
    padding: var(--space-4);
}

.file-lightbox-body img {
    display: block;
    margin: 0 auto;
    max-width: 100%;
    max-height: 82vh;
    object-fit: contain;
}

.file-lightbox-body iframe {
    display: block;
    width: min(1000px, 90vw);
    height: 82vh;
    border: none;
    background-color: #fff;
}

@media (max-width: 768px) {
    .file-lightbox {
        padding: var(--space-3);
    }
}
