/**
 * İslam Arşivi - Genel Mobil Optimizasyonlar
 * Modern, performanslı, 2026 standartları
 */

/* ==================== BASE MOBILE OPTIMIZATIONS ==================== */
@media (max-width: 1024px) {
    /* Genel spacing ayarları */
    .container, .section {
        padding-left: 1.5rem;
        padding-right: 1.5rem;
    }
    
    /* Typography */
    h1 { font-size: 2rem; line-height: 1.2; }
    h2 { font-size: 1.75rem; line-height: 1.3; }
    h3 { font-size: 1.5rem; line-height: 1.3; }
    h4 { font-size: 1.25rem; line-height: 1.4; }
    
    /* Grid sistemler */
    .grid-3, .grid-4 { grid-template-columns: repeat(2, 1fr); }
    .grid-5, .grid-6 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
    /* Spacing */
    .container, .section {
        padding-left: 1rem;
        padding-right: 1rem;
    }
    
    section, .section {
        padding-top: 2.5rem;
        padding-bottom: 2.5rem;
    }
    
    /* Typography */
    h1 { font-size: 1.75rem; }
    h2 { font-size: 1.5rem; }
    h3 { font-size: 1.25rem; }
    p { font-size: 0.9375rem; line-height: 1.6; }
    
    /* Grid sistemler */
    .grid-2, .grid-3, .grid-4, .grid-5, .grid-6 {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    /* Flex wrap */
    .flex-row {
        flex-direction: column;
        gap: 1rem;
    }
    
    /* Buttons */
    .btn, button, a.button {
        min-height: 44px;
        padding: 0.75rem 1.5rem;
        font-size: 0.9375rem;
    }
    
    /* Cards */
    .card {
        padding: 1rem;
        border-radius: 12px;
    }
    
    /* Images */
    img {
        max-width: 100%;
        height: auto;
    }
}

@media (max-width: 480px) {
    /* Ultra compact */
    .container, .section {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }
    
    section, .section {
        padding-top: 2rem;
        padding-bottom: 2rem;
    }
    
    /* Typography */
    h1 { font-size: 1.5rem; }
    h2 { font-size: 1.25rem; }
    h3 { font-size: 1.125rem; }
    p { font-size: 0.875rem; }
    
    /* Buttons */
    .btn, button, a.button {
        width: 100%;
        justify-content: center;
    }
    
    /* Cards */
    .card {
        padding: 0.875rem;
        border-radius: 10px;
    }
}

/* ==================== LANDSCAPE MOBILE (düşük yükseklik) ==================== */
@media (max-height: 500px) and (orientation: landscape) {
    /* Compact spacing */
    section, .section {
        padding-top: 1.5rem !important;
        padding-bottom: 1.5rem !important;
    }
    
    h1 { font-size: 1.25rem !important; }
    h2 { font-size: 1.125rem !important; }
    
    .card { padding: 0.75rem !important; }
    
    /* Modal/popup'lar daha compact */
    .modal, .popup, .overlay {
        padding: 1rem;
        max-height: 85vh;
        overflow-y: auto;
    }
}

/* ==================== TOUCH-FRIENDLY INTERACTIONS ==================== */
@media (hover: none) and (pointer: coarse) {
    /* Tüm tıklanabilir elemanlar minimum 44x44px */
    button, a, .clickable, [role="button"], input[type="button"], input[type="submit"] {
        min-width: 44px;
        min-height: 44px;
        padding: 0.625rem 1rem;
    }
    
    /* Hover yerine active states */
    button:active, a:active, .clickable:active {
        transform: scale(0.97);
        opacity: 0.8;
    }
    
    /* Select, input gibi form elemanları */
    select, input, textarea {
        font-size: 16px; /* iOS zoom'u engelle */
        min-height: 44px;
    }
    
    /* Link spacing */
    a {
        padding: 0.25rem 0;
    }
}

/* ==================== SAFE AREA (iOS notch, Android gesture bar) ==================== */
@supports (padding: max(0px)) {
    body {
        padding-left: env(safe-area-inset-left);
        padding-right: env(safe-area-inset-right);
    }
    
    .header, .mv-hdr {
        padding-left: max(1rem, env(safe-area-inset-left));
        padding-right: max(1rem, env(safe-area-inset-right));
    }
    
    .footer {
        padding-bottom: max(1rem, env(safe-area-inset-bottom));
    }
    
    /* Fixed bottom elements */
    .bottom-nav, .fixed-bottom {
        padding-bottom: calc(0.75rem + env(safe-area-inset-bottom));
    }
}

/* ==================== SCROLLBAR (mobil) ==================== */
/* Sadece yatay swipeable container'larda scrollbar gizle.
   Sayfa ve genel listelerde affordance için ince scrollbar bırak. */
@media (max-width: 768px) {
    .swipeable::-webkit-scrollbar,
    .scroll-x::-webkit-scrollbar {
        width: 0;
        height: 0;
        display: none;
    }
    .swipeable,
    .scroll-x {
        scrollbar-width: none;
    }
    html {
        scrollbar-width: thin;
    }
}

/* ==================== PERFORMANCE OPTIMIZATIONS ==================== */
@media (max-width: 768px) {
    /* GPU acceleration */
    .animate, .transition, [class*="animate"], [class*="fade"], [class*="slide"] {
        will-change: transform, opacity;
        transform: translateZ(0);
        backface-visibility: hidden;
    }
    
    /* Animasyonları durdur (prefers-reduced-motion) */
    @media (prefers-reduced-motion: reduce) {
        *,
        *::before,
        *::after {
            animation-duration: 0.01ms !important;
            animation-iteration-count: 1 !important;
            transition-duration: 0.01ms !important;
        }
    }
    
    /* Yavaş cihazlarda ağır efektleri devre dışı bırak */
    @media (prefers-reduced-motion: reduce) {
        .blur, [class*="blur"] {
            backdrop-filter: none !important;
            -webkit-backdrop-filter: none !important;
        }
        
        .shadow, [class*="shadow"] {
            box-shadow: none !important;
        }
    }
}

/* ==================== MODAL/OVERLAY MOBİL ==================== */
@media (max-width: 768px) {
    .modal, .popup, .overlay-content {
        width: 95vw !important;
        max-width: 95vw;
        max-height: 85vh;
        overflow-y: auto;
        border-radius: 16px;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Full-screen modal seçeneği */
    .modal.full, .popup.full {
        width: 100vw !important;
        height: 100vh !important;
        max-width: 100vw;
        max-height: 100vh;
        border-radius: 0;
    }
    
    /* Modal kapatma butonu büyük */
    .modal-close, .popup-close {
        min-width: 44px;
        min-height: 44px;
        top: 0.5rem;
        right: 0.5rem;
    }
}

/* ==================== TABLE MOBİL (responsive) ==================== */
@media (max-width: 768px) {
    table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        white-space: nowrap;
    }
    
    /* Alternatif: Stack layout */
    table.stack {
        white-space: normal;
    }
    
    table.stack thead {
        display: none;
    }
    
    table.stack tr {
        display: block;
        margin-bottom: 1rem;
        border: 1px solid var(--border, #E0D5C8);
        border-radius: 8px;
        padding: 0.75rem;
    }

    table.stack td {
        display: flex;
        justify-content: space-between;
        padding: 0.5rem 0;
        border: none;
        border-bottom: 1px solid var(--border-l, #EDE6DC);
    }
    
    table.stack td:last-child {
        border-bottom: none;
    }
    
    table.stack td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--text-2, #6B5B4F);
    }
}

/* ==================== FORM MOBİL ==================== */
@media (max-width: 768px) {
    form {
        width: 100%;
    }
    
    .form-row {
        flex-direction: column;
    }
    
    input, select, textarea {
        width: 100%;
        font-size: 16px; /* iOS zoom engel */
    }
    
    label {
        font-size: 0.875rem;
        margin-bottom: 0.5rem;
    }
    
    /* Stacked buttons */
    .form-actions, .button-group {
        flex-direction: column;
        gap: 0.75rem;
    }
    
    .form-actions button,
    .button-group button {
        width: 100%;
    }
}

/* ==================== NAVİGATION MOBİL ==================== */
@media (max-width: 768px) {
    /* Bottom navigation friendly */
    .bottom-nav {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 90;
        background: #FAF7F2;
        box-shadow: 0 -2px 20px rgba(15, 10, 7, 0.08);
        padding: 0.625rem 0;
        padding-bottom: calc(0.625rem + env(safe-area-inset-bottom));
    }
    
    .bottom-nav nav {
        display: flex;
        justify-content: space-around;
        align-items: center;
    }
    
    .bottom-nav a {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 0.25rem;
        padding: 0.5rem;
        min-width: 60px;
        font-size: 0.75rem;
        color: var(--text-2, #6B5B4F);
        text-decoration: none;
    }

    .bottom-nav a.active {
        color: var(--copper, #B87333);
    }
    
    .bottom-nav i {
        font-size: 1.25rem;
    }
    
    /* Body padding for bottom nav */
    body.has-bottom-nav {
        padding-bottom: calc(70px + env(safe-area-inset-bottom));
    }
}

/* ==================== UTILITY CLASSES ==================== */
@media (max-width: 768px) {
    .hide-mobile { display: none !important; }
    .show-mobile { display: block !important; }
    .show-mobile-flex { display: flex !important; }
    .show-mobile-inline { display: inline !important; }
    
    .full-width-mobile { width: 100% !important; }
    .text-center-mobile { text-align: center !important; }
    
    .mb-mobile { margin-bottom: 1rem !important; }
    .mt-mobile { margin-top: 1rem !important; }
    .p-mobile { padding: 1rem !important; }
}

@media (min-width: 769px) {
    .hide-desktop { display: none !important; }
}

/* ==================== ACCESSIBILITY (mobil) ==================== */
@media (max-width: 768px) {
    /* Focus states daha belirgin */
    *:focus-visible {
        outline: 3px solid #B87333;
        outline-offset: 2px;
    }
    
    /* Skip to content */
    .skip-to-content {
        position: absolute;
        top: -40px;
        left: 0;
        background: #B87333;
        color: white;
        padding: 0.5rem 1rem;
        z-index: 1000;
        border-radius: 0 0 8px 0;
    }
    
    .skip-to-content:focus {
        top: 0;
    }
}

/* ==================== PRINT (mobil) ==================== */
@media print {
    .mv-hdr, .header, .footer, .bottom-nav, .sidebar,
    button, .btn, .modal, .popup, .overlay {
        display: none !important;
    }
    
    body {
        font-size: 12pt;
        line-height: 1.5;
        color: #000;
        background: #fff;
    }
    
    a {
        text-decoration: underline;
        color: #000;
    }
    
    a[href]:after {
        content: " (" attr(href) ")";
        font-size: 10pt;
        color: #666;
    }
}

/* ==================== DARK MODE (mobil uyumlu) ==================== */
@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0F0A07;
        --card: #1C1410;
        --text: #F5F1E8;
        --text-secondary: #9B8B7F;
        --border: #3D3228;
    }

    body {
        background: var(--bg);
        color: var(--text);
    }

    .mv-hdr {
        background: rgba(28, 20, 16, 0.95);
        border-bottom-color: rgba(255, 255, 255, 0.08);
    }

    .card {
        background: var(--card);
        border-color: var(--border);
    }

    input, select, textarea {
        background: var(--card);
        color: var(--text);
        border-color: var(--border);
    }
}

/* ==================== PWA SPECIFIC ==================== */
@media (display-mode: standalone) {
    /* PWA modunda çalışıyorsa */
    body {
        padding-top: env(safe-area-inset-top);
    }
    
    .mv-hdr {
        top: env(safe-area-inset-top);
    }
    
    /* iOS status bar spacing */
    .ios-status-bar {
        height: env(safe-area-inset-top);
        background: linear-gradient(135deg, var(--copper, #B87333), var(--copper-l, #D4956A));
    }
}

/* ==================== ORIENTATION CHANGE ==================== */
@media (orientation: landscape) and (max-height: 500px) {
    /* Landscape'te tüm section'ları sıkıştır */
    section, .section {
        padding-top: 1.5rem !important;
        padding-bottom: 1.5rem !important;
    }
    
    /* Modal'ları daha dar yap */
    .modal, .popup {
        max-height: 90vh;
        padding: 1rem;
    }
    
    /* Header daha ince */
    .mv-hdr-in {
        height: 44px !important;
    }
}

/* ==================== FONT SIZE ACCESSIBILITY ==================== */
@media (min-width: 320px) {
    /* Minimum font size - küçük ekranlarda okunabilirlik */
    body { font-size: 15px; }
    small, .small { font-size: 13px; }
}

/* ==================== IMAGE OPTIMIZATION ==================== */
@media (max-width: 768px) {
    /* Lazy loading + aspect ratio */
    img[loading="lazy"] {
        background: linear-gradient(135deg, #F3EDE4, #E0D5C8);
    }
    
    /* Responsive images */
    picture img,
    img[srcset] {
        width: 100%;
        height: auto;
    }
    
    /* Avatar/thumbnail boyutları */
    .avatar, .thumbnail {
        max-width: 100px;
        max-height: 100px;
    }
}

/* ==================== SWIPE GESTURES SUPPORT ==================== */
@media (hover: none) and (pointer: coarse) {
    /* Swipeable containers */
    .swipeable {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scroll-snap-type: x mandatory;
        scrollbar-width: none;
    }
    
    .swipeable::-webkit-scrollbar {
        display: none;
    }
    
    .swipeable > * {
        scroll-snap-align: start;
    }
}

/* ==================== LOADING STATES (mobil) ==================== */
@media (max-width: 768px) {
    .loading, .skeleton {
        background: linear-gradient(90deg, #F3EDE4 25%, #E0D5C8 50%, #F3EDE4 75%);
        background-size: 200% 100%;
        animation: shimmer 1.5s infinite;
    }
    
    @keyframes shimmer {
        0% { background-position: 200% 0; }
        100% { background-position: -200% 0; }
    }
    
    /* Loading spinner */
    .spinner {
        width: 32px;
        height: 32px;
        border: 3px solid var(--border, #E0D5C8);
        border-top-color: var(--copper, #B87333);
        border-radius: 50%;
        animation: spin 0.8s linear infinite;
    }
    
    @keyframes spin {
        to { transform: rotate(360deg); }
    }
}
