/* =========================================================
   ACF Layout Preview Manager - Popup & Field Group Styles  v2.6.0
   ========================================================= */

/* =========================================================
   1. MODAL OVERLAY  (acf-browse-fields-modal style)
   ========================================================= */

.acflp-modal-wrap {
    --acflp-modal-cols: 4;
    display: none;
    position: fixed;
    inset: 0;
    z-index: 160000; /* above ACF's own modals (159000) */
    align-items: flex-start;
    justify-content: center;
    padding: 32px 20px 20px;
    background: rgba(0, 0, 0, 0.72);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    overflow-y: auto;
}

.acflp-modal-wrap[data-theme="light"] {
    background: rgba(15, 23, 42, 0.42);
}

.acflp-modal-wrap--open {
    display: flex;
}

/* Hide ACF's original popup when our modal is open */
.acf-fc-popup.acflp-popup-hidden {
    display: none !important;
    visibility: hidden !important;
    pointer-events: none !important;
}

/* Inner panel — matches acf-browse-fields-modal proportions */
.acflp-modal-inner {
    width: 100%;
    max-width: 1280px;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.28);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: acflp-modal-in .18s ease both;
}

@keyframes acflp-modal-in {
    from { opacity: 0; transform: translateY(-14px) scale(.98); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ---- HEADER ---- */
.acflp-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 16px 20px;
    background: #1e293b;
    border-bottom: 1px solid rgba(255,255,255,.08);
    flex-shrink: 0;
}

.acflp-modal-title-row {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.acflp-modal-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: rgba(37,99,235,.2);
    border-radius: 8px;
    flex-shrink: 0;
}

.acflp-modal-title {
    margin: 0 !important;
    padding: 0 !important;
    font-size: 16px !important;
    font-weight: 700 !important;
    color: #f1f5f9 !important;
    line-height: 1 !important;
    white-space: nowrap;
}

.acflp-modal-header-right {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    justify-content: flex-end;
}

/* Search bar */
.acflp-modal-search-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #0f172a;
    border: 1px solid #334155;
    border-radius: 8px;
    padding: 0 12px;
    width: 320px;
    max-width: 100%;
    transition: border-color .15s;
}
.acflp-modal-search-wrap:focus-within {
    border-color: #3b82f6;
    box-shadow: 0 0 0 2px rgba(59,130,246,.25);
}

.acflp-modal-search-icon {
    color: #64748b;
    font-size: 15px !important;
    width: 16px !important;
    height: 16px !important;
    flex-shrink: 0;
}

.acflp-modal-search-input {
    flex: 1;
    padding: 9px 0;
    border: none !important;
    background: transparent !important;
    color: #e2e8f0 !important;
    font-size: 13px;
    outline: none !important;
    box-shadow: none !important;
    min-width: 0;
}
.acflp-modal-search-input::placeholder { color: #475569; }

.acflp-modal-search-clear {
    border: none;
    background: transparent;
    color: #64748b;
    font-size: 18px;
    line-height: 1;
    padding: 0;
    cursor: pointer;
    transition: color .15s;
    flex-shrink: 0;
}
.acflp-modal-search-clear:hover { color: #94a3b8; }

/* Close button — the ONLY way to dismiss */
.acflp-modal-close-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 8px;
    border: 1px solid rgba(255,255,255,.12);
    background: rgba(255,255,255,.06);
    color: #94a3b8;
    cursor: pointer;
    transition: background .15s, color .15s, border-color .15s;
    flex-shrink: 0;
    padding: 0;
}
.acflp-modal-close-btn:hover {
    background: rgba(239,68,68,.15);
    border-color: rgba(239,68,68,.4);
    color: #fca5a5;
}

/* ---- BODY / GRID ---- */
.acflp-modal-body {
    padding: 20px;
    overflow-y: auto;
    max-height: calc(100vh - 160px);
    background: #f8fafc;
}

.acflp-modal-grid {
    display: grid;
    grid-template-columns: repeat(var(--acflp-modal-cols), minmax(0, 1fr));
    gap: 16px;
}

@media (max-width: 860px)  { .acflp-modal-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 560px)  { .acflp-modal-grid { grid-template-columns: 1fr; } }

/* ---- LIGHT THEME FOR CHOOSE LAYOUT POPUP ---- */
.acflp-modal-wrap[data-theme="light"] .acflp-modal-header {
    background: #ffffff;
    border-bottom-color: #e2e8f0;
}
.acflp-modal-wrap[data-theme="light"] .acflp-modal-title {
    color: #0f172a !important;
}
.acflp-modal-wrap[data-theme="light"] .acflp-modal-search-wrap {
    background: #f8fafc;
    border-color: #cbd5e1;
}
.acflp-modal-wrap[data-theme="light"] .acflp-modal-search-input {
    color: #0f172a !important;
}
.acflp-modal-wrap[data-theme="light"] .acflp-modal-body {
    background: #f8fafc;
}
.acflp-modal-wrap[data-theme="light"] .acflp-modal-close-btn {
    background: #f1f5f9;
    border-color: #cbd5e1;
    color: #64748b;
}

/* ---- DARK THEME FOR CHOOSE LAYOUT POPUP ---- */
.acflp-modal-wrap[data-theme="dark"] .acflp-modal-inner {
    background: #0f172a;
}
.acflp-modal-wrap[data-theme="dark"] .acflp-modal-body {
    background: #111827;
}
.acflp-modal-wrap[data-theme="dark"] .acflp-modal-card {
    background: #0f172a;
    border-color: #334155;
}
.acflp-modal-wrap[data-theme="dark"] .acflp-mc-footer {
    background: #0f172a;
    border-top-color: #334155;
}
.acflp-modal-wrap[data-theme="dark"] .acflp-mc-title {
    color: #f8fafc;
}
.acflp-modal-wrap[data-theme="dark"] .acflp-mc-slug {
    color: #94a3b8;
}
.acflp-modal-wrap[data-theme="dark"] .acflp-mc-img-wrap--empty {
    background: #1e293b;
}

.acflp-modal-no-results {
    grid-column: 1/-1;
    text-align: center;
    padding: 48px 20px;
    color: #94a3b8;
    font-size: 14px;
}

/* ---- LAYOUT CARD ---- */
.acflp-modal-card {
    display: flex;
    flex-direction: column;
    background: #fff;
    border: 1.5px solid #e2e8f0;
    border-radius: 10px;
    overflow: hidden;
    cursor: pointer;
    text-align: left;
    padding: 0;
    transition: border-color .18s, box-shadow .18s, transform .18s;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.acflp-modal-card:hover {
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59,130,246,.15), 0 8px 24px rgba(15,23,42,.1);
    transform: translateY(-2px);
}

.acflp-modal-card:focus-visible {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

/* Image area */
.acflp-mc-img-wrap {
    width: 100%;
    aspect-ratio: 16 / 9;
    overflow: hidden;
    background: #f1f5f9;
    position: relative;
}

.acflp-mc-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform .22s ease;
}
.acflp-modal-card:hover .acflp-mc-img { transform: scale(1.04); }

/* Empty state image area */
.acflp-mc-img-wrap--empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: linear-gradient(135deg, #f0f4ff 0%, #e8edf8 100%);
}
.acflp-mc-empty-icon {
    font-size: 28px;
    color: #c0ccda;
    line-height: 1;
}
.acflp-mc-empty-txt {
    font-size: 11px;
    color: #94a3b8;
    letter-spacing: .02em;
}

/* Card footer */
.acflp-mc-footer {
    padding: 11px 13px 13px;
    border-top: 1px solid #f1f5f9;
    background: #fff;
    display: flex;
    flex-direction: column;
    gap: 3px;
}
.acflp-mc-title {
    display: block;
    font-size: 13px;
    font-weight: 700;
    color: #1e293b;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.acflp-mc-slug {
    display: block;
    font-size: 10px;
    color: #94a3b8;
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', monospace;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* =========================================================
   2. INLINE PREVIEW TOOLTIP  (field-group editor)
   ========================================================= */

#acflp-inline-tooltip {
    position: absolute;
    z-index: 999999;
    width: 240px;
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 8px 32px rgba(15,23,42,.18), 0 0 0 1px rgba(0,0,0,.08);
    display: none;
    overflow: visible;
}

#acflp-inline-tooltip.acflp-itip--visible {
    display: block;
}

.acflp-itip-img-wrap {
    width: 100%;
    aspect-ratio: 16/9;
    overflow: hidden;
    background: #f1f5f9;
    border-radius: 5px;
}
.acflp-itip-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    border-radius: 5px;
}

.acflp-itip-footer {
    padding: 10px 12px;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 8px;
    border-top: 1px solid #f1f5f9;
}

.acflp-itip-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    flex: 1;
}

.acflp-itip-row {
    display: flex;
    align-items: center;
    gap: 4px;
    min-width: 0;
    font-size: 11px;
    font-weight: 700;
    color: #1e293b;
    font-family: -apple-system, sans-serif;
}

.acflp-itip-label {
    display: block;
    font-size: 11px;
    font-weight: 700;
    color: #64748b;
    font-family: -apple-system, sans-serif;
    white-space: nowrap;
    flex-shrink: 0;
}

.acflp-itip-title,
.acflp-itip-slug {
    display: block;
    font-size: 11px;
    font-weight: 700;
    color: #1e293b;
    font-family: -apple-system, sans-serif;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0;
}

/* =========================================================
   3. INLINE "Set Preview" BUTTON  (field-group editor)
   ========================================================= */

.acflp-preview-li {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-right: 2px;
    vertical-align: middle;
}

.acflp-set-preview-btn {
    display: inline-flex !important;
    align-items: center;
    gap: 5px;
    font-size: 11px !important;
    line-height: 1 !important;
    cursor: pointer;
    transition: background .15s, color .15s, border-color .15s !important;
    white-space: nowrap;
}

.acflp-set-preview-btn .acf-icon.acflp-icon-img::before {
    content: "\f128"; /* dashicons-format-image */
    font-family: dashicons;
    font-size: 13px;
    line-height: 1;
    speak: never;
    display: inline-block;
    margin-right: 1px;
}

.acflp-set-preview-btn .acf-icon.acflp-icon-spin::before {
    content: "\f463";
    font-family: dashicons;
    font-size: 13px;
    line-height: 1;
    display: inline-block;
    animation: acflp-spin .7s linear infinite;
}
@keyframes acflp-spin { to { transform: rotate(360deg); } }

/* No image: dashed outline */
.acflp-set-preview-btn:not(.acflp-has-img) {
    background: transparent !important;
    color: #6b7280 !important;
    border: 1.5px dashed #d1d5db !important;
    box-shadow: none !important;
}
.acflp-set-preview-btn:not(.acflp-has-img):hover {
    background: #eff6ff !important;
    color: #2563eb !important;
    border-color: #93c5fd !important;
    border-style: solid !important;
}

/* Has image: green solid */
.acflp-set-preview-btn.acflp-has-img {
    background: #f0fdf4 !important;
    color: #15803d !important;
    border: 1.5px solid #86efac !important;
    box-shadow: none !important;
}
.acflp-set-preview-btn.acflp-has-img:hover {
    background: #dcfce7 !important;
    color: #166534 !important;
    border-color: #4ade80 !important;
}

/* Disabled */
.acflp-set-preview-btn:disabled {
    opacity: .42 !important;
    cursor: not-allowed !important;
    pointer-events: auto !important;
    filter: grayscale(30%);
}

/* =========================================================
   4. TOAST NOTIFICATIONS
   ========================================================= */

#acflp-toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999999;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}
.acflp-toast-item {
    display: inline-flex;
    align-items: center;
    padding: 10px 16px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    color: #fff;
    box-shadow: 0 4px 16px rgba(0,0,0,.18);
    animation: acflp-toast-in .2s ease;
    pointer-events: auto;
    font-family: -apple-system, sans-serif;
}
.acflp-toast-item--success { background: #059669; }
.acflp-toast-item--error   { background: #dc2626; }
.acflp-toast-item--info    { background: #2563eb; }
@keyframes acflp-toast-in {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}
