/**
 * Critical fixes for Waply admin
 * !important flags are used to override any other styles
 */

/* Force scroll bar to always be visible */
html {
    overflow-y: scroll !important;
    margin-right: 0 !important;
    padding-right: 0 !important;
    width: auto !important;
}

body {
    overflow-y: auto !important;
    margin-right: 0 !important;
    padding-right: 0 !important;
    width: auto !important;
}

/* Hide one of the buttons based on active button type */
body[data-active-button-type="standard"] #waply-custom-preview-button,
body[data-active-button-type="standard"] #waply-custom-pos-preview-btn {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    position: absolute !important;
    top: -9999px !important;
    left: -9999px !important;
}

body[data-active-button-type="custom"] #waply-preview-btn-top,
body[data-active-button-type="custom"] #waply-pos-preview-btn {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    position: absolute !important;
    top: -9999px !important;
    left: -9999px !important;
}

/* Always show custom button on custom button page */
body.wp-admin.waply-custom-button-page #waply-custom-preview-button,
body.wp-admin.waply-custom-button-page #waply-custom-pos-preview-btn {
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
    position: relative !important;
}

/* Button type tabs styling */
.waply-button-type-tabs {
    margin-bottom: 0 !important;
}

.waply-button-type-tab {
    transition: all 0.3s ease;
}

.waply-button-type-tab:hover {
    background-color: #f8f8f8 !important;
}

.waply-button-type-tab.active {
    background-color: #f0f0f0 !important;
    border-bottom-color: #f0f0f0 !important;
}

/* Fix for button previews */
#waply-preview-btn-top {
    display: block !important;
    margin: 0 auto !important;
    text-align: center !important;
    max-width: 173px !important;
}

#waply-custom-preview-button {
    display: flex !important;
    margin: 0 auto !important;
    align-items: center !important;
    justify-content: center !important;
}

/* Make sure the correct button is shown based on active tab */
body[data-active-button-type="standard"] .waply-style-options {
    display: block !important;
}

body[data-active-button-type="custom"] .waply-style-options {
    display: none !important;
}

/* Fix for position preview buttons */
#waply-pos-preview-btn,
#waply-custom-pos-preview-btn {
    position: absolute !important;
    z-index: 10 !important;
}

body[data-active-button-type="standard"] #waply-pos-preview-btn {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
}

body[data-active-button-type="custom"] #waply-custom-pos-preview-btn {
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
}

/* Fix for button icons */
#waply-pos-preview-btn .waply-btn-icon,
#waply-preview-btn-top .waply-btn-icon {
    display: block !important;
    width: 100% !important;
    height: auto !important;
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
    outline: none !important;
}

/* Fix for position preview button */
#waply-pos-preview-btn {
    display: block !important;
    width: 173px !important;
    height: 60px !important;
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
    outline: none !important;
    box-shadow: none !important;
    background-color: transparent !important;
    object-fit: contain !important;
    position: absolute !important;
    transform: translate(-50%, -50%) !important;
    z-index: 10 !important;
    max-width: none !important;
    max-height: none !important;
}

/* Force button visibility */
.waply-preview-screen #waply-pos-preview-btn {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
}

/* Ultra-direct button selection mechanism */
.waply-ultra-direct-buttons {
    display: flex !important;
    flex-wrap: wrap !important;
    justify-content: center !important;
    gap: 20px !important;
    margin: 20px 0 !important;
}

.waply-ultra-button-option {
    width: 220px !important;
    border: 3px solid #ddd !important;
    border-radius: 8px !important;
    padding: 15px !important;
    text-align: center !important;
    transition: all 0.3s ease !important;
    background-color: #fff !important;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1) !important;
    margin-bottom: 20px !important;
}

.waply-ultra-button-option:hover {
    border-color: #2271b1 !important;
    box-shadow: 0 5px 15px rgba(0,0,0,0.1) !important;
    transform: translateY(-5px) !important;
}

.waply-ultra-button-option.selected {
    border-color: #2271b1 !important;
    background-color: #f0f7fc !important;
    box-shadow: 0 5px 15px rgba(34, 113, 177, 0.2) !important;
    position: relative !important;
}

.waply-ultra-button-option.selected:before {
    content: "✓ SELECTED" !important;
    position: absolute !important;
    top: -12px !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
    background-color: #2271b1 !important;
    color: white !important;
    padding: 3px 10px !important;
    border-radius: 4px !important;
    font-size: 12px !important;
    font-weight: bold !important;
    letter-spacing: 1px !important;
    white-space: nowrap !important;
}

.waply-ultra-button-preview {
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    gap: 10px !important;
}

.waply-ultra-button-img {
    width: 173px !important;
    height: 60px !important;
    object-fit: contain !important;
    margin-bottom: 10px !important;
    border: 1px solid #f0f0f0 !important;
    padding: 5px !important;
    background-color: #fafafa !important;
    border-radius: 4px !important;
}

.waply-ultra-button-label {
    font-weight: bold !important;
    font-size: 16px !important;
    color: #333 !important;
    margin-bottom: 10px !important;
}

.waply-ultra-button-select {
    display: none !important; /* Hide the radio button select */
}

.waply-ultra-save-button {
    width: 100% !important;
    margin-top: 10px !important;
    font-weight: bold !important;
    text-transform: uppercase !important;
    letter-spacing: 0.5px !important;
    padding: 8px 12px !important;
    height: auto !important;
    line-height: 1.4 !important;
    transition: all 0.3s ease !important;
}

.waply-ultra-save-button:hover {
    transform: translateY(-2px) !important;
    box-shadow: 0 4px 8px rgba(0, 115, 170, 0.3) !important;
}

.waply-ultra-button-option.selected .waply-ultra-save-button {
    background-color: #2271b1 !important;
    border-color: #2271b1 !important;
}

/* Make sure the position preview is visible */
.waply-preview-screen {
    overflow: visible !important;
    position: relative !important;
}

#waply-pos-preview-btn {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    z-index: 100 !important;
}

/* Custom button message */
#waply-custom-button-message {
    background-color: #f8f8f8 !important;
    border: 1px solid #ddd !important;
    border-radius: 5px !important;
    padding: 30px !important;
    margin: 20px 0 !important;
    text-align: center !important;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05) !important;
}

#waply-custom-button-message h3 {
    font-size: 20px !important;
    margin-bottom: 15px !important;
    color: #333 !important;
}

#waply-custom-button-message p {
    font-size: 15px !important;
    margin-bottom: 20px !important;
    color: #555 !important;
}

#waply-custom-button-message .button-primary {
    font-size: 16px !important;
    padding: 10px 20px !important;
    height: auto !important;
    line-height: 1.4 !important;
    text-transform: uppercase !important;
    font-weight: bold !important;
    transition: all 0.3s ease !important;
}

#waply-custom-button-message .button-primary:hover {
    transform: translateY(-2px) !important;
    box-shadow: 0 4px 8px rgba(0, 115, 170, 0.3) !important;
}

/* Fix for position preview button */
.waply-preview-screen #waply-pos-preview-btn {
    position: absolute !important;
    transform: translate(-50%, -50%) !important;
    z-index: 10 !important;
}

/* Fix for button positioning at edges */
.waply-preview-screen {
    position: relative !important;
    overflow: visible !important;
    padding: 150px !important;
    box-sizing: border-box !important;
    min-height: 500px !important;
}

#waply-pos-preview-btn,
#waply-custom-pos-preview-btn {
    transform: translate(-50%, -50%) !important;
    width: 173px !important;
    height: 60px !important;
    min-width: 173px !important;
    min-height: 60px !important;
    max-width: 173px !important;
    max-height: 60px !important;
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    z-index: 9999 !important;
}

/* Ensure buttons stay within the preview area */
.waply-preview-screen #waply-pos-preview-btn,
.waply-preview-screen #waply-custom-pos-preview-btn {
    position: absolute !important;
    transform-origin: center center !important;
}

/* Ensure the button is visible at extreme positions */
.waply-preview-screen #waply-pos-preview-btn[style*="left:100%"],
.waply-preview-screen #waply-custom-pos-preview-btn[style*="left:100%"] {
    margin-left: -100px !important;
}

.waply-preview-screen #waply-pos-preview-btn[style*="top:100%"],
.waply-preview-screen #waply-custom-pos-preview-btn[style*="top:100%"] {
    margin-top: -80px !important;
}

/* Ensure the button is visible at 0% positions */
.waply-preview-screen #waply-pos-preview-btn[style*="left:0%"],
.waply-preview-screen #waply-custom-pos-preview-btn[style*="left:0%"] {
    margin-left: 100px !important;
}

.waply-preview-screen #waply-pos-preview-btn[style*="top:0%"],
.waply-preview-screen #waply-custom-pos-preview-btn[style*="top:0%"] {
    margin-top: 80px !important;
}

/* Handle corner cases */
.waply-preview-screen #waply-pos-preview-btn[style*="left:100%"][style*="top:100%"],
.waply-preview-screen #waply-custom-pos-preview-btn[style*="left:100%"][style*="top:100%"] {
    margin-left: -100px !important;
    margin-top: -80px !important;
}

.waply-preview-screen #waply-pos-preview-btn[style*="left:0%"][style*="top:0%"],
.waply-preview-screen #waply-custom-pos-preview-btn[style*="left:0%"][style*="top:0%"] {
    margin-left: 100px !important;
    margin-top: 80px !important;
}

.waply-preview-screen #waply-pos-preview-btn[style*="left:100%"][style*="top:0%"],
.waply-preview-screen #waply-custom-pos-preview-btn[style*="left:100%"][style*="top:0%"] {
    margin-left: -100px !important;
    margin-top: 80px !important;
}

.waply-preview-screen #waply-pos-preview-btn[style*="left:0%"][style*="top:100%"],
.waply-preview-screen #waply-custom-pos-preview-btn[style*="left:0%"][style*="top:100%"] {
    margin-left: 100px !important;
    margin-top: -80px !important;
}

#waply-custom-pos-preview-btn span {
    display: block !important;
    width: 100% !important;
    height: 100% !important;
    background-size: 50% !important;
    background-position: center !important;
    background-repeat: no-repeat !important;
}

/* Make sure the visible buttons are properly displayed */
body[data-active-button-type="standard"] #waply-preview-btn-top,
body[data-active-button-type="standard"] #waply-pos-preview-btn {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    position: relative !important;
}

body[data-active-button-type="custom"] #waply-custom-preview-button,
body[data-active-button-type="custom"] #waply-custom-pos-preview-btn {
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
    position: relative !important;
}

/* Fix for position preview */
#waply-custom-pos-preview-btn,
#waply-pos-preview-btn {
    position: absolute !important;
}

/* Ensure the preview container has enough height */
.waply-preview-screen {
    min-height: 600px !important;
    height: 600px !important;
    margin-bottom: 50px !important;
    border: 2px solid #ddd !important;
}

/* Fix for button preview container */
#waply-preview-btn-top-container {
    display: inline-block !important;
    width: auto !important;
    margin: 0 auto !important;
}

/* Font fixes - apply to all popup elements */
html body .waply-popup,
html body .waply-comprehensive-popup,
html body .waply-popup-header h2,
html body .waply-popup-header p,
html body .waply-popup-header-title,
html body .waply-popup-header-subtitle,
html body .waply-popup-messages-container,
html body .waply-popup-accounts-container,
html body .waply-popup-account-name,
html body .waply-popup-account-title,
html body .waply-popup-message,
html body .waply-popup-send,
html body .waply-popup-default-message,
html body .waply-online-status {
    font-family: var(--waply-popup-font, inherit) !important;
    font-family: inherit !important;
}

/* Ensure font setting takes precedence */
[data-popup-type="simple"] *,
[data-popup-type="comprehensive"] * {
    font-family: var(--waply-popup-font, inherit) !important;
}
