/**
 * ============================================================
 * ApartaRD - Mobile Premium Experience v2.0
 * ============================================================
 * Estilo: App nativa tipo Stripe/Apple/Notion
 * Mobile-first con glassmorphism y microinteracciones
 */

/* ============================================================
   MOBILE BASE - Safe Areas y Touch
   ============================================================ */
@media (max-width: 768px) {
    :root {
        --safe-top: env(safe-area-inset-top, 0px);
        --safe-bottom: env(safe-area-inset-bottom, 0px);
        --header-height: 56px;
        --bottom-nav-height: 64px;
    }
    html {
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }
    body {
        padding-top: calc(var(--header-height) + var(--safe-top));
        padding-bottom: calc(var(--bottom-nav-height) + var(--safe-bottom) + 20px);
        -webkit-tap-highlight-color: transparent;
    }
    /* Prevent zoom on input focus */
    input, select, textarea { font-size: 16px !important; }
    /* Smooth touch feedback */
    a, button, .touchable {
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
    }
}

/* ============================================================
   MOBILE HEADER - Premium Glassmorphism
   ============================================================ */
@media (max-width: 768px) {
    .header {
        position: fixed;
        top: 0; left: 0; right: 0;
        height: calc(var(--header-height) + var(--safe-top));
        padding-top: var(--safe-top);
        background: rgba(255,255,255,0.92);
        backdrop-filter: blur(24px) saturate(180%);
        -webkit-backdrop-filter: blur(24px) saturate(180%);
        border-bottom: 1px solid rgba(0,0,0,0.06);
        z-index: var(--z-sticky);
        transition: box-shadow 0.3s ease;
    }
    .header.scrolled {
        box-shadow: 0 2px 20px rgba(0,0,0,0.10);
        background: rgba(255,255,255,0.97);
    }
    .nav {
        height: var(--header-height);
        padding: 0 var(--space-4);
    }
    .logo { font-size: var(--text-lg); }
    .logo-icon { font-size: 1.3em; }
    /* Hide desktop menu */
    .nav-menu {
        position: fixed;
        top: calc(var(--header-height) + var(--safe-top));
        left: 0; right: 0; bottom: 0;
        background: var(--surface);
        padding: var(--space-6);
        transform: translateX(-100%);
        transition: transform 0.35s var(--ease-out);
        z-index: var(--z-overlay);
        display: flex;
        flex-direction: column;
        gap: var(--space-2);
        overflow-y: auto;
    }
    .nav-menu.active { transform: translateX(0); }
    .nav-menu a {
        padding: var(--space-4);
        font-size: var(--text-base);
        border-radius: var(--radius-xl);
        font-weight: 500;
    }
    .nav-toggle { display: flex; }
}

/* ============================================================
   BOTTOM NAVIGATION - App Style
   ============================================================ */
@media (max-width: 768px) {
    .bottom-nav {
        position: fixed;
        bottom: 0; left: 0; right: 0;
        height: calc(var(--bottom-nav-height) + var(--safe-bottom));
        padding-bottom: var(--safe-bottom);
        background: rgba(255,255,255,0.95);
        backdrop-filter: blur(20px) saturate(180%);
        -webkit-backdrop-filter: blur(20px) saturate(180%);
        border-top: 1px solid rgba(0,0,0,0.06);
        display: flex;
        align-items: center;
        justify-content: space-around;
        z-index: var(--z-sticky);
        box-shadow: 0 -4px 20px rgba(0,0,0,0.04);
    }
    .bottom-nav-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        flex: 1;
        height: 100%;
        padding: var(--space-2) 0;
        text-decoration: none;
        color: var(--text-muted);
        transition: all 0.2s var(--ease-out);
        position: relative;
    }
    .bottom-nav-item.active { color: var(--primary); }
    .bottom-nav-item.active::before {
        content: '';
        position: absolute;
        top: 0; left: 50%;
        transform: translateX(-50%);
        width: 40px; height: 3px;
        background: var(--primary);
        border-radius: 0 0 3px 3px;
    }
    .bottom-nav-icon {
        font-size: 22px;
        margin-bottom: 4px;
        transition: transform 0.25s var(--ease-spring);
    }
    .bottom-nav-item.active .bottom-nav-icon {
        transform: scale(1.15) translateY(-2px);
    }
    .bottom-nav-label { font-size: 10px; font-weight: 600; letter-spacing: 0.3px; }
    .bottom-nav-item:active { transform: scale(0.92); }
}

/* ============================================================
   HERO - Mobile Optimized
   ============================================================ */
@media (max-width: 768px) {
    .hero {
        padding: var(--space-8) 0 var(--space-12);
        min-height: auto;
    }
    .hero::after { height: 30px; }
    .hero-content {
        text-align: center;
        margin-bottom: var(--space-6);
    }
    .hero h1 {
        font-size: var(--text-3xl);
        margin-bottom: var(--space-3);
        line-height: 1.2;
    }
    .hero p {
        font-size: var(--text-base);
        padding: 0 var(--space-2);
    }
    .search-box {
        margin: 0 var(--space-3);
        padding: var(--space-5);
        border-radius: var(--radius-2xl);
    }
    .search-box-grid { gap: var(--space-4); }
    .search-box .form-control {
        padding: var(--space-4);
        border-radius: var(--radius-lg);
    }
    .search-box .btn {
        padding: var(--space-4);
        border-radius: var(--radius-lg);
        margin-top: var(--space-2);
    }
}

/* ============================================================
   CARDS - Premium Mobile
   ============================================================ */
@media (max-width: 768px) {
    .apartments-grid {
        display: flex;
        flex-direction: column;
        gap: var(--space-4);
        padding: 0;
    }
    .apartment-card {
        border-radius: var(--radius-2xl);
        box-shadow: 0 2px 16px rgba(0,0,0,0.06);
    }
    .apartment-card:active {
        transform: scale(0.98);
        box-shadow: 0 1px 8px rgba(0,0,0,0.08);
    }
    .apartment-card-image {
        aspect-ratio: 16 / 10;
        border-radius: var(--radius-2xl) var(--radius-2xl) 0 0;
    }
    .apartment-card-content { padding: var(--space-4); }
    .apartment-card-price { font-size: var(--text-xl); }
    .apartment-card-title { font-size: var(--text-base); }
    .apartment-card-location { font-size: var(--text-xs); }
    .apartment-card-features { gap: var(--space-3); }
    .apartment-card-feature { font-size: var(--text-xs); }
}

/* ============================================================
   STATS - Horizontal Scroll
   ============================================================ */
@media (max-width: 768px) {
    .stats-grid {
        display: flex;
        gap: var(--space-3);
        overflow-x: auto;
        scroll-snap-type: x mandatory;
        padding: var(--space-2) var(--space-4);
        margin: 0 calc(var(--gutter) * -1);
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    .stats-grid::-webkit-scrollbar { display: none; }
    .stat-card {
        flex: 0 0 140px;
        scroll-snap-align: start;
        padding: var(--space-4);
        border-radius: var(--radius-xl);
    }
    .stat-card-value { font-size: var(--text-2xl); }
    .stat-card-label { font-size: var(--text-xs); }
}

/* ============================================================
   FORMS - Touch Optimized
   ============================================================ */
@media (max-width: 768px) {
    .form-group { margin-bottom: var(--space-4); }
    .form-label { font-size: var(--text-sm); margin-bottom: var(--space-2); }
    .form-control {
        padding: var(--space-4);
        border-radius: var(--radius-lg);
        border-width: 2px;
        min-height: 52px;
    }
    .form-control:focus { box-shadow: 0 0 0 4px var(--primary-glow); }
    select.form-control { background-position: right var(--space-4) center; }
}

/* ============================================================
   BUTTONS - Touch Friendly
   ============================================================ */
@media (max-width: 768px) {
    .btn {
        padding: var(--space-4) var(--space-6);
        min-height: 52px;
        border-radius: var(--radius-lg);
        font-size: var(--text-base);
    }
    .btn:active { transform: scale(0.97); }
    .btn-primary { box-shadow: 0 4px 16px rgba(0,84,136,0.3); }
    .btn-sm { padding: var(--space-3) var(--space-4); min-height: 44px; font-size: var(--text-sm); }
    .btn-lg { padding: var(--space-5) var(--space-8); min-height: 56px; }
}

/* ============================================================
   SECTIONS - Mobile Spacing
   ============================================================ */
@media (max-width: 768px) {
    .section { padding: var(--space-10) 0; }
    .section-title { font-size: var(--text-2xl); margin-bottom: var(--space-2); }
    .section-subtitle { font-size: var(--text-base); }
    .section-header { margin-bottom: var(--space-5); padding: 0 var(--space-4); }
    .container { padding-left: var(--space-4); padding-right: var(--space-4); }
}

/* ============================================================
   ALERTS - Mobile
   ============================================================ */
@media (max-width: 768px) {
    .alert {
        margin: var(--space-3) var(--space-4);
        padding: var(--space-4);
        border-radius: var(--radius-lg);
        font-size: var(--text-sm);
    }
}

/* ============================================================
   FOOTER - Mobile
   ============================================================ */
@media (max-width: 768px) {
    .footer {
        padding: var(--space-10) var(--space-4) var(--space-8);
        display: none; /* Hide on mobile - use bottom nav */
    }
    .footer-grid { gap: var(--space-6); }
    .footer-col h4 { font-size: var(--text-sm); }
    .footer-bottom { padding-top: var(--space-4); font-size: var(--text-xs); }
}

/* ============================================================
   USER DROPDOWN - Mobile Sheet
   ============================================================ */
@media (max-width: 768px) {
    .user-dropdown { display: none; }
    .dropdown-menu {
        position: fixed;
        top: auto; right: 0; bottom: 0; left: 0;
        min-width: 100%;
        margin: 0;
        padding: var(--space-4);
        padding-bottom: calc(var(--space-4) + var(--safe-bottom));
        border-radius: var(--radius-2xl) var(--radius-2xl) 0 0;
        max-height: 80vh;
    }
}

/* ============================================================
   MOBILE HEADER - Custom
   ============================================================ */
@media (max-width: 768px) {
    .mobile-header {
        position: fixed;
        top: 0; left: 0; right: 0;
        height: calc(var(--header-height) + var(--safe-top));
        padding-top: var(--safe-top);
        background: rgba(255,255,255,0.92);
        backdrop-filter: blur(24px) saturate(180%);
        -webkit-backdrop-filter: blur(24px) saturate(180%);
        border-bottom: 1px solid rgba(0,0,0,0.06);
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding-left: var(--space-4);
        padding-right: var(--space-4);
        z-index: var(--z-sticky);
        transition: box-shadow 0.3s ease;
    }
    .mobile-header.scrolled { box-shadow: 0 2px 16px rgba(0,0,0,0.08); }
    .mobile-logo {
        font-family: var(--font-display);
        font-size: var(--text-lg);
        font-weight: 700;
        color: var(--dark);
        text-decoration: none;
    }
    .mobile-logo span { color: var(--primary); }
    .mobile-header-btn {
        width: 40px; height: 40px;
        border-radius: var(--radius-full);
        display: flex;
        align-items: center;
        justify-content: center;
        background: transparent;
        border: none;
        font-size: 20px;
        color: var(--text-secondary);
        transition: all var(--transition-fast);
    }
    .mobile-header-btn:active {
        background: var(--background);
        transform: scale(0.92);
    }
}

/* ============================================================
   TYPOGRAPHY - Mobile Scale
   ============================================================ */
@media (max-width: 768px) {
    h1 { font-size: var(--text-3xl); }
    h2 { font-size: var(--text-2xl); }
    h3 { font-size: var(--text-xl); }
    h4 { font-size: var(--text-lg); }
    h5 { font-size: var(--text-base); }
    p { font-size: var(--text-base); line-height: 1.7; }
}

/* ============================================================
   HIDE/SHOW UTILITIES
   ============================================================ */
@media (max-width: 768px) {
    .desktop-only { display: none !important; }
}
@media (min-width: 769px) {
    .mobile-only { display: none !important; }
    .bottom-nav { display: none !important; }
    .mobile-header { display: none !important; }
}

/* ============================================================
   TOUCH FEEDBACK
   ============================================================ */
@media (max-width: 768px) {
    .touchable:active,
    .apartment-card:active,
    .stat-card:active,
    .card:active,
    .btn:active {
        transform: scale(0.98);
        opacity: 0.9;
    }
    .ripple {
        position: relative;
        overflow: hidden;
    }
    .ripple::after {
        content: '';
        position: absolute;
        inset: 0;
        background: radial-gradient(circle at center, rgba(0,0,0,0.08) 0%, transparent 70%);
        opacity: 0;
        transition: opacity 0.3s;
    }
    .ripple:active::after { opacity: 1; }
}

/* ============================================================
   SKELETON LOADING
   ============================================================ */
@media (max-width: 768px) {
    .skeleton {
        background: linear-gradient(90deg,
            var(--border-light) 25%,
            var(--background) 50%,
            var(--border-light) 75%
        );
        background-size: 200% 100%;
        animation: shimmer 1.5s infinite;
        border-radius: var(--radius-md);
    }
    @keyframes shimmer {
        0% { background-position: 200% 0; }
        100% { background-position: -200% 0; }
    }
}

/* ============================================================
   TOAST NOTIFICATIONS
   ============================================================ */
@media (max-width: 768px) {
    .toast-container {
        position: fixed;
        top: calc(var(--header-height) + var(--safe-top) + var(--space-3));
        left: var(--space-4); right: var(--space-4);
        z-index: var(--z-toast);
    }
    .toast {
        display: flex;
        align-items: center;
        gap: var(--space-3);
        padding: var(--space-4);
        background: var(--dark);
        color: white;
        border-radius: var(--radius-xl);
        box-shadow: var(--shadow-xl);
        animation: toastIn 0.4s var(--ease-spring);
        margin-bottom: var(--space-2);
    }
    @keyframes toastIn {
        from { opacity: 0; transform: translateY(-16px) scale(0.95); }
        to { opacity: 1; transform: translateY(0) scale(1); }
    }
    .toast-success { background: var(--success); }
    .toast-error { background: var(--error); }
    .toast-warning { background: var(--warning); }
}

/* ============================================================
   SAFE AREA HELPERS
   ============================================================ */
@supports (padding: env(safe-area-inset-bottom)) {
    @media (max-width: 768px) {
        .safe-area-bottom { padding-bottom: env(safe-area-inset-bottom); }
        .safe-area-top { padding-top: env(safe-area-inset-top); }
    }
}

/* ============================================================
   MOBILE SEARCH PAGE
   ============================================================ */
@media (max-width: 768px) {
    .search-filters {
        display: flex;
        gap: var(--space-3);
        overflow-x: auto;
        padding: var(--space-4) var(--space-4) 0;
        scrollbar-width: none;
        -webkit-overflow-scrolling: touch;
        scroll-snap-type: x mandatory;
    }
    .search-filters::-webkit-scrollbar { display: none; }
    .filter-chip {
        flex: 0 0 auto;
        display: inline-flex;
        align-items: center;
        gap: var(--space-2);
        padding: var(--space-2) var(--space-4);
        background: var(--surface);
        border: 2px solid var(--border);
        border-radius: var(--radius-full);
        font-size: var(--text-sm);
        font-weight: 500;
        color: var(--text);
        white-space: nowrap;
        cursor: pointer;
        transition: all var(--transition-fast);
        scroll-snap-align: start;
    }
    .filter-chip.active {
        background: var(--primary);
        border-color: var(--primary);
        color: white;
    }
    .filter-chip:active { transform: scale(0.95); }
}

/* ============================================================
   MICROINTERACTIONS - Mobile
   ============================================================ */
@media (max-width: 768px) {
    @media (prefers-reduced-motion: reduce) {
        *, *::before, *::after {
            animation-duration: 0.01ms !important;
            animation-iteration-count: 1 !important;
            transition-duration: 0.01ms !important;
        }
    }
    .page-enter {
        animation: slideUp 0.35s var(--ease-out);
    }
    @keyframes slideUp {
        from { opacity: 0; transform: translateY(16px); }
        to { opacity: 1; transform: translateY(0); }
    }
}