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

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

/* ---- Overlay ---- */
.odse-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(--odse-foreground);
    -webkit-font-smoothing: antialiased;
}

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

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

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

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

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

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

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

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

.odse-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(--odse-radius) - 2px);
    color: var(--odse-foreground);
    cursor: pointer;
    transition: background .15s ease, color .15s ease;
}

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

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

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

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

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

/* ---- Buttons ---- */
.odse-modal-overlay .odse-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(--odse-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;
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

/* ---- Skeleton shimmer ---- */
.odse-modal-overlay .odse-sk {
    display: block;
    border-radius: 6px;
    background-color: var(--odse-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: odseshimmer 1.4s ease-in-out infinite;
}

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

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

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

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

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

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

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

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

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

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

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

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

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

    .odse-modal-container,
    .odse-skeleton-loader {
        padding: 16px;
    }
}
/* Brand theme -- OneDrive (blue) */
.odse-modal-overlay {
    --odse-brand: oklch(0.52 0.13 245);
    --odse-brand-foreground: oklch(0.99 0 0);
    --odse-brand-soft: oklch(0.94 0.04 245);
    --odse-brand-strong: oklch(0.45 0.12 245);
    --odse-brand-ring: oklch(0.52 0.13 245 / .16);
}
.odse_file_button {
    background: #0364b8 !important;
    color: #fff !important;
    border-color: #025aa3 !important;
}
.odse_file_button:hover,
.odse_file_button:focus {
    background: #024e8c !important;
    color: #fff !important;
    border-color: #024e8c !important;
}

/* Keep scrolling inside the modal; do not pass it through to the page behind. */
.odse-modal-overlay,
.odse-modal-overlay .odse-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. */
.odse-modal-overlay .odse-btn-outline:focus,
.odse-modal-overlay .odse-btn-outline:focus-visible,
.odse-modal-overlay .odse-btn-outline:active {
    background: var(--odse-brand) !important;
    border-color: var(--odse-brand) !important;
    color: var(--odse-brand-foreground) !important;
}
