/* General Form Styling */
#beehiiv-form {
    display: flex;
    flex-direction: column;
    gap: 15px;
    max-width: 1000px;
    width: 100%;
    --beehiiv-form-control-height: 48px;
}

/* Desktop: Use CSS Grid for precise alignment */
#beehiiv-form .form-row {
    display: grid;
    grid-template-columns: 1fr 1fr auto;
    gap: 10px;
    align-items: stretch;
}

/* Desktop: Single column layout when first name is disabled */
/* Use 2fr to give email field more space, matching the combined width of both fields in normal mode */
#beehiiv-form .form-row.email-only {
    grid-template-columns: 2fr auto;
}

/* Desktop: Checkbox below button - hide the inline version */
#beehiiv-form .form-row .secondary-subscription-wrapper {
    display: none;
}

/* Hide Labels */
#beehiiv-form label {
    display: none;
}

/* Input Fields Styling */
#beehiiv-form .form-row input[type="text"],
#beehiiv-form .form-row input[type="email"] {
    flex: 1; /* Makes inputs take equal space */
    min-width: 200px;
    height: var(--beehiiv-form-control-height);
    min-height: var(--beehiiv-form-control-height);
    padding: 0 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 16px;
}

/* Disclaimer Microcopy */
#beehiiv-form .beehiiv-form-disclaimer {
    margin: 8px 0 0 0;
    font-size: 12px;
    line-height: 1.5;
    font-weight: 400;
    color: #6b6b6b;
    text-align: right;
    overflow-wrap: anywhere;
    width: 100%;
}

/* Submit Button Styling */
#beehiiv-form .form-row .beehiiv-submit-button {
    background-color: var(--beehiiv-theme-color, #ff1493);
    color: white;
    height: var(--beehiiv-form-control-height);
    min-height: var(--beehiiv-form-control-height);
    padding: 0 20px;
    font-size: 16px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
    flex-shrink: 0; /* Prevent button from shrinking */
    grid-column: -2 / -1;
    grid-row: 1;
    justify-self: stretch;
}

/* Submit Button Hover Effect */
#beehiiv-form .form-row .beehiiv-submit-button:hover {
    background-color: var(--beehiiv-theme-color-dark, #d8007c);
}

/* Submit Button Loading State */
#beehiiv-form .form-row .beehiiv-submit-button:disabled {
    background-color: #cccccc;
    cursor: not-allowed;
    opacity: 0.7;
}

/* Loading Animation for Frontend Form */
@keyframes beehiiv-form-spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Form Loading Overlay */
.beehiiv-form-loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    z-index: 1000;
    border-radius: 8px;
    opacity: 0;
    transition: opacity 0.2s ease-in-out;
}

.beehiiv-form-loading-overlay.show {
    opacity: 1;
}

.beehiiv-form-loading-overlay .beehiiv-loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid var(--beehiiv-theme-color, #ff1493);
    border-radius: 50%;
    animation: beehiiv-form-spin 1s linear infinite;
    margin-bottom: 16px;
}

.beehiiv-form-loading-overlay .loading-text {
    font-size: 16px;
    font-weight: bold;
    color: #333;
    text-align: center;
}

/* Form container needs relative positioning for overlay */
#beehiiv-form {
    position: relative;
}

/* Secondary Subscription Checkbox */
#beehiiv-form .secondary-subscription-wrapper {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 0;
}

/* Hide checkbox when in popup mode */
#beehiiv-form.popup-mode .desktop-checkbox-wrapper,
#beehiiv-form.popup-mode .mobile-checkbox-wrapper {
    display: none !important;
}

#beehiiv-form .secondary-subscription-wrapper input[type="checkbox"] {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    width: 20px;
    height: 20px;
    border: 2px solid #ddd;
    border-radius: 4px;
    background-color: #fff;
    cursor: pointer;
    position: relative;
    transition: all 0.3s ease;
    margin: 0;
    flex-shrink: 0;
}

#beehiiv-form .secondary-subscription-wrapper input[type="checkbox"]:hover {
    border-color: var(--beehiiv-theme-color, #ff1493);
    background-color: #fff5f8;
}

#beehiiv-form .secondary-subscription-wrapper input[type="checkbox"]:checked {
    background-color: var(--beehiiv-theme-color, #ff1493);
    border-color: var(--beehiiv-theme-color, #ff1493);
}

#beehiiv-form .secondary-subscription-wrapper input[type="checkbox"]:checked::before {
    content: "✓";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    font-size: 14px;
    font-weight: bold;
    line-height: 1;
}

#beehiiv-form .secondary-subscription-wrapper input[type="checkbox"]:focus {
    outline: 2px solid var(--beehiiv-theme-color, #ff1493);
    outline-offset: 2px;
}

#beehiiv-form .secondary-subscription-wrapper label {
    display: inline !important;
    font-size: 15px;
    color: #333;
    cursor: pointer;
    line-height: 1.4;
    user-select: none;
}

/* Responsive for Mobile */
@media (max-width: 768px) {
    #beehiiv-form {
        gap: 10px;
    }
    
    #beehiiv-form .form-row {
        display: flex; /* Override grid on mobile */
        flex-direction: column;
        gap: 10px;
        order: 2; /* Button section comes after checkbox on mobile */
    }
    
    /* Hide desktop checkbox wrapper on mobile */
    #beehiiv-form .desktop-checkbox-wrapper {
        display: none !important;
    }
    
    /* On mobile: checkbox is separate and centered above button */
    #beehiiv-form .form-row .secondary-subscription-wrapper {
        display: none; /* Hide the inline version */
    }
    
    /* Mobile checkbox styling - centered between inputs and button */
    #beehiiv-form .mobile-checkbox-wrapper {
        display: flex !important; /* Override desktop display: none */
        justify-content: center;
        align-items: center;
        gap: 12px;
        order: 2; /* Checkbox comes after inputs but before button on mobile */
        margin: 10px 0;
        width: 100%;
    }

    /* Make button appear last on mobile */
    #beehiiv-form .form-row .beehiiv-submit-button {
        order: 3; /* Button comes last on mobile */
    }

    /* Keep disclaimer at the very bottom on mobile */
    #beehiiv-form .beehiiv-form-disclaimer {
        order: 4;
        text-align: right;
    }
    
    #beehiiv-form .form-row input[type="text"],
    #beehiiv-form .form-row input[type="email"],
    #beehiiv-form .form-row .beehiiv-submit-button {
        width: 100%; /* Full width on small screens */
    }
}

/* Desktop: Show desktop checkbox wrapper below form-row, aligned with button using grid */
#beehiiv-form .desktop-checkbox-wrapper {
    display: grid;
    grid-template-columns: 1fr 1fr auto;
    gap: 10px;
    margin-top: 10px;
    align-items: center;
}

#beehiiv-form .desktop-checkbox-wrapper .checkbox-content {
    grid-column: 3;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-direction: row-reverse; /* Put checkbox on the right of text */
}

/* Desktop: Adjust checkbox wrapper when first name is disabled to match email-only layout */
#beehiiv-form .desktop-checkbox-wrapper.email-only {
    grid-template-columns: 2fr auto;
}

/* When email-only, checkbox content should be in column 2 instead of 3 */
#beehiiv-form .desktop-checkbox-wrapper.email-only .checkbox-content {
    grid-column: 2;
}

/* Desktop: Hide mobile checkbox wrapper */
#beehiiv-form .mobile-checkbox-wrapper {
    display: none;
}

/* Desktop checkbox styling */
#beehiiv-form .desktop-checkbox-wrapper input[type="checkbox"] {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    width: 20px;
    height: 20px;
    border: 2px solid #ddd;
    border-radius: 4px;
    background-color: #fff;
    cursor: pointer;
    position: relative;
    transition: all 0.3s ease;
    margin: 0;
    flex-shrink: 0;
}

#beehiiv-form .desktop-checkbox-wrapper input[type="checkbox"]:hover {
    border-color: var(--beehiiv-theme-color, #ff1493);
    background-color: #fff5f8;
}

#beehiiv-form .desktop-checkbox-wrapper input[type="checkbox"]:checked {
    background-color: var(--beehiiv-theme-color, #ff1493);
    border-color: var(--beehiiv-theme-color, #ff1493);
}

#beehiiv-form .desktop-checkbox-wrapper input[type="checkbox"]:checked::before {
    content: "✓";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    font-size: 14px;
    font-weight: bold;
    line-height: 1;
}

#beehiiv-form .desktop-checkbox-wrapper input[type="checkbox"]:focus {
    outline: 2px solid var(--beehiiv-theme-color, #ff1493);
    outline-offset: 2px;
}

#beehiiv-form .desktop-checkbox-wrapper label {
    display: inline !important;
    font-size: 15px;
    color: #333;
    cursor: pointer;
    line-height: 1.4;
    user-select: none;
}

/* Shared checkbox styling for both desktop and mobile versions */
#beehiiv-form .mobile-checkbox-wrapper input[type="checkbox"] {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    width: 20px;
    height: 20px;
    border: 2px solid #ddd;
    border-radius: 4px;
    background-color: #fff;
    cursor: pointer;
    position: relative;
    transition: all 0.3s ease;
    margin: 0;
    flex-shrink: 0;
}

#beehiiv-form .mobile-checkbox-wrapper input[type="checkbox"]:hover {
    border-color: var(--beehiiv-theme-color, #ff1493);
    background-color: #fff5f8;
}

#beehiiv-form .mobile-checkbox-wrapper input[type="checkbox"]:checked {
    background-color: var(--beehiiv-theme-color, #ff1493);
    border-color: var(--beehiiv-theme-color, #ff1493);
}

#beehiiv-form .mobile-checkbox-wrapper input[type="checkbox"]:checked::before {
    content: "✓";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    font-size: 14px;
    font-weight: bold;
    line-height: 1;
}

#beehiiv-form .mobile-checkbox-wrapper input[type="checkbox"]:focus {
    outline: 2px solid var(--beehiiv-theme-color, #ff1493);
    outline-offset: 2px;
}

#beehiiv-form .mobile-checkbox-wrapper label {
    display: inline !important;
    font-size: 15px;
    color: #333;
    cursor: pointer;
    line-height: 1.4;
    user-select: none;
}

/* Popup Modal Styles */
.beehiiv-popup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    font-family: inherit;
}

.beehiiv-popup-overlay.show {
    opacity: 1;
    visibility: visible;
}

.beehiiv-popup-modal {
    background-color: #f8f5fc;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    max-width: 450px;
    width: 90%;
    padding: 40px;
    text-align: center;
    font-family: inherit;
    position: relative;
    max-height: 90vh;
    overflow-y: auto;
    /* Initial state - hidden and slightly below */
    opacity: 0;
    transform: translateY(20px) scale(0.98);
    transition: opacity 0.35s cubic-bezier(0.4, 0, 0.2, 1),
                transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Animate modal when overlay is shown */
.beehiiv-popup-overlay.show .beehiiv-popup-modal {
    opacity: 1;
    transform: translateY(0) scale(1);
}

.beehiiv-popup-modal[role="dialog"] {
    outline: none;
}

.beehiiv-popup-modal:focus {
    outline: 2px solid var(--beehiiv-theme-color, #ff1493);
    outline-offset: 0;
}

.beehiiv-popup-title {
    font-size: 24px;
    font-weight: bold;
    color: #222;
    margin: 0 0 16px 0;
    line-height: 1.2;
    font-family: inherit;
}

.beehiiv-popup-body {
    font-size: 16px;
    color: #555;
    margin: 0 0 32px 0;
    line-height: 1.5;
    font-family: inherit;
}

.beehiiv-popup-buttons {
    display: flex;
    flex-direction: row-reverse; /* Yes on right, No on left for desktop */
    gap: 12px;
    justify-content: center;
    align-items: stretch; /* Ensure buttons match height when text wraps */
    width: 100%;
}

.beehiiv-popup-button {
    padding: 12px 28px;
    font-size: 16px;
    font-weight: 600;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
    min-height: 48px; /* Minimum height for consistent appearance */
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.beehiiv-popup-button:focus {
    outline: 2px solid var(--beehiiv-theme-color, #ff1493);
    outline-offset: 2px;
}

/* Desktop: Yes button 75%, No button 25% */
.beehiiv-popup-yes {
    flex: 3;
    min-width: 0;
    background-color: var(--beehiiv-theme-color, #ff1493);
    color: white;
}

.beehiiv-popup-yes:hover {
    background-color: var(--beehiiv-theme-color-dark, #d8007c);
}

.beehiiv-popup-yes:disabled {
    background-color: #ccc;
    cursor: not-allowed;
    opacity: 0.6;
}

.beehiiv-popup-no {
    flex: 1;
    min-width: 0;
    background-color: #e0e0e0;
    color: #333;
}

.beehiiv-popup-no:hover {
    background-color: #d0d0d0;
}

.beehiiv-popup-no:disabled {
    background-color: #f0f0f0;
    cursor: not-allowed;
    opacity: 0.6;
}

/* Button loading state */
.beehiiv-popup-button.loading {
    position: relative;
    color: transparent !important;
    pointer-events: none;
}

.beehiiv-popup-button.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 18px;
    height: 18px;
    margin-top: -9px;
    margin-left: -9px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: beehiiv-btn-spin 0.8s linear infinite;
}

.beehiiv-popup-no.loading::after {
    border: 2px solid rgba(0, 0, 0, 0.15);
    border-top-color: #333;
}

/* EXP-002 reuses the accessible popup mechanics while retaining its polished,
   pathway-specific presentation. The configured plugin theme colour remains
   the accent so this shared ZIP does not hard-code a site or campaign brand. */
body.beehiiv-exp002-open {
    overflow: hidden;
}

.beehiiv-popup-overlay.beehiiv-exp002-overlay {
    z-index: 10000;
    padding: 24px;
    background: rgba(31, 37, 25, 0.36);
}

.beehiiv-exp002-overlay .beehiiv-exp002-modal {
    box-sizing: border-box;
    width: calc(100% - 48px);
    max-width: 560px;
    max-height: 92vh;
    padding: 28px;
    overflow-y: auto;
    overscroll-behavior: contain;
    border: 1px solid #ded7c8;
    border-radius: 28px;
    background: #fffdf9;
    box-shadow: 0 24px 70px rgba(43, 48, 34, 0.2);
    color: #172d25;
    text-align: left;
    overflow-wrap: anywhere;
    transform: translateY(14px) scale(0.985);
    transition: opacity 0.25s ease, transform 0.25s ease;
}

.beehiiv-exp002-overlay.show .beehiiv-exp002-modal {
    transform: translateY(0) scale(1);
}

.beehiiv-exp002-modal:focus,
.beehiiv-exp002-button:focus-visible {
    outline: 3px solid var(--beehiiv-theme-color, #ff1493);
    outline-offset: 2px;
}

.beehiiv-exp002-modal .beehiiv-exp002-eyebrow {
    margin: 0 0 12px;
    color: #68725c;
    font-size: 14px;
    font-weight: 700;
    letter-spacing: 0.06em;
    line-height: 1.3;
    text-align: left;
    text-transform: uppercase;
}

.beehiiv-exp002-modal .beehiiv-exp002-title {
    margin: 0 0 14px;
    color: #173129;
    font-family: Georgia, serif;
    font-size: clamp(30px, 6vw, 42px);
    line-height: 1.04;
    text-align: left;
    text-transform: none;
}

.beehiiv-exp002-modal .beehiiv-exp002-body {
    margin: 0 0 20px;
    color: #5c6558;
    font-size: 17px;
    line-height: 1.55;
    text-align: left;
}

.beehiiv-exp002-benefits {
    margin: 0 0 22px;
    padding: 18px 18px 10px 48px;
    border: 1px solid #e1dacb;
    border-radius: 18px;
    background: #faf7f0;
}

.beehiiv-exp002-benefits:empty {
    display: none;
}

.beehiiv-exp002-benefits li {
    margin: 0 0 10px;
    padding-left: 4px;
    line-height: 1.4;
}

.beehiiv-exp002-benefits li::marker {
    color: var(--beehiiv-theme-color, #ff1493);
    content: '\2713  ';
    font-weight: 700;
}

.beehiiv-popup-buttons.beehiiv-exp002-buttons {
    display: flex;
    flex-direction: column;
    gap: 0;
    align-items: stretch;
}

.beehiiv-exp002-buttons .beehiiv-exp002-button {
    box-sizing: border-box;
    width: 100%;
    min-height: 58px;
    margin: 0 0 12px;
    padding: 14px 20px;
    flex: none;
    border: 1px solid #dcd5c7;
    border-radius: 16px;
    font-size: 17px;
    font-weight: 700;
    line-height: 1.35;
}

.beehiiv-exp002-buttons .beehiiv-exp002-yes {
    border-color: var(--beehiiv-theme-color, #ff1493);
    background: var(--beehiiv-theme-color, #ff1493);
    color: #fff;
    box-shadow: 0 8px 18px rgba(43, 48, 34, 0.16);
}

.beehiiv-exp002-buttons .beehiiv-exp002-yes:not(.loading):hover,
.beehiiv-exp002-buttons .beehiiv-exp002-yes:not(.loading):focus-visible,
.beehiiv-exp002-buttons .beehiiv-exp002-yes:not(.loading):active {
    background: var(--beehiiv-theme-color-dark, #d8007c);
    color: #fff !important;
}

.beehiiv-exp002-buttons .beehiiv-exp002-no {
    background: #fff;
    color: #173129;
}

.beehiiv-exp002-buttons .beehiiv-exp002-no:not(.loading):hover,
.beehiiv-exp002-buttons .beehiiv-exp002-no:not(.loading):focus-visible,
.beehiiv-exp002-buttons .beehiiv-exp002-no:not(.loading):active {
    background: #faf7f0;
    color: #173129 !important;
}

.beehiiv-exp002-footnote {
    margin: 4px 0 0;
    color: #697164;
    font-size: 13px;
    line-height: 1.45;
    text-align: center;
}

.beehiiv-exp002-body:empty,
.beehiiv-exp002-footnote:empty {
    display: none;
}

/* The short challenger mirrors the DG popup's one-question, two-choice rhythm. */
.beehiiv-exp002-overlay[data-popup-variant="challenger"] .beehiiv-exp002-modal {
    max-width: 600px;
    padding: 38px;
    text-align: center;
}

.beehiiv-exp002-overlay[data-popup-variant="challenger"] .beehiiv-exp002-eyebrow,
.beehiiv-exp002-overlay[data-popup-variant="challenger"] .beehiiv-exp002-title,
.beehiiv-exp002-overlay[data-popup-variant="challenger"] .beehiiv-exp002-body {
    text-align: center;
}

.beehiiv-exp002-overlay[data-popup-variant="challenger"] .beehiiv-exp002-title {
    margin-bottom: 26px;
    font-family: Arial, sans-serif;
    font-size: clamp(27px, 5vw, 34px);
    line-height: 1.2;
}

.beehiiv-exp002-overlay[data-popup-variant="challenger"] .beehiiv-exp002-buttons {
    flex-direction: row-reverse; /* Keep the affirmative action on the right, matching DG and the control. */
    gap: 12px;
}

.beehiiv-exp002-overlay[data-popup-variant="challenger"] .beehiiv-exp002-button {
    min-width: 0;
    margin: 0;
    flex: 1;
}

@keyframes beehiiv-btn-spin {
    to { transform: rotate(360deg); }
}

/* Mobile responsive popup */
@media (max-width: 600px) {
    .beehiiv-popup-modal {
        width: 95%;
        padding: 30px 20px;
        max-width: 100%;
    }

    .beehiiv-popup-title {
        font-size: 20px;
    }

    .beehiiv-popup-body {
        font-size: 15px;
    }

    .beehiiv-popup-buttons {
        flex-direction: column; /* Yes on top, No below */
        align-items: center;
    }

    .beehiiv-popup-button {
        min-width: unset;
    }

    /* Mobile: Yes button 75% width, No button 50% width */
    .beehiiv-popup-yes {
        width: 75%;
        flex: none;
    }

    .beehiiv-popup-no {
        width: 50%;
        flex: none;
    }

    .beehiiv-popup-overlay.beehiiv-exp002-overlay {
        align-items: flex-end;
        padding: 10px 10px max(10px, env(safe-area-inset-bottom));
    }

    .beehiiv-exp002-overlay .beehiiv-exp002-modal {
        width: 100%;
        max-width: 560px;
        max-height: calc(100dvh - 20px);
        padding: 24px 20px;
        border-radius: 24px;
    }

    .beehiiv-exp002-modal .beehiiv-exp002-title {
        font-size: clamp(29px, 9vw, 34px);
    }

    .beehiiv-exp002-modal .beehiiv-exp002-body {
        font-size: 16px;
    }

    .beehiiv-exp002-buttons .beehiiv-exp002-button {
        width: 100%;
        min-height: 56px;
    }

    .beehiiv-exp002-overlay[data-popup-variant="challenger"] .beehiiv-exp002-modal {
        padding: 24px 20px;
    }

    .beehiiv-exp002-overlay[data-popup-variant="challenger"] .beehiiv-exp002-buttons {
        flex-direction: column;
    }
}

@media (prefers-reduced-motion: reduce) {
    .beehiiv-exp002-overlay,
    .beehiiv-exp002-overlay .beehiiv-exp002-modal {
        transition: none;
    }
}
