/* ═══════════════════════════════════════════════════════════════════════════
   PWA App Shell — سجلات الغياب
   Mobile-first · Bottom Navigation · Top Header · RTL · Dark Mode
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── PWA App Shell Container ── */
.pwa-app-shell {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    background: var(--cw-bg, #ecf4f6);
}

/* ════════════════════════════════════════════════
   TOP HEADER — ثابت في أعلى الشاشة
   ════════════════════════════════════════════════ */
.pwa-topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: var(--cw-surface-2, #ffffff);
    border-bottom: 1px solid var(--cw-border, rgba(13,26,30,0.08));
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
    z-index: 1000;
    direction: rtl;
    transition: background 0.3s ease, border-color 0.3s ease;
    box-shadow: 0 1px 8px rgba(0,0,0,0.04);
}
html[data-theme="dark"] .pwa-topbar {
    background: var(--cw-bg-alt, #1a2c2e);
    border-bottom-color: rgba(91,192,190,0.12);
    box-shadow: 0 1px 8px rgba(0,0,0,0.2);
}

/* ── زر المدرسة النشطة مع القائمة المنسدلة ── */
.pwa-school-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border: none;
    background: rgba(59,148,168,0.06);
    border-radius: 10px;
    color: var(--cw-text-1, #0d1a1e);
    font-family: 'Tajawal', sans-serif;
    font-size: 0.85rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.25s ease;
    max-width: 55%;
    overflow: hidden;
}
.pwa-school-btn:hover {
    background: rgba(59,148,168,0.12);
}
.pwa-school-btn .school-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.pwa-school-btn .pwa-dropdown-arrow {
    font-size: 0.6rem;
    opacity: 0.6;
    transition: transform 0.3s ease;
}
.pwa-school-btn[aria-expanded="true"] .pwa-dropdown-arrow {
    transform: rotate(180deg);
}

/* ── قائمة المدارس المنسدلة ── */
.pwa-school-dropdown {
    display: none;
    position: fixed;
    top: 56px;
    right: 12px;
    left: 12px;
    max-width: 320px;
    background: var(--cw-surface-2, #ffffff);
    border: 1px solid var(--cw-border, rgba(13,26,30,0.08));
    border-radius: 14px;
    box-shadow: 0 12px 40px rgba(0,0,0,0.1);
    z-index: 1001;
    padding: 8px;
    direction: rtl;
}
html[data-theme="dark"] .pwa-school-dropdown {
    background: #1a2c2e;
    border-color: rgba(91,192,190,0.12);
    box-shadow: 0 12px 40px rgba(0,0,0,0.4);
}
.pwa-school-dropdown.show {
    display: block;
    animation: pwaFadeIn 0.2s ease;
}
.pwa-school-dropdown .dropdown-label {
    padding: 8px 12px 4px;
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--cw-text-3, #4d6b73);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.pwa-school-dropdown a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    color: var(--cw-text-1, #0d1a1e);
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 600;
    border-radius: 10px;
    transition: all 0.2s ease;
}
.pwa-school-dropdown a:hover {
    background: rgba(59,148,168,0.06);
}
.pwa-school-dropdown a.active {
    color: var(--cw-accent, #3b94a8);
    background: rgba(59,148,168,0.08);
}

/* ── أزرار الشريط العلوي اليمنى ── */
.pwa-topbar-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}
.pwa-topbar-btn {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: none;
    border-radius: 10px;
    color: var(--cw-text-2, #3A545C);
    font-size: 1.1rem;
    cursor: pointer;
    transition: all 0.25s ease;
    position: relative;
    font-family: 'Tajawal', sans-serif;
}
.pwa-topbar-btn:hover {
    background: rgba(59,148,168,0.06);
    color: var(--cw-accent, #3b94a8);
}

/* ── زر الثيم (cw-theme-toggle) داخل PWA topbar ── */
.pwa-topbar .cw-theme-toggle {
    width: 36px;
    height: 36px;
    border: 1px solid rgba(59,148,168,0.1);
    background: rgba(59,148,168,0.04);
}
.pwa-topbar .cw-theme-toggle svg {
    width: 18px;
    height: 18px;
}
.pwa-topbar-btn .pwa-badge {
    position: absolute;
    top: 2px;
    left: 2px;
    background: #ef4444;
    color: #fff;
    font-size: 0.5rem;
    font-weight: 700;
    min-width: 14px;
    height: 14px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 2px;
    box-shadow: 0 2px 6px rgba(239,68,68,0.3);
    pointer-events: none;
}
html[dir="rtl"] .pwa-topbar-btn .pwa-badge {
    left: auto;
    right: 2px;
}

/* ════════════════════════════════════════════════
   MAIN CONTENT — بين الشريطين مع تباعد
   ════════════════════════════════════════════════ */
.pwa-content {
    flex: 1;
    padding-top: 56px;   /* ارتفاع الشريط العلوي */
    padding-bottom: 72px; /* ارتفاع الشريط السفلي */
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* ════════════════════════════════════════════════
   BOTTOM NAVIGATION — ثابت في أسفل الشاشة
   ════════════════════════════════════════════════ */
.pwa-bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 72px;
    background: var(--cw-surface-2, #ffffff);
    border-top: 1px solid var(--cw-border, rgba(13,26,30,0.08));
    display: flex;
    align-items: stretch;
    z-index: 1000;
    direction: rtl;
    transition: background 0.3s ease, border-color 0.3s ease;
    padding-bottom: env(safe-area-inset-bottom, 0);
}
html[data-theme="dark"] .pwa-bottom-nav {
    background: #1a2c2e;
    border-top-color: rgba(91,192,190,0.12);
}

/* ── كل عنصر في الشريط السفلي ── */
.pwa-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    color: var(--cw-text-3, #4d6b73);
    text-decoration: none;
    padding: 8px 0 6px;
    cursor: pointer;
    transition: all 0.25s ease;
    border: none;
    background: none;
    font-family: 'Tajawal', sans-serif;
    position: relative;
    -webkit-tap-highlight-color: transparent;
}
.pwa-nav-item:active {
    transform: scale(0.92);
}

/* ── التاب النشط ── */
.pwa-nav-item.active {
    color: var(--cw-accent, #3b94a8);
}
.pwa-nav-item.active::before {
    content: '';
    position: absolute;
    top: 0;
    width: 32px;
    height: 3px;
    border-radius: 0 0 4px 4px;
    background: linear-gradient(90deg, var(--cw-accent, #3b94a8), #5BC0BE);
}

/* ── أيقونة التاب ── */
.pwa-nav-icon {
    font-size: 1.3rem;
    line-height: 1;
    transition: transform 0.3s ease;
}
.pwa-nav-item.active .pwa-nav-icon {
    transform: scale(1.1);
}

/* ── نص التاب ── */
.pwa-nav-label {
    font-size: 0.6rem;
    font-weight: 700;
    line-height: 1.2;
}

/* ── عداد الإشعارات في التاب ── */
.pwa-nav-badge {
    position: absolute;
    top: 4px;
    left: 50%;
    transform: translateX(-50%);
    background: #ef4444;
    color: #fff;
    font-size: 0.5rem;
    font-weight: 700;
    min-width: 16px;
    height: 16px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 3px;
    box-shadow: 0 2px 6px rgba(239,68,68,0.3);
    pointer-events: none;
}

/* ════════════════════════════════════════════════
   OVERLAY MENU (قائمة "إدارة" المنبثقة)
   ════════════════════════════════════════════════ */
.pwa-overlay-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    z-index: 998;
    animation: pwaFadeIn 0.2s ease;
}
.pwa-overlay-backdrop.show {
    display: block;
}

.pwa-overlay-menu {
    display: none;
    position: fixed;
    top: 0;
    bottom: 0;
    right: auto;
    left: 0;
    width: 55%;
    max-width: 360px;
    min-width: 240px;
    max-height: 100vh;
    overflow-y: auto;
    background: var(--cw-surface-2, #ffffff);
    border: none;
    border-right: 1px solid var(--cw-border, rgba(13,26,30,0.08));
    border-radius: 0;
    box-shadow: 8px 0 40px rgba(0,0,0,0.12);
    z-index: 999;
    padding: 20px 12px;
    direction: rtl;
    animation: pwaSlideInLeft 0.3s ease;
}
html[data-theme="dark"] .pwa-overlay-menu {
    background: #1a2c2e;
    border-right-color: rgba(91,192,190,0.12);
    box-shadow: 8px 0 40px rgba(0,0,0,0.4);
}
.pwa-overlay-menu.show {
    display: block;
}

.pwa-overlay-menu .menu-section-label {
    padding: 12px 16px 6px;
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--cw-text-3, #4d6b73);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.pwa-overlay-menu a,
.pwa-overlay-menu button.menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    color: var(--cw-text-1, #0d1a1e);
    text-decoration: none;
    font-size: 0.82rem;
    font-weight: 600;
    border-radius: 12px;
    margin-bottom: 2px;
    transition: all 0.2s ease;
    border: none;
    background: none;
    width: 100%;
    text-align: right;
    cursor: pointer;
    font-family: 'Tajawal', sans-serif;
}
.pwa-overlay-menu a:hover,
.pwa-overlay-menu button.menu-item:hover {
    background: rgba(59,148,168,0.06);
}
.pwa-overlay-menu .menu-divider {
    border: none;
    border-top: 1px solid var(--cw-border, rgba(13,26,30,0.08));
    margin: 6px 12px;
    opacity: 0.5;
}
.pwa-overlay-menu .menu-icon {
    font-size: 1.1rem;
    width: 28px;
    text-align: center;
    flex-shrink: 0;
    opacity: 0.8;
}
.pwa-overlay-menu .menu-icon svg {
    width: 20px;
    height: 20px;
    display: block;
    margin: 0 auto;
}
.pwa-overlay-menu .menu-danger {
    color: var(--cw-error, #ef4444) !important;
}

/* ════════════════════════════════════════════════
   BOTTOM NAV SUBMENUS (تظهر فوق الشريط السفلي)
   ════════════════════════════════════════════════ */
.pwa-submenu {
    display: none;
    position: fixed;
    bottom: 72px;
    /* left, right, width, max-width, margin يتم تحديدها عبر JS */
    max-height: 35vh;
    overflow-y: auto;
    background: rgba(255,255,255,0.95);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--cw-border, rgba(13,26,30,0.08));
    border-radius: 14px;
    box-shadow: 0 -4px 24px rgba(0,0,0,0.1);
    z-index: 999;
    padding: 8px 4px;
    scroll-padding-bottom: 20px;
    direction: rtl;
    animation: pwaSubmenuFadeIn 0.2s ease;
}
html[data-theme="dark"] .pwa-submenu {
    background: rgba(26,44,46,0.95);
    border-color: rgba(91,192,190,0.12);
    box-shadow: 0 -4px 24px rgba(0,0,0,0.3);
}
.pwa-submenu.show {
    display: block;
}

.pwa-submenu .pwa-submenu-header {
    padding: 8px 12px 10px;
    font-size: 0.78rem;
    font-weight: 800;
    color: var(--cw-text-1, #0d1a1e);
    border-bottom: 1px solid var(--cw-border, rgba(13,26,30,0.06));
    margin-bottom: 4px;
}
.pwa-submenu a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    color: var(--cw-text-1, #0d1a1e);
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 600;
    border-radius: 12px;
    transition: all 0.2s ease;
}
.pwa-submenu a:hover {
    background: rgba(59,148,168,0.06);
}
.pwa-submenu a:active {
    background: rgba(59,148,168,0.12);
    transform: scale(0.98);
}
.pwa-submenu a:last-child {
    margin-bottom: 24px;
}
.pwa-submenu .pwa-sub-icon {
    font-size: 1rem;
    width: 24px;
    text-align: center;
    flex-shrink: 0;
    opacity: 0.8;
}

/* Submenu backdrop */
.pwa-submenu-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.35);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    z-index: 998;
    animation: pwaFadeIn 0.2s ease;
}
.pwa-submenu-backdrop.show {
    display: block;
}

/* ════════════════════════════════════════════════
   OFFLINE INDICATOR
   ════════════════════════════════════════════════ */
.pwa-offline-bar {
    display: none;
    position: fixed;
    top: 56px;
    left: 0;
    right: 0;
    background: #f59e0b;
    color: #1a1a1a;
    text-align: center;
    padding: 6px 12px;
    font-size: 0.78rem;
    font-weight: 700;
    z-index: 999;
    font-family: 'Tajawal', sans-serif;
    direction: rtl;
    animation: pwaSlideDown 0.3s ease;
}
.pwa-offline-bar.show {
    display: block;
}

/* ════════════════════════════════════════════════
   INSTALL PROMPT
   ════════════════════════════════════════════════ */
.pwa-install-banner {
    display: none;
    position: fixed;
    bottom: 80px;
    left: 12px;
    right: 12px;
    background: var(--cw-surface-2, #ffffff);
    border: 1px solid var(--cw-accent-border, rgba(59,148,168,0.15));
    border-radius: 14px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.12);
    z-index: 997;
    padding: 12px 16px;
    display: none;
    align-items: center;
    gap: 12px;
    direction: rtl;
    animation: pwaSlideUp 0.3s ease;
}
html[data-theme="dark"] .pwa-install-banner {
    background: #1a2c2e;
    border-color: rgba(91,192,190,0.2);
    box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}
.pwa-install-banner.show {
    display: flex;
}
.pwa-install-banner .install-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    flex-shrink: 0;
}
.pwa-install-banner .install-info {
    flex: 1;
    min-width: 0;
}
.pwa-install-banner .install-title {
    font-weight: 700;
    font-size: 0.85rem;
    color: var(--cw-text-1, #0d1a1e);
}
.pwa-install-banner .install-desc {
    font-size: 0.72rem;
    color: var(--cw-text-3, #4d6b73);
}
.pwa-install-banner .install-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}
.pwa-install-banner .install-btn {
    padding: 8px 16px;
    background: var(--cw-accent, #3b94a8);
    color: #fff;
    border: none;
    border-radius: 10px;
    font-weight: 700;
    font-size: 0.78rem;
    cursor: pointer;
    font-family: 'Tajawal', sans-serif;
    transition: background 0.2s ease;
}
.pwa-install-banner .install-btn:hover {
    background: #2a7a8e;
}
.pwa-install-banner .install-dismiss {
    padding: 8px;
    background: none;
    border: none;
    color: var(--cw-text-3, #4d6b73);
    font-size: 0.78rem;
    cursor: pointer;
    font-family: 'Tajawal', sans-serif;
    border-radius: 8px;
}
.pwa-install-banner .install-dismiss:hover {
    background: rgba(0,0,0,0.04);
}

/* ════════════════════════════════════════════════
   ANIMATIONS
   ════════════════════════════════════════════════ */
@keyframes pwaFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}
@keyframes pwaSubmenuFadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}
@keyframes pwaSlideUp {
    from {
        transform: translateY(20px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}
@keyframes pwaSlideDown {
    from {
        transform: translateY(-100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}
@keyframes pwaSlideInRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}
@keyframes pwaSlideInLeft {
    from {
        transform: translateX(-100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* ════════════════════════════════════════════════
   RESPONSIVE — في الشاشات الكبيرة جداً
   ════════════════════════════════════════════════ */
@media (min-width: 1024px) {
    .pwa-app-shell {
        max-width: 480px;
        margin: 0 auto;
        border-left: 1px solid var(--cw-border);
        border-right: 1px solid var(--cw-border);
        min-height: 100vh;
        box-shadow: 0 0 40px rgba(0,0,0,0.06);
    }
}

/* ════════════════════════════════════════════════
   SAFE AREA (iPhone Notch)
   ════════════════════════════════════════════════ */
@supports (padding-top: env(safe-area-inset-top)) {
    .pwa-topbar {
        padding-top: env(safe-area-inset-top, 0);
        height: calc(56px + env(safe-area-inset-top, 0));
    }
    .pwa-content {
        padding-top: calc(56px + env(safe-area-inset-top, 0));
    }
    .pwa-bottom-nav {
        padding-bottom: env(safe-area-inset-bottom, 0);
        height: calc(72px + env(safe-area-inset-bottom, 0));
    }
    .pwa-overlay-menu {
        padding-top: calc(20px + env(safe-area-inset-top, 0px));
        padding-bottom: env(safe-area-inset-bottom, 0);
    }
    .pwa-content-inner {
        min-height: calc(100vh - 56px - 72px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
    }
}

/* ════════════════════════════════════════════════
   PWA CONTENT INNER — مسافات مناسبة للحواف (عرض وطول كامل)
   ════════════════════════════════════════════════ */
.pwa-content-inner {
    width: 100%;
    min-height: calc(100vh - 56px - 72px);
    padding: 16px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
}
@media (max-width: 480px) {
    .pwa-content-inner {
        padding: 12px;
    }
}

/* ════════════════════════════════════════════════
   PWA LOGO — شعار الموقع في الرأس
   ════════════════════════════════════════════════ */
.pwa-logo {
    display: flex;
    align-items: center;
    flex-shrink: 0;
    margin-left: 8px;
}
.pwa-logo svg text {
    font-family: 'Tajawal', sans-serif;
    direction: rtl;
}
html[data-theme="dark"] .pwa-logo svg text:last-child {
    fill: #E8F0F0 !important;
}

/* ════════════════════════════════════════════════
   PREVENT ZOOM — منع تغيير حجم الصفحة
   ════════════════════════════════════════════════ */
html {
    -webkit-text-size-adjust: 100%;
    touch-action: manipulation;
}

/* ════════════════════════════════════════════════
   PWA STANDALONE MODE — معالجة notch و gesture bar
   ════════════════════════════════════════════════ */
@media all and (display-mode: standalone) {
    .pwa-content {
        padding-top: calc(56px + constant(safe-area-inset-top, 0px)) !important;
        padding-top: calc(56px + env(safe-area-inset-top, 0px)) !important;
        padding-bottom: calc(72px + constant(safe-area-inset-bottom, 0px)) !important;
        padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px)) !important;
    }
    .pwa-content-inner {
        min-height: calc(100vh - 56px - 72px - constant(safe-area-inset-top, 0px) - constant(safe-area-inset-bottom, 0px)) !important;
        min-height: calc(100vh - 56px - 72px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)) !important;
    }
    .pwa-overlay-menu {
        padding-top: calc(20px + constant(safe-area-inset-top, 0px)) !important;
        padding-top: calc(20px + env(safe-area-inset-top, 0px)) !important;
    }
}

/* ════════════════════════════════════════════════
   إخفاء PWA components في سطح المكتب
   ════════════════════════════════════════════════ */
@media (min-width: 769px) {
    .pwa-topbar,
    .pwa-bottom-nav,
    .pwa-overlay-backdrop,
    .pwa-overlay-menu,
    .pwa-offline-bar,
    .pwa-install-banner,
    .pwa-submenu,
    .pwa-submenu-backdrop {
        display: none !important;
    }
    .pwa-logo {
        display: none !important;
    }
}
