/* 
 * سكرتيري - تأثيرات التطبيق الناتيف
 * v2.6
 * 
 * يضيف شعور وملمس التطبيق الحقيقي للـ PWA
 */

/* ========== Safe Areas للـ iPhone Notch ========== */
:root {
    --safe-top: env(safe-area-inset-top);
    --safe-bottom: env(safe-area-inset-bottom);
    --safe-left: env(safe-area-inset-left);
    --safe-right: env(safe-area-inset-right);
    --bottom-nav-height: 64px;
}

/* ========== في وضع التطبيق المستقل (Standalone) ========== */
@media (display-mode: standalone) {
    body {
        /* إضافة المساحة للـ Status bar */
        padding-top: var(--safe-top);
        padding-bottom: var(--safe-bottom);
    }
    
    /* تثبيت navbar في الأعلى */
    .navbar {
        padding-top: calc(0.5rem + var(--safe-top)) !important;
    }
    
    /* تثبيت footer مع safe area */
    .footer {
        padding-bottom: calc(1rem + var(--safe-bottom)) !important;
    }
}

/* ========== منع التحديد على الجوال (مثل التطبيقات) ========== */
@media (max-width: 768px) {
    body {
        -webkit-user-select: none;
        -webkit-touch-callout: none;
        -webkit-tap-highlight-color: transparent;
    }
    
    /* السماح بالتحديد للنصوص المهمة */
    p, h1, h2, h3, h4, h5, h6, span, td, .selectable {
        -webkit-user-select: text;
        user-select: text;
    }
    
    /* إخفاء scrollbar على الجوال (مثل التطبيقات) */
    body::-webkit-scrollbar,
    .scrollable::-webkit-scrollbar {
        display: none;
    }
    
    body, .scrollable {
        -ms-overflow-style: none;
        scrollbar-width: none;
    }
}

/* ========== Ripple Effect على الأزرار (Material Design) ========== */
.btn, button, .nav-link, .list-group-item, .card a {
    position: relative;
    overflow: hidden;
}

.btn::after, button::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.4);
    transform: translate(-50%, -50%);
    transition: width 0.5s, height 0.5s, opacity 0.5s;
    pointer-events: none;
    opacity: 0;
}

.btn:active::after, button:active::after {
    width: 300px;
    height: 300px;
    opacity: 1;
    transition: width 0.2s, height 0.2s, opacity 0s;
}

/* ========== Touch Feedback - أحجام أكبر للأزرار على الجوال ========== */
@media (max-width: 768px) {
    .btn {
        min-height: 44px; /* Apple HIG: minimum touch target */
        padding: 0.6rem 1rem;
    }
    
    .btn-sm {
        min-height: 36px;
    }
    
    /* مساحة أوسع للروابط */
    a, .nav-link {
        min-height: 44px;
        display: inline-flex;
        align-items: center;
    }
}

/* ========== Page Transitions ========== */
main {
    animation: pageEnter 0.3s ease-out;
}

@keyframes pageEnter {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ========== Loading States محسّنة ========== */
.skeleton {
    background: linear-gradient(
        90deg,
        var(--bg-card, #f0f0f0) 25%,
        var(--bg, #e0e0e0) 50%,
        var(--bg-card, #f0f0f0) 75%
    );
    background-size: 200% 100%;
    animation: skeletonLoad 1.5s infinite;
    border-radius: 8px;
}

@keyframes skeletonLoad {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ========== Bottom Navigation للجوال ========== */
.app-bottom-nav {
    display: none; /* مخفي على الكمبيوتر */
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(var(--bottom-nav-height) + var(--safe-bottom));
    padding-bottom: var(--safe-bottom);
    background: white;
    box-shadow: 0 -2px 20px rgba(0, 0, 0, 0.08);
    z-index: 999;
    border-top: 1px solid var(--border, #e5e7eb);
}

[data-theme="dark"] .app-bottom-nav {
    background: #1e293b;
    border-top-color: rgba(255, 255, 255, 0.1);
    box-shadow: 0 -2px 20px rgba(0, 0, 0, 0.4);
}

.app-bottom-nav-items {
    display: flex;
    justify-content: space-around;
    align-items: center;
    height: var(--bottom-nav-height);
    max-width: 600px;
    margin: 0 auto;
}

.app-bottom-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 8px 4px;
    color: var(--text-muted, #6b7280);
    text-decoration: none;
    font-size: 0.7rem;
    font-weight: 500;
    transition: all 0.2s;
    position: relative;
    min-height: var(--bottom-nav-height);
}

.app-bottom-nav-item i {
    font-size: 1.4rem;
    transition: transform 0.2s;
}

.app-bottom-nav-item.active {
    color: var(--primary, #0a2540);
}

.app-bottom-nav-item.active i {
    transform: translateY(-2px);
}

.app-bottom-nav-item.active::before {
    content: '';
    position: absolute;
    top: 0;
    left: 30%;
    right: 30%;
    height: 3px;
    background: var(--primary, #0a2540);
    border-radius: 0 0 3px 3px;
}

.app-bottom-nav-item:hover {
    color: var(--primary, #0a2540);
}

/* زر FAB في الوسط (إضافة) */
.app-bottom-nav-fab {
    background: linear-gradient(135deg, #f97316, #ea580c) !important;
    color: white !important;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    margin-top: -20px;
    box-shadow: 0 4px 12px rgba(249, 115, 22, 0.4);
    flex: 0 0 56px !important;
    min-height: 56px !important;
    font-size: 1.5rem !important;
}

.app-bottom-nav-fab i {
    font-size: 1.5rem !important;
    transform: none !important;
}

.app-bottom-nav-fab::before {
    display: none !important;
}

.app-bottom-nav-fab .label-text {
    display: none;
}

/* بادج التنبيهات في bottom nav */
.bottom-nav-badge {
    position: absolute;
    top: 6px;
    left: calc(50% + 5px);
    background: #dc2626;
    color: white;
    font-size: 0.65rem;
    font-weight: 700;
    padding: 1px 5px;
    border-radius: 8px;
    min-width: 16px;
    text-align: center;
    border: 2px solid white;
}

[data-theme="dark"] .bottom-nav-badge {
    border-color: #1e293b;
}

/* إظهار bottom nav على الجوال فقط */
@media (max-width: 768px) {
    .app-bottom-nav {
        display: block;
    }
    
    /* إضافة padding للـ body عشان ما يخفي المحتوى */
    body {
        padding-bottom: calc(var(--bottom-nav-height) + var(--safe-bottom) + 10px);
    }
    
    /* تعديل الـ footer العادي */
    .footer {
        margin-bottom: calc(var(--bottom-nav-height) + var(--safe-bottom));
    }
    
    /* تعديل الزر العائم للطباعة */
    .btn-floating-print {
        bottom: calc(var(--bottom-nav-height) + var(--safe-bottom) + 20px) !important;
    }
    
    /* تعديل بانر PWA */
    .pwa-install-banner {
        bottom: calc(var(--bottom-nav-height) + var(--safe-bottom) + 12px) !important;
    }
}

/* إخفاء على شاشات الطباعة */
@media print {
    .app-bottom-nav { display: none !important; }
}

/* ========== Smooth Scrolling ========== */
html {
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch; /* iOS momentum */
}

/* ========== Animations محسّنة ========== */
.card {
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.card:active {
    transform: scale(0.98);
}

@media (max-width: 768px) {
    .card {
        border-radius: 14px !important;
    }
}

/* ========== Status Bar (في وضع Standalone) ========== */
@media (display-mode: standalone) {
    .navbar {
        background: var(--primary, #0a2540) !important;
        color: white !important;
    }
    
    .navbar .nav-link {
        color: white !important;
    }
    
    .navbar .nav-link.active {
        color: #f97316 !important;
    }
}

/* ========== شاشة Splash بسيطة عند التحميل الأول ========== */
.app-splash {
    position: fixed;
    inset: 0;
    background: linear-gradient(135deg, #0a2540, #1e3a5f);
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 20px;
    transition: opacity 0.5s, visibility 0.5s;
}

.app-splash.hide {
    opacity: 0;
    visibility: hidden;
}

.app-splash-logo {
    width: 100px;
    height: 100px;
    background: white;
    border-radius: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3rem;
    color: #0a2540;
    animation: splashPulse 1.5s ease-in-out infinite;
}

@keyframes splashPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

.app-splash-name {
    color: white;
    font-size: 1.5rem;
    font-weight: 800;
}

.app-splash-tagline {
    color: rgba(255,255,255,0.7);
    font-size: 0.9rem;
}

/* ========== Pull to Refresh Animation ========== */
.pull-refresh-indicator {
    position: fixed;
    top: -60px;
    left: 50%;
    transform: translateX(-50%);
    width: 44px;
    height: 44px;
    background: white;
    border-radius: 50%;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: top 0.3s;
}

.pull-refresh-indicator.visible {
    top: 20px;
}

.pull-refresh-indicator i {
    color: var(--primary, #0a2540);
    font-size: 1.4rem;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* ========== iOS Specific Tweaks ========== */
@supports (-webkit-touch-callout: none) {
    .btn {
        cursor: pointer;
    }
    
    /* تحسين الأزرار على iOS */
    input, select, textarea {
        font-size: 16px !important; /* منع zoom on focus */
    }
}
