@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans+Arabic:wght@300;400;500;600;700&display=swap');

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg:       #0a0a0a;
    --card:     #141414;
    --card2:    #1e1e1e;
    --border:   #2a2a2a;
    --text:     #f0f0f0;
    --muted:    #999;
    --dim:      #555;
    --primary:  #e50914;
    --primary-d:#b00710;
    --primary-l:rgba(229,9,20,.12);
    --radius:   10px;
    --radius-lg:16px;
    --header-h: 56px;
    --nav-h:    62px;
    --font:     'IBM Plex Sans Arabic', system-ui, sans-serif;
}

html { scroll-behavior: smooth; }

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    direction: rtl;
    min-height: 100vh;
    overflow-x: hidden;
    padding-top: var(--header-h);
    padding-bottom: var(--nav-h);
    -webkit-text-size-adjust: 100%;
}

/* iOS zoom fix */
input, select, textarea, button { font-family: var(--font); font-size: 16px; }
a { color: inherit; text-decoration: none; }
img { display: block; max-width: 100%; }
button { background: none; border: none; cursor: pointer; -webkit-tap-highlight-color: transparent; }

/* ============================================================
   HEADER
============================================================ */
.header {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: var(--header-h);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
    background: linear-gradient(to bottom, rgba(0,0,0,.9) 0%, transparent 100%);
    transition: background .3s;
}
.header.solid { background: rgba(10,10,10,.98); border-bottom: 1px solid var(--border); }

.header-logo {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--primary);
    letter-spacing: -0.5px;
}

.header-actions { display: flex; align-items: center; gap: .35rem; }

.icon-btn {
    width: 38px; height: 38px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 50%;
    font-size: 1.1rem;
    position: relative;
    transition: background .15s;
    -webkit-tap-highlight-color: transparent;
}
.icon-btn:active { background: rgba(255,255,255,.1); }

.notif-dot {
    position: absolute;
    top: 6px; left: 6px;
    width: 8px; height: 8px;
    background: var(--primary);
    border-radius: 50%;
    border: 1.5px solid var(--bg);
    display: none;
}
.notif-dot.show { display: block; }

/* ============================================================
   BOTTOM NAV
============================================================ */
.bottom-nav {
    isolation: isolate;
    -webkit-isolation: isolate;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: var(--nav-h);
    background: #0a0a0a;

    border-top: 1px solid var(--border);
    display: flex;
    z-index: 9999;
    padding-bottom: env(safe-area-inset-bottom);
}

.nav-item {
    flex: 1;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    gap: 3px;
    color: var(--dim);
    font-size: .62rem;
    font-weight: 500;
    transition: color .15s;
    -webkit-tap-highlight-color: transparent;
}
.nav-item .nav-icon { font-size: 1.3rem; line-height: 1; }
.nav-item.active { color: var(--primary); }
.nav-item.active .nav-icon { transform: scale(1.1); }

/* ============================================================
   HERO BANNER — Netflix Style
============================================================ */
.hero {
    position: relative;
    width: 100%;
    height: 100vw;
    max-height: 580px;
    min-height: 320px;
    overflow: hidden;
    margin-top: calc(-1 * var(--header-h));
}

.hero-slide {
    position: absolute; inset: 0;
    opacity: 0;
    transition: opacity .7s ease;
}
.hero-slide.active { opacity: 1; }

.hero-bg {
    width: 100%; height: 100%;
    object-fit: cover;
    object-position: center top;
}

.hero-overlay {
    position: absolute; inset: 0;
    background: linear-gradient(
        to bottom,
        rgba(0,0,0,.2) 0%,
        rgba(0,0,0,.1) 40%,
        rgba(10,10,10,.85) 75%,
        var(--bg) 100%
    );
}

.hero-content {
    position: absolute;
    bottom: 0; left: 0; right: 0;
    padding: 1.25rem 1rem 1.5rem;
}

.hero-badge {
    display: inline-flex; align-items: center; gap: .3rem;
    background: var(--primary);
    color: #fff;
    font-size: .65rem; font-weight: 700;
    padding: 3px 10px;
    border-radius: 4px;
    margin-bottom: .5rem;
    letter-spacing: .04em;
}

.hero-title {
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1.2;
    margin-bottom: .4rem;
    text-shadow: 0 2px 8px rgba(0,0,0,.8);
}

.hero-meta {
    display: flex; align-items: center; gap: .6rem;
    margin-bottom: .6rem;
    font-size: .78rem; color: var(--muted);
}
.hero-rating { color: #f5c518; font-weight: 600; }

.hero-desc {
    font-size: .8rem;
    color: #bbb;
    line-height: 1.6;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin-bottom: .85rem;
}

.hero-actions { display: flex; gap: .6rem; }

.hero-btn {
    display: inline-flex; align-items: center; gap: .4rem;
    padding: .55rem 1.2rem;
    border-radius: 8px;
    font-size: .85rem; font-weight: 600;
    border: none; cursor: pointer;
    font-family: var(--font);
    transition: all .15s;
    -webkit-tap-highlight-color: transparent;
}
.hero-btn:active { transform: scale(.96); }
.hero-btn-primary { background: #fff; color: #000; }
.hero-btn-secondary { background: rgba(255,255,255,.15); color: #fff; backdrop-filter: blur(4px); }

/* Dots */
.hero-dots {
    position: absolute;
    bottom: 1rem; left: 50%; transform: translateX(-50%);
    display: flex; gap: 5px;
    z-index: 5;
}
.hero-dot {
    width: 5px; height: 5px;
    border-radius: 50%;
    background: rgba(255,255,255,.35);
    transition: all .3s;
    border: none; cursor: pointer;
    padding: 0;
}
.hero-dot.active { background: var(--primary); width: 16px; border-radius: 3px; }

/* ============================================================
   SECTIONS
============================================================ */
.section { margin-bottom: 1.5rem; }

.section-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 1rem;
    margin-bottom: .65rem;
}

.section-title {
    font-size: .95rem;
    font-weight: 700;
}

.section-more {
    font-size: .75rem;
    color: var(--primary);
    -webkit-tap-highlight-color: transparent;
}

/* Horizontal scroll */
.cards-row {
    display: flex;
    gap: .65rem;
    overflow-x: auto;
    padding: .25rem 1rem;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x mandatory;
}
.cards-row::-webkit-scrollbar { display: none; }

/* ============================================================
   MOVIE CARD
============================================================ */
.movie-card {
    flex-shrink: 0;
    width: 120px;
    scroll-snap-align: start;
    position: relative;
    -webkit-tap-highlight-color: transparent;
    cursor: pointer;
}

.movie-card-poster {
    width: 100%;
    aspect-ratio: 2/3;
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--card2);
    position: relative;
    margin-bottom: .4rem;
}

.movie-card-poster img {
    width: 100%; height: 100%;
    object-fit: cover;
    transition: transform .3s;
}
.movie-card:active .movie-card-poster img { transform: scale(1.04); }

.movie-card-rating {
    position: absolute;
    bottom: 5px; right: 5px;
    background: rgba(0,0,0,.75);
    color: #f5c518;
    font-size: .62rem; font-weight: 700;
    padding: 2px 5px;
    border-radius: 4px;
    backdrop-filter: blur(4px);
}

.save-btn {
    position: absolute;
    top: 6px; left: 6px;
    width: 28px; height: 28px;
    background: rgba(0,0,0,.65);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: .8rem;
    backdrop-filter: blur(4px);
    border: none; cursor: pointer;
    transition: transform .2s;
    -webkit-tap-highlight-color: transparent;
    z-index: 2;
}
.save-btn:active { transform: scale(1.3); }
.save-btn.saved { color: var(--primary); }

.movie-card-title {
    font-size: .75rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text);
}

.movie-card-year {
    font-size: .65rem;
    color: var(--muted);
    margin-top: 1px;
}

/* ============================================================
   MOVIE DETAIL PAGE
============================================================ */
.movie-page { min-height: 100vh; }

.movie-backdrop-wrap {
    position: relative;
    height: 56vw;
    max-height: 320px;
    min-height: 200px;
    margin-top: calc(-1 * var(--header-h));
}

.movie-backdrop {
    width: 100%; height: 100%;
    object-fit: cover;
    object-position: center top;
}

.movie-backdrop-overlay {
    position: absolute; inset: 0;
    background: linear-gradient(
        to bottom,
        rgba(0,0,0,.3) 0%,
        rgba(10,10,10,.9) 80%,
        var(--bg) 100%
    );
}

.movie-back-btn {
    position: absolute;
    top: calc(var(--header-h) + .75rem);
    right: 1rem;
    width: 36px; height: 36px;
    background: rgba(0,0,0,.6);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 1rem;
    backdrop-filter: blur(4px);
    -webkit-tap-highlight-color: transparent;
}

.movie-body { padding: 0 1rem 2rem; margin-top: -1rem; position: relative; }

.movie-header { display: flex; gap: .9rem; align-items: flex-end; margin-bottom: 1rem; }

.movie-poster-wrap {
    position: relative;
    flex-shrink: 0;
    width: 100px;
}
.movie-poster-wrap img {
    width: 100px;
    aspect-ratio: 2/3;
    object-fit: cover;
    border-radius: var(--radius);
    box-shadow: 0 8px 24px rgba(0,0,0,.6);
}

.movie-save-btn {
    position: absolute;
    top: -8px; left: -8px;
    width: 32px; height: 32px;
    background: var(--card2);
    border: 2px solid var(--border);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: .85rem;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: all .2s;
}
.movie-save-btn.saved { background: var(--primary-l); border-color: var(--primary); }
.movie-save-btn:active { transform: scale(1.2); }

.movie-info { flex: 1; min-width: 0; padding-bottom: .25rem; }

.movie-title {
    font-size: 1.15rem;
    font-weight: 700;
    line-height: 1.25;
    margin-bottom: .4rem;
}

.movie-tags {
    display: flex; flex-wrap: wrap; gap: .3rem;
    margin-bottom: .45rem;
}

.tag {
    background: var(--card2);
    border: 1px solid var(--border);
    font-size: .65rem;
    padding: 2px 7px;
    border-radius: 4px;
    color: var(--muted);
}
.tag-rating { color: #f5c518; border-color: rgba(245,197,24,.3); background: rgba(245,197,24,.08); }

.movie-genres { font-size: .75rem; color: var(--muted); }

/* Watch Button */
.watch-btn {
    display: flex; align-items: center; justify-content: center; gap: .5rem;
    width: 100%;
    padding: .8rem;
    background: var(--primary);
    color: #fff;
    border-radius: var(--radius);
    font-size: .95rem; font-weight: 700;
    margin: 1rem 0;
    border: none; cursor: pointer;
    font-family: var(--font);
    -webkit-tap-highlight-color: transparent;
    transition: all .15s;
}
.watch-btn:active { background: var(--primary-d); transform: scale(.98); }

/* Overview */
.movie-overview-title { font-size: .85rem; font-weight: 700; color: var(--muted); margin-bottom: .45rem; }
.movie-overview-text  { font-size: .85rem; line-height: 1.75; color: #ccc; margin-bottom: 1.25rem; }

/* Cast */
.cast-row {
    display: flex; gap: .75rem;
    overflow-x: auto; padding-bottom: .25rem;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
}
.cast-row::-webkit-scrollbar { display: none; }

.cast-item { flex-shrink: 0; width: 68px; text-align: center; }
.cast-photo {
    width: 68px; height: 68px;
    border-radius: 50%;
    object-fit: cover;
    background: var(--card2);
    margin: 0 auto .35rem;
    border: 2px solid var(--border);
}
.cast-name { font-size: .62rem; font-weight: 600; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cast-char { font-size: .58rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Player */
.player-wrap {
    display: none;
    position: relative;
    width: 100%;
    aspect-ratio: 16/9;
    background: #000;
    border-radius: var(--radius);
    overflow: hidden;
    margin: 1rem 0;
}
.player-wrap.show { display: block; }
.player-wrap iframe { width: 100%; height: 100%; border: none; }
.player-close {
    position: absolute;
    top: 8px; right: 8px;
    background: rgba(0,0,0,.7);
    color: #fff;
    border: none; cursor: pointer;
    padding: .3rem .65rem;
    border-radius: 6px;
    font-size: .75rem;
    font-family: var(--font);
    z-index: 10;
    -webkit-tap-highlight-color: transparent;
}

/* ============================================================
   SEARCH PAGE
============================================================ */
.search-page { padding: 1rem; }

.search-bar-wrap {
    position: relative;
    margin-bottom: 1rem;
}
.search-input-field {
    width: 100%;
    padding: .7rem 1rem .7rem 2.8rem;
    background: var(--card2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 16px;
    font-family: var(--font);
    -webkit-appearance: none;
}
.search-input-field:focus { outline: none; border-color: var(--primary); }
.search-icon { position: absolute; left: .9rem; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 1rem; }

.search-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: .6rem;
}

.search-card {
    position: relative;
    border-radius: var(--radius);
    overflow: hidden;
    aspect-ratio: 2/3;
    background: var(--card2);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}
.search-card img { width: 100%; height: 100%; object-fit: cover; }
.search-card-info {
    position: absolute; bottom: 0; left: 0; right: 0;
    padding: .5rem .4rem .35rem;
    background: linear-gradient(to top, rgba(0,0,0,.85), transparent);
    font-size: .65rem; font-weight: 600;
}

/* ============================================================
   FAVORITES & PROFILE PAGES
============================================================ */
.page-header {
    padding: 1rem 1rem .5rem;
    font-size: 1rem;
    font-weight: 700;
}

.empty-state {
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    min-height: 40vh;
    gap: .75rem; text-align: center;
    padding: 2rem;
}
.empty-icon { font-size: 3rem; }
.empty-title { font-size: 1rem; font-weight: 700; }
.empty-sub   { font-size: .83rem; color: var(--muted); }

.profile-header {
    display: flex; flex-direction: column;
    align-items: center;
    padding: 1.5rem 1rem 1rem;
    text-align: center;
}
.profile-avatar {
    width: 80px; height: 80px;
    border-radius: 50%;
    object-fit: cover;
    border: 3px solid var(--primary);
    margin-bottom: .75rem;
}
.profile-name  { font-size: 1.05rem; font-weight: 700; }
.profile-email { font-size: .8rem; color: var(--muted); margin-top: .2rem; }

.profile-stats {
    display: flex;
    margin: 1rem;
    background: var(--card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    overflow: hidden;
}
.profile-stat { flex: 1; padding: .9rem .5rem; text-align: center; }
.profile-stat + .profile-stat { border-right: 1px solid var(--border); }
.profile-stat-num   { font-size: 1.3rem; font-weight: 700; color: var(--primary); }
.profile-stat-label { font-size: .65rem; color: var(--muted); margin-top: 2px; }

.menu-list { margin: 0 1rem; display: flex; flex-direction: column; gap: .4rem; }
.menu-item {
    display: flex; align-items: center; gap: .75rem;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: .85rem 1rem;
    font-size: .88rem;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    width: 100%;
    font-family: var(--font);
    color: var(--text);
    transition: background .15s;
}
.menu-item:active { background: var(--card2); }
.menu-item-arrow { margin-right: auto; color: var(--dim); font-size: .8rem; }
.menu-item-danger { color: #ff4444; }

/* ============================================================
   AUTH PAGES
============================================================ */
.auth-page {
    min-height: 100vh;
    display: flex; align-items: center; justify-content: center;
    padding: 1.5rem;
}
.auth-box { width: 100%; max-width: 360px; }
.auth-logo { font-size: 2rem; font-weight: 700; color: var(--primary); text-align: center; margin-bottom: 1.75rem; }
.auth-title { font-size: 1.1rem; font-weight: 700; margin-bottom: 1.25rem; text-align: center; }

.auth-form { display: flex; flex-direction: column; gap: .85rem; }
.form-group { display: flex; flex-direction: column; gap: .35rem; }
.form-label { font-size: .72rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.form-input {
    padding: .7rem .9rem;
    background: var(--card2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 16px;
    font-family: var(--font);
    -webkit-appearance: none;
    transition: border-color .15s;
}
.form-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(229,9,20,.12); }

.auth-btn {
    width: 100%; padding: .8rem;
    background: var(--primary); color: #fff;
    border: none; border-radius: var(--radius);
    font-size: .95rem; font-weight: 700;
    font-family: var(--font);
    cursor: pointer;
    margin-top: .25rem;
    -webkit-tap-highlight-color: transparent;
    transition: background .15s;
}
.auth-btn:active { background: var(--primary-d); }

.auth-footer { text-align: center; font-size: .83rem; color: var(--muted); margin-top: 1rem; }
.auth-footer a { color: var(--primary); font-weight: 600; }

/* ============================================================
   TOAST
============================================================ */
.toast-wrap {
    position: fixed;
    bottom: calc(var(--nav-h) + 12px);
    left: 50%; transform: translateX(-50%);
    z-index: 300;
    width: 90%; max-width: 340px;
    display: flex; flex-direction: column; gap: 8px;
    pointer-events: none;
}
.toast {
    display: flex; align-items: center; gap: .5rem;
    padding: .7rem 1rem;
    background: var(--card2);
    border-radius: var(--radius);
    font-size: .83rem;
    box-shadow: 0 4px 20px rgba(0,0,0,.5);
    opacity: 0; transform: translateY(8px);
    transition: all .25s ease;
    pointer-events: auto;
    border-right: 3px solid var(--border);
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.success { border-color: #22c55e; }
.toast.error   { border-color: var(--primary); }
.toast.info    { border-color: var(--blue, #3b82f6); }

/* ============================================================
   SKELETON
============================================================ */
.skeleton {
    background: linear-gradient(90deg, var(--card) 25%, var(--card2) 50%, var(--card) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.4s infinite;
    border-radius: var(--radius);
}
@keyframes shimmer { to { background-position: -200% 0; } }

.skeleton-hero { height: 100vw; max-height: 580px; min-height: 320px; margin-top: calc(-1 * var(--header-h)); border-radius: 0; }
.skeleton-card { width: 120px; height: 180px; flex-shrink: 0; }

/* ============================================================
   LOADER
============================================================ */
.page-loader {
    position: fixed; top: var(--header-h); left: 0; right: 0;
    height: 3px; z-index: 200; overflow: hidden;
}
.page-loader-bar {
    height: 100%; width: 100%;
    background: var(--primary);
    animation: loading 1s ease infinite;
    transform-origin: right;
}
@keyframes loading { 0% { transform: scaleX(0) translateX(0); } 50% { transform: scaleX(.6) translateX(-30%); } 100% { transform: scaleX(0) translateX(-100%); } }
.page-loader.hidden { display: none; }

/* Categories page */
.categories-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: .65rem;
    padding: 0 1rem;
}
.category-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem 1rem;
    display: flex; flex-direction: column;
    align-items: center; gap: .5rem;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: background .15s;
    text-decoration: none;
}
.category-card:active { background: var(--card2); }
.category-icon { font-size: 1.75rem; }
.category-name { font-size: .82rem; font-weight: 600; text-align: center; }

/* ---- Fix: منع تحرك Header و BottomNav عند Scroll ---- */
.header {
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
    will-change: transform;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
}

.bottom-nav {
    isolation: isolate;
    -webkit-isolation: isolate;
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
    will-change: transform;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    /* تأكيد الثبات */
    position: fixed !important;
    bottom: 0 !important;
}

/* منع الـ body من التحرك تحت الـ nav */
body {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: none;
}
