/**
 * Mobile Responsive Styles
 * Include this file in all pages for consistent mobile experience
 */

/* Missing Scores Page Mobile Styles */
@media (max-width: 768px) {
    .student-tag {
        display: inline-block !important;
        margin: 2px 4px 2px 0 !important;
        font-size: 11px !important;
        padding: 3px 6px !important;
        white-space: nowrap !important;
    }
    .missing-scores-container .card {
        margin-bottom: 10px !important;
    }
    .missing-scores-container .card-header {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 5px !important;
    }
    .missing-scores-container .badge {
        align-self: flex-start !important;
    }
    .summary-card {
        margin-bottom: 10px !important;
    }
    .missing-scores-container .col-md-4 {
        width: 100% !important;
        flex: 0 0 100% !important;
        max-width: 100% !important;
    }
}

/* End of Missing Scores Styles */

/* Ensure viewport allows zoom and proper scaling on all devices */
html {
    -webkit-text-size-adjust: 100%;
}

/* Base Mobile Styles */
@media (max-width: 768px) {
    /* Reset all container/content margins that assume sidebar width */
    .main-content,
    .container,
    .container-fluid,
    main,
    main.col-md-9,
    main[class*="col-"] {
        margin-left: 0 !important;
        padding: 15px 12px !important;
        max-width: 100% !important;
        width: 100% !important;
    }
    
    /* Space for fixed mobile menu button - when present */
    body:has(.mobile-menu-toggle) .main-content,
    body:has(.mobile-menu-toggle) .container,
    body:has(.mobile-menu-toggle) .container-fluid,
    body:has(.mobile-menu-toggle) main {
        padding-top: 55px !important;
    }
    
    .main-wrapper {
        flex-direction: column;
    }
    
    /* Prevent horizontal overflow - common cause of "desktop mode" on mobile */
    body, html {
        overflow-x: hidden !important;
    }
    
    /* Override inline margin-left on main content areas */
    [style*="margin-left: 220px"],
    [style*="margin-left: 260px"],
    [style*="margin-left: 200px"] {
        margin-left: 0 !important;
    }
    
    /* Mobile menu toggle */
    .mobile-menu-toggle {
        display: block !important;
        position: fixed;
        top: 15px;
        left: 15px;
        z-index: 1001;
        background: #2c3e50;
        color: white;
        border: none;
        padding: 12px 16px;
        border-radius: 6px;
        cursor: pointer;
        font-size: 20px;
        box-shadow: 0 2px 8px rgba(0,0,0,0.3);
    }
    
    /* Sidebar adjustments */
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        width: 280px;
        z-index: 1000;
    }
    
    .sidebar.open {
        transform: translateX(0);
    }
    
    /* Overlay when sidebar is open */
    .sidebar-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0,0,0,0.5);
        z-index: 999;
        display: none;
    }
    
    .sidebar.open ~ .sidebar-overlay {
        display: block;
    }
    
    /* Header adjustments */
    .header {
        padding: 20px 15px !important;
        margin-bottom: 15px !important;
    }
    
    .header h1 {
        font-size: 24px !important;
    }
    
    /* Stats grid - stack on mobile */
    .stats-grid {
        grid-template-columns: 1fr !important;
        gap: 12px !important;
    }
    
    .stat-card {
        padding: 18px !important;
    }
    
    .stat-value {
        font-size: 24px !important;
    }
    
    /* Quick actions - stack */
    .action-buttons {
        grid-template-columns: 1fr !important;
        gap: 10px !important;
    }
    
    .action-btn {
        padding: 12px 16px !important;
        font-size: 13px !important;
    }
    
    /* Charts row - stack */
    .charts-row {
        grid-template-columns: 1fr !important;
    }
    
    .chart-card {
        margin-bottom: 15px;
    }
    
    /* Details row - stack */
    .details-row {
        grid-template-columns: 1fr !important;
    }
    
    /* Tables - make scrollable with visible scrollbar */
    .table-responsive {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
        display: block;
        width: 100%;
        max-width: 100vw;
    }
    
    /* Scrollbar hint on mobile */
    .table-responsive::-webkit-scrollbar {
        height: 8px;
    }
    .table-responsive::-webkit-scrollbar-thumb {
        background: #bdc3c7;
        border-radius: 4px;
    }
    
    table {
        min-width: 500px;
        font-size: 12px;
    }
    
    table th,
    table td {
        padding: 8px 6px !important;
        font-size: 12px;
    }
    
    /* Compact tables */
    .compact-table {
        font-size: 11px;
    }
    
    .compact-table th,
    .compact-table td {
        padding: 8px 4px !important;
    }
    
    /* Cards */
    .card {
        margin-bottom: 15px;
    }
    
    .card-body {
        padding: 15px !important;
    }
    
    .card-header {
        padding: 12px 15px !important;
    }
    
    /* Forms */
    .form-group {
        margin-bottom: 15px;
    }
    
    input[type="text"],
    input[type="number"],
    input[type="email"],
    input[type="password"],
    input[type="date"],
    select,
    textarea {
        width: 100%;
        padding: 12px !important;
        font-size: 16px !important; /* Prevents zoom on iOS */
        border-radius: 6px;
    }
    
    /* Toolbar - stack on mobile */
    .toolbar {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 10px !important;
    }
    
    .toolbar input,
    .toolbar select,
    .toolbar .form-control,
    .toolbar .form-select {
        max-width: 100% !important;
        width: 100% !important;
    }
    
    /* Form rows - stack */
    .form-row,
    .form-row-3,
    .grid-2,
    .grid-3 {
        grid-template-columns: 1fr !important;
    }
    
    /* Buttons */
    .btn {
        padding: 12px 20px !important;
        font-size: 14px !important;
        margin-bottom: 10px;
    }
    
    /* Full width for standalone buttons, auto for table actions */
    .toolbar .btn,
    .form-actions .btn,
    .modal-footer .btn,
    .card .btn:not(.btn-sm) {
        width: 100% !important;
    }
    
    /* Table action buttons - keep compact */
    table .btn,
    table .btn-sm,
    .btn-sm {
        width: auto !important;
        padding: 8px 12px !important;
        font-size: 12px !important;
        margin-bottom: 0 !important;
    }
    
    /* Button groups */
    .btn-group {
        display: flex;
        flex-direction: column;
        width: 100%;
    }
    
    .btn-group .btn {
        margin-bottom: 8px;
        border-radius: 6px !important;
    }
    
    /* Modals */
    .modal-content {
        width: 95% !important;
        margin: 10px auto !important;
        padding: 15px !important;
    }
    
    /* Student cards in skills rating */
    .student-card {
        margin-bottom: 12px;
    }
    
    .student-card-header {
        padding: 10px 12px !important;
        font-size: 14px;
    }
    
    .skills-grid {
        grid-template-columns: 1fr !important;
    }
    
    /* Summary grid - stack */
    .summary-grid {
        grid-template-columns: 1fr 1fr !important;
        gap: 10px !important;
    }
    
    .summary-box {
        padding: 12px !important;
    }
    
    .summary-box .value {
        font-size: 20px !important;
    }
    
    /* Invoice type grid */
    .invoice-type-grid {
        grid-template-columns: 1fr !important;
    }
    
    /* Activity list */
    .activity-item {
        padding: 12px !important;
    }
    
    /* Filters */
    .filters form {
        grid-template-columns: 1fr !important;
    }
    
    /* Tabs - wrap on mobile */
    .tabs {
        flex-wrap: wrap !important;
        gap: 8px !important;
    }
    .tabs .tab {
        flex: 1 1 auto;
        min-width: 100px;
    }
    
    /* Pagination */
    .pagination {
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
        gap: 5px;
    }
    
    .pagination a {
        padding: 8px 12px;
        font-size: 13px;
    }
    
    /* Print bar */
    .print-bar {
        padding: 15px !important;
    }
    
    .print-bar button,
    .print-bar a {
        width: 100%;
        margin-bottom: 10px;
    }
    
    /* Report card - fit to viewport, allow zoom/scroll */
    .report-card,
    .rc,
    .rc-container {
        padding: 10px 5px !important;
        width: 100% !important;
        max-width: 100vw !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Report card tables - ensure horizontal scroll */
    .report-card table,
    .rc table,
    .rc-container table,
    .rc-results {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Report card student info */
    .report-card .rc-student-info,
    .rc-student-info {
        font-size: 8pt !important;
    }
    
    /* Report card summary boxes - stack on mobile */
    .report-card .rc-summary,
    .rc-summary {
        flex-wrap: wrap;
        gap: 5px !important;
    }
    
    .report-card .rc-summary-box,
    .rc-summary-box {
        min-width: 45% !important;
        padding: 3px !important;
    }
    
    /* Score sheet - horizontal scroll */
    .score-sheet,
    .scores-table,
    .print-score-sheet {
        overflow-x: auto !important;
        max-width: 100% !important;
    }
    
    /* Skills rating buttons */
    .rating-btn {
        width: 28px !important;
        height: 28px !important;
        font-size: 10px !important;
    }
    
    /* Hide less important elements on mobile */
    .d-none-mobile {
        display: none !important;
    }
    
    /* Text adjustments */
    h1 { font-size: 24px !important; }
    h2 { font-size: 20px !important; }
    h3 { font-size: 18px !important; }
    h4 { font-size: 16px !important; }
    h5 { font-size: 14px !important; }
    
    /* Spacing adjustments */
    .mb-4 { margin-bottom: 15px !important; }
    .mb-3 { margin-bottom: 12px !important; }
    .mt-4 { margin-top: 15px !important; }
    .mt-3 { margin-top: 12px !important; }
    .py-4 { padding-top: 15px !important; padding-bottom: 15px !important; }
    .px-4 { padding-left: 15px !important; padding-right: 15px !important; }
}

/* Tablet styles (768px - 1024px) */
@media (min-width: 769px) and (max-width: 1024px) {
    .main-content {
        margin-left: 220px;
        padding: 20px;
    }
    
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .charts-row {
        grid-template-columns: 1fr;
    }
    
    .action-buttons {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Very small screens (below 480px) */
@media (max-width: 480px) {
    .header {
        padding: 15px 10px !important;
    }
    
    .header h1 {
        font-size: 20px !important;
    }
    
    .stat-value {
        font-size: 20px !important;
    }
    
    table {
        min-width: 500px;
        font-size: 11px;
    }
    
    .summary-grid {
        grid-template-columns: 1fr !important;
    }
    
    .card-body {
        padding: 12px !important;
    }
}

/* Touch-friendly improvements */
@media (hover: none) and (pointer: coarse) {
    /* Larger touch targets */
    a, button, .btn {
        min-height: 44px;
        min-width: 44px;
    }
    
    /* Remove hover effects on touch devices */
    .sidebar-nav a:hover {
        background: transparent;
    }
    
    /* Better focus states */
    input:focus,
    select:focus,
    textarea:focus,
    button:focus {
        outline: 3px solid #3498db;
        outline-offset: 2px;
    }
}
