/* ============================================================================
 *  ویزیت منزل — استایل
 *
 *  دو قید که همه‌ی تصمیم‌ها را ساخته‌اند:
 *   ۱. این صفحه در خانه‌ی بیمار، ایستاده، با یک دست و زیر نور روز خوانده
 *      می‌شود. پس کنتراست بالا، تایپ درشت، و هدف لمسی ≥۴۸ پیکسل.
 *   ۲. عصر همین صفحه روی لپ‌تاپ کنار سامانه باز می‌شود. پس در عرض زیاد
 *      نباید کش بیاید؛ ستون محدود می‌ماند.
 * ========================================================================= */

@font-face {
  font-family: Vazirmatn; src: url(/fonts/Vazirmatn-Regular.woff2) format("woff2");
  font-weight: 400; font-display: swap;
}
@font-face {
  font-family: Vazirmatn; src: url(/fonts/Vazirmatn-Medium.woff2) format("woff2");
  font-weight: 500; font-display: swap;
}
@font-face {
  font-family: Vazirmatn; src: url(/fonts/Vazirmatn-Bold.woff2) format("woff2");
  font-weight: 700; font-display: swap;
}

:root {
  --bg: #F4F6F5;
  --surface: #FFFFFF;
  --ink: #16211B;
  --ink-soft: #55635C;
  --primary: #12594A;
  --primary-soft: #E6EFEC;
  --ok: #1B7A4F;
  --warn: #9A5716;
  --danger: #A33A31;
  --danger-soft: #FBEEEC;
  --border: #D6DEDA;
  --border-strong: #9EAEA7;

  --r: 12px;
  --tap: 48px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --ease: cubic-bezier(.23, 1, .32, 1);
  --shadow: 0 1px 2px rgba(22,33,27,.06), 0 4px 16px rgba(22,33,27,.05);
  color-scheme: light;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 15px/1.8 Vazirmatn, system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 6px; }
[hidden] { display: none !important; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

/* ── دروازه ─────────────────────────────────────────────────────────── */
.gate {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center; padding: 24px;
  background: var(--bg);
}
.gate-card {
  width: 100%; max-width: 360px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 28px 22px; box-shadow: var(--shadow);
}
.gate-title { margin: 0 0 6px; font-size: 22px; font-weight: 700; }
.gate-sub { margin: 0 0 18px; color: var(--ink-soft); font-size: 14px; }
.gate-err { margin: 10px 0 0; color: var(--danger); font-size: 14px; font-weight: 500; }

/* ── نوار بالا ──────────────────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding-top: var(--safe-t);
}
.topbar-in {
  display: flex; align-items: center; gap: 8px;
  max-width: 820px; margin: 0 auto; padding: 8px 12px; min-height: 56px;
}
.topbar-title { flex: 1; margin: 0; font-size: 17px; font-weight: 700; }
.icon-btn {
  width: var(--tap); height: var(--tap); flex: none;
  display: grid; place-items: center;
  background: none; border: 0; color: var(--ink); cursor: pointer; border-radius: 10px;
  transition: background 140ms var(--ease);
}
.icon-btn:active { background: var(--primary-soft); }

.sync {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: var(--tap); padding: 0 10px;
  background: none; border: 0; cursor: pointer;
  font: inherit; font-size: 13px; color: var(--ink-soft); border-radius: 10px;
}
.sync-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--border-strong); flex: none; }
.sync-dot.ok { background: var(--ok); }
.sync-dot.pending { background: var(--warn); }
.sync-dot.off { background: var(--border-strong); }

/* ── نماها ──────────────────────────────────────────────────────────── */
.view { max-width: 820px; margin: 0 auto; padding: 14px 12px 140px; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 14px; }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r);
  padding: 12px 8px; text-align: center;
}
.stat b { display: block; font-size: 22px; font-weight: 700; line-height: 1.3; }
.stat span { font-size: 12px; color: var(--ink-soft); }

/* ── فهرست بیماران ──────────────────────────────────────────────────── */
.list { display: flex; flex-direction: column; gap: 8px; }
.pcard {
  width: 100%; text-align: start;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r);
  padding: 12px 14px; cursor: pointer; font: inherit; color: inherit;
  display: flex; align-items: center; gap: 10px; min-height: 64px;
  transition: transform 140ms var(--ease), border-color 140ms var(--ease);
}
.pcard:active { transform: scale(.985); border-color: var(--border-strong); }
.pcard-main { flex: 1; min-width: 0; }
.pcard-name { font-weight: 700; font-size: 16px; }
.pcard-sub {
  font-size: 13px; color: var(--ink-soft);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.pcard-nid { font-size: 13px; color: var(--ink-soft); direction: ltr; text-align: right; }
.pill {
  flex: none; font-size: 11px; font-weight: 500;
  padding: 3px 8px; border-radius: 999px; white-space: nowrap;
}
.pill-pending { background: #FBF0E3; color: var(--warn); }
.pill-done { background: #E6F2EB; color: var(--ok); }
.pill-bad { background: var(--danger-soft); color: var(--danger); }

.empty { text-align: center; padding: 48px 20px; }
.empty-title { margin: 0 0 6px; font-weight: 700; font-size: 16px; }
.empty-sub { margin: 0; color: var(--ink-soft); font-size: 14px; }

.list-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 18px; }

/* ── کارت‌ها و فیلدها ───────────────────────────────────────────────── */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r); padding: 16px 14px; margin-bottom: 12px;
}
.card-h {
  margin: 0 0 12px; font-size: 16px; font-weight: 700;
  display: flex; align-items: center; gap: 8px;
}
.card-note { margin: -4px 0 12px; font-size: 13px; color: var(--ink-soft); }
.count-badge {
  background: var(--primary); color: #fff; font-size: 12px; font-weight: 700;
  min-width: 22px; height: 22px; border-radius: 999px;
  display: inline-grid; place-items: center; padding: 0 6px;
}

.lbl { display: block; font-size: 14px; font-weight: 500; margin: 14px 0 6px; }
.card > .lbl:first-of-type, .card .lbl:first-child { margin-top: 0; }
.opt { font-weight: 400; color: var(--ink-soft); font-size: 13px; }

.field {
  display: block; width: 100%; min-height: var(--tap);
  padding: 10px 12px; font: inherit; font-size: 16px; /* ۱۶ تا iOS زوم نکند */
  color: var(--ink); background: var(--surface);
  border: 1.5px solid var(--border-strong); border-radius: 10px;
  transition: border-color 140ms var(--ease), box-shadow 140ms var(--ease);
}
.field:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.field-num { direction: ltr; text-align: left; letter-spacing: .06em; font-variant-numeric: tabular-nums; }
.field-area { min-height: 84px; resize: vertical; line-height: 1.8; }
.field.bad { border-color: var(--danger); }
.field.good { border-color: var(--ok); }

.hint { margin: 6px 0 0; font-size: 13px; min-height: 20px; color: var(--ink-soft); }
.hint.bad { color: var(--danger); font-weight: 500; }
.hint.good { color: var(--ok); font-weight: 500; }

.row2 { display: grid; grid-template-columns: 1fr 1.4fr; gap: 12px; align-items: start; }

.seg { display: flex; gap: 8px; }
.seg-b {
  flex: 1; min-height: var(--tap); padding: 0 12px;
  background: var(--surface); border: 1.5px solid var(--border-strong);
  border-radius: 10px; font: inherit; font-size: 15px; color: var(--ink); cursor: pointer;
  transition: all 140ms var(--ease);
}
.seg-b[aria-pressed="true"] { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 500; }
.seg-b:active { transform: scale(.96); }

/* ── چیپ‌ها ─────────────────────────────────────────────────────────── */
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; -webkit-overflow-scrolling: touch; }
.chips-wrap { flex-wrap: wrap; overflow: visible; max-height: 152px; overflow-y: auto; }
.chip {
  flex: none; min-height: 40px; padding: 0 14px;
  display: inline-flex; align-items: center;
  background: var(--surface); border: 1.5px solid var(--border-strong);
  border-radius: 999px; font: inherit; font-size: 14px; color: var(--ink);
  cursor: pointer; white-space: nowrap;
  transition: all 140ms var(--ease);
  position: relative;
}
/* هدف لمسی را تا ۴۸ بی‌صدا بزرگ می‌کند بی‌آنکه چیپ چاق شود */
.chip::after { content: ""; position: absolute; inset: -4px; }
.chip[aria-pressed="true"] { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 500; }
.chip:active { transform: scale(.95); }

/* ── داروی انتخاب‌شده ───────────────────────────────────────────────── */
.chosen { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.chosen:empty { display: none; }
.crow {
  display: flex; align-items: center; gap: 8px;
  background: var(--primary-soft); border: 1px solid #C3DAD3;
  border-radius: 10px; padding: 8px 10px;
}
.crow-main { flex: 1; min-width: 0; }
.crow-n { font-weight: 500; font-size: 15px; }
.crow-d { font-size: 13px; color: var(--ink-soft); }
.crow-q {
  width: 76px; min-height: var(--tap); flex: none;
  padding: 4px 8px; font: inherit; font-size: 15px; text-align: center;
  border: 1.5px solid var(--border-strong); border-radius: 8px; background: var(--surface);
}
.crow-x {
  flex: none; width: 40px; height: 40px; display: grid; place-items: center;
  background: none; border: 0; color: var(--danger); cursor: pointer; border-radius: 8px;
  position: relative;
}
.crow-x::after { content: ""; position: absolute; inset: -4px; }
.crow-x:active { background: var(--danger-soft); }

.free-add { margin-top: 8px; }
.groups { margin-top: 12px; display: flex; flex-direction: column; gap: 6px; }
.grp { border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.grp-h {
  width: 100%; min-height: var(--tap); padding: 0 12px;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: var(--surface); border: 0; font: inherit; font-size: 15px; font-weight: 500;
  color: var(--ink); cursor: pointer; text-align: start;
}
.grp-h svg { width: 18px; height: 18px; transition: transform 200ms var(--ease); color: var(--ink-soft); }
.grp[open] .grp-h svg { transform: rotate(-90deg); }
.grp-body { padding: 4px 10px 12px; display: flex; flex-wrap: wrap; gap: 8px; }

/* ── دکمه‌ها ────────────────────────────────────────────────────────── */
.btn {
  min-height: var(--tap); padding: 0 18px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-size: 16px; font-weight: 500;
  border-radius: 10px; border: 1.5px solid transparent; cursor: pointer;
  transition: transform 140ms var(--ease), background 140ms var(--ease);
}
.btn:active { transform: scale(.97); }
.btn-block { width: 100%; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-ghost { background: var(--surface); color: var(--ink); border-color: var(--border-strong); }
.btn-danger-ghost { background: var(--surface); color: var(--danger); border-color: var(--danger); flex: none; padding: 0 16px; }
.btn:disabled { opacity: .5; cursor: default; transform: none; }

.bottombar {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 25;
  display: flex; gap: 8px;
  background: var(--surface); border-top: 1px solid var(--border);
  padding: 10px 12px calc(10px + var(--safe-b));
}
.bottombar > * { max-width: 820px; }
.form-pad { height: 20px; }

.fab {
  position: fixed; inset-inline-start: 16px; bottom: calc(16px + var(--safe-b)); z-index: 24;
  min-height: 56px; padding: 0 22px 0 18px;
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--primary); color: #fff; border: 0; border-radius: 999px;
  font: inherit; font-size: 16px; font-weight: 500; cursor: pointer;
  box-shadow: 0 4px 16px rgba(18,89,74,.3);
  transition: transform 140ms var(--ease);
}
.fab:active { transform: scale(.95); }

/* ── جمع‌بندی عصر ───────────────────────────────────────────────────── */
.evening-head { margin-bottom: 14px; }
.evening { display: flex; flex-direction: column; gap: 12px; }
.ecard {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r); padding: 14px; transition: opacity 200ms var(--ease);
}
/* عمداً opacity نیست: کارتِ ثبت‌شده باید همچنان خوانا بماند — ممکن است
   بخواهید کد رهگیری همان بیمار را دوباره بخوانید. تمایز با رنگ زمینه
   و نوار سبز است، نه با محو کردن متن. */
.ecard.is-done { background: #F1F7F3; border-color: #BAD6C7; }
.ecard.is-done .ecard-name::before { content: "✓ "; color: var(--ok); }
.ecard-top { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 10px; }
.ecard-name { flex: 1; font-weight: 700; font-size: 17px; }
.ecard-nid {
  direction: ltr; font-size: 16px; font-variant-numeric: tabular-nums;
  letter-spacing: .08em; font-weight: 500;
}
.ecard-meta { font-size: 13px; color: var(--ink-soft); margin-bottom: 8px; }
.ecard-dx { margin: 0 0 10px; font-size: 15px; }
.ecard-drugs { margin: 0 0 12px; padding: 0; list-style: none; font-size: 15px; }
.ecard-drugs li { padding: 3px 0; border-bottom: 1px dashed var(--border); }
.ecard-drugs li:last-child { border-bottom: 0; }
.ecard-note { font-size: 14px; color: var(--ink-soft); margin: 0 0 12px; }
.ecard-acts { display: flex; flex-wrap: wrap; gap: 8px; }
.btn-sm { min-height: 44px; padding: 0 12px; font-size: 14px; border-radius: 8px; }
.done-toggle {
  display: inline-flex; align-items: center; gap: 8px; min-height: 44px;
  padding: 0 12px; border-radius: 8px; border: 1.5px solid var(--border-strong);
  background: var(--surface); font: inherit; font-size: 14px; cursor: pointer; color: var(--ink);
}
.done-toggle[aria-pressed="true"] { background: var(--ok); border-color: var(--ok); color: #fff; }

/* ── توست ───────────────────────────────────────────────────────────── */
.toast {
  position: fixed; inset-inline: 16px; bottom: calc(84px + var(--safe-b)); z-index: 40;
  max-width: 420px; margin: 0 auto;
  background: var(--ink); color: #fff; border-radius: 10px;
  padding: 12px 16px; font-size: 15px; text-align: center;
  animation: toast-in 220ms var(--ease);
}
.toast.err { background: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; }
  .btn:active, .chip:active, .seg-b:active, .pcard:active, .fab:active { transform: none; }
}

@media (min-width: 720px) {
  .fab { inset-inline-start: auto; inset-inline-end: calc(50% - 410px + 16px); }
  .bottombar { justify-content: center; }
  .bottombar .btn-block { max-width: 400px; }
}

/* ── نوار روز ───────────────────────────────────────────────────────── */
.daybar { margin: -2px 0 8px; }
.day-chip { gap: 6px; }
.day-n {
  font-size: 12px; font-weight: 700; min-width: 20px; height: 20px;
  border-radius: 999px; display: inline-grid; place-items: center; padding: 0 5px;
  background: var(--primary-soft); color: var(--primary);
}
.day-chip[aria-pressed="true"] .day-n { background: rgba(255,255,255,.22); color: #fff; }
.day-label { margin: 0 0 14px; font-size: 14px; color: var(--ink-soft); font-weight: 500; }

/* ── کد رهگیری در کارت عصر ──────────────────────────────────────────── */
.track-row { display: flex; align-items: center; gap: 8px; margin: 0 0 12px; }
.track-lbl { flex: none; font-size: 14px; font-weight: 500; }
.track-in { flex: 1; min-width: 0; font-size: 16px; }

.evening-day { margin: 0 0 8px; font-size: 17px; font-weight: 700; }
.report-btns { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
@media (min-width: 560px) {
  .report-btns { flex-direction: row; }
}

/* ── شماره تماس در کارت عصر ─────────────────────────────────────────── */
/* شماره از خط meta بیرون آورده شد: یک شماره‌ی لاتین وسط متن فارسی،
   بر اثر الگوریتم دوجهته جابه‌جا دیده می‌شود. اینجا جهتش صریح است. */
.phone-row { display: flex; align-items: center; gap: 8px; margin: 0 0 10px; }
.phone-lbl { flex: none; font-size: 14px; color: var(--ink-soft); }
.phone-num {
  flex: 1; min-width: 0; font-size: 16px; font-weight: 500;
  font-variant-numeric: tabular-nums; letter-spacing: .04em;
  text-align: start;
}
