/* =========================================================
   COMPREHENSIVE RESPONSIVE DESIGN FIXES
   This file ensures the system works perfectly on all devices
   ========================================================= */

/* ===== BASE RESPONSIVE FIXES ===== */

/* Ensure all containers respect viewport */
* {
    max-width: 100%;
}

img, video, iframe {
    max-width: 100%;
    height: auto;
}

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

/* ===== TABLET (768px - 1024px) ===== */
@media (max-width: 1024px) {
    /* Dashboard container */
    .dashboard-container {
        flex-direction: column;
    }
    
    /* Stats grid - 2 columns on tablet */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 15px;
    }
    
    /* Charts grid */
    .charts-grid-2 {
        grid-template-columns: 1fr;
    }
    
    .charts-grid-4 {
        grid-template-columns: repeat(2, 1fr);
    }
    
    /* Form rows - stack on tablet */
    .form-row {
        flex-direction: column;
        gap: 15px;
    }
    
    .form-row .form-group {
        width: 100%;
    }
    
    /* Card headers */
    .card-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }
    
    .card-header .card-title {
        font-size: 18px;
    }
    
    /* Tables - enable horizontal scroll */
    .table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .table {
        min-width: 600px;
    }
    
    /* Action buttons in tables */
    .action-buttons {
        flex-wrap: wrap;
        gap: 5px;
    }
    
    .btn-icon {
        width: 32px;
        height: 32px;
        font-size: 12px;
    }
}

/* ===== MOBILE (up to 768px) ===== */
@media (max-width: 768px) {
    /* Sidebar - already handled in other files, but ensure consistency */
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        transform: translateX(-100%);
        width: 280px !important;
        z-index: 2000;
        transition: transform 0.3s ease;
    }
    
    .sidebar.mobile-open {
        transform: translateX(0);
    }
    
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.5);
        z-index: 1999;
    }
    
    .sidebar-overlay.active {
        display: block;
    }
    
    .main-content {
        margin-left: 0 !important;
        width: 100% !important;
    }
    
    /* Top header */
    .top-header {
        padding: 12px 15px;
        flex-wrap: wrap;
        gap: 10px;
    }
    
    .header-left {
        flex: 1;
        min-width: 0;
    }
    
    .header-right {
        flex-wrap: wrap;
        gap: 8px;
    }
    
    .page-title {
        font-size: 18px;
        margin: 5px 0;
    }
    
    .breadcrumb {
        font-size: 11px;
    }
    
    .user-menu {
        flex-direction: column;
        align-items: flex-end;
        gap: 5px;
    }
    
    .user-name {
        font-size: 13px;
    }
    
    .user-role {
        font-size: 10px;
        padding: 3px 8px;
    }
    
    .logout-btn {
        font-size: 12px;
        padding: 6px 12px;
    }
    
    /* Content wrapper */
    .content-wrapper {
        padding: 15px;
    }
    
    /* Stats grid - single column */
    .stats-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }
    
    .stat-card {
        padding: 15px;
    }
    
    .stat-card-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }
    
    .stat-content {
        width: 100%;
        min-width: 0;
    }
    
    .stat-icon-wrapper {
        flex-direction: row;
        align-items: center;
        width: 100%;
        justify-content: space-between;
    }
    
    .stat-value {
        font-size: 28px;
    }
    
    .stat-label {
        font-size: 12px;
    }
    
    .stat-icon {
        width: 45px;
        height: 45px;
        font-size: 20px;
    }
    
    .btn-edit-stat {
        width: 36px;
        height: 36px;
    }
    
    /* Charts - full width */
    .charts-grid-2,
    .charts-grid-4 {
        grid-template-columns: 1fr !important;
    }
    
    /* Cards */
    .card {
        padding: 15px;
        margin-bottom: 15px;
        border-radius: 10px;
    }
    
    .card-header {
        margin: -15px -15px 15px -15px;
        padding: 12px 15px;
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    
    .card-title {
        font-size: 16px;
    }
    
    .card-body {
        padding: 0;
    }
    
    /* Forms */
    .styled-form,
    .modern-form {
        padding: 15px;
    }
    
    .form-section {
        margin-bottom: 20px;
        padding: 15px;
    }
    
    .form-section-title {
        font-size: 15px;
        margin: 0 0 15px 0;
    }
    
    .form-row {
        flex-direction: column;
        gap: 15px;
    }
    
    .form-group {
        width: 100%;
        margin-bottom: 15px;
    }
    
    .form-group label {
        font-size: 13px;
        margin-bottom: 6px;
    }
    
    .form-group input,
    .form-group select,
    .form-group textarea {
        padding: 10px 12px;
        font-size: 14px;
        width: 100%;
    }
    
    /* Tables - horizontal scroll */
    .table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 0 -15px;
        padding: 0 15px;
    }
    
    .table {
        min-width: 100%;
        font-size: 13px;
    }
    
    .table th,
    .table td {
        padding: 10px 8px;
        white-space: nowrap;
        font-size: 12px;
    }
    
    .table th {
        font-size: 11px;
        font-weight: 600;
    }
    
    /* Action buttons in tables */
    .action-buttons {
        flex-direction: column;
        gap: 5px;
    }
    
    .action-buttons .btn {
        width: 100%;
        justify-content: center;
    }
    
    /* Buttons */
    .btn {
        padding: 10px 16px;
        font-size: 13px;
        width: auto;
    }
    
    .btn-block {
        width: 100%;
    }
    
    .btn-icon {
        width: 36px;
        height: 36px;
        font-size: 14px;
    }
    
    .btn-group {
        flex-direction: column;
        width: 100%;
    }
    
    .btn-group .btn {
        width: 100%;
        border-radius: 6px;
        margin: 0;
    }
    
    /* Badges */
    .badge {
        font-size: 11px;
        padding: 4px 8px;
    }
    
    /* Filter forms */
    .filter-form,
    .table-filters {
        flex-direction: column;
        gap: 12px;
    }
    
    .table-filters .form-group {
        width: 100%;
    }
    
    /* Bulk actions */
    .bulk-actions-bar {
        flex-direction: column;
        gap: 12px;
        padding: 12px;
    }
    
    .bulk-actions {
        flex-wrap: wrap;
        width: 100%;
        gap: 8px;
    }
    
    .bulk-action-btn {
        flex: 1;
        min-width: 120px;
        padding: 8px 12px;
        font-size: 12px;
    }
    
    /* Student/Teacher cards grid */
    .students-grid,
    .teachers-grid {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    .student-card,
    .teacher-card {
        margin-bottom: 0;
    }
    
    /* Modals */
    .modal {
        padding: 15px;
    }
    
    .modal-content {
        width: 95%;
        max-width: 100%;
        margin: 10px auto;
        padding: 20px 15px;
    }
    
    .modal-header {
        padding: 15px;
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    
    .modal-title {
        font-size: 18px;
    }
    
    .modal-body {
        padding: 15px;
    }
    
    .modal-footer {
        padding: 15px;
        flex-direction: column;
        gap: 10px;
    }
    
    .modal-footer .btn {
        width: 100%;
    }
    
    /* Attendance checkboxes */
    .attendance-checkboxes {
        flex-direction: column;
        gap: 8px;
        align-items: stretch;
    }
    
    .status-checkbox {
        width: 100%;
        justify-content: space-between;
        padding: 12px;
    }
    
    /* Attendance footer */
    .attendance-footer {
        flex-direction: column;
        gap: 15px;
        align-items: stretch;
        padding: 15px;
    }
    
    .status-legend {
        justify-content: center;
        flex-wrap: wrap;
    }
    
    .save-btn {
        width: 100%;
    }
    
    /* Search and filter bars */
    .search-bar,
    .filter-bar {
        flex-direction: column;
        gap: 10px;
    }
    
    .search-bar input,
    .filter-bar select {
        width: 100%;
    }
    
    /* Pagination */
    .pagination {
        flex-wrap: wrap;
        justify-content: center;
        gap: 5px;
    }
    
    .pagination .btn {
        min-width: 36px;
        padding: 8px 12px;
    }
    
    /* View toggles */
    .view-toggle {
        flex-wrap: wrap;
        gap: 8px;
    }
    
    .view-toggle-btn {
        flex: 1;
        min-width: 80px;
    }
    
    /* Login page */
    .login-box {
        padding: 30px 20px;
        margin: 20px;
    }
    
    .login-header h1 {
        font-size: 20px;
    }
    
    /* Public results page */
    .public-container {
        padding: 15px;
    }
    
    .search-box {
        padding: 20px;
    }
    
    .result-card {
        margin-bottom: 20px;
    }
    
    .result-summary {
        flex-direction: column;
        gap: 15px;
    }
    
    .summary-item {
        width: 100%;
    }
    
    .student-meta-grid {
        grid-template-columns: 1fr;
    }
}

/* ===== VERY SMALL MOBILE (up to 480px) ===== */
@media (max-width: 480px) {
    /* Top header */
    .top-header {
        padding: 10px 12px;
    }
    
    .page-title {
        font-size: 16px;
    }
    
    .breadcrumb {
        font-size: 10px;
    }
    
    /* Content wrapper */
    .content-wrapper {
        padding: 12px;
    }
    
    /* Cards */
    .card {
        padding: 12px;
    }
    
    .card-header {
        margin: -12px -12px 12px -12px;
        padding: 10px 12px;
    }
    
    .card-title {
        font-size: 15px;
    }
    
    /* Stats */
    .stat-card-header {
        gap: 10px;
    }
    
    .stat-content {
        width: 100%;
    }
    
    .stat-value {
        font-size: 24px;
    }
    
    .stat-label {
        font-size: 11px;
    }
    
    .stat-icon {
        width: 40px;
        height: 40px;
        font-size: 18px;
    }
    
    .btn-edit-stat {
        width: 32px;
        height: 32px;
        font-size: 11px;
    }
    
    /* Forms */
    .form-group input,
    .form-group select,
    .form-group textarea {
        padding: 8px 10px;
        font-size: 13px;
    }
    
    /* Tables */
    .table {
        font-size: 12px;
    }
    
    .table th,
    .table td {
        padding: 8px 6px;
        font-size: 11px;
    }
    
    /* Buttons */
    .btn {
        padding: 8px 14px;
        font-size: 12px;
    }
    
    .btn-icon {
        width: 32px;
        height: 32px;
        font-size: 12px;
    }
    
    /* Badges */
    .badge {
        font-size: 10px;
        padding: 3px 6px;
    }
    
    /* Modals */
    .modal-content {
        width: 98%;
        padding: 15px 12px;
    }
    
    .modal-title {
        font-size: 16px;
    }
    
    /* Login */
    .login-box {
        padding: 25px 15px;
    }
    
    .login-header .logo {
        width: 100px;
        height: 100px;
    }
    
    .login-header h1 {
        font-size: 18px;
    }
}

/* ===== LANDSCAPE ORIENTATION FIXES ===== */
@media (max-width: 768px) and (orientation: landscape) {
    .top-header {
        padding: 8px 15px;
    }
    
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .charts-grid-4 {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ===== PRINT STYLES ===== */
@media print {
    .sidebar,
    .top-header,
    .sidebar-toggle,
    .btn,
    .action-buttons,
    .bulk-actions-bar,
    .filter-form,
    .pagination {
        display: none !important;
    }
    
    .main-content {
        margin-left: 0 !important;
        width: 100% !important;
    }
    
    .card {
        page-break-inside: avoid;
    }
    
    .table {
        font-size: 10px;
    }
}

/* ===== UTILITY CLASSES FOR RESPONSIVE ===== */
.mobile-hidden {
    display: block;
}

.mobile-visible {
    display: none;
}

@media (max-width: 768px) {
    .mobile-hidden {
        display: none !important;
    }
    
    .mobile-visible {
        display: block !important;
    }
}

.tablet-hidden {
    display: block;
}

@media (max-width: 1024px) {
    .tablet-hidden {
        display: none !important;
    }
}

/* ===== FIX FOR SPECIFIC COMPONENTS ===== */

/* Fix for fee collection modal */
@media (max-width: 768px) {
    .payment-modal .modal-content {
        width: 95%;
        max-height: 90vh;
        overflow-y: auto;
    }
    
    .payment-form .form-row {
        flex-direction: column;
    }
}

/* Fix for exam results tables */
@media (max-width: 768px) {
    .exam-results-table {
        font-size: 12px;
    }
    
    .exam-results-table th,
    .exam-results-table td {
        padding: 8px 4px;
    }
}

/* Fix for attendance tables */
@media (max-width: 768px) {
    .attendance-table {
        font-size: 11px;
    }
    
    .attendance-table th,
    .attendance-table td {
        padding: 6px 4px;
    }
    
    .attendance-checkbox {
        width: 20px;
        height: 20px;
    }
}

/* Fix for student/teacher profile cards */
@media (max-width: 768px) {
    .profile-card {
        flex-direction: column;
    }
    
    .profile-avatar {
        width: 100px;
        height: 100px;
        margin: 0 auto 15px;
    }
}

/* Fix for dashboard charts */
@media (max-width: 768px) {
    .chart-container {
        height: 250px !important;
    }
}

/* Fix for action dropdowns */
@media (max-width: 768px) {
    .dropdown-menu {
        position: static !important;
        transform: none !important;
        width: 100%;
        margin-top: 5px;
    }
}

/* Fix for tooltips on mobile */
@media (max-width: 768px) {
    [data-tooltip]:hover::after {
        display: none;
    }
}

/* Fix for fixed headers/footers */
@media (max-width: 768px) {
    .fixed-header,
    .fixed-footer {
        position: relative;
    }
}

/* Ensure touch-friendly targets */
@media (max-width: 768px) {
    .btn,
    .nav-item,
    a,
    button,
    input[type="checkbox"],
    input[type="radio"] {
        min-height: 44px;
        min-width: 44px;
    }
}
