:root {
  --bg: #0b0c0f;
  --surface: #14161b;
  --surface-2: #1c1f26;
  --line: #262a33;
  --text: #eceef2;
  --muted: #8b919e;
  --accent: #e8b04b;
  --accent-ink: #1a1408;
  --ok: #3ecf8e;
  --warn: #f0b429;
  --bad: #f06a6a;
  --wa: #25d366;
  --radius: 14px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  overflow-x: clip;
  background: var(--bg);
  color: var(--text);
  font-family: 'IBM Plex Sans Arabic', system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.remember { margin: -2px 0 6px; color: var(--muted); }

.wrap { width: min(760px, 100%); margin: 0 auto; padding: 0 16px; }

/* ── الأزرار والحقول ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 0 18px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface-2); cursor: pointer; text-decoration: none;
  font-weight: 600; white-space: nowrap; transition: transform .12s, background-color .15s, opacity .15s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn-wa { background: var(--wa); color: #06210f; border-color: transparent; }
.btn-ghost { background: transparent; }
.btn-danger { color: var(--bad); }
.btn-sm { min-height: 36px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn-block { width: 100%; }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
input, select, textarea {
  width: 100%; min-height: 46px; padding: 10px 14px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 12px;
}
textarea { min-height: 90px; resize: vertical; direction: ltr; text-align: left; font-family: ui-monospace, monospace; font-size: 13px; }
input[type="tel"], input[type="password"] { direction: ltr; text-align: right; }
.field { margin-bottom: 14px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--bad); font-size: 14px; min-height: 1.4em; margin: 4px 0 10px; }
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 10px; border-radius: 99px; font-size: 13px; font-weight: 600;
  background: var(--surface-2); border: 1px solid var(--line);
}
.badge::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.ok { color: var(--ok); }
.badge.warn { color: var(--warn); }
.badge.bad { color: var(--bad); }
.badge.idle { color: var(--muted); }

/* ── صفحة الدخول ── */
.auth { min-height: 100dvh; display: grid; place-items: center; padding: 32px 16px 12px; }
.auth-box { width: min(380px, 100%); text-align: center; }
.brand-logo { width: 200px; height: 200px; object-fit: contain; margin: 0 auto 14px; display: block; }
.brand-headline { margin: 0; font-size: 22px; font-weight: 700; line-height: 1.4; text-wrap: balance; }
.brand-sub { margin: 6px 0 22px; font-size: 14px; color: var(--muted); text-wrap: balance; }
.brand-name { font-size: 28px; font-weight: 700; margin: 0; letter-spacing: -.01em; }
.brand-tag { color: var(--muted); margin: 2px 0 28px; }
.devices-title { margin: 0 0 8px; font-size: 13px; color: var(--muted); }
.devices { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 18px; }
.device { display: grid; justify-items: center; gap: 4px; padding: 10px 4px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); font-size: 12px; font-weight: 600; }
.device svg { width: 24px; height: 24px; fill: none; stroke: var(--accent); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.cta-set { display: grid; gap: 10px; margin-bottom: 26px; }
.auth-box form { text-align: right; }
.switch { margin-top: 18px; color: var(--muted); font-size: 14px; }
.switch button { background: none; border: 0; color: var(--accent); cursor: pointer; font-weight: 600; padding: 4px; }

/* ── الهيدر ── */
.top { position: sticky; top: 0; z-index: 5; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.top .wrap { display: flex; align-items: center; gap: 10px; min-height: 60px; }
.top-logo { width: 48px; height: 48px; object-fit: contain; }
.top-name { font-weight: 700; margin-inline-end: auto; }

/* ── لوحة الزبون ── */
.dash { padding-block: 24px 48px; display: grid; gap: 16px; }
.hello { margin: 0; font-size: 22px; }
.status-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.remaining { font-size: 30px; font-weight: 700; font-variant-numeric: tabular-nums; margin: 10px 0 2px; }
.creds { display: grid; gap: 10px; }
.cred { display: flex; align-items: center; gap: 10px; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 8px 8px 8px 14px; }
.cred-label { font-size: 12px; color: var(--muted); min-width: 70px; }
.cred-value { flex: 1; direction: ltr; text-align: left; font-family: ui-monospace, monospace; font-size: 14px; overflow-wrap: anywhere; }
.dash-banner { display: block; width: min(340px, 80%); height: auto; margin: 24px auto 0; }
.auth-plans { margin-top: 34px; text-align: right; }
.policy { border-top: 1px solid var(--line); padding: 18px 0 28px; color: var(--muted); font-size: 13px; line-height: 1.8; }
.policy b { color: var(--text); font-size: 14px; }
.policy p { margin: 4px 0 0; }
.plans { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.plan { position: relative; text-align: center; display: grid; gap: 6px; padding: 18px 14px; }
.plan-name { font-weight: 700; font-size: 17px; }
.plan-price { color: var(--accent); font-weight: 700; font-variant-numeric: tabular-nums; }
.steps { margin: 8px 0 0; padding-inline-start: 20px; color: var(--muted); font-size: 14px; }
.section-title { font-size: 16px; margin: 0 0 12px; }

/* ── المشغل ── */
.player { display: grid; grid-template-columns: 1fr 340px; gap: 16px; padding: 16px; height: calc(100dvh - 61px); }
.screen { display: grid; grid-template-rows: auto auto auto 1fr; gap: 12px; min-height: 0; }
.video-box { position: relative; background: #000; border-radius: var(--radius); overflow: hidden; aspect-ratio: 16 / 9; }
.video-box video { width: 100%; height: 100%; display: block; background: #000; }
.video-msg { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 20px; color: var(--muted); pointer-events: none; }
.now { display: flex; align-items: center; gap: 10px; }
.now-name { min-width: 0; font-weight: 700; font-size: 17px; margin-inline-end: auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seek { display: flex; align-items: center; gap: 10px; direction: ltr; font-variant-numeric: tabular-nums; font-size: 13px; color: var(--muted); }
.seek input { flex: 1; min-height: 0; padding: 0; height: 28px; accent-color: var(--accent); background: transparent; border: 0; }
.side { display: grid; grid-template-rows: auto auto auto auto 1fr; gap: 10px; min-height: 0; }
.channels { overflow-y: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 6px; }
.ch {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 8px 10px; border: 0; border-radius: 10px; background: transparent;
  text-align: right; cursor: pointer;
}
.ch:hover, .ch:focus-visible { background: var(--surface-2); }
.ch:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.ch.on { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent); }
.ch img, .ch .ph { width: 36px; height: 36px; border-radius: 8px; object-fit: contain; background: var(--bg); flex: none; }
.ch span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty { padding: 24px; text-align: center; color: var(--muted); }

.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 4px; }
.seg-btn { min-height: 38px; border: 0; border-radius: 9px; background: transparent; color: var(--muted); font-weight: 600; cursor: pointer; }
.seg-btn.on { background: var(--accent); color: var(--accent-ink); }
.series-head { display: flex; gap: 8px; }
.series-head select { flex: 1; min-height: 36px; padding: 4px 10px; }
.ch.poster img, .ch.poster .ph { width: 40px; height: 58px; object-fit: cover; }
.ch small { color: var(--muted); margin-inline-start: auto; font-variant-numeric: tabular-nums; flex: none; }

/* عناصر الشبكة ما تتمدد أعرض من الشاشة بسبب الأسماء الطويلة */
.player > *, .screen > *, .side > *, .dash > *, .admin > * { min-width: 0; }
select { max-width: 100%; text-overflow: ellipsis; }

@media (max-width: 860px) {
  .player { grid-template-columns: 1fr; height: auto; }
  .screen { grid-template-rows: auto auto; }
  .channels { max-height: 60dvh; }
}

/* ── لوحة المدير ── */
.admin { padding-block: 20px 48px; display: grid; gap: 14px; }
.tabs { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; }
.tab { white-space: nowrap; }
.tab.on { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.tab .n { opacity: .7; font-variant-numeric: tabular-nums; }
.users { display: grid; gap: 10px; }
.u { display: grid; gap: 10px; padding: 16px; }
.u-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.u-name { font-weight: 700; margin-inline-end: auto; }
.u-phone { direction: ltr; color: var(--muted); text-decoration: none; font-variant-numeric: tabular-nums; }
.u-line { direction: ltr; text-align: left; font-family: ui-monospace, monospace; font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.u-creds { display: grid; gap: 4px; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; }
.u-creds div { display: flex; gap: 10px; align-items: baseline; }
.u-creds span { color: var(--muted); font-size: 12px; min-width: 56px; }
.u-creds b { font-weight: 500; direction: ltr; text-align: left; font-family: ui-monospace, monospace; font-size: 13px; overflow-wrap: anywhere; }
.u-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.chips { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.check { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 14px; margin: 0; }
.check input { width: 18px; height: 18px; min-height: 0; }

dialog {
  width: min(460px, calc(100% - 32px)); padding: 22px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--line); border-radius: 18px;
}
dialog::backdrop { background: rgba(0, 0, 0, .6); }
dialog h3 { margin: 0 0 4px; }
.dlg-actions { display: flex; gap: 8px; margin-top: 16px; }
.dlg-actions .btn { flex: 1; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 18px; z-index: 50; font-size: 14px;
}

.wa-contact { margin-bottom: 16px; }

/* شعار الهيدر بالنص بصفحات الزبون (لوحة المدير تبقى مثل ما هي) */
#top .wrap { position: relative; justify-content: flex-end; }
#top .top-name { display: none; }
#top .top-logo { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: 54px; height: 54px; }

/* خصم الباقات */
.plan-off { position: absolute; top: -10px; inset-inline-start: 50%; transform: translateX(50%); background: #ff4d6d; color: #fff; font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 999px; white-space: nowrap; box-shadow: 0 4px 12px rgb(255 77 109 / .35); }
.plan-old { color: var(--muted); font-size: 13px; text-decoration: line-through; text-decoration-color: #ff4d6d; font-variant-numeric: tabular-nums; }
.plans { padding-top: 10px; }
.plan { display: flex; flex-direction: column; align-items: stretch; }
.plan > .btn { margin-top: auto; }
.plan > .plan-price { margin-bottom: 8px; }
