/* ============================================
   GLOBAL RESPONSIVE DESIGN
   المستشار Control Panel - All Screen Sizes
   ============================================ */

/* ============================================
   BREAKPOINT: ≤1200px (Small Laptops / Large Tablets Landscape)
   ============================================ */
@media (max-width: 1200px) {
    .main-content {
        max-width: 100%;
        padding: 20px 25px;
    }

    /* Hero sections - shared pattern across all pages */
    [class*="-hero"],
    .subscription-hero,
    .dashboard-hero {
        padding: 2.5rem 2rem !important;
        border-radius: 1.25rem !important;
    }

    [class*="-hero"] h1,
    .subscription-hero h1,
    .dashboard-hero h1 {
        font-size: 2.25rem !important;
    }

    /* Tables */
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Filter forms - ensure they don't overflow */
    .row.g-4 {
        --bs-gutter-x: 1rem;
    }

    /* Subject cards grid */
    #subjectsList {
        grid-template-columns: repeat(auto-fill, minmax(350px, 1fr)) !important;
    }
}

/* ============================================
   BREAKPOINT: ≤992px (Tablets Portrait)
   Sidebar already collapses at this breakpoint
   ============================================ */
@media (max-width: 992px) {

    /* Main content takes full width when sidebar collapses */
    .main-content {
        margin-right: 0;
        padding: 15px 20px;
        max-width: 100%;
    }

    /* Hero sections */
    [class*="-hero"],
    .subscription-hero,
    .dashboard-hero {
        padding: 2rem 1.5rem !important;
        margin-bottom: 1.5rem !important;
    }

    [class*="-hero"] h1,
    .subscription-hero h1,
    .dashboard-hero h1 {
        font-size: 2rem !important;
    }

    [class*="-hero"] p,
    .subscription-hero p,
    .dashboard-hero p {
        font-size: 1rem !important;
    }

    /* Hide decorative pseudo-elements on smaller screens for performance */
    [class*="-hero"]::before,
    .subscription-hero::before,
    .dashboard-hero::before {
        display: none !important;
    }

    /* Hero flex layouts - stack vertically */
    .subscription-hero {
        flex-direction: column !important;
        text-align: center !important;
        gap: 1.5rem !important;
    }

    /* Premium cards */
    .premium-card {
        border-radius: 12px !important;
    }

    .premium-card-body {
        padding: 1rem !important;
    }

    /* Filter forms */
    .row.g-4.align-items-end>[class*="col-lg"],
    .row.g-4.align-items-end>[class*="col-md"] {
        flex: 0 0 50%;
        max-width: 50%;
    }

    /* Dashboard container */
    .dashboard-container {
        grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
        gap: 1rem;
    }

    /* Statistics grid */
    .stats-grid,
    .statistics-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    /* Form container - wider on tablets */
    .form-container {
        max-width: 100%;
        padding: 2rem;
    }

    /* Card hover - disable transform on touch devices */
    .card:hover {
        transform: none;
    }

    .dashboard-card:hover {
        transform: none;
    }

    /* Sidebar toggle button - position adjustment */
    .sidebar-toggle {
        top: 0.75rem;
        right: 0.75rem;
        width: 45px;
        height: 45px;
    }

    /* Tables - ensure readability */
    .student-table th,
    .student-table td,
    .modern-table th,
    .modern-table td {
        padding: 0.75rem 0.85rem;
        font-size: 0.9rem;
    }

    /* Tab navigation */
    .nav-tabs,
    .nav-pills {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .nav-tabs::-webkit-scrollbar,
    .nav-pills::-webkit-scrollbar {
        display: none;
    }

    .nav-tabs .nav-link,
    .nav-pills .nav-link {
        white-space: nowrap;
        font-size: 0.9rem;
        padding: 0.5rem 1rem;
    }

    /* Page title */
    .page-title {
        font-size: 2rem;
        margin: 1.5rem 0;
    }

    /* Pagination */
    .pagination {
        flex-wrap: wrap;
        justify-content: center;
        gap: 0.25rem;
    }

    .pagination .page-link {
        padding: 0.35rem 0.65rem;
        font-size: 0.85rem;
    }
}

/* ============================================
   BREAKPOINT: ≤768px (Small Tablets / Large Phones Landscape)
   ============================================ */
@media (max-width: 768px) {
    .main-content {
        padding: 12px 15px;
    }

    /* Hero sections - compact */
    [class*="-hero"],
    .subscription-hero,
    .dashboard-hero {
        padding: 1.5rem 1.25rem !important;
        margin-bottom: 1.25rem !important;
        border-radius: 1rem !important;
    }

    [class*="-hero"] h1,
    .subscription-hero h1,
    .dashboard-hero h1 {
        font-size: 1.6rem !important;
        letter-spacing: -0.01em !important;
    }

    [class*="-hero"] p,
    .subscription-hero p,
    .dashboard-hero p {
        font-size: 0.9rem !important;
    }

    /* Filter forms - stack fully */
    .row.g-4.align-items-end>[class*="col-lg"],
    .row.g-4.align-items-end>[class*="col-md"] {
        flex: 0 0 100%;
        max-width: 100%;
    }

    .row.g-3>[class*="col-md"] {
        flex: 0 0 100%;
        max-width: 100%;
    }

    /* Dashboard */
    .dashboard-container {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
    }

    /* Dashboard hero */
    .dashboard-hero {
        flex-direction: column !important;
        text-align: center !important;
    }

    /* Stats grid */
    .stats-grid,
    .statistics-grid {
        grid-template-columns: 1fr 1fr !important;
        gap: 0.75rem !important;
    }

    /* Premium card adjustments */
    .premium-card-header {
        padding: 1rem 1.25rem;
        flex-direction: column;
        gap: 0.5rem;
        text-align: center;
    }

    .premium-card-body {
        padding: 1rem !important;
    }

    /* Delete/Ban/Unban card width */
    .delete-card-premium {
        max-width: 100% !important;
    }

    .delete-card-body {
        padding: 1.5rem !important;
    }

    /* Form container */
    .form-container {
        padding: 1.25rem;
        margin: 1rem auto;
        max-width: 100%;
    }

    /* Tables */
    .student-table thead th {
        font-size: 0.7rem !important;
        padding: 0.6rem 0.5rem !important;
        letter-spacing: 0.3px !important;
    }

    .student-table td {
        padding: 0.6rem 0.5rem !important;
        font-size: 0.85rem;
    }

    /* Avatar in tables */
    .avatar-subtle {
        width: 32px !important;
        height: 32px !important;
        font-size: 0.8rem !important;
        margin-right: 0.5rem !important;
    }

    /* Badge-id */
    .badge-id {
        font-size: 0.75rem !important;
        padding: 0.25rem 0.5rem !important;
    }

    /* Buttons */
    .btn-lg {
        padding: 0.6rem 1.5rem !important;
        font-size: 0.95rem !important;
    }

    .btn-view-subs {
        width: 100%;
        text-align: center;
        padding: 0.6rem 1.5rem !important;
    }

    /* Subject card grid */
    #subjectsList {
        grid-template-columns: 1fr !important;
    }

    /* Cards - remove excessive shadow and animations */
    .card::before {
        display: none;
    }

    /* Pagination - compact */
    .pagination .page-link {
        padding: 0.3rem 0.5rem;
        font-size: 0.8rem;
    }

    /* Student preview sections */
    .student-preview-ban,
    .student-preview-unban,
    .student-preview-danger {
        padding: 0.75rem !important;
    }

    /* Input groups */
    .input-group {
        flex-wrap: nowrap;
    }

    /* Toast container */
    .toast-container {
        max-width: 95vw;
    }

    .modern-toast {
        border-radius: 12px;
        padding: 0.5rem 1rem;
    }

    /* Alert boxes */
    .alert {
        padding: 0.75rem 1rem;
        font-size: 0.9rem;
    }

    /* File upload area */
    .upload-zone {
        padding: 1.5rem !important;
    }

    /* Live search suggestions */
    #liveSuggestions {
        max-height: 200px !important;
    }

    /* Marketing promo cards */
    .promo-card {
        padding: 1rem !important;
    }

    /* Exams management tabs */
    .management-tabs {
        overflow-x: auto;
    }

    /* Container fluid override */
    .container-fluid {
        padding-left: 10px;
        padding-right: 10px;
    }

    .container {
        padding-left: 10px;
        padding-right: 10px;
    }
}

/* ============================================
   BREAKPOINT: ≤576px (Phones Portrait)
   ============================================ */
@media (max-width: 576px) {
    .main-content {
        padding: 10px 10px;
        max-width: 100%;
    }

    /* Hero sections - very compact */
    [class*="-hero"],
    .subscription-hero,
    .dashboard-hero {
        padding: 1.25rem 1rem !important;
        margin-bottom: 1rem !important;
        border-radius: 0.75rem !important;
        box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15) !important;
    }

    [class*="-hero"] h1,
    .subscription-hero h1,
    .dashboard-hero h1 {
        font-size: 1.35rem !important;
    }

    [class*="-hero"] p,
    .subscription-hero p,
    .dashboard-hero p {
        font-size: 0.8rem !important;
        margin-top: 0.25rem !important;
    }

    /* Dashboard grid - single column */
    .dashboard-container {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }

    /* Stats cards - stack on phones */
    .stats-grid,
    .statistics-grid {
        grid-template-columns: 1fr !important;
    }

    /* Filter row */
    .row.g-4 {
        --bs-gutter-y: 0.75rem;
    }

    /* Form labels */
    .form-label {
        font-size: 0.85rem;
        margin-bottom: 0.35rem;
    }

    /* Form controls */
    .form-control {
        font-size: 0.9rem;
        padding: 0.65rem 0.85rem;
    }

    .form-select {
        font-size: 0.9rem;
        padding: 0.65rem 0.85rem;
    }

    /* Input group text */
    .input-group-text {
        padding: 0.5rem 0.65rem;
        font-size: 0.85rem;
    }

    /* Premium cards */
    .premium-card {
        border-radius: 10px !important;
        margin-bottom: 1rem !important;
    }

    .premium-card-header {
        padding: 0.75rem 1rem;
    }

    .premium-card-header h5 {
        font-size: 0.95rem;
    }

    /* Buttons */
    .btn {
        font-size: 0.9rem;
        padding: 0.5rem 1rem;
    }

    .btn-lg {
        padding: 0.5rem 1.25rem !important;
        font-size: 0.9rem !important;
    }

    .btn-delete-premium {
        padding: 0.7rem 2rem !important;
        font-size: 0.9rem !important;
    }

    /* Table - card-like layout for very small screens */
    .student-table {
        font-size: 0.8rem;
    }

    .student-table thead th {
        font-size: 0.65rem !important;
        padding: 0.5rem 0.4rem !important;
    }

    .student-table td {
        padding: 0.5rem 0.4rem !important;
        font-size: 0.8rem;
    }

    /* Hide less important table columns on phones */
    .student-table .d-flex {
        flex-direction: column;
        gap: 0.15rem;
    }

    .avatar-subtle {
        display: none !important;
    }

    /* Page title */
    .page-title {
        font-size: 1.5rem;
        margin: 1rem 0;
    }

    /* Single col for all rows */
    .col-lg-8,
    .col-lg-4,
    .col-lg-3,
    .col-md-6,
    .col-md-4,
    .col-md-8 {
        flex: 0 0 100%;
        max-width: 100%;
    }

    /* Caution header in delete page */
    .caution-header {
        padding: 1rem !important;
    }

    .caution-header .fs-1 {
        font-size: 2rem !important;
    }

    /* Selected student preview */
    .student-preview-ban,
    .student-preview-unban,
    .student-preview-danger {
        padding: 0.65rem !important;
    }

    .student-preview-ban .d-flex,
    .student-preview-unban .d-flex,
    .student-preview-danger .d-flex {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    /* Card body */
    .card-body {
        padding: 1rem;
    }

    .card-header {
        padding: 0.75rem 1rem;
    }

    /* Sidebar - full screen */
    .sidebar {
        width: 100%;
    }

    /* Mobile header */
    .mobile-header {
        padding: 0.75rem 1rem;
    }

    .mobile-header-brand {
        font-size: 1.1rem;
    }

    /* Sidebar toggle */
    .sidebar-toggle {
        width: 42px;
        height: 42px;
        top: 0.6rem;
        right: 0.6rem;
    }

    .sidebar-toggle i {
        font-size: 1.2rem;
    }

    /* Pagination - minimal */
    .pagination {
        gap: 0.15rem;
    }

    .pagination .page-link {
        padding: 0.25rem 0.45rem;
        font-size: 0.75rem;
    }

    /* Live search - full width on phones */
    #liveSuggestions {
        max-height: 180px !important;
    }

    .suggestion-item {
        padding: 8px 10px !important;
    }

    .avatar-initial-sm {
        width: 30px !important;
        height: 30px !important;
        font-size: 0.8rem !important;
    }

    /* d-flex gap adjustments */
    .d-flex.gap-3 {
        gap: 0.5rem !important;
    }

    /* Alert */
    .alert {
        padding: 0.65rem 0.85rem;
        font-size: 0.85rem;
    }

    /* Container override */
    .container-fluid,
    .container {
        padding-left: 8px;
        padding-right: 8px;
    }

    /* Fix overflow on body */
    body {
        overflow-x: hidden;
    }

    /* Forensic analysis page */
    .forensic-hero {
        padding: 1.5rem 1rem !important;
    }

    /* File menu cards */
    .file-card {
        padding: 1rem !important;
    }

    /* Summer courses */
    .course-card {
        padding: 1rem !important;
    }

    /* Login page - already mostly responsive but ensure padding */
    .login-form {
        padding: 1.25rem;
        margin: 0 0.5rem;
        max-width: calc(100% - 1rem);
    }

    .login-title {
        font-size: 2.25rem;
    }

    .login-subtitle {
        font-size: 1rem;
    }
}

/* ============================================
   BREAKPOINT: ≤400px (Very Small Phones)
   ============================================ */
@media (max-width: 400px) {
    .main-content {
        padding: 8px 8px;
    }

    /* Hero - minimal */
    [class*="-hero"] h1,
    .subscription-hero h1,
    .dashboard-hero h1 {
        font-size: 1.15rem !important;
    }

    [class*="-hero"],
    .subscription-hero,
    .dashboard-hero {
        padding: 1rem 0.75rem !important;
    }

    /* Form elements */
    .form-control {
        font-size: 0.85rem;
        padding: 0.55rem 0.75rem;
    }

    .form-select {
        font-size: 0.85rem;
    }

    /* Buttons even smaller */
    .btn {
        font-size: 0.8rem;
        padding: 0.4rem 0.8rem;
    }

    .btn-lg {
        font-size: 0.85rem !important;
        padding: 0.45rem 1rem !important;
    }

    /* Table text */
    .student-table {
        font-size: 0.75rem;
    }

    .student-table thead th {
        font-size: 0.6rem !important;
    }

    /* Login */
    .login-title {
        font-size: 1.85rem;
    }

    .login-form {
        padding: 1rem;
    }

    /* Form floating */
    .form-floating .form-control {
        height: 3rem;
        padding: 1.25rem 2.5rem 0.35rem 0.5rem;
    }

    /* Premium card header */
    .premium-card-header h5 {
        font-size: 0.85rem;
    }
}

/* ============================================
   LANDSCAPE ORIENTATION ADJUSTMENTS
   ============================================ */
@media (max-height: 500px) and (orientation: landscape) {

    /* Hero sections - very compact in landscape */
    [class*="-hero"],
    .subscription-hero,
    .dashboard-hero {
        padding: 1rem 1.5rem !important;
        margin-bottom: 0.75rem !important;
    }

    [class*="-hero"] h1,
    .subscription-hero h1,
    .dashboard-hero h1 {
        font-size: 1.35rem !important;
    }

    [class*="-hero"] p,
    .subscription-hero p,
    .dashboard-hero p {
        display: none !important;
    }

    /* Reduce vertical spacing */
    .main-content {
        padding-top: 8px;
        padding-bottom: 8px;
    }

    /* Dashboard grid - horizontal layout in landscape */
    .dashboard-container {
        grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    }

    /* Mobile header compact */
    .mobile-header {
        padding: 0.5rem 1rem;
    }

    /* Sidebar toggle smaller */
    .sidebar-toggle {
        width: 38px;
        height: 38px;
        top: 0.4rem;
        right: 0.4rem;
    }
}

/* ============================================
   TABLET LANDSCAPE SPECIFIC (768-1024px, landscape)
   ============================================ */
@media (min-width: 768px) and (max-width: 1024px) and (orientation: landscape) {
    .main-content {
        padding: 15px 25px;
    }

    /* Two-column layout for filters */
    .row.g-4.align-items-end>[class*="col-lg"],
    .row.g-4.align-items-end>[class*="col-md"] {
        flex: 0 0 50%;
        max-width: 50%;
    }

    /* Dashboard grid */
    .dashboard-container {
        grid-template-columns: repeat(3, 1fr);
    }

    /* Stats */
    .stats-grid,
    .statistics-grid {
        grid-template-columns: repeat(3, 1fr) !important;
    }
}

/* ============================================
   GLOBAL UTILITY FIXES
   ============================================ */

/* Prevent horizontal overflow - ONLY on body, NOT html (breaks position:fixed) */
body {
    overflow-x: hidden;
}

/* Ensure images never overflow their containers */
img {
    max-width: 100%;
    height: auto;
}

/* Ensure tables are scrollable */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    width: 100%;
}

/* === SIDEBAR MOBILE FIX ===
   Ensure sidebar always overlays content properly on mobile.
   Without these, sidebar can render below page content. */
@media (max-width: 992px) {
    .sidebar {
        position: fixed !important;
        top: 0 !important;
        right: 0 !important;
        height: 100vh !important;
        height: 100dvh !important;
        z-index: 1050 !important;
        transform: translateX(100%);
    }

    .sidebar.active {
        transform: translateX(0) !important;
    }

    .sidebar-overlay {
        z-index: 1040 !important;
    }

    .sidebar-toggle {
        z-index: 1060 !important;
    }

    .mobile-header {
        z-index: 1030 !important;
    }
}

/* Better touch targets for mobile */
@media (pointer: coarse) {
    .btn {
        min-height: 44px;
        min-width: 44px;
    }

    .form-control,
    .form-select {
        min-height: 44px;
    }

    .pagination .page-link {
        min-height: 38px;
        min-width: 38px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .sidebar-link {
        min-height: 48px;
    }

    .nav-link {
        min-height: 44px;
        display: flex;
        align-items: center;
    }
}

/* Smooth scrolling for all scrollable containers */
* {
    -webkit-overflow-scrolling: touch;
}

/* Fix Bootstrap row negative margins causing horizontal scroll */
.row {
    margin-right: 0;
    margin-left: 0;
}

.row>* {
    padding-right: calc(var(--bs-gutter-x, 1.5rem) * 0.5);
    padding-left: calc(var(--bs-gutter-x, 1.5rem) * 0.5);
}

/* Container max-width fix */
.container-fluid {
    max-width: 100%;
    overflow-x: hidden;
}