/**
 * MUKO - Modern Responsive Layout System
 * Tüm cihazlarda tutarlı, stabil görünüm
 * Mobile-first, CSS Variables tabanlı
 */

/* =================================================================== */
/* === 1. CSS VARIABLES - Tek kaynak, tüm cihazlar                === */
/* =================================================================== */

:root {
    /* Safe Area Insets - iOS notch, Android gesture bar */
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --safe-right: env(safe-area-inset-right, 0px);

    /* Header - SABİT yükseklik tüm cihazlarda */
    --header-height: 60px;

    /* Spacing - Tutarlı boşluklar */
    --spacing-xs: 8px;
    --spacing-sm: 12px;
    --spacing-md: 16px;
    --spacing-lg: 24px;
    --spacing-xl: 32px;

    /* Content spacing - Header ile içerik arası */
    --content-top-spacing: 16px;

    /* Container max-width */
    --container-max: 100%;

    /* Viewport Height Fix - Mobile browser address bar için */
    --vh: 1vh;
}

/* =================================================================== */
/* === 2. RESET & BASE STYLES                                     === */
/* =================================================================== */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    height: 100%;
    overflow-x: hidden;
    -webkit-text-size-adjust: 100%;
    font-size: 16px;
}

body {
    height: 100%;
    overflow-x: hidden;
    background: #ffffff;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;

    /* Safe area padding - sadece yan taraflar */
    padding-left: max(var(--safe-left), var(--spacing-sm));
    padding-right: max(var(--safe-right), var(--spacing-sm));

    /* NO top/bottom padding - header ve content kendi halleder */
    padding-top: 0;
    padding-bottom: 0;
}

/* Fullscreen Container - Login, Register, Forgot Password sayfaları için */
body.fullscreen-container {
    /* Safe area'yı dahil et - özellikle üst notch alanı için */
    padding-top: var(--safe-top);
    padding-bottom: var(--safe-bottom);
    padding-left: max(var(--safe-left), var(--spacing-sm));
    padding-right: max(var(--safe-right), var(--spacing-sm));
}

/* =================================================================== */
/* === 3. HEADER - SABİT YÜKSEKLİK, TÜM CİHAZLARDA AYNI         === */
/* =================================================================== */

header {
    /* Position */
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;

    /* SABİT yükseklik + safe area top - !important ile koruma */
    height: calc(var(--header-height) + var(--safe-top)) !important;
    min-height: calc(var(--header-height) + var(--safe-top)) !important;
    max-height: calc(var(--header-height) + var(--safe-top)) !important;
    padding-top: var(--safe-top);

    /* İçerik padding - sağ sol */
    padding-left: max(var(--safe-left), var(--spacing-md));
    padding-right: max(var(--safe-right), var(--spacing-md));

    /* Görünüm */
    background: #ffffff;
    border-bottom: 1px solid #e5e7eb;
    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);

    /* Flex layout */
    display: flex;
    align-items: center;
}

/* Header içerik container - Sabit yükseklik */
header > div {
    width: 100%;
    height: var(--header-height) !important;
    min-height: var(--header-height) !important;
    max-height: var(--header-height) !important;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--spacing-sm);
}

/* Logo */
header h1 {
    font-size: clamp(1.5rem, 4vw, 2rem);
    font-weight: 900;
    line-height: 1;
    margin: 0;
    padding: 0;
    white-space: nowrap;
}

/* Header buttons container */
header .flex.items-center.space-x-2,
header .flex.items-center.space-x-3 {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    flex-shrink: 0;
}

/* Header buttons - Sadece ikon, sabit boyut */
header button,
header a[id$="-btn"] {
    /* Sabit boyut - sadece ikon göster */
    width: 38px;
    height: 38px;
    min-width: 38px;
    min-height: 38px;
    max-width: 38px;
    max-height: 38px;

    padding: 0;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    flex-shrink: 0;

    /* Stabil görünüm */
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
}

/* Header button SVG icons - Sabit boyut */
header button svg,
header a[id$="-btn"] svg {
    width: 18px;
    height: 18px;
    min-width: 18px;
    min-height: 18px;
    flex-shrink: 0;
}

/* Button text - Her zaman gizli (sadece ikon) */
header button span:not(.icon-emoji),
header a[id$="-btn"] span:not(.icon-emoji) {
    display: none !important;
}

/* Emoji ikonlar her zaman görünür */
header button span.icon-emoji,
header a[id$="-btn"] span.icon-emoji {
    display: inline-block !important;
    line-height: 1;
}

/* =================================================================== */
/* === 4. MAIN CONTENT - Header altında, tutarlı spacing         === */
/* =================================================================== */

main {
    /* Header yüksekliği + safe area + spacing */
    margin-top: calc(var(--header-height) + var(--safe-top) + var(--content-top-spacing));

    /* Alt padding - safe area + ekstra */
    padding-bottom: calc(var(--safe-bottom) + var(--spacing-lg));

    /* Yan padding */
    padding-left: var(--spacing-md);
    padding-right: var(--spacing-md);

    /* Minimum height - full viewport */
    min-height: calc(100vh - var(--header-height) - var(--safe-top) - var(--content-top-spacing));

    /* Scroll */
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
}

/* Main content container */
main > div {
    width: 100%;
    max-width: var(--container-max);
    margin: 0 auto;
}

/* =================================================================== */
/* === 5. MODE SELECTOR - Fotoğraf/Metin Butonları               === */
/* =================================================================== */

.mode-selector {
    display: flex;
    gap: var(--spacing-sm);
    padding: 6px;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 16px;
    border: 1px solid rgba(102, 126, 234, 0.2);
    margin: 0 auto var(--spacing-md);
    max-width: 480px;
    width: 100%;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.mode-selector button {
    flex: 1;
    height: 48px;
    min-height: 48px;
    padding: 0 var(--spacing-md);
    border-radius: 12px;
    border: none;
    font-weight: 600;
    font-size: 0.95rem;
    line-height: 1.2;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-xs);
    transition: all 0.2s ease;
    white-space: nowrap;
    cursor: pointer;
}

.mode-selector button span.text-xl {
    font-size: 1.25rem;
    line-height: 1;
}

.mode-selector button span:not(.text-xl) {
    font-size: 0.95rem;
    line-height: 1;
}

/* Question Setup Area - Stabil Container */
#question-setup-area {
    width: 100%;
    max-width: 640px;
    margin: 0 auto;
}

/* Photo/Text Mode Containers */
#photo-mode-container,
#handwriting-mode-container {
    width: 100%;
    max-width: 640px;
    margin: 0 auto;
}

/* Question Summary Container */
#question-summary-container {
    width: 100%;
    max-width: 640px;
    margin: var(--spacing-md) auto;
    padding: var(--spacing-md);
    background: rgba(255, 255, 255, 0.95);
    border-radius: 16px;
    border: 1px solid rgba(102, 126, 234, 0.1);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

/* Action Buttons Grid */
#top-action-buttons {
    width: 100%;
    max-width: 960px;
    margin: var(--spacing-lg) auto;
}

/* Solving Workspace */
#solving-workspace {
    width: 100%;
    max-width: 960px;
    margin: var(--spacing-lg) auto;
}

/* Result Container */
#result-container {
    width: 100%;
    max-width: 960px;
    margin: var(--spacing-lg) auto;
}

/* =================================================================== */
/* === 6. RESPONSIVE BREAKPOINTS                                  === */
/* =================================================================== */

/* Small Mobile (< 375px) */
@media (max-width: 374px) {
    :root {
        --header-height: 56px;
        --spacing-md: 12px;
        --content-top-spacing: 12px;
    }

    header h1 {
        font-size: 1.5rem;
    }

    /* Küçük ekranlarda butonlar biraz daha küçük */
    header button,
    header a[id$="-btn"] {
        width: 36px;
        height: 36px;
        min-width: 36px;
        min-height: 36px;
        max-width: 36px;
        max-height: 36px;
    }

    header button svg,
    header a[id$="-btn"] svg {
        width: 16px;
        height: 16px;
        min-width: 16px;
        min-height: 16px;
    }

    /* Mode selector küçük ekranlarda daha kompakt */
    .mode-selector {
        padding: 4px;
        gap: 8px;
    }

    .mode-selector button {
        height: 44px;
        min-height: 44px;
        padding: 0 var(--spacing-sm);
        font-size: 0.875rem;
    }

    .mode-selector button span.text-xl {
        font-size: 1.125rem;
    }

    .mode-selector button span:not(.text-xl) {
        font-size: 0.875rem;
    }
}

/* Mobile Portrait (375px - 767px) - DEFAULT */
/* Yukarıdaki ayarlar zaten mobile-first */

/* Tablet Portrait (768px - 1023px) */
@media (min-width: 768px) {
    :root {
        --header-height: 64px;
        --spacing-md: 24px;
        --spacing-lg: 32px;
        --content-top-spacing: 24px;
        --container-max: 720px;
    }

    header {
        padding-left: max(var(--safe-left), var(--spacing-lg));
        padding-right: max(var(--safe-right), var(--spacing-lg));
    }

    /* Tablet - butonlar biraz daha büyük */
    header button,
    header a[id$="-btn"] {
        width: 40px;
        height: 40px;
        min-width: 40px;
        min-height: 40px;
        max-width: 40px;
        max-height: 40px;
    }

    main {
        padding-left: var(--spacing-lg);
        padding-right: var(--spacing-lg);
    }

    /* Mode selector tablet'te daha geniş */
    .mode-selector {
        max-width: 560px;
        padding: 8px;
    }

    .mode-selector button {
        height: 52px;
        min-height: 52px;
        font-size: 1rem;
    }

    .mode-selector button span.text-xl {
        font-size: 1.5rem;
    }
}

/* Desktop (1024px+) */
@media (min-width: 1024px) {
    :root {
        --header-height: 68px;
        --spacing-xl: 48px;
        --content-top-spacing: 32px;
        --container-max: 960px;
    }

    header {
        padding-left: max(var(--safe-left), var(--spacing-xl));
        padding-right: max(var(--safe-right), var(--spacing-xl));
    }

    /* Desktop - butonlar en büyük */
    header button,
    header a[id$="-btn"] {
        width: 42px;
        height: 42px;
        min-width: 42px;
        min-height: 42px;
        max-width: 42px;
        max-height: 42px;
    }

    header button svg,
    header a[id$="-btn"] svg {
        width: 20px;
        height: 20px;
        min-width: 20px;
        min-height: 20px;
    }

    main {
        padding-left: var(--spacing-xl);
        padding-right: var(--spacing-xl);
    }

    /* Mode selector desktop'ta maksimum boyut */
    .mode-selector {
        max-width: 600px;
    }

    .mode-selector button {
        height: 56px;
        min-height: 56px;
        font-size: 1.05rem;
    }
}

/* Large Desktop (1440px+) */
@media (min-width: 1440px) {
    :root {
        --container-max: 1200px;
    }
}

/* =================================================================== */
/* === 7. LANDSCAPE ORIENTATION - Kompakt Mod                    === */
/* =================================================================== */

/* Landscape + küçük yükseklik = kompakt header */
@media (orientation: landscape) and (max-height: 500px) {
    :root {
        --header-height: 52px;
        --content-top-spacing: 8px;
        --spacing-sm: 8px;
        --spacing-md: 12px;
    }

    header h1 {
        font-size: 1.5rem;
    }

    /* Landscape - çok kompakt */
    header button,
    header a[id$="-btn"] {
        width: 34px;
        height: 34px;
        min-width: 34px;
        min-height: 34px;
        max-width: 34px;
        max-height: 34px;
    }

    header button svg,
    header a[id$="-btn"] svg {
        width: 16px;
        height: 16px;
        min-width: 16px;
        min-height: 16px;
    }

    main {
        padding-bottom: var(--spacing-md);
    }

    /* Mode selector landscape'te kompakt */
    .mode-selector {
        padding: 4px;
        max-width: 400px;
    }

    .mode-selector button {
        height: 40px;
        min-height: 40px;
        font-size: 0.875rem;
    }

    .mode-selector button span.text-xl {
        font-size: 1.125rem;
    }
}

/* =================================================================== */
/* === 8. UTILITY CLASSES                                         === */
/* =================================================================== */

/* Scrollbar gizle */
.no-scrollbar {
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.no-scrollbar::-webkit-scrollbar {
    display: none;
}

/* Safe area bottom spacer */
.safe-area-bottom {
    height: max(var(--safe-bottom), 20px);
    width: 100%;
    flex-shrink: 0;
}

/* Hidden utility */
.hidden {
    display: none !important;
}

/* =================================================================== */
/* === 9. VIEWPORT HEIGHT FIX - Mobile Browser Address Bar       === */
/* =================================================================== */

/* JavaScript ile set edilecek --vh değerini kullan */
body {
    min-height: 100vh;
    min-height: calc(var(--vh, 1vh) * 100);
}

/* =================================================================== */
/* === 10. PRINT STYLES                                           === */
/* =================================================================== */

@media print {
    header {
        position: static;
        border: none;
        box-shadow: none;
    }

    main {
        margin-top: 0;
        padding: 0;
    }
}

/* =================================================================== */
/* === 11. DARK MODE SUPPORT (Future)                             === */
/* =================================================================== */

@media (prefers-color-scheme: dark) {
    /* Şu an aktif değil, gelecekte eklenebilir */
}

/* =================================================================== */
/* === 12. REDUCED MOTION                                         === */
/* =================================================================== */

@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* =================================================================== */
/* === 13. HIGH CONTRAST MODE                                     === */
/* =================================================================== */

@media (prefers-contrast: high) {
    header {
        border-bottom-width: 2px;
    }

    button {
        border: 2px solid currentColor !important;
    }
}

/* =================================================================== */
/* === 14. HEADER BUTTONS & LOGO STYLING                         === */
/* =================================================================== */

/* Header Logo Gradient */
.header-logo {
    background: linear-gradient(135deg, #4338CA, #3730A3);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.1));
}

/* Header Button Base */
.header-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

.header-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.header-btn:active {
    transform: translateY(0);
}

/* Premium Button Special Styling */
.header-btn-premium {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    box-shadow: 0 2px 8px rgba(245, 158, 11, 0.3);
}

.header-btn-premium:hover {
    box-shadow: 0 4px 12px rgba(245, 158, 11, 0.4);
}

/* =================================================================== */
/* === 15. MODE BUTTONS - Fotoğraf/Metin                         === */
/* =================================================================== */

.mode-btn {
    background: rgba(102, 126, 234, 0.1);
    color: #6b7280;
    font-weight: 600;
    transition: all 0.2s ease;
    cursor: pointer;
}

.mode-btn:hover {
    background: rgba(102, 126, 234, 0.15);
    color: #4f46e5;
    transform: translateY(-1px);
}

.mode-btn.active,
.mode-btn.mode-btn-active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
    transform: translateY(-1px);
}

/* =================================================================== */
/* === 16. UPLOAD ZONE & ACTION BUTTONS                          === */
/* =================================================================== */

.upload-zone {
    background: rgba(255, 255, 255, 0.5);
    backdrop-filter: blur(20px);
    border: 2px solid rgba(102, 126, 234, 0.2);
    border-radius: 20px;
    padding: var(--spacing-lg);
    transition: all 0.3s ease;
}

.upload-zone:hover {
    background: rgba(255, 255, 255, 0.7);
    border-color: rgba(102, 126, 234, 0.4);
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
}

/* Blur Button - Kullanılan primary action buttons */
.blur-button {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    font-weight: 600;
    border: none;
    transition: all 0.2s ease;
    position: relative;
    overflow: hidden;
}

.blur-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(102, 126, 234, 0.4);
}

.blur-button:active {
    transform: translateY(0);
}

.blur-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* =================================================================== */
/* === 17. SPACING UTILITIES                                      === */
/* =================================================================== */

.space-y-4 > * + * {
    margin-top: 1rem;
}

.space-y-6 > * + * {
    margin-top: 1.5rem;
}

.space-y-8 > * + * {
    margin-top: 2rem;
}