/**
 * MediaPicker v20260725a — styles for the shared Media picker.
 *
 * Self-contained on purpose: this component renders into settings, products,
 * blog, workshops, the studios and the partner pages, so it can never rely on a
 * host page's button/input styles. Every control the JS emits is styled here.
 */

.mp-overlay {
    position: fixed;
    inset: 0;
    z-index: 10000;                 /* above dashboard drawers, below VivaDialogs */
    background: rgba(16, 24, 40, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    overflow-y: auto;
}

.mp-modal {
    background: #fff;
    border-radius: 14px;
    box-shadow: 0 20px 48px rgba(16, 24, 40, 0.24);
    width: 100%;
    max-width: 640px;
    max-height: calc(100vh - 40px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    font-family: inherit;
}

.mp-head {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 18px;
    border-bottom: 1px solid #E5E7EB;
}
.mp-title {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: #101828;
    flex: 1;
}
.mp-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: #6A7282;
    cursor: pointer;
}
.mp-close:hover { background: #F3F4F6; color: #101828; }

/* ── tabs (only rendered when a stock source is supplied) ── */
.mp-tabs {
    display: flex;
    gap: 4px;
    padding: 10px 18px 0;
    border-bottom: 1px solid #E5E7EB;
}
.mp-tab {
    padding: 8px 14px;
    border: 0;
    border-bottom: 2px solid transparent;
    background: transparent;
    font-family: inherit;
    font-size: 13.5px;
    font-weight: 500;
    color: #6A7282;
    cursor: pointer;
}
.mp-tab:hover { color: #101828; }
.mp-tab--active { color: #7C3AED; border-bottom-color: #7C3AED; font-weight: 600; }

/* Inline status/error line — the picker reports failures here rather than via
   VivaDialogs, since not every host page loads dialogs.js. */
.mp-status {
    margin: 0;
    padding: 9px 18px;
    font-size: 13px;
    line-height: 1.45;
    background: #F3F4F6;
    color: #374151;
    border-bottom: 1px solid #E5E7EB;
}
.mp-status--err { background: #FEF2F2; color: #B91C1C; }

.mp-body {
    padding: 16px 18px 18px;
    overflow-y: auto;
    flex: 1;
}

/* Vertical rhythm via margins, not flex gap — gap has been unreliable for
   stacked sections in this codebase (see CLAUDE.md CSS Spacing Guidelines). */
.mp-pane > * { margin-bottom: 12px; }
.mp-pane > *:last-child { margin-bottom: 0; }

/* ── upload dropzone ── */
.mp-drop {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 18px;
    border: 1.5px dashed #D1D5DB;
    border-radius: 10px;
    background: #FAFAFA;
    color: #6A7282;
    cursor: pointer;
    text-align: center;
}
.mp-drop:hover,
.mp-drop:focus-visible { border-color: #7C3AED; background: #FAF5FF; color: #5B21B6; outline: none; }
.mp-drop--over { border-color: #7C3AED; background: #F3E8FF; color: #5B21B6; }
.mp-drop--busy { opacity: 0.6; pointer-events: none; }
.mp-drop-text { font-size: 13.5px; font-weight: 500; }
.mp-drop-link { color: #7C3AED; text-decoration: underline; }
.mp-drop-hint { font-size: 12px; color: #9CA3AF; }

/* ── import / search row ── */
.mp-import {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}
.mp-input {
    flex: 1 1 200px;
    min-width: 0;
    padding: 8px 11px;
    border: 1.5px solid #E5E7EB;
    border-radius: 9px;
    font-family: inherit;
    font-size: 14px;
    color: #101828;
    background: #fff;
}
.mp-input:focus {
    outline: none;
    border-color: #7C3AED;
    box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.12);
}

.mp-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: 9px;
    border: 1.5px solid transparent;
    font-family: inherit;
    font-size: 13.5px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
}
.mp-btn:disabled { opacity: 0.6; cursor: default; }
.mp-btn--secondary { background: #fff; border-color: #E5E7EB; color: #374151; }
.mp-btn--secondary:hover:not(:disabled) { border-color: #7C3AED; color: #5B21B6; }
.mp-btn--field {
    background: #fff;
    border-color: #D1D5DB;
    color: #5B21B6;
    padding: 6px 11px;
    font-size: 13px;
}
.mp-btn--field:hover { border-color: #7C3AED; background: #FAF5FF; }

.mp-hint {
    margin: 0;
    font-size: 12px;
    color: #9CA3AF;
    line-height: 1.45;
}

/* ── results grid ── */
.mp-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 10px;
    max-height: 340px;
    overflow-y: auto;
}
.mp-empty {
    grid-column: 1 / -1;
    margin: 0;
    padding: 18px 4px;
    font-size: 13px;
    color: #9CA3AF;
    text-align: center;
    line-height: 1.5;
}
.mp-empty--err { color: #B91C1C; }

.mp-item {
    display: flex;
    flex-direction: column;
    padding: 0;
    border: 1.5px solid #E5E7EB;
    border-radius: 10px;
    background: #fff;
    cursor: pointer;
    overflow: hidden;
    text-align: left;
    font-family: inherit;
}
.mp-item:hover,
.mp-item:focus-visible {
    border-color: #7C3AED;
    box-shadow: 0 2px 10px rgba(124, 58, 237, 0.16);
    outline: none;
}
.mp-thumb {
    width: 100%;
    height: 92px;
    object-fit: cover;
    display: block;
    background: #F3F4F6;
}
.mp-item-name {
    padding: 6px 8px 0;
    font-size: 12px;
    font-weight: 500;
    color: #101828;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.mp-item-usage {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: 4px 8px 8px;
}
.mp-chip {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    background: #E5E7EB;
    color: #4B5563;
    padding: 2px 6px;
    border-radius: 999px;
}

/* ── inline field affordance (URL input + "Choose from Media") ── */
.mp-field {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-top: 6px;
    flex-wrap: wrap;
}
.mp-field-thumb {
    width: 34px;
    height: 34px;
    object-fit: cover;
    border-radius: 6px;
    border: 1px solid #E5E7EB;
    background: #F3F4F6;
}

@media (max-width: 640px) {
    .mp-overlay { padding: 0; align-items: stretch; }
    .mp-modal { max-width: none; max-height: 100vh; border-radius: 0; }
    .mp-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); max-height: none; }
    /* 16px keeps iOS from zooming the viewport on focus. */
    .mp-input { font-size: 16px; width: 100%; flex-basis: 100%; }
    .mp-import .mp-btn { width: 100%; justify-content: center; }
    .mp-btn { min-height: 44px; }          /* touch target */
    .mp-close { width: 40px; height: 40px; }
}
