/* ============================================
   COMPREHENSIVE MOBILE RESPONSIVENESS
   Enhanced Mobile UI with Modern Design
   ============================================ */

/* Mobile-First Base Styles */
* {
    -webkit-tap-highlight-color: transparent;
}

/* Mobile Header - Fixed at top - Enhanced */
.mobile-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 64px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    z-index: 1000;
    display: none;
    align-items: center;
    padding: 0 16px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    backdrop-filter: blur(10px);
}

@media (max-width: 767px) {
    .mobile-header {
        display: flex !important;
    }
}

.mobile-header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
}

.mobile-menu-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 44px;
    height: 44px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    font-size: 20px;
    flex-shrink: 0;
}

.mobile-menu-btn:hover {
    background: rgba(255, 255, 255, 0.25);
}

.mobile-menu-btn:active {
    background: rgba(255, 255, 255, 0.35);
    transform: scale(0.92);
}

.mobile-logo {
    color: white;
    font-weight: 600;
    font-size: 17px;
    flex: 1;
    text-align: center;
    margin: 0 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    letter-spacing: -0.01em;
}

/* Mobile Layout Container */
.mobile-layout {
    display: flex;
    flex-direction: column;
}

@media (min-width: 768px) {
    .mobile-layout {
        flex-direction: row;
    }
}

/* Sidebar - Hidden on mobile, shown via overlay - Enhanced */
.sidebar {
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@media (max-width: 767px) {
    .sidebar {
        position: fixed;
        top: 64px;
        left: 0;
        bottom: 0;
        width: 300px;
        max-width: 85vw;
        z-index: 999;
        transform: translateX(-100%);
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.2);
        overflow-y: auto;
        overflow-x: hidden;
        background: white;
    }
    
    .sidebar.open {
        transform: translateX(0);
    }
    
    /* Smooth scrollbar for sidebar */
    .sidebar::-webkit-scrollbar {
        width: 4px;
    }
    
    .sidebar::-webkit-scrollbar-track {
        background: transparent;
    }
    
    .sidebar::-webkit-scrollbar-thumb {
        background: rgba(0, 0, 0, 0.2);
        border-radius: 2px;
    }
    
    .sidebar::-webkit-scrollbar-thumb:hover {
        background: rgba(0, 0, 0, 0.3);
    }
}

/* Sidebar Overlay - Enhanced */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 64px;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 998;
    backdrop-filter: blur(4px);
    transition: opacity 0.3s ease;
    opacity: 0;
}

.sidebar-overlay.active {
    opacity: 1;
}

@media (max-width: 767px) {
    .sidebar-overlay.active {
        display: block;
    }
}

/* Main Content - Adjust for mobile header - Enhanced */
.main-content-mobile {
    padding-top: 80px !important;
    padding-left: 16px !important;
    padding-right: 16px !important;
    padding-bottom: 32px !important;
    min-height: calc(100vh - 64px);
}

@media (min-width: 768px) {
    .main-content-mobile {
        padding-top: 32px !important;
        padding-left: 32px !important;
        padding-right: 32px !important;
        padding-bottom: 32px !important;
    }
}

/* Ensure all main content areas have proper spacing on mobile */
@media (max-width: 767px) {
    /* Target main content divs that might not have the class */
    .flex.mobile-layout > .flex-1,
    .flex.mobile-layout > div[class*="flex-1"],
    body > .flex > .flex-1:first-of-type {
        padding-top: 80px !important;
    }
    
    /* Ensure content inside main-content-mobile starts properly */
    .main-content-mobile > *:first-child {
        margin-top: 0;
    }
    
    /* Fix for pages with p-8 or p-6 that might conflict - More specific */
    .main-content-mobile.p-8,
    .main-content-mobile.p-6,
    .flex-1.p-8.main-content-mobile,
    .flex-1.p-6.main-content-mobile,
    div[class*="flex-1"][class*="p-8"].main-content-mobile,
    div[class*="flex-1"][class*="p-6"].main-content-mobile {
        padding-top: 80px !important;
    }
    
    /* Override any Tailwind padding-top that might interfere */
    .main-content-mobile[class*="pt-"] {
        padding-top: 80px !important;
    }
    
    /* Ensure max-w containers inside don't cause issues */
    .main-content-mobile > .max-w-7xl,
    .main-content-mobile > .max-w-6xl,
    .main-content-mobile > .max-w-5xl {
        margin-top: 0;
    }
}

/* Responsive Typography */
@media (max-width: 767px) {
    h1 {
        font-size: 1.75rem !important;
        line-height: 2rem !important;
    }
    
    h2 {
        font-size: 1.5rem !important;
        line-height: 1.75rem !important;
    }
    
    h3 {
        font-size: 1.25rem !important;
        line-height: 1.5rem !important;
    }
    
    .text-3xl {
        font-size: 1.5rem !important;
    }
    
    .text-4xl {
        font-size: 2rem !important;
    }
    
    .text-5xl {
        font-size: 2.5rem !important;
    }
}

/* Responsive Grids */
@media (max-width: 767px) {
    .grid {
        gap: 16px !important;
    }
    
    .grid-cols-2,
    .grid-cols-3,
    .grid-cols-4 {
        grid-template-columns: 1fr !important;
    }
}

/* Cards - Mobile Optimized - Enhanced */
@media (max-width: 767px) {
    .card,
    [class*="rounded-xl"],
    [class*="rounded-lg"] {
        padding: 18px !important;
        margin-bottom: 16px;
        border-radius: 16px !important;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08) !important;
    }
    
    .p-6 {
        padding: 18px !important;
    }
    
    .p-8 {
        padding: 24px !important;
    }
    
    /* Better card spacing */
    .bg-white {
        border-radius: 16px;
    }
}

/* Buttons - Touch Friendly - Enhanced */
@media (max-width: 767px) {
    button,
    .btn,
    [role="button"],
    a[class*="bg-"] {
        min-height: 48px;
        min-width: 48px;
        padding: 14px 24px !important;
        font-size: 16px !important;
        font-weight: 500;
        border-radius: 12px !important;
        transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    }
    
    button:active,
    .btn:active,
    a[class*="bg-"]:active {
        transform: scale(0.96);
        opacity: 0.9;
    }
    
    /* Button groups - better spacing */
    .flex.space-x-2 > button,
    .flex.space-x-3 > button,
    .flex.space-x-4 > button {
        flex: 1;
    }
}

/* Forms - Mobile Optimized - Enhanced */
@media (max-width: 767px) {
    input,
    textarea,
    select {
        font-size: 16px !important; /* Prevents zoom on iOS */
        padding: 14px 16px !important;
        min-height: 48px;
        border-radius: 12px !important;
        border: 1.5px solid #e5e7eb !important;
        transition: all 0.2s ease;
    }
    
    input:focus,
    textarea:focus,
    select:focus {
        border-color: #667eea !important;
        box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1) !important;
        outline: none;
    }
    
    label {
        font-size: 14px !important;
        font-weight: 500 !important;
        margin-bottom: 8px !important;
        color: #374151 !important;
    }
    
    /* Form groups */
    .space-y-4 > div,
    .space-y-6 > div {
        margin-bottom: 20px;
    }
}

/* Tables - Horizontal Scroll on Mobile */
@media (max-width: 767px) {
    table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        white-space: nowrap;
    }
    
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}

/* Modals - Mobile Optimized - Enhanced */
@media (max-width: 767px) {
    .modal,
    [class*="modal"],
    [id*="Modal"] {
        padding: 0 !important;
        margin: 0 !important;
        max-width: 100% !important;
        max-height: 100vh !important;
        border-radius: 0 !important;
    }
    
    /* Modal container */
    .fixed.inset-0 > .flex {
        align-items: flex-end;
        padding: 0;
    }
    
    /* Modal content */
    .modal-content,
    [class*="modal"] > div,
    [id*="Modal"] > div {
        padding: 24px !important;
        border-radius: 24px 24px 0 0 !important;
        max-height: 90vh;
        overflow-y: auto;
        width: 100%;
        margin-top: auto;
    }
    
    /* Modal header */
    .modal-content > div:first-child,
    [id*="Modal"] h3 {
        padding-bottom: 16px;
        margin-bottom: 20px;
        border-bottom: 1px solid #e5e7eb;
    }
    
    /* Modal buttons */
    .modal-content button,
    [id*="Modal"] button {
        width: 100%;
        margin-bottom: 12px;
    }
    
    .modal-content button:last-child,
    [id*="Modal"] button:last-child {
        margin-bottom: 0;
    }
}

/* Stats Cards - Stack on Mobile */
@media (max-width: 767px) {
    .stat-card,
    [class*="stat"] {
        margin-bottom: 12px;
    }
}

/* Navigation - Mobile Menu - Enhanced */
@media (max-width: 767px) {
    .nav-item {
        padding: 16px 20px !important;
        font-size: 16px !important;
        min-height: 52px;
        display: flex;
        align-items: center;
        border-radius: 12px;
        margin-bottom: 4px;
        transition: all 0.2s ease;
    }
    
    .nav-item:hover,
    .nav-item:active {
        background-color: #f3f4f6;
        transform: translateX(4px);
    }
    
    .nav-item i {
        width: 24px;
        text-align: center;
        margin-right: 12px;
    }
}

/* Spacing Adjustments - Enhanced */
@media (max-width: 767px) {
    .mb-8 {
        margin-bottom: 24px !important;
    }
    
    .mb-6 {
        margin-bottom: 20px !important;
    }
    
    .mb-4 {
        margin-bottom: 16px !important;
    }
    
    .mt-8 {
        margin-top: 24px !important;
    }
    
    .mt-6 {
        margin-top: 20px !important;
    }
    
    .mt-4 {
        margin-top: 16px !important;
    }
    
    .gap-6 {
        gap: 16px !important;
    }
    
    .gap-8 {
        gap: 20px !important;
    }
    
    .gap-4 {
        gap: 12px !important;
    }
    
    /* Page headers */
    .mb-8 > h1,
    .mb-8 > h2 {
        margin-bottom: 8px !important;
    }
}

/* Header - Hide on mobile, show mobile header */
@media (max-width: 767px) {
    #header-placeholder,
    nav[class*="header"],
    header {
        display: none !important;
    }
    
    /* Ensure body content doesn't overlap mobile header */
    body {
        padding-top: 0 !important;
    }
    
    /* Additional safety for any content that might be at the top */
    body > div:first-child:not(.mobile-header):not(#header-placeholder) {
        margin-top: 0;
    }
}

/* Sidebar - Hide on mobile by default */
@media (max-width: 767px) {
    #sidebar-placeholder > .sidebar:not(.open) {
        display: none;
    }
}

/* Filters and Search - Stack on Mobile */
@media (max-width: 767px) {
    .filters,
    [class*="filter"],
    .search-bar {
        flex-direction: column !important;
        gap: 12px !important;
    }
    
    .filters > *,
    [class*="filter"] > * {
        width: 100% !important;
    }
}

/* Badges and Tags - Adjust Size */
@media (max-width: 767px) {
    .badge,
    [class*="badge"],
    [class*="tag"] {
        font-size: 12px !important;
        padding: 4px 8px !important;
    }
}

/* Images - Responsive */
@media (max-width: 767px) {
    img {
        max-width: 100% !important;
        height: auto !important;
    }
}

/* Text Truncation */
@media (max-width: 767px) {
    .truncate-mobile {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        max-width: 100%;
    }
}

/* Safe Area for Notched Devices */
@supports (padding: max(0px)) {
    .mobile-header {
        padding-left: max(16px, env(safe-area-inset-left));
        padding-right: max(16px, env(safe-area-inset-right));
    }
    
    .main-content-mobile {
        padding-left: max(16px, env(safe-area-inset-left)) !important;
        padding-right: max(16px, env(safe-area-inset-right)) !important;
    }
}

/* Loading States */
@media (max-width: 767px) {
    .loading,
    [class*="loading"] {
        padding: 20px !important;
    }
}

/* Empty States */
@media (max-width: 767px) {
    .empty-state {
        padding: 40px 20px !important;
        text-align: center;
    }
}

/* Utility Classes */
@media (max-width: 767px) {
    .mobile-hidden {
        display: none !important;
    }
    
    .mobile-block {
        display: block !important;
    }
    
    .mobile-flex {
        display: flex !important;
    }
    
    .mobile-text-center {
        text-align: center !important;
    }
    
    .mobile-full-width {
        width: 100% !important;
    }
}

/* Smooth Scrolling */
@media (max-width: 767px) {
    html {
        scroll-behavior: smooth;
        -webkit-overflow-scrolling: touch;
    }
}

/* Prevent Text Selection on Buttons */
@media (max-width: 767px) {
    button,
    .btn,
    [role="button"] {
        -webkit-user-select: none;
        -moz-user-select: none;
        user-select: none;
    }
}

/* ============================================
   ADDITIONAL MOBILE ENHANCEMENTS
   ============================================ */

/* Enhanced Stats Cards */
@media (max-width: 767px) {
    .stat-card,
    [class*="stat"] {
        margin-bottom: 16px;
        padding: 20px !important;
        border-radius: 16px !important;
    }
    
    /* Stats grid - better spacing */
    .grid.grid-cols-1.md\:grid-cols-4 {
        gap: 16px !important;
    }
}

/* Enhanced Badges and Status Indicators */
@media (max-width: 767px) {
    .badge,
    [class*="badge"],
    [class*="tag"],
    span[class*="rounded-full"] {
        font-size: 12px !important;
        padding: 6px 12px !important;
        border-radius: 12px !important;
        font-weight: 600;
        display: inline-flex;
        align-items: center;
        gap: 4px;
    }
}

/* Enhanced Dropdowns and Selects */
@media (max-width: 767px) {
    select {
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3E%3Cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3E%3C/svg%3E");
        background-position: right 12px center;
        background-repeat: no-repeat;
        background-size: 16px;
        padding-right: 40px !important;
        appearance: none;
        -webkit-appearance: none;
        -moz-appearance: none;
    }
}

/* Enhanced Input Groups */
@media (max-width: 767px) {
    .flex.items-center.space-x-2,
    .flex.items-center.space-x-3,
    .flex.items-center.space-x-4 {
        flex-wrap: wrap;
        gap: 12px;
    }
    
    .flex.items-center.space-x-2 > *,
    .flex.items-center.space-x-3 > *,
    .flex.items-center.space-x-4 > * {
        flex: 1 1 auto;
        min-width: 0;
    }
}

/* Enhanced Cards with Better Visual Hierarchy */
@media (max-width: 767px) {
    /* Assignment cards, course cards, etc. */
    [class*="rounded-xl"].bg-white,
    [class*="rounded-lg"].bg-white {
        box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08) !important;
        border: 1px solid #f3f4f6;
    }
    
    [class*="rounded-xl"].bg-white:hover,
    [class*="rounded-lg"].bg-white:hover {
        box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12) !important;
        transform: translateY(-2px);
        transition: all 0.2s ease;
    }
}

/* Enhanced Text Readability */
@media (max-width: 767px) {
    p,
    span,
    div {
        line-height: 1.6 !important;
    }
    
    .text-gray-600,
    .text-gray-500 {
        font-size: 14px !important;
    }
}

/* Enhanced Scroll Areas */
@media (max-width: 767px) {
    .overflow-y-auto,
    .overflow-auto {
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
        scrollbar-color: rgba(0, 0, 0, 0.2) transparent;
    }
    
    .overflow-y-auto::-webkit-scrollbar,
    .overflow-auto::-webkit-scrollbar {
        width: 4px;
        height: 4px;
    }
    
    .overflow-y-auto::-webkit-scrollbar-thumb,
    .overflow-auto::-webkit-scrollbar-thumb {
        background: rgba(0, 0, 0, 0.2);
        border-radius: 2px;
    }
}

/* Enhanced Loading and Empty States */
@media (max-width: 767px) {
    .loading,
    [class*="loading"],
    .spinner {
        padding: 32px !important;
    }
    
    .empty-state {
        padding: 48px 24px !important;
        text-align: center;
    }
    
    .empty-state i {
        font-size: 48px !important;
        margin-bottom: 16px;
        opacity: 0.3;
    }
}

/* Enhanced Action Buttons in Cards */
@media (max-width: 767px) {
    /* Button groups in cards */
    .flex.space-x-2,
    .flex.space-x-3 {
        flex-direction: column;
        gap: 12px;
    }
    
    .flex.space-x-2 > *,
    .flex.space-x-3 > * {
        width: 100%;
        margin: 0 !important;
    }
}

/* Enhanced Filter Sections */
@media (max-width: 767px) {
    /* Filter cards */
    .bg-white.rounded-xl.shadow-sm,
    .bg-gray-50.rounded-xl {
        padding: 20px !important;
        margin-bottom: 20px;
    }
    
    /* Filter buttons */
    .flex.flex-wrap.gap-2 button,
    .flex.flex-wrap.gap-3 button {
        flex: 1 1 auto;
        min-width: calc(50% - 6px);
    }
}

/* Enhanced Progress Bars */
@media (max-width: 767px) {
    .progress-bar,
    [class*="progress"],
    [class*="h-2"].bg-gray-200 {
        height: 8px !important;
        border-radius: 4px;
    }
    
    .progress-fill,
    [class*="progress"] > div {
        border-radius: 4px;
    }
}

/* Enhanced Icons in Mobile */
@media (max-width: 767px) {
    i.fas,
    i.far,
    i.fab {
        font-size: 18px;
    }
    
    /* Icon buttons */
    button i,
    a i {
        margin-right: 8px;
    }
}

/* Enhanced Safe Area for Notched Devices */
@supports (padding: max(0px)) {
    .mobile-header {
        padding-top: max(0px, env(safe-area-inset-top));
        padding-left: max(16px, env(safe-area-inset-left));
        padding-right: max(16px, env(safe-area-inset-right));
        height: calc(64px + env(safe-area-inset-top));
    }
    
    .main-content-mobile {
        padding-top: calc(80px + env(safe-area-inset-top)) !important;
        padding-left: max(16px, env(safe-area-inset-left)) !important;
        padding-right: max(16px, env(safe-area-inset-right)) !important;
        padding-bottom: max(32px, env(safe-area-inset-bottom)) !important;
    }
    
    .sidebar {
        top: calc(64px + env(safe-area-inset-top));
        padding-bottom: env(safe-area-inset-bottom);
    }
    
    .sidebar-overlay {
        top: calc(64px + env(safe-area-inset-top));
    }
}

/* Enhanced Focus States for Accessibility */
@media (max-width: 767px) {
    button:focus-visible,
    a:focus-visible,
    input:focus-visible,
    select:focus-visible,
    textarea:focus-visible {
        outline: 2px solid #667eea;
        outline-offset: 2px;
    }
}

/* Enhanced Animations */
@media (max-width: 767px) {
    @keyframes slideInRight {
        from {
            transform: translateX(100%);
            opacity: 0;
        }
        to {
            transform: translateX(0);
            opacity: 1;
        }
    }
    
    @keyframes slideInLeft {
        from {
            transform: translateX(-100%);
            opacity: 0;
        }
        to {
            transform: translateX(0);
            opacity: 1;
        }
    }
    
    @keyframes fadeInUp {
        from {
            transform: translateY(20px);
            opacity: 0;
        }
        to {
            transform: translateY(0);
            opacity: 1;
        }
    }
    
    .sidebar.open {
        animation: slideInLeft 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }
    
    .sidebar-overlay.active {
        animation: fadeIn 0.3s ease;
    }
    
    @keyframes fadeIn {
        from { opacity: 0; }
        to { opacity: 1; }
    }
}

/* ============================================
   LOADING INDICATOR STYLES
   ============================================ */

/* Full-page loading indicator - Above all content */
.page-loading-indicator {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    background: rgba(255, 255, 255, 0.98) !important;
    backdrop-filter: blur(8px);
    z-index: 999999 !important; /* Above everything including modals */
    display: flex !important;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease;
    width: 100vw !important;
    height: 100vh !important;
    margin: 0 !important;
    padding: 0 !important;
    pointer-events: all;
}

/* Inline loading indicator (for containers) */
.page-loading-indicator.page-loading-inline {
    position: relative;
    background: rgba(255, 255, 255, 0.9);
    min-height: 200px;
    border-radius: 12px;
}

.loading-content {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
}

.loading-spinner {
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.loading-spinner i {
    font-size: 48px;
    color: #667eea;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

.loading-text {
    font-size: 16px;
    font-weight: 500;
    color: #6b7280;
    margin: 0;
}

/* Mobile-specific loading styles */
@media (max-width: 767px) {
    .page-loading-indicator {
        top: 0; /* Cover entire screen including mobile header */
        height: 100vh;
    }
    
    .loading-spinner {
        width: 40px;
        height: 40px;
    }
    
    .loading-spinner i {
        font-size: 40px;
    }
    
    .loading-text {
        font-size: 14px;
    }
    
    .page-loading-indicator.page-loading-inline {
        min-height: 150px;
    }
}

/* Loading states for specific containers */
.grid.loading,
#assignmentsGrid.loading,
#coursesGrid.loading,
#examsGrid.loading {
    position: relative;
    min-height: 300px;
}

/* Skeleton loading (optional - for future enhancement) */
.skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading 1.5s ease-in-out infinite;
}

@keyframes loading {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

