/* Responsive Design for Mobile Devices */

/* Mobile Menu Toggle */
@media (max-width: 992px) {
    .sidebar {
        position: fixed;
        right: auto !important;
        left: -280px;
        transition: left 0.3s ease;
        z-index: 1000;
        height: 100vh;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
    }

    .sidebar.active {
        left: 0;
    }

    .main-content {
        margin-right: 0 !important;
        padding: 15px;
        padding-bottom: calc(88px + env(safe-area-inset-bottom, 0px));
        max-width: 100vw;
        overflow-x: hidden;
    }

    /* Sidebar Close Button (inside sidebar) */
    .sidebar-close-btn {
        display: block !important;
        position: absolute;
        top: 15px;
        left: 15px;
        background: transparent;
        color: #14B8A6;
        border: 2px solid #14B8A6;
        border-radius: 6px;
        padding: 6px 12px;
        font-size: 24px;
        cursor: pointer;
        transition: all 0.3s ease;
        line-height: 1;
    }

    .sidebar-close-btn:hover {
        background: #14B8A6;
        color: white;
    }

    /* Mobile Menu Button */
    .mobile-menu-toggle {
        display: block !important;
        position: fixed;
        top: 15px;
        left: 15px;
        z-index: 1001;
        background: #1F2937;
        color: #14B8A6;
        border: 2px solid #14B8A6;
        border-radius: 8px;
        padding: 10px 14px;
        font-size: 24px;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
        cursor: pointer;
        transition: all 0.3s ease;
    }

    .mobile-menu-toggle:hover {
        background: #14B8A6;
        color: white;
    }

    .mobile-menu-toggle:active {
        transform: scale(0.95);
    }

    .mobile-menu-toggle .close-icon {
        font-size: 26px;
        font-weight: bold;
    }

    /* Overlay */
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.5);
        z-index: 999;
    }

    .sidebar-overlay.active {
        display: block;
    }

    /* Responsive grids on tablet/mobile */
    .stats-grid {
        grid-template-columns: 1fr;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    /* Prevent horizontal overflow */
    body {
        overflow-x: hidden !important;
        max-width: 100vw;
    }

    .app-container {
        overflow-x: hidden;
        max-width: 100vw;
    }
}

/* Tables Responsive */
@media (max-width: 768px) {

    /* Reduce base font size */
    html {
        font-size: 14px;
    }

    /* Headings optimization */
    h1 {
        font-size: 1.5rem !important;
    }

    h2 {
        font-size: 1.25rem !important;
    }

    h3 {
        font-size: 1.1rem !important;
    }

    .page-title {
        font-size: 1.5rem !important;
    }

    /* Table improvements */
    .table-responsive {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
        margin: 0 -15px;
        padding: 0 15px;
    }

    table {
        min-width: 600px;
        font-size: 0.8rem;
    }

    th,
    td {
        padding: 8px 6px !important;
        white-space: nowrap;
    }

    /* Stack cards on mobile */
    .card {
        margin: 0 0 1rem 0;
        padding: 12px;
        border-radius: 8px;
    }

    .card-body {
        padding: 12px 0;
    }

    .stats-grid {
        gap: 12px;
    }

    .stat-card {
        padding: 12px;
    }

    .row>[class*='col-'] {
        margin-bottom: 15px;
    }

    /* أهداف لمس أوضح دون فرض عرض كامل لكل الأزرار */
    .btn {
        min-height: 44px;
        padding: 10px 16px;
    }

    /* صفوف أزرار: تبقى أفقية قدر الإمكان */
    .d-flex.flex-wrap .btn,
    .page-header .btn,
    .page-toolbar .btn,
    .modal-footer .btn,
    .table .btn,
    .btn-group .btn,
    .input-group .btn,
    .quick-menu .btn,
    .navbar .btn {
        width: auto;
        margin-bottom: 0;
    }

    /* Form inputs */
    input,
    select,
    textarea {
        font-size: 16px !important;
        /* Prevents auto-zoom on iOS */
        padding: 10px 12px;
    }

    .form-control {
        padding: 10px 12px;
    }

    .form-label {
        font-size: 0.9rem;
        margin-bottom: 6px;
    }

    /* أزرار النماذج البسيطة داخل البطاقة فقط: عرض كامل عند الحاجة */
    .card-body > form > .btn.btn-primary:only-of-type:not(.btn-sm),
    .card-body > form > .btn.btn-success:only-of-type:not(.btn-sm) {
        width: 100%;
    }

    /* Spacing optimizations — الحفاظ على مساحة أسفل الشاشة للقائمة السريعة */
    .main-content {
        padding: 12px !important;
        padding-bottom: calc(88px + env(safe-area-inset-bottom, 0px)) !important;
    }

    .page-header {
        margin-bottom: 16px;
    }

    .card-header {
        padding: 12px;
        margin-bottom: 12px;
    }

    /* Dashboard cards */
    .col-md-4,
    .col-md-6 {
        width: 100%;
    }

    /* Hide less important columns on small screens */
    .hide-mobile {
        display: none !important;
    }
}

/* Extra small devices */
@media (max-width: 576px) {
    h1 {
        font-size: 1.5rem;
    }

    h2 {
        font-size: 1.25rem;
    }

    .card-body {
        padding: 1rem;
    }

    /* Stack buttons vertically */
    .btn-group {
        flex-direction: column;
        width: 100%;
    }

    .btn-group .btn {
        width: 100%;
        margin-bottom: 5px;
    }
}

/* Print styles */
@media print {

    .sidebar,
    .mobile-menu-toggle,
    .quick-menu,
    .btn {
        display: none !important;
    }

    .main-content {
        margin: 0 !important;
        padding: 0 !important;
    }
}

/* Landscape mobile */
@media (max-width: 992px) and (orientation: landscape) {
    .sidebar {
        max-height: 100vh;
        overflow-y: auto;
    }
}

/* Touch improvements */
@media (hover: none) {
    .hover-link:active {
        color: #0d6efd !important;
        text-decoration: underline !important;
    }
}

/* شاشات عريضة: شبكة إحصائيات أوضح */
@media (min-width: 1200px) {
    .stats-grid {
        grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    }
}

@media (min-width: 1600px) {
    .stats-grid {
        grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    }
}

/* Default hide mobile menu button on desktop */
.mobile-menu-toggle {
    display: none;
}