/* ==========================================================================
 *  Media Library + Picker — minimal, polished, dense.
 *  Design tokens (only ones used; keep small):
 *    radius: 6px (tiles) / 8px (cards)
 *    accent: #2563eb
 *    gray:   #f3f4f6 #e5e7eb #9ca3af #6b7280 #374151 #1f2937
 *    danger: #dc2626 / hover #b91c1c
 *    timing: .12s ease
 * ========================================================================== */

/* ---------- Library: title bar ---------- */
.media-library-titlebar {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 12px; flex-wrap: wrap; gap: 8px;
}
.media-library-h1-count {
    background: #f3f4f6; color: #6b7280;
    font-size: 12px; font-weight: 500;
    padding: 2px 10px; border-radius: 12px;
}

/* ---------- Library: filter bar (sticky toolbar) ---------- */
.media-library-filterbar {
    position: sticky; top: 0; z-index: 1000;
    background: #fff;
    padding: 12px 0;
    margin-bottom: 12px;
    border: 0; border-radius: 0;
    display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
    justify-content: space-between;
    box-shadow: 0 2px 6px -2px rgba(15, 23, 42, .08);
}
/* Extend white background to .content-center edges (cover its 1.5rem padding) */
.media-library-filterbar::before {
    content: '';
    position: absolute;
    left: -1.5rem; right: -1.5rem;
    top: 0; bottom: 0;
    background: #fff;
    z-index: -1;
    box-shadow: 0 2px 6px -2px rgba(15, 23, 42, .08);
}
/* Normalize control heights inside the toolbar — theme overrides Bootstrap
 * heights inconsistently across input/select/btn. Force 36px uniform. */
.media-library-filterbar .form-control,
.media-library-filterbar .form-select,
.media-library-filterbar .btn,
.media-library-filterbar .input-group-text {
    height: 36px;
    min-height: 36px;
    padding-top: 4px;
    padding-bottom: 4px;
    font-size: 13px;
    line-height: 1;
    box-sizing: border-box;
}
.media-library-filterbar .input-group { height: 36px; }
.media-library-filterbar .btn-outline-secondary,
.media-library-filterbar .btn-outline-secondary:focus {
    color: #374151; background: #fff; border-color: #d1d5db;
}
.media-library-filterbar .btn-outline-secondary:hover,
.media-library-filterbar .btn-outline-secondary:active {
    color: #fff !important; background: #4b5563 !important; border-color: #4b5563 !important;
}

/* ---------- Library: grid + tile ---------- */
.media-library-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 10px;
}
.media-library-tile {
    position: relative; margin: 0;
    border: 1px solid #e5e7eb; border-radius: 6px;
    background: #fff; overflow: hidden;
    display: flex; flex-direction: column;
    transition: box-shadow .12s ease, transform .12s ease, border-color .12s ease;
}
.media-library-tile:hover {
    box-shadow: 0 4px 10px rgba(15, 23, 42, .08);
    transform: translateY(-1px);
}
.media-library-tile.is-selected {
    border-color: #2563eb;
    box-shadow: 0 0 0 2px #2563eb;
}
.media-library-thumb-wrap {
    width: 100%; aspect-ratio: 1/1;
    background: #f3f4f6;
    display: flex; align-items: center; justify-content: center;
    overflow: hidden;
}
.media-library-thumb { width: 100%; height: 100%; object-fit: cover; display: block; }
.media-library-thumb--broken {
    position: relative;
    background: repeating-linear-gradient(45deg, #e5e7eb 0 8px, #f3f4f6 8px 16px);
}
.media-library-thumb--broken::after {
    content: "✕"; position: absolute; inset: 0;
    display: flex; align-items: center; justify-content: center;
    color: #9ca3af; font-size: 24px;
}
.media-library-tile figcaption {
    padding: 6px 8px; min-height: 36px;
    display: flex; flex-direction: column; gap: 1px;
    font-size: 11px; line-height: 1.3;
}
.media-library-title {
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    font-weight: 500; color: #111827;
}
.media-library-meta { color: #6b7280; font-size: 10px; }

.media-library-actions {
    position: absolute; bottom: 38px; right: 4px;
    display: flex; gap: 3px;
    opacity: 0; transition: opacity .12s ease;
}
.media-library-tile:hover .media-library-actions,
.media-library-tile.is-selected .media-library-actions { opacity: 1; }
.media-library-actions .btn {
    padding: 4px 8px; line-height: 1; font-size: 12px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, .12);
}
.media-library-actions .btn-light,
.media-library-actions .btn-light:focus {
    color: #1f2937 !important; background: #fff !important; border-color: #e5e7eb !important;
}
.media-library-actions .btn-light:hover,
.media-library-actions .btn-light:active {
    color: #fff !important; background: #4b5563 !important; border-color: #4b5563 !important;
}
.media-library-actions .btn-danger:hover,
.media-library-actions .btn-danger:active {
    color: #fff !important; background: #b91c1c !important; border-color: #b91c1c !important;
}

.media-library-checkbox {
    position: absolute; top: 4px; left: 4px; z-index: 2; margin: 0;
    line-height: 0; cursor: pointer;
    opacity: 0; transition: opacity .12s ease;
}
.media-library-tile:hover .media-library-checkbox,
.media-library-tile.is-selected .media-library-checkbox { opacity: 1; }
.media-library-checkbox .form-check-input { margin: 0; cursor: pointer; }

body.media-picker-mode .media-library-filterbar [data-media-select-all],
body.media-picker-mode .media-library-filterbar [data-media-bulk-delete],
body.media-picker-mode .media-library-checkbox,
body.media-picker-mode .media-library-actions { display: none !important; }
body.media-picker-mode .media-library-tile { cursor: pointer; }
body.media-picker-mode .media-library-tile:hover { outline: 2px solid #2563eb; }

/* Picker mode (in iframe): hide admin layout chrome, content-right full width */
body.media-picker-mode > header,
body.media-picker-mode .content > .content-left,
body.media-picker-mode .content-right > footer,
body.media-picker-mode .breadcrumb-wrapper,
body.media-picker-mode .breadcrumb { display: none !important; }
body.media-picker-mode .content { display: block !important; padding: 8px !important; }
body.media-picker-mode .content-right { width: 100% !important; margin: 0 !important; }

.media-library-empty {
    padding: 64px 16px; text-align: center;
    color: #6b7280; background: #fff;
    border: 1px dashed #d1d5db; border-radius: 8px;
    font-size: 14px;
}

.media-picker-hint {
    margin-top: 8px;
    font-size: 12px;
    color: #2563eb;
    display: flex; flex-wrap: wrap; gap: 4px 12px;
    line-height: 1.4;
}
.media-picker-hint .text-muted { color: #6b7280 !important; }
.media-picker-hint .text-danger { color: #dc2626 !important; font-weight: 500; }

.media-picker--single .media-picker-slot {
    position: relative; cursor: pointer; overflow: hidden;
    width: 100%; max-width: 240px;
    border: 1px dashed #d1d5db; border-radius: 8px;
    background: #f9fafb; transition: border-color .12s ease, background-color .12s ease;
}
.media-picker--single .media-picker-slot:hover,
.media-picker--single .media-picker-slot.is-dragover {
    border-color: #2563eb; background: #eff6ff;
}
.media-picker--single .media-picker-slot.is-uploading {
    opacity: .65; cursor: progress;
}
.media-picker-selected.is-dragover,
.media-picker.is-dragover {
    outline: 2px dashed #2563eb; outline-offset: 4px;
    background: #eff6ff;
    border-radius: 8px;
}
.media-picker-slot-img { width: 100%; height: 100%; object-fit: cover; display: block; }
.media-picker-slot-empty {
    position: absolute; inset: 0;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
    color: #6b7280; font-size: 13px; pointer-events: none;
}
.media-picker-slot-empty i { font-size: 24px; color: #9ca3af; }
.media-picker-slot-actions {
    position: absolute; top: 6px; right: 6px;
    display: flex; gap: 4px;
    opacity: 0; transition: opacity .12s ease;
}
.media-picker-slot:hover .media-picker-slot-actions { opacity: 1; }
.media-picker-slot-actions .btn { padding: 4px 8px; box-shadow: 0 2px 4px rgba(0, 0, 0, .12); }
.media-picker-slot-actions .btn-light,
.media-picker-slot-actions .btn-light:focus {
    color: #1f2937 !important; background: #fff !important; border-color: #e5e7eb !important;
}
.media-picker-slot-actions .btn-light:hover,
.media-picker-slot-actions .btn-light:active {
    color: #fff !important; background: #4b5563 !important; border-color: #4b5563 !important;
}
.media-picker-slot-actions .btn-danger:hover,
.media-picker-slot-actions .btn-danger:active {
    color: #fff !important; background: #b91c1c !important; border-color: #b91c1c !important;
}

/* ---------- Picker: multi-image selected tiles ---------- */
.media-picker-selected {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: 10px;
    margin-top: 8px;
}
.media-picker-selected:empty { display: none; }
.media-picker-selected-tile {
    position: relative; aspect-ratio: 1/1;
    background-size: cover; background-position: center;
    background-color: #f3f4f6;
    border: 1px solid #e5e7eb; border-radius: 8px;
    cursor: grab; overflow: hidden;
}
.media-picker-selected-tile:active { cursor: grabbing; }
.media-picker-selected-order {
    position: absolute; top: 4px; left: 4px;
    display: inline-flex; align-items: center; justify-content: center;
    width: 22px; height: 22px; padding: 0;
    background: #2563eb; color: #fff;
    border-radius: 50%; font-size: 11px; font-weight: 600;
    line-height: 1;
    box-shadow: 0 1px 3px rgba(0, 0, 0, .15);
}
.media-picker-selected-tile .remove-btn {
    position: absolute; top: 4px; right: 4px;
    background: rgba(15, 23, 42, .75); color: #fff;
    border: 0; border-radius: 50%;
    width: 22px; height: 22px; line-height: 1; padding: 0;
    font-size: 14px; cursor: pointer;
}
.media-picker-selected-tile .remove-btn:hover { background: #dc2626; }

/* ---------- Picker: modal ---------- */
.media-picker-modal .modal-dialog { max-width: min(1100px, 95vw); }
.media-picker-modal .modal-body { padding: 16px 20px; }
.media-picker-modal .nav-tabs { border-bottom: 1px solid #e5e7eb; margin: 0; }
.media-picker-modal .nav-tabs .nav-link {
    border: 0; border-bottom: 2px solid transparent;
    color: #6b7280; padding: 10px 16px; background: none;
}
.media-picker-modal .nav-tabs .nav-link.active {
    color: #2563eb; border-bottom-color: #2563eb;
    background: none; font-weight: 600;
}

.media-picker-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 8px; min-height: 220px;
}

/* Picker modal: zero out modal-body padding so the sticky search bar can
 * hug the very top edge with no gap. Children restore their own spacing. */
.media-picker-modal .modal-body { padding: 0; }
.media-picker-modal .media-picker-search-bar {
    position: sticky;
    top: 0;
    z-index: 10;
    background: #fff;
    padding: 12px 1rem;
    margin-bottom: 12px;
    box-shadow: 0 2px 6px -2px rgba(15, 23, 42, .08);
}
.media-picker-modal [data-tab-panel="library"] > .media-picker-grid,
.media-picker-modal [data-tab-panel="library"] > [data-picker-sentinel],
.media-picker-modal [data-tab-panel="library"] > [data-picker-pagination-info] {
    padding-left: 1rem;
    padding-right: 1rem;
}
.media-picker-modal [data-tab-panel="library"] > [data-picker-pagination-info] {
    padding-bottom: 1rem;
}
.media-picker-modal [data-tab-panel="upload"] { padding: 1rem; }
.media-picker-status {
    grid-column: 1/-1; padding: 60px 12px; text-align: center; color: #6b7280;
}
.media-picker-cell {
    position: relative; aspect-ratio: 1/1;
    border: 2px solid transparent; border-radius: 8px;
    background-size: cover; background-position: center; background-color: #f3f4f6;
    cursor: pointer; overflow: hidden;
    transition: border-color .12s ease, transform .12s ease;
}
.media-picker-cell:hover { transform: translateY(-1px); }
.media-picker-cell.is-selected { border-color: #2563eb; }
.media-picker-cell.is-uploading { opacity: .65; cursor: default; }
.media-picker-cell .media-picker-check {
    position: absolute; top: 6px; right: 6px;
    width: 24px; height: 24px; border-radius: 50%;
    background: #fff; border: 2px solid #d1d5db;
    display: flex; align-items: center; justify-content: center;
    color: transparent; font-size: 14px; line-height: 1;
}
.media-picker-cell.is-selected .media-picker-check {
    background: #2563eb; border-color: #2563eb; color: #fff;
}
.media-picker-cell .media-picker-order {
    position: absolute; top: 6px; left: 6px;
    align-items: center; justify-content: center;
    width: 24px; height: 24px; padding: 0;
    background: #2563eb; color: #fff;
    border-radius: 50%; font-size: 11px; font-weight: 600;
    line-height: 1; display: none;
}
.media-picker-cell.is-selected .media-picker-order:not(:empty) { display: inline-flex; }

/* Failed-upload cell: keep tile in the grid with inline error so a multi-file
   batch shows every failed file independently — no toast overwrite. */
.media-picker-cell.is-error {
    border-color: #dc2626;
    background-image: none !important;
    background-color: #fef2f2;
    cursor: default;
}
.media-picker-cell.is-error:hover { transform: none; }
.media-picker-cell-error-overlay {
    position: absolute; inset: 0;
    padding: 6px;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 4px; text-align: center;
    color: #b91c1c;
}
.media-picker-cell-error-overlay i { font-size: 18px; }
.media-picker-cell-error-name {
    font-size: 10px; font-weight: 600;
    max-width: 100%;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.media-picker-cell-error-msg {
    font-size: 10px; line-height: 1.25;
    color: #7f1d1d;
    overflow: hidden;
    display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical;
}

.media-picker-dropzone {
    border: 2px dashed #d1d5db; border-radius: 8px;
    padding: 48px 24px; text-align: center;
    color: #6b7280; cursor: pointer;
    transition: border-color .15s ease, background-color .15s ease, color .15s ease;
}
.media-picker-dropzone:hover { border-color: #2563eb; color: #2563eb; }
.media-picker-dropzone.is-dragover { border-color: #2563eb; color: #2563eb; background: #eff6ff; }
.media-picker-dropzone-icon { font-size: 40px; line-height: 1; }
.media-picker-dropzone-text { font-size: 14px; }

/* Scroll-to-load sentinel — empty marker the IntersectionObserver watches. */
.media-picker-sentinel { height: 1px; }
.media-library-sentinel { height: 1px; }

/* Skeleton placeholders shown while the next batch is fetched.
   Pulsing shimmer keeps the layout stable and signals progress without
   reflowing the grid when real tiles arrive. */
@keyframes media-skeleton-pulse {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}
.media-picker-cell.is-skeleton,
.media-library-tile.is-skeleton {
    pointer-events: none;
    border-color: #e5e7eb;
    background-image: linear-gradient(90deg, #f3f4f6 0%, #e5e7eb 50%, #f3f4f6 100%);
    background-size: 200% 100%;
    animation: media-skeleton-pulse 1.4s ease-in-out infinite;
}
.media-picker-cell.is-skeleton { aspect-ratio: 1/1; }
.media-library-tile.is-skeleton {
    height: 200px;
}
.media-library-tile.is-skeleton > * { display: none; }
@media (prefers-reduced-motion: reduce) {
    .media-picker-cell.is-skeleton,
    .media-library-tile.is-skeleton { animation: none; }
}

.media-picker-toast {
    border-radius: 6px;
    font-size: 12px; line-height: 1.4;
}
.media-picker-toast-line + .media-picker-toast-line {
    margin-top: 2px;
    padding-top: 2px;
    border-top: 1px solid rgba(220, 38, 38, .15);
}

/* Upload spinner */
.media-picker-cell.is-uploading .spin {
    animation: media-picker-spin 1s linear infinite; display: inline-block;
}
@keyframes media-picker-spin {
    from { transform: rotate(0); }
    to   { transform: rotate(360deg); }
}

/* Respect reduced motion */
@media (prefers-reduced-motion: reduce) {
    .media-library-tile, .media-picker-cell, .media-picker-selected-tile,
    .media-library-actions, .media-library-checkbox,
    .media-picker--single .media-picker-slot, .media-picker-slot-actions {
        transition: none !important;
    }
    .media-picker-cell.is-uploading .spin { animation: none !important; }
}
