/* عيادتي — التصميم الأصلي (تركواز مع لمسات خضراء وبنفسجية) */
* {
  box-sizing: border-box;
}
body {
  margin: 0;
  background: #f4f7f9;
  color: #223947;
  font:
    15px Tahoma,
    Arial;
}
button,
input,
select,
textarea {
  font: inherit;
}
button {
  cursor: pointer;
  border: 0;
  border-radius: 10px;
  padding: 12px 18px;
  background: #087f8c;
  color: white;
}
button.secondary {
  background: #e7f3f4;
  color: #087f8c;
}
aside {
  position: fixed;
  inset-inline-start: 0;
  top: 0;
  bottom: 0;
  width: 235px;
  background: #fff;
  border-inline-end: 1px solid #e1e9ed;
  padding: 28px 18px;
}
h1 {
  font-size: 28px;
  margin: 0 0 10px;
}
h2 {
  font-size: 20px;
}
aside h1 {
  color: #087f8c;
}
small,
.muted {
  color: #758794;
}
nav {
  margin-top: 36px;
}
nav button {
  display: block;
  width: 100%;
  text-align: start;
  margin: 7px 0;
  background: transparent;
  color: #526774;
}
nav button.active {
  background: #e5f4f3;
  color: #087f8c;
  font-weight: bold;
}
.foot {
  position: absolute;
  bottom: 25px;
  font-size: 12px;
  color: #7c8d98;
}
main {
  margin-inline-start: 235px;
  padding: 30px 38px;
}
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 30px;
}
.pill {
  background: #e8f4ee;
  color: #307958;
  padding: 9px 14px;
  border-radius: 20px;
  font-size: 12px;
}
.banner {
  background: #fff4db;
  border: 1px solid #ecdcb2;
  padding: 12px 18px;
  border-radius: 12px;
  margin-bottom: 24px;
  font-size: 13px;
}
.cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 18px;
}
.card,
.panel {
  background: white;
  border: 1px solid #e2e9ed;
  border-radius: 16px;
  padding: 24px;
}
.card strong {
  display: block;
  font-size: 30px;
  margin: 16px 0 8px;
}
.panel {
  margin-top: 22px;
}
.split {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 22px;
}
.toolbar {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
input,
select,
textarea {
  padding: 12px;
  border: 1px solid #d9e3e7;
  border-radius: 9px;
  background: #fff;
  min-width: 0;
}
input:focus,
textarea:focus {
  outline: 2px solid #87c6cb;
}
table {
  width: 100%;
  border-collapse: collapse;
  text-align: start;
}
td,
th {
  padding: 16px 10px;
  border-bottom: 1px solid #eef2f4;
  font-size: 14px;
}
th {
  color: #84929e;
  font-weight: normal;
}
.avatar {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: #e9f4f5;
  color: #087f8c;
  margin-inline-end: 12px;
}
.status {
  color: #087f8c;
  background: #e9f6f4;
  padding: 6px 10px;
  border-radius: 15px;
  font-size: 12px;
}
.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
label {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}
dialog {
  border: 0;
  border-radius: 18px;
  padding: 28px;
  width: min(540px, 95vw);
  box-shadow: 0 20px 70px #2345;
}
dialog::backdrop {
  background: #1237;
}
.rx {
  background: white;
  border: 1px solid #dce7eb;
  border-radius: 14px;
  padding: 30px;
  margin-top: 20px;
}
.rxhead {
  border-bottom: 3px solid #087f8c;
  padding-bottom: 20px;
  display: flex;
  justify-content: space-between;
}
.empty {
  text-align: center;
  padding: 35px;
  color: #7c8d98;
}
.notice {
  padding: 14px;
  background: #eaf5f5;
  border-radius: 10px;
  margin: 16px 0;
}
#toast {
  position: fixed;
  bottom: 25px;
  inset-inline-end: 25px;
  background: #234a54;
  color: white;
  padding: 14px 24px;
  border-radius: 12px;
  display: none;
  z-index: 9;
}
.scroll {
  overflow: auto;
}
@media (max-width: 850px) {
  aside {
    position: static;
    width: auto;
    padding: 16px;
  }
  nav {
    display: flex;
    overflow: auto;
    margin-top: 15px;
  }
  nav button {
    white-space: nowrap;
    width: auto;
  }
  .foot {
    display: none;
  }
  main {
    margin: 0;
    padding: 20px;
  }
  .cards {
    grid-template-columns: 1fr 1fr;
  }
  .split {
    grid-template-columns: 1fr;
  }
}

.printsheet {
  max-width: 420px;
  margin: 20px auto;
  font-size: 14px;
}
.medicine-print {
  padding: 14px 0;
  border-bottom: 1px dashed #bbb;
  overflow-wrap: anywhere;
}
.medicine-print p {
  margin: 6px 0;
}
.receipt-line {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px dashed #bbb;
}
.printhelp {
  font-size: 13px;
  color: #627784;
}


body {
  background:
    radial-gradient(ellipse at 8% 0%, #e8eefb 0, transparent 42%),
    radial-gradient(ellipse at 90% 100%, #e0f5ef 0, transparent 38%), #f5f8fb;
}
aside {
  background: linear-gradient(170deg, #fff 60%, #edf8f7);
  border-inline-end: 1px solid #dce8ed;
}
aside h1 {
  letter-spacing: -1px;
}
header {
  background: linear-gradient(105deg, #eef0ff, #e8f7f4);
  padding: 20px 24px;
  border-radius: 18px;
  border: 1px solid #dce9ed;
  box-shadow: 0 6px 24px #22394705;
}
.panel,
.card {
  box-shadow: 0 6px 24px #29465405;
}
.card {
  position: relative;
  overflow: hidden;
  border-top: 3px solid #159a9c;
}
.card:nth-child(2) {
  border-top-color: #8b78cc;
}
.card:nth-child(3) {
  border-top-color: #e3a247;
}
.card:nth-child(4) {
  border-top-color: #599bcf;
}
.card:after {
  content: "";
  position: absolute;
  width: 75px;
  height: 75px;
  border-radius: 50%;
  background: #087f8c06;
  inset-inline-end: -18px;
  bottom: -20px;
}
.status {
  display: inline-block;
  font-weight: bold;
  border: 1px solid transparent;
  white-space: nowrap;
}
.status-booked {
  color: #245da0;
  background: #eaf2ff;
  border-color: #c9dcfa;
}
.status-arrived {
  color: #95560b;
  background: #fff1d9;
  border-color: #f3d5a2;
}
.status-done {
  color: #246c48;
  background: #e5f5eb;
  border-color: #b9e0c9;
}
.status-cancelled {
  color: #a43f4b;
  background: #fdebee;
  border-color: #f2c4cc;
}
button {
  transition:
    background 0.15s,
    box-shadow 0.15s;
}
button:hover {
  box-shadow: 0 4px 12px #087f8c20;
}
nav button.active {
  background: linear-gradient(90deg, #def2ef, #ecf7f5);
  box-shadow: inset -3px 0 #087f8c;
}
tbody tr:hover {
  background: #f7fbfc;
}

.patient-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 24px 0 0;
  background: #e8eff3;
  padding: 7px;
  border-radius: 14px;
}
.patient-tabs button {
  background: transparent;
  color: #647782;
  flex: 1;
  white-space: nowrap;
}
.patient-tabs button.active {
  background: white;
  color: #087f8c;
  box-shadow: 0 3px 12px #22394710;
  font-weight: bold;
}
.detail {
  background: #f6f9fb;
  border-radius: 12px;
  padding: 18px;
}
.detail h2 {
  font-size: 17px;
  margin: 10px 0 0;
}
.clinical-summary {
  display: grid;
  grid-template-columns: 1.4fr 1fr 1.4fr;
  gap: 20px;
  border: 1px solid #cce4e2;
  border-radius: 14px;
  background: linear-gradient(100deg, #eaf6f3, #f3f4ff);
  padding: 20px;
  margin-bottom: 24px;
}
.clinical-summary h2 {
  margin: 8px 0;
}
.clinical-summary p {
  margin: 10px 0;
}
.operation-card {
  padding: 20px;
  margin: 15px 0;
  border: 1px solid #e3e3f4;
  border-inline-start: 4px solid #8b78cc;
  border-radius: 12px;
  background: #fafaff;
}
.eyebrow {
  color: #087f8c;
  font-weight: bold;
}
[hidden] {
  display: none !important;
}
@media (max-width: 650px) {
  .clinical-summary {
    grid-template-columns: 1fr;
    gap: 12px;
  }
  .patient-tabs button {
    flex: 1 1 40%;
  }
}

/* ===== إضافات النسخة السحابية ===== */
.toolbar { flex-wrap: wrap; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.actions button { padding: 9px 14px; }
button.danger { background: #fdebee; color: #a43f4b; }
button[disabled] { opacity: .55; cursor: not-allowed; }
.badge { display: inline-block; padding: 3px 9px; border-radius: 12px; font-size: 12px; background: #eef2f6; color: #526774; }
.saving { font-size: 12px; color: #758794; }
.auth-wrap { max-width: 460px; margin: 6vh auto; padding: 0 16px; }
.auth-wrap .brand { text-align: center; color: #087f8c; margin-bottom: 18px; }
.linkbtn { background: none; color: #087f8c; padding: 6px 0; text-decoration: underline; box-shadow: none !important; }
.who { font-size: 13px; color: #526774; margin-top: 14px; line-height: 1.7; }
.err { color: #a43f4b; white-space: pre-wrap; }
.searchlist { max-height: 300px; overflow: auto; border: 1px solid #deeaee; border-radius: 10px; }
.searchlist .row { padding: 10px; border-bottom: 1px solid #eef2f4; display: flex; justify-content: space-between; gap: 10px; align-items: center; }
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.chk { flex-direction: row; align-items: center; gap: 8px; }
dialog { max-height: 92vh; overflow: auto; }
dialog.wide { width: min(820px, 96vw); }
.foot { inset-inline: 18px; }
@media (max-width: 850px) {
  aside { border-inline-end: 0; border-bottom: 1px solid #dce8ed; }
  .cards { gap: 12px; }
  .card { padding: 16px; }
  .card strong { font-size: 24px; }
  header { flex-wrap: wrap; gap: 10px; }
}
@media (max-width: 600px) {
  .grid { grid-template-columns: 1fr; }
  main { padding: 12px; }
  .panel { padding: 16px; }
  td, th { padding: 10px 6px; font-size: 13px; }
  h1 { font-size: 22px; }
  dialog { padding: 18px; }
}

/* ===== الطباعة: 80 مم للروشتة والإيصال وطلب الفحص، وA4 أفقي للتقارير =====
   المحتوى المطبوع يُنسخ إلى #printArea، وكل ما عداه يُخفى أثناء الطباعة. */
.printsheet { max-width: 420px; margin: 20px auto; font-size: 14px; background: #fff; }
.medicine-print { padding: 14px 0; border-bottom: 1px dashed #bbb; overflow-wrap: anywhere; }
.medicine-print p { margin: 6px 0; }
.receipt-line { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px dashed #bbb; }
.printhelp { font-size: 13px; color: #627784; }
#printArea { display: none; }
/* ورق الإيصالات: بدون هوامش، والطول يحدده تعريف الطابعة (ورق 80 مم متصل) */
@page { margin: 0; }
@page wide { size: A4 landscape; margin: 12mm; }
@media print {
  body.printing { background: #fff !important; color: #000 !important; margin: 0; }
  body.printing > *:not(#printArea) { display: none !important; }
  body.printing #printArea { display: block !important; }
  #printArea .noprint { display: none !important; }
  body.print-80 { width: 80mm; }
  body.print-80 .printsheet { width: 72mm; max-width: 72mm; margin: 0 auto !important; padding: 4mm 0 !important; font: 12px Tahoma, Arial !important; border: 0 !important; }
  body.print-80 .printsheet h1 { font-size: 18px !important; }
  body.print-80 .printsheet h2 { font-size: 16px !important; }
  body.print-80 .printsheet .notice { background: none !important; border: 1px solid #000; padding: 5px; font-size: 11px; }
  .medicine-print, .receipt-line { break-inside: avoid; }
  body.print-a4 { page: wide; }
  body.print-a4 .card, body.print-a4 .panel { box-shadow: none !important; padding: 8px; border: 0; }
  body.print-a4 .card strong { font-size: 20px; margin: 4px; }
  body.print-a4 .scroll { overflow: visible; }
  body.print-a4 table { table-layout: fixed; }
  body.print-a4 td, body.print-a4 th { font-size: 11px; padding: 7px; overflow-wrap: anywhere; }
  body.print-a4 tr { break-inside: avoid; }
  body.print-a4 thead { display: table-header-group; }
  .status { color: #000 !important; background: #fff !important; }
}
/* عناصر الشبكة تنكمش بدل أن تدفع الصفحة للعرض */
.split { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.split > *, .grid > *, .cards > * { min-width: 0; }
@media (max-width: 850px) { .split { grid-template-columns: minmax(0, 1fr); } }

/* ---------------- مخطط الأسنان */
.dchart { position: relative; margin: 10px 0 6px; padding: 14px 8px; background: #fbfdfd; border: 1px solid #dce8ed; border-radius: 16px; overflow-x: auto; }
.dc-jaw { display: flex; justify-content: center; align-items: flex-end; gap: 2px; min-width: max-content; margin: 0 auto; }
.dc-jaw.lower { align-items: flex-start; }
.dc-jaw .mid { width: 2px; align-self: stretch; background: #c8d7dc; margin: 0 6px; }
.dc-line { height: 2px; background: #c8d7dc; margin: 6px 24px; }
.dc-side { position: absolute; inset: 10px 12px auto 12px; display: flex; justify-content: space-between; font-size: 11px; color: #7c8d98; pointer-events: none; }
.tooth { display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 3px 1px; min-width: 38px; background: none; border: 2px solid transparent; border-radius: 10px; color: #234a54; cursor: pointer; box-shadow: none; }
.tooth:hover { background: #eef7f8; }
.tooth b { font-size: 11px; font-weight: 600; line-height: 1.2; }
.tooth.sel { border-color: #087f8c; background: #e7f3f4; }
.tooth.planned svg { outline: 2px dashed #f08c00; outline-offset: 1px; border-radius: 8px; }
.tooth.missing b { color: #a8b3b9; }
.tooth .marks { display: flex; gap: 2px; min-height: 6px; }
.tooth .marks i, .dc-legend i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; }
.dc-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12.5px; color: #4a636b; margin: 6px 0 14px; }
.dc-legend span { display: inline-flex; align-items: center; gap: 5px; }
.dc-legend i { width: 11px; height: 11px; border-radius: 3px; }
.dc-legend i.pl { background: none; border: 2px dashed #f08c00; }
.dc-panel { border: 1px solid #dce8ed; border-radius: 14px; padding: 14px 16px; margin: 8px 0 16px; background: #fff; }
.dc-surf { grid-column: 1 / -1; border: 1px solid #e1e9ed; border-radius: 10px; display: flex; flex-wrap: wrap; gap: 6px 16px; }
@media print { .dchart { overflow: visible; } }

/* ===== إصلاحات بعد الاختبار ===== */
/* الموبايل: تسجيل الخروج وتغيير اللغة وكلمة المرور تظهر أسفل القائمة بدل اختفائها */
@media (max-width: 850px) {
  .foot { display: block; position: static; margin-top: 12px; padding-top: 10px; border-top: 1px solid #eef2f4; line-height: 2; }
  .foot .who { margin-top: 0; }
}
/* «إضافة فحص غير موجود» لا تتداخل مع الحقل الذي بعدها */
details { margin: 12px 0; }
details > summary { cursor: pointer; padding: 8px 0; color: #087f8c; }
details[open] { padding-bottom: 6px; }
/* مخطط الأسنان على الموبايل: الفك كاملًا في عرض الشاشة بدون تمرير */
@media (max-width: 600px) {
  .dchart { padding: 14px 2px; }
  .dc-jaw { gap: 0; min-width: 0; }
  .dc-jaw .mid { margin: 0 2px; }
  .dc-line { margin: 6px 8px; }
  .tooth { min-width: 0; flex: 1 1 0; padding: 2px 0; border-width: 1px; border-radius: 6px; }
  .tooth svg { width: 100%; max-width: 22px; height: auto; }
  .tooth b { font-size: 9px; }
  .tooth .marks i { width: 5px; height: 5px; }
}
@media (max-width: 600px) { .dc-jaw { width: 100%; } }
.dc-panel tr.editing td { background: #fff8e6; }
.dc-jaw.primary-row { margin: 4px 0; }
.dc-jaw.primary-row .tooth svg { transform: scale(.82); }
button.wa { background: #e7f8ee; color: #15803d; }
button.wa:hover { background: #d3f1df; }
.linkbox { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; background: #f3fafb; border: 1px dashed #9cc9ce; border-radius: 12px; padding: 10px 12px; margin-bottom: 14px; }
.linkbox code { direction: ltr; unicode-bidi: isolate; font-size: 13px; word-break: break-all; }
.day-head { margin: 18px 0 6px; font-size: 15px; color: #234a54; }
.badge.online { background: #e8f0fe; color: #1d4ed8; }
.badge.warn { background: #fff4db; color: #8a5a00; }
.overdue td { background: #fff6f6; }
.navcount { display: inline-block; min-width: 18px; padding: 0 6px; margin-inline-start: 6px; border-radius: 10px; background: #d64545; color: #fff; font-size: 11px; line-height: 18px; text-align: center; }
/* الموبايل: صفوف الجداول الطويلة (المواعيد، الحجوزات، المعمل) تتحول لكروت بدل التمرير للجنب */
@media (max-width: 600px) {
  .stack table, .stack tbody, .stack tr, .stack td { display: block; width: 100%; }
  .stack thead { display: none; }
  .stack tr { border: 1px solid #e3edf0; border-radius: 12px; padding: 8px 10px; margin-bottom: 10px; background: #fff; }
  .stack td { border: 0; padding: 4px 0; }
  .stack td:empty { display: none; }
  .stack .scroll { overflow: visible; }
}
/* القائمة الجانبية: الذيل (الحساب وتسجيل الخروج) تحت آخر بند بدل ما يغطي القائمة لما تطول */
@media (min-width: 851px) {
  aside { display: flex; flex-direction: column; overflow-y: auto; }
  aside .foot { position: static; margin-top: auto; padding-top: 16px; }
  nav { margin-top: 24px; }
  nav button { margin: 3px 0; padding-top: 9px; padding-bottom: 9px; }
}
.join-feats { margin: 0 0 18px; padding-inline-start: 20px; line-height: 2; color: #34525b; }
a.btnlink { display: inline-block; padding: 9px 14px; border-radius: 10px; background: #087f8c; color: #fff; text-decoration: none; font-size: 14px; }
a.btnlink.secondary { background: #e7f3f4; color: #087f8c; }
a.btnlink.wa { background: #e7f8ee; color: #15803d; }
