/* =========================================================
   ثيم لوحة التحكم الليلي (الداكن)
   ينحمّل بلوحة التحكم (admin.html) وصفحة المشترك (index.html)، بعد style.css.
   الألوان كلها بمتغيرات بمكان واحد. الحالات بس ملوّنة:
   أخضر = زين/متصل، أصفر = قريب ينتهي، أحمر = منتهي/مقيّد، برتقالي = دين
   ========================================================= */
/* ألوان هادئة: الخلفية مو سودة كاملة والنص مو أبيض ناصع (تباين مريح للعين بالليل)،
   وألوان الحالة أقل تشبّع بس واضحة. كلها فوق نسبة القراءة المطلوبة (WCAG AA) */
html.dark {
  color-scheme: dark;
  --bg: #10161F;
  --card: #171E2A;
  --card-2: #1D2532;
  --border: #262F3E;
  --border-strong: #354052;
  --ink: #D7DDE6;
  --muted: #8A95A6;
  --blue: #3768C8;
  --blue-light: rgba(76, 132, 232, .15);
  --blue-mid: #7AA5EE;
  --orange: #F0B37E;
  --orange-bg: rgba(240, 179, 126, .12);
  --red: #EE8A8A;
  --red-bg: rgba(238, 138, 138, .12);
  --green: #5CC9A0;
  --green-bg: rgba(92, 201, 160, .12);
  --amber: #E9C46A;
  --amber-bg: rgba(233, 196, 106, .12);
  --ease: cubic-bezier(.2, .7, .2, 1);
}

html.dark body { background: var(--bg); color: var(--ink); -webkit-font-smoothing: antialiased; line-height: 1.5; }

/* سلاسة: حركة خفيفة وسريعة (150ms) للأزرار والبطاقات، وتنطفي لمن يفضّل بدون حركة */
html.dark button, html.dark .sub-row, html.dark .kpi, html.dark .chip, html.dark input, html.dark select {
  transition: background-color .15s var(--ease), border-color .15s var(--ease), color .15s var(--ease), transform .1s var(--ease);
}
html.dark button:active:not(:disabled), html.dark .sub-row:active { transform: scale(.985); }
html.dark :focus-visible { outline: 2px solid var(--blue-mid); outline-offset: 2px; }
html.dark [data-dpanel]:not([hidden]), html.dark #sub-detail:not([hidden]) { animation: fadeIn .16s var(--ease); }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) {
  html.dark *, html.dark *::before, html.dark *::after { animation: none !important; transition: none !important; }
}
html.dark ::selection { background: rgba(76, 132, 232, .35); }
html.dark .admin { max-width: 760px; padding-top: 20px; }

/* حقول الإدخال */
html.dark .form input, html.dark .form textarea, html.dark .form select, html.dark #h-filter, html.dark input[type="search"] {
  background: var(--card-2); border-color: var(--border-strong); color: var(--ink);
}
html.dark .form input::placeholder, html.dark textarea::placeholder { color: #66748F; }
html.dark .form .ifield input, html.dark .form .ifield select { background: transparent; }
html.dark .ifield, html.dark .loc-card { background: var(--card); border-color: var(--border-strong); }

/* أزرار */
html.dark .btn { background: var(--blue); }
html.dark .btn-outline { background: transparent; border-color: var(--border-strong); color: var(--ink); }
html.dark .btn-ghost { background: var(--card); border-color: var(--border); color: var(--ink); }
html.dark .btn-danger { background: var(--red-bg); border-color: transparent; color: var(--red); }
html.dark .admin-tabs button { background: var(--card); border-color: var(--border); color: var(--muted); }
html.dark .admin-tabs button.active { background: var(--blue); border-color: var(--blue); color: #fff; }
html.dark .icon-btn { background: var(--card); border-color: var(--border); color: var(--ink); }
html.dark .icon-pill { background: var(--card); border-color: var(--border); }
html.dark .icon-pill button { color: var(--ink); }
html.dark dialog.sheet { background: var(--card); color: var(--ink); }
html.dark dialog.sheet::backdrop { background: rgba(2, 6, 16, .7); }
html.dark .menu button { color: var(--ink); }
html.dark .menu button:hover { background: var(--card-2); }
html.dark .chip:has(input:checked) { background: var(--blue-light); border-color: var(--blue); color: var(--blue-mid); }
html.dark .form input.switch { background: #3A4762; }

/* ألوان الحالات */
html.dark .status-dot.on { color: var(--green); }
html.dark .status-dot.off { color: var(--muted); }
html.dark .status-dot.bad { color: var(--red); }
html.dark .ok { color: var(--green); }
html.dark .debt-neg { color: var(--green); }
html.dark .tag { background: var(--blue-light); color: var(--blue-mid); }
html.dark .note-box { background: var(--amber-bg); color: #FDE68A; }
html.dark .alert-box { background: var(--amber-bg); border-color: #B45309; color: #FDE68A; }
html.dark .danger-note { background: var(--red-bg); color: var(--red); }
html.dark .k-payment { background: var(--blue-light); color: var(--blue-mid); }
html.dark .k-renewal { background: rgba(167, 139, 250, .16); color: #C4B5FD; }
html.dark .k-correction, html.dark .kind-chip { background: var(--card-2); color: var(--muted); }
html.dark .kv, html.dark .panels, html.dark .balance-box { background: var(--card-2); }
html.dark .sas-box { background: var(--card-2); border-color: var(--border); }
html.dark .alert-row, html.dark .archive-row { background: var(--card-2); border-color: var(--border); }

/* ---------- الهيدر ---------- */
.brand-head { min-width: 0; }
.company { font-size: 17px; line-height: 1.4; font-weight: 700; }
.sub-head { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: 2px; }
.link-btn { border: 0; background: none; padding: 0; color: var(--blue-mid); font-family: inherit; font-size: 12px; cursor: pointer; }
.link-btn:disabled { color: var(--muted); }
.top { gap: 10px; align-items: flex-start; }
#logout-btn { min-height: 40px; padding: 0 12px; }
#sync-status { margin: -6px 0 0; font-size: 13px; }

/* ---------- بطاقات الملخص ---------- */
.kpis { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (min-width: 640px) { .kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.kpi { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; padding: 12px 14px; border-radius: 16px;
       border: 1px solid var(--border); background: var(--card); color: var(--ink); font-family: inherit; cursor: pointer; text-align: right; }
.kpi span { font-size: 12px; color: var(--muted); }
.kpi strong { font-size: 21px; line-height: 1.2; }
.kpi small { font-size: 11px; color: var(--muted); }
.kpi.active { border-color: var(--blue); box-shadow: 0 0 0 1px var(--blue) inset; }
.c-orange { color: var(--orange); } .c-green { color: var(--green); } .c-amber { color: var(--amber); } .c-red { color: var(--red); }

/* البحث والفلاتر السريعة */
.search-box input { width: 100%; height: 48px; border-radius: 14px; border: 1px solid var(--border); padding: 0 16px;
                    font-family: inherit; font-size: 15px; background: var(--card); color: var(--ink); }
.search-box input:focus { outline: 2px solid var(--blue); outline-offset: 1px; }
.quick-chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.quick-chips button { flex: none; min-height: 34px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--border);
                      background: var(--card); color: var(--muted); font-family: inherit; font-size: 13px; cursor: pointer; }
.quick-chips button.active { background: var(--blue); border-color: var(--blue); color: #fff; }

/* ---------- صف المشترك ---------- */
html.dark .sub-row { background: var(--card); border-color: var(--border); padding: 10px 12px; gap: 12px; align-items: center; border-radius: 16px; }
html.dark .sub-row:hover { border-color: var(--border-strong); background: var(--card-2); }
.sub-row .sub-info strong { font-size: 15px; font-weight: 700; }
.sub-row .sub-meta { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sub-side { flex: none; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; text-align: left; }
.sub-side .status-dot { font-size: 12px; font-weight: 500; }
.sub-side .amt { font-size: 14px; font-weight: 700; }
html.dark .days-badge { width: 56px; height: 56px; border-radius: 14px; background: var(--card-2); color: var(--ink); }
html.dark .days-badge strong { font-size: 18px; line-height: 1; }
html.dark .days-badge span { font-size: 11px; opacity: .85; }
html.dark .days-badge.d-good { background: var(--green-bg); color: var(--green); }
html.dark .days-badge.d-mid { background: var(--blue-light); color: var(--blue-mid); }
html.dark .days-badge.d-soon { background: var(--amber-bg); color: var(--amber); }
html.dark .days-badge.d-exp, html.dark .days-badge.expired { background: var(--red-bg); color: var(--red); }
html.dark .days-badge.d-exp strong { font-size: 13px; }
.sub-row.is-restricted { border-color: rgba(248, 113, 113, .45) !important; }
html.dark .group-head { border-color: var(--border); }
html.dark .group-head strong { color: var(--blue-mid); }

/* ---------- صفحة المشترك ---------- */
html.dark .name-card { background: linear-gradient(135deg, #274877, #1B2D4C); border: 1px solid #2C4A78; padding: 18px; gap: 12px; }
html.dark .name-card.restricted { background: linear-gradient(135deg, #AD5028, #9A3535); border-color: #B4552F; }
.name-card h2 { margin: 0; font-size: 22px; }
.name-sub { display: block; font-size: 12px; color: rgba(255, 255, 255, .75); margin-top: 2px; }
.days-pill { flex: none; padding: 5px 12px; border-radius: 999px; font-size: 12px; font-weight: 700; background: rgba(255, 255, 255, .18); color: #fff; }
.days-pill.soon { background: var(--amber); color: #3D2C06; }
.days-pill.exp { background: var(--red); color: #3B0D0D; }
.nc-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.nc-box { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 10px 12px; border-radius: 12px;
          background: rgba(255, 255, 255, .12); border: 0; color: #fff; font-family: inherit; text-align: right; }
.nc-box span { font-size: 12px; opacity: .85; }
.nc-box strong { font-size: 20px; }
button.nc-box { cursor: pointer; }
.nc-box.due-chip { margin: 0; }
.nc-box.due-chip strong { font-size: 16px; }
.nc-box.due-chip.late { background: rgba(238, 138, 138, .22); color: #FFD9D9; box-shadow: inset 0 0 0 1px rgba(238, 138, 138, .55); }

.d-tabs { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.d-tabs button { min-height: 38px; border-radius: 999px; border: 1px solid var(--border); background: var(--card); color: var(--muted);
                 font-family: inherit; font-size: 13px; cursor: pointer; }
.d-tabs button.active { background: var(--ink); color: var(--bg); border-color: var(--ink); font-weight: 700; }
html.dark .info-card dd { font-weight: 600; font-size: 15px; }
html.dark dd.link { color: var(--blue-mid); }

.mini-ledger { display: flex; flex-direction: column; }
.mini-ledger > div { display: flex; justify-content: space-between; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.mini-ledger > div:last-child { border-bottom: 0; }
.mini-ledger small { display: block; color: var(--muted); font-size: 12px; }

.d-actions.two { flex-direction: row; display: grid; grid-template-columns: 1fr 1.5fr; gap: 10px; }
.d-actions.two .btn, .d-actions.two .btn-outline { height: 52px; margin: 0; border-radius: 14px; }
html.dark .d-actions { background: linear-gradient(to top, var(--bg) 75%, transparent); }

/* ---------- صفحة المشترك (index.html) ---------- */
html.dark .login .brand h1 { font-size: 21px; line-height: 1.5; }
html.dark .card { background: var(--card); border-color: var(--border); }
html.dark .card.status { background: linear-gradient(135deg, #274877, #1B2D4C); border: 1px solid #2C4A78; }
html.dark .label-light, html.dark .ring-text span { color: rgba(255, 255, 255, .75); }
html.dark .ring-bg { stroke: rgba(255, 255, 255, .18); }
html.dark .dates hr { background: rgba(255, 255, 255, .18); }
html.dark .badge { background: rgba(255, 255, 255, .18); color: #fff; }
html.dark .badge.expired { background: var(--red); color: #3B0D0D; }
html.dark .icon-box { background: var(--orange-bg); color: var(--orange); }
html.dark .debt strong { color: var(--orange); }
html.dark .debt strong.zero { color: var(--green); }
html.dark .grid > div { background: var(--card-2); }
html.dark .bars i { background: #33415E; }
html.dark .bars i.on { background: var(--green); }
html.dark .quality { color: var(--ink); }
html.dark .conn-status { color: var(--green); }
html.dark .conn-status.off { color: var(--muted); }
html.dark .bottom-nav { background: rgba(19, 28, 46, .96); border-top-color: var(--border); backdrop-filter: blur(8px); }
html.dark .bottom-nav button { color: var(--muted); }
html.dark .bottom-nav button.active { color: var(--blue-mid); }
html.dark .msg p, html.dark .offer p { color: var(--muted); }
html.dark .msg.outage { border-color: rgba(251, 146, 60, .45); }
html.dark .msg.announcement { border-color: rgba(59, 130, 246, .45); }
html.dark .msg.announcement .kind, html.dark .offer .speed { color: var(--blue-mid); }
html.dark .secure { color: var(--green); }

/* زر واتساب الدعم بشاشة الدخول */
.help { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.wa-btn { display: inline-flex; align-items: center; gap: 8px; min-height: 46px; padding: 0 20px; border-radius: 999px;
          background: #3DBE76; color: #062614; font-weight: 700; font-size: 16px; text-decoration: none; }
.wa-btn:hover { background: #36AB6A; }
.wa-btn:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

/* ملاحظاتي */
.notes-area { min-height: 55vh !important; line-height: 1.8; font-size: 15px !important; }
/* الموبايل: مساحة الشق والحواف (iPhone) وأزرار أسهل للإصبع */
html.dark .screen { padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
html.dark .d-actions { padding-bottom: max(16px, env(safe-area-inset-bottom)); }
@media (max-width: 480px) {
  /* الهيدر: الاسم بسطر كامل، والأيقونات تحته */
  .top { flex-wrap: wrap; row-gap: 10px; }
  .brand-head { flex: 1 1 100%; }
  .top-actions { flex: 1 1 100%; justify-content: space-between; }
  html.dark .admin-tabs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  html.dark .admin-tabs button { flex: 1 0 auto; padding: 0 12px; font-size: 14px; min-height: 42px; }
  .company { font-size: 15px; }
  .icon-pill button { width: 36px; height: 36px; }
}

/* الترحيب وخدماتنا (بوابة المشترك): شرائح تنسحب بالإصبع */
.welcome { min-height: 100dvh; display: flex; flex-direction: column; gap: 14px;
  padding-top: max(16px, env(safe-area-inset-top)); padding-bottom: max(20px, env(safe-area-inset-bottom)); }
.wl-top { display: flex; justify-content: flex-end; }
.wl-skip { min-height: 36px; padding: 0 16px; border-radius: 999px; }
.wl-track { flex: 1; display: flex; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none; overscroll-behavior-x: contain; }
.wl-track::-webkit-scrollbar { display: none; }
.wl-slide { flex: 0 0 100%; box-sizing: border-box; scroll-snap-align: start; display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center; gap: 14px; padding: 0 12px; }
.wl-art { width: 168px; height: 168px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  background: var(--blue-light); color: var(--blue-mid); }
.wl-art svg { width: 104px; height: 104px; }
.wl-art.amber { background: var(--amber-bg); color: var(--amber); }
.wl-art.green { background: var(--green-bg); color: var(--green); }
.wl-art.orange { background: var(--orange-bg); color: var(--orange); }
.wl-slide h2 { font-size: 22px; margin: 8px 0 0; }
.wl-slide p { color: var(--muted); font-size: 16px; line-height: 1.9; max-width: 340px; margin: 0; }
.wl-slide p strong { color: var(--ink); }
.wl-dots { display: flex; justify-content: center; gap: 8px; }
.wl-dots i { width: 8px; height: 8px; border-radius: 999px; background: var(--border-strong); transition: width .2s var(--ease), background-color .2s var(--ease); }
.wl-dots i.on { width: 24px; background: var(--blue-mid); }
.wl-next { width: 100%; max-width: 420px; align-self: center; }
@media (prefers-reduced-motion: reduce) { .wl-dots i { transition: none; } }
.wl-img { width: 100%; max-width: 400px; height: auto; aspect-ratio: 4 / 3; border-radius: 20px; display: block;
  border: 1px solid var(--border); background: var(--card); }
.wl-slide { justify-content: flex-start; padding-top: 8px; }
.wl-open { display: block; margin: 14px auto 0; min-height: 42px; padding: 0 20px; border-radius: 999px; }
/* تحذير بعد الدخول الغلط (بوابة المشترك) */
.login-help { margin: 4px 0 12px; padding: 10px 12px; border-radius: 10px; font-size: 14px; line-height: 1.8;
  background: var(--amber-bg); color: var(--amber); }
.login-help a { color: #25D366; font-weight: 700; text-decoration: none; }
/* تنبيه دخول غلط للوحة المدير */
html.dark .alert-row.alert-danger { border-color: var(--red); background: var(--red-bg); cursor: default; }
html.dark .alert-row.alert-danger strong { color: var(--red); }
.alert-row.alert-danger .btn-ghost { margin-top: 8px; min-height: 36px; padding: 0 14px; border-radius: 999px; }
/* الدخول برقم الموبايل + كود الواتساب */
.link-btn { display: block; width: 100%; margin-top: 10px; min-height: 40px; background: none; border: 0;
  color: var(--blue-mid); font-size: 15px; cursor: pointer; }
.link-btn:disabled { color: var(--muted); cursor: default; }
.small-note { font-size: 13px; margin: -4px 0 10px; }
.otp-msg { margin: 0 0 12px; line-height: 1.8; color: var(--ink); }
.otp-input { font-size: 26px !important; letter-spacing: 10px; text-align: center; }
.lc-list { display: flex; flex-direction: column; gap: 8px; }
.lc-item { display: flex; justify-content: space-between; align-items: center; gap: 10px; min-height: 52px; padding: 0 14px;
  border-radius: 12px; border: 1px solid var(--border-strong); background: var(--card-2); color: var(--ink); font-size: 16px; cursor: pointer; }
.lc-item:hover { border-color: var(--blue-mid); }
/* صفحة من نحن */
.about { max-width: 640px; margin: 0 auto; padding-top: 24px; padding-bottom: 40px; }
.about .brand { text-align: center; margin-bottom: 16px; }
.about .logo { margin: 0 auto 10px; }
.about-card { margin-bottom: 14px; }
.about-card h2 { font-size: 18px; margin: 0 0 8px; }
.about-card p { line-height: 1.9; margin: 0; color: var(--ink); }
.about-list { margin: 0; padding-right: 20px; line-height: 2; }
.about-info { display: grid; grid-template-columns: 1fr; gap: 2px; margin: 0; }
.about-info dt { color: var(--muted); font-size: 13px; margin-top: 10px; }
.about-info dd { margin: 0; font-size: 15px; }
.about-info a, .about-back a { color: var(--blue-mid); text-decoration: none; }
.about-back { text-align: center; }
.about-link { display: block; text-align: center; margin-top: 10px; color: var(--muted); font-size: 13px; }

/* ---------- تبليغات المشترك (فوك معلوماتي) ---------- */
.me-alerts { display: flex; flex-direction: column; gap: 10px; }
.me-alerts[hidden] { display: none; }
.me-alert { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px;
            border-radius: 16px; border: 1px solid var(--border); background: var(--card); }
.me-alert-text { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.me-alert-text strong { font-size: 15px; }
.me-alert-text span { font-size: 13px; color: var(--muted); }
.me-alert.bad { border-color: var(--red); background: var(--red-bg); }
.me-alert.bad strong { color: var(--red); }
.me-alert.warn { border-color: var(--amber); background: var(--amber-bg); }
.me-alert.warn strong { color: var(--amber); }
.me-alert.debt { border-color: var(--orange); background: var(--orange-bg); }
.me-alert.debt strong { color: var(--orange); }
.me-alert.info { border-color: var(--blue); background: var(--blue-light); }
.me-alert.info strong { color: var(--blue-mid); }
.me-alert-btn { flex-shrink: 0; display: inline-flex; align-items: center; min-height: 40px; padding: 0 16px; border-radius: 999px;
                border: 0; background: var(--blue); color: #fff; font-family: inherit; font-size: 14px; font-weight: 700;
                text-decoration: none; cursor: pointer; white-space: nowrap; }
.bottom-nav button { position: relative; }
.nav-dot { position: absolute; top: 8px; left: calc(50% - 16px); width: 9px; height: 9px; border-radius: 50%; background: var(--red); }
.nav-dot[hidden] { display: none; }
html.dark .msg.personal { border-color: var(--blue); }
html.dark .tag.new { background: var(--red-bg); color: var(--red); }

/* ---------- واتساب اليوم (لوحة المدير) ---------- */
.wa-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.wa-head h2 { margin: 0; }
.wa-counts { display: flex; gap: 8px; flex-wrap: wrap; }
.wa-row { display: flex; flex-direction: column; gap: 8px; padding: 12px 14px; border-radius: 14px;
          border: 1px solid var(--border); background: var(--card-2); }
.wa-row.done { opacity: .55; }
.wa-row-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.wa-row-top div { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.wa-reasons { display: flex; gap: 6px; flex-wrap: wrap; }
.wa-chip { font-size: 12px; padding: 3px 10px; border-radius: 999px; }
.wa-chip.soon { background: var(--amber-bg); color: var(--amber); }
.wa-chip.expired { background: var(--red-bg); color: var(--red); }
.wa-chip.due { background: var(--orange-bg); color: var(--orange); }
.wa-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.wa-actions .wa-btn { min-height: 40px; padding: 0 16px; font-size: 14px; }
.wa-actions .btn-ghost { min-height: 40px; padding: 0 14px; border-radius: 999px; }
.wa-tpl textarea { min-height: 90px; }
button.wa-btn { border: 0; font-family: inherit; cursor: pointer; }
button.wa-btn:disabled { opacity: .4; cursor: not-allowed; }
