/* ─── Client Portal & Block Builder — Frontend CSS ─── */

:root {
    --cpb-primary: #2563eb;
    --cpb-primary-hover: #1d4ed8;
    --cpb-dark: #111827;
    --cpb-light: #f9fafb;
    --cpb-border: #e5e7eb;
    --cpb-radius: 12px;
    --cpb-shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --cpb-shadow-md: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -2px rgba(0,0,0,0.05);
}

/* ═══════════════════════════════════════════════
   PORTAL DASHBOARD
   ═══════════════════════════════════════════════ */
.cpb-portal {
    max-width: 1200px;
    margin: 0 auto;
    padding: 30px 20px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* Category Cards */
.cpb-category-card {
    border-radius: var(--cpb-radius) !important;
    transition: all 0.2s ease;
    cursor: pointer;
}
.cpb-category-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--cpb-shadow-md);
    border-color: var(--cpb-primary) !important;
}
.cpb-category-card:hover .bi {
    color: var(--cpb-primary) !important;
}


/* ═══════════════════════════════════════════════
   BUILDER OVERLAY (fullscreen on same page)
   ═══════════════════════════════════════════════ */
.cpb-builder-overlay {
    position: fixed;
    inset: 0;
    z-index: 100001; /* Above WP admin bar */
    background: #fff;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* Top bar */
.cpb-builder-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    border-bottom: 1px solid var(--cpb-border);
    background: #fff;
    flex-shrink: 0;
    z-index: 10;
}

/* Body */
.cpb-builder-body {
    flex: 1;
    overflow: hidden;
}
.cpb-builder-body > .row {
    height: 100%;
}

/* Sidebar */
.cpb-builder-sidebar {
    background: var(--cpb-light);
    border-right: 1px solid var(--cpb-border);
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}
.cpb-sidebar-header {
    padding: 14px 16px;
    background: var(--cpb-dark);
    color: #fff;
    flex-shrink: 0;
}
.cpb-sidebar-body {
    flex: 1;
    overflow-y: auto;
}

/* Main collection area */
.cpb-builder-main {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}
.cpb-builder-collection {
    flex: 1;
    overflow-y: auto;
}


/* ─── Block Library ─────────────────────────── */
.cpb-lib-category {
    border-bottom: 1px solid var(--cpb-border);
}
.cpb-lib-category-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    cursor: pointer;
    font-weight: 600;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #374151;
    transition: background 0.15s ease;
    user-select: none;
}
.cpb-lib-category-header:hover {
    background: #f3f4f6;
}
.cpb-lib-category-header .bi-chevron-down {
    transition: transform 0.2s ease;
}
.cpb-lib-category-header.collapsed .bi-chevron-down {
    transform: rotate(-90deg);
}
.cpb-lib-items {
    padding: 8px;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}
.cpb-lib-sub-category {
    padding: 4px 16px 8px;
}
.cpb-lib-sub-header {
    font-size: 11px;
    font-weight: 600;
    color: #9ca3af;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 4px 0;
    margin-bottom: 4px;
}

/* Block thumbnails */
.cpb-lib-block {
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all 0.2s ease;
    position: relative;
    background: #fff;
}
.cpb-lib-block:hover {
    border-color: var(--cpb-primary);
    transform: scale(1.02);
    box-shadow: var(--cpb-shadow);
}
.cpb-lib-block img {
    width: 100%;
    height: 80px;
    object-fit: cover;
    display: block;
}
.cpb-lib-block .cpb-lib-block-name {
    font-size: 10px;
    padding: 4px 6px;
    color: #6b7280;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: center;
    background: var(--cpb-light);
}
.cpb-lib-block.added {
    border-color: #10b981;
    opacity: 0.6;
}
.cpb-lib-block.added::after {
    content: '\2713';
    position: absolute;
    top: 4px;
    right: 4px;
    background: #10b981;
    color: #fff;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: bold;
}


/* ─── Collection area ───────────────────────── */
.border-dashed {
    border-style: dashed !important;
    border-color: #d1d5db !important;
}

/* Block items in collection */
.cpb-block-item {
    background: #fff;
    border: 1px solid var(--cpb-border);
    border-radius: var(--cpb-radius);
    overflow: hidden;
    transition: all 0.2s ease;
    margin-bottom: 16px;
}
.cpb-block-item:hover {
    box-shadow: var(--cpb-shadow-md);
}
.cpb-block-item img {
    width: 100%;
    max-height: 400px;
    object-fit: contain;
    background: var(--cpb-light);
    display: block;
}
.cpb-block-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    border-top: 1px solid var(--cpb-border);
    background: #fff;
    flex-wrap: wrap;
    gap: 8px;
}
.cpb-block-name {
    font-weight: 600;
    font-size: 14px;
    color: var(--cpb-dark);
}
.cpb-block-meta {
    font-size: 12px;
    color: #9ca3af;
}
.cpb-block-actions .btn {
    padding: 4px 10px;
    font-size: 12px;
}

/* Inline form for block content */
.cpb-block-form {
    padding: 16px;
    background: #f0f9ff;
    border-top: 1px solid #bfdbfe;
}
.cpb-block-form .form-label {
    font-size: 13px;
    font-weight: 600;
    color: #374151;
}
.cpb-block-form .form-control {
    font-size: 13px;
}

/* Form badge */
.cpb-form-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 20px;
    font-weight: 600;
    cursor: pointer;
}
.cpb-form-badge.filled {
    background: #d1fae5;
    color: #065f46;
}
.cpb-form-badge.empty {
    background: #fef3c7;
    color: #92400e;
}


/* ─── Toast ──────────────────────────────────── */
.cpb-toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    padding: 10px 24px;
    border-radius: 8px;
    color: #fff;
    font-weight: 500;
    font-size: 14px;
    z-index: 999999;
    opacity: 0;
    transition: all 0.3s ease;
    box-shadow: 0 10px 25px rgba(0,0,0,0.15);
}
.cpb-toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}
.cpb-toast.success { background: #10b981; }
.cpb-toast.warning { background: #f59e0b; }
.cpb-toast.error   { background: #ef4444; }
.cpb-toast.info    { background: #3b82f6; }


/* ─── Mobile ─────────────────────────────────── */
.cpb-mobile-lib-btn {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 56px;
    height: 56px;
    z-index: 99995;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.cpb-mobile-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 99991;
    display: none;
}
.cpb-mobile-overlay.show {
    display: block;
}

@media (max-width: 991px) {
    .cpb-builder-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 85%;
        max-width: 360px;
        z-index: 99993;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
    }
    .cpb-builder-sidebar.open {
        transform: translateX(0);
    }
}

@media (min-width: 992px) {
    .cpb-mobile-lib-btn { display: none !important; }
    .cpb-mobile-overlay { display: none !important; }
}

/* Scrollbars */
.cpb-sidebar-body::-webkit-scrollbar,
.cpb-builder-collection::-webkit-scrollbar { width: 4px; }
.cpb-sidebar-body::-webkit-scrollbar-thumb,
.cpb-builder-collection::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 4px; }

/* Locked state */
.cpb-builder-overlay[data-is-locked="1"] .cpb-block-actions .btn-danger,
.cpb-builder-overlay[data-is-locked="1"] .cpb-form-badge,
.cpb-builder-overlay[data-is-locked="1"] #cpb-save-btn {
    display: none !important;
}

/* ─── GLOBAL MOBILE MENU FIX ─────────────────────────── */
/* Ensures hamburger menu stays visible while scrolling on all pages */
@media (max-width: 768px) {
    #cpb-portal .cpp-topbar {
        background: #fff !important;
        box-shadow: 0 2px 12px rgba(47,43,61,0.14) !important;
    }
    #cpb-portal .cpp-topbar-hamburger {
        width: 40px !important;
        height: 40px !important;
        border-radius: 10px !important;
        border: 1px solid #e2e8f0 !important;
        background: #f8fafc !important;
        font-size: 1.3rem !important;
        color: #2b2c40 !important;
        box-shadow: 0 1px 4px rgba(0,0,0,0.06) !important;
    }
    #cpb-portal .cpp-topbar-hamburger:hover,
    #cpb-portal .cpp-topbar-hamburger:active {
        background: #1E78CD !important;
        color: #fff !important;
        border-color: #1E78CD !important;
    }
}

/* Flatpickr: hide floating calendar until opened (inline .inline calendars unchanged) */
body .flatpickr-calendar:not(.open):not(.inline) {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
}
