/**
 * Accessibility & UI Fixes
 * Ensures proper color contrast, readability, and user experience
 */

/* Button Contrast Fixes */
.wp-element-button,
.wp-block-button__link {
    min-height: 44px; /* Touch target size */
    font-weight: 600 !important;
}

/* Ensure buttons have proper contrast */
.wp-block-button__link[style*="background-color: transparent"],
.wp-block-button__link[style*="background:transparent"] {
    border: 2px solid currentColor !important;
    font-weight: 700 !important;
}

/* Fix outline buttons with low contrast */
.wp-block-button.is-style-outline .wp-block-button__link {
    border-width: 2px !important;
    font-weight: 700 !important;
}

/* Ensure white text is only on dark backgrounds */
.has-text-color[style*="color:#ffffff"],
.has-text-color[style*="color: #ffffff"],
.has-text-color[style*="color:rgb(255,255,255)"],
.has-text-color[style*="color: rgb(255,255,255)"] {
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

/* Fix pricing cards hover states */
.pricing-card {
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.pricing-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.15) !important;
}

/* Ensure featured pricing card has strong contrast */
.pricing-card.featured {
    box-shadow: 0 8px 16px rgba(102, 126, 234, 0.3) !important;
}

/* Icon contrast fixes */
svg {
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.05));
}

/* Admin interface fixes */
.tailorbirds-icon-manager button,
.tailorbirds-icon-manager .button {
    min-height: 36px;
    padding: 8px 16px;
    font-weight: 600;
}

/* Copy button visibility */
.copy-btn {
    background-color: #667eea !important;
    color: #ffffff !important;
    border: none !important;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.copy-btn:hover {
    background-color: #5568d3 !important;
}

.copy-btn:active {
    background-color: #4452bb !important;
}

/* Icon grid improvements */
.icon-grid {
    gap: 20px;
}

.icon-item {
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.icon-item:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.2);
}

.icon-item.selected {
    box-shadow: 0 0 0 3px #667eea !important;
    transform: scale(1.05);
}

/* Form input contrast fixes */
input[type="text"],
input[type="email"],
input[type="url"],
input[type="tel"],
input[type="number"],
select,
textarea {
    border: 2px solid #e0e0e0 !important;
    min-height: 44px;
    padding: 10px 14px;
    font-size: 16px; /* Prevents iOS zoom */
}

input[type="text"]:focus,
input[type="email"]:focus,
input[type="url"]:focus,
input[type="tel"]:focus,
input[type="number"]:focus,
select:focus,
textarea:focus {
    border-color: #667eea !important;
    outline: 3px solid rgba(102, 126, 234, 0.2) !important;
    outline-offset: 2px;
}

/* Color picker improvements */
input.color-picker {
    min-height: 44px !important;
    cursor: pointer;
}

/* Range slider accessibility */
input[type="range"] {
    min-height: 44px;
    cursor: pointer;
}

input[type="range"]:focus {
    outline: 3px solid rgba(102, 126, 234, 0.3);
    outline-offset: 2px;
}

/* Checkbox and radio button improvements */
input[type="checkbox"],
input[type="radio"] {
    min-width: 20px;
    min-height: 20px;
    cursor: pointer;
}

input[type="checkbox"]:focus,
input[type="radio"]:focus {
    outline: 3px solid rgba(102, 126, 234, 0.3);
    outline-offset: 2px;
}

/* Link contrast fixes */
a {
    color: inherit;
    transition: opacity 0.2s ease;
}

a:hover {
    opacity: 0.8;
}

a:focus {
    outline: 3px solid rgba(102, 126, 234, 0.5);
    outline-offset: 2px;
    border-radius: 2px;
}

/* Ensure navigation links are visible */
.hm-header__nav a {
    font-weight: 600;
    text-decoration: none;
    position: relative;
}

.hm-header__nav a:hover {
    opacity: 0.7;
}

.hm-header__nav a:focus {
    outline: 3px solid rgba(255, 255, 255, 0.5);
    outline-offset: 2px;
}

/* Admin notices improvements */
.notice,
.notice-success,
.notice-error,
.notice-warning {
    border-left-width: 4px !important;
    padding: 12px !important;
    font-weight: 500;
}

/* Table accessibility */
table {
    border-collapse: collapse;
}

th {
    font-weight: 700;
    background-color: #f8f9fa;
    padding: 12px;
}

td {
    padding: 12px;
    border-bottom: 1px solid #e0e0e0;
}

/* Code block readability */
code,
pre {
    background-color: #f5f5f5 !important;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    padding: 2px 6px;
    font-family: 'Monaco', 'Courier New', monospace;
    font-size: 14px;
}

pre {
    padding: 16px;
    overflow-x: auto;
}

pre code {
    background: none !important;
    border: none;
    padding: 0;
}

/* Loading spinner visibility */
.spinner,
.wp-block-spinner {
    border: 3px solid #f3f3f3;
    border-top: 3px solid #667eea;
    opacity: 1 !important;
}

/* Modal/dialog accessibility */
.wp-block-modal,
[role="dialog"] {
    background-color: white;
    border-radius: 8px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

/* Tooltip visibility */
.tooltip,
[role="tooltip"] {
    background-color: #23282d;
    color: #ffffff;
    padding: 8px 12px;
    border-radius: 4px;
    font-size: 13px;
    font-weight: 600;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

/* Skip to content link */
.skip-link {
    position: absolute;
    top: -40px;
    left: 6px;
    background-color: #667eea;
    color: white;
    padding: 8px 16px;
    text-decoration: none;
    font-weight: 700;
    border-radius: 4px;
    z-index: 100000;
}

.skip-link:focus {
    top: 6px;
    outline: 3px solid rgba(255, 255, 255, 0.8);
    outline-offset: 2px;
}

/* Error messages */
.error,
.error-message,
[role="alert"] {
    background-color: #fee;
    border-left: 4px solid #dc3545;
    padding: 12px 16px;
    color: #721c24;
    font-weight: 600;
}

/* Success messages */
.success,
.success-message {
    background-color: #d4edda;
    border-left: 4px solid #28a745;
    padding: 12px 16px;
    color: #155724;
    font-weight: 600;
}

/* Warning messages */
.warning,
.warning-message {
    background-color: #fff3cd;
    border-left: 4px solid #ffc107;
    padding: 12px 16px;
    color: #856404;
    font-weight: 600;
}

/* Focus visible for keyboard navigation */
*:focus-visible {
    outline: 3px solid #667eea;
    outline-offset: 2px;
}

/* Ensure proper heading hierarchy is visible */
h1 { font-size: clamp(2rem, 5vw, 3rem); }
h2 { font-size: clamp(1.75rem, 4vw, 2.5rem); }
h3 { font-size: clamp(1.5rem, 3vw, 2rem); }
h4 { font-size: clamp(1.25rem, 2vw, 1.5rem); }
h5 { font-size: clamp(1.125rem, 1.5vw, 1.25rem); }
h6 { font-size: clamp(1rem, 1vw, 1.125rem); }

/* Ensure all headings have proper weight */
h1, h2, h3, h4, h5, h6 {
    font-weight: 600;
    line-height: 1.2;
}

/* Mobile improvements */
@media (max-width: 768px) {
    /* Prevent horizontal overflow on mobile */
    html, body {
        overflow-x: hidden !important;
        max-width: 100vw !important;
    }

    /* Ensure touch targets are large enough */
    button,
    a,
    input[type="button"],
    input[type="submit"],
    .wp-block-button__link {
        min-height: 48px;
        min-width: 48px;
    }

    /* Improve mobile navigation */
    .hm-header__nav a {
        padding: 12px 16px;
        display: block;
    }

    /* Larger text for readability */
    body {
        font-size: 16px;
    }

    /* Add proper padding on mobile to all content */
    .wp-site-blocks {
        padding-left: 9px !important;
        padding-right: 9px !important;
    }

    /* Apply padding to main content containers */
    main,
    article,
    .entry-content {
        padding-left: 9px !important;
        padding-right: 9px !important;
    }

    /* Ensure blocks have proper padding */
    .wp-block-group,
    .wp-block-columns,
    .wp-block-column {
        padding-left: 9px !important;
        padding-right: 9px !important;
    }

    /* Remove padding from Forminator form containers to prevent negative margin appearance */
    .wp-block-group:has(.forminator-ui),
    .wp-block-column:has(.forminator-ui),
    div:has(> .forminator-ui),
    div:has(> [id*="forminator"]) {
        padding-left: 0 !important;
        padding-right: 0 !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
    }

    /* Ensure Forminator forms don't overflow viewport */
    .forminator-ui,
    [id*="forminator-module"] {
        max-width: 100vw !important;
        overflow-x: hidden !important;
        box-sizing: border-box !important;
    }

    /* Remove padding from HostMap contact form containers to prevent overflow */
    .wp-block-group:has(.hostmap-contact-form),
    .wp-block-group:has(.hostmap-contact-form-wrapper),
    .wp-block-column:has(.hostmap-contact-form),
    .wp-block-column:has(.hostmap-contact-form-wrapper),
    div:has(> .hostmap-contact-form),
    div:has(> .hostmap-contact-form-wrapper) {
        padding-left: 0 !important;
        padding-right: 0 !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
    }

    /* Ensure HostMap contact forms don't overflow viewport */
    .hostmap-contact-form,
    .hostmap-contact-form-wrapper {
        max-width: 100vw !important;
        overflow-x: hidden !important;
        box-sizing: border-box !important;
    }

    /* Fix CTA content box on mobile - white box inset in purple background */
    .wp-block-group.cta-content {
        padding: 1rem !important;
        margin-left: 1rem !important;
        margin-right: 1rem !important;
        border-radius: 12px !important;
        width: auto !important;
        max-width: calc(100% - 2rem) !important;
        box-sizing: border-box !important;
    }

    /* Make purple section full-width edge-to-edge on mobile */
    .section-gradient-cta.alignfull {
        width: 100vw !important;
        position: relative !important;
        left: 50% !important;
        right: 50% !important;
        margin-left: -50vw !important;
        margin-right: -50vw !important;
        padding-left: 1rem !important;
        padding-right: 1rem !important;
        box-sizing: border-box !important;
    }

    /* Make columns in contact section stack properly on mobile */
    .section-gradient-cta .wp-block-columns {
        padding-left: 0 !important;
        padding-right: 0 !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
    }

    .section-gradient-cta .wp-block-column {
        padding-left: 0 !important;
        padding-right: 0 !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
        width: 100% !important;
        flex-basis: 100% !important;
    }

    /* Explicitly ensure footer and header have no extra padding */
    .hm-footer,
    .hm-header,
    .wp-block-hostmap-footer,
    .wp-block-hostmap-header,
    [data-type="hostmap/footer"],
    [data-type="hostmap/header"] {
        padding-left: 0 !important;
        padding-right: 0 !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
    }

    /* Footer and header containers should be full width */
    .wp-block-hostmap-footer,
    .wp-block-hostmap-header {
        width: 100vw !important;
        position: relative !important;
        left: 50% !important;
        right: 50% !important;
        margin-left: -50vw !important;
        margin-right: -50vw !important;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    *:focus {
        outline-width: 4px !important;
    }

    a {
        text-decoration: underline;
    }

    button,
    .wp-block-button__link {
        border: 2px solid currentColor;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* Print styles */
@media print {
    .hm-header__toggle,
    .skip-link,
    .no-print {
        display: none !important;
    }

    a[href]::after {
        content: " (" attr(href) ")";
        font-size: 0.8em;
        color: #666;
    }
}
