/* ========================================
   LAYOUT — Mobile First, All Devices
   ======================================== */

/* Base Body */
body {
    padding-top: 90px;
    padding-bottom: 90px;
    overflow-x: hidden;
    min-height: 100vh;
}

/* Main Container */
.main-container {
    display: flex;
    min-height: calc(100vh - 180px);
    max-width: 2200px;
    margin: 0 auto;
    padding: 10px 270px; /* Desktop: room for side ads */
    overflow: hidden;
}

.content-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: calc(100vh - 180px);
}

/* ========================================
   Watermark Overlay
   ======================================== */
.watermark-overlay {
    position: fixed;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    pointer-events: none;
    z-index: 9999;
    background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='280' height='140'%3E%3Ctext x='50%25' y='50%25' dominant-baseline='middle' text-anchor='middle' fill='rgba(130,130,130,0.15)' font-size='34' font-family='Cairo, sans-serif' font-weight='800'%3Eبدر الجمل%3C/text%3E%3C/svg%3E");
    background-repeat: repeat;
    transform: rotate(-35deg);
}

/* ========================================
   Ad Spaces
   ======================================== */
.ad-space {
    background-color: var(--ad-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--ad-text);
    font-size: 0.9rem;
    z-index: 2000;
    overflow: hidden;
}

.ad-top {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 90px;
    border-bottom: 1px dashed var(--surface-border);
}

.ad-bottom {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 90px;
    border-top: 1px dashed var(--surface-border);
}

.ad-side {
    position: fixed;
    top: 90px;
    bottom: 90px;
    width: 250px;
}

.ad-right {
    right: 0;
    border-left: 1px dashed var(--surface-border);
}

.ad-left {
    left: 0;
    border-right: 1px dashed var(--surface-border);
}

/* ========================================
   App Header
   ======================================== */
.app-header {
    position: sticky;
    top: 5px;
    z-index: 1001;
    background: var(--surface-color);
    padding: 8px 20px;
    border-radius: var(--card-radius);
    border: 1px solid var(--surface-border);
    margin-bottom: 15px;
    box-shadow: var(--shadow-premium);
    /* backdrop-filter: blur(20px); */
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}

.header-center-logo {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    top: 10px;
    display: flex;
    justify-content: center;
}

/* ========================================
   App View (main scrollable panel)
   ======================================== */
.app-view {
    flex: 1;
    padding: 15px;
    background: var(--surface-color);
    /* backdrop-filter: blur(20px); */
    border: 1px solid var(--surface-border);
    border-radius: var(--card-radius);
    width: 100%;
    max-width: 1600px;
    margin: 0 auto;
    overflow-y: auto;
    overflow-x: hidden;
    box-shadow: var(--shadow-premium);
    scrollbar-width: thin;
    scrollbar-color: var(--primary-color) rgba(255,255,255,0.05);
    padding-bottom: 80px;
    -webkit-overflow-scrolling: touch;
}

.app-view::-webkit-scrollbar { width: 6px; }
.app-view::-webkit-scrollbar-track { background: rgba(255,255,255,0.05); border-radius: 10px; }
.app-view::-webkit-scrollbar-thumb { background: var(--primary-gradient); border-radius: 10px; }

/* ========================================
   Home/Pages: Stages Grid — عرض كقائمة (List) عمودية
   كل عنصر يأخذ صفاً كاملاً بعرض الشاشة (عمود واحد)
   لتوفير المساحة وزيادة مجال الرؤية في كل صفحات المنصة
   ======================================== */
.stages-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    margin-top: 15px;
    padding-bottom: 20px;
}

.stage-card {
    background: linear-gradient(145deg, rgba(30, 41, 59, 0.4), rgba(15, 23, 42, 0.6));
    border: 1px solid var(--surface-border);
    border-radius: 12px;
    padding: 8px 4px;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    min-height: 80px;
    -webkit-tap-highlight-color: transparent;
}

.stage-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; height: 4px;
    background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
    opacity: 0;
    transition: var(--transition);
}

.stage-card:hover, .stage-card:active {
    transform: translateY(-4px) scale(1.02);
    box-shadow: var(--shadow-hover);
    border-color: var(--primary-color);
    background: linear-gradient(145deg, rgba(99, 102, 241, 0.1), rgba(15, 23, 42, 0.8));
}

.stage-icon {
    font-size: 1.4rem;
    margin-bottom: 3px;
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    transition: var(--transition);
}

.stage-title {
    font-size: 0.75rem;
    font-weight: 700;
    margin-bottom: 0;
    color: var(--text-primary);
}

.stage-desc {
    color: var(--text-secondary);
    font-size: 0.85rem;
}

/* ========================================
   Admin Panel
   ======================================== */
.admin-panel { max-width: 800px; margin: 0 auto; }

.form-group { margin-bottom: 20px; }

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: var(--text-primary);
}

.form-control {
    width: 100%;
    padding: 12px 15px;
    border-radius: 8px;
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid var(--surface-border);
    color: white;
    font-size: max(16px, 1rem); /* Prevents iOS auto-zoom */
    transition: var(--transition);
}

.form-control:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.2);
}

.file-upload-box {
    border: 2px dashed var(--surface-border);
    border-radius: var(--card-radius);
    padding: 20px;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
    background: rgba(30, 41, 59, 0.4);
}

.file-upload-box:hover, .file-upload-box.dragover {
    border-color: var(--primary-color);
    background: rgba(79, 70, 229, 0.05);
}

.file-upload-icon { font-size: 2rem; color: var(--text-secondary); margin-bottom: 10px; }
.file-input { display: none; }

/* ========================================
   Breadcrumbs
   ======================================== */
.breadcrumbs {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 20px;
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.breadcrumb-item {
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}

.breadcrumb-item:hover { color: var(--primary-color); }
.breadcrumb-separator { color: var(--surface-border); }

/* ========================================
   List Group
   ======================================== */
.list-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
}

.list-item {
    background: rgba(30, 41, 59, 0.6);
    border: 1px solid var(--surface-border);
    padding: 15px;
    border-radius: 12px;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 12px;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.list-item:hover, .list-item:active {
    background: rgba(30, 41, 59, 0.9);
    border-color: var(--primary-color);
}

.list-item span {
    font-size: 0.75rem;
    line-height: 1.4;
    word-break: break-word;
    white-space: normal;
    flex: 1;
}

/* ========================================
   Content Viewers
   ======================================== */
.viewer-container {
    background: transparent;
    color: var(--text-primary);
    padding: 0;
    border-radius: var(--card-radius);
    min-height: 400px;
    direction: rtl;
    line-height: 1.8;
}

.viewer-content img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin: 10px 0;
}

/* ========================================
   Button / Icon touch targets
   ======================================== */
.btn {
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.btn-icon {
    background: none;
    border: none;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    padding: 10px;
    border-radius: 8px;
    transition: var(--transition);
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-icon:hover, .btn-icon:active { background: rgba(255,255,255,0.08); }

/* ========================================
   RESPONSIVE — Tablet (≤1024px)
   ======================================== */
@media (max-width: 1024px) {
    .ad-side { display: none; }
    .main-container { padding: 10px 15px; }
    body { padding-top: 70px; padding-bottom: 70px; }
    .ad-top, .ad-bottom { height: 70px; }
    .main-container { min-height: calc(100vh - 140px); }
    .content-area { min-height: calc(100vh - 140px); }
}

/* ========================================
   RESPONSIVE — Mobile (≤768px)
   ======================================== */
@media (max-width: 768px) {
    body { padding-top: 60px; padding-bottom: 60px; }
    .ad-top, .ad-bottom { height: 60px; }
    .main-container { padding: 8px 10px; min-height: calc(100vh - 120px); }
    .content-area { min-height: calc(100vh - 120px); }

    .app-header {
        padding: 12px;
        flex-direction: column;
        align-items: center;
        text-align: center;
        gap: 12px;
    }

    .header-center-logo {
        position: static;
        transform: none;
        margin-bottom: 5px;
    }

    .nav-links {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
        width: 100%;
        justify-content: center;
    }

    .nav-btn {
        font-size: 0.72rem;
        padding: 6px 8px;
        flex: 1 1 auto;
        justify-content: center;
        min-height: 38px;
    }

    .platform-title { font-size: 0.95rem; }
    .platform-subtitle { font-size: 0.72rem; }

    .app-view {
        padding: 10px;
        padding-bottom: 70px;
        border-radius: 12px;
    }

    .stages-grid {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .stage-card { min-height: 70px; }

    .list-group { grid-template-columns: 1fr; gap: 10px; }
    .list-item { padding: 12px; }
    .breadcrumbs { font-size: 0.8rem; gap: 5px; margin-bottom: 12px; }
    .viewer-container { min-height: 250px; }

    /* Tables scroll horizontally on mobile */
    .notes-reader table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        white-space: nowrap;
    }

    .av-player-container { border-radius: 15px !important; }
}

/* ========================================
   RESPONSIVE — Small Phone (≤480px)
   ======================================== */
@media (max-width: 480px) {
    body { padding-top: 50px; padding-bottom: 50px; }
    .ad-top, .ad-bottom { height: 50px; }
    .main-container { padding: 5px 6px; }

    .stages-grid { grid-template-columns: 1fr; gap: 6px; }
    .stage-card { min-height: 62px; padding: 5px 2px; }
    .stage-icon { font-size: 1.1rem; }
    .stage-title { font-size: 0.68rem; }

    .nav-btn { font-size: 0.68rem; padding: 5px 6px; min-height: 36px; }
    .btn { padding: 9px 12px; font-size: 0.88rem; }
    .form-control { padding: 10px 12px; }
    .list-item { padding: 10px; gap: 8px; font-size: 0.88rem; }
}

/* ========================================
   RESPONSIVE — Landscape Phone
   ======================================== */
@media (max-height: 600px) and (orientation: landscape) {
    body { padding-top: 50px; padding-bottom: 50px; }
    .ad-top, .ad-bottom { height: 50px; }
    .app-view { padding-bottom: 55px; }
}

/* ========================================
   إصلاحات الموبايل — منع overflow ومشاكل العرض
   ======================================== */

/* منع أي overflow أفقي على الصفحة */
html, body {
    overflow-x: hidden;
    max-width: 100vw;
}

/* ضمان عدم تجاوز أي عنصر حدود الـ viewport */
.main-container, .content-area, .app-view {
    max-width: 100%;
    box-sizing: border-box;
}

/* إصلاح stages-grid على الموبايل */
@media (max-width: 768px) {
    .stages-grid {
        width: 100%;
        max-width: 100%;
        overflow: hidden;
        box-sizing: border-box;
    }

    .stage-card {
        word-break: break-word;
        overflow: hidden;
    }

    /* إصلاح الـ fade-in container على الموبايل */
    .fade-in {
        max-width: 100%;
        overflow-x: hidden;
    }

    /* منع overflow الـ inline styles */
    [style*="margin-bottom"] {
        max-width: 100%;
        box-sizing: border-box;
    }
}

/* إصلاح خاص للشاشات الصغيرة جداً (أقل من 360px) */
@media (max-width: 360px) {
    .stages-grid {
        grid-template-columns: 1fr !important;
        gap: 5px;
    }

    .stage-card {
        min-height: 58px;
        padding: 4px 2px;
    }

    .stage-icon {
        font-size: 1rem;
    }

    .stage-title {
        font-size: 0.62rem;
    }

    .nav-btn {
        font-size: 0.62rem;
        padding: 4px 5px;
        min-height: 34px;
    }

    .platform-title {
        font-size: 0.85rem;
    }
}

/* ================================================================
   عناصر الشاشة الرئيسية (المراحل/الصفوف/المواد) تعرض كنظام شبكة (Grid)
   كما كانت في الأصل — رُبِط التوزيع بها عند كونها شبكة
   ================================================================ */

.stage-card {
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    justify-content: flex-start !important;
    text-align: right !important;
    gap: 12px !important;
    min-height: 0 !important;
    padding: 12px 14px !important;
    width: 100% !important;
    box-sizing: border-box !important;
    overflow: hidden !important;
}

/* شريط لون جانبي يمين بدل الشريط العلوي */
.stage-card::before {
    top: 0 !important;
    bottom: 0 !important;
    left: auto !important;
    right: 0 !important;
    height: 100% !important;
    width: 4px !important;
    opacity: 1 !important;
    border-radius: 12px 0 0 12px !important;
}

.stage-card:hover, .stage-card:active {
    transform: translateX(-4px) !important;
    box-shadow: var(--shadow-hover);
}

.stage-icon {
    margin-bottom: 0 !important;
    font-size: 1.25rem !important;
    width: 26px !important;
    text-align: center !important;
    flex-shrink: 0 !important;
}

.stage-title {
    font-size: 0.92rem !important;
    text-align: right !important;
}

/* إخفاء شارات مطلقة (LIVE/OPEN) إذا سببت تزاحم في وضع الصف */
.stage-card > div[style*="position: absolute"] {
    display: none !important;
}

/* ================================================================
   الشاشة الرئيسية: وضع القائمة (List) بدل الشبكة
   - كل عنصر يأخذ صفاً كاملاً بعرض الشاشة (عمود واحد) لتوفير المساحة
     وزيادة مجال الرؤية، دون التأثير على شاشات المراحل/الصفوف/المواد.
   ================================================================ */
.stages-grid.home-list {
    display: grid;
    grid-template-columns: 1fr !important;
    gap: 8px;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}
