/* Mobile Responsive CSS for Rehan School System */
/* AGGRESSIVE MOBILE FIXES - WORKS ON ALL DEVICES */

/* Mobile Menu Toggle Button - FORCE OVERRIDE student_dashboard.css */
button.mobile-menu-toggle,
.mobile-menu-toggle {
    position: fixed !important;
    top: 20px !important;
    left: 20px !important;
    z-index: 99999 !important;
    background: linear-gradient(135deg, #60a5fa 0%, #93c5fd 100%) !important;
    color: white !important;
    border: none !important;
    padding: 12px !important;
    border-radius: 8px !important;
    cursor: pointer !important;
    font-size: 18px !important;
    box-shadow: 0 4px 12px rgba(96, 165, 250, 0.4) !important;
    transition: all 0.3s ease !important;
    width: 48px !important;
    height: 48px !important;
    display: none !important;
    align-items: center !important;
    justify-content: center !important;
    opacity: 1 !important;
    visibility: visible !important;
    line-height: 1 !important;
}

.mobile-menu-toggle:hover {
    transform: translateY(-2px) !important;
    box-shadow: 0 6px 16px rgba(96, 165, 250, 0.5) !important;
}

.mobile-menu-toggle:active {
    transform: translateY(0) !important;
}

/* Base Mobile Styles - FORCE OVERRIDE */
@media screen and (max-width: 768px) {
    /* Show mobile menu button - FORCE DISPLAY */
    button.mobile-menu-toggle,
    .mobile-menu-toggle {
        display: flex !important;
        opacity: 1 !important;
        visibility: visible !important;
        pointer-events: auto !important;
        transform: none !important;
        left: 20px !important;
        top: 20px !important;
        z-index: 99999 !important;
    }
    
    /* Hide sidebar by default on mobile */
    .sidebar {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        width: 280px !important;
        height: 100vh !important;
        background: white !important;
        transform: translateX(-100%) !important;
        transition: transform 0.3s ease !important;
        z-index: 9998 !important;
        overflow-y: auto !important;
        box-shadow: 2px 0 10px rgba(0,0,0,0.1) !important;
    }
    
    /* Show sidebar when open */
    .sidebar.open {
        transform: translateX(0) !important;
    }
    
    /* Adjust main content */
    .content,
    .main-content,
    .dashboard-content {
        margin-left: 0 !important;
        padding: 80px 15px 20px 15px !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }
    
    /* Top bar adjustments */
    .top-bar,
    .header,
    .navbar {
        left: 0 !important;
        width: 100% !important;
        padding-left: 70px !important;
    }
    
    /* Cards and containers */
    .card,
    .dashboard-card,
    .stats-card {
        margin: 10px 0 !important;
        padding: 15px !important;
        border-radius: 8px !important;
    }
    
    /* Grid layouts become single column */
    .dashboard-grid,
    .stats-grid,
    .grid-container {
        display: block !important;
        grid-template-columns: 1fr !important;
    }
    
    .dashboard-grid > *,
    .stats-grid > *,
    .grid-container > * {
        margin-bottom: 15px !important;
    }
    
    /* Tables responsive */
    .table-container,
    .data-table-container {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        margin: 10px 0 !important;
    }
    
    table {
        min-width: 600px !important;
        font-size: 14px !important;
    }
    
    th, td {
        padding: 8px 6px !important;
        white-space: nowrap !important;
    }
    
    /* Forms */
    .form-container,
    form {
        padding: 15px !important;
    }
    
    .form-group {
        margin-bottom: 15px !important;
    }
    
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    input[type="date"],
    select,
    textarea {
        width: 100% !important;
        padding: 12px !important;
        font-size: 16px !important;
        border-radius: 6px !important;
        box-sizing: border-box !important;
    }
    
    /* Buttons */
    .btn,
    button,
    input[type="submit"],
    input[type="button"] {
        padding: 12px 20px !important;
        font-size: 16px !important;
        border-radius: 6px !important;
        min-height: 44px !important;
        margin: 5px 0 !important;
    }
    
    /* Modal adjustments */
    .modal-content {
        width: 95% !important;
        max-width: 500px !important;
        margin: 20px auto !important;
        padding: 0 !important;
    }
    
    /* Navigation adjustments */
    .sidebar-menu li a {
        padding: 15px 20px !important;
        font-size: 16px !important;
        display: flex !important;
        align-items: center !important;
    }
    
    .sidebar-menu li a i {
        margin-right: 12px !important;
        width: 20px !important;
    }
    
    /* Hide desktop-only elements */
    .desktop-only {
        display: none !important;
    }
    
    /* Show mobile-only elements */
    .mobile-only {
        display: block !important;
    }
    
    /* Text adjustments */
    h1 { font-size: 24px !important; }
    h2 { font-size: 20px !important; }
    h3 { font-size: 18px !important; }
    h4 { font-size: 16px !important; }
    
    /* Spacing adjustments */
    .section {
        margin: 20px 0 !important;
    }
    
    /* Dashboard specific */
    .dashboard-header {
        padding: 15px !important;
        margin-bottom: 20px !important;
    }
    
    .welcome-banner {
        padding: 20px 15px !important;
        margin: 10px 0 !important;
    }
    
    /* Statistics cards */
    .stats-container {
        display: block !important;
    }
    
    .stat-card {
        margin: 10px 0 !important;
        padding: 20px 15px !important;
    }
    
    /* Action buttons */
    .action-buttons {
        display: flex !important;
        flex-direction: column !important;
        gap: 10px !important;
    }
    
    .action-buttons .btn {
        width: 100% !important;
    }
}

/* Extra small devices (phones in portrait) */
@media screen and (max-width: 480px) {
    .content,
    .main-content,
    .dashboard-content {
        padding: 80px 10px 20px 10px !important;
    }
    
    /* FORCE mobile button on small screens */
    button.mobile-menu-toggle,
    .mobile-menu-toggle {
        display: flex !important;
        top: 10px !important;
        left: 10px !important;
        width: 45px !important;
        height: 45px !important;
        font-size: 16px !important;
        opacity: 1 !important;
        visibility: visible !important;
        z-index: 99999 !important;
    }
    
    .sidebar {
        width: 260px !important;
    }
    
    table {
        font-size: 12px !important;
    }
    
    th, td {
        padding: 6px 4px !important;
    }
    
    .modal-content {
        width: 98% !important;
        margin: 10px auto !important;
    }
}

/* Landscape phones and small tablets */
@media screen and (max-width: 768px) and (orientation: landscape) {
    .content,
    .main-content,
    .dashboard-content {
        padding: 70px 15px 15px 15px !important;
    }
    
    .mobile-menu-toggle {
        top: 10px !important;
    }
}

/* Ensure touch targets are at least 44px */
@media screen and (max-width: 768px) {
    a, button, input[type="submit"], input[type="button"], .btn {
        min-height: 44px !important;
        min-width: 44px !important;
    }
    
    /* FINAL OVERRIDE - Force button visibility */
    button.mobile-menu-toggle,
    .mobile-menu-toggle {
        display: flex !important;
        opacity: 1 !important;
        visibility: visible !important;
        z-index: 99999 !important;
    }
}

/* Fix any overflow issues */
@media screen and (max-width: 768px) {
    body {
        overflow-x: hidden !important;
    }
    
    * {
        box-sizing: border-box !important;
    }
}

/* ============================================
   TABLE TO CARD CONVERSION ON MOBILE
   ============================================ */
@media screen and (max-width: 768px) {
    /* Convert tables to card layout */
    .table-responsive,
    table {
        display: block !important;
        width: 100% !important;
    }
    
    thead {
        display: none !important;
    }
    
    tbody {
        display: block !important;
        width: 100% !important;
    }
    
    tr {
        display: block !important;
        margin-bottom: 15px !important;
        background: #fff !important;
        border: 1px solid #e2e8f0 !important;
        border-radius: 12px !important;
        padding: 15px !important;
        box-shadow: 0 2px 8px rgba(0,0,0,0.08) !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }
    
    td {
        display: block !important;
        width: 100% !important;
        padding: 10px 0 !important;
        text-align: left !important;
        border: none !important;
        white-space: normal !important;
        word-wrap: break-word !important;
        position: relative !important;
        padding-left: 40% !important;
    }
    
    td:before {
        content: attr(data-label) !important;
        position: absolute !important;
        left: 0 !important;
        width: 35% !important;
        font-weight: 600 !important;
        color: #475569 !important;
        font-size: 14px !important;
    }
    
    /* For tables without data-label attributes, use column headers */
    td:first-child:before { content: "Item" !important; }
    td:nth-child(2):before { content: "Details" !important; }
    td:nth-child(3):before { content: "Status" !important; }
    td:nth-child(4):before { content: "Date" !important; }
    td:nth-child(5):before { content: "Action" !important; }
}

/* ============================================
   EXTRA SMALL DEVICES (360px - 390px)
   ============================================ */
@media screen and (max-width: 390px) {
    body {
        font-size: 14px !important;
        overflow-x: hidden !important;
    }
    
    .content,
    .main-content,
    .dashboard-content,
    main {
        padding: 70px 10px 15px 10px !important;
        width: 100% !important;
        max-width: 100% !important;
    }
    
    /* Header adjustments */
    header {
        padding: 15px 10px !important;
    }
    
    header h1 {
        font-size: 20px !important;
        line-height: 1.3 !important;
    }
    
    header p {
        font-size: 14px !important;
    }
    
    /* Cards and containers */
    .card,
    .dashboard-card,
    .stats-card,
    .wrapper,
    main > section {
        padding: 15px !important;
        margin: 10px 0 !important;
        border-radius: 12px !important;
    }
    
    /* Stats grid - single column */
    .stats,
    .stats-bar,
    .stats-grid {
        display: block !important;
        width: 100% !important;
    }
    
    .stats-card,
    .stats-item {
        width: 100% !important;
        margin: 10px 0 !important;
        padding: 15px !important;
    }
    
    /* Grid layouts */
    .grid {
        grid-template-columns: 1fr !important;
        gap: 12px !important;
    }
    
    /* Buttons - full width on mobile */
    .actions,
    .action-buttons {
        flex-direction: column !important;
        gap: 10px !important;
    }
    
    .actions a,
    .actions button,
    .btn,
    button {
        width: 100% !important;
        padding: 14px 16px !important;
        font-size: 15px !important;
        min-height: 48px !important;
        box-sizing: border-box !important;
    }
    
    /* Search inputs */
    .search-wrap,
    .search-bar {
        width: 100% !important;
        margin-bottom: 15px !important;
    }
    
    .search-wrap input,
    .search-bar input {
        width: 100% !important;
        padding: 12px 40px 12px 12px !important;
        font-size: 16px !important;
        box-sizing: border-box !important;
    }
    
    /* Modals */
    .modal {
        padding: 10px !important;
    }
    
    .modal-content {
        width: 100% !important;
        max-width: 100% !important;
        margin: 10px 0 !important;
        padding: 20px 15px !important;
        border-radius: 12px !important;
    }
    
    /* Forms */
    .form-group input,
    .form-group select,
    .form-group textarea {
        width: 100% !important;
        padding: 12px !important;
        font-size: 16px !important;
        box-sizing: border-box !important;
    }
    
    /* Text sizes */
    h1 { font-size: 22px !important; }
    h2 { font-size: 20px !important; }
    h3 { font-size: 18px !important; }
    h4 { font-size: 16px !important; }
    p { font-size: 14px !important; }
    
    /* Table cards on extra small */
    tr {
        padding: 12px !important;
        margin-bottom: 12px !important;
    }
    
    td {
        padding: 8px 0 8px 35% !important;
        font-size: 13px !important;
    }
    
    td:before {
        font-size: 12px !important;
        width: 32% !important;
    }
}

/* ============================================
   MINIMUM WIDTH SUPPORT (360px)
   ============================================ */
@media screen and (max-width: 360px) {
    body {
        font-size: 13px !important;
    }
    
    .content,
    .main-content,
    .dashboard-content {
        padding: 65px 8px 12px 8px !important;
    }
    
    .card,
    .wrapper,
    main > section {
        padding: 12px !important;
        margin: 8px 0 !important;
    }
    
    header {
        padding: 12px 8px !important;
    }
    
    header h1 {
        font-size: 18px !important;
    }
    
    .actions a,
    .actions button,
    .btn {
        padding: 12px 14px !important;
        font-size: 14px !important;
    }
    
    .stats-card span,
    .stats-item span {
        font-size: 22px !important;
    }
    
    td {
        padding-left: 38% !important;
        font-size: 12px !important;
    }
    
    td:before {
        font-size: 11px !important;
        width: 35% !important;
    }
}

/* ============================================
   APK/WEBVIEW OPTIMIZATIONS
   ============================================ */
@media screen and (max-width: 768px) {
    /* Remove heavy animations for WebView compatibility */
    * {
        animation-duration: 0.2s !important;
        transition-duration: 0.2s !important;
    }
    
    /* Disable complex transforms that may break in WebView */
    .card:hover,
    .stats-card:hover {
        transform: none !important;
    }
    
    /* Standard fonts for better compatibility */
    body {
        font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif !important;
    }
    
    /* Ensure no fixed widths cause overflow */
    img {
        max-width: 100% !important;
        height: auto !important;
    }
    
    /* Prevent horizontal scroll */
    html, body {
        max-width: 100vw !important;
        overflow-x: hidden !important;
    }
    
    /* Container max-widths */
    .container,
    .wrapper,
    main {
        max-width: 100% !important;
        width: 100% !important;
    }
}