/* ═══ تطبيق العيادة ═══ */
.shell { display: grid; grid-template-columns: 208px 1fr; min-height: 100vh; min-height: 100dvh; }
@media (max-width: 900px) { .shell { grid-template-columns: 1fr; } }

.sidebar { background: var(--surface); border-inline-end: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 14px 10px; }
.brand { display: flex; align-items: center; gap: 8px; padding: 4px 8px 14px; }
.brand .logo { font-size: 1.4rem; }
.brand .name { font-weight: 800; font-size: .9rem; line-height: 1.25; }
.brand .sub { font-size: .68rem; color: var(--faint); }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item { display: flex; align-items: center; gap: 9px; padding: 9px 11px; border-radius: var(--radius-sm);
  color: var(--muted); font-weight: 600; font-size: .875rem; cursor: pointer; border: none;
  background: transparent; font-family: inherit; text-align: start; white-space: nowrap; }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.on { background: var(--brand-soft); color: var(--brand-ink); }
.nav-item .ico { font-size: 1rem; width: 19px; text-align: center; }
.nav-item .n { margin-inline-start: auto; font-size: .7rem; background: var(--danger);
  color: var(--on-danger); padding: 0 6px; border-radius: 999px; font-weight: 700; }
.side-foot { margin-top: auto; padding: 10px; font-size: .72rem; color: var(--faint); }

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 10px; padding: 11px 20px;
  border-bottom: 1px solid var(--line); background: var(--surface); flex-wrap: wrap; }
.content { padding: 20px; width: 100%; max-width: 1500px; }
@media (max-width: 640px) { .content { padding: 12px; } }

.impersonate-bar {
  background: var(--warn); color: var(--on-warn); padding: 7px 18px; font-size: .82rem;
  font-weight: 700; display: flex; align-items: center; gap: 10px;
}
.trial-bar {
  background: var(--info-soft); color: var(--info); padding: 7px 18px;
  font-size: .82rem; font-weight: 700; display: flex; align-items: center; gap: 10px;
}

/* ── الدخول ─────────────────────────────────────────────────────────── */
.login-page { min-height: 100vh; min-height: 100dvh; display: flex; align-items: center; justify-content: center;
  padding: 20px; background: linear-gradient(155deg, var(--bg) 40%, var(--brand-soft)); }
.login-card { width: 100%; max-width: 400px; }
.login-card .card-body { padding: 26px; }
.login-logo { text-align: center; font-size: 2.8rem; }

/* ── شاشة الممنوع ───────────────────────────────────────────────────── */
.blocked-page { min-height: 100vh; min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.blocked-card { max-width: 520px; width: 100%; text-align: center; }
.blocked-card .icon { font-size: 3.2rem; margin-bottom: 10px; }
.blocked-card .kv { text-align: start; margin: 18px 0; }
/* 8.23:1 — تغميق الأخضر مع أبيض لا ينفع: #128c4a=4.31 و#0f8a45=4.43، كلاهما يسقط */
.wa-btn { background: #25d366 !important; border-color: #1aa851 !important; color: #06251a !important; }

/* ═══ خريطة الأسنان — أهم شاشة في النظام ═══════════════════════════════ */
.chart-wrap { background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px 14px; overflow-x: auto; }
.arch { display: flex; justify-content: center; gap: 22px; min-width: max-content; }
.arch + .arch { margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--line); }
.quad { display: flex; gap: 3px; }

.tooth { width: 40px; display: flex; flex-direction: column; align-items: center; gap: 2px; }
/* 🔴 هذا زرّ (chart.js) — بلا إعادة تهيئة كان المتصفح يرسم خلفية ButtonFace
   رمادية وحدّ outset تحت كل الـ٥٢ سن، في الوضعين معًا. */
.tooth .no {
  appearance: none; background: none; border: 0; padding: 0; cursor: pointer; line-height: 1.2;
  font-family: inherit; font-size: .68rem; color: var(--muted); font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.tooth .no:hover:not(:disabled) { color: var(--brand); }
.tooth.sel .no { color: var(--brand); }
.tooth-box {
  width: 38px; height: 38px; display: grid; cursor: pointer;
  grid-template-columns: 8px 1fr 8px; grid-template-rows: 8px 1fr 8px;
  border: 1px solid var(--line); border-radius: 4px; overflow: hidden; background: var(--surface-2);
  transition: box-shadow .12s;
}
.tooth-box:hover { box-shadow: 0 0 0 2px var(--brand-soft); }
.tooth.sel .tooth-box { box-shadow: 0 0 0 2px var(--brand); }
.surf { background: transparent; border: 0; padding: 0; cursor: pointer; }
.surf:hover { filter: brightness(.88); outline: 1px solid var(--brand); outline-offset: -1px; }
.surf.s-B { grid-area: 1 / 1 / 2 / 4; }
.surf.s-L { grid-area: 3 / 1 / 4 / 4; }
.surf.s-M { grid-area: 2 / 1 / 3 / 2; }
.surf.s-D { grid-area: 2 / 3 / 3 / 4; }
.surf.s-O { grid-area: 2 / 2 / 3 / 3; border-radius: 2px; }
.tooth-box.mirror .surf.s-M { grid-area: 2 / 3 / 3 / 4; }
.tooth-box.mirror .surf.s-D { grid-area: 2 / 1 / 3 / 2; }

.tooth-box.whole { position: relative; }
.tooth-box.whole::after {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background: var(--whole-color); opacity: .85;
}
.tooth-box.missing::after { background: repeating-linear-gradient(45deg,
  var(--hatch) 0 4px, transparent 4px 6px); opacity: 1; }
.tooth .mark { font-size: .6rem; line-height: 1; height: 8px; color: var(--warn); font-weight: 800; }

.chart-legend { display: flex; flex-wrap: wrap; gap: 6px 12px; margin-top: 14px;
  padding-top: 12px; border-top: 1px solid var(--line-soft); }
.legend-item { display: flex; align-items: center; gap: 5px; font-size: .74rem; color: var(--muted); }
.legend-swatch { width: 12px; height: 12px; border-radius: 3px;
  border: 1px solid color-mix(in srgb, var(--text) 35%, transparent); }

.timeline-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 14px; background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--radius-sm); margin-bottom: 12px; }

.cond-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 6px; }
.cond-btn { display: flex; align-items: center; gap: 7px; padding: 8px 10px; cursor: pointer;
  border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface);
  font: inherit; font-size: .82rem; font-weight: 600; text-align: start; }
.cond-btn:hover { border-color: var(--brand); background: var(--brand-soft); }
.cond-dot { width: 13px; height: 13px; border-radius: 3px; flex: 0 0 auto;
  border: 1px solid color-mix(in srgb, var(--text) 35%, transparent); }

/* ═══ التقويم ══════════════════════════════════════════════════════════ */
.cal { display: grid; border: 1px solid var(--line); border-radius: var(--radius);
  overflow: auto; background: var(--surface); max-height: 74vh; max-height: 74dvh; }
.cal-head { display: contents; }
.cal-cell { border-inline-end: 1px solid var(--line-soft); border-bottom: 1px solid var(--line-soft);
  min-height: 30px; position: relative; }
.cal-time { font-size: .68rem; color: var(--faint); padding: 2px 6px; text-align: center;
  background: var(--surface-2); white-space: nowrap; font-variant-numeric: tabular-nums;
  position: sticky; inset-inline-start: 0; z-index: 2; border-bottom: 1px solid var(--line-soft); }
.cal-col-head { position: sticky; top: 0; z-index: 3; background: var(--surface-2);
  padding: 8px 6px; font-size: .8rem; font-weight: 700; text-align: center;
  border-bottom: 1px solid var(--line); border-inline-end: 1px solid var(--line-soft); }
.appt {
  position: absolute; inset-inline: 2px; border-radius: 5px; padding: 3px 6px;
  font-size: .72rem; line-height: 1.3; overflow: hidden; cursor: pointer; z-index: 1;
  border-inline-start: 3px solid var(--appt-color, var(--brand)); color: var(--appt-ink, #fff);
  background: var(--appt-color, var(--brand)); box-shadow: var(--shadow);
}
.appt .nm { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appt .mt { font-size: .66rem; }
.appt.st-DONE {
  opacity: 1; border-inline-start-style: dashed; color: var(--text);
  background: color-mix(in srgb, var(--appt-color, var(--brand)) 40%, var(--surface));
}
.appt.st-CANCELLED, .appt.st-NOSHOW {
  opacity: 1; text-decoration: line-through; color: var(--text);
  background: color-mix(in srgb, var(--appt-color, var(--brand)) 25%, var(--surface));
}
.appt .flag { font-size: .7rem; }

.day-list { display: flex; flex-direction: column; gap: 8px; }
.day-item { display: flex; align-items: center; gap: 12px; padding: 11px 14px;
  border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface);
  border-inline-start: 4px solid var(--appt-color, var(--brand)); }
.day-item .time { font-weight: 800; font-size: .95rem; white-space: nowrap;
  font-variant-numeric: tabular-nums; }

/* ═══ المريض ═══════════════════════════════════════════════════════════ */
.patient-head { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap;
  padding: 16px 20px; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); margin-bottom: 14px; box-shadow: var(--shadow); }
.patient-head .avatar { width: 48px; height: 48px; border-radius: 50%; background: var(--brand-soft);
  color: var(--brand-ink); display: grid; place-items: center; font-size: 1.2rem; font-weight: 800; }
.patient-head .nm { font-size: 1.25rem; font-weight: 800; }
.patient-head .meta { display: flex; gap: 6px 14px; flex-wrap: wrap; font-size: .82rem;
  color: var(--muted); margin-top: 3px; }

.result-list { display: flex; flex-direction: column; }
.result-item { display: flex; align-items: center; gap: 12px; padding: 10px 14px;
  border-bottom: 1px solid var(--line-soft); cursor: pointer; }
.result-item:hover { background: var(--surface-2); }
.result-item:last-child { border-bottom: none; }
.result-item .file { font-family: var(--mono); font-size: .74rem; color: var(--faint); white-space: nowrap; }

.plan-item-row { display: flex; align-items: center; gap: 10px; padding: 9px 0;
  border-bottom: 1px solid var(--line-soft); flex-wrap: wrap; }
.plan-item-row:last-child { border-bottom: none; }
.tooth-tag { background: var(--surface-2); border: 1px solid var(--line); border-radius: 5px;
  padding: 1px 7px; font-size: .74rem; font-weight: 700; white-space: nowrap;
  font-variant-numeric: tabular-nums; }

.doc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.doc-card { border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden;
  background: var(--surface); }
.doc-card img { width: 100%; height: 110px; object-fit: cover; display: block; cursor: pointer;
  background: var(--surface-2); }
.doc-card .cap { padding: 6px 8px; font-size: .74rem; }

/* ── اللثة: رقم ثم Tab، ماوس هنا = الطبيب لن يستخدمها ────────────────── */
.perio-table { border-collapse: collapse; font-size: .78rem; }
.perio-table th, .perio-table td { border: 1px solid var(--line-soft); padding: 0; text-align: center; }
.perio-table th { background: var(--surface-2); padding: 4px 6px; font-size: .72rem;
  font-variant-numeric: tabular-nums; }
.perio-table input { width: 34px; padding: 3px 2px; text-align: center; border: none;
  background: transparent; font-size: .78rem; border-radius: 0; }
.perio-table input:focus { box-shadow: inset 0 0 0 2px var(--brand); }
.perio-table input.deep { background: var(--danger-soft); color: var(--danger); font-weight: 700; }
.perio-table td.bleed { background: var(--danger-soft); }

.bar-chart { display: flex; align-items: flex-end; gap: 3px; height: 120px; }
.bar-chart .bar { flex: 1; background: var(--brand); border-radius: 3px 3px 0 0; min-height: 2px;
  position: relative; }
.bar-chart .bar.alt { background: var(--info); }

/* ── المتجاوب: بعد القواعد الأساسية حتى لا تكسبه ─────────────────────── */
@media (max-width: 900px) {
  /* 🔴 الجذر: عمود 1fr حدّه الأدنى auto = عرض الـnav الأفقي، و overflow-x:hidden
     على body يقصّ الفائض — فتصير عناصر التنقّل غير قابلة للوصول لا بتمرير ولا بلمس.
     و auto 1fr تمنع الصفّين من اقتسام الفراغ (٣٥٣px فراغ على آيباد طولي). */
  .shell { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; }
  .sidebar { min-width: 0; }
  .sidebar nav {
    scroll-snap-type: x proximity; scrollbar-width: none;
    -webkit-mask-image: linear-gradient(to left, #000 calc(100% - 26px), transparent);
            mask-image: linear-gradient(to left, #000 calc(100% - 26px), transparent);
  }
  .sidebar nav .nav-item { scroll-snap-align: start; }
  .sidebar { border-inline-end: none; border-bottom: 1px solid var(--line); padding: 8px; }
  .sidebar nav { flex-direction: row; overflow-x: auto; gap: 4px; }
  .sidebar .brand, .sidebar .side-foot { display: none; }
}

/* الصف كله هدف ضغط — لا يبحث الطبيب عن اللينك الصغير */
.day-item.clickable { cursor: pointer; transition: border-color .12s, background .12s; }
.day-item.clickable:hover { background: var(--surface-2); border-color: var(--muted); }

/* ═══ دليل الاستخدام ═══════════════════════════════════════════════════ */
.faq { display: flex; flex-direction: column; gap: 12px; min-height: 340px; }
.faq-head { position: sticky; top: -18px; z-index: 2; background: var(--surface);
  padding-bottom: 8px; display: flex; flex-direction: column; gap: 4px; }
.faq-search { font-size: 1rem; padding: 11px 14px; }

.faq-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.faq-tabs button {
  border: 1px solid var(--line); background: var(--surface); color: var(--muted);
  padding: 6px 12px; border-radius: 999px; cursor: pointer; font: inherit;
  font-size: .82rem; font-weight: 600; white-space: nowrap;
}
.faq-tabs button:hover { border-color: var(--muted); color: var(--text); }
.faq-tabs button.on { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }

.faq-section { margin-bottom: 18px; }
.faq-section > h3 { margin: 6px 0 8px; color: var(--brand-ink); font-size: 1rem; }

.faq-item { border: 1px solid var(--line); border-radius: var(--radius-sm);
  margin-bottom: 6px; background: var(--surface); overflow: hidden; }
.faq-item > summary {
  cursor: pointer; padding: 11px 14px; font-weight: 700; font-size: .9rem;
  list-style: none; display: flex; align-items: flex-start; gap: 8px;
}
.faq-item > summary::-webkit-details-marker { display: none; }
.faq-item > summary::before { content: '▸'; color: var(--brand); flex: 0 0 auto; }
.faq-item[open] > summary::before { content: '▾'; }
.faq-item > summary:hover { background: var(--surface-2); }
.faq-item[open] { border-color: var(--brand); }
.faq-item[open] > summary { background: var(--brand-soft); color: var(--brand-ink); }

.faq-a { padding: 4px 16px 13px 34px; font-size: .88rem; line-height: 1.75; color: var(--text); }
.faq-a p { margin: 0 0 7px; }
.faq-list { margin: 0 0 7px; padding-inline-start: 18px; }
.faq-list li { margin-bottom: 4px; }
.faq-where { margin-top: 9px; font-size: .78rem; color: var(--muted);
  background: var(--surface-2); border-radius: 6px; padding: 5px 9px; display: inline-block; }

.faq-hit { margin-bottom: 8px; }
.faq-hit-sec { font-size: .72rem; color: var(--faint); font-weight: 700; margin-bottom: 3px; }
.faq mark { background: var(--warn-soft); color: var(--warn); padding: 0 2px;
  border-radius: 3px; font-weight: 700; }

@media (max-width: 640px) {
  .faq-a { padding-inline: 14px 20px; }
}

/* ══ تجاوب تطبيق العيادة ══════════════════════════════════════════════ */
.faq-a { max-width: 80ch; }   /* ٧٦ محرفًا عربيًا — قياس فعلي */

@media (max-width: 640px) {
  /* قوس الأسنان: ربع فوق ربع بدل صفّ واحد بعرض ٧٦٠px */
  .chart-wrap { padding: 12px 8px; }
  .arch { flex-direction: column; align-items: flex-start; min-width: 0; gap: 6px; }
  .arch + .arch { margin-top: 8px; padding-top: 8px; }
  .quad { gap: 2px; }
  .tooth { width: 46px; flex: 0 0 auto; }
  .tooth-box { width: 44px; height: 44px;
    grid-template-columns: 12px 1fr 12px; grid-template-rows: 12px 1fr 12px; }
  .tooth .no { font-size: .78rem; min-height: 22px; }

  /* بدون التكديس يقفز الشريط من ٢٣٠px إلى ٥٤٢px عند تكبير الأزرار */
  .timeline-bar { flex-direction: column; align-items: stretch; gap: 8px; }
  .timeline-bar > .spacer { display: none; }
  .timeline-bar .row.wrap { flex: none; }
  .timeline-bar label { max-width: none; }

  .faq-tabs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none;
              scroll-snap-type: x proximity; padding-bottom: 4px; }
  .faq-tabs button { scroll-snap-align: start; flex: 0 0 auto; }
}

@media (min-width: 1600px) {
  .tooth { width: 54px; }
  .tooth-box { width: 52px; height: 52px;
    grid-template-columns: 11px 1fr 11px; grid-template-rows: 11px 1fr 11px; }
  .result-list { max-width: 1100px; }
}

@media (pointer: coarse) {
  .nav-item { min-height: 44px; }
  .cond-btn { min-height: 44px; padding: 11px 10px; }
  .cond-grid { gap: 8px; }
  .perio-table input { width: 44px; height: 44px; padding: 2px; font-size: 16px; }
  .perio-table th { padding: 6px 2px; }
  .cal { --slot-h: 44px; }
  .cal-cell { min-height: 44px; }
  .appt { min-height: 40px; }
  .day-item a.bold { display: inline-block; padding-block: 11px; }
}

/* الموبايل بالعرض: ارتفاع ~٣٩٠px، الشريط الجانبي كان ياكل الشاشة */
@media (max-width: 900px) and (max-height: 480px) {
  .sidebar { position: sticky; top: 0; z-index: 5; padding: 4px; }
  .topbar { padding: 6px 14px; }
}

/* التقويم الأسبوعي: سبعة أعمدة تحتاج ١٢٠٠px — دونها تُقصّ رؤوس البطاقات */
.week-grid { display: grid; gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(min(170px, 100%), 1fr)); }
@media (min-width: 1200px) { .week-grid { grid-template-columns: repeat(7, minmax(0, 1fr)); } }
