:root {
  --bg: #14120f; --surface: #1e1b17; --raised: #28241e; --line: #3a342b;
  --text: #f4efe6; --muted: #b3a998; --accent: #e8b04a; --on-accent: #1b1407;
  --ok: #7ad6a0; --soon: #f4c552; --out: #f4806f;
  --head: "Readex Pro", "IBM Plex Sans Arabic", sans-serif;
  --body: "IBM Plex Sans Arabic", "Readex Pro", sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 400 16px/1.6 var(--body); }
a { color: inherit; text-decoration: none; }
h1, h2, h3 { font-family: var(--head); margin: 0; line-height: 1.3; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.wrap { max-width: 1080px; margin: 0 auto; padding: 20px 16px calc(48px + env(safe-area-inset-bottom)); }
.ltr { direction: ltr; unicode-bidi: isolate; display: inline-block; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }

/* الأزرار */
.btn { min-height: 44px; padding: 8px 16px; border-radius: 10px; border: 1px solid var(--line); background: var(--raised); font-weight: 500; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.1); }
.btn.danger { color: var(--out); }
.btn.small { min-height: 38px; padding: 4px 12px; font-size: 14px; }
.btn[disabled] { opacity: .55; cursor: default; }
.link { background: none; border: 0; color: var(--accent); padding: 8px 0; min-height: 44px; }

/* الرأس */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand h1 { font-size: 26px; font-weight: 700; }
.top h1 { overflow-wrap: anywhere; }
.crumb { display: inline-flex; align-items: center; min-height: 44px; color: var(--muted); font-size: 15px; margin-bottom: 4px; }
.crumb:hover { color: var(--text); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* البحث */
.search { width: 100%; min-height: 50px; padding: 10px 16px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); margin-bottom: 20px; }
.search::placeholder { color: var(--muted); }

/* النقاط الثلاث: كل نقطة مكان مشترك */
.dots { display: inline-flex; gap: 5px; align-items: center; }
.dots i { width: 12px; height: 12px; border-radius: 50%; border: 1.5px solid var(--pc, var(--accent)); }
.dots i.on { background: var(--pc, var(--accent)); }
.brand .dots i { width: 11px; height: 11px; }

/* الخانات */
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(min(320px, 100%), 1fr)); }
.email-card > .actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(92px, 1fr)); margin-top: auto; }
.email-card > .actions .btn { padding-inline: 6px; }
.card { display: block; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 18px; }
a.card:hover { border-color: var(--pc, var(--muted)); background: #221f1a; }
.prog-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.mono { flex: none; width: 48px; height: 48px; border-radius: 13px; display: grid; place-items: center; font: 700 22px var(--head); color: var(--on-pc, var(--bg)); background: var(--pc); overflow: hidden; }
.mono.has-img { background: #fff; padding: 6px; }
.mono.has-img.own { padding: 0; }
.mono img { width: 100%; height: 100%; object-fit: cover; display: block; }
.meter { width: 96px; height: 8px; accent-color: var(--pc, var(--accent)); }
.prog-head h2 { font-size: 20px; font-weight: 600; overflow-wrap: anywhere; }
.facts { display: flex; flex-wrap: wrap; gap: 6px 14px; color: var(--muted); font-size: 14.5px; }
.alerts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.add-tile { display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 130px; width: 100%; background: none; border: 1.5px dashed var(--line); border-radius: 16px; color: var(--muted); font-weight: 500; }
.add-tile:hover { color: var(--text); border-color: var(--muted); }

/* حالة الانتهاء */
.pill { display: inline-block; padding: 2px 10px; border-radius: 99px; font-size: 13.5px; font-weight: 500; border: 1px solid currentColor; white-space: nowrap; }
.pill.ok { color: var(--ok); } .pill.soon { color: var(--soon); } .pill.out { color: var(--out); }
.card.is-soon { border-color: #7a6426; } .card.is-out { border-color: #7f4137; }

/* القائمة والتنبيهات */
.menu { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 14px; }
.badge { display: inline-grid; place-items: center; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 99px; background: var(--out); color: #2a0a05; font-size: 13px; font-weight: 700; }
.alert-banner { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 14px; background: #3a1a15; border: 1px solid var(--out); border-radius: 14px; padding: 12px 16px; margin-bottom: 14px; }
.alert-banner span { color: var(--out); font-size: 14.5px; }
.group-head { margin-top: 22px; }
.under { text-decoration: underline; }
.wa { background: #25d366; border-color: #25d366; color: #06290f; font-weight: 600; }
.wa:hover { border-color: #25d366; filter: brightness(1.08); }
.copyable { cursor: pointer; }
.slot .actions { align-items: center; }

/* طرق الدفع والمبالغ */
.pay { background: var(--surface); border: 1px solid var(--accent); border-radius: 14px; padding: 12px; margin-bottom: 14px; }
.pay-head h2 { font-size: 17px; font-weight: 600; }
.pay-details { border: 0; margin: 8px 0 0; background: none; }
.pay-details summary { padding: 6px 0; color: var(--muted); font: 500 14.5px var(--body); }
.pay-details .notes-body { padding: 4px 0 0; }
.pay-empty { margin-bottom: 14px; border-color: var(--accent); color: var(--text); }
.unpaid-line { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 14px; margin-bottom: 14px; border: 1px solid var(--line); border-radius: 12px; color: var(--soon); }
.paid.yes { background: #123524; border-color: var(--ok); color: var(--ok); }
.paid.no { border-color: var(--out); color: var(--out); }

/* حالة الإيميل: أخضر متاح، أصفر قبط، أحمر منتهي */
.state-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.state-row .email-addr { min-width: 0; overflow-wrap: anywhere; padding-top: 2px; }
.state-badge { flex: none; display: inline-block; padding: 4px 12px; border-radius: 9px; font-size: 14px; font-weight: 700; white-space: nowrap; }
.state-badge.st-open { background: var(--ok); color: #06291a; }
.state-badge.st-full { background: var(--soon); color: #2a1f02; }
.state-badge.st-out { background: var(--out); color: #2c0a05; }
.card.st-open { --pc: var(--ok); border-color: var(--ok); background: #17231c; }
.card.st-full { --pc: var(--soon); border-color: var(--soon); background: #262013; }
.card.st-out { --pc: var(--out); border-color: var(--out); background: #2a1714; }
.end-note { font-size: 13.5px; color: var(--muted); white-space: nowrap; }
.end-note.near { color: #f4906a; font-weight: 600; }
.page-state { margin-top: 8px; }

/* شريط الإضافة والأدوات */
.quick-box { background: var(--surface); border: 1px solid var(--accent); border-radius: 16px; margin-bottom: 14px; }
.quick-box summary { cursor: pointer; padding: 14px 18px; min-height: 48px; font: 600 17px var(--head); color: var(--accent); }
.quick { display: grid; grid-template-columns: 1fr 2.2fr 1.5fr 1.2fr 110px; gap: 12px; align-items: end; padding: 0 18px 18px; }
.plan-tag { flex: none; padding: 2px 12px; border-radius: 8px; background: var(--raised); border: 1px solid var(--line); font-size: 14px; font-weight: 600; white-space: nowrap; }
.qf { display: block; min-width: 0; }
.qf > span { display: block; font-size: 14px; color: var(--muted); margin-bottom: 5px; }
.q-go { grid-column: 1 / -1; min-height: 52px; font-size: 18px; }
.q-err { grid-column: 1 / -1; margin: 0; }
.tools { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 14px 0 16px; }
.tools-search, .tools-actions { grid-column: 1 / -1; }
.tools-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.tools-actions .btn { flex: 1 1 170px; }
.count { margin: 0 0 10px; }
.more { text-align: center; margin-top: 16px; }
.more.before { margin: 0 0 12px; }
select.input { appearance: auto; font-size: 15px; }

/* تفاصيل الاشتراك */
.notes { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; margin: 0 0 14px; }
.notes summary { cursor: pointer; padding: 12px 16px; min-height: 44px; font: 600 16px var(--head); }
.notes-body { display: grid; gap: 10px; padding: 0 12px 12px; }
.note-card { background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.note-card h3 { font-size: 15.5px; font-weight: 600; }
.note-text { white-space: pre-wrap; overflow-wrap: anywhere; max-height: 170px; overflow-y: auto; font-size: 14.5px; color: var(--muted); }

/* الإيميل */
.email-card { display: flex; flex-direction: column; gap: 12px; scroll-margin: 90px; }
.card-link { display: flex; flex-direction: column; gap: 10px; }
.card-link:hover .email-addr { color: var(--accent); }
.head-actions { margin-top: 10px; }
.flash { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.email-addr { font-weight: 600; font-size: 16.5px; }
.email-addr h1 { font-size: 22px; font-weight: 600; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.muted { color: var(--muted); }
.small-text { font-size: 14.5px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin: 16px 0 24px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.stat b { display: block; font: 600 18px/1.4 var(--head); margin-top: 2px; }
.stat span { color: var(--muted); font-size: 13.5px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.section-head h2 { font-size: 18px; font-weight: 600; }
.slots { display: grid; gap: 10px; }
.slot { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; display: flex; flex-direction: column; gap: 8px; }
.slot.is-soon { border-color: #7a6426; } .slot.is-out { border-color: #7f4137; }
.slot-empty { display: flex; align-items: center; justify-content: center; min-height: 64px; width: 100%; background: none; border: 1.5px dashed var(--line); border-radius: 14px; color: var(--muted); }
.slot-empty:hover { color: var(--text); border-color: var(--muted); }
.phone { font: 600 18px var(--head); }
.pass-box { margin-top: 14px; }
.copy { background: none; border: 0; padding: 6px; min-width: 44px; min-height: 40px; color: var(--accent); font-size: 14px; }
.warn { color: var(--soon); font-size: 14px; }
.note { color: var(--muted); font-size: 14.5px; white-space: pre-wrap; overflow-wrap: anywhere; }
.empty { text-align: center; color: var(--muted); padding: 40px 16px; border: 1.5px dashed var(--line); border-radius: 16px; }

/* نتائج البحث */
.results { display: grid; gap: 8px; }
.result { display: block; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.result:hover { border-color: var(--muted); }

/* الدخول */
.auth { max-width: 400px; margin: 10vh auto 0; }
.auth h1 { font-size: 28px; margin: 12px 0 6px; }

/* النماذج */
dialog { width: min(480px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: 18px; padding: 22px; }
dialog::backdrop { background: rgba(0,0,0,.65); }
dialog h2 { font-size: 20px; font-weight: 600; margin-bottom: 14px; }
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 14.5px; color: var(--muted); margin-bottom: 5px; }
.input { width: 100%; min-height: 46px; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); }
textarea.input { min-height: 72px; resize: vertical; }
.input.en { direction: ltr; text-align: left; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.chip { min-height: 40px; padding: 4px 14px; border-radius: 99px; border: 1px solid var(--line); background: none; }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
textarea.input.big { min-height: 190px; }
.logo-field { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 14px; }
.hint { margin: 6px 0 0; }
input[type="color"].input, .color-input { padding: 4px; height: 46px; cursor: pointer; }
.color-input { width: 72px; }
.err { color: var(--out); font-size: 14.5px; margin: 0 0 12px; min-height: 0; }
.err:empty { display: none; }
.foot { display: flex; gap: 8px; margin-top: 6px; }
.foot .btn { flex: 1; }
.settings-group { border-top: 1px solid var(--line); padding: 14px 0; }
.settings-group:first-of-type { border-top: 0; padding-top: 0; }
.settings-group h3 { font-size: 16px; font-weight: 600; margin-bottom: 10px; }
.backup-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 4px 0; }

#toast { position: fixed; inset-inline: 16px; bottom: calc(20px + env(safe-area-inset-bottom)); margin: 0 auto; max-width: 420px; padding: 12px 16px; border-radius: 12px; background: var(--text); color: var(--bg); font-weight: 500; text-align: center; opacity: 0; transform: translateY(8px); transition: opacity .18s, transform .18s; pointer-events: none; z-index: 10; }
#toast.show { opacity: 1; transform: none; }
#toast.bad { background: var(--out); }

@media (max-width: 420px) {
  .two { grid-template-columns: 1fr; }
  .brand h1 { font-size: 23px; }
}
@media (max-width: 680px) {
  .quick { grid-template-columns: 1fr 1fr; padding: 0 14px 14px; }
  .q-mail, .q-pass { grid-column: 1 / -1; }
  .q-kind { grid-column: 1 / -1; }
}
@media (prefers-reduced-motion: reduce) { #toast { transition: none; } }
