/* ============================================
   UNIVERSITY AI BATCH - ENHANCED MOBILE STYLES
   Comprehensive responsive improvements
   ============================================ */

/* ===== GLOBAL MOBILE IMPROVEMENTS ===== */
@media (max-width: 768px) {
    /* Base Font Size Adjustments */
    html {
        font-size: 15px;
    }
    
    /* Improve touch targets */
    .btn {
        min-height: 44px;
        padding: 0.75rem 1rem;
        font-size: 0.9rem;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 0.5rem;
        white-space: nowrap;
    }
    
    /* Buttons with icons */
    .btn i {
        margin-right: 0.375rem !important;
    }
    
    /* Container Padding */
    .container {
        padding-left: 1rem !important;
        padding-right: 1rem !important;
    }
    
    /* Page Titles */
    h1 {
        font-size: 1.75rem !important;
    }
    
    h2 {
        font-size: 1.5rem !important;
    }
    
    h3 {
        font-size: 1.25rem !important;
    }
    
    /* Flex Gap Fix */
    .d-flex.gap-2 {
        gap: 0.5rem !important;
    }
    
    .d-flex.gap-3 {
        gap: 0.75rem !important;
    }
}

/* ===== TELEGRAM BUTTON FIXES (Home Page & Footer) ===== */
@media (max-width: 768px) {
    /* Telegram Join Bot button in feature box */
    .feature-box .btn[href*="telegram"],
    .feature-box .btn[href*="t.me"] {
        width: 100%;
        padding: 0.75rem 1rem;
    }
    
    /* Footer Telegram button */
    footer .btn[href*="telegram"],
    footer .btn[href*="t.me"] {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        padding: 0.625rem 1rem;
        font-size: 0.85rem;
        white-space: nowrap;
    }
    
    /* Feature boxes on mobile */
    .feature-box {
        padding: 1.5rem;
        text-align: center;
    }
    
    .feature-box .btn {
        margin-top: 0.5rem;
    }
}

/* ===== LECTURE DOWNLOAD BUTTON FIXES ===== */
@media (max-width: 768px) {
    /* List group items in lectures */
    .list-group-item {
        padding: 1rem;
    }
    
    /* Lecture item layout */
    .list-group-item .d-flex.justify-content-between {
        flex-direction: column;
        gap: 0.75rem;
    }
    
    /* Download button - full width on mobile */
    .list-group-item .btn-success,
    .list-group-item .btn[href*="download"],
    a[href*="download_lecture"] {
        width: 100%;
        padding: 0.75rem 1rem;
        font-size: 0.875rem;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    /* Truncate long file names */
    .list-group-item .btn-success,
    a[href*="download_lecture"] {
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    
    /* Accordion lecture items */
    .accordion-body .list-group-item {
        padding: 1rem;
    }
    
    .accordion-body .d-flex.justify-content-end {
        justify-content: stretch !important;
        width: 100%;
    }
    
    .accordion-body .d-flex.justify-content-end .btn {
        width: 100%;
    }
    
    /* Subject detail - admin actions */
    .admin-actions {
        display: flex;
        flex-direction: column;
        gap: 0.75rem;
    }
    
    .admin-actions .btn {
        width: 100%;
    }
    
    .admin-actions form {
        width: 100%;
    }
    
    .admin-actions form .btn {
        width: 100%;
    }
}

/* ===== NAVBAR MOBILE IMPROVEMENTS ===== */
@media (max-width: 991px) {
    .modern-navbar {
        position: sticky;
        top: 0;
        z-index: 1050;
    }
    
    .navbar-container {
        padding: 0 1rem;
        height: 60px;
    }
    
    .navbar-actions {
        gap: 0.35rem;
    }
    
    /* Action Buttons */
    .action-btn {
        width: 40px;
        height: 40px;
        padding: 0 !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
    }
    
    .action-btn span {
        display: none;
    }
    
    .action-btn i {
        margin: 0 !important;
    }
    
    /* Theme Button */
    .theme-btn {
        width: 40px;
        height: 40px;
    }
    
    /* Login Button */
    .login-btn {
        width: 40px;
        height: 40px;
        padding: 0 !important;
        border-radius: var(--radius-md);
    }
    
    .login-btn span {
        display: none !important;
    }
    
    .login-btn i {
        margin: 0 !important;
    }
    
    /* Mobile Menu Toggle */
    .mobile-menu-toggle {
        width: 40px !important;
        height: 40px !important;
        font-size: 1.1rem;
    }
    
    /* Mobile Menu Overlay Improvements */
    .mobile-menu-overlay {
        display: flex !important;
        flex-direction: column;
        padding: 1.5rem;
        gap: 0.5rem;
        overflow-y: auto;
    }
    
    .mobile-menu-overlay.active {
        transform: translateX(0);
    }
    
    .mobile-menu-overlay .nav-link-modern {
        width: 100%;
        padding: 1rem 1.25rem;
        font-size: 1rem;
        border-radius: var(--radius-lg);
        background: var(--bg-secondary);
        border: 1px solid var(--border-color);
    }
    
    .mobile-menu-overlay .nav-link-modern:hover {
        transform: none;
        background: var(--primary);
        color: white;
        border-color: var(--primary);
    }
    
    .mobile-menu-overlay .nav-link-modern.active {
        background: var(--primary);
        color: white;
        border-color: var(--primary);
    }
    
    .mobile-menu-overlay .nav-link-modern.active::after {
        display: none;
    }
    
    /* User Dropdown Mobile */
    .user-dropdown {
        position: fixed;
        top: 60px;
        left: 1rem;
        right: 1rem;
        width: auto;
        max-height: calc(100vh - 70px);
        overflow-y: auto;
    }
    
    .dropdown-link {
        padding: 1rem 1.25rem;
    }
}

/* ===== BUTTON IMPROVEMENTS ===== */
@media (max-width: 768px) {
    /* Button Groups */
    .d-flex.justify-content-between.align-items-center {
        flex-direction: column;
        align-items: stretch !important;
        gap: 1rem;
    }
    
    .d-flex.gap-2.flex-wrap {
        width: 100%;
        flex-direction: column;
    }
    
    .d-flex.gap-2.flex-wrap > a,
    .d-flex.gap-2.flex-wrap > button {
        width: 100%;
        display: flex;
        justify-content: center;
    }
    
    /* Assignment Buttons */
    .btn.btn-primary,
    .btn.btn-success,
    .btn.btn-info,
    .btn.btn-warning,
    .btn.btn-danger {
        padding: 0.875rem 1.25rem;
        font-size: 0.9rem;
    }
    
    /* Small buttons in tables */
    .btn.btn-sm {
        width: 38px;
        height: 38px;
        padding: 0;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
}

/* ===== TABLE IMPROVEMENTS ===== */
@media (max-width: 768px) {
    /* Make tables scrollable */
    .table-responsive {
        margin: 0 -1rem;
        padding: 0 1rem;
        border: none;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .table {
        min-width: 600px;
        font-size: 0.875rem;
    }
    
    .table th,
    .table td {
        padding: 0.75rem 0.5rem;
        white-space: nowrap;
    }
    
    /* Badge in tables */
    .table .badge {
        font-size: 0.75rem;
        padding: 0.35rem 0.5rem;
    }
}

/* ===== CARD IMPROVEMENTS ===== */
@media (max-width: 768px) {
    .card {
        border-radius: var(--radius-lg);
        margin-bottom: 1rem;
    }
    
    .card-body {
        padding: 1rem;
    }
    
    .card-header {
        padding: 0.875rem 1rem;
    }
    
    /* Statistics Cards */
    .card.text-center h3 {
        font-size: 1.5rem;
    }
    
    .card.text-center small {
        font-size: 0.75rem;
    }
}

/* ===== FORM IMPROVEMENTS ===== */
@media (max-width: 768px) {
    .form-control,
    .form-select {
        font-size: 16px !important; /* Prevents iOS zoom */
        min-height: 48px;
        padding: 0.75rem 1rem;
    }
    
    .form-label {
        font-size: 0.9rem;
        margin-bottom: 0.5rem;
    }
    
    .input-group {
        flex-wrap: wrap;
    }
    
    .input-group .form-control {
        min-width: 0;
    }
    
    .input-group-text {
        padding: 0.75rem 1rem;
    }
    
    /* Row in forms */
    .row {
        margin-left: -0.5rem;
        margin-right: -0.5rem;
    }
    
    .row > [class*="col-"] {
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }
    
    /* Stack form columns on mobile */
    .row .col-md-6 {
        margin-bottom: 1rem;
    }
}

/* ===== TAB IMPROVEMENTS ===== */
@media (max-width: 768px) {
    .nav-tabs {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        white-space: nowrap;
        border-bottom: none;
        gap: 0.5rem;
        padding-bottom: 0.5rem;
        margin-bottom: 1rem !important;
    }
    
    .nav-tabs .nav-item {
        flex-shrink: 0;
    }
    
    .nav-tabs .nav-link {
        padding: 0.75rem 1rem;
        font-size: 0.85rem;
        border-radius: var(--radius-lg);
        border: 1px solid var(--border-color);
        background: var(--bg-secondary);
    }
    
    .nav-tabs .nav-link.active {
        background: var(--primary);
        color: white;
        border-color: var(--primary);
    }
    
    .nav-tabs .nav-link .badge {
        font-size: 0.7rem;
        padding: 0.25rem 0.5rem;
    }
    
    /* Hide icons in tabs on small screens */
    .nav-tabs .nav-link i {
        display: none;
    }
}

/* ===== STATISTICS ROW IMPROVEMENTS ===== */
@media (max-width: 768px) {
    .row.mb-4 .col-md-3,
    .row.mb-4 .col-lg-2,
    .row.mb-4 .col-lg-3 {
        flex: 0 0 50%;
        max-width: 50%;
    }
    
    .row.mb-4 .card.text-center .card-body {
        padding: 0.75rem;
    }
    
    .row.mb-4 .card.text-center h3 {
        font-size: 1.25rem;
        margin-bottom: 0.25rem;
    }
}

/* ===== ALERT IMPROVEMENTS ===== */
@media (max-width: 768px) {
    .alert {
        padding: 0.875rem 1rem;
        font-size: 0.9rem;
        border-radius: var(--radius-lg);
    }
    
    .alert i {
        font-size: 1rem;
    }
    
    .alert .btn-close {
        padding: 1rem;
    }
}

/* ===== MODAL IMPROVEMENTS ===== */
@media (max-width: 768px) {
    .modal-dialog {
        margin: 0.5rem;
        max-width: calc(100% - 1rem);
    }
    
    .modal-content {
        border-radius: var(--radius-xl);
    }
    
    .modal-header {
        padding: 1rem;
    }
    
    .modal-body {
        padding: 1rem;
    }
    
    .modal-footer {
        padding: 1rem;
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .modal-footer .btn {
        width: 100%;
        margin: 0;
    }
}

/* ===== FOOTER IMPROVEMENTS ===== */
@media (max-width: 768px) {
    footer {
        text-align: center;
        padding: 2rem 0 1rem;
    }
    
    footer .row > div {
        margin-bottom: 1.5rem;
    }
    
    footer h5 {
        font-size: 1.1rem;
        margin-bottom: 1rem;
    }
    
    footer p,
    footer li {
        font-size: 0.9rem;
    }
    
    footer ul {
        padding-left: 0;
    }
    
    footer .social-links {
        justify-content: center;
        display: flex;
        gap: 1rem;
    }
    
    footer .social-links a {
        font-size: 1.25rem;
    }
    
    .copyright {
        font-size: 0.8rem;
        padding: 1rem;
    }
}

/* ===== CHATBOT PAGE IMPROVEMENTS ===== */
@media (max-width: 768px) {
    .chat-container-modern {
        border-radius: 0;
        height: calc(100vh - 140px);
    }
    
    .chat-messages {
        padding: 1rem;
    }
    
    .message-text {
        padding: 0.875rem 1rem;
        font-size: 0.9rem;
        max-width: 90%;
    }
    
    .chat-input-container {
        padding: 1rem;
    }
    
    .chat-input {
        font-size: 16px !important;
        padding: 0.875rem 1rem;
    }
    
    .send-btn {
        width: 48px;
        height: 48px;
    }
    
    .welcome-section {
        padding: 1.5rem;
    }
    
    .welcome-section h2 {
        font-size: 1.25rem;
    }
    
    .example-prompts {
        gap: 0.75rem;
    }
    
    .example-prompt {
        padding: 0.875rem;
    }
}

/* ===== ASSIGNMENT PAGE IMPROVEMENTS ===== */
@media (max-width: 768px) {
    /* Assignment create buttons */
    .d-flex.gap-2:has(a[href*="create_assignment"]) {
        flex-direction: column;
        gap: 0.5rem !important;
    }
    
    .d-flex.gap-2:has(a[href*="create_assignment"]) > a {
        width: 100%;
        justify-content: center;
    }
    
    /* Assignment type badge */
    .type-badge {
        font-size: 0.8rem;
        padding: 0.4rem 0.75rem;
    }
}

/* ===== LECTURES PAGE IMPROVEMENTS ===== */
@media (max-width: 768px) {
    .lecture-week-item {
        margin-bottom: 1rem;
    }
    
    .lecture-week-header {
        padding: 1rem;
    }
    
    .week-toggle-btn {
        padding: 1rem;
    }
    
    .week-info {
        gap: 0.75rem;
    }
    
    .week-info i {
        width: 40px;
        height: 40px;
        font-size: 1rem;
    }
    
    .week-title {
        font-size: 1rem;
    }
    
    .lecture-week-body {
        padding: 1rem;
    }
    
    .lecture-item-modern {
        flex-direction: column;
        align-items: stretch;
        padding: 1rem;
        gap: 1rem;
    }
    
    .lecture-info {
        width: 100%;
    }
    
    .lecture-action {
        width: 100%;
    }
    
    .btn-download-modern {
        width: 100%;
        justify-content: center;
    }
}

/* ===== STUDENT DASHBOARD IMPROVEMENTS ===== */
@media (max-width: 768px) {
    .dashboard-card {
        margin-bottom: 1rem;
    }
    
    .profile-section {
        text-align: center;
        padding: 1.5rem 1rem;
    }
    
    .profile-avatar {
        margin: 0 auto 1rem;
    }
}

/* ===== ADMIN DASHBOARD IMPROVEMENTS ===== */
@media (max-width: 768px) {
    .admin-sidebar {
        position: fixed;
        left: -280px;
        top: 60px;
        height: calc(100vh - 60px);
        width: 280px;
        z-index: 1040;
        transition: left 0.3s ease;
        background: var(--bg-primary);
        border-right: 1px solid var(--border-color);
        overflow-y: auto;
    }
    
    .admin-sidebar.show {
        left: 0;
    }
    
    .admin-content {
        margin-left: 0;
        width: 100%;
    }
    
    .sidebar-toggle {
        display: block !important;
    }
}

/* ===== BACK TO TOP BUTTON ===== */
@media (max-width: 768px) {
    #backToTopBtn {
        width: 45px;
        height: 45px;
        bottom: 1rem;
        right: 1rem;
        font-size: 1rem;
    }
}

/* ===== PAGE HEADER IMPROVEMENTS ===== */
@media (max-width: 768px) {
    .d-flex.justify-content-between.align-items-center.mb-4 {
        flex-direction: column;
        align-items: stretch !important;
        text-align: center;
        gap: 1rem;
    }
    
    .d-flex.justify-content-between.align-items-center.mb-4 > div:first-child {
        margin-bottom: 0.5rem;
    }
    
    .d-flex.justify-content-between.align-items-center.mb-4 h1 {
        font-size: 1.5rem;
        margin-bottom: 0.5rem;
    }
    
    .d-flex.justify-content-between.align-items-center.mb-4 p {
        margin-bottom: 0;
    }
}

/* ===== EXTRA SMALL DEVICES ===== */
@media (max-width: 375px) {
    html {
        font-size: 14px;
    }
    
    .container {
        padding-left: 0.75rem !important;
        padding-right: 0.75rem !important;
    }
    
    .card-body {
        padding: 0.875rem;
    }
    
    .btn {
        padding: 0.625rem 1rem;
        font-size: 0.85rem;
    }
    
    h1 {
        font-size: 1.5rem !important;
    }
    
    h2 {
        font-size: 1.3rem !important;
    }
    
    /* Brand adjustments */
    .brand-text {
        display: none;
    }
    
    .navbar-container {
        height: 55px;
    }
}

/* ===== LANDSCAPE PHONE IMPROVEMENTS ===== */
@media (max-width: 768px) and (orientation: landscape) {
    .navbar-container {
        height: 55px;
    }
    
    .mobile-menu-overlay {
        top: 55px;
        height: calc(100vh - 55px);
    }
    
    .chat-container-modern {
        height: calc(100vh - 100px);
    }
}

/* ===== SAFE AREA SUPPORT (iPhone X+) ===== */
@supports (padding: env(safe-area-inset-bottom)) {
    @media (max-width: 768px) {
        .mobile-menu-overlay {
            padding-bottom: calc(1.5rem + env(safe-area-inset-bottom));
        }
        
        .chat-input-container {
            padding-bottom: calc(1rem + env(safe-area-inset-bottom));
        }
        
        footer {
            padding-bottom: calc(1rem + env(safe-area-inset-bottom));
        }
        
        #backToTopBtn {
            bottom: calc(1rem + env(safe-area-inset-bottom));
        }
    }
}

/* ===== TOUCH DEVICE IMPROVEMENTS ===== */
@media (hover: none) and (pointer: coarse) {
    /* Remove hover effects on touch devices */
    .nav-link-modern:hover,
    .card:hover,
    .btn:hover {
        transform: none;
    }
    
    /* Larger touch targets */
    .btn,
    .nav-link-modern,
    .action-btn {
        min-height: 44px;
    }
    
    /* Disable hover state highlighting */
    .table-hover tbody tr:hover {
        background: inherit !important;
    }
}

/* ===== PRINT HIDING FOR NAVIGATION ===== */
@media print {
    .modern-navbar,
    .mobile-menu-overlay,
    #backToTopBtn,
    footer {
        display: none !important;
    }
}
