/* Mobile Optimierungen */
@media (max-width: 767px) {
    /* Sidebar als Overlay auf Mobile */
    .sidebar {
        position: fixed;
        top: 0;
        left: -250px;
        width: 250px;
        height: 100vh;
        z-index: 1500;
        transition: left 0.3s ease-out;
        box-shadow: 2px 0 8px rgba(0, 0, 0, 0.15);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .sidebar.open {
        left: 0;
    }
    
    /* Sidebar Overlay/Backdrop */
    .sidebar-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 1400;
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.3s ease-out, visibility 0.3s ease-out;
        -webkit-tap-highlight-color: transparent;
    }
    
    .sidebar-overlay.active {
        opacity: 1;
        visibility: visible;
    }
    
    .container {
        padding-bottom: 60px;
    }
    
    .main-content {
        width: 100%;
    }
    
    .page-header {
        padding: 12px;
    }
    
    .tweet-composer {
        padding: 12px;
    }
    
    .composer-avatar {
        width: 40px;
        height: 40px;
    }
    
    .tweet {
        padding: 12px;
    }
    
    .tweet-avatar {
        width: 40px;
        height: 40px;
    }
    
    .tweet-content {
        font-size: 15px;
    }
    
    .tweet-actions {
        gap: 4px;
    }
    
    .tweet-action {
        padding: 6px;
        font-size: 12px;
    }
    
    .tweet-action svg {
        width: 16px;
        height: 16px;
    }
    
    .profile-banner {
        height: 150px;
    }
    
    .profile-avatar {
        width: 60px;
        height: 60px;
        margin-top: -30px;
    }
    
    .dark-mode-toggle {
        bottom: 80px;
        right: 16px;
        width: 44px;
        height: 44px;
    }
    
    /* Touch-optimierte Buttons */
    button, .nav-link, .tweet-action {
        min-height: 44px;
        min-width: 44px;
    }
    
    /* Swipe-Gesten Unterstützung */
    .tweet {
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        user-select: none;
    }
    
    /* Bessere Scroll-Performance */
    .tweets-container,
    .notifications-container,
    .messages-container {
        -webkit-overflow-scrolling: touch;
        will-change: scroll-position;
    }
    
    /* Messages Badge auf Mobile */
    .nav-btn .badge {
        font-size: 9px;
        padding: 1px 5px;
        min-width: 16px;
    }
    
    /* New Conversation Modal auf Mobile */
    .new-conversation-results {
        max-height: 50vh;
    }
    
    .user-search-item {
        padding: 16px;
    }
    
    /* Message Delete Button auf Mobile */
    .message-delete-btn {
        display: flex !important;
        opacity: 0.7;
    }
    
    .message.sent:active .message-delete-btn {
        opacity: 1;
    }
    
    /* Optimierte Schriftgrößen */
    .tweet-content {
        font-size: 15px;
        line-height: 1.4;
    }
    
    .tweet-username {
        font-size: 15px;
    }
    
    .tweet-handle,
    .tweet-time {
        font-size: 14px;
    }
    
    /* Bild-Optimierungen für Mobile */
    .tweet-image-container {
        min-height: 150px;
        max-height: 400px;
    }
    
    .tweet-image {
        max-height: 400px;
    }
    
    /* Responsive Bildgrößen */
    .tweet-image-container img {
        width: 100%;
        height: auto;
        object-fit: cover;
    }
    
    /* Pull-to-Refresh Indicator */
    .pull-to-refresh-indicator {
        display: none;
        position: absolute;
        top: -60px;
        left: 50%;
        transform: translateX(-50%);
        align-items: center;
        gap: 12px;
        padding: 12px 20px;
        background: var(--bg-primary);
        border-radius: 20px;
        box-shadow: var(--shadow-lg);
        z-index: 100;
        transition: all 0.2s ease;
    }
    
    .pull-to-refresh-indicator.ready {
        background: var(--primary-color);
        color: white;
    }
    
    .pull-to-refresh-indicator.refreshing .pull-spinner {
        animation: spin 0.8s linear infinite;
    }
    
    .pull-spinner {
        width: 20px;
        height: 20px;
        border: 2px solid var(--border-color);
        border-top-color: var(--primary-color);
        border-radius: 50%;
    }
    
    .pull-to-refresh-indicator.ready .pull-spinner {
        border-color: rgba(255, 255, 255, 0.3);
        border-top-color: white;
    }
    
    .pull-text {
        font-size: 14px;
        color: var(--text-primary);
        white-space: nowrap;
    }
    
    .pull-to-refresh-indicator.ready .pull-text {
        color: white;
    }
    
    @keyframes spin {
        to { transform: rotate(360deg); }
    }
    
    /* Swipe-to-Delete Visual Feedback */
    .tweet {
        transition: transform 0.2s ease, background-color 0.2s ease;
    }
    
    /* Formular-Optimierungen für Mobile */
    .modal-content input,
    .modal-content textarea {
        font-size: 16px; /* Verhindert Zoom auf iOS */
        -webkit-appearance: none;
        appearance: none;
        border-radius: 8px;
    }
    
    .modal-content input:focus,
    .modal-content textarea:focus {
        outline: none;
        border-color: var(--primary-color);
        box-shadow: 0 0 0 3px rgba(29, 161, 242, 0.1);
    }
    
    /* Fehleranzeige für Mobile */
    .error-message {
        display: block;
        color: var(--error-color);
        font-size: 13px;
        margin-top: 4px;
        padding: 4px 8px;
        background: rgba(224, 36, 94, 0.1);
        border-radius: 4px;
    }
    
    /* Submit-Buttons immer sichtbar halten */
    .form-actions {
        position: sticky;
        bottom: 0;
        background: var(--bg-primary);
        padding: 16px 0;
        margin-top: 20px;
        z-index: 10;
    }
    
    /* Tastatur-Handling: Formulare scrollen zu Submit-Button */
    .modal-content form {
        padding-bottom: 80px; /* Platz für Tastatur */
    }
    
    /* Message Input optimieren */
    .message-input-container {
        position: sticky;
        bottom: 0;
        background: var(--bg-primary);
        padding: 12px;
        border-top: 1px solid var(--border-color);
        z-index: 100;
    }
    
    .message-input {
        font-size: 16px; /* Verhindert Zoom auf iOS */
        padding: 12px;
        border-radius: 24px;
    }
    
    /* Messages Badge auf Mobile */
    .nav-btn .badge {
        font-size: 9px;
        padding: 1px 5px;
        min-width: 16px;
    }
    
    /* New Conversation Modal auf Mobile */
    .new-conversation-results {
        max-height: 50vh;
    }
    
    .user-search-item {
        padding: 16px;
    }
    
    /* Message Delete Button auf Mobile */
    .message-delete-btn {
        display: flex !important;
        opacity: 0.7;
    }
    
    .message.sent:active .message-delete-btn {
        opacity: 1;
    }
}

/* Landscape Mode */
@media (max-width: 767px) and (orientation: landscape) {
    .navbar {
        padding: 4px 0;
    }
    
    .nav-btn {
        padding: 8px;
    }
    
    .container {
        padding-bottom: 50px;
    }
}

/* Sehr kleine Screens */
@media (max-width: 360px) {
    .page-header h1 {
        font-size: 18px;
    }
    
    .tweet-composer textarea {
        font-size: 18px;
    }
    
    .composer-actions {
        flex-direction: column;
        gap: 8px;
        align-items: flex-end;
    }
}

/* Performance-Optimierungen */
.tweet,
.tweet-composer,
.page-header {
    contain: layout style paint;
}

.tweets-container {
    content-visibility: auto;
}

/* Smooth Scrolling */
html {
    scroll-behavior: smooth;
}

/* Prevent Text Selection auf Buttons */
button,
.nav-link,
.tweet-action {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* Optimierte Animationen */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Modal-Optimierungen für Mobile */
@media (max-width: 767px) {
    .modal {
        padding: 0;
        align-items: flex-end;
    }
    
    .modal-content {
        width: 100%;
        max-width: 100%;
        max-height: 95vh;
        border-radius: 20px 20px 0 0;
        padding: 20px;
        margin: 0;
        position: relative;
        animation: slideUp 0.3s ease-out;
    }
    
    @keyframes slideUp {
        from {
            transform: translateY(100%);
        }
        to {
            transform: translateY(0);
        }
    }
    
    .modal-close {
        width: 44px;
        height: 44px;
        min-width: 44px;
        min-height: 44px;
        font-size: 24px;
        top: 10px;
        right: 10px;
        background: var(--bg-secondary);
        z-index: 10;
    }
    
    .modal-content h2 {
        font-size: 20px;
        margin-bottom: 16px;
        padding-right: 50px;
    }
    
    .modal-content input,
    .modal-content textarea {
        font-size: 16px; /* Verhindert Zoom auf iOS */
        padding: 14px;
    }
    
    /* Tweet Details Modal auf Mobile */
    .tweet-details-modal {
        max-width: 100%;
        border-radius: 20px 20px 0 0;
    }
    
    /* Crop Modal auf Mobile */
    .crop-modal-content {
        max-width: 100%;
        border-radius: 20px 20px 0 0;
        padding: 16px;
    }
    
    .crop-container {
        margin: 16px 0;
        max-height: 60vh;
        overflow: hidden;
    }
    
    .crop-actions {
        display: flex;
        gap: 12px;
        margin-top: 16px;
    }
    
    .crop-actions button {
        flex: 1;
        min-height: 48px;
        font-size: 16px;
    }
    
    /* Formulare in Modals */
    .form-group {
        margin-bottom: 16px;
    }
    
    .form-actions {
        display: flex;
        gap: 12px;
        margin-top: 20px;
        position: sticky;
        bottom: 0;
        background: var(--bg-primary);
        padding-top: 16px;
        padding-bottom: env(safe-area-inset-bottom, 0);
    }
    
    .form-actions button {
        flex: 1;
        min-height: 48px;
        font-size: 16px;
    }
    
    /* Kommentar-Modal */
    .comment-preview {
        font-size: 14px;
        padding: 10px;
    }
    
    /* Edit Profile Modal */
    .image-upload-container {
        margin-top: 12px;
    }
    
    .image-preview {
        margin-bottom: 12px;
    }
    
    .upload-progress {
        margin-top: 16px;
    }
}

