/*
 * The media library picker (<x-media-picker />, #316), drawn once per page by layouts/app.blade.php.
 * Linked in the layout's <head>: inside the component it came after the page content and arrived late.
 */

/* Media picker (resources/views/components/media-picker.blade.php) */
/* --------------------------------------------------------------------
   Design tokens — B&W monochrome, matches /media page identity
-------------------------------------------------------------------- */
.mp-root {
    --mp-ink: #0a0a0a;
    --mp-text-2: #525252;
    --mp-text-3: #a3a3a3;
    --mp-line: #e5e5e5;
    --mp-line-2: #d4d4d4;
    --mp-bg: #fafafa;
    --mp-surface: #fff;
}

[x-cloak] { display: none !important; }

.mp-modal {
    /* The dialog is the dimmed overlay itself: the browser's own dialog box is reset, its ::backdrop is clear. */
    position: fixed; inset: 0;
    width: 100%; height: 100%; max-width: none; max-height: none;
    margin: 0; border: 0; color: inherit;
    background: rgba(10, 10, 10, .6);
    backdrop-filter: blur(4px);
    z-index: 1400;
    display: flex; align-items: center; justify-content: center;
    padding: 24px;
    font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
}
.mp-modal:not([open]) { display: none; }
.mp-modal::backdrop { background: transparent; }
.mp-drawer {
    background: var(--mp-surface);
    border-radius: 12px;
    width: 100%; max-width: 640px;
    max-height: calc(100vh - 48px);
    display: flex; flex-direction: column;
    box-shadow: 0 24px 64px -12px rgba(0, 0, 0, .4),
                0 0 0 1px rgba(0, 0, 0, .04);
    overflow: hidden;
    animation: mpDrawerIn .22s cubic-bezier(.16, 1, .3, 1);
}
@keyframes mpDrawerIn {
    from { opacity: 0; transform: translateY(12px) scale(.97); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.mp-drawer__head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--mp-line);
    background: linear-gradient(180deg, #fdfdfd 0%, #fff 100%);
}
.mp-tabs { display: flex; gap: 4px; padding: 3px;
    background: var(--mp-bg); border-radius: 6px;
    border: 1px solid var(--mp-line);
}
.mp-tab {
    border: 0; background: transparent;
    color: var(--mp-text-2);
    padding: 6px 14px; border-radius: 4px;
    font: 500 12px/1 inherit; cursor: pointer;
    transition: background-color .12s ease, color .12s ease;
}
.mp-tab:hover { color: var(--mp-ink); }
.mp-tab--on {
    background: var(--mp-ink); color: #fff;
    box-shadow: 0 1px 2px rgba(0, 0, 0, .1);
}
.mp-close {
    width: 32px; height: 32px; border-radius: 6px;
    border: 1px solid var(--mp-line); background: var(--mp-surface);
    color: var(--mp-text-2); cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center;
    transition: all .12s ease;
}
.mp-close:hover { background: var(--mp-ink); color: #fff; border-color: var(--mp-ink); }

.mp-drawer__body { padding: 18px; overflow-y: auto; }

/* Meta strip — count + optional search side by side. Search only
   appears when there are 30+ items (see x-show above). */
.mp-meta {
    display: flex; align-items: center; gap: 12px;
    margin-bottom: 14px;
}
.mp-meta__count {
    color: var(--mp-text-3); font: 500 12px/1 inherit;
    font-variant-numeric: tabular-nums; flex-shrink: 0;
}
.mp-search { position: relative; flex: 1 1 auto; }
.mp-search svg {
    position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
    color: var(--mp-text-3); width: 13px; height: 13px;
}
.mp-search input {
    width: 100%; height: 32px;
    border: 1px solid var(--mp-line); border-radius: 6px;
    padding: 0 10px 0 30px;
    font: 12px inherit; color: var(--mp-ink);
    background: var(--mp-surface);
    transition: border-color .12s ease, box-shadow .12s ease;
}
.mp-search input::placeholder { color: var(--mp-text-3); }
.mp-search input:focus {
    outline: none; border-color: var(--mp-ink);
    box-shadow: 0 0 0 3px rgba(10, 10, 10, .06);
}

/* Grid — bigger tiles (was 96px min → now 140px). At 640px drawer
   width - 36px padding = ~600px usable → 4 columns of 140-150px each.
   Owner recognises photos by content, not filename. */
.mp-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 10px;
}
.mp-cell {
    border: 1px solid var(--mp-line); padding: 0;
    background: var(--mp-bg);
    aspect-ratio: 1; overflow: hidden;
    border-radius: 8px; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    position: relative;
    transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}
.mp-cell:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 24px -14px rgba(0, 0, 0, .35);
    border-color: var(--mp-ink);
}
.mp-cell:active { transform: scale(.98); }
.mp-cell img { width: 100%; height: 100%; object-fit: cover; display: block; }
.mp-cell__glyph { color: var(--mp-text-3); }

/* Video play circle overlay */
.mp-cell__play {
    position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
    width: 36px; height: 36px; border-radius: 50%;
    background: var(--mp-ink); color: #fff;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, .3);
    pointer-events: none;
    transition: transform .18s ease;
}
.mp-cell__play svg { margin-left: 2px; }
.mp-cell:hover .mp-cell__play { transform: translate(-50%, -50%) scale(1.08); }

.mp-cell__dur {
    position: absolute; bottom: 6px; left: 6px;
    background: rgba(10, 10, 10, .85); color: #fff;
    font: 600 10px/1 inherit; padding: 3px 6px; border-radius: 3px;
    font-variant-numeric: tabular-nums;
    backdrop-filter: blur(6px);
}
/* "Used elsewhere" indicator — tiny B&W dot, matches /media page */
.mp-cell__dot {
    position: absolute; top: 8px; right: 8px;
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--mp-ink);
    box-shadow: 0 0 0 2px #fff;
}

/* Hover info strip — slides up from the bottom of each tile. Shows
   dimensions so the owner can tell "1200×675 hero" from "800×600
   square" without opening every candidate. */
.mp-cell__info {
    position: absolute; left: 0; right: 0; bottom: 0;
    padding: 6px 8px;
    background: linear-gradient(to top, rgba(0,0,0,.75), transparent);
    color: #fff; font: 500 10px/1.2 inherit;
    text-align: right;
    opacity: 0; transform: translateY(4px);
    transition: opacity .15s ease, transform .15s ease;
    pointer-events: none;
    font-variant-numeric: tabular-nums;
}
.mp-cell:hover .mp-cell__info { opacity: 1; transform: translateY(0); }

.mp-empty { text-align: center; color: var(--mp-text-3); padding: 40px 20px; font-size: 13px; }

/* Infinite-scroll sentinel — invisible spacer at the end of the grid.
   Small vertical extent so IntersectionObserver fires when we're
   close to the bottom, giving loadMore() a head start before the
   owner runs out of tiles to scroll through. */
.mp-sentinel { height: 40px; width: 100%; }

/* Loading + end-of-list note */
.mp-endnote {
    text-align: center; color: var(--mp-text-3);
    padding: 12px 0;
    font: 500 11px/1 inherit;
    text-transform: uppercase; letter-spacing: .06em;
    display: flex; align-items: center; justify-content: center;
}
.mp-spinner {
    width: 20px; height: 20px; border-radius: 50%;
    border: 2px solid var(--mp-line);
    border-top-color: var(--mp-ink);
    animation: mpSpin .8s linear infinite;
}
@keyframes mpSpin { to { transform: rotate(360deg); } }

/* Upload tab */
.mp-drop {
    display: block; cursor: pointer;
    border: 2px dashed var(--mp-line-2); border-radius: 10px;
    padding: 20px; transition: border-color .12s ease;
    background: var(--mp-bg);
}
.mp-drop:hover { border-color: var(--mp-ink); }
.mp-drop__inner {
    text-align: center; padding: 12px;
    color: var(--mp-text-2);
}
.mp-drop__inner svg { color: var(--mp-text-3); margin-bottom: 8px; }
.mp-drop__inner p { margin: 0 0 4px; color: var(--mp-ink); font-weight: 500; font-size: 14px; }
.mp-drop__inner small { display: block; color: var(--mp-text-3); font-size: 11px; margin-bottom: 14px; }

.mp-btn {
    display: inline-flex; align-items: center; justify-content: center;
    gap: 6px; height: 36px; padding: 0 18px;
    border: 1px solid transparent; border-radius: 6px;
    font: 500 13px/1 inherit; cursor: pointer;
    transition: transform .06s ease, background-color .12s ease;
}
.mp-btn:disabled { opacity: .55; cursor: not-allowed; }
.mp-btn:active:not(:disabled) { transform: scale(.98); }
.mp-btn-primary { background: var(--mp-ink); color: #fff; }
.mp-btn-primary:hover:not(:disabled) { background: #000; }

.mp-uploading { margin-top: 14px; }
.mp-bar {
    height: 4px; background: var(--mp-bg); border-radius: 100px;
    overflow: hidden; position: relative;
}
.mp-bar__fill {
    position: absolute; inset: 0;
    background: var(--mp-ink);
    animation: mpBar 1.5s ease-in-out infinite;
    transform-origin: left;
}
@keyframes mpBar {
    0%   { transform: scaleX(.2); }
    50%  { transform: scaleX(1); }
    100% { transform: scaleX(.2); }
}
.mp-uploading p { text-align: center; color: var(--mp-text-3); font-size: 12px; margin: 6px 0 0; }

.mp-alert {
    margin-top: 14px; padding: 10px 12px; border-radius: 6px;
    background: var(--mp-ink); color: #fff; font-size: 12px;
}

@media (max-width: 640px) {
    .mp-modal { padding: 0; align-items: flex-end; }
    .mp-drawer {
        max-width: 100%; max-height: 92vh;
        border-radius: 12px 12px 0 0;
    }
    .mp-grid { grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); }
}
