/* ============================================================
   khadmaty / Khedmatak — Mobile App Shell
   يجعل كل الشاشات تبدو كتطبيق موبايل أصلي على الهاتف
   مع بقائها كموقع كامل على الشاشات الكبيرة
   ============================================================ */

:root {
    --app-bg: #f2f5f4;
    --app-surface: #ffffff;
    --app-primary: #00875a;
    --app-primary-dark: #006b48;
    --app-accent: #00c47e;
    --app-text: #152018;
    --app-text-2: #5b6b63;
    --app-text-3: #94a29b;
    --app-line: #e5ece8;
    --app-radius: 18px;
    --app-shadow: 0 6px 24px rgba(20, 60, 40, .08);
    --app-bar-h: 60px;
    --app-nav-h: 68px;
    --app-safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* ==== App Header (علوي ثابت) ==== */
.app-header {
    position: sticky;
    top: 0;
    z-index: 900;
    display: none;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    height: var(--app-bar-h);
    padding: 0 14px;
    background: rgba(255, 255, 255, .92);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--app-line);
}
.app-header .app-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 900;
    font-size: 1.05rem;
    color: var(--app-text);
}
.app-header .app-brand .logo-emoji { font-size: 1.4rem; }
.app-header .app-brand .app-logo-img { height: 32px; width: 32px; flex: none; }
.app-header .app-brand small { display: block; font-size: .62rem; font-weight: 700; color: var(--app-primary); }
.app-header .app-actions { display: flex; align-items: center; gap: 8px; }
.app-header .app-actions a, .app-header .app-actions button {
    min-width: 40px;
    height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    background: var(--app-surface);
    border: 1px solid var(--app-line);
    color: var(--app-text);
    font-size: 1.1rem;
    text-decoration: none;
    position: relative;
    font-family: inherit;
    cursor: pointer;
}
.app-header .app-actions .app-cart-count {
    position: absolute;
    top: -4px;
    left: -4px;
    background: #ff4757;
    color: #fff;
    min-width: 18px;
    height: 18px;
    border-radius: 999px;
    font-size: .62rem;
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    box-shadow: 0 2px 6px rgba(255,71,87,.4);
}

/* ==== Bottom Navigation (شريط سفلي كالتطبيقات) ==== */
.app-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 950;
    display: none;
    flex-direction: column;
    align-items: stretch;
    background: rgba(255, 255, 255, .96);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-top: 1px solid var(--app-line);
    box-shadow: 0 -6px 24px rgba(20, 60, 40, .08);
    padding-bottom: min(var(--app-safe-bottom), 14px);
}
.app-nav-inner {
    display: flex;
    align-items: stretch;
    height: var(--app-nav-h);
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    flex-wrap: nowrap;
}
.app-nav-inner::-webkit-scrollbar { display: none; }
.app-nav a {
    flex: 1 1 0;
    min-width: 52px;
    padding: 0 4px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    text-decoration: none;
    color: var(--app-text-2);
    font-size: 0.72rem;
    font-weight: 800;
    position: relative;
    white-space: nowrap;
    transition: color .2s;
}
.app-nav a .ic { font-size: 0.8rem; line-height: 1; }
.app-nav a.active { color: var(--app-primary); }
.app-nav a.active::before {
    content: '';
    position: absolute;
    top: 0;
    width: 46px;
    height: 4px;
    border-radius: 0 0 4px 4px;
    background: var(--app-primary);
}
.app-nav a .badge-dot {
    position: absolute;
    top: 6px;
    inset-inline-end: calc(50% - 24px);
    background: #ff4757;
    color: #fff;
    min-width: 17px;
    height: 17px;
    border-radius: 999px;
    font-size: .62rem;
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
}

/* ==== App Content (بطاقات) ==== */
.app-page { max-width: 1320px; margin: 0 auto; padding: 14px 14px calc(var(--app-nav-h) + var(--app-safe-bottom) + 20px); }
.app-card {
    background: var(--app-surface);
    border-radius: var(--app-radius);
    border: 1px solid var(--app-line);
    box-shadow: var(--app-shadow);
    padding: 16px;
    margin-bottom: 14px;
}
.app-card .app-card-title {
    font-weight: 900;
    font-size: 1rem;
    color: var(--app-text);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.app-list { display: flex; flex-direction: column; }
.app-list-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid var(--app-line);
}
.app-list-item:last-child { border-bottom: none; }
.app-list-item .app-li-ic {
    width: 44px;
    height: 44px;
    border-radius: 14px;
    background: #eef7f2;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    flex-shrink: 0;
}
.app-list-item .app-li-body { flex: 1; min-width: 0; }
.app-list-item .app-li-body .t { font-weight: 800; font-size: .9rem; color: var(--app-text); }
.app-list-item .app-li-body .s { font-size: .75rem; color: var(--app-text-3); }
.app-list-item .app-li-val { font-weight: 900; font-size: .9rem; color: var(--app-text); white-space: nowrap; }

/* ==== App Buttons ==== */
.app-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 14px;
    border: none;
    border-radius: 14px;
    font-family: inherit;
    font-size: .95rem;
    font-weight: 800;
    cursor: pointer;
    text-decoration: none;
    transition: transform .15s, box-shadow .2s;
}
.app-btn:active { transform: scale(.98); }
.app-btn.primary { background: linear-gradient(135deg, var(--app-primary), var(--app-accent)); color: #fff; box-shadow: 0 6px 18px rgba(0, 135, 90, .3); }
.app-btn.soft { background: #eef7f2; color: var(--app-primary); }
.app-btn.ghost { background: transparent; color: var(--app-primary); border: 1.5px solid var(--app-primary); }
.app-btn.danger { background: #ffecec; color: #d64545; }

/* ==== Forms بأسلوب التطبيق ==== */
.app-field { margin-bottom: 14px; }
.app-field label { display: block; font-size: .78rem; font-weight: 800; color: var(--app-text-2); margin-bottom: 6px; }
.app-field input, .app-field select, .app-field textarea {
    width: 100%;
    padding: 13px 14px;
    border: 1.5px solid var(--app-line);
    border-radius: 13px;
    font-family: inherit;
    font-size: .92rem;
    color: var(--app-text);
    background: var(--app-surface);
    transition: border-color .2s, box-shadow .2s;
}
.app-field input:focus, .app-field select:focus, .app-field textarea:focus {
    outline: none;
    border-color: var(--app-primary);
    box-shadow: 0 0 0 4px rgba(0, 135, 90, .12);
}

/* ==== App Sections ==== */
.app-section-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 1.05rem;
    font-weight: 900;
    color: var(--app-text);
    margin: 18px 4px 10px;
}
.app-chip-row { display: flex; gap: 8px; overflow-x: auto; padding: 4px 2px 10px; scrollbar-width: none; }
.app-chip-row::-webkit-scrollbar { display: none; }
.app-chip {
    flex-shrink: 0;
    padding: 9px 16px;
    border-radius: 999px;
    background: var(--app-surface);
    border: 1.5px solid var(--app-line);
    font-family: inherit;
    font-size: .82rem;
    font-weight: 800;
    color: var(--app-text-2);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.app-chip.active { background: var(--app-primary); color: #fff; border-color: var(--app-primary); }

/* ==== Empty / نتائج ==== */
.app-empty { text-align: center; padding: 46px 20px; color: var(--app-text-3); }
.app-empty .ei { font-size: 3.2rem; margin-bottom: 10px; }
.app-empty p { font-size: .9rem; font-weight: 700; }

/* ==== Toast ==== */
.app-toast {
    position: fixed;
    bottom: calc(var(--app-nav-h) + var(--app-safe-bottom) + 16px);
    left: 50%;
    transform: translateX(-50%);
    background: #152018;
    color: #fff;
    padding: 12px 22px;
    border-radius: 999px;
    font-size: .85rem;
    font-weight: 700;
    z-index: 9999;
    box-shadow: 0 8px 30px rgba(0,0,0,.3);
    animation: appToastIn .3s ease;
}
@keyframes appToastIn { from { opacity: 0; transform: translate(-50%, 14px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ==== الجداول: بطاقات قابلة للطي على الموبايل ==== */
.app-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ==== إخفاء العناصر المكتبية على الموبايل ==== */
@media (max-width: 820px) {
    body { background: var(--app-bg); }
    .app-header { display: flex; }
    .app-nav { display: flex; align-items: flex-end; }
    .app-page { padding-left: 12px; padding-right: 12px; }
    .app-desktop-only { display: none !important; }
    /* إخفاء الفوتر والهيدر المكتبي واستبدالهما بالتطبيق */
    .footer { display: none !important; }
    .main-content { padding-bottom: calc(var(--app-nav-h) + var(--app-safe-bottom) + 24px); }
    .topbar.site-topbar { display: none !important; }
    /* ضبط الشبكة الأساسية للمنتجات والبطاقات */
    .grid { grid-template-columns: repeat(2, 1fr) !important; gap: 10px !important; }
    /* صفحات تصميمها الخاص (Default.aspx dark) */
    .page { padding-bottom: calc(var(--app-nav-h) + var(--app-safe-bottom) + 20px) !important; }
    .hero-inner { padding-top: 20px !important; }
    .hero { padding-top: 0 !important; }
}

@media (min-width: 821px) {
    .app-mobile-only { display: none !important; }
}

/* ==== Install Banner (ثبّت التطبيق) ==== */
.install-banner {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: calc(var(--app-nav-h) + var(--app-safe-bottom) + 12px);
    z-index: 1200;
}
.install-banner-inner {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--app-primary);
    color: #fff;
    border-radius: 14px;
    padding: 12px 14px;
    font-weight: 700;
    font-size: .9rem;
    box-shadow: 0 8px 28px rgba(0, 100, 70, .35);
}
.install-banner-inner > span { flex: 1; }
.install-ios-text {
    font-size: .8rem;
    font-weight: 600;
    line-height: 1.9;
}
.install-btn {
    background: #fff;
    color: var(--app-primary);
    border: none;
    border-radius: 10px;
    padding: 8px 14px;
    font-weight: 800;
    font-size: .85rem;
    cursor: pointer;
    font-family: inherit;
}
.install-dismiss {
    background: transparent;
    color: #fff;
    border: none;
    font-size: 1rem;
    cursor: pointer;
    padding: 4px;
    opacity: .85;
}

/* ==== Standalone Mode (بعد التثبيت = بدون شريط المتصفح) ==== */
@media (display-mode: standalone) {
    .install-banner { display: none !important; }
    body { padding-top: env(safe-area-inset-top, 0px); }
    .app-header { padding-top: env(safe-area-inset-top, 0px); }
}

/* ==== تجاوب أي مقاس شاشة ==== */
/* الشريط العلوي المكتبي: منع التفاف أعمدة القائمة حتى 1024px (كان يلتف ويفسد التخطيط بين 821-1024) */
@media (max-width: 1024px) {
    .topbar-inner { flex-wrap: nowrap; height: 58px; padding: 0 .75rem; }
    .topbar-nav { overflow-x: auto; flex-wrap: nowrap; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
    .topbar-nav::-webkit-scrollbar { display: none; }
    .topbar-nav li a { white-space: nowrap; padding: 8px 10px; font-size: .8rem; }
    .topbar-brand { font-size: 1.2rem; }
    .topbar-logo { height: 30px; max-width: 170px; }
    .topbar-actions { flex-shrink: 0; }
}

/* الشاشات الصغيرة جداً (أصغر من 360px) */
@media (max-width: 360px) {
    .app-header { padding: 0 10px; }
    .app-header .app-brand { font-size: .98rem; }
    .app-header .app-brand small { display: none; }
    .app-header .app-actions { gap: 6px; }
    .app-header .app-actions a, .app-header .app-actions button {
        min-width: 36px; height: 36px; font-size: 1rem; border-radius: 10px;
    }
    .app-nav-inner { height: 62px; }
    .app-nav a { font-size: 0.65rem; }
    .app-nav a .ic { font-size: 0.7rem; }
    .app-nav a .badge-dot { top: 4px; inset-inline-end: calc(50% - 20px); }
    .main-content { overflow-x: hidden; }
}

/* ===== SAFETY NET: منع الانزياح الأفقي لكل الصفحات ===== */
html, body { max-width: 100%; overflow-x: hidden; }
img, video, canvas, svg { max-width: 100%; }
table { max-width: 100%; }
.app-page, .main-content, .page { max-width: 100%; }
.app-grid, .grid { max-width: 100%; }
@media (max-width: 820px) {
    .app-card, .app-field input, .app-field select, .app-field textarea { max-width: 100%; }
    .app-table-wrap table { min-width: 560px; }
}
