/* ================= دندان — پنل مدیریت مطب ================= */
@font-face { font-family: "Vazirmatn"; src: url("/lib/fonts/Vazirmatn-Variable.woff2") format("woff2"); font-weight: 100 900; font-display: swap; }

:root {
  --ink: #14324A;
  --ink-2: #22476A;
  --teal: #0F8F8A;
  --teal-600: #0B7672;
  --teal-50: #E4F3F2;
  --bg: #F2F5F8;
  --surface: #FFFFFF;
  --line: #E1E8EE;
  --muted: #687A8B;
  --amber: #D9822B;
  --amber-50: #FCF1E5;
  --rose: #D64545;
  --rose-50: #FBEAEA;
  --violet: #8A55D6;
  --blue: #2F7DE1;
  --green: #2E9E6A;
  --green-50: #E5F5EC;
  --enamel: #FBFCFD;
  --radius-lg: 18px;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(20, 50, 74, .05), 0 6px 18px -10px rgba(20, 50, 74, .18);
  --sidebar-w: 248px;
  --bs-font-sans-serif: "Vazirmatn", Tahoma, sans-serif;
  --bs-body-font-family: "Vazirmatn", Tahoma, sans-serif;
  --bs-primary: var(--teal);
  --bs-primary-rgb: 15, 143, 138;
  --bs-link-color: var(--teal-600);
  --bs-link-hover-color: var(--ink);
  --bs-border-color: var(--line);
}

html, body { font-family: "Vazirmatn", Tahoma, sans-serif; }
body.panel { background: var(--bg); color: var(--ink); font-size: 14.5px; line-height: 1.75; font-feature-settings: "ss01"; }
a { text-decoration: none; }
::selection { background: var(--teal); color: #fff; }
:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }

/* ---------- ساختار ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w); flex-shrink: 0; background: var(--ink); color: #C9D6E2;
  position: fixed; inset-block: 0; inset-inline-start: 0; z-index: 1030; display: flex; flex-direction: column;
  transition: transform .25s ease;
}
.sidebar .brand { display: flex; align-items: center; gap: .7rem; padding: 1.15rem 1.25rem 1rem; color: #fff; }
.sidebar .brand svg { width: 34px; height: 34px; flex-shrink: 0; }
.sidebar .brand b { font-size: 1.05rem; font-weight: 800; display: block; line-height: 1.3; }
.sidebar .brand small { color: #8FA6BB; font-size: .74rem; }
.sidebar nav { overflow-y: auto; padding: .25rem .75rem 1.5rem; flex: 1; scrollbar-width: thin; scrollbar-color: #2C5070 transparent; }
.sidebar .group { color: #6F8BA4; font-size: .72rem; font-weight: 600; margin: 1.1rem .6rem .35rem; }
.sidebar .nav-item {
  display: flex; align-items: center; gap: .7rem; color: #C9D6E2; padding: .52rem .75rem; border-radius: 10px;
  font-size: .9rem; font-weight: 500; margin-bottom: 1px; position: relative;
}
.sidebar .nav-item i { font-size: 1.05rem; width: 1.2rem; text-align: center; color: #7F9AB2; }
.sidebar .nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.sidebar .nav-item.active { background: var(--teal); color: #fff; }
.sidebar .nav-item.active i { color: #fff; }
.sidebar .nav-item .count { margin-inline-start: auto; background: var(--amber); color: #fff; font-size: .7rem; border-radius: 99px; padding: 0 .45rem; line-height: 1.5; font-weight: 700; }

.main { flex: 1; margin-inline-start: var(--sidebar-w); min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 1020; background: rgba(242,245,248,.86); backdrop-filter: blur(10px);
  display: flex; align-items: center; gap: .75rem; padding: .7rem 1.5rem; border-bottom: 1px solid var(--line);
}
.topbar .search { position: relative; flex: 1; max-width: 460px; }
.topbar .search input { border-radius: 99px; padding-inline-start: 2.4rem; background: var(--surface); border-color: var(--line); height: 40px; }
.topbar .search i { position: absolute; inset-inline-start: .95rem; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search-results { position: absolute; top: calc(100% + 6px); inset-inline: 0; background: #fff; border-radius: 14px; box-shadow: 0 18px 40px -12px rgba(20,50,74,.35); border: 1px solid var(--line); overflow: hidden; display: none; }
.search-results a { display: flex; justify-content: space-between; padding: .6rem 1rem; color: var(--ink); border-bottom: 1px solid var(--line); }
.search-results a:hover, .search-results a.on { background: var(--teal-50); }
.search-results small { color: var(--muted); }
.content { padding: 1.5rem; flex: 1; }
.menu-btn { display: none; }

@media (max-width: 991.98px) {
  .sidebar { transform: translateX(100%); }
  html[dir="ltr"] .sidebar { transform: translateX(-100%); }
  body.menu-open .sidebar { transform: none; box-shadow: 0 0 0 100vmax rgba(10,25,40,.45); }
  .main { margin-inline-start: 0; }
  .menu-btn { display: inline-flex; }
  .content { padding: 1rem; }
  .topbar { padding: .6rem 1rem; }
}

/* ---------- سربرگ صفحه ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.page-head h1 { font-size: 1.45rem; font-weight: 800; margin: 0; letter-spacing: -.01em; }
.page-head p { margin: .15rem 0 0; color: var(--muted); }
.page-head .actions { display: flex; gap: .5rem; flex-wrap: wrap; }

/* ---------- کارت‌ها ---------- */
.card-x { background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow); border: 1px solid rgba(225,232,238,.7); }
.card-x > .hd { display: flex; align-items: center; justify-content: space-between; padding: 1rem 1.25rem .25rem; gap: .5rem; }
.card-x > .hd h2, .card-x > .hd h3 { font-size: 1rem; font-weight: 700; margin: 0; }
.card-x > .hd a { font-size: .85rem; }
.card-x > .bd { padding: 1rem 1.25rem 1.25rem; }
.card-x.flat { box-shadow: none; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.kpi { background: var(--surface); border-radius: var(--radius-lg); padding: 1rem 1.15rem; box-shadow: var(--shadow); display: flex; gap: .9rem; align-items: center; border: 1px solid rgba(225,232,238,.7); }
.kpi .ic { width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center; font-size: 1.3rem; flex-shrink: 0; background: var(--teal-50); color: var(--teal); }
.kpi .ic.amber { background: var(--amber-50); color: var(--amber); }
.kpi .ic.rose { background: var(--rose-50); color: var(--rose); }
.kpi .ic.ink { background: #E7EDF3; color: var(--ink); }
.kpi .v { font-size: 1.35rem; font-weight: 800; line-height: 1.2; }
.kpi .l { color: var(--muted); font-size: .82rem; }
.kpi a.stretched { position: absolute; inset: 0; }

/* «درآمد روی میز» — مهم‌ترین عدد داشبورد */
.opportunity {
  background: var(--ink); color: #fff; border-radius: var(--radius-lg); padding: 1.4rem 1.5rem; position: relative; overflow: hidden;
  display: grid; grid-template-columns: 1fr auto; gap: 1rem; align-items: center; margin-bottom: 1.25rem;
}
.opportunity .big { font-size: 2.1rem; font-weight: 800; line-height: 1.15; }
.opportunity .big small { font-size: .95rem; font-weight: 500; color: #9FB6CA; }
.opportunity p { margin: .35rem 0 0; color: #B9CADA; max-width: 60ch; }
.opportunity .smile { position: absolute; inset-inline-end: -20px; bottom: -32px; width: 210px; opacity: .13; pointer-events: none; }
.opportunity .btn { position: relative; }

/* ---------- جدول ---------- */
.table-x { width: 100%; border-collapse: separate; border-spacing: 0; }
.table-x th { font-size: .78rem; font-weight: 600; color: var(--muted); padding: .55rem .75rem; border-bottom: 1px solid var(--line); white-space: nowrap; background: #F8FAFC; }
.table-x td { padding: .7rem .75rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table-x tr:last-child td { border-bottom: 0; }
.table-x tbody tr:hover td { background: #FAFCFD; }
.table-x .num { font-feature-settings: "tnum"; white-space: nowrap; }
.table-wrap { overflow-x: auto; }

/* ---------- برچسب وضعیت ---------- */
.chip { display: inline-flex; align-items: center; gap: .3rem; font-size: .76rem; font-weight: 600; padding: .12rem .6rem; border-radius: 99px; background: #EEF2F6; color: var(--ink-2); white-space: nowrap; }
.chip.teal { background: var(--teal-50); color: var(--teal-600); }
.chip.amber { background: var(--amber-50); color: #A65F17; }
.chip.rose { background: var(--rose-50); color: #A82F2F; }
.chip.green { background: var(--green-50); color: #1F7A50; }
.chip.violet { background: #F1EAFB; color: #6B3DB3; }
.chip.blue { background: #E6F0FC; color: #215FB0; }
.chip .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

/* ---------- دکمه و فرم ---------- */
.btn { border-radius: 10px; font-weight: 600; padding: .45rem 1rem; }
.btn-sm { border-radius: 8px; padding: .25rem .65rem; }
.btn-primary { --bs-btn-bg: var(--teal); --bs-btn-border-color: var(--teal); --bs-btn-hover-bg: var(--teal-600); --bs-btn-hover-border-color: var(--teal-600); --bs-btn-active-bg: var(--teal-600); --bs-btn-disabled-bg: var(--teal); }
.btn-ink { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn-ink:hover { background: var(--ink-2); color: #fff; }
.btn-soft { background: var(--teal-50); color: var(--teal-600); border: 0; }
.btn-soft:hover { background: #D2ECEA; color: var(--ink); }
.btn-light { background: #fff; border-color: var(--line); color: var(--ink); }
.btn-light:hover { background: #F4F7F9; border-color: #CBD6DF; }
.form-control, .form-select { border-radius: 10px; border-color: #D5DFE7; padding: .5rem .8rem; }
.form-control:focus, .form-select:focus { border-color: var(--teal); box-shadow: 0 0 0 .2rem rgba(15,143,138,.15); }
.form-label { font-size: .85rem; font-weight: 600; color: var(--ink-2); margin-bottom: .3rem; }
.form-text { color: var(--muted); }
.form-check-input:checked { background-color: var(--teal); border-color: var(--teal); }
.input-group-text { border-radius: 10px; background: #F4F7F9; border-color: #D5DFE7; color: var(--muted); font-size: .85rem; }
.ltr { direction: ltr; text-align: left; }
input[data-money], input.num-in { font-feature-settings: "tnum"; }

.alert-x { border-radius: 12px; padding: .75rem 1rem; display: flex; gap: .6rem; align-items: center; margin-bottom: 1rem; font-weight: 500; }
.alert-x.ok { background: var(--green-50); color: #1F6F49; }
.alert-x.err { background: var(--rose-50); color: #9C2B2B; }
.alert-x.warn { background: var(--amber-50); color: #8C5214; }

.empty { text-align: center; padding: 2.5rem 1rem; color: var(--muted); }
.empty i { font-size: 2.2rem; color: #B7C6D3; display: block; margin-bottom: .5rem; }
.empty .btn { margin-top: .75rem; }

.muted { color: var(--muted); }
.fw-800 { font-weight: 800; }
.avatar { width: 40px; height: 40px; border-radius: 12px; background: var(--teal-50); color: var(--teal-600); display: inline-grid; place-items: center; font-weight: 800; flex-shrink: 0; }
.avatar.lg { width: 64px; height: 64px; border-radius: 18px; font-size: 1.5rem; }
.list-row { display: flex; align-items: center; gap: .8rem; padding: .7rem 0; border-bottom: 1px solid var(--line); }
.list-row:last-child { border-bottom: 0; }
.list-row .grow { flex: 1; min-width: 0; }
.list-row .t { font-weight: 600; }
.list-row .s { color: var(--muted); font-size: .82rem; }
.time-pill { font-weight: 800; font-feature-settings: "tnum"; min-width: 52px; text-align: center; background: #EEF2F6; border-radius: 10px; padding: .2rem .4rem; font-size: .9rem; }

.tabs-x { display: flex; gap: .25rem; border-bottom: 1px solid var(--line); margin-bottom: 1.25rem; overflow-x: auto; scrollbar-width: none; }
.tabs-x a { padding: .65rem 1rem; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; white-space: nowrap; font-size: .9rem; }
.tabs-x a.active { color: var(--ink); border-color: var(--teal); }
.tabs-x a .count { font-size: .72rem; background: #E7EDF3; border-radius: 99px; padding: 0 .4rem; margin-inline-start: .25rem; }

.medical-alert { background: var(--rose-50); color: #9C2B2B; border-radius: 12px; padding: .55rem .85rem; font-weight: 600; display: flex; gap: .5rem; align-items: center; }

/* ---------- تقویم نوبت‌ها ---------- */
.cal { display: block; background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow); overflow: hidden; border: 1px solid rgba(225,232,238,.7); }
.cal-head { display: grid; position: relative; z-index: 5; background: #fff; border-bottom: 1px solid var(--line); }
.cal-head div { padding: .6rem .5rem; text-align: center; font-weight: 700; font-size: .85rem; border-inline-start: 1px solid var(--line); }
.cal-head div small { display: block; color: var(--muted); font-weight: 500; }
.cal-head div.today { color: var(--teal); background: var(--teal-50); }
.cal-body { display: grid; position: relative; }
.cal-times div { height: 56px; font-size: .75rem; color: var(--muted); text-align: center; border-top: 1px dashed var(--line); padding-top: 2px; font-feature-settings: "tnum"; }
.cal-col { position: relative; border-inline-start: 1px solid var(--line); background-image: repeating-linear-gradient(to bottom, transparent 0, transparent 55px, var(--line) 55px, var(--line) 56px); }
.cal-col.off { background-color: #F8FAFB; }
.cal-col .slot { position: absolute; inset-inline: 0; height: 14px; cursor: copy; }
.cal-col .slot:hover { background: rgba(15,143,138,.08); }
.appt { position: absolute; inset-inline: 3px; border-radius: 9px; padding: .2rem .45rem; font-size: .76rem; line-height: 1.45; overflow: hidden; color: var(--ink); background: var(--teal-50); border-inline-start: 4px solid var(--teal); cursor: pointer; z-index: 2; }
.appt b { display: block; font-size: .8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appt.requested { background: var(--amber-50); border-color: var(--amber); }
.appt.done { opacity: .6; }
.appt.cancelled, .appt.noshow { background: #F3F4F6; border-color: #9AA5B1; text-decoration: line-through; opacity: .6; }
.appt.arrived { background: #E6F0FC; border-color: var(--blue); }
.now-line { position: absolute; inset-inline: 0; height: 2px; background: var(--rose); z-index: 3; }
.now-line::before { content: ""; position: absolute; inset-inline-start: -4px; top: -4px; width: 10px; height: 10px; border-radius: 50%; background: var(--rose); }

/* ---------- تاریخ‌نمای شمسی ---------- */
.jdp { position: absolute; z-index: 2000; background: #fff; border-radius: 14px; box-shadow: 0 20px 40px -12px rgba(20,50,74,.4); border: 1px solid var(--line); padding: .7rem; width: 270px; user-select: none; }
.jdp .jh { display: flex; justify-content: space-between; align-items: center; margin-bottom: .4rem; font-weight: 700; }
.jdp .jh button { border: 0; background: #F2F5F8; border-radius: 8px; width: 30px; height: 30px; }
.jdp .jg { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; text-align: center; font-size: .82rem; }
.jdp .jg span { padding: .35rem 0; color: var(--muted); font-size: .72rem; }
.jdp .jg button { border: 0; background: none; border-radius: 8px; padding: .32rem 0; font-feature-settings: "tnum"; }
.jdp .jg button:hover { background: var(--teal-50); }
.jdp .jg button.sel { background: var(--teal); color: #fff; }
.jdp .jg button.td { outline: 1px solid var(--teal); }
.jdp .jf { display: flex; justify-content: space-between; margin-top: .4rem; }
.jdp .jf button { border: 0; background: none; color: var(--teal-600); font-weight: 600; font-size: .82rem; }

/* ---------- امضا ---------- */
.sign-pad { border: 2px dashed #C3D1DC; border-radius: 14px; background: #fff; touch-action: none; width: 100%; height: 220px; cursor: crosshair; }

/* ---------- چاپ ---------- */
@media print {
  .sidebar, .topbar, .no-print, .page-head .actions { display: none !important; }
  .main { margin: 0 !important; }
  .content { padding: 0 !important; }
  .card-x { box-shadow: none; border: 1px solid #ddd; }
  body.panel { background: #fff; }
}

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ================= چارت دندانی ================= */
.chart-wrap { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 1rem; align-items: start; }
@media (max-width: 1199.98px) { .chart-wrap { grid-template-columns: 1fr; } }
.chart-card { background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow); border: 1px solid rgba(225,232,238,.7); padding: .75rem 1rem 1rem; }
.chart-tools { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; margin-bottom: .5rem; }
.chart-tools .form-check { margin: 0; }
#chartHost { direction: ltr; overflow-x: auto; }
.dchart { width: 100%; min-width: 760px; height: auto; display: block; user-select: none; }
.dchart [data-tooth] { cursor: pointer; }
.dchart .tbg { fill: transparent; transition: fill .15s; }
.dchart .tbg:hover { fill: #EEF5F8; }
.dchart .tbg.sel { fill: #DDF1EF; stroke: #0F8F8A; stroke-width: 1.4; }
.dchart .tooth.missing { opacity: .16; }
.dchart .tooth:hover path { filter: brightness(1.03); }
.dchart .marks { pointer-events: none; }
.dchart .tnum { font: 600 11.5px Vazirmatn, sans-serif; fill: #687A8B; }
.dchart .tnum.sel { fill: #0F8F8A; font-weight: 800; font-size: 13px; }
.dchart .pcount { font: 700 8.5px Vazirmatn, sans-serif; fill: #fff; pointer-events: none; }
.dchart .surf .sp { stroke: #AEBBC6; stroke-width: .8; transition: fill .1s; }
.dchart .surf .sp:hover { stroke: #0F8F8A; stroke-width: 1.4; }
.dchart .surf .sp.on { stroke: #0F8F8A; stroke-width: 2.2; }
.dchart .surf.gone { opacity: .25; }

.legend { display: flex; flex-wrap: wrap; gap: .35rem .9rem; font-size: .76rem; color: var(--muted); margin-top: .6rem; }
.legend span { display: inline-flex; align-items: center; gap: .3rem; }
.legend i { width: 11px; height: 11px; border-radius: 3px; display: inline-block; }

.tooth-panel { background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow); border: 1px solid rgba(225,232,238,.7); position: sticky; top: 76px; max-height: calc(100vh - 92px); overflow-y: auto; }
.tooth-panel .empty { padding: 2rem 1.25rem; }
.tp-head { display: flex; gap: .75rem; align-items: center; padding: 1rem 1rem .75rem; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: #fff; z-index: 2; }
.tp-num { width: 46px; height: 46px; border-radius: 14px; background: var(--ink); color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 1.15rem; flex-shrink: 0; }
.tp-sec { padding: .8rem 1rem; border-bottom: 1px solid var(--line); }
.tp-sec:last-child { border-bottom: 0; }
.tp-label { font-size: .78rem; font-weight: 700; color: var(--muted); margin-bottom: .45rem; }
.sbtns { display: grid; grid-template-columns: repeat(5, 1fr); gap: .3rem; }
.sbtn { border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: .25rem 0; font-weight: 800; line-height: 1.2; color: var(--ink); }
.sbtn small { display: block; font-size: .62rem; font-weight: 500; color: var(--muted); }
.sbtn.on { background: var(--teal); border-color: var(--teal); color: #fff; }
.sbtn.on small { color: #DDF1EF; }
.cbtns { display: grid; grid-template-columns: 1fr 1fr; gap: .3rem; }
.cbtn { border: 1px solid var(--line); background: #fff; border-radius: 9px; padding: .3rem .5rem; font-size: .78rem; display: flex; align-items: center; gap: .4rem; text-align: start; color: var(--ink); }
.cbtn:hover { border-color: var(--teal); background: var(--teal-50); }
.cbtn span { width: 12px; height: 12px; border-radius: 4px; flex-shrink: 0; }
.cond-row { display: flex; gap: .5rem; align-items: center; padding: .35rem 0; font-size: .86rem; }
.cond-row .grow { flex: 1; min-width: 0; }
.cond-row .sw { width: 12px; height: 12px; border-radius: 4px; flex-shrink: 0; }
.thumbs { display: grid; grid-template-columns: repeat(3, 1fr); gap: .35rem; }
.thumbs a { display: grid; place-items: center; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: #F2F5F8; color: var(--muted); }
.thumbs img { width: 100%; height: 100%; object-fit: cover; }

.mic-btn { width: 84px; height: 84px; border-radius: 50%; border: 0; background: var(--teal); color: #fff; font-size: 2rem; display: grid; place-items: center; margin: 0 auto; box-shadow: 0 10px 24px -8px rgba(15,143,138,.6); }
.mic-btn.rec { background: var(--rose); animation: pulse 1.4s infinite; }
.mic-btn:disabled { background: #B7C6D3; box-shadow: none; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(214,69,69,.45); } 70% { box-shadow: 0 0 0 18px rgba(214,69,69,0); } 100% { box-shadow: 0 0 0 0 rgba(214,69,69,0); } }

.chart-toast { position: fixed; bottom: 24px; left: 50%; transform: translate(-50%, 20px); background: var(--ink); color: #fff; padding: .6rem 1.1rem; border-radius: 12px; opacity: 0; transition: .25s; z-index: 3000; font-weight: 600; box-shadow: 0 12px 30px -10px rgba(20,50,74,.5); }
.chart-toast.show { opacity: 1; transform: translate(-50%, 0); }
.chart-toast.err { background: var(--rose); }

.patient-head { display: flex; gap: 1rem; align-items: center; margin-bottom: 1rem; flex-wrap: wrap; }
.patient-head h1 { font-size: 1.4rem; font-weight: 800; margin: 0; }
.patient-head .meta { color: var(--muted); font-size: .86rem; display: flex; gap: 1rem; flex-wrap: wrap; }
.patient-head .meta span { display: inline-flex; gap: .3rem; align-items: center; }
.balance { margin-inline-start: auto; text-align: end; }
.balance b { display: block; font-size: 1.15rem; }
.balance.debt b { color: var(--rose); }
@media (max-width: 600px) { .opportunity { grid-template-columns: 1fr; } .opportunity .big { font-size: 1.7rem; } }
