/**
 * Mobile Enhancements CSS
 * Additional mobile-specific styling and optimizations
 * The HARNESS Project - Fearless. Protected. Empowered.
 */

/* ===== Mobile-Specific Improvements ===== */

/* Improve touch targets */
@media (max-width: 768px) {
    button,
    a,
    .nav-item,
    .journey-card,
    .value-card {
        min-height: 44px;
        min-width: 44px;
        padding: 12px;
    }
    
    /* Larger tap targets for navigation */
    .bottom-nav .nav-item {
        padding: 12px 8px;
        min-height: 60px;
    }
    
    /* Better spacing for cards */
    .journey-cards,
    .values-grid {
        gap: 16px;
    }
    
    /* Improved readability */
    body {
        font-size: 16px; /* Prevents iOS zoom on input focus */
        line-height: 1.5;
    }
    
    h1 {
        font-size: 28px;
    }
    
    h2 {
        font-size: 22px;
    }
    
    h3 {
        font-size: 18px;
    }
}

/* ===== Smooth Scrolling ===== */
html {
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

/* ===== Prevent Text Selection on UI Elements ===== */
.nav-item,
.journey-card,
.value-card,
button,
.hamburger-menu {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* ===== Better Focus States for Accessibility ===== */
button:focus,
a:focus,
input:focus,
textarea:focus {
    outline: 2px solid var(--color-teal);
    outline-offset: 2px;
}

/* ===== Loading States ===== */
.loading {
    pointer-events: none;
    opacity: 0.6;
    position: relative;
}

.loading::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid transparent;
    border-top-color: var(--color-teal);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ===== Page Transition Animations ===== */
.screen {
    animation: fadeIn 0.3s ease-in-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ===== Swipe Indicators ===== */
.swipeable {
    position: relative;
    touch-action: pan-y;
}

.swipeable::before,
.swipeable::after {
    content: "";
    position: absolute;
    top: 50%;
    width: 40px;
    height: 40px;
    margin-top: -20px;
    background: rgba(255, 255, 255, 0.8);
    border-radius: 50%;
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
    z-index: 10;
}

.swipeable::before {
    left: 10px;
    background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%2300BDBD"><path d="M15.41 7.41L14 6l-6 6 6 6 1.41-1.41L10.83 12z"/></svg>');
    background-size: 24px;
    background-position: center;
    background-repeat: no-repeat;
}

.swipeable::after {
    right: 10px;
    background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%2300BDBD"><path d="M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"/></svg>');
    background-size: 24px;
    background-position: center;
    background-repeat: no-repeat;
}

.swipeable:hover::before,
.swipeable:hover::after {
    opacity: 0.3;
}

/* ===== Pull to Refresh Styling ===== */
.pull-to-refresh-active {
    transition: transform 0.2s ease-out;
}

/* ===== Offline Indicator ===== */
.offline-indicator {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: #F6CC00;
    color: #2C3E50;
    padding: 8px 16px;
    text-align: center;
    font-size: 14px;
    font-weight: 600;
    z-index: 10003;
    transform: translateY(-100%);
    transition: transform 0.3s ease;
}

.offline-indicator.visible {
    transform: translateY(0);
}

.offline-indicator::before {
    content: "⚠️";
    margin-right: 8px;
}

/* ===== Card Animations ===== */
.card {
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.card:active {
    transform: scale(0.98);
}

/* ===== Input Enhancements ===== */
input,
textarea,
select {
    font-size: 16px; /* Prevents iOS zoom */
    -webkit-appearance: none;
    appearance: none;
}

input[type="text"],
input[type="email"],
input[type="password"],
textarea {
    border-radius: var(--radius-md);
    border: 2px solid var(--color-border);
    padding: 12px 16px;
    transition: border-color 0.2s;
}

input:focus,
textarea:focus {
    border-color: var(--color-teal);
    outline: none;
}

/* ===== Improved Bottom Navigation ===== */
@media (max-width: 768px) {
    .bottom-nav {
        padding-bottom: env(safe-area-inset-bottom);
    }
    
    /* Add blur effect to bottom nav */
    .bottom-nav {
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        background: rgba(255, 255, 255, 0.9);
    }
    
    /* Active state improvements */
    .nav-item.active {
        background: rgba(0, 189, 189, 0.1);
    }
    
    .nav-item:active {
        background: rgba(0, 189, 189, 0.15);
    }
}

/* ===== Safe Area Padding ===== */
@supports (padding: env(safe-area-inset-top)) {
    .app-header {
        padding-top: env(safe-area-inset-top);
    }
    
    .bottom-nav {
        padding-bottom: calc(env(safe-area-inset-bottom) + 8px);
    }
}

/* ===== Haptic Feedback Visual Indication ===== */
.haptic-feedback {
    animation: hapticPulse 0.3s ease;
}

@keyframes hapticPulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(0.95);
    }
}

/* ===== Improved Scrollbars for Mobile ===== */
::-webkit-scrollbar {
    width: 4px;
    height: 4px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(0, 189, 189, 0.3);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 189, 189, 0.5);
}

/* ===== Status Bar Theming ===== */
@media (prefers-color-scheme: dark) {
    :root {
        --color-bg: #1A1D23;
        --color-surface: #25282E;
        --color-text: #E8ECEF;
        --color-text-secondary: #A0A6B0;
        --color-border: #353841;
    }
    
    body {
        background: linear-gradient(180deg, #1A1D23 0%, #25282E 40%, #2F3339 100%);
    }
}

/* ===== Touch Ripple Effect ===== */
.ripple {
    position: relative;
    overflow: hidden;
}

.ripple::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.5);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

.ripple:active::after {
    width: 300px;
    height: 300px;
}

/* ===== Image Optimization ===== */
img {
    max-width: 100%;
    height: auto;
    display: block;
}

img[loading="lazy"] {
    opacity: 0;
    transition: opacity 0.3s;
}

img[loading="lazy"].loaded {
    opacity: 1;
}

/* ===== 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;
    }
}

/* ===== Better Modal Backdrop ===== */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 9998;
    animation: fadeIn 0.3s ease;
}

/* ===== Floating Elements Shadow ===== */
.floating {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1),
                0 8px 24px rgba(0, 0, 0, 0.08);
}

/* ===== Content Placeholder Animation ===== */
.placeholder {
    background: linear-gradient(
        90deg,
        #f0f0f0 25%,
        #e0e0e0 50%,
        #f0f0f0 75%
    );
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
    0% {
        background-position: -200% 0;
    }
    100% {
        background-position: 200% 0;
    }
}

/* ===== Network Status Badge ===== */
.network-status {
    position: fixed;
    top: 10px;
    right: 10px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #00A8A8;
    z-index: 10004;
    transition: background 0.3s;
}

.network-status.offline {
    background: #7F8C8D;
}

/* ===== App Install Prompt Styling ===== */
.install-prompt {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: white;
    padding: 16px 24px;
    border-radius: 16px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.15);
    z-index: 10000;
    animation: slideUp 0.4s ease;
    max-width: 90%;
}

@keyframes slideUp {
    from {
        bottom: -100px;
        opacity: 0;
    }
    to {
        bottom: 80px;
        opacity: 1;
    }
}

/* ===== Improved Form Validation ===== */
input:invalid {
    border-color: var(--color-magenta);
}

input:valid {
    border-color: var(--color-teal);
}

.error-message {
    color: var(--color-magenta);
    font-size: 14px;
    margin-top: 4px;
}

/* ===== Landscape Mode Adjustments ===== */
@media (orientation: landscape) and (max-height: 500px) {
    .splash-screen {
        padding: 20px;
    }
    
    .splash-content {
        max-width: 80%;
    }
    
    .bottom-nav {
        flex-direction: row;
        height: 50px;
    }
    
    .nav-label {
        display: none;
    }
}

/* ===== Print Styles ===== */
@media print {
    .bottom-nav,
    .app-header,
    .mobile-fab,
    .pwa-install-banner {
        display: none !important;
    }
    
    body {
        background: white;
    }
}
