/**
 * تجربة تطبيق أصلي — PWA / Add to Home Screen
 * يقلّل إحساس Safari ويحسّن اللمس والتمرير
 */

html {
    height: 100%;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    scroll-behavior: smooth;
}

html,
body {
    overscroll-behavior: none;
    -webkit-overflow-scrolling: touch;
}

body {
    min-height: 100%;
    min-height: 100dvh;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    padding-left: env(safe-area-inset-left, 0);
    padding-right: env(safe-area-inset-right, 0);
}

button,
a,
[role="button"],
.btn-primary-custom,
.btn-secondary-custom,
.btn-logout,
.admin-menu-btn,
.admin-menu-item,
.btn-student-news-mini,
.student-push-enable-btn,
.student-news-alert,
.student-news-archive-item,
.admin-back-btn,
.btn-student-card-save,
.btn-action,
.close-btn {
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

input,
textarea,
select {
    font-size: 16px;
    touch-action: manipulation;
}

/* ─── لمس بدل hover على الجوال ─── */
@media (hover: none) and (pointer: coarse) {
    .btn-primary-custom:hover,
    .btn-secondary-custom:hover,
    .btn-student-news-mini:hover,
    .student-news-alert:hover,
    .student-news-archive-item:hover,
    .btn-logout:hover,
    .student-push-enable-btn:hover {
        transform: none;
    }

    button:active,
    .btn-primary-custom:active,
    .btn-secondary-custom:active,
    .btn-student-news-mini:active,
    .student-news-alert:active,
    .student-news-archive-item:active,
    .admin-menu-item:active,
    .admin-back-btn:active {
        transform: scale(0.97);
        opacity: 0.92;
        transition: transform 0.12s ease, opacity 0.12s ease;
    }
}

/* ─── وضع التطبيق (Add to Home Screen) ─── */
html.is-standalone {
    background: #eef4f7;
}

html.is-standalone body {
    background: #eef4f7;
    padding-bottom: env(safe-area-inset-bottom, 0);
}

html.is-standalone .login-choice-overlay {
    padding:
        env(safe-area-inset-top, 0)
        env(safe-area-inset-right, 0)
        env(safe-area-inset-bottom, 0)
        env(safe-area-inset-left, 0);
}

html.is-standalone .page-header {
    position: sticky;
    top: 0;
    z-index: 200;
    margin-bottom: 16px;
    border-radius: 0;
    padding-top: calc(14px + env(safe-area-inset-top, 0));
    padding-bottom: 14px;
    background: rgba(255, 255, 255, 0.94);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-bottom: 1px solid rgba(226, 232, 240, 0.95);
    box-shadow: 0 1px 0 rgba(15, 23, 42, 0.04);
}

html.is-standalone .main-container {
    max-width: 100%;
    padding-top: 0;
    padding-bottom: calc(20px + env(safe-area-inset-bottom, 0));
}

@media (max-width: 600px) {
    html.is-standalone .main-container {
        padding-inline: 12px;
    }

    html.is-standalone .page-header {
        margin-inline: -12px;
        padding-inline: 16px;
        width: calc(100% + 24px);
    }
}

/* ─── انتقالات الصفحات ─── */
html.is-native-feel .student-view,
html.is-native-feel .admin-view {
    animation: nativePageIn 0.32s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes nativePageIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ─── iOS: تقليل ارتداد وسلوك المتصفح ─── */
html.is-ios.is-native-feel body {
    position: relative;
}

html.is-ios .modal,
html.is-ios .login-choice-overlay {
    padding-bottom: env(safe-area-inset-bottom, 0);
}

html.is-ios input[type="text"],
html.is-ios input[type="password"],
html.is-ios input[type="number"],
html.is-ios textarea,
html.is-ios select {
    border-radius: 12px;
    appearance: none;
    -webkit-appearance: none;
}

/* ─── شريط سفلي آمن للأزرار الثابتة ─── */
html.is-standalone .site-footer-brand {
    padding-bottom: env(safe-area-inset-bottom, 8px);
}

/* ─── دعوة التثبيت على الشاشة الرئيسية ─── */
.install-sheet-backdrop {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    background: rgba(15, 23, 42, 0);
    transition: background 0.26s ease;
}

.install-sheet-backdrop.is-open {
    background: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
}

.install-sheet {
    position: relative;
    width: min(440px, 100%);
    background: #fff;
    border-radius: 24px 24px 0 0;
    padding: 24px 22px calc(22px + env(safe-area-inset-bottom, 0));
    box-shadow: 0 -12px 40px rgba(15, 23, 42, 0.24);
    transform: translateY(100%);
    transition: transform 0.32s cubic-bezier(0.22, 1, 0.36, 1);
    text-align: right;
}

.install-sheet-backdrop.is-open .install-sheet {
    transform: translateY(0);
}

.install-sheet-close {
    position: absolute;
    top: 12px;
    inset-inline-start: 14px;
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 50%;
    background: #f2efe9;
    color: #64748b;
    font-size: 1.35rem;
    line-height: 1;
    cursor: pointer;
}

.install-sheet-head {
    display: flex;
    align-items: center;
    gap: 13px;
    padding-bottom: 16px;
    margin-bottom: 16px;
    border-bottom: 1px solid var(--border-color);
}

.install-sheet-logo {
    width: 52px;
    height: 52px;
    flex-shrink: 0;
    border-radius: 50%;
    background: #f7f5f1;
    border: 1px solid rgba(20, 58, 77, 0.12);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.install-sheet-logo img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: 50% 30%;
}

.install-sheet-title {
    margin: 0 0 2px;
    font-size: 1.05rem;
    font-weight: 800;
    color: var(--primary-dark);
}

.install-sheet-sub {
    font-size: 0.76rem;
    font-weight: 700;
    color: var(--text-muted);
}

.install-sheet-lead {
    margin: 0 0 16px;
    font-size: 0.9rem;
    font-weight: 700;
    color: #334155;
    line-height: 1.65;
}

.install-steps {
    list-style: none;
    margin: 0 0 18px;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.install-steps li {
    display: flex;
    align-items: flex-start;
    gap: 11px;
    background: #f7f5f1;
    border: 1px solid var(--border-color);
    border-radius: 13px;
    padding: 12px 13px;
}

.install-step-num {
    width: 25px;
    height: 25px;
    flex-shrink: 0;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    font-size: 0.8rem;
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
}

.install-step-text {
    font-size: 0.87rem;
    font-weight: 700;
    color: #334155;
    line-height: 1.6;
}

.install-step-text strong {
    color: var(--primary-dark);
    font-weight: 800;
}

.install-share-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    margin: 0 2px;
    vertical-align: -7px;
    border-radius: 7px;
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    color: #2563eb;
}

.install-sheet-btn {
    width: 100%;
    padding: 14px;
    border-radius: 13px;
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 800;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.install-sheet-btn--primary {
    border: none;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #fff;
    margin-bottom: 9px;
    box-shadow: 0 6px 18px rgba(35, 107, 140, 0.26);
}

.install-sheet-btn--ghost {
    border: 1px solid var(--border-color);
    background: #fff;
    color: var(--text-muted);
}

.install-sheet-btn:active {
    transform: scale(0.98);
}

@media (min-width: 620px) {
    .install-sheet-backdrop {
        align-items: center;
    }

    .install-sheet {
        border-radius: 22px;
        padding-bottom: 22px;
        transform: translateY(18px) scale(0.97);
        opacity: 0;
        transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.3s ease;
    }

    .install-sheet-backdrop.is-open .install-sheet {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
}
