/* --- NEW: Prevent Body Scroll --- */
body.sfp-modal-is-open,
body.sfp-overlay-is-open { /* ADDED overlay class */
    overflow: hidden;
}

/* --- General & Layout --- */
.sfp-library-wrapper {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    color: #111;
    background: #fcfcfc;
}
.sfp-library {
    padding: 20px;
    position: relative;
    max-width: 1400px;
    margin: 0 auto;
}

/* --- Header --- */
.sfp-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;
    padding-bottom: 20px;
    border-bottom: 1px solid #eee;
}
.sfp-header h1 {
    font-weight: 700;
    letter-spacing: -0.02em;
    margin: 0;
    font-size: 24px;
}
.sfp-header-right {
    display: flex;
    gap: 18px;
    align-items: center;
}
.sfp-remaining {
    background: #fff;
    padding: 8px 14px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
    border: 1px solid #eee;
    font-weight: 600;
    font-size: 14px;
}
#sfp_remaining_count {
    font-weight: 700;
    color: #0073aa;
}

/* --- Admin Save Order Bar --- */
.sfp-save-order-wrap {
    display: flex;
    align-items: center;
    gap: 15px;
    background: #fff;
    border: 1px solid #ddd;
    padding: 10px 15px;
    border-radius: 8px;
    margin-bottom: 25px;
}
.sfp-save-order-wrap .sfp-save-status {
    font-size: 14px;
    color: #555;
    transition: color 0.3s ease;
}
#sfp_save_order_btn {
    padding: 8px 15px;
    font-size: 14px;
    height: auto;
    line-height: 1.5;
}


/* --- Filter Bar --- */
.sfp-filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 25px;
}
.sfp-filter-item {
    flex-grow: 1;
    flex-basis: 180px;
}
.sfp-filter-item.sfp-search-item {
    flex-basis: 300px; /* Search bar has a min width */
}
.sfp-filter {
    width: 100%;
    padding: 12px 14px;
    border-radius: 8px;
    border: 1px solid #ddd;
    background: #fff;
    font-size: 14px;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}
select.sfp-filter {
    background-image: url('image/svg+xml;charset=US-ASCII,%3Csvg%20width%3D%2220%22%20height%3D%2220%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Cpath%20d%3D%22M5%208l5%205%205-5%22%20fill%3D%22none%22%20stroke%3D%22%23666%22%20stroke-width%3D%221.5%22%20stroke-linecap%3D%22round%22%20stroke-linejoin%3D%22round%22%2F%3E%3C%2Fsvg%3E');
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 16px;
    padding-right: 35px; /* space for arrow */
    cursor: pointer;
}

/* --- Video Grid --- */
.sfp-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill,minmax(280px,1fr));
    gap: 20px;
}
.sfp-card {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 6px 18px rgba(0,0,0,0.04);
    border: 1px solid #eee;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.sfp-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 10px 25px rgba(0,0,0,0.08);
}

/* Admin Sorting Placeholders */
.sfp-grid.is-admin-sortable .sfp-card {
    cursor: move;
}
.sfp-card.ui-sortable-helper { /* Item being dragged */
    transform: translateY(-4px) scale(1.05);
    box-shadow: 0 10px 25px rgba(0,0,0,0.2) !important;
    cursor: grabbing;
}
.sfp-sortable-placeholder {
    border: 2px dashed #0073aa;
    background: #f0f6fa;
    border-radius: 12px;
    visibility: visible !important;
    height: 180px; /* Match thumb height */
    box-shadow: none;
}


.sfp-thumb {
    height: 180px;
    background-size: cover;
    background-position: center;
    position: relative;
    cursor: pointer;
    background-color: #eee;
    overflow: hidden; /* Contain hover video */
}
.sfp-thumb-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s ease;
    z-index: 2; /* On top of hover video */
}
.sfp-card:hover .sfp-thumb-overlay {
    opacity: 1;
}
.sfp-hover-video {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    z-index: 1; /* Below overlay */
}
.sfp-preview {
    padding: 10px 18px;
    border-radius: 20px;
    border: 0;
    background: rgba(255,255,255,0.9);
    color: #111;
    font-weight: 600;
    cursor: pointer;
    transform: translateY(10px);
    transition: transform 0.2s ease;
}
.sfp-card:hover .sfp-preview {
    transform: translateY(0);
}
.sfp-card-content {
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    flex-grow: 1;
}
.sfp-card-content h3 {
    margin: 0 0 5px 0;
    font-size: 17px;
    font-weight: 600;
}
.sfp-meta {
    font-size: 13px;
    color: #666;
    margin: 0;
    text-transform: capitalize;
    min-height: 1.2em; /* Prevent layout shift */
}
.sfp-meta span {
    margin-right: 8px;
    opacity: 0.8;
}
.sfp-actions {
    margin-top: auto;
    padding-top: 15px;
    border-top: 1px solid #f5f5ff;
    margin-top: 15px;
}
.sfp-download {
    width: 100%;
    padding: 12px 10px;
    border-radius: 8px;
    border: 0;
    background: #222;
    color: #fff;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease, opacity 0.2s ease;
}
.sfp-download:hover {
    background: #000;
}
.sfp-download[disabled] {
    opacity: 0.5;
    cursor: not-allowed;
}
.sfp-no-results {
    grid-column: 1 / -1;
    text-align: center;
    padding: 40px;
    font-size: 16px;
    color: #555;
}

/* --- Blur Effect --- */
.sfp-content.sfp-blurred {
    filter: blur(8px);
    pointer-events: none;
    /* NEW: Prevent content from being selected when blurred */
    user-select: none;
}

/* --- MODIFIED Overlay for Gated Content --- */
.sfp-overlay {
    position: fixed; /* ✅ FIXED: was absolute */
    inset: 0;
    background: rgba(0,0,0,0.5); /* Darkened background */
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    padding: 20px; /* Added padding for small screens */
}
.sfp-overlay-inner {
    width: 400px;
    max-width: 100%;
    text-align: center;
    padding: 30px;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.1);
    margin: auto; 
}
.sfp-overlay-inner form {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin: 20px 0;
}
.sfp-overlay-inner input[type="text"],
.sfp-overlay-inner input[type="email"] {
    width: 100%;
    padding: 12px;
    border-radius: 8px;
    border: 1px solid #ddd;
    box-sizing: border-box; /* Important */
    margin-bottom: 10px; /* Added margin */
}
.sfp-button-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    justify-content: center;
    margin-top: 10px; /* Reduced margin */
}
.sfp-buy-btn, .sfp-login-btn {
    display: inline-block;
    padding: 14px 25px;
    border-radius: 8px;
    text-decoration: none;
    font-weight: 600;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    cursor: pointer;
    border: none;
    width: 100%;
}
.sfp-buy-btn {
    background: #111;
    color: #fff;
}
.sfp-login-btn {
    background: #f0f0f0;
    color: #333;
}
.sfp-buy-btn:hover, .sfp-login-btn:hover {
    transform: scale(1.03);
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
}
.sfp-small {
    font-size: 13px;
    color: #777;
    margin-top: 20px;
}

/* --- Modals (Base) --- */
.sfp-modal {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.6);
    z-index: 99990;
    padding: 20px;
}
.sfp-modal-inner {
    background: #fff;
    width: 720px;
    max-width: 100%;
    border-radius: 10px;
    padding: 20px;
    position: relative;
    box-shadow: 0 20px 50px rgba(0,0,0,0.3);
    max-height: 90vh;
    display: flex;
    flex-direction: column;
}
.sfp-modal-close {
    position: absolute;
    right: 12px;
    top: 8px;
    background: transparent;
    border: 0;
    font-size: 28px;
    line-height: 1;
    cursor: pointer;
    color: #888;
    padding: 5px;
    z-index: 99992;
}
.sfp-modal-close:hover {
    color: #111;
}
.sfp-loading {
    text-align: center;
    padding: 40px;
    font-size: 16px;
    color: #555;
}

/* --- Login Modal --- */
.sfp-login-modal-inner {
    width: 400px;
    max-width: 100%;
}
.sfp-login-modal-inner h2 {
    text-align: center;
    margin-top: 10px;
    margin-bottom: 25px;
}
#sfp_login_container #loginform {
    border: none;
    box-shadow: none;
    padding: 0;
}
#sfp_login_container #loginform p {
    margin-bottom: 15px;
}
#sfp_login_container #loginform label {
    font-weight: 600;
    color: #333;
}
#sfp_login_container #loginform input[type="text"],
#sfp_login_container #loginform input[type="password"] {
    width: 100%;
    padding: 10px;
    border-radius: 8px;
    border: 1px solid #ddd;
    box-shadow: none;
    margin-top: 5px;
}
#sfp_login_container .login-remember {
    font-size: 13px;
}
#sfp_login_container .login-submit #wp-submit {
    width: 100%;
    padding: 12px;
    border-radius: 8px;
    background: #111;
    border: none;
    height: auto;
    font-weight: 600;
    font-size: 15px;
    transition: transform 0.2s ease;
}
#sfp_login_container .login-submit #wp-submit:hover {
    transform: scale(1.02);
}

/* --- NEW: Checkout IFRAME Modal --- */
.sfp-checkout-modal-inner {
    width: 90vw;
    max-width: 600px; /* Max width for a checkout form */
    height: 90vh;
    padding: 20px;
}
.sfp-checkout-container {
    overflow-y: hidden; /* IFRAME will handle scrolling */
    padding: 0;
    height: 100%;
    display: flex;
    flex-direction: column;
}
.sfp-checkout-container iframe {
    width: 100%;
    height: 100%;
    border: none;
    flex-grow: 1;
}

/* --- NEW: Hide Checkout Fields --- */
/* This class is added by PHP in frontend.php */
.woocommerce-checkout .form-row.sfp-hidden-field {
    display: none !important;
}

/* --- Aspect Ratio Containers for Bunny Stream --- */
.sfp-aspect-container {
    position: relative;
    width: 100%;
    height: 0;
}
.sfp-aspect-container iframe,
.sfp-aspect-container video {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: 0;
}

/* --- Preview Modal & Watermark --- */
.sfp-preview-modal-inner {
    width: 90vw;
    height: 90vh;
    padding: 0;
    background: #000;
    overflow: hidden;
}
#sfp_preview_container { /* This is the main wrapper */
    width: 100%;
    height: 100%;
    position: relative; /* Key for watermark */
    display: flex; /* Center video by default */
    align-items: center;
    justify-content: center;
}
#sfp_preview_container video,
#sfp_preview_container iframe { /* Apply to both */
    width: 100%;
    height: 100%;
    object-fit: contain;
    z-index: 1; /* Below watermark */
    border: none;
}
.sfp-video-watermark {
    position: absolute;
    z-index: 2; /* On top of video */
    color: #fff;
    font-weight: 700;
    font-size: 100%; /* Base size, overridden by inline style */
    user-select: none;
    pointer-events: none;
    text-shadow: 0 0 10px rgba(0,0,0,0.5);
    /* Default (center) */
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    padding: 10px;
    white-space: nowrap;
}
/* Position overrides */
.sfp-video-watermark[data-position="top-left"] {
    top: 20px;
    left: 20px;
    transform: none;
}
.sfp-video-watermark[data-position="top-right"] {
    top: 20px;
    right: 20px;
    left: auto;
    transform: none;
}
.sfp-video-watermark[data-position="bottom-left"] {
    bottom: 20px;
    top: auto;
    left: 20px;
    transform: none;
}
.sfp-video-watermark[data-position="bottom-right"] {
    bottom: 20px;
    top: auto;
    right: 20px;
    left: auto;
    transform: none;
}
.sfp-preview-modal-inner .sfp-modal-close {
    color: #fff;
    opacity: 0.7;
    right: 20px;
    top: 15px;
    font-size: 36px;
    font-weight: 300;
    z-index: 3; /* Above watermark */
}
.sfp-preview-modal-inner .sfp-modal-close:hover {
    opacity: 1;
}