/**
 * Dropbox Modal Styles
 * Rebuilt to match the shadcn "S3 File Browser" design (dbxe-popup-all.html)
 * All rules are scoped under .dbxe-modal-overlay so nothing leaks into wp-admin.
 */

/* ---- Design tokens (neutral). Brand colors live in brand.css ---- */
.dbxe-modal-overlay {
    --dbxe-background: oklch(1 0 0);
    --dbxe-foreground: oklch(0.145 0 0);
    --dbxe-card: oklch(1 0 0);
    --dbxe-muted: oklch(0.97 0 0);
    --dbxe-muted-foreground: oklch(0.556 0 0);
    --dbxe-accent: oklch(0.97 0 0);
    --dbxe-warning-soft: oklch(0.96 0.05 80);
    --dbxe-border: oklch(0.922 0 0);
    --dbxe-input: oklch(0.922 0 0);
    --dbxe-ring: oklch(0.708 0 0);
    --dbxe-radius: 0.625rem;
    --dbxe-sk: oklch(0.93 0 0);
    --dbxe-sk2: oklch(0.955 0 0);
}

/* ---- Overlay ---- */
.dbxe-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 100000;
    display: none;
    justify-content: center;
    align-items: center;
    padding: 32px 20px;
    box-sizing: border-box;
    font-family: Vazirmatn, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-size: 14px;
    line-height: 1.55;
    color: var(--dbxe-foreground);
    -webkit-font-smoothing: antialiased;
}

.dbxe-modal-overlay.open {
    display: flex;
}

.dbxe-modal-overlay *,
.dbxe-modal-overlay *::before,
.dbxe-modal-overlay *::after {
    box-sizing: border-box;
}

/* ---- Dialog card ---- */
.dbxe-modal {
    position: relative;
    width: 100%;
    max-width: 1200px;
    height: 800px;
    max-height: calc(100vh - 64px);
    background: var(--dbxe-card);
    border: 1px solid var(--dbxe-border);
    border-radius: 14px;
    box-shadow: 0 18px 50px rgba(0, 0, 0, .18);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ---- Header ---- */
.dbxe-modal-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    padding: 20px 26px;
    border-bottom: 1px solid var(--dbxe-border);
    background: var(--dbxe-card);
    flex-shrink: 0;
}

.dbxe-modal-heading {
    min-width: 0;
}

.dbxe-modal-title {
    margin: 0;
    padding: 0;
    font-size: 17px;
    font-weight: 650;
    letter-spacing: -0.01em;
    line-height: 1.3;
    color: var(--dbxe-foreground);
}

.dbxe-modal-subtitle {
    font-size: 12.5px;
    color: var(--dbxe-muted-foreground);
    margin-top: 3px;
    unicode-bidi: plaintext;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.dbxe-modal-subtitle:empty {
    display: none;
}

.dbxe-modal-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    padding: 0;
    flex-shrink: 0;
    background: transparent;
    border: 1px solid transparent;
    border-radius: calc(var(--dbxe-radius) - 2px);
    color: var(--dbxe-foreground);
    cursor: pointer;
    transition: background .15s ease, color .15s ease;
}

.dbxe-modal-close:hover {
    background: var(--dbxe-accent);
    color: var(--dbxe-brand-strong);
}

.dbxe-modal-close svg {
    width: 16px;
    height: 16px;
}

/* ---- Content wrapper ---- */
.dbxe-modal-content {
    flex: 1;
    min-height: 0;
    position: relative;
    background: var(--dbxe-card);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* The dialog body (AJAX content) + skeleton share the same padding */
.dbxe-modal-container,
.dbxe-skeleton-loader {
    flex: 1;
    min-height: 0;
    overflow-y: scroll;
    overflow-x: hidden;
    scrollbar-gutter: stable both-edges;
    padding: 20px;
    background: var(--dbxe-card);
    -webkit-overflow-scrolling: touch;
}

.dbxe-modal-container.hidden,
.dbxe-skeleton-loader.hidden {
    display: none !important;
}

/* ---- Buttons ---- */
.dbxe-modal-overlay .dbxe-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    height: 38px;
    padding: 0 16px;
    font-size: 13.5px;
    font-weight: 550;
    line-height: 1;
    border-radius: calc(var(--dbxe-radius) - 2px);
    border: 1px solid transparent;
    cursor: pointer;
    white-space: nowrap;
    text-decoration: none;
    box-shadow: none;
    transition: filter .15s ease, background .15s ease, border-color .15s ease, box-shadow .15s ease, color .15s ease;
}

.dbxe-modal-overlay .dbxe-btn svg {
    width: 15px;
    height: 15px;
    flex-shrink: 0;
}

.dbxe-modal-overlay .dbxe-btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px var(--dbxe-brand-ring);
}

.dbxe-modal-overlay .dbxe-btn-primary {
    background: var(--dbxe-brand);
    color: var(--dbxe-brand-foreground);
    border-color: transparent;
}

.dbxe-modal-overlay .dbxe-btn-primary:hover {
    background: var(--dbxe-brand);
    color: var(--dbxe-brand-foreground);
    filter: brightness(0.93);
}

.dbxe-modal-overlay .dbxe-btn-primary:active {
    filter: brightness(0.87);
}

.dbxe-modal-overlay .dbxe-btn-outline {
    background: var(--dbxe-background);
    border-color: var(--dbxe-border);
    color: var(--dbxe-foreground);
}

.dbxe-modal-overlay .dbxe-btn-outline:hover {
    background: var(--dbxe-brand);
    border-color: var(--dbxe-brand);
    color: #fff;
}

.dbxe-modal-overlay .dbxe-btn-outline:active {
    background: var(--dbxe-muted);
}

.dbxe-modal-overlay .dbxe-btn-ghost {
    background: transparent;
    color: var(--dbxe-foreground);
}

.dbxe-modal-overlay .dbxe-btn-ghost:hover {
    background: var(--dbxe-accent);
    color: var(--dbxe-brand-strong);
}

.dbxe-modal-overlay .dbxe-btn-sm {
    height: 32px;
    padding: 0 12px;
    font-size: 12.5px;
}

.dbxe-modal-overlay .dbxe-btn-icon {
    width: 34px;
    height: 34px;
    padding: 0;
}

/* ---- Toolbar (back + breadcrumbs + upload) ---- */
.dbxe-toolbar {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}

.dbxe-nav-back {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    flex-shrink: 0;
    background: var(--dbxe-background);
    border: 1px solid var(--dbxe-border);
    border-radius: calc(var(--dbxe-radius) - 2px);
    color: var(--dbxe-foreground);
    cursor: pointer;
    text-decoration: none;
    transition: background .15s ease, border-color .15s ease, color .15s ease;
}

.dbxe-nav-back:hover {
    background: var(--dbxe-accent);
    border-color: var(--dbxe-brand);
    color: var(--dbxe-brand-strong);
}

/* Override WordPress admin focus styles without losing the modal's radius. */
.dbxe-modal-overlay .dbxe-nav-back:focus,
.dbxe-modal-overlay .dbxe-nav-back:focus-visible {
    border-radius: calc(var(--dbxe-radius) - 2px) !important;
    outline: none !important;
    outline-offset: 0;
    color: var(--dbxe-brand) !important;
    box-shadow: 0 0 0 3px var(--dbxe-brand-ring) !important;
}

.dbxe-nav-back svg {
    width: 16px;
    height: 16px;
}

.dbxe-nav-back.disabled {
    opacity: .45;
    cursor: default;
    pointer-events: none;
}

.dbxe-breadcrumbs {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--dbxe-muted-foreground);
    flex: 1;
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.dbxe-breadcrumbs a {
    color: var(--dbxe-foreground);
    text-decoration: none;
    font-weight: 550;
    box-shadow: none;
    outline: none;
}

.dbxe-breadcrumbs a:hover {
    color: var(--dbxe-brand-strong);
}

.dbxe-breadcrumbs .sep {
    opacity: .5;
}

.dbxe-breadcrumbs .current {
    color: var(--dbxe-brand-strong);
    font-weight: 650;
}

/* ---- Search ---- */
.dbxe-search {
    position: relative;
    width: 100%;
    margin-bottom: 16px;
}

.dbxe-search svg {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    color: var(--dbxe-muted-foreground);
    pointer-events: none;
}

.dbxe-modal-overlay .dbxe-input {
    height: 38px;
    width: 100%;
    border: 1px solid var(--dbxe-input);
    border-radius: calc(var(--dbxe-radius) - 2px);
    padding: 0 12px;
    font-size: 13.5px;
    color: var(--dbxe-foreground);
    background: var(--dbxe-background);
    outline: none;
    box-shadow: none;
    transition: border-color .15s ease, box-shadow .15s ease;
}

.dbxe-search .dbxe-input {
    padding-left: 38px;
}

.dbxe-search .dbxe-input:hover {
    border-color: var(--dbxe-brand);
}

.dbxe-modal-overlay .dbxe-input:focus {
    border-color: var(--dbxe-brand);
    box-shadow: 0 0 0 3px var(--dbxe-brand-ring);
}

/* ---- Skeleton shimmer ---- */
.dbxe-modal-overlay .dbxe-sk {
    display: block;
    border-radius: 6px;
    background-color: var(--dbxe-sk);
    background-image: linear-gradient(90deg, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, .7) 50%, rgba(255, 255, 255, 0) 100%);
    background-size: 220px 100%;
    background-repeat: no-repeat;
    background-position: -220px 0;
    animation: dbxeshimmer 1.4s ease-in-out infinite;
}

.dbxe-modal-overlay .dbxe-sk-line {
    height: 11px;
}

.dbxe-modal-overlay .dbxe-sk-icon {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    flex-shrink: 0;
}

.dbxe-modal-overlay .dbxe-sk-pill {
    border-radius: 8px;
}

@keyframes dbxeshimmer {
    0% { background-position: -220px 0; }
    100% { background-position: calc(100% + 220px) 0; }
}

/* ---- RTL ---- */
html[dir="rtl"] .dbxe-search svg,
body.rtl .dbxe-search svg {
    left: auto;
    right: 12px;
}

html[dir="rtl"] .dbxe-search .dbxe-input,
body.rtl .dbxe-search .dbxe-input {
    padding-left: 12px;
    padding-right: 38px;
}

html[dir="rtl"] .dbxe-nav-back svg,
body.rtl .dbxe-nav-back svg {
    transform: scaleX(-1);
}

html[dir="rtl"] .dbxe-breadcrumbs,
body.rtl .dbxe-breadcrumbs {
    direction: rtl;
}

html[dir="rtl"] .dbxe-modal-subtitle,
body.rtl .dbxe-modal-subtitle {
    text-align: right;
    direction: rtl;
}

html[dir="rtl"] .dbxe-modal-header,
body.rtl .dbxe-modal-header {
    text-align: right;
}

/* ---- Responsive ---- */
@media screen and (max-width: 782px) {
    .dbxe-modal-overlay {
        padding: 0;
    }

    .dbxe-modal {
        width: 100%;
        height: 100%;
        max-width: none;
        max-height: none;
        border: 0;
        border-radius: 0;
    }

    .dbxe-modal-header {
        padding: 16px;
    }

    .dbxe-modal-container,
    .dbxe-skeleton-loader {
        padding: 16px;
    }
}
/* Brand theme -- Dropbox (blue) */
.dbxe-modal-overlay {
    --dbxe-brand: oklch(0.58 0.20 260);
    --dbxe-brand-foreground: oklch(0.99 0 0);
    --dbxe-brand-soft: oklch(0.95 0.05 260);
    --dbxe-brand-strong: oklch(0.50 0.18 260);
    --dbxe-brand-ring: oklch(0.58 0.20 260 / .16);
}
.dbxe_file_button {
    background: #0061ff !important;
    color: #fff !important;
    border-color: #0052d6 !important;
}
.dbxe_file_button:hover,
.dbxe_file_button:focus {
    background: #0047b8 !important;
    color: #fff !important;
    border-color: #0047b8 !important;
}

/* Keep scrolling inside the modal; do not pass it through to the page behind. */
.dbxe-modal-overlay,
.dbxe-modal-overlay .dbxe-modal-container {
    overscroll-behavior: contain;
}

/* Reserve the browser scrollbar lane on this admin/editor page from first paint. */
html {
    overflow-y: scroll;
    scrollbar-gutter: stable;
}

/* A focused/active Select control uses the same solid brand treatment as Upload. */
.dbxe-modal-overlay .dbxe-btn-outline:focus,
.dbxe-modal-overlay .dbxe-btn-outline:focus-visible,
.dbxe-modal-overlay .dbxe-btn-outline:active {
    background: var(--dbxe-brand) !important;
    border-color: var(--dbxe-brand) !important;
    color: var(--dbxe-brand-foreground) !important;
}
