/* ============ لوحة إدارة اشتراكات الأطباء ============ */
*, *::before, *::after { box-sizing: border-box; }

:root {
  --bg: #F1F5F4;
  --surface: #FFFFFF;
  --surface-2: #F6FAF9;
  --ink: #0E1E24;
  --ink-2: #35494F;
  --muted: #6C8189;
  --line: #E1EAE8;
  --teal: #0E7A6E;
  --teal-dark: #0A5B52;
  --teal-soft: #E2F2EF;
  --blue: #2B5EA8;
  --blue-soft: #E8EFFA;
  --rose: #B23A48;
  --rose-soft: #FCEBED;
  --amber: #A9711B;
  --amber-soft: #FBF1DF;
  --grey: #74868D;
  --grey-soft: #EDF2F3;
  --shadow-1: 0 1px 2px rgba(14,30,36,.05), 0 6px 18px -12px rgba(14,30,36,.22);
  --radius: 16px;
}

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg);
  overflow: hidden;
}
body {
  font-family: 'IBM Plex Sans Arabic', 'Tajawal', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  font-size: 15px;
}
button, input, textarea, select { font-family: inherit; font-size: inherit; color: inherit; }
button { -webkit-user-select: none; user-select: none; }
h1, h2, h3, p { margin: 0; }
.hidden { display: none !important; }

/* ---------------- gate ---------------- */
.gate {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  padding: 18px;
  background:
    radial-gradient(120% 90% at 50% 0%, #124b45 0%, #0c2d2b 55%, #081d1d 100%);
  overflow-y: auto;
}
.gate-card {
  width: 100%; max-width: 380px;
  background: var(--surface);
  border-radius: 22px;
  padding: 26px 22px 20px;
  box-shadow: 0 26px 60px -20px rgba(0,0,0,.6);
  display: flex; flex-direction: column; align-items: center;
  gap: 10px; text-align: center;
  margin: auto;
}
.gate-mark {
  width: 54px; height: 54px; border-radius: 16px;
  display: grid; place-items: center;
  background: linear-gradient(160deg, #14A08F, #0E7A6E);
  color: #fff;
  box-shadow: 0 8px 18px -8px rgba(14,122,110,.9);
}
.gate-card h1 { font-size: 21px; font-weight: 700; color: var(--ink); }
.gate-sub { font-size: 13.5px; line-height: 1.7; color: var(--muted); }
.gate-owner {
  font-size: 12px; font-weight: 700; color: var(--teal-dark);
  background: var(--teal-soft); border: 1px solid #CDE8E2;
  border-radius: 999px; padding: 4px 12px; margin-top: -2px;
}
.gate-form { width: 100%; display: flex; flex-direction: column; gap: 10px; margin-top: 4px; }
.gate-note { font-size: 11.5px; line-height: 1.6; color: var(--muted); margin-top: 6px; }
.linkbtn {
  border: none; background: none; padding: 6px 4px;
  color: var(--teal); font-size: 13px; font-weight: 600;
  cursor: pointer; text-decoration: underline; text-underline-offset: 3px;
  min-height: 36px;
}

/* ---------------- shell ---------------- */
.shell {
  display: flex; flex-direction: column;
  height: 100vh; height: 100dvh;
  background: var(--bg);
}
.topbar {
  flex: 0 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  z-index: 10;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 11px;
  display: grid; place-items: center; flex: 0 0 auto;
  background: var(--teal-soft); color: var(--teal);
}
.brand-txt { display: flex; flex-direction: column; min-width: 0; }
.brand-txt b {
  font-size: 15px; font-weight: 700; line-height: 1.35;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.brand-txt span {
  font-size: 11px; color: var(--muted); line-height: 1.4;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar-actions { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }
.owner-chip {
  display: inline-flex; align-items: center; gap: 6px;
  max-width: 160px; min-width: 0;
  font-size: 11.5px; font-weight: 700; color: var(--teal);
  background: var(--teal-soft);
  border: 1px solid #CDE8E2;
  padding: 3px; padding-inline-end: 10px;
  border-radius: 999px;
}
.owner-av {
  flex: 0 0 auto;
  width: 22px; height: 22px; border-radius: 50%;
  display: grid; place-items: center;
  background: #fff; color: var(--teal);
  font-size: 11px; font-weight: 700;
}
.owner-nick { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.iconbtn {
  width: 38px; height: 38px; border-radius: 11px;
  display: grid; place-items: center;
  border: 1px solid var(--line); background: var(--surface-2);
  color: var(--ink-2); cursor: pointer;
  transition: background .12s ease, transform .1s ease;
}
.iconbtn:active { transform: scale(.94); background: var(--grey-soft); }
.iconbtn:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }

/* ---------------- tabs ---------------- */
.tabbar {
  order: 3; flex: 0 0 auto;
  display: flex; gap: 6px;
  padding: 7px 10px;
  background: rgba(255,255,255,.96);
  border-top: 1px solid var(--line);
  z-index: 10;
}
.tab {
  flex: 1 1 0; min-width: 0; min-height: 50px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px;
  border: none; border-radius: 13px; background: none;
  color: var(--muted); cursor: pointer;
  font-size: 11px; font-weight: 600;
  transition: background .14s ease, color .14s ease;
}
.tab.active { color: var(--teal); background: var(--teal-soft); }
.tab:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }

.main {
  order: 2; flex: 1 1 auto; min-height: 0;
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 14px 14px 26px;
}
.view { max-width: 880px; margin: 0 auto; display: flex; flex-direction: column; gap: 14px; }

/* ---------------- headings ---------------- */
.view-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 10px; flex-wrap: wrap;
}
.view-head h2 { font-size: 19px; font-weight: 700; line-height: 1.4; }
.sub { font-size: 12.5px; color: var(--muted); line-height: 1.6; margin-top: 2px; }
.sec-title { font-size: 14px; font-weight: 700; color: var(--ink-2); margin-top: 4px; }

/* ---------------- stats ---------------- */
.stats {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px;
}
.stat {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; padding: 10px 12px;
  display: flex; flex-direction: column; gap: 1px;
  box-shadow: var(--shadow-1);
}
.stat-n { font-size: 20px; font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat-l { font-size: 11.5px; color: var(--muted); line-height: 1.5; }
.stat.free .stat-n { color: var(--teal); }
.stat.paid .stat-n { color: var(--blue); }
.stat.expired .stat-n { color: var(--rose); }

/* ---------------- search ---------------- */
.search {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; padding: 0 12px;
  box-shadow: var(--shadow-1);
}
.search svg { color: var(--muted); flex: 0 0 auto; }
.search input {
  flex: 1 1 auto; min-width: 0; min-height: 46px;
  border: none; background: none; outline: none;
  font-size: 14.5px;
}
.search input::placeholder { color: #9AA9AE; }

/* ---------------- doctor cards ---------------- */
.doc-grid { display: grid; grid-template-columns: 1fr; gap: 9px; }
.doc-card {
  display: flex; align-items: center; gap: 12px;
  width: 100%; text-align: start;
  padding: 13px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-1);
  cursor: pointer; color: inherit;
  transition: transform .12s ease, border-color .12s ease, box-shadow .12s ease;
}
.doc-card:active { transform: scale(.985); }
.doc-card:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }
.doc-card:hover { border-color: #CFE0DC; }
.avatar {
  flex: 0 0 auto;
  width: 44px; height: 44px; border-radius: 13px;
  display: grid; place-items: center;
  font-size: 15px; font-weight: 700;
  background: var(--grey-soft); color: var(--grey);
}
.avatar.t-teal { background: var(--teal-soft); color: var(--teal); }
.avatar.t-blue { background: var(--blue-soft); color: var(--blue); }
.avatar.t-rose { background: var(--rose-soft); color: var(--rose); }
.avatar.lg { width: 58px; height: 58px; border-radius: 17px; font-size: 19px; }
.doc-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1 1 auto; }
.doc-name { font-size: 14.5px; font-weight: 700; line-height: 1.4; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-spec { font-size: 12px; color: var(--muted); line-height: 1.5; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-foot { display: flex; align-items: center; gap: 7px; margin-top: 4px; flex-wrap: wrap; }
.doc-date { font-size: 11px; color: var(--muted); }
.chev { flex: 0 0 auto; color: #B6C5C9; }

/* ---------------- badges ---------------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; font-weight: 700; line-height: 1.4;
  padding: 3px 9px; border-radius: 999px;
  white-space: nowrap;
}
.badge.big { font-size: 13px; padding: 5px 13px; }
.b-teal { background: var(--teal-soft); color: var(--teal); }
.b-blue { background: var(--blue-soft); color: var(--blue); }
.b-rose { background: var(--rose-soft); color: var(--rose); }
.b-grey { background: var(--grey-soft); color: var(--grey); }
.b-amber { background: var(--amber-soft); color: var(--amber); }

.empty {
  text-align: center; padding: 26px 16px;
  color: var(--muted); font-size: 13.5px; line-height: 1.7;
  background: var(--surface); border: 1px dashed var(--line);
  border-radius: var(--radius);
}

/* ---------------- doctor detail ---------------- */
.back {
  align-self: flex-start;
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 40px; padding: 6px 12px 6px 8px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface); color: var(--ink-2);
  font-size: 13px; font-weight: 600; cursor: pointer;
}
.back:active { background: var(--grey-soft); }
.back:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }

.profile {
  display: flex; align-items: center; gap: 13px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 15px;
  box-shadow: var(--shadow-1);
}
.profile-body { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.profile-body h2 { font-size: 17px; font-weight: 700; line-height: 1.4; }
.profile-body .spec { font-size: 12.5px; color: var(--muted); }
.chips-line { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.mini-chip {
  font-size: 11.5px; color: var(--ink-2);
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 999px; padding: 3px 10px;
}

.status-card {
  border-radius: var(--radius);
  padding: 15px;
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow-1);
  display: flex; flex-direction: column; gap: 12px;
}
.status-card.tone-teal { background: linear-gradient(180deg, #F3FBF9, #FFFFFF 60%); border-color: #CDE8E2; }
.status-card.tone-blue { background: linear-gradient(180deg, #F4F8FE, #FFFFFF 60%); border-color: #D3E1F6; }
.status-card.tone-rose { background: linear-gradient(180deg, #FEF6F7, #FFFFFF 60%); border-color: #F3D5D9; }
.status-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.days-left { font-size: 12px; font-weight: 600; color: var(--ink-2); }
.status-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.status-grid > div { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.status-grid span { font-size: 11px; color: var(--muted); }
.status-grid b { font-size: 13.5px; font-weight: 600; line-height: 1.5; word-break: break-word; }
.free-note {
  font-size: 12.5px; line-height: 1.7; color: var(--teal-dark);
  background: var(--teal-soft); border-radius: 11px; padding: 9px 12px;
}

.actions { display: grid; grid-template-columns: 1fr; gap: 8px; }

/* ---------------- buttons ---------------- */
.btn {
  min-height: 48px; padding: 11px 18px;
  border-radius: 13px; border: 1px solid transparent;
  font-size: 14.5px; font-weight: 600;
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  transition: transform .1s ease, background .14s ease, box-shadow .14s ease;
  text-align: center;
}
.btn:active { transform: scale(.98); }
.btn:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }
.btn-block { width: 100%; }
.btn-primary {
  background: linear-gradient(180deg, #12907F, #0E7A6E);
  color: #fff;
  box-shadow: 0 6px 16px -8px rgba(14,122,110,.95);
}
.btn-primary:active { box-shadow: 0 2px 8px -6px rgba(14,122,110,.95); }
.btn-outline {
  background: var(--surface); color: var(--teal-dark);
  border-color: #BFDDD7;
}
.btn-outline:active { background: var(--teal-soft); }
.btn-ghost {
  background: var(--surface-2); color: var(--ink-2);
  border-color: var(--line);
}
.btn-ghost:active { background: var(--grey-soft); }
.btn-danger {
  background: var(--surface); color: var(--rose);
  border-color: #EFC9CE;
}
.btn-danger:active { background: var(--rose-soft); }
.btn-sm { min-height: 42px; padding: 8px 14px; font-size: 13.5px; border-radius: 12px; }

/* ---------------- timeline / log ---------------- */
.timeline { display: flex; flex-direction: column; gap: 8px; }
.log-item {
  display: flex; gap: 11px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; padding: 12px 13px;
  box-shadow: var(--shadow-1);
}
.log-dot {
  flex: 0 0 auto; width: 9px; height: 9px; border-radius: 50%;
  margin-top: 7px; background: var(--grey);
}
.log-dot.d-teal { background: var(--teal); box-shadow: 0 0 0 4px rgba(14,122,110,.13); }
.log-dot.d-blue { background: var(--blue); box-shadow: 0 0 0 4px rgba(43,94,168,.12); }
.log-dot.d-rose { background: var(--rose); box-shadow: 0 0 0 4px rgba(178,58,72,.12); }
.log-dot.d-amber { background: var(--amber); box-shadow: 0 0 0 4px rgba(169,113,27,.14); }
.log-body { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.log-top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.log-top b { font-size: 13.5px; font-weight: 700; }
.log-top time { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.log-doc { font-size: 12.5px; color: var(--ink-2); }
.log-detail { font-size: 12px; color: var(--muted); line-height: 1.6; }
.log-reason {
  font-size: 12px; line-height: 1.65; color: var(--ink-2);
  background: var(--surface-2); border-radius: 9px; padding: 6px 10px; margin-top: 2px;
}

/* ---------------- settings ---------------- */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 15px;
  box-shadow: var(--shadow-1);
  display: flex; flex-direction: column; gap: 11px;
}
.card h3 { font-size: 14px; font-weight: 700; }
.card p.hint { font-size: 12px; line-height: 1.7; color: var(--muted); }

/* ---------------- fields ---------------- */
.field { display: flex; flex-direction: column; gap: 5px; text-align: start; width: 100%; }
.lbl { font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
.lbl em { color: var(--rose); font-style: normal; }
.field input, .field textarea, .field select {
  width: 100%; min-height: 46px;
  padding: 11px 13px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface-2);
  outline: none;
  font-size: 15px;
  transition: border-color .14s ease, background .14s ease;
  resize: vertical;
}
.field textarea { min-height: 78px; line-height: 1.6; }
.field input:focus, .field textarea:focus, .field select:focus {
  border-color: var(--teal); background: #fff;
  box-shadow: 0 0 0 3px rgba(14,122,110,.12);
}
.form-error { font-size: 12.5px; color: var(--rose); min-height: 0; line-height: 1.6; }
.form-error:empty { display: none; }

/* ---------------- modal ---------------- */
.modal-root {
  position: fixed; inset: 0; z-index: 90;
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet-backdrop {
  position: absolute; inset: 0;
  background: rgba(9,26,30,.5);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  animation: fade .16s ease-out;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.sheet {
  position: relative;
  width: 100%; max-width: 520px;
  max-height: 90vh; max-height: 90dvh;
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: var(--surface);
  border-radius: 22px 22px 0 0;
  padding: 6px 18px 18px;
  box-shadow: 0 -14px 44px -14px rgba(9,26,30,.5);
  animation: rise .22s cubic-bezier(.2,.9,.3,1);
}
@keyframes rise { from { transform: translateY(28px); opacity: .6; } to { transform: none; opacity: 1; } }
.sheet-inner { display: flex; flex-direction: column; gap: 12px; padding-top: 10px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.sheet-head h3 { font-size: 16.5px; font-weight: 700; }
.sheet-sub { font-size: 12.5px; color: var(--muted); margin-top: -6px; }
.sheet-actions { display: flex; gap: 8px; margin-top: 2px; }
.sheet-actions .btn { flex: 1 1 0; }
.xbtn {
  width: 38px; height: 38px; flex: 0 0 auto;
  border-radius: 11px; border: 1px solid var(--line);
  background: var(--surface-2); color: var(--ink-2);
  display: grid; place-items: center; cursor: pointer;
  font-size: 17px; line-height: 1;
}
.xbtn:active { background: var(--grey-soft); }

.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip {
  min-height: 42px; padding: 8px 14px;
  border-radius: 11px; border: 1px solid var(--line);
  background: var(--surface-2); color: var(--ink-2);
  font-size: 13px; font-weight: 600; cursor: pointer;
  transition: background .14s ease, border-color .14s ease, color .14s ease;
}
.chip.on { background: var(--teal-soft); border-color: #9FD3C9; color: var(--teal-dark); }
.chip:disabled { opacity: .45; cursor: not-allowed; }
.check {
  display: flex; align-items: center; gap: 9px;
  font-size: 13px; color: var(--ink-2);
  padding: 6px 2px; cursor: pointer;
}
.check input { width: 19px; height: 19px; accent-color: var(--teal); flex: 0 0 auto; }
.dates { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.preview {
  font-size: 12.5px; line-height: 1.75;
  color: var(--teal-dark);
  background: var(--teal-soft);
  border-radius: 11px; padding: 9px 12px;
}
.preview b { font-weight: 700; }

/* طلب معاينة بطاقة الطبيب */
.dcard {
  border-radius: 18px; padding: 18px;
  background: linear-gradient(165deg, #0F8578, #0A5B52);
  color: #fff;
  display: flex; flex-direction: column; gap: 12px;
}
.dcard-head { display: flex; align-items: center; gap: 12px; }
.dcard-head .av {
  width: 46px; height: 46px; border-radius: 14px;
  display: grid; place-items: center;
  background: rgba(255,255,255,.18); font-weight: 700;
}
.dcard-head b { font-size: 16px; display: block; }
.dcard-head span { font-size: 12px; opacity: .82; }
.dcard-status {
  background: rgba(255,255,255,.14);
  border-radius: 13px; padding: 11px 13px;
  display: flex; flex-direction: column; gap: 3px;
}
.dcard-status b { font-size: 15px; }
.dcard-status span { font-size: 12.5px; opacity: .9; line-height: 1.65; }
.dcard-owner {
  font-size: 11.5px; opacity: .8; text-align: start;
  border-top: 1px solid rgba(255,255,255,.22); padding-top: 9px;
}

/* ---------------- toast ---------------- */
.toast {
  position: fixed; left: 50%; bottom: 86px;
  transform: translate(-50%, 12px);
  z-index: 120;
  padding: 9px 18px; border-radius: 999px;
  background: rgba(14,30,36,.94); color: #fff;
  font-size: 13px; font-weight: 600; white-space: nowrap;
  max-width: 90vw; overflow: hidden; text-overflow: ellipsis;
  opacity: 0; pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------------- responsive ---------------- */
@media (min-width: 520px) {
  .doc-grid { grid-template-columns: 1fr 1fr; }
  .stats { grid-template-columns: repeat(4, 1fr); }
  .actions { grid-template-columns: 1fr 1fr; }
  .sheet { border-radius: 22px; margin-bottom: 6vh; }
  .modal-root { align-items: center; padding: 16px; }
  .toast { bottom: 24px; }
}
@media (min-width: 760px) {
  .main { order: 3; padding: 20px 22px 40px; }
  .tabbar {
    order: 2;
    max-width: 430px; margin: 12px auto 0;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 15px;
    padding: 5px;
    gap: 4px;
    box-shadow: var(--shadow-1);
  }
  .tab { flex-direction: row; gap: 7px; min-height: 42px; font-size: 13px; }
  .topbar { padding: 12px 22px; }
  .toast { bottom: 28px; }
}
@media (max-width: 380px) {
  .brand-txt b { font-size: 14px; }
  .owner-chip { max-width: 104px; }
  .status-grid { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}