/**
 * استجابة موحّدة للوحات الويب (خبير / إدارة / …)
 * هاتف · تابلت · سطح مكتب
 */
html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    overflow-x: hidden;
}

img,
svg,
video,
canvas {
    max-width: 100%;
    height: auto;
}

/* ——— جداول: تمرير أفقي آمن ——— */
.table-responsive,
.admin-table-wrap,
.overflow-x-auto,
.web-table-scroll {
    display: block;
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
}

#page-content table,
.main-content table:not(.osh-skip),
.sheet table.data-table {
    max-width: none;
}

@media (max-width: 1024px) {
    #page-content table,
    #main-content table,
    .main-content .card table,
    .main-content .glass-card table,
    .main-content .admin-table-wrap table {
        min-width: 640px;
    }

    #page-content .card,
    #page-content .glass-card,
    #page-content .bg-white,
    #page-content .rounded-2xl,
    #page-content .rounded-xl,
    #main-content .card,
    #main-content .glass-card,
    #main-content .bg-white,
    #main-content .rounded-2xl,
    #main-content .rounded-xl {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    #page-content,
    #main-content,
    .main-content {
        min-width: 0;
        max-width: 100%;
    }
}

/* ——— شبكة وأعمدة ——— */
@media (max-width: 768px) {
    .container-fluid,
    .container {
        padding-left: 0.75rem !important;
        padding-right: 0.75rem !important;
    }

    #page-content,
    #main-content {
        min-width: 0;
    }

    .main-content > .flex-1,
    .main-content .p-4,
    .main-content .lg\:p-5 {
        padding: 0.75rem !important;
    }

    /* صفوف أزرار العنوان */
    .page-header-actions,
    .d-flex.justify-content-between.align-items-center,
    .flex.justify-between.items-center {
        flex-wrap: wrap !important;
        gap: 0.75rem !important;
    }

    .brand-btn-primary,
    .brand-btn-gold,
    .brand-btn-outline {
        min-height: 44px;
    }

    /* بطاقات الإحصاء */
    .stat-card,
    .glass-card {
        border-radius: 1rem;
    }

    /* نماذج */
    .form-control,
    .form-select,
    input.form-control,
    select.form-select,
    textarea.form-control {
        font-size: 16px !important; /* يمنع تكبير iOS التلقائي */
        min-height: 44px;
    }

    .modal-dialog {
        margin: 0.5rem;
        max-width: calc(100% - 1rem);
    }

    .modal-dialog.modal-xl,
    .modal-dialog.modal-lg {
        max-width: calc(100% - 1rem);
    }

    .modal-content {
        border-radius: 1rem !important;
        max-height: calc(100vh - 1rem);
    }
}

@media (max-width: 576px) {
    #page-content h1,
    #page-content .brand-page-title,
    #main-content h1,
    #main-content .brand-page-title,
    header h1 {
        font-size: 1.05rem !important;
        line-height: 1.4 !important;
    }

    #page-content h2,
    #main-content h2 {
        font-size: 1rem !important;
    }

    .btn-group {
        flex-wrap: wrap;
        width: 100%;
    }

    .btn-group .btn {
        flex: 1 1 auto;
    }

    /* شريط تبويب أفقي */
    .nav-tabs,
    .flex.border-b {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        gap: 0.25rem;
        padding-bottom: 2px;
    }

    .nav-tabs .nav-link {
        white-space: nowrap;
    }
}

/* ——— صحائف التقييم الرسمية ——— */
.sheet {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.official-sheet-header {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
}

@media (max-width: 768px) {
    .sheet {
        padding: 12px 10px 20px !important;
        margin: 0 !important;
        border-radius: 0;
        box-shadow: none !important;
    }

    .toolbar {
        padding: 0 4px;
        gap: 8px !important;
    }

    .toolbar .btn {
        flex: 1 1 calc(50% - 8px);
        justify-content: center;
        min-height: 44px;
        font-size: 13px !important;
        padding: 10px 12px !important;
    }

    .inspector-meta {
        flex-direction: column !important;
        gap: 8px !important;
        font-size: 12px !important;
    }

    .official-sheet-header table,
    .sheet table.data-table {
        min-width: 720px;
        font-size: 11px !important;
    }

    .official-sheet-header .osh-title {
        font-size: 14px !important;
    }

    .official-sheet-header .osh-form-box,
    .official-sheet-header .osh-logo {
        font-size: 10px !important;
    }

    .official-sheet-header .osh-label {
        white-space: normal !important;
    }

    .sheet .section h3 {
        font-size: 12px !important;
        padding: 6px 8px !important;
    }

    table.data-table th,
    table.data-table td {
        padding: 5px 4px !important;
    }
}

@media (max-width: 480px) {
    .toolbar .btn {
        flex: 1 1 100%;
    }

    .official-sheet-header table,
    .sheet table.data-table {
        min-width: 640px;
    }
}

/* ——— طباعة ——— */
@media print {
    .toolbar,
    .sidebar,
    .sidebar-overlay,
    .admin-top-header,
    header {
        display: none !important;
    }

    .main-content {
        margin: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
    }

    .sheet {
        box-shadow: none !important;
        border: none !important;
        overflow: visible !important;
        max-width: none !important;
    }

    .official-sheet-header table,
    .sheet table.data-table {
        min-width: 0 !important;
    }
}

/* قائمة الملف الشخصي في لوحة المفتش (ويب) */
@media (max-width: 767.98px) {
    .top-navbar .dropdown-menu {
        position: fixed !important;
        left: 0.75rem !important;
        right: 0.75rem !important;
        width: auto !important;
        max-width: none !important;
        inset-inline: 0.75rem;
        transform: none !important;
        z-index: 1050;
    }
}

/* ——— مناطق آمنة للهاتف ——— */
@supports (padding: env(safe-area-inset-bottom)) {
    body {
        padding-left: env(safe-area-inset-left);
        padding-right: env(safe-area-inset-right);
    }

    .main-content {
        padding-bottom: env(safe-area-inset-bottom);
    }
}
