/* Mobile Optimizations */

/* ⚡ Improved Touch Feedback */
@media (hover: none) and (pointer: coarse) {
    /* Tüm tıklanabilir elementler için hızlı feedback */
    button, a, .clickable, [role="button"] {
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
        user-select: none;
    }
    
    /* Active state - haptic-style visual feedback */
    button:active, 
    .chat-history-item:active,
    .sidebar-nav-btn:active,
    .profile-menu-item:active {
        transform: scale(0.97);
        opacity: 0.85;
        transition: transform 0.1s ease, opacity 0.1s ease;
    }
    
    /* Smooth scrolling */
    .chat-messages,
    .chat-history,
    .settings-content {
        -webkit-overflow-scrolling: touch;
        scroll-behavior: smooth;
    }
}

/* Overlay */
.mobile-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 99;
    opacity: 0;
    transition: opacity 0.3s;
}

.mobile-overlay.active {
    display: block;
    opacity: 1;
}

/* Touch Device - Telefonda masaüstü modu için */
body.touch-device .sidebar {
    position: fixed !important;
    left: -280px !important;
    width: 280px !important;
    height: 100vh !important;
    z-index: 100 !important;
    transition: left 0.3s ease !important;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.3);
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
}

body.touch-device .sidebar.open {
    left: 0 !important;
}

/* Sidebar içerik düzeni - Touch device */
body.touch-device .sidebar-header {
    flex-shrink: 0;
}

body.touch-device .sidebar-nav {
    flex-shrink: 0;
}

body.touch-device .chat-history {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

body.touch-device .sidebar-footer {
    flex-shrink: 0;
    padding: 12px;
}

body.touch-device .user-profile {
    display: flex !important;
    align-items: center !important;
    gap: 10px !important;
}

body.touch-device .user-avatar {
    flex-shrink: 0;
    width: 36px !important;
    height: 36px !important;
}

body.touch-device .user-info {
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

body.touch-device .user-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Main content düzeni - Touch device */
body.touch-device .main-content {
    width: 100%;
    transition: none;
}

body.touch-device #menuBtn {
    display: flex !important;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: 8px;
    cursor: pointer;
    font-size: 20px;
    color: var(--text-primary);
    transition: all 0.2s;
}

body.touch-device #menuBtn:active {
    transform: scale(0.95);
}

/* Touch Device Detection - Media query fallback */
@media (hover: none) and (pointer: coarse) {
    .sidebar {
        position: fixed !important;
        left: -280px !important;
        width: 280px !important;
        height: 100vh !important;
        z-index: 100 !important;
        transition: left 0.3s ease !important;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.3);
        display: flex !important;
        flex-direction: column !important;
        overflow: hidden !important;
    }

    .sidebar.open {
        left: 0 !important;
    }

    /* Sidebar içerik düzeni */
    .sidebar-header {
        flex-shrink: 0;
    }

    .sidebar-nav {
        flex-shrink: 0;
    }

    .chat-history {
        flex: 1;
        overflow-y: auto;
        min-height: 0;
    }

    .sidebar-footer {
        flex-shrink: 0;
        padding: 12px;
    }

    .user-profile {
        display: flex !important;
        align-items: center !important;
        gap: 10px !important;
    }

    .user-avatar {
        flex-shrink: 0;
        width: 36px !important;
        height: 36px !important;
    }

    .user-info {
        flex: 1;
        min-width: 0;
        overflow: hidden;
    }

    .user-name {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    #menuBtn {
        display: flex !important;
        align-items: center;
        justify-content: center;
        width: 44px;
        height: 44px;
        background: var(--bg-secondary);
        border: 1px solid var(--border-primary);
        border-radius: 8px;
        cursor: pointer;
        font-size: 20px;
        color: var(--text-primary);
        transition: all 0.2s;
    }

    #menuBtn:active {
        transform: scale(0.95);
    }

    /* Main content düzeni */
    .main-content {
        width: 100%;
    }
}

/* Sidebar Mobile - Küçük ekranlar için */
@media (max-width: 768px) {
    .sidebar {
        position: fixed !important;
        left: -280px !important;
        width: 280px !important;
        height: 100vh !important;
        z-index: 100 !important;
        transition: left 0.3s ease !important;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.3);
        display: flex !important;
        flex-direction: column !important;
        overflow: hidden !important;
    }

    .sidebar.open {
        left: 0 !important;
    }

    /* Sidebar içerik düzeni */
    .sidebar-header {
        flex-shrink: 0;
    }

    .sidebar-nav {
        flex-shrink: 0;
    }

    .chat-history {
        flex: 1;
        overflow-y: auto;
        min-height: 0;
    }

    .sidebar-footer {
        flex-shrink: 0;
        padding: 12px;
    }

    .user-profile {
        display: flex !important;
        align-items: center !important;
        gap: 10px !important;
    }

    .user-avatar {
        flex-shrink: 0;
        width: 36px !important;
        height: 36px !important;
    }

    .user-info {
        flex: 1;
        min-width: 0;
        overflow: hidden;
    }

    .user-name {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* Chat area padding */
    .chat-messages {
        padding: 16px;
    }

    .input-area {
        padding: 16px;
    }

    /* Menu button */
    #menuBtn {
        display: flex !important;
        align-items: center;
        justify-content: center;
        width: 44px;
        height: 44px;
        background: var(--bg-secondary);
        border: 1px solid var(--border-primary);
        border-radius: 8px;
        cursor: pointer;
        font-size: 20px;
        color: var(--text-primary);
        transition: all 0.2s;
    }

    #menuBtn:hover {
        background: var(--bg-hover);
    }

    #menuBtn:active {
        transform: scale(0.95);
    }
}

/* Touch Gestures */
.swipe-delete {
    position: relative;
    overflow: hidden;
}

.swipe-delete-bg {
    position: absolute;
    top: 0;
    right: 0;
    height: 100%;
    width: 80px;
    background: #dc3545;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 20px;
}

/* Pull to Refresh */
.pull-to-refresh {
    position: absolute;
    top: -60px;
    left: 0;
    right: 0;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-secondary);
    transition: top 0.3s;
}

.pull-to-refresh.active {
    top: 0;
}

.pull-to-refresh-icon {
    font-size: 24px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* Touch Friendly */
@media (max-width: 768px) {
    button,
    .chat-item,
    .input-btn {
        min-height: 44px;
        min-width: 44px;
    }

    .chat-item {
        padding: 12px 16px;
    }

    /* Safe Area (iPhone notch) */
    .sidebar {
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
    }

    .chat-area {
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
    }
}

/* Responsive Typography */
@media (max-width: 480px) {
    body {
        font-size: 14px;
    }

    h1 {
        font-size: 20px;
    }

    h2 {
        font-size: 18px;
    }

    .message-content {
        font-size: 14px;
    }
}
