/**
 * CW First-Party Popups, Sticky & Lead Engine — Frontend Stylesheet v1.4.0
 * 100% System / Inherited Fonts — Zero Google Fonts Remote Calls
 */

/* Prevent scroll when center modal open */
body.cw-popup-open {
    overflow: hidden !important;
}

/* ==========================================================================
   1. CENTER MODAL OVERLAY & BACKDROP
   ========================================================================== */
.cw-popup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 999999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.28s ease, visibility 0.28s ease;
    padding: 16px;
    box-sizing: border-box;
}

.cw-popup-overlay.cw-active {
    opacity: 1;
    visibility: visible;
}

.cw-popup-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(15, 23, 42, 0.72);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.cw-popup-container {
    position: relative;
    z-index: 2;
    width: 100%;
    max-width: 540px;
    max-height: 90vh;
    overflow-y: auto;
    border-radius: 16px;
    transform: scale(0.94) translateY(12px);
    transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1);
}

.cw-popup-overlay.cw-active .cw-popup-container {
    transform: scale(1) translateY(0);
}

.cw-popup-card {
    position: relative;
    background: #ffffff;
    border-radius: 16px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.35);
    padding: 32px 28px;
    color: #1e293b;
    font-family: inherit;
}

.cw-popup-close {
    position: absolute;
    top: 14px;
    right: 14px;
    width: 36px;
    height: 36px;
    background: #f1f5f9;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #64748b;
    transition: background-color 0.15s, color 0.15s, transform 0.15s;
    z-index: 10;
}

.cw-popup-close:hover {
    background: #e2e8f0;
    color: #0f172a;
    transform: rotate(90deg);
}

/* ==========================================================================
   2. STICKY SIDE-TAB & FLYOUT DRAWER (MyStickyElements Replacement)
   ========================================================================== */
.cw-sticky-widget {
    position: fixed;
    z-index: 999990;
    font-family: inherit;
    box-sizing: border-box;
}

/* Left Side-Tab (Sagres Default) */
.cw-sticky-widget.cw-mode-sticky_left {
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
}

/* Right Side-Tab */
.cw-sticky-widget.cw-mode-sticky_right {
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    flex-direction: row-reverse;
    align-items: center;
}

/* Floating Action Button (Bottom Right) */
.cw-sticky-widget.cw-mode-floating_button {
    right: 24px;
    bottom: 24px;
}

/* Sticky Trigger Button */
.cw-sticky-handle {
    position: relative;
    background: transparent;
    border: none;
    padding: 0;
    margin: 0;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    outline: none;
    z-index: 2;
}

/* Rotated "Contattaci!" Label Above Icon (Sagres Style) */
.cw-sticky-rotated-label {
    position: absolute;
    top: -62px;
    left: 50%;
    transform: translateX(-50%) rotate(-90deg);
    white-space: nowrap;
    font-size: 14px;
    font-weight: 800;
    color: #1e293b;
    letter-spacing: 0.02em;
    pointer-events: none;
    text-shadow: 0 1px 2px rgba(255, 255, 255, 0.85);
}

/* Icon Box */
.cw-sticky-icon-box {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-width: 52px;
    min-height: 52px;
    background: var(--cw-popup-primary, #1e73be);
    color: #ffffff;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.22);
    transition: background-color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}

.cw-mode-sticky_left .cw-sticky-icon-box {
    border-radius: 0 28px 28px 0;
    padding: 14px 16px 14px 14px;
}

.cw-mode-sticky_right .cw-sticky-icon-box {
    border-radius: 28px 0 0 28px;
    padding: 14px 14px 14px 16px;
}

.cw-mode-floating_button .cw-sticky-icon-box {
    border-radius: 30px;
    padding: 14px 20px;
}

.cw-sticky-handle:hover .cw-sticky-icon-box {
    background: var(--cw-popup-primary-hover, #155799);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

.cw-sticky-inline-label {
    font-size: 14px;
    font-weight: 700;
    letter-spacing: 0.02em;
    white-space: nowrap;
}

/* Flyout Drawer Container */
.cw-sticky-drawer {
    position: absolute;
    width: var(--cw-drawer-width, 380px);
    max-width: calc(100vw - 64px);
    max-height: 86vh;
    overflow-y: auto;
    border-radius: 14px;
    box-shadow: 0 20px 45px rgba(0, 0, 0, 0.28);
    padding: 24px 22px;
    box-sizing: border-box;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.24s ease, visibility 0.24s ease;
    z-index: 3;
}

.cw-mode-sticky_left .cw-sticky-drawer {
    left: 52px;
    top: 50%;
    transform: translateY(-50%) translateX(-18px);
    border-top-left-radius: 6px;
    border-bottom-left-radius: 6px;
}

.cw-mode-sticky_right .cw-sticky-drawer {
    right: 52px;
    top: 50%;
    transform: translateY(-50%) translateX(18px);
    border-top-right-radius: 6px;
    border-bottom-right-radius: 6px;
}

.cw-mode-floating_button .cw-sticky-drawer {
    right: 0;
    bottom: 66px;
    transform: translateY(16px) scale(0.96);
}

/* Open State for Sticky Drawer */
.cw-sticky-widget.cw-sticky-open .cw-sticky-drawer {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.cw-sticky-widget.cw-mode-sticky_left.cw-sticky-open .cw-sticky-drawer,
.cw-sticky-widget.cw-mode-sticky_right.cw-sticky-open .cw-sticky-drawer {
    transform: translateY(-50%) translateX(0);
}

.cw-sticky-widget.cw-mode-floating_button.cw-sticky-open .cw-sticky-drawer {
    transform: translateY(0) scale(1);
}

/* Theme 1: Brand Background (Sagres Blue #1e73be style) */
.cw-theme-brand_bg .cw-sticky-drawer {
    background: var(--cw-popup-primary, #1e73be);
    color: #ffffff;
}

.cw-theme-brand_bg .cw-popup-title,
.cw-theme-brand_bg .cw-popup-subtitle,
.cw-theme-brand_bg .cw-form-group label,
.cw-theme-brand_bg .cw-checkbox-label,
.cw-theme-brand_bg .cw-checkbox-label a {
    color: #ffffff !important;
}

/* Theme 2: Light Card */
.cw-theme-card_light .cw-sticky-drawer {
    background: #ffffff;
    color: #1e293b;
    border-top: 5px solid var(--cw-popup-primary, #1e73be);
}

/* Close Button inside Sticky Drawer */
.cw-sticky-close {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.2);
    color: currentColor;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.15s, transform 0.15s;
    z-index: 10;
}

.cw-theme-card_light .cw-sticky-close {
    background: #f1f5f9;
    color: #475569;
}

.cw-sticky-close:hover {
    background: rgba(255, 255, 255, 0.35);
    transform: rotate(90deg);
}

/* Formidable Forms Styling Inside Sticky Drawer (Sagres Compatibility) */
.cw-sticky-custom-content .frm_forms .frm_form_fields .frm_primary_label {
    color: inherit !important;
    font-size: 13px !important;
    font-weight: 600 !important;
    margin-bottom: 4px !important;
}

.cw-sticky-custom-content .frm_forms input[type="text"],
.cw-sticky-custom-content .frm_forms input[type="email"],
.cw-sticky-custom-content .frm_forms input[type="tel"],
.cw-sticky-custom-content .frm_forms textarea,
.cw-sticky-custom-content .frm_forms select {
    border-radius: 24px !important;
    padding: 9px 14px !important;
    border: 1px solid rgba(255, 255, 255, 0.4) !important;
    background: #ffffff !important;
    color: #1e293b !important;
    font-size: 13.5px !important;
    width: 100% !important;
    box-sizing: border-box !important;
}

.cw-sticky-custom-content .frm_forms .frm_checkbox label,
.cw-sticky-custom-content .frm_forms .frm_checkbox label a {
    color: inherit !important;
    font-size: 12px !important;
    line-height: 1.35 !important;
}

.cw-sticky-custom-content .frm_forms .frm_checkbox label a {
    text-decoration: underline !important;
}

.cw-sticky-custom-content .frm_forms .frm_button_submit,
.cw-sticky-custom-content .frm_forms button[type="submit"] {
    width: 100% !important;
    border-radius: 24px !important;
    padding: 11px 20px !important;
    font-weight: 700 !important;
    cursor: pointer !important;
}

/* ==========================================================================
   3. BUILT-IN FORM & TYPOGRAPHY
   ========================================================================== */
.cw-popup-eyebrow {
    display: inline-block;
    background: #edf7ee;
    color: var(--cw-popup-primary, #1e73be);
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    padding: 5px 12px;
    border-radius: 20px;
    margin-bottom: 12px;
}

.cw-popup-title {
    margin: 0 0 10px 0;
    font-size: 22px;
    font-weight: 800;
    line-height: 1.25;
    color: #0f172a;
}

.cw-popup-subtitle {
    margin: 0 0 18px 0;
    font-size: 14px;
    line-height: 1.5;
    color: #475569;
}

.cw-form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px 14px;
    margin-bottom: 14px;
}

.cw-sticky-drawer .cw-form-grid {
    grid-template-columns: 1fr;
    gap: 10px;
}

.cw-form-group {
    display: flex;
    flex-direction: column;
}

.cw-form-group-full {
    grid-column: 1 / -1;
}

.cw-form-group label {
    font-size: 12px;
    font-weight: 600;
    color: #334155;
    margin-bottom: 4px;
}

.cw-form-group label span.required {
    color: #ef4444;
}

.cw-form-control {
    width: 100%;
    padding: 10px 14px;
    font-size: 14px;
    border: 1.5px solid #cbd5e1;
    border-radius: 20px;
    background-color: #ffffff;
    color: #0f172a;
    box-sizing: border-box;
    transition: border-color 0.15s, box-shadow 0.15s;
    outline: none;
}

.cw-form-control:focus {
    border-color: var(--cw-popup-primary, #1e73be);
    box-shadow: 0 0 0 3px rgba(30, 115, 190, 0.2);
}

textarea.cw-form-control {
    resize: vertical;
    min-height: 55px;
    border-radius: 14px;
}

.cw-privacy-group {
    margin: 12px 0 16px 0;
}

.cw-checkbox-label {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    cursor: pointer;
    font-size: 11.5px;
    line-height: 1.4;
    color: #64748b;
}

.cw-checkbox-label input[type="checkbox"] {
    margin-top: 2px;
    accent-color: var(--cw-popup-primary, #1e73be);
    cursor: pointer;
}

.cw-submit-wrap {
    margin-top: 6px;
}

.cw-btn-submit {
    width: 100%;
    padding: 13px 20px;
    font-size: 14px;
    font-weight: 700;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    background: linear-gradient(135deg, var(--cw-popup-primary, #1e73be) 0%, var(--cw-popup-primary-hover, #155799) 100%);
    color: #ffffff;
    border: 1.5px solid rgba(255, 255, 255, 0.35);
    border-radius: 24px;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s, filter 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.2);
}

.cw-btn-submit:hover {
    filter: brightness(1.08);
    transform: translateY(-1px);
}

.cw-spinner {
    width: 16px;
    height: 16px;
    border: 2.5px solid rgba(255, 255, 255, 0.35);
    border-radius: 50%;
    border-top-color: #ffffff;
    animation: cw-spin 0.75s linear infinite;
}

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

.cw-form-feedback {
    margin-top: 14px;
    padding: 12px 14px;
    border-radius: 8px;
    font-size: 13px;
    line-height: 1.4;
    font-weight: 500;
    text-align: center;
}

.cw-success-msg {
    background-color: #ecfdf5;
    color: #065f46;
    border: 1px solid #a7f3d0;
}

.cw-error-msg {
    background-color: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

/* Coupon Box Component */
.cw-coupon-box {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #fdfaf5;
    border: 2px dashed var(--cw-popup-accent, #d4a373);
    border-radius: 10px;
    padding: 14px 18px;
    margin: 18px 0;
    gap: 12px;
}

.cw-coupon-code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 20px;
    font-weight: 800;
    color: var(--cw-popup-primary, #1e73be);
}

.cw-coupon-copy-btn {
    background: var(--cw-popup-primary, #1e73be);
    color: #ffffff;
    border: none;
    padding: 10px 16px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
}

@media (max-width: 580px) {
    .cw-popup-card {
        padding: 24px 18px;
    }
    .cw-form-grid {
        grid-template-columns: 1fr;
        gap: 10px;
    }
    .cw-sticky-drawer {
        padding: 18px 16px;
        max-width: calc(100vw - 58px);
    }
}
