/**
 * TaskSalonApp - iOS Native App Experience Styling (Cupertino Theme)
 * Enhances PWA on mobile and iOS Safari with native feel, frosted glass,
 * notch / safe area insets, and smooth haptic tap feedback.
 */

:root {
    --ios-system-blue: #007aff;
    --ios-system-indigo: #4f46e5;
    --ios-system-green: #34c759;
    --ios-system-orange: #ff9500;
    --ios-system-red: #ff3b30;
    --ios-system-gray: #8e8e93;
    --ios-bg-grouped: #f2f2f7;
    --ios-card-bg: #ffffff;
    --ios-hairline: rgba(60, 60, 67, 0.18);
    --ios-blur-bg: rgba(255, 255, 255, 0.82);
    --ios-tab-bg: rgba(255, 255, 255, 0.88);
}

/* 1. Global iOS Typography, Touch Controls & Zero Horizontal Overflow */
*, *::before, *::after {
    box-sizing: border-box;
}

html {
    max-width: 100%;
    width: 100%;
    overflow-x: hidden !important;
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body {
    max-width: 100%;
    width: 100%;
    overflow-x: hidden !important;
    position: relative;
    margin: 0;
    padding-left: 0 !important;
    padding-right: 0 !important;
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Helvetica Neue", Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}

/* Prevent container and row horizontal overflow: Desktop vs Mobile */
@media (min-width: 992px) {
    .app-main {
        margin-left: var(--sidebar-width) !important;
        width: calc(100% - var(--sidebar-width)) !important;
        max-width: calc(100% - var(--sidebar-width)) !important;
        min-height: 100vh;
        overflow-x: hidden !important;
        box-sizing: border-box !important;
        min-width: 0;
    }

    .container-fluid {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
    }
}

@media (max-width: 991.98px) {
    .app-main {
        margin-left: 0 !important;
        width: 100% !important;
        max-width: 100vw !important;
        overflow-x: hidden !important;
        box-sizing: border-box !important;
        min-width: 0;
    }

    .container-fluid {
        width: 100% !important;
        max-width: 100% !important;
        overflow-x: hidden !important;
        padding-left: 12px !important;
        padding-right: 12px !important;
        box-sizing: border-box !important;
    }

    .row {
        margin-left: -6px !important;
        margin-right: -6px !important;
        max-width: calc(100% + 12px);
    }

    .row > * {
        padding-left: 6px !important;
        padding-right: 6px !important;
        max-width: 100%;
    }
}

/* Allow text selection in readable text blocks, inputs and tables */
p, span, td, th, input, textarea, select, .user-select-text {
    user-select: text;
    -webkit-user-select: text;
}

/* 2. Top Header - Cupertino Translucent Frosted Glass */
.app-main > header.sticky-top,
header.ios-navbar {
    background: var(--ios-blur-bg) !important;
    backdrop-filter: saturate(180%) blur(20px) !important;
    -webkit-backdrop-filter: saturate(180%) blur(20px) !important;
    border-bottom: 0.5px solid var(--ios-hairline) !important;
    padding-top: calc(0.55rem + env(safe-area-inset-top, 0px)) !important;
    transition: background-color 0.2s ease;
}

/* 3. Mobile Bottom Navigation - Cupertino Tab Bar */
@media (max-width: 991.98px) {
    .mobile-bottom-nav {
        background: var(--ios-tab-bg) !important;
        backdrop-filter: saturate(180%) blur(20px) !important;
        -webkit-backdrop-filter: saturate(180%) blur(20px) !important;
        border-top: 0.5px solid var(--ios-hairline) !important;
        height: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom, 0px)) !important;
        padding-bottom: env(safe-area-inset-bottom, 0px) !important;
        box-shadow: none !important;
    }

    body {
        padding-bottom: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom, 16px) + 12px) !important;
    }

    .mobile-nav-link {
        color: var(--ios-system-gray);
        font-weight: 500;
        letter-spacing: -0.01em;
        font-size: 0.72rem;
        transition: transform 0.12s cubic-bezier(0.2, 0.8, 0.2, 1), color 0.15s ease;
        -webkit-touch-callout: none;
    }

    .mobile-nav-link:active {
        transform: scale(0.92);
    }

    .mobile-nav-link i {
        font-size: 1.4rem;
        transition: transform 0.15s ease;
    }

    .mobile-nav-link.active {
        color: var(--primary) !important;
        font-weight: 600;
    }

    .mobile-nav-link.active i {
        transform: scale(1.06);
    }
}

/* 4. iOS Tactile Micro-Interactions (Active Tap Feedback) */
.btn, .choice-btn, .card-hover, .badge, .dropdown-item {
    -webkit-touch-callout: none;
    transition: transform 0.12s cubic-bezier(0.2, 0.8, 0.2, 1), background-color 0.15s ease, opacity 0.15s ease;
}

.btn:active, .card-hover:active {
    transform: scale(0.97);
}

.choice-btn:active {
    transform: scale(0.95);
}

/* 5. Cupertino Rounded Cards & Hairline Borders */
.card {
    border-radius: 16px !important;
    border: 0.5px solid rgba(0, 0, 0, 0.08) !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.03), 0 8px 24px rgba(0, 0, 0, 0.04) !important;
}

.checklist-item-card {
    border-radius: 16px !important;
    border: 0.5px solid rgba(0, 0, 0, 0.08) !important;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.02) !important;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.checklist-item-card.answered {
    border-color: rgba(79, 70, 229, 0.3) !important;
    background-color: #fafbff !important;
}

/* 6. Form Inputs & Selects - Clean iOS Style */
.form-control, .form-select {
    border-radius: 12px;
    border: 1px solid #d1d5db;
    padding: 0.65rem 0.95rem;
    font-size: 0.95rem;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
    -webkit-appearance: none;
}

.form-control:focus, .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}

/* 7. Modal & Bottom Sheet (iOS Style) */
.modal-content {
    border-radius: 20px;
    border: 0.5px solid rgba(0, 0, 0, 0.1);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15);
    overflow: hidden;
}

.modal-header {
    border-bottom: 0.5px solid var(--ios-hairline);
    padding: 1.1rem 1.4rem;
}

.modal-footer {
    border-top: 0.5px solid var(--ios-hairline);
    padding: 1rem 1.4rem;
}

/* 8. iOS Add to Home Screen (A2HS) Prompt Banner */
.ios-install-banner {
    position: fixed;
    bottom: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom, 16px) + 12px);
    left: 50% !important;
    right: auto !important;
    transform: translateX(-50%) !important;
    width: calc(100% - 24px) !important;
    max-width: 420px !important;
    margin: 0 !important;
    box-sizing: border-box !important;
    background: rgba(255, 255, 255, 0.94);
    backdrop-filter: saturate(180%) blur(24px);
    -webkit-backdrop-filter: saturate(180%) blur(24px);
    border: 0.5px solid rgba(0, 0, 0, 0.12);
    border-radius: 20px;
    padding: 16px 18px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.12), 0 4px 10px rgba(0, 0, 0, 0.05);
    z-index: 1040;
    display: flex;
    flex-direction: column;
    gap: 12px;
    animation: iosSlideUp 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes iosSlideUp {
    from {
        opacity: 0;
        transform: translate(-50%, 24px) scale(0.96);
    }
    to {
        opacity: 1;
        transform: translate(-50%, 0) scale(1);
    }
}

.ios-install-banner .app-icon-thumb {
    width: 46px;
    height: 46px;
    border-radius: 11px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

.ios-step-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #eef2ff;
    color: var(--primary);
    font-weight: 700;
    font-size: 0.75rem;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    margin-right: 6px;
}

/* 9. Standalone Mode Customizations (when running from Home Screen) */
@media (display-mode: standalone) {
    /* Prevent webview pull refresh glitch while keeping internal momentum scroll */
    body {
        overscroll-behavior-y: none;
    }

    /* Extra safe space for iPhone Notch / Dynamic Island */
    .app-main > header.sticky-top {
        padding-top: calc(0.75rem + env(safe-area-inset-top, 0px)) !important;
    }
}

/* 10. iOS Status / Network Toast Notification */
.ios-toast {
    position: fixed;
    top: calc(12px + env(safe-area-inset-top, 0px));
    left: 50%;
    transform: translateX(-50%) translateY(-100px);
    background: rgba(15, 23, 42, 0.9);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    color: #ffffff;
    font-size: 0.85rem;
    font-weight: 600;
    padding: 8px 18px;
    border-radius: 30px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    z-index: 2000;
    display: flex;
    align-items: center;
    gap: 8px;
    opacity: 0;
    transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.3s ease;
    pointer-events: none;
}

.ios-toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

.ios-toast.offline {
    background: rgba(220, 38, 38, 0.95);
}

.ios-toast.online {
    background: rgba(16, 185, 129, 0.95);
}

/* 11. Custom Pull-to-Refresh Spinner Indicator */
.ios-ptr-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 48px;
    margin-top: -48px;
    transition: margin-top 0.2s ease;
    color: var(--ios-system-gray);
}

.ios-ptr-indicator.pulling {
    margin-top: 0;
}

/* 12. Offcanvas Mobile Menu iOS Safe Area & Dismissal Polish */
.offcanvas {
    z-index: 1060 !important;
}

.offcanvas-start {
    width: 295px !important;
    max-width: 85vw !important;
}

.offcanvas-backdrop {
    z-index: 1055 !important;
    cursor: pointer !important;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.offcanvas-header {
    padding-top: calc(0.9rem + env(safe-area-inset-top, 0px)) !important;
    padding-bottom: 0.8rem !important;
    padding-left: 1.2rem !important;
    padding-right: 1.2rem !important;
    background: #ffffff;
}

.offcanvas-body {
    padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px)) !important;
    -webkit-overflow-scrolling: touch;
}

#btnCloseMobileSidebar {
    min-height: 36px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}
