/* ===== منصة نور — التصميم العام (RTL) ===== */
:root {
    --bg: #f9f9f9;
    --surface: #ffffff;
    --text: #0f0f0f;
    --text-muted: #606060;
    --border: #e5e5e5;
    --chip: #f2f2f2;         /* خلفيات رمادية فاتحة: أزرار وشرائح */
    --chip-hover: #e5e5e5;
    --primary: #0b6e4f;      /* أخضر */
    --primary-dark: #095c42;
    --accent: #c9a227;       /* ذهبي */
    --danger: #c0392b;
    --radius: 12px;
    --header-h: 56px;
    --shadow: 0 1px 3px rgba(0,0,0,.12);
    font-family: "Segoe UI", Tahoma, "Noto Naskh Arabic", "Amiri", system-ui, sans-serif;
    color-scheme: light;
}

/* الوضع الليلي: تُضبط data-theme على <html> من site.js وتُحفظ في localStorage */
[data-theme="dark"] {
    --bg: #0f0f0f;
    --surface: #212121;
    --text: #f1f1f1;
    --text-muted: #aaaaaa;
    --border: #3f3f3f;
    --chip: #272727;
    --chip-hover: #3d3d3d;
    --shadow: 0 1px 3px rgba(0,0,0,.5);
    color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: inherit;
    line-height: 1.6;
}

a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }

/* ===== الهيدر ===== */
/* ponytail: الهيدر وشريط التصنيفات داخل حاوية لاصقة واحدة — لا حساب إزاحات يدوي */
.topbar {
    position: sticky;
    top: 0;
    z-index: 50;
    background: var(--surface);
}

.app-header {
    min-height: var(--header-h);
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 0 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.header-right, .header-left { display: flex; align-items: center; gap: 12px; }
.header-left { margin-inline-start: auto; }

.brand { display: flex; align-items: center; gap: 6px; font-weight: 700; font-size: 20px; }
.brand-mark { color: var(--primary); font-size: 24px; }
.brand-text { color: var(--text); }

.icon-btn {
    background: none; border: none; font-size: 20px; cursor: pointer;
    width: 40px; height: 40px; border-radius: 50%;
}
.icon-btn:hover { background: var(--chip); }
.menu-toggle { display: none; }

.header-search {
    flex: 1 1 auto;
    min-width: 0;          /* بدونها لا ينكمش الحقل فيطفح الهيدر على الشاشات الصغيرة */
    max-width: 640px;
    display: flex;
    margin: 0 auto;
}
.header-search input {
    flex: 1;
    min-width: 0;
    width: 100%;
    height: 40px;
    padding: 0 16px;
    border: 1px solid var(--border);
    border-radius: 20px 0 0 20px;
    font-size: 15px;
    font-family: inherit;
    outline: none;
}
.header-search input:focus { border-color: var(--primary); }
.search-btn {
    width: 60px;
    border: 1px solid var(--border);
    border-right: none;
    border-radius: 0 20px 20px 0;
    background: var(--chip);
    cursor: pointer;
    font-size: 16px;
}
.search-btn:hover { background: var(--chip-hover); }

.btn-upload, .btn-login {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 14px; border-radius: 20px;
    font-weight: 600; font-size: 14px;
    border: 1px solid var(--border);
    background: var(--surface);
    cursor: pointer;
}
.btn-upload:hover, .btn-login:hover { background: var(--chip); }
.btn-upload .plus { font-size: 18px; color: var(--primary); }
.btn-login { color: var(--primary); border-color: var(--primary); }

/* قائمة الحساب */
.account-menu { position: relative; }
.avatar-btn { border: none; background: none; cursor: pointer; padding: 0; }
.avatar-btn img { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; border: 1px solid var(--border); }
.dropdown {
    position: absolute; top: 46px; left: 0;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow);
    min-width: 220px; padding: 8px 0; z-index: 60;
}
.dropdown a, .dropdown .link-btn {
    display: block; width: 100%; text-align: right;
    padding: 10px 16px; font-size: 14px;
    background: none; border: none; cursor: pointer; font-family: inherit;
}
.dropdown a:hover, .dropdown .link-btn:hover { background: var(--chip); }
.dropdown-header { padding: 10px 16px; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; }
.dropdown-header span { color: var(--text-muted); font-size: 12px; }
.dropdown-divider { height: 1px; background: var(--border); margin: 6px 0; }

/* ===== شريط التصنيفات ===== */
.cat-bar-wrap { background: var(--surface); border-bottom: 1px solid var(--border); }
.cat-bar { display: flex; gap: 10px; overflow-x: auto; padding: 10px 16px; scrollbar-width: thin; }
.cat-chip {
    white-space: nowrap; padding: 7px 14px; border-radius: 16px;
    background: var(--chip); font-size: 14px; font-weight: 600; color: var(--text);
}
.cat-chip:hover { background: var(--chip-hover); }
.cat-chip.active { background: var(--text); color: var(--bg); }

/* ===== المحتوى ===== */
.app-main { max-width: 1400px; margin: 0 auto; padding: 20px 16px 48px; min-height: 60vh; }

.section-title { font-size: 20px; font-weight: 700; margin: 8px 0 16px; }

/* شبكة الفيديوهات */
.video-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px 16px;
}

/* بطاقة فيديو */
.video-card { display: flex; flex-direction: column; }
.video-card .thumb {
    position: relative; width: 100%; aspect-ratio: 16 / 9;
    background: #000; border-radius: var(--radius); overflow: hidden;
}
.video-card .thumb img { width: 100%; height: 100%; object-fit: cover; }
.video-card .duration {
    position: absolute; bottom: 8px; left: 8px;
    background: rgba(0,0,0,.8); color: #fff;
    font-size: 12px; padding: 1px 6px; border-radius: 4px;
}
.video-card .badge-processing {
    position: absolute; top: 8px; right: 8px;
    background: var(--accent); color: #000; font-size: 11px;
    padding: 2px 8px; border-radius: 4px; font-weight: 700;
}
.video-card .meta { display: flex; gap: 10px; padding: 10px 2px; }
.video-card .meta .ch-avatar { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; flex: 0 0 36px; }
.video-card .title { font-size: 15px; font-weight: 600; margin: 0 0 4px; display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.video-card .sub { font-size: 13px; color: var(--text-muted); }

/* ===== صفحة المشاهدة ===== */
.watch-layout { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 24px; }
.player-wrap { width: 100%; aspect-ratio: 16 / 9; background: #000; border-radius: var(--radius); overflow: hidden; }
.player-wrap video { width: 100%; height: 100%; background: #000; }
.watch-title { font-size: 20px; font-weight: 700; margin: 14px 0 8px; }
.watch-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 10px 0; }
.pill-btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 18px; background: var(--chip); border: none; cursor: pointer; font-family: inherit; font-size: 14px; font-weight: 600; }
.pill-btn:hover { background: var(--chip-hover); }
.pill-btn.active { background: var(--primary); color: #fff; }
.channel-row { display: flex; align-items: center; gap: 12px; padding: 14px 0; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); margin: 12px 0; }
.channel-row .ch-avatar { width: 48px; height: 48px; border-radius: 50%; object-fit: cover; }
.btn-subscribe { padding: 9px 18px; border-radius: 20px; background: var(--primary); color: #fff; border: none; cursor: pointer; font-weight: 700; font-family: inherit; }
.btn-subscribe.subscribed { background: var(--chip-hover); color: var(--text); }
.video-desc { background: var(--chip); border-radius: var(--radius); padding: 12px 14px; white-space: pre-wrap; font-size: 14px; margin: 12px 0; }

/* التعليقات */
.comment { display: flex; gap: 12px; margin: 16px 0; }
.comment .ch-avatar { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; flex: 0 0 40px; }
.comment .c-body { flex: 1; }
.comment .c-head { font-size: 13px; color: var(--text-muted); margin-bottom: 2px; }
.comment .c-head b { color: var(--text); font-size: 14px; }
.comment .replies { margin-inline-start: 52px; }
.comment-form textarea, .form-control, textarea.form-control {
    width: 100%; padding: 10px 12px; border: 1px solid var(--border);
    border-radius: 8px; font-family: inherit; font-size: 14px; resize: vertical;
}

/* ===== النماذج ===== */
.auth-card, .form-card { max-width: 520px; margin: 24px auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; }
.form-card.wide { max-width: 760px; }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 14px; }
input.form-control, select.form-control { width: 100%; height: 42px; padding: 0 12px; border: 1px solid var(--border); border-radius: 8px; font-family: inherit; font-size: 14px; }
input.form-control:focus, select.form-control:focus, textarea.form-control:focus { outline: none; border-color: var(--primary); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 10px 18px; border-radius: 8px; border: none; cursor: pointer; font-family: inherit; font-size: 15px; font-weight: 600; text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--chip); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-block { width: 100%; }
.text-danger, .field-validation-error { color: var(--danger); font-size: 13px; }
.text-muted { color: var(--text-muted); }
.validation-summary-errors ul { margin: 0; padding-inline-start: 18px; color: var(--danger); }
.form-actions { display: flex; gap: 10px; margin-top: 8px; }
.auth-alt { text-align: center; margin-top: 14px; font-size: 14px; color: var(--text-muted); }
.auth-alt a { color: var(--primary); font-weight: 600; }

/* التنبيهات */
.alert { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; font-size: 14px; }
.alert-success { background: #e6f5ee; color: var(--primary-dark); border: 1px solid #b7e0cd; }
.alert-error { background: #fdecea; color: var(--danger); border: 1px solid #f5c6c2; }
.alert-info { background: #eef4fb; color: #1c4f8b; border: 1px solid #cfe0f3; }

/* إشعارات خفيفة (Toast) لعمليات AJAX */
.toast {
    position: fixed;
    bottom: 24px;
    inset-inline-start: 50%;
    transform: translateX(50%) translateY(20px);
    z-index: 1000;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 14px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, .18);
    opacity: 0;
    transition: opacity .25s ease, transform .25s ease;
    max-width: min(90vw, 420px);
}
.toast.show { opacity: 1; transform: translateX(50%) translateY(0); }
.toast-success { background: var(--primary-dark, #1b5e3f); color: #fff; }
.toast-error { background: var(--danger, #c0392b); color: #fff; }

/* الفوتر */
.app-footer { border-top: 1px solid var(--border); padding: 20px 16px; text-align: center; color: var(--text-muted); font-size: 13px; background: var(--surface); }

/* شريط تقدّم الرفع */
.progress { width: 100%; height: 10px; background: var(--chip); border-radius: 6px; overflow: hidden; margin-top: 10px; display: none; }
.progress.show { display: block; }
.progress-bar { height: 100%; width: 0; background: var(--primary); transition: width .2s; }

/* حالة فارغة */
.empty-state { text-align: center; padding: 60px 20px; color: var(--text-muted); }
.empty-state .big { font-size: 48px; margin-bottom: 12px; }

/* رأس القناة */
.channel-header { display: flex; align-items: center; gap: 18px; padding: 20px 0; border-bottom: 1px solid var(--border); margin-bottom: 20px; flex-wrap: wrap; }
.channel-header .ch-avatar-lg { width: 88px; height: 88px; border-radius: 50%; object-fit: cover; }
.channel-header h1 { font-size: 24px; margin: 0 0 4px; }
.channel-header .sub { color: var(--text-muted); font-size: 14px; }

/* جداول الإدارة */
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: right; }
.table th { background: var(--chip); font-weight: 700; }
.status-tag { padding: 2px 8px; border-radius: 4px; font-size: 12px; font-weight: 700; }
.status-Ready { background: #e6f5ee; color: var(--primary-dark); }
.status-Processing { background: #fff4d6; color: #8a6d00; }
.status-Uploaded { background: #eef; color: #334; }
.status-Failed { background: #fdecea; color: var(--danger); }

/* ===== لوحة الإدارة ===== */
.admin-nav {
    display: flex; flex-wrap: wrap; gap: 6px;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 6px; margin-bottom: 18px;
}
.admin-tab {
    padding: 8px 14px; border-radius: 8px; font-size: 14px; font-weight: 600;
    color: var(--text-muted); white-space: nowrap;
}
.admin-tab:hover { background: var(--chip); color: var(--text); }
.admin-tab.active { background: var(--primary); color: #fff; }

.admin-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; }
.admin-head .section-title { margin-bottom: 0; }

/* بطاقات المؤشّرات */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.kpi {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 14px 16px;
}
.kpi-value { font-size: 26px; font-weight: 700; line-height: 1.2; }
.kpi-label { font-size: 13px; color: var(--text-muted); margin-top: 2px; }
.kpi-sub { font-size: 12px; color: var(--text-muted); margin-top: 6px; }
.kpi.danger .kpi-value { color: var(--danger); }
.kpi.ok .kpi-value { color: var(--primary); }
.kpi.accent .kpi-value { color: #8a6d00; }

.badge-soft { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 12px; font-weight: 700; background: var(--chip); color: var(--text-muted); }
.badge-soft.on { background: #e6f5ee; color: var(--primary-dark); }
.badge-soft.off { background: #fdecea; color: var(--danger); }

/* ===== لوحات الإحصاءات (تُستخدم في إحصاءات القناة وتقارير الإدارة) ===== */
.stats-panel {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow);
    padding: 16px; margin-top: 16px;
}
.stats-panel h2 { margin: 0 0 12px; font-size: 17px; }
.stats-panels { display: grid; grid-template-columns: repeat(auto-fit, minmax(290px, 1fr)); gap: 16px; }
.stats-panels .stats-panel { margin-top: 0; }

/* المخطط اليومي: أعمدة div بارتفاع محسوب */
.stats-chart-scroll { overflow-x: auto; }
.stats-chart {
    display: flex; align-items: flex-end; gap: 3px;
    min-width: 620px; height: 185px;
    border-bottom: 1px solid var(--border); padding-bottom: 4px;
}
.stats-col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; min-width: 0; }
.stats-col-value { font-size: 10px; color: var(--text-muted); line-height: 1.2; white-space: nowrap; }
.stats-col-bar { width: 100%; max-width: 22px; border-radius: 3px 3px 0 0; background: var(--primary); }
.stats-col-bar.empty { height: 2px; background: var(--border); }
.stats-col-bar.alt { background: var(--accent); }
.stats-col-day { font-size: 10px; color: var(--text-muted); line-height: 1.4; white-space: nowrap; height: 14px; }

/* أشرطة التوزيع الأفقية */
.stats-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.stats-row-label { flex: 0 0 110px; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stats-row-track { flex: 1; background: var(--bg); border-radius: 4px; height: 14px; overflow: hidden; }
.stats-row-fill { height: 100%; background: var(--primary); border-radius: 4px; }
.stats-row-count { flex: 0 0 auto; font-size: 12px; color: var(--text-muted); white-space: nowrap; }

/* صفوف الفيديوهات والقنوات داخل اللوحات */
.stats-video-row { display: flex; align-items: center; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--border); }
.stats-video-row:last-child { border-bottom: none; }
.stats-video-rank { flex: 0 0 20px; text-align: center; color: var(--text-muted); font-size: 13px; }
.stats-video-thumb { flex: 0 0 72px; width: 72px; height: 40px; object-fit: cover; border-radius: 6px; background: var(--bg); }
.stats-video-avatar { flex: 0 0 32px; width: 32px; height: 32px; object-fit: cover; border-radius: 50%; background: var(--bg); }
.stats-video-title {
    flex: 1; font-size: 13px; overflow: hidden; text-overflow: ellipsis;
    display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical;
}
.stats-video-title:hover { color: var(--primary); }
.stats-video-views { flex: 0 0 auto; font-size: 12px; color: var(--text-muted); white-space: nowrap; }

/* ===== الاستجابة ===== */
@media (max-width: 900px) {
    .watch-layout { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
    .brand-text { display: none; }
    .btn-upload-text { display: none; }
    .header-search { max-width: none; }
    .video-grid { grid-template-columns: 1fr; }
    :root { --header-h: 52px; }

    /* مساحة أقل للهيدر حتى يتسع حقل البحث */
    .app-header { gap: 8px; padding: 0 8px; }
    .header-right, .header-left { gap: 8px; }
    .header-search input { padding: 0 12px; font-size: 14px; }
    .search-btn { width: 44px; }
    .btn-upload, .btn-login { padding: 8px 10px; font-size: 13px; white-space: nowrap; }
    .cat-bar { padding: 8px 8px; }

    .admin-nav { overflow-x: auto; flex-wrap: nowrap; }
    .kpi-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
    .kpi { padding: 10px 12px; }
    .kpi-value { font-size: 22px; }
}

/* الشاشات الضيقة جداً: أيقونة القائمة تكفي عن نص التصنيفات الطويل */
@media (max-width: 380px) {
    .header-search input::placeholder { font-size: 13px; }
    .search-btn { width: 38px; font-size: 14px; }
}

/* شريط تثبيت تطبيق PWA — يظهر أسفل الشاشة عندما يسمح المتصفح بالتثبيت */
.pwa-install-bar {
    position: fixed; bottom: 0; right: 0; left: 0; z-index: 1000;
    display: flex; align-items: center; gap: 12px;
    padding: 12px 16px; background: var(--primary-dark); color: #fff;
    box-shadow: 0 -2px 8px rgba(0,0,0,.2);
}
.pwa-install-bar span { flex: 1; font-size: 14px; }
.pwa-install-btn {
    padding: 8px 18px; border: none; border-radius: 20px; cursor: pointer;
    background: #fff; color: var(--primary-dark); font-weight: 700; font-family: inherit;
}
.pwa-install-close {
    background: none; border: none; color: #fff; cursor: pointer; font-size: 16px; padding: 4px;
}
