/* ===================================================
   APPLEGRADE UI/UX OPTIMIZATION v2.0
   Apple-grade improvements for accessibility,
   mobile experience, and performance
   =================================================== */

:root {
    /* WCAG AA Compliant Color Palette */
    --color-primary: #007a3d; /* 4.54:1 contrast */
    --color-primary-dark: #00632f; /* 5.9:1 contrast */
    --color-primary-light: #00a651;
    --color-text-muted: #555555; /* 7.43:1 contrast */
    --color-text-body: #333333;

    /* Apple HIG Standard Timings */
    --transition-instant: 100ms cubic-bezier(0.25, 0.46, 0.45, 0.94);
    --transition-fast: 200ms cubic-bezier(0.25, 0.46, 0.45, 0.94);
    --transition-base: 250ms cubic-bezier(0.25, 0.46, 0.45, 0.94);
    --transition-slow: 350ms cubic-bezier(0.25, 0.46, 0.45, 0.94);

    /* Elevation System */
    --elevation-1: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.06);
    --elevation-2: 0 3px 6px rgba(0,0,0,0.15), 0 2px 4px rgba(0,0,0,0.1);
    --elevation-3: 0 10px 20px rgba(0,0,0,0.15), 0 3px 6px rgba(0,0,0,0.1);

    /* Spacing System (8pt rhythm) */
    --space-1: 8px;
    --space-2: 16px;
    --space-3: 24px;
    --space-4: 32px;
    --space-5: 40px;
    --space-6: 48px;

    /* Border Radius */
    --radius-small: 8px;
    --radius-medium: 12px;
    --radius-large: 16px;

    /* Z-Index Hierarchy */
    --z-base: 0;
    --z-dropdown: 100;
    --z-sticky: 200;
    --z-modal-backdrop: 300;
    --z-modal: 400;
}

/* ===================================================
   TOUCH TARGET OPTIMIZATION (48px minimum)
   iOS: 44x44pt, Android: 48x48dp
   =================================================== */

button,
a.btn,
.btn-white,
.btn-outline-white,
input[type="submit"],
input[type="button"],
input[type="reset"],
.navbar-menu a,
.faq-question {
    min-height: 48px;
    min-width: 48px;
    padding: 12px 24px;
    position: relative;
    touch-action: manipulation;
}

button::before,
a.btn::before {
    content: '';
    position: absolute;
    top: -4px;
    right: -4px;
    bottom: -4px;
    left: -4px;
    z-index: -1;
}

@media (max-width: 768px) {
    .btn,
    .btn-primary,
    .btn-secondary {
        min-height: 52px;
        padding: 14px 24px;
        font-size: 17px;
    }

    .btn-large {
        min-height: 56px;
        padding: 16px 32px;
        font-size: 18px;
    }

    .hero-buttons {
        gap: 12px;
        flex-direction: column;
        width: 100%;
    }

    .hero-buttons .btn {
        width: 100%;
        max-width: 100%;
    }
}

/* ===================================================
   TYPOGRAPHY OPTIMIZATION (≥16pt baseline)
   =================================================== */

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto',
                 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans',
                 'Droid Sans', 'Helvetica Neue', sans-serif;
    line-height: 1.6;
    color: var(--color-text-body);
}

h1, h2, h3, h4, h5, h6 {
    font-weight: 600;
    line-height: 1.2;
    margin-bottom: 0.5em;
}

h1 { font-size: clamp(2rem, 5vw, 3rem); }
h2 { font-size: clamp(1.75rem, 4vw, 2.5rem); }
h3 { font-size: clamp(1.5rem, 3vw, 2rem); }

a {
    color: var(--color-primary);
    text-decoration: underline;
    text-underline-offset: 2px;
    text-decoration-thickness: 1px;
    transition: all var(--transition-fast);
}

a:hover,
a:focus-visible {
    color: var(--color-primary-dark);
    text-decoration-thickness: 2px;
}

/* ===================================================
   FOCUS STATES (WCAG 2.1 Focus Visible)
   =================================================== */

*:focus-visible {
    outline: 3px solid var(--color-primary);
    outline-offset: 2px;
    border-radius: var(--radius-small);
}

*:focus:not(:focus-visible) {
    outline: none;
}

button:focus-visible,
.btn:focus-visible {
    outline: 3px solid var(--color-primary);
    outline-offset: 3px;
    box-shadow: 0 0 0 3px rgba(0, 122, 61, 0.2);
}

.skip-to-main {
    position: absolute;
    left: -9999px;
    z-index: 999;
    padding: 12px 20px;
    background: var(--color-primary-dark);
    color: white;
    text-decoration: none;
    font-weight: 600;
    font-size: 16px;
}

.skip-to-main:focus {
    left: 50%;
    top: 10px;
    transform: translateX(-50%);
    z-index: 999;
}

/* ===================================================
   FORM OPTIMIZATION (17px minimum on iOS)
   =================================================== */

input[type="text"],
input[type="email"],
input[type="tel"],
input[type="date"],
input[type="url"],
input[type="search"],
input[type="password"],
input[type="number"],
textarea,
select {
    min-height: 52px;
    padding: 14px 16px;
    font-size: 17px;
    line-height: 1.5;
    border: 1px solid #d1d5db;
    border-radius: var(--radius-medium);
    background-color: #ffffff;
    -webkit-appearance: none;
    appearance: none;
    transition: all var(--transition-fast);
    font-family: inherit;
}

input:focus,
textarea:focus,
select:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(0, 122, 61, 0.1),
                0 0 0 1px var(--color-primary);
}

input:invalid:not(:placeholder-shown),
textarea:invalid:not(:placeholder-shown) {
    border-color: #dc3545;
    box-shadow: 0 0 0 3px rgba(220, 53, 69, 0.1);
}

input[type="checkbox"],
input[type="radio"] {
    min-width: 24px;
    min-height: 24px;
    margin-right: 12px;
    cursor: pointer;
    accent-color: var(--color-primary);
}

/* ===================================================
   BUTTON STATE IMPROVEMENTS
   =================================================== */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-weight: 600;
    text-decoration: none;
    border: none;
    cursor: pointer;
    transition: all var(--transition-fast);
    transform: translateZ(0);
    will-change: transform;
    border-radius: var(--radius-small);
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: var(--elevation-2);
}

.btn:active {
    transform: translateY(0) scale(0.96);
    transition-duration: 100ms;
}

.btn[disabled],
.btn.loading {
    opacity: 0.6;
    cursor: not-allowed;
    pointer-events: none;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ===================================================
   COLOR CONTRAST FIXES (WCAG AA: 4.5:1)
   =================================================== */

.text-muted,
.section-subtitle,
.footer p {
    color: var(--color-text-muted);
}

.bg-primary,
.btn-primary {
    background: var(--color-primary);
    color: white;
}

@media (prefers-contrast: high) {
    :root {
        --color-primary: #00632f;
        --color-text-muted: #000000;
    }

    .btn-primary {
        border: 2px solid currentColor;
    }

    input,
    textarea,
    select {
        border-width: 2px;
    }
}

/* ===================================================
   NAVIGATION FIX (proper z-index)
   =================================================== */

.navbar {
    z-index: var(--z-sticky);
}

.navbar-menu {
    z-index: calc(var(--z-sticky) + 10);
}

.mobile-menu-backdrop {
    z-index: calc(var(--z-sticky) - 10);
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
}

.tbm-floating-btn {
    display: none !important;
}

.navbar-toggle {
    min-width: 48px;
    min-height: 48px;
    padding: 12px;
}

/* ===================================================
   REDUCED MOTION SUPPORT (WCAG 2.1)
   =================================================== */

@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;
    }

    .btn:hover {
        transform: none;
    }
}

/* ===================================================
   MOBILE RESPONSIVE OPTIMIZATIONS
   =================================================== */

@media (max-width: 768px) {
    .hero-content > div[style] {
        margin-bottom: 1rem !important;
        padding: 12px 20px !important;
    }

    .grid-4 {
        grid-template-columns: repeat(2, 1fr);
        gap: var(--space-2);
    }

    .card,
    .service-card {
        padding: var(--space-3);
        margin-bottom: var(--space-2);
        border-radius: var(--radius-large);
    }

    .testimonial-modern {
        padding: var(--space-3);
    }

    .quote-container {
        margin: 0;
        border-radius: 0;
        min-height: 100vh;
    }

    .comparison-table table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .navbar-menu {
        flex-direction: column;
        gap: 0;
    }

    .navbar-menu li a {
        padding: var(--space-2);
        width: 100%;
    }
}

/* ===================================================
   ACCESSIBILITY ENHANCEMENTS
   =================================================== */

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

.modal-open {
    overflow: hidden;
}

/* ===================================================
   PERFORMANCE OPTIMIZATIONS
   =================================================== */

img {
    max-width: 100%;
    height: auto;
    display: block;
}

img[loading="lazy"] {
    background: linear-gradient(
        90deg,
        #f0f0f0 25%,
        #e0e0e0 50%,
        #f0f0f0 75%
    );
    background-size: 200% 100%;
    animation: shimmer 1.4s ease infinite;
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.btn,
.card,
.service-card {
    transform: translateZ(0);
    backface-visibility: hidden;
}

/* ===================================================
   PRINT OPTIMIZATION
   =================================================== */

@media print {
    .navbar,
    .footer,
    .btn,
    .cta-section {
        display: none !important;
    }

    body {
        font-size: 12pt;
        line-height: 1.5;
        color: black;
        background: white;
    }

    a[href]:after {
        content: " (" attr(href) ")";
    }
}
