/* Responsive rules for mobile and tablet views */

/* ============================================
   TABLET VIEW (768px - 1024px)
   ============================================ */
@media (max-width: 1024px) {
    /* Sidebar adjustments for tablet */
    .sidebar {
        width: 220px;
    }
    
    .main-content {
        margin-left: 220px;
    }
    
    /* Grid adjustments */
    .stats-grid,
    .attendance-stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }
    
    /* Two column layouts become single column */
    .dashboard-content > div[style*="grid-template-columns: 1fr 1fr"] {
        grid-template-columns: 1fr !important;
    }
    
    /* Performance section */
    .performance-section {
        grid-template-columns: 1fr !important;
    }
    
    /* Form grids */
    .form-group[style*="grid-template-columns: 1fr 1fr"] {
        grid-template-columns: 1fr !important;
    }
    
    /* Table adjustments */
    .data-table {
        font-size: 0.9rem;
    }
    
    .data-table th,
    .data-table td {
        padding: 10px 8px;
    }
    
    /* Modal adjustments */
    .modal-content {
        max-width: 90%;
        margin: 20px;
    }
    
    /* Header adjustments */
    .header h2 {
        font-size: 1.5rem;
    }
    
    /* Action buttons wrap */
    .action-buttons {
        flex-wrap: wrap;
    }
}

/* ============================================
   MOBILE VIEW (max-width: 768px)
   ============================================ */
@media (max-width: 768px) {
    /* Sidebar - Hidden by default, shown as overlay on mobile */
    .sidebar {
        width: 280px !important;
        transform: translateX(-100%) !important;
        transition: transform 0.3s ease !important;
        z-index: 1001 !important;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1) !important;
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        height: 100vh !important;
        background: var(--secondary) !important;
        overflow-y: auto !important;
    }
    
    .sidebar.mobile-open {
        transform: translateX(0) !important;
    }
    
    /* Ensure sidebar is visible when open */
    .sidebar.mobile-open {
        visibility: visible !important;
        opacity: 1 !important;
    }
    
    /* Overlay for mobile menu */
    .sidebar-overlay {
        display: none !important;
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        width: 100% !important;
        height: 100% !important;
        background: rgba(0, 0, 0, 0.5) !important;
        z-index: 1000 !important;
        opacity: 0;
        transition: opacity 0.3s ease;
    }
    
    .sidebar-overlay.active {
        display: block !important;
        opacity: 1 !important;
    }
    
    /* Main content takes full width on mobile */
    .main-content {
        margin-left: 0;
        width: 100%;
    }
    
    /* Mobile menu toggle button */
    .mobile-menu-toggle {
        display: flex !important;
        align-items: center;
        justify-content: center;
        width: 40px;
        height: 40px;
        min-width: 40px;
        min-height: 40px;
        background: var(--primary) !important;
        color: white !important;
        border: none !important;
        border-radius: 8px;
        cursor: pointer !important;
        font-size: 1.2rem;
        margin-right: 15px;
        padding: 0 !important;
        transition: all 0.3s ease;
        z-index: 1002;
        position: relative;
    }
    
    .mobile-menu-toggle:hover {
        background: var(--primary-dark) !important;
        transform: scale(1.05);
    }
    
    .mobile-menu-toggle:active {
        transform: scale(0.95);
    }
    
    .mobile-menu-toggle.active {
        background: var(--primary-dark) !important;
    }
    
    .mobile-menu-toggle i {
        pointer-events: none;
        display: block;
    }
    
    /* Header adjustments */
    .header {
        padding: 12px 15px;
        flex-wrap: wrap;
        gap: 10px;
    }
    
    .header h2 {
        font-size: 1.25rem;
        flex: 1;
        min-width: 0;
    }
    
    .user-info {
        flex: 1;
        min-width: 0;
        justify-content: flex-end;
    }
    
    .user-info > div:last-child {
        display: none; /* Hide user name text on very small screens */
    }
    
    /* Dashboard content padding */
    .dashboard-content {
        padding: 15px;
    }
    
    /* Page title adjustments */
    .page-title {
        flex-direction: column;
        align-items: flex-start;
        gap: 15px;
        margin-bottom: 20px;
    }
    
    .page-title h1 {
        font-size: 1.5rem;
        width: 100%;
    }
    
    .action-buttons {
        width: 100%;
        flex-wrap: wrap;
        gap: 8px;
    }
    
    .action-buttons .btn {
        flex: 1;
        min-width: 120px;
        padding: 10px 12px;
        font-size: 0.875rem;
    }
    
    /* Stats grid - single column on mobile */
    .stats-grid,
    .attendance-stats-grid {
        grid-template-columns: 1fr !important;
        gap: 15px;
    }
    
    .stat-card {
        padding: 20px !important;
    }
    
    .stat-number-large {
        font-size: 28px !important;
    }
    
    /* Quick actions grid */
    div[style*="grid-template-columns: repeat(auto-fit, minmax(200px, 1fr))"] {
        grid-template-columns: 1fr !important;
    }
    
    /* Two column layouts become single column */
    .dashboard-content > div[style*="grid-template-columns: 1fr 1fr"],
    div[style*="grid-template-columns: 1fr 1fr"] {
        grid-template-columns: 1fr !important;
        gap: 20px !important;
    }
    
    /* Academic controls */
    .academic-controls {
        flex-direction: column;
        align-items: stretch;
        gap: 15px;
        padding: 15px;
        margin-bottom: 20px;
    }
    
    .control-group {
        width: 100%;
    }
    
    .control-group label {
        display: block;
        margin-bottom: 8px;
        font-size: 0.9rem;
    }
    
    .control-group select {
        width: 100%;
        padding: 10px;
        font-size: 0.9rem;
    }
    
    .current-info {
        width: 100%;
        flex-direction: column;
        gap: 8px;
        padding: 15px;
        border-left: none;
        border-top: 2px solid #4CAF50;
        padding-top: 15px;
        margin-top: 10px;
    }
    
    /* Tables - Horizontal scroll on mobile */
    .table-container {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
        margin: 0 -15px;
        padding: 0 15px;
        position: relative;
    }
    
    .table-container::after {
        content: '';
        position: absolute;
        top: 0;
        right: 0;
        bottom: 0;
        width: 20px;
        background: linear-gradient(to right, transparent, rgba(255,255,255,0.8));
        pointer-events: none;
        opacity: 0;
        transition: opacity 0.3s;
    }
    
    .table-container:not(:hover)::after {
        opacity: 1;
    }
    
    .data-table {
        min-width: 600px !important;
        font-size: 0.85rem;
        width: 100%;
    }
    
    .data-table th,
    .data-table td {
        padding: 10px 8px;
        white-space: nowrap;
    }
    
    /* Make action buttons in tables more touch-friendly */
    .data-table .action-btn {
        min-width: 36px;
        min-height: 36px;
        padding: 6px;
    }
    
    /* Table header adjustments */
    .table-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 15px;
    }
    
    .table-header h3 {
        font-size: 1.1rem;
        width: 100%;
    }
    
    .table-header .btn {
        width: 100%;
        justify-content: center;
    }
    
    /* Tabs - Scrollable on mobile */
    .tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        flex-wrap: nowrap;
        gap: 0;
        padding-bottom: 2px;
    }
    
    .tab {
        padding: 10px 16px;
        font-size: 0.875rem;
        white-space: nowrap;
        min-width: fit-content;
    }
    
    /* Forms */
    .form-group[style*="grid-template-columns: 1fr 1fr"],
    .form-group[style*="grid-template-columns: repeat(2, 1fr)"] {
        grid-template-columns: 1fr !important;
    }
    
    .form-group input,
    .form-group select,
    .form-group textarea {
        font-size: 16px; /* Prevents zoom on iOS */
        padding: 12px;
    }
    
    /* Modals - Full screen on mobile */
    .modal {
        padding: 0 !important;
        align-items: flex-start !important;
    }
    
    .modal-content {
        max-width: 100% !important;
        width: 100% !important;
        height: 100vh !important;
        max-height: 100vh !important;
        border-radius: 0 !important;
        margin: 0 !important;
        display: flex !important;
        flex-direction: column !important;
    }
    
    /* Override inline styles on modals */
    div[style*="max-width: 800px"],
    div[style*="max-width: 700px"],
    div[style*="max-width: 600px"] {
        max-width: 100% !important;
        width: 100% !important;
    }
    
    .modal-header {
        padding: 15px 20px;
        border-radius: 0;
    }
    
    .modal-title {
        font-size: 1.2rem;
    }
    
    .modal-body {
        padding: 20px;
        flex: 1;
        overflow-y: auto;
    }
    
    .modal-footer {
        padding: 15px 20px;
        border-radius: 0;
        flex-wrap: wrap;
    }
    
    .modal-footer .btn {
        flex: 1;
        min-width: 100px;
    }
    
    /* Cards and containers */
    .class-cards {
        grid-template-columns: 1fr !important;
    }
    
    .class-card {
        padding: 15px;
    }
    
    .class-stats {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }
    
    /* Performance section */
    .performance-section {
        grid-template-columns: 1fr !important;
        gap: 20px;
    }
    
    .chart-wrapper {
        height: 250px;
    }
    
    /* Attendance section */
    .attendance-stats {
        flex-direction: column;
        gap: 15px;
    }
    
    .attendance-stat {
        min-width: 100%;
    }
    
    /* User filters */
    .user-filters,
    .attendance-filters {
        flex-direction: column;
        gap: 10px;
    }
    
    .filter-group {
        width: 100%;
    }
    
    /* Timetable */
    .timetable {
        font-size: 0.75rem;
    }
    
    .timetable th,
    .timetable td {
        padding: 8px 4px;
    }
    
    .period {
        padding: 6px;
        font-size: 0.7rem;
    }
    
    /* Assignment cards */
    .assignments-section,
    .assignment-cards {
        grid-template-columns: 1fr !important;
    }
    
    /* Announcement cards */
    .announcement-card {
        padding: 15px;
    }
    
    .announcement-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    
    .announcement-actions {
        width: 100%;
        justify-content: flex-end;
    }
    
    /* Buttons - Better touch targets */
    .btn {
        min-height: 44px; /* iOS recommended touch target */
        padding: 10px 16px;
        font-size: 0.9rem;
    }
    
    /* Action buttons in tables */
    .action-btn {
        width: 36px;
        height: 36px;
        min-width: 36px;
        min-height: 36px;
    }
    
    /* Notification adjustments */
    .notification {
        left: 10px;
        right: 10px;
        max-width: calc(100% - 20px);
        padding: 12px 15px;
        font-size: 0.875rem;
    }
    
    /* Logo adjustments */
    .logo span {
        font-size: 1rem;
    }
    
    /* Navigation links - Better touch targets */
    .nav-link {
        padding: 15px;
        min-height: 48px;
    }
    
    /* System settings */
    .system-settings-section form > div[style*="grid-template-columns"] {
        grid-template-columns: 1fr !important;
    }
}

/* ============================================
   SMALL MOBILE VIEW (max-width: 480px)
   ============================================ */
@media (max-width: 480px) {
    /* Even more compact spacing */
    .dashboard-content {
        padding: 10px;
    }
    
    .header {
        padding: 10px;
    }
    
    .header h2 {
        font-size: 1.1rem;
    }
    
    .page-title h1 {
        font-size: 1.3rem;
    }
    
    /* Stats cards */
    .stat-card {
        padding: 15px !important;
    }
    
    .stat-number-large {
        font-size: 24px !important;
    }
    
    /* Smaller buttons */
    .btn {
        padding: 8px 12px;
        font-size: 0.85rem;
        min-height: 40px;
    }
    
    /* Table font size */
    .data-table {
        font-size: 0.8rem;
        min-width: 500px;
    }
    
    .data-table th,
    .data-table td {
        padding: 8px 6px;
    }
    
    /* Modal adjustments */
    .modal-header {
        padding: 12px 15px;
    }
    
    .modal-title {
        font-size: 1.1rem;
    }
    
    .modal-body {
        padding: 15px;
    }
    
    .modal-footer {
        padding: 12px 15px;
        flex-direction: column;
    }
    
    .modal-footer .btn {
        width: 100%;
        margin: 0;
    }
    
    /* User info - Hide on very small screens */
    .user-info > div:last-child {
        display: none;
    }
    
    .user-avatar {
        width: 36px;
        height: 36px;
        font-size: 0.9rem;
    }
    
    /* Chart wrapper */
    .chart-wrapper {
        height: 200px;
    }
    
    /* Academic controls */
    .academic-controls {
        padding: 12px;
    }
    
    .control-group label {
        font-size: 0.85rem;
    }
    
    .control-group select {
        padding: 8px;
        font-size: 0.85rem;
    }
}

/* ============================================
   LANDSCAPE MOBILE ORIENTATION
   ============================================ */
@media (max-width: 768px) and (orientation: landscape) {
    /* Sidebar adjustments for landscape */
    .sidebar {
        width: 240px;
    }
    
    /* Stats grid - 2 columns in landscape */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }
    
    /* Modal - Not full screen in landscape */
    .modal-content {
        height: auto;
        max-height: 90vh;
        border-radius: 16px;
        margin: 20px auto;
    }
}

/* ============================================
   PRINT STYLES
   ============================================ */
@media print {
    .sidebar,
    .header,
    .action-buttons,
    .mobile-menu-toggle,
    .sidebar-overlay {
        display: none !important;
    }
    
    .main-content {
        margin-left: 0;
        width: 100%;
    }
    
    .dashboard-content {
        padding: 0;
    }
    
    .page-title {
        page-break-after: avoid;
    }
    
    .stat-card,
    .table-container {
        page-break-inside: avoid;
    }
}

/* ============================================
   UTILITY CLASSES FOR RESPONSIVE DESIGN
   ============================================ */
.mobile-only {
    display: none;
}

.desktop-only {
    display: block;
}

@media (max-width: 768px) {
    .mobile-only {
        display: block;
    }
    
    .desktop-only {
        display: none;
    }
}

/* Smooth transitions for responsive changes */
* {
    transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

/* Prevent horizontal scroll */
body {
    overflow-x: hidden;
}

/* Ensure images are responsive */
img {
    max-width: 100%;
    height: auto;
}
