/**
 * S&S Wolf Sheds - Shared Mobile CSS Utilities
 * Mobile-First Responsive Design
 * Touch-friendly with 44px minimum tap targets
 *
 * Usage: Include this file in all S&S Wolf Sheds interfaces for consistent mobile optimization
 */

/* ===========================
   CSS CUSTOM PROPERTIES
   =========================== */

:root {
    /* Breakpoints */
    --breakpoint-phone: 480px;
    --breakpoint-tablet: 768px;
    --breakpoint-desktop: 1024px;

    /* Touch Targets */
    --touch-target-min: 44px;
    --touch-target-comfortable: 48px;
    --touch-target-large: 56px;

    /* Spacing Scale (Mobile-First) */
    --spacing-xs: 4px;
    --spacing-sm: 8px;
    --spacing-md: 12px;
    --spacing-lg: 16px;
    --spacing-xl: 24px;
    --spacing-xxl: 32px;

    /* Typography Scale (Mobile-Optimized) */
    --font-size-xs: 12px;
    --font-size-sm: 14px;
    --font-size-base: 16px; /* Prevents iOS zoom */
    --font-size-lg: 18px;
    --font-size-xl: 20px;
    --font-size-xxl: 24px;
    --font-size-display: 28px;

    /* Line Heights */
    --line-height-tight: 1.25;
    --line-height-normal: 1.5;
    --line-height-relaxed: 1.75;

    /* Border Radius */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --radius-round: 50%;

    /* Shadows */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 20px rgba(0, 0, 0, 0.15);
    --shadow-xl: 0 20px 40px rgba(0, 0, 0, 0.2);

    /* Z-Index Scale */
    --z-base: 1;
    --z-dropdown: 100;
    --z-sticky: 200;
    --z-fixed: 300;
    --z-modal-backdrop: 400;
    --z-modal: 500;
    --z-popover: 600;
    --z-tooltip: 700;
}

/* ===========================
   BASE RESET & MOBILE-FIRST DEFAULTS
   =========================== */

* {
    -webkit-tap-highlight-color: transparent; /* Remove iOS tap highlight */
    -webkit-touch-callout: none; /* Disable iOS callout */
}

html {
    font-size: 16px; /* Base font size prevents iOS zoom */
    -webkit-text-size-adjust: 100%; /* Prevent font scaling */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: var(--font-size-base);
    line-height: var(--line-height-normal);
}

/* ===========================
   TOUCH-FRIENDLY BUTTON UTILITIES
   =========================== */

.btn-touch,
.touch-target {
    min-height: var(--touch-target-min);
    min-width: var(--touch-target-min);
    padding: 12px 20px;
    font-size: var(--font-size-base);
    cursor: pointer;
    user-select: none;
}

.btn-touch-comfortable {
    min-height: var(--touch-target-comfortable);
    min-width: var(--touch-target-comfortable);
    padding: 14px 24px;
}

.btn-touch-large {
    min-height: var(--touch-target-large);
    min-width: var(--touch-target-large);
    padding: 16px 28px;
    font-size: var(--font-size-lg);
}

/* Button states for touch feedback */
.btn-touch:active,
.touch-target:active {
    transform: translateY(1px);
    opacity: 0.9;
}

/* ===========================
   MOBILE-OPTIMIZED FORMS
   =========================== */

.form-input-mobile {
    width: 100%;
    padding: 14px 16px;
    font-size: var(--font-size-base); /* Prevents iOS zoom */
    border: 2px solid #e0e0e0;
    border-radius: var(--radius-md);
    transition: border-color 0.2s;
}

.form-input-mobile:focus {
    border-color: #007bff;
    outline: none;
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.1);
}

.form-textarea-mobile {
    width: 100%;
    padding: 14px 16px;
    font-size: var(--font-size-base);
    border: 2px solid #e0e0e0;
    border-radius: var(--radius-md);
    resize: vertical;
    min-height: 100px;
}

.form-select-mobile {
    width: 100%;
    padding: 14px 16px;
    font-size: var(--font-size-base);
    border: 2px solid #e0e0e0;
    border-radius: var(--radius-md);
    background-color: white;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M0 0l6 8 6-8z' fill='%23666'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 16px center;
    padding-right: 40px;
}

/* Input type optimizations */
input[type="tel"],
input[type="number"],
input[data-numeric] {
    inputmode: numeric;
    pattern: "[0-9]*";
}

input[type="email"] {
    inputmode: email;
    autocapitalize: none;
    autocorrect: off;
}

input[type="url"] {
    inputmode: url;
    autocapitalize: none;
}

/* Smart capitalization */
input[name*="name"],
input[name*="Name"],
input[data-capitalize="words"] {
    autocapitalize: words;
}

/* ===========================
   RESPONSIVE LAYOUT UTILITIES
   =========================== */

/* Container sizes */
.container-mobile {
    width: 100%;
    max-width: 600px;
    margin: 0 auto;
    padding: 0 var(--spacing-md);
}

.container-full {
    width: 100%;
    padding: 0 var(--spacing-md);
}

/* Stack items vertically on mobile */
.stack-mobile {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
}

.stack-mobile-sm {
    gap: var(--spacing-sm);
}

.stack-mobile-lg {
    gap: var(--spacing-lg);
}

/* Horizontal layouts that stack on mobile */
.flex-mobile {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
}

@media (min-width: 768px) {
    .flex-mobile {
        flex-direction: row;
    }
}

/* Grid utilities */
.grid-mobile {
    display: grid;
    gap: var(--spacing-md);
    grid-template-columns: 1fr;
}

@media (min-width: 768px) {
    .grid-mobile-2col {
        grid-template-columns: repeat(2, 1fr);
    }

    .grid-mobile-3col {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* ===========================
   CARD COMPONENTS
   =========================== */

.card-mobile {
    background: white;
    border-radius: var(--radius-lg);
    padding: var(--spacing-lg);
    box-shadow: var(--shadow-md);
    margin-bottom: var(--spacing-md);
}

.card-mobile-compact {
    padding: var(--spacing-md);
}

.card-mobile-spacious {
    padding: var(--spacing-xl);
}

/* ===========================
   RESPONSIVE TABLE UTILITIES
   =========================== */

.table-mobile-cards {
    display: block;
}

@media (max-width: 768px) {
    .table-mobile-cards thead {
        display: none;
    }

    .table-mobile-cards tr {
        display: block;
        margin-bottom: var(--spacing-md);
        border: 1px solid #e0e0e0;
        border-radius: var(--radius-md);
        padding: var(--spacing-md);
        background: white;
        box-shadow: var(--shadow-sm);
    }

    .table-mobile-cards td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: var(--spacing-sm) 0;
        border: none;
        min-height: 44px; /* Touch-friendly row height */
    }

    .table-mobile-cards td:before {
        content: attr(data-label);
        font-weight: 600;
        margin-right: var(--spacing-md);
        color: #666;
        flex-shrink: 0;
    }

    .table-mobile-cards td:last-child {
        border-bottom: none;
    }
}

/* ===========================
   MOBILE NAVIGATION PATTERNS
   =========================== */

.mobile-nav-bottom {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(60px, 1fr));
    background: white;
    border-top: 1px solid #e0e0e0;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
    z-index: var(--z-fixed);
    padding-bottom: env(safe-area-inset-bottom); /* iOS safe area */
}

.mobile-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--spacing-sm);
    min-height: var(--touch-target-large);
    color: #666;
    text-decoration: none;
    font-size: var(--font-size-xs);
    transition: all 0.2s;
}

.mobile-nav-item.active {
    color: #007bff;
    background: rgba(0, 123, 255, 0.05);
}

.mobile-nav-item:active {
    background: rgba(0, 0, 0, 0.05);
}

/* Hide on desktop */
@media (min-width: 1024px) {
    .mobile-nav-bottom {
        display: none;
    }
}

/* ===========================
   SPACING UTILITIES
   =========================== */

/* Margin utilities */
.m-mobile-0 { margin: 0; }
.m-mobile-xs { margin: var(--spacing-xs); }
.m-mobile-sm { margin: var(--spacing-sm); }
.m-mobile-md { margin: var(--spacing-md); }
.m-mobile-lg { margin: var(--spacing-lg); }
.m-mobile-xl { margin: var(--spacing-xl); }

.mt-mobile-0 { margin-top: 0; }
.mt-mobile-xs { margin-top: var(--spacing-xs); }
.mt-mobile-sm { margin-top: var(--spacing-sm); }
.mt-mobile-md { margin-top: var(--spacing-md); }
.mt-mobile-lg { margin-top: var(--spacing-lg); }
.mt-mobile-xl { margin-top: var(--spacing-xl); }

.mb-mobile-0 { margin-bottom: 0; }
.mb-mobile-xs { margin-bottom: var(--spacing-xs); }
.mb-mobile-sm { margin-bottom: var(--spacing-sm); }
.mb-mobile-md { margin-bottom: var(--spacing-md); }
.mb-mobile-lg { margin-bottom: var(--spacing-lg); }
.mb-mobile-xl { margin-bottom: var(--spacing-xl); }

/* Padding utilities */
.p-mobile-0 { padding: 0; }
.p-mobile-xs { padding: var(--spacing-xs); }
.p-mobile-sm { padding: var(--spacing-sm); }
.p-mobile-md { padding: var(--spacing-md); }
.p-mobile-lg { padding: var(--spacing-lg); }
.p-mobile-xl { padding: var(--spacing-xl); }

/* ===========================
   TYPOGRAPHY UTILITIES
   =========================== */

.text-mobile-xs { font-size: var(--font-size-xs); }
.text-mobile-sm { font-size: var(--font-size-sm); }
.text-mobile-base { font-size: var(--font-size-base); }
.text-mobile-lg { font-size: var(--font-size-lg); }
.text-mobile-xl { font-size: var(--font-size-xl); }
.text-mobile-xxl { font-size: var(--font-size-xxl); }
.text-mobile-display { font-size: var(--font-size-display); }

/* Text alignment */
.text-center-mobile { text-align: center; }
.text-left-mobile { text-align: left; }
.text-right-mobile { text-align: right; }

/* Line height */
.leading-tight { line-height: var(--line-height-tight); }
.leading-normal { line-height: var(--line-height-normal); }
.leading-relaxed { line-height: var(--line-height-relaxed); }

/* ===========================
   VISIBILITY UTILITIES
   =========================== */

/* Show only on mobile */
.show-mobile {
    display: block;
}

@media (min-width: 768px) {
    .show-mobile {
        display: none;
    }
}

/* Hide on mobile */
.hide-mobile {
    display: none;
}

@media (min-width: 768px) {
    .hide-mobile {
        display: block;
    }
}

/* Show only on tablet */
.show-tablet {
    display: none;
}

@media (min-width: 768px) and (max-width: 1023px) {
    .show-tablet {
        display: block;
    }
}

/* Show only on desktop */
.show-desktop {
    display: none;
}

@media (min-width: 1024px) {
    .show-desktop {
        display: block;
    }
}

/* ===========================
   POSITION UTILITIES
   =========================== */

.sticky-top-mobile {
    position: sticky;
    top: 0;
    z-index: var(--z-sticky);
    background: white;
    box-shadow: var(--shadow-sm);
}

.fixed-bottom-mobile {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: var(--z-fixed);
}

/* ===========================
   ACCESSIBILITY UTILITIES
   =========================== */

/* High contrast mode for outdoor/sunlight use */
@media (prefers-contrast: high) {
    .btn-touch,
    .touch-target {
        border: 3px solid currentColor;
        font-weight: 600;
    }

    .card-mobile {
        border: 2px solid #333;
    }
}

/* Reduced motion for users with vestibular disorders */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    :root {
        color-scheme: dark;
    }

    .card-mobile {
        background: #1a1a1a;
        color: #f0f0f0;
        border-color: #333;
    }

    .form-input-mobile,
    .form-textarea-mobile,
    .form-select-mobile {
        background: #2a2a2a;
        color: #f0f0f0;
        border-color: #444;
    }
}

/* ===========================
   SAFE AREA SUPPORT (iOS Notch/Home Indicator)
   =========================== */

.safe-area-top {
    padding-top: env(safe-area-inset-top);
}

.safe-area-bottom {
    padding-bottom: env(safe-area-inset-bottom);
}

.safe-area-left {
    padding-left: env(safe-area-inset-left);
}

.safe-area-right {
    padding-right: env(safe-area-inset-right);
}

/* ===========================
   MEDIA QUERIES BREAKPOINTS
   =========================== */

/* Phone only */
@media (max-width: 479px) {
    .phone-only {
        display: block;
    }
}

/* Tablet and up */
@media (min-width: 768px) {
    .tablet-up {
        display: block;
    }
}

/* Desktop and up */
@media (min-width: 1024px) {
    .desktop-up {
        display: block;
    }
}

/* Landscape orientation */
@media (orientation: landscape) and (max-height: 500px) {
    /* Compact mode for landscape phones */
    .compact-landscape {
        padding: var(--spacing-sm);
        font-size: var(--font-size-sm);
    }
}

/* ===========================
   PERFORMANCE OPTIMIZATIONS
   =========================== */

/* GPU acceleration for smooth animations */
.will-animate {
    will-change: transform, opacity;
}

/* Lazy loading images */
img.lazy {
    opacity: 0;
    transition: opacity 0.3s;
}

img.lazy.loaded {
    opacity: 1;
}

/* ===========================
   FLOATING ACTION BUTTON (FAB)
   =========================== */

.fab-mobile {
    position: fixed;
    bottom: calc(80px + env(safe-area-inset-bottom));
    right: var(--spacing-lg);
    width: var(--touch-target-large);
    height: var(--touch-target-large);
    border-radius: var(--radius-round);
    background: #007bff;
    color: white;
    border: none;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    z-index: var(--z-fixed);
    transition: all 0.3s;
}

.fab-mobile:active {
    transform: scale(0.95);
}

/* ===========================
   PULL-TO-REFRESH INDICATOR
   =========================== */

.pull-refresh-indicator {
    position: absolute;
    top: -60px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s;
}

.pull-refresh-indicator.ready {
    transform: translateX(-50%) rotate(180deg);
}

/* ===========================
   SWIPE GESTURE INDICATORS
   =========================== */

.swipe-hint {
    position: relative;
    overflow: hidden;
}

.swipe-hint::after {
    content: '';
    position: absolute;
    top: 50%;
    right: 0;
    width: 40px;
    height: 100%;
    background: linear-gradient(to left, rgba(0, 0, 0, 0.05), transparent);
    transform: translateY(-50%);
    pointer-events: none;
}
