/* تحسينات تجربة الجوال — تُحمّل بعد ملف التصميم الرئيسي */
@media (max-width: 767px) {
    html {
        -webkit-text-size-adjust: 100%;
    }
    body {
        overflow-x: hidden;
    }

    /* منع التكبير التلقائي عند الكتابة (iOS يكبّر الحقول الأصغر من 16px) */
    input, select, textarea {
        font-size: 16px;
    }

    button, [role="button"], a, input, select, textarea {
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
    }
    button, a, select {
        -webkit-user-select: none;
        user-select: none;
    }

    .container {
        padding: 4.35rem .85rem 1.5rem;
    }
    .panel {
        padding: 1rem 1rem 1.25rem;
    }
    .page-heading {
        margin-bottom: 1.1rem;
    }
    .page-heading h1 {
        font-size: 1.4rem;
    }

    .sidebar-toggle {
        padding: .7rem .95rem;
        right: max(.75rem, env(safe-area-inset-right));
        top: max(.75rem, env(safe-area-inset-top));
    }
    .sidebar {
        padding-bottom: env(safe-area-inset-bottom);
    }

    /* أحجام لمس مريحة */
    .btn, .btn-primary, .login-submit {
        font-size: .95rem;
        min-height: 3rem;
    }
    .btn-sm, .btn-delete-user, .btn-edit, .btn-outline, .btn-pdf {
        min-height: 2.5rem;
    }
    .input-toggle {
        height: 2.75rem;
        width: 2.75rem;
    }

    .stats-grid {
        gap: .75rem;
    }
    .stats-grid > * {
        min-width: 13.25rem;
    }
    .stat-card {
        padding: .95rem .9rem 1rem;
    }

    /* الجداول تتحول على الهاتف إلى بطاقات مرتبة (بدل التمرير الأفقي) */
    .table-wrap {
        background: transparent;
        border: 0;
        border-radius: 0;
        overflow: visible;
        -webkit-overflow-scrolling: touch;
    }
    .table-wrap table {
        display: block;
        min-width: 0;
        width: 100%;
    }
    .table-wrap thead {
        display: none;
    }
    .table-wrap tbody {
        display: block;
    }
    .table-wrap tbody tr {
        background: rgb(var(--surface)/.78);
        border: 1px solid rgb(var(--border));
        border-radius: 1rem;
        display: block;
        margin-bottom: .75rem;
        padding: .65rem .9rem;
    }
    .table-wrap tbody tr:hover {
        background: rgb(var(--surface)/.82);
    }
    .table-wrap tbody td {
        align-items: center;
        border: 0;
        display: flex;
        gap: 1rem;
        justify-content: space-between;
        padding: .42rem 0;
        text-align: start;
        white-space: normal;
    }
    .table-wrap tbody td:before {
        color: rgb(var(--muted));
        content: attr(data-label);
        flex-shrink: 0;
        font-size: .73rem;
        font-weight: 600;
    }
    .table-wrap tbody td[colspan]:before,
    .table-wrap tbody td.empty:before {
        content: "";
    }
    .table-wrap tbody td.empty {
        justify-content: center;
        padding: 1.25rem 0;
        text-align: center;
    }
    .table-wrap tbody td:last-child,
    .table-wrap thead th:last-child {
        background: transparent;
        inset-inline-end: auto;
        position: static;
    }
    .table-wrap tbody tr:last-child td {
        border-bottom: 0;
    }
    .table-wrap tbody td.actions {
        border-top: 1px dashed rgb(var(--border));
        justify-content: flex-end;
        margin-top: .4rem;
        padding-top: .6rem;
    }
    .table-wrap tbody td.actions:before {
        margin-inline-end: auto;
    }
    .table-wrap tbody tr.total-row td,
    .table-wrap tbody tr.totals-row td {
        justify-content: flex-start;
    }

    .field label {
        font-size: .92rem;
    }
    .inline-fields {
        gap: .75rem;
    }

    .radio-segmented, .segmented {
        overflow-x: auto;
        flex-wrap: nowrap;
    }

    /* النوافذ المنبثقة: أسفل الشاشة على الجوال */
    .modal-overlay {
        align-items: flex-end;
        padding: .75rem;
    }
    .modal-box {
        border-radius: 1.25rem 1.25rem 0 0;
        max-height: 90vh;
        max-height: 90dvh;
        padding: 1.25rem 1rem max(1.25rem, env(safe-area-inset-bottom));
    }

    /* صفحة الدخول: نفس أبعاد وبنية صفحة دخول ريبا */
    body.login-page {
        padding: 0;
        min-height: 100vh;
        min-height: 100dvh;
        align-items: stretch;
    }
    body.login-page .split-wrap {
        max-width: none;
        width: 100%;
        min-height: 100vh;
        min-height: 100dvh;
        height: auto;
        border: 0;
        border-radius: 0;
        box-shadow: none;
        grid-template-rows: auto minmax(0, 1fr);
    }
    body.login-page .split-info {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        padding: 1.75rem 1.25rem 1rem !important;
        border-inline-end: 0;
        border-bottom: 1px solid rgb(var(--border));
        text-align: center;
    }
    body.login-page .split-form {
        justify-content: center;
        min-height: auto;
        padding: 1.5rem 1.25rem max(1.5rem, env(safe-area-inset-bottom));
    }
    body.login-page .split-form .form-inner {
        max-width: 100%;
    }
}