/**
 * Responsive Design Improvements
 * Mobile-first, touch-friendly interface
 */

/* ============================================
   Mobile-First Base Styles
   ============================================ */

/* Touch-friendly tap targets (minimum 44x44px) */
button, 
a.button,
input[type="submit"],
input[type="button"],
.btn,
.nav-link,
.menu-item,
.notification-item,
.post-action-button {
    min-height: 44px;
    min-width: 44px;
    padding: 12px 16px;
    touch-action: manipulation; /* Disable double-tap zoom */
}

/* Improved touch scrolling */
body, 
.scrollable,
.thread-list,
.post-list,
.notification-list {
    -webkit-overflow-scrolling: touch;
    overflow-scrolling: touch;
}

/* Prevent text selection on buttons (better UX on mobile) */
button,
.btn,
.nav-link {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* ============================================
   Mobile Navigation Improvements
   ============================================ */

@media (max-width: 768px) {
    /* Mobile menu improvements */
    .mobile-menu-toggle {
        position: fixed;
        top: 15px;
        right: 15px;
        z-index: 1000;
        width: 48px;
        height: 48px;
        border-radius: 8px;
        background: var(--discord-blurple, #5865F2);
        color: white;
        border: none;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 20px;
    }
    
    .mobile-menu-toggle:active {
        transform: scale(0.95);
        background: var(--discord-blurple-dark, #4752C4);
    }
    
    /* Navigation overlay improvements */
    .mobile-menu-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.7);
        z-index: 999;
        backdrop-filter: blur(4px);
        -webkit-backdrop-filter: blur(4px);
    }
    
    /* Sidebar navigation for mobile */
    .sidebar-nav {
        position: fixed;
        top: 0;
        left: -100%;
        width: 280px;
        max-width: 85vw;
        height: 100vh;
        background: var(--discord-dark, #2C2F33);
        z-index: 1000;
        transition: left 0.3s ease;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.3);
    }
    
    .sidebar-nav.open {
        left: 0;
    }
    
    .sidebar-nav .nav-item {
        padding: 16px 20px;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
        display: block;
        color: white;
        text-decoration: none;
        font-size: 16px;
        min-height: 56px;
        display: flex;
        align-items: center;
    }
    
    .sidebar-nav .nav-item:active {
        background: rgba(255, 255, 255, 0.1);
    }
}

/* ============================================
   Thread & Post Improvements
   ============================================ */

@media (max-width: 768px) {
    /* Thread cards - better spacing on mobile */
    .thread-card,
    .post-card {
        padding: 16px;
        margin-bottom: 12px;
        border-radius: 8px;
        background: var(--discord-dark, #2C2F33);
    }
    
    /* Thread title - larger, more readable */
    .thread-title {
        font-size: 18px;
        line-height: 1.4;
        margin-bottom: 8px;
        word-wrap: break-word;
    }
    
    /* Post content - better readability */
    .post-content {
        font-size: 16px;
        line-height: 1.6;
        word-wrap: break-word;
    }
    
    /* Action buttons - larger, easier to tap */
    .post-actions,
    .thread-actions {
        display: flex;
        gap: 8px;
        margin-top: 12px;
    }
    
    .post-action-button,
    .thread-action-button {
        flex: 1;
        min-height: 44px;
        padding: 12px;
        font-size: 14px;
        border-radius: 6px;
    }
}

/* ============================================
   Form Improvements
   ============================================ */

@media (max-width: 768px) {
    /* Form inputs - larger, easier to use */
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="search"],
    textarea,
    select {
        font-size: 16px; /* Prevents zoom on iOS */
        padding: 12px 16px;
        min-height: 44px;
        border-radius: 6px;
        width: 100%;
        box-sizing: border-box;
    }
    
    /* Textarea - better for mobile */
    textarea {
        min-height: 120px;
        resize: vertical;
    }
    
    /* Form buttons - full width on mobile */
    .form-actions button,
    .form-actions .btn {
        width: 100%;
        margin-bottom: 8px;
    }
    
    /* Search bar improvements */
    .search-bar {
        width: 100%;
        padding: 12px 16px;
        font-size: 16px;
    }
}

/* ============================================
   Touch Gestures
   ============================================ */

/* Swipe gestures for mobile */
.swipeable {
    position: relative;
    overflow: hidden;
}

.swipeable-content {
    transition: transform 0.3s ease;
}

/* Pull to refresh indicator */
.pull-to-refresh {
    position: absolute;
    top: -50px;
    left: 50%;
    transform: translateX(-50%);
    padding: 10px;
    background: var(--discord-blurple, #5865F2);
    color: white;
    border-radius: 20px;
    font-size: 14px;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.pull-to-refresh.active {
    opacity: 1;
}

/* ============================================
   Modal Improvements
   ============================================ */

@media (max-width: 768px) {
    /* Full-screen modals on mobile */
    .modal {
        margin: 0;
        max-width: 100%;
        height: 100vh;
        border-radius: 0;
    }
    
    .modal-content {
        height: 100%;
        border-radius: 0;
        display: flex;
        flex-direction: column;
    }
    
    .modal-header {
        flex-shrink: 0;
        padding: 16px;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    }
    
    .modal-body {
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding: 16px;
    }
    
    .modal-footer {
        flex-shrink: 0;
        padding: 16px;
        border-top: 1px solid rgba(255, 255, 255, 0.1);
    }
    
    /* Close button - larger, easier to tap */
    .modal-close {
        width: 44px;
        height: 44px;
        font-size: 24px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
}

/* ============================================
   Table Improvements
   ============================================ */

@media (max-width: 768px) {
    /* Convert tables to cards on mobile */
    .responsive-table {
        display: block;
    }
    
    .responsive-table thead {
        display: none;
    }
    
    .responsive-table tbody,
    .responsive-table tr,
    .responsive-table td {
        display: block;
        width: 100%;
    }
    
    .responsive-table tr {
        margin-bottom: 16px;
        padding: 16px;
        background: var(--discord-dark, #2C2F33);
        border-radius: 8px;
    }
    
    .responsive-table td {
        padding: 8px 0;
        text-align: left;
        border: none;
    }
    
    .responsive-table td:before {
        content: attr(data-label) ": ";
        font-weight: bold;
        display: inline-block;
        width: 120px;
    }
}

/* ============================================
   Image Improvements
   ============================================ */

@media (max-width: 768px) {
    /* Responsive images */
    img {
        max-width: 100%;
        height: auto;
    }
    
    /* Image lightbox - full screen on mobile */
    .lightbox-image {
        max-width: 100%;
        max-height: 90vh;
    }
    
    /* Thumbnails - better spacing */
    .thumbnail-grid {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
        gap: 8px;
    }
}

/* ============================================
   Notification Improvements
   ============================================ */

@media (max-width: 768px) {
    /* Notification bell - larger tap target */
    .notification-bell {
        width: 44px;
        height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    /* Notification dropdown - full width on mobile */
    .notification-dropdown {
        position: fixed;
        top: 60px;
        left: 0;
        right: 0;
        max-height: 70vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Notification items - larger, easier to tap */
    .notification-item {
        padding: 16px;
        min-height: 60px;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    }
}

/* ============================================
   Typography Improvements
   ============================================ */

@media (max-width: 768px) {
    /* Better line height for readability */
    body {
        font-size: 16px;
        line-height: 1.6;
    }
    
    h1 {
        font-size: 24px;
        line-height: 1.3;
    }
    
    h2 {
        font-size: 20px;
        line-height: 1.3;
    }
    
    h3 {
        font-size: 18px;
        line-height: 1.4;
    }
    
    /* Better spacing */
    p {
        margin-bottom: 12px;
    }
}

/* ============================================
   Loading States
   ============================================ */

/* Skeleton loading for better perceived performance */
.skeleton {
    background: linear-gradient(
        90deg,
        rgba(255, 255, 255, 0.1) 25%,
        rgba(255, 255, 255, 0.2) 50%,
        rgba(255, 255, 255, 0.1) 75%
    );
    background-size: 200% 100%;
    animation: loading 1.5s ease-in-out infinite;
    border-radius: 4px;
}

@keyframes loading {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

/* ============================================
   Accessibility Improvements
   ============================================ */

/* Focus states for keyboard navigation */
button:focus,
a:focus,
input:focus,
textarea:focus,
select:focus {
    outline: 2px solid var(--discord-blurple, #5865F2);
    outline-offset: 2px;
}

/* Reduced motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ============================================
   Landscape Orientation
   ============================================ */

@media (max-width: 768px) and (orientation: landscape) {
    /* Adjustments for landscape mode */
    .modal {
        max-height: 90vh;
    }
    
    .sidebar-nav {
        width: 240px;
    }
}

/* ============================================
   Very Small Screens
   ============================================ */

@media (max-width: 480px) {
    /* Extra small screens */
    .container {
        padding: 8px;
    }
    
    .thread-card,
    .post-card {
        padding: 12px;
    }
    
    .thread-title {
        font-size: 16px;
    }
    
    /* Stack buttons vertically */
    .button-group {
        flex-direction: column;
    }
    
    .button-group button,
    .button-group .btn {
        width: 100%;
        margin-bottom: 8px;
    }
}

