/* =========================================================================
 * MeeClass v2.1 — app.css
 * ระบบดีไซน์ Light Premium สืบทอดจาก Togtag Dashboard v26.09
 * v2.1: จูนโทนตามแนวทาง Notion/Linear/Stripe (awesome-claude-design) —
 *   พื้นกระดาษอุ่น, hairline เดียวกันทั้งระบบ, เงาบางซ้อนชั้น, ลดกรอบ chip
 * ใช้คู่กับ Tailwind Play CDN (utility classes อยู่ใน markup)
 * สำรองเวอร์ชันก่อนหน้า: css/app.css.bak-v20
 * ========================================================================= */

/* ---------- Design tokens (v2.1 polish — แนวทาง Notion/Linear/Stripe) ----------
 * พื้นกระดาษอุ่นสบายตา · เส้นขอบ hairline เดียวกันทั้งระบบ · เงาบางแบบซ้อนชั้น */
:root {
  --paper: #f6f5f2;                 /* พื้นหลังโทนกระดาษอุ่น (ลดแสบตากว่าโทนฟ้าเย็น) */
  --hairline: #e8e7e2;              /* เส้นขอบการ์ด/ตัวแบ่ง */
  --hairline-soft: #f0efeb;         /* เส้นแบ่งภายใน (แทนเส้นประ) */
  --shadow-card: 0 1px 2px rgba(0,0,0,0.02), 0 4px 16px -8px rgba(24,20,12,0.06);
  --shadow-lift: 0 2px 4px rgba(0,0,0,0.03), 0 14px 28px -14px rgba(24,20,12,0.14);
}

/* ---------- CI Theme ตามคลินิกที่ใช้งาน (กัน user สับสนว่าอยู่คลินิกไหน) ----------
 * CC = เหลือง · DC = ชมพู · MC = แดง · ทุกคลินิก = น้ำเงิน (ค่าเริ่มต้น) */
:root, body[data-ci="all"] {
  --ci: #2563eb;
  --ci-soft: #dbeafe;
  --ci-softer: #eff6ff;
  --ci-text: #1d4ed8;
  --ci-wash1: rgba(191,219,254,.40);
  --ci-wash2: rgba(221,214,254,.30);
}
body[data-ci="classcare"] {
  --ci: #eab308; --ci-soft: #fef08a; --ci-softer: #fefce8; --ci-text: #854d0e;
  --ci-wash1: rgba(253,224,71,.40); --ci-wash2: rgba(253,230,138,.30);
}
body[data-ci="dearclass"] {
  --ci: #ec4899; --ci-soft: #fbcfe8; --ci-softer: #fdf2f8; --ci-text: #be185d;
  --ci-wash1: rgba(249,168,212,.40); --ci-wash2: rgba(251,207,232,.32);
}
body[data-ci="menclass"] {
  --ci: #ef4444; --ci-soft: #fecaca; --ci-softer: #fef2f2; --ci-text: #991b1b;
  --ci-wash1: rgba(252,165,165,.40); --ci-wash2: rgba(254,202,202,.32);
}

/* ริบบิ้นสีคลินิกพาดบนสุดของจอ — เห็นตลอดเวลาว่าอยู่คลินิกไหน */
body[data-ci]::after {
  content: '';
  position: fixed; top: 0; left: 0; right: 0; height: 4px;
  background: var(--ci); z-index: 60; pointer-events: none;
}
body[data-ci="all"]::after { background: linear-gradient(90deg, #2563eb, #7c3aed); }

/* ---------- พื้นฐาน ---------- */
html { font-size: 115%; min-height: 100%; }
body {
  font-family: 'Anuphan', sans-serif;
  background-color: var(--paper);
  color: #1e293b;
  min-height: 100vh;
}
/* หัวข้อรัดตัวอักษรเล็กน้อย (แนว Notion/Linear) — เบามากพอไม่กระทบสระ/วรรณยุกต์ไทย */
h1, h2, h3 { letter-spacing: -0.01em; }
/* gradient พื้นหลังวาดบนเลเยอร์ fixed แยกต่างหาก —
 * แก้บั๊ก gradient ขาด/เลื่อนตาม scroll (background-attachment: fixed ใช้ไม่ได้บนมือถือ)
 * โทนกลางเบาๆ เหมือนกันทุกแบรนด์ (ไม่ย้อมสีตามคลินิก — ตาลาย/แสบตา
 * สี CI แสดงที่ริบบิ้นบนสุด สวิตช์ เมนู และแถบมือถือแทน) */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -2;
  pointer-events: none;
  background-color: var(--paper);
  background-image:
    radial-gradient(at 15% 8%, rgba(214,211,203,.30) 0px, transparent 55%);
}
.tabular { font-variant-numeric: tabular-nums; }

/* วงกลมสีตกแต่ง — ปิดไว้ (พื้นหลังโทนกลางสบายตา) */
.bg-blob { display: none; position: fixed; border-radius: 9999px; filter: blur(90px); z-index: -1; pointer-events: none; opacity: .55; }
.bg-blob-1 { width: 420px; height: 420px; background: #bfdbfe; top: -120px; left: -120px; }
.bg-blob-2 { width: 380px; height: 380px; background: #ddd6fe; top: 30%; right: -140px; }
.bg-blob-3 { width: 360px; height: 360px; background: #bae6fd; bottom: -140px; left: 25%; }

.custom-scrollbar::-webkit-scrollbar { height: 8px; width: 8px; }
.custom-scrollbar::-webkit-scrollbar-track { background: #f1f5f9; border-radius: 8px; }
.custom-scrollbar::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 8px; }
.custom-scrollbar::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ---------- แผงเนื้อหา — พื้นขาวทึบทุกแบรนด์ (อ่านสบายตา ไม่โดนสีพื้นหลังย้อม) ---------- */
.panel {
  background: #ffffff !important;
  border: 1px solid var(--hairline) !important;
  outline: none;
  box-shadow: var(--shadow-card) !important;
}

/* ---------- การ์ด KPI ---------- */
.metric-card, .clickable-card { cursor: pointer; transition: all .3s cubic-bezier(0.4,0,0.2,1); position: relative; }
.metric-card:not(.card-hero) {
  background-color: #ffffff;
  border: 1px solid var(--hairline);
  box-shadow: var(--shadow-card);
}
.metric-card:hover { transform: translateY(-2px); }
.metric-card:not(.card-hero):hover {
  box-shadow: var(--shadow-lift);
  border-color: #d9d7d1; background-color: #fff;
}
.metric-card::before {
  content: ''; position: absolute; top: 0; left: 12%; right: 12%; height: 3px;
  background: linear-gradient(90deg, transparent, #3b82f6, transparent);
  border-radius: 3px; opacity: 0; transition: opacity .3s;
}
.metric-card:hover::before { opacity: 1; }
.card-hero:hover { box-shadow: 0 24px 44px -16px rgba(37,99,235,0.55); }
.metric-card h3, .ratio-value { font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }

.kicker { font-size: .7rem; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: #8b97ab; }
.icon-chip { width: 42px; height: 42px; border-radius: .85rem; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.ctx-chip {
  display: inline-flex; align-items: center; gap: 4px; font-size: .65rem; font-weight: 600;
  padding: 2px 8px; border-radius: 9999px; background: #f4f3f0; color: #6b6a66;
  border: 1px solid transparent; font-variant-numeric: tabular-nums;
}
.card-foot {
  display: flex; align-items: flex-end; justify-content: space-between; gap: .75rem;
  margin-top: .85rem; padding-top: .7rem; border-top: 1px solid var(--hairline-soft);
}

/* ---------- delta chips ---------- */
.delta-chip {
  display: inline-flex; align-items: center; gap: 3px; font-size: .68rem; font-weight: 700; line-height: 1;
  padding: 4px 8px; border-radius: 9999px; white-space: nowrap; font-variant-numeric: tabular-nums;
}
.delta-up   { background: #ecfdf5; color: #047857; border: 1px solid transparent; }
.delta-down { background: #fef2f2; color: #b91c1c; border: 1px solid transparent; }
.delta-flat { background: #f4f3f0; color: #64748b; border: 1px solid transparent; }
.delta-chip.delta-dark { background: rgba(255,255,255,0.16) !important; border-color: rgba(255,255,255,0.3) !important; color: #fff !important; }
.prev-val { font-size: .65rem; color: #94a3b8; }
.prev-val.on-dark { color: rgba(255,255,255,0.6); }

/* ---------- แท็บเลือกคลินิก ---------- */
.tab-btn { transition: all .2s ease; border-bottom: 4px solid transparent; opacity: .7; color: #64748b; background: #fff; }
.tab-btn:hover { opacity: 1; background-color: #f8fafc; }
.tab-btn.active { opacity: 1; transform: translateY(-2px); background: white; box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05); font-weight: 700; }
.tab-all.active { border-color: #2563eb; color: #1e40af; }
.tab-classcare.active { border-color: #eab308; color: #854d0e; }
.tab-dearclass.active { border-color: #ec4899; color: #be185d; }
.tab-menclass.active { border-color: #ef4444; color: #991b1b; }

/* ---------- โครงเลย์เอาต์: เมนูด้านซ้าย (desktop) ---------- */
#sidebar {
  position: fixed; top: 0; left: 0; bottom: 0; width: 232px; z-index: 40;
  display: flex; flex-direction: column;
  background: #ffffff;
  border-right: 1px solid var(--hairline);
  box-shadow: none;
}
#mobile-header { display: none; }
#main-area { margin-left: 232px; padding: 1.25rem 1.75rem 4rem; }
#view-root { max-width: 1480px; margin: 0 auto; }

.side-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: .6rem .8rem; border-radius: .65rem;
  font-size: .85rem; font-weight: 600; color: #64748b;
  transition: all .18s ease; text-align: left;
}
.side-item:hover { background: #f1f5f9; color: var(--ci-text); }
.side-item.active { background: var(--ci-soft); color: var(--ci-text); box-shadow: inset 0 0 0 1px var(--ci); }
body[data-ci="all"] .side-item.active { background: linear-gradient(90deg, #dbeafe, #ede9fe); box-shadow: inset 0 0 0 1px #bfdbfe; }
/* แถบมือถือ: เส้นขอบล่างสี CI (พื้นขาว ไม่ย้อม) */
#mobile-header { border-bottom: 2px solid var(--ci) !important; }

/* ---------- สวิตช์คลินิก (มุมบน — กันกรอกผิดคลินิก) ---------- */
.clinic-switch {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: .55rem .75rem; border-radius: .75rem; cursor: pointer;
  border: 1.5px solid #e2e8f0; background: #fff;
  transition: all .2s ease; text-align: left;
}
.clinic-switch:hover { border-color: #93c5fd; box-shadow: 0 4px 12px -6px rgba(37,99,235,0.25); }
/* เมื่อเลือกคลินิกเฉพาะ — สวิตช์ย้อมสี CI เต็มๆ */
body[data-ci]:not([data-ci="all"]) .clinic-switch {
  background: var(--ci-softer);
  border-color: var(--ci);
  box-shadow: 0 4px 14px -6px var(--ci);
}
body[data-ci]:not([data-ci="all"]) .clinic-switch .cs-name { color: var(--ci-text); }
body[data-ci]:not([data-ci="all"]) .clinic-switch .cs-sub { color: var(--ci-text); opacity: .65; }
.clinic-switch .cs-dot { width: 10px; height: 10px; border-radius: 9999px; flex-shrink: 0; }
.clinic-switch .cs-name { font-size: .82rem; font-weight: 700; color: #1e293b; line-height: 1.1; }
.clinic-switch .cs-sub { font-size: .58rem; font-weight: 600; color: #94a3b8; text-transform: uppercase; letter-spacing: .04em; }

/* ---------- รายงาน (หน้าจอ + พิมพ์ A4 แนวตั้ง) ---------- */
.rp-h {
  font-size: .8rem; font-weight: 700; color: #334155;
  border-left: 3px solid var(--ci); padding-left: .6rem; margin: 1.1rem 0 .6rem;
}
@media print {
  .report-print { display: block !important; width: 100%; background: #fff; color: #0f172a; font-size: 11px; padding: 0; }
  .report-print .sum-table th { background: #f1f5f9 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .report-print .rp-h { border-left-color: #334155; }
  .report-print .delta-chip { border: 1px solid #cbd5e1 !important; background: #fff !important; color: #334155 !important; }
  .report-print .status-pill { border: 1px solid #cbd5e1 !important; }
  .report-print h3 { font-size: 18px; }
  .report-print .rp-sign { page-break-inside: avoid; }
}

/* ---------- ค้นหาทั่วระบบ (Ctrl+K) ---------- */
.gs-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: .55rem .75rem; border-radius: .65rem; text-align: left;
  transition: background .12s;
}
.gs-item:hover { background: #eff6ff; }
.gs-group { font-size: .62rem; font-weight: 800; color: #94a3b8; text-transform: uppercase; letter-spacing: .05em; padding: .6rem .3rem .2rem; }

/* ---------- กรอบมือถือ (preview ลิงก์หมอ) ---------- */
.phone-frame {
  width: 340px; max-width: 100%; margin: 0 auto;
  border: 10px solid #1e293b; border-radius: 2.2rem;
  background: var(--paper); overflow: hidden;
  box-shadow: 0 24px 48px -18px rgba(15,23,42,0.4);
}
.phone-notch { height: 22px; background: #1e293b; border-radius: 0 0 14px 14px; width: 45%; margin: 0 auto; }
.phone-screen { height: 480px; overflow-y: auto; padding: 12px; }

/* ---------- dropdown สถานะในตาราง (สีตามสถานะ: ลงคิว=เขียว รอแจ้ง=เหลือง ยกเลิก=แดง) ---------- */
.row-status { font-weight: 700; cursor: pointer; transition: none; }
.row-status.st-booking   { background: #eff6ff; color: #1d4ed8; border-color: #93c5fd; }
.row-status.st-queued    { background: #f0fdf4; color: #15803d; border-color: #4ade80; }
.row-status.st-done      { background: #f0fdfa; color: #0f766e; border-color: #2dd4bf; }
.row-status.st-upsell    { background: #ecfeff; color: #0e7490; border-color: #67e8f9; }
.row-status.st-pending   { background: #fefce8; color: #a16207; border-color: #facc15; }
.row-status.st-cancelled { background: #fef2f2; color: #b91c1c; border-color: #f87171; }
.row-status.st-declined  { background: #fff1f2; color: #9f1239; border-color: #fda4af; }
.row-status.st-expired   { background: #f5f5f4; color: #57534e; border-color: #d6d3d1; }

/* ---------- แท็กเคส ---------- */
.tag-chip {
  font-size: .72rem; font-weight: 600; padding: .3rem .65rem; border-radius: 9999px;
  border: 1px solid var(--hairline); background: #fff; color: #64748b; transition: all .15s;
}
.tag-chip:hover:not([disabled]) { border-color: #a5b4fc; color: #4338ca; }
.tag-chip.on { background: #eef2ff; border-color: #818cf8; color: #3730a3; }
.tag-mini {
  display: inline-block; font-size: 9.5px; font-weight: 700; line-height: 1.4; padding: 0 5px; margin: 1px 2px 0 0;
  border-radius: 4px; background: #eef2ff; color: #4338ca; white-space: nowrap;
}
.hn-badge { font-weight: 700; color: #047857; background: #ecfdf5; border-radius: 4px; padding: 1px 6px; font-size: .72rem; white-space: nowrap; }

/* ---------- แถบ bulk selection ---------- */
.bulk-bar {
  display: flex; align-items: center; gap: .5rem; flex-wrap: wrap;
  background: #eff6ff; border: 1px solid #bfdbfe; border-radius: .75rem;
  padding: .5rem .8rem; margin-bottom: .75rem;
  animation: fadeIn .25s ease both;
}
.bulk-check { width: 15px; height: 15px; accent-color: #2563eb; cursor: pointer; }

/* ---------- slot คิวต่อวัน ---------- */
.slot-chip {
  display: inline-flex; align-items: center; gap: 3px; font-size: .62rem; font-weight: 700;
  padding: 2px 8px; border-radius: 9999px; font-variant-numeric: tabular-nums;
  background: #f0fdf4; color: #15803d; border: 1px solid transparent;
}
.slot-chip.slot-full { background: #fef2f2; color: #b91c1c; }
.slot-chip.slot-near { background: #fffbeb; color: #b45309; }

/* ---------- กระดานวาด OPD ---------- */
.opd-canvas-box { border: 1.5px dashed #cbd5e1; border-radius: .75rem; overflow: hidden; background: #fff; touch-action: none; }
.opd-canvas-box canvas { display: block; width: 100%; cursor: crosshair; touch-action: none; }

/* ---------- ป้ายโปรโมชั่น ---------- */
.promo-badge {
  display: inline-flex; align-items: center; gap: 3px;
  font-size: .58rem; font-weight: 800; padding: 1px 7px; border-radius: 9999px;
  background: linear-gradient(90deg, #f43f5e, #f97316); color: #fff;
}
.price-strike { text-decoration: line-through; color: #94a3b8; font-weight: 500; font-size: .72rem; }

/* ---------- period chips (เดือน/ปี กดง่ายๆ) ---------- */
.pd-chip {
  padding: .4rem .8rem; border-radius: 9999px; font-size: .72rem; font-weight: 700;
  color: #64748b; background: #fff; border: 1px solid var(--hairline); transition: all .18s; white-space: nowrap;
}
.pd-chip:hover { border-color: #93c5fd; color: #2563eb; }
.pd-chip.active { background: #2563eb; color: #fff; border-color: #2563eb; box-shadow: 0 2px 6px -2px rgba(37,99,235,.4); }

/* ---------- Dropdown วัน/เดือน/ปี ---------- */
.datedd { display: flex; gap: 4px; }
.datedd .f-select { min-width: 0; padding-left: .45rem; padding-right: 1.4rem; }
.datedd .dd-d { flex: 0 0 27%; }
.datedd .dd-m { flex: 1 1 42%; }
.datedd .dd-y { flex: 0 0 31%; }

/* ---------- ปฏิทินคิวผ่าตัด ---------- */
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.cal-head { font-size: .68rem; font-weight: 700; color: #94a3b8; text-align: center; padding: .3rem 0; text-transform: uppercase; }
.cal-cell {
  min-height: 86px; border: 1px solid var(--hairline-soft); border-radius: .55rem; padding: 4px;
  background: #fff; cursor: pointer; transition: border-color .15s, background .15s; overflow: hidden;
}
.cal-cell:hover { border-color: #93c5fd; }
.cal-cell.other { background: #faf9f7; opacity: .45; }
.cal-cell.today { box-shadow: inset 0 0 0 2px #2563eb; }
.cal-cell.selected { background: #eff6ff; border-color: #2563eb; }
.cal-daynum { font-size: .68rem; font-weight: 700; color: #64748b; }
.cal-chip {
  display: block; font-size: 9px; font-weight: 600; border-radius: 4px; padding: 1px 4px;
  color: #fff; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cal-count { display: none; font-size: 9px; font-weight: 700; background: #dbeafe; color: #1d4ed8; border-radius: 9999px; padding: 0 5px; margin-top: 2px; }
@media (max-width: 767px) {
  .cal-cell { min-height: 48px; padding: 3px; }
  .cal-chip { display: none; }
  .cal-count { display: inline-block; }
}

/* ---------- แท็บเมนูหลัก (view switcher) ---------- */
.nav-tab {
  display: inline-flex; align-items: center; gap: 6px; padding: .45rem .85rem; border-radius: .6rem;
  font-size: .8rem; font-weight: 600; color: #64748b; transition: all .2s ease; white-space: nowrap;
}
.nav-tab:hover { color: #2563eb; background: #eff6ff; }
.nav-tab.active { color: #1d4ed8; background: #dbeafe; box-shadow: inset 0 0 0 1px #bfdbfe; }

/* ---------- bottom nav (มือถือ) ---------- */
#bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 45;
  background: rgba(255,255,255,0.92); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--hairline); display: none;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
/* ปุ่มเมนูเดียวบนแถบล่าง — กดแล้วเด้ง popup */
.bnav-menu-btn {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: .85rem 0; font-size: .9rem; font-weight: 700; color: var(--ci-text);
  transition: background .15s;
}
.bnav-menu-btn:active { background: var(--ci-softer); }

/* bottom sheet เมนูมือถือ */
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  background: #fff; border-radius: 1.25rem 1.25rem 0 0;
  padding: .6rem .9rem calc(1rem + env(safe-area-inset-bottom, 0));
  box-shadow: 0 -12px 40px -12px rgba(15,23,42,0.3);
  animation: sheetUp .26s cubic-bezier(0.21,1.02,0.73,1);
}
@keyframes sheetUp { from { transform: translateY(100%); } to { transform: none; } }
.sheet-handle { width: 42px; height: 4px; border-radius: 9999px; background: #e2e8f0; margin: 0 auto .8rem; }
.sheet-item {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  padding: .9rem .25rem; border-radius: .9rem; border: 1px solid #eef2f7;
  font-size: .72rem; font-weight: 700; color: #475569; background: #fff; transition: all .15s;
}
.sheet-item:active { transform: scale(.96); }
.sheet-item.active { background: var(--ci-soft); color: var(--ci-text); border-color: var(--ci); }

/* ---------- ratio ring ---------- */
.ratio-tile {
  display: flex; align-items: center; gap: .85rem; background: #ffffff;
  border: 1px solid var(--hairline); border-radius: 1rem; padding: .9rem 1.1rem;
  box-shadow: var(--shadow-card); transition: all .3s ease;
}
.ratio-tile:hover { transform: translateY(-2px); box-shadow: var(--shadow-lift); }
.ratio-ring { position: relative; width: 52px; height: 52px; flex-shrink: 0; }
.ratio-ring svg { transform: rotate(-90deg); }
.ratio-ring circle { fill: none; stroke-width: 5.5; stroke-linecap: round; }
.ratio-ring .ring-bg { stroke: #eef2f7; }
.ratio-ring .ring-val { transition: stroke-dashoffset .9s cubic-bezier(0.25,1,0.5,1); }
.ring-label { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: .68rem; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------- section หัวข้อพับได้ ---------- */
.section-head {
  width: 100%; display: flex; justify-content: space-between; align-items: center;
  padding: 1rem 1.5rem; background: rgba(255,255,255,0.6); border-bottom: 1px solid var(--hairline-soft);
  transition: background .2s; text-align: left; cursor: pointer;
}
.section-head:hover { background: rgba(250,249,247,0.9); }
.section-content { transition: max-height .3s ease-in-out, opacity .3s ease-in-out; max-height: 9000px; opacity: 1; overflow: hidden; }
.section-content.collapsed { max-height: 0; opacity: 0; padding-top: 0 !important; padding-bottom: 0 !important; }
.chevron-icon { transition: transform .3s ease; }
.chevron-icon.rotated { transform: rotate(-180deg); }

/* ---------- ตาราง ---------- */
.sum-table th {
  font-size: .68rem; font-weight: 600; color: #7d7b76; text-transform: uppercase; letter-spacing: .05em;
  padding: .7rem .9rem; background: #faf9f7; border-bottom: 1px solid var(--hairline); white-space: nowrap; text-align: left;
}
.sum-table td { padding: .55rem .9rem; font-size: .8rem; white-space: nowrap; font-variant-numeric: tabular-nums; border-bottom: 1px solid var(--hairline-soft); }
.sum-table tbody tr:hover td { background: #faf9f7; }
.sum-table tr.is-current td { background: #eff6ff; }
.sum-table tr.row-dim td { opacity: .4; }
.sum-table tr.row-total td { background: #faf9f7; border-top: 2px solid var(--hairline); font-weight: 700; }
.status-pill { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: .4rem; font-size: .68rem; font-weight: 600; border-width: 1px; white-space: nowrap; }

/* ---------- อันดับ (stat list) ---------- */
.stat-list-item { display: flex; justify-content: space-between; align-items: center; padding: .75rem 0; border-bottom: 1px solid var(--hairline-soft); font-size: .95rem; position: relative; }
.stat-list-item .rank-bar { position: absolute; bottom: 0; left: 0; height: 2px; background: #dbeafe; border-radius: 2px; }

/* ---------- progress bar เป้าหมาย ---------- */
.progress-track { width: 100%; background: #f1f5f9; border-radius: 9999px; height: 10px; overflow: hidden; }
.progress-fill { height: 100%; border-radius: 9999px; position: relative; transition: width 1s ease-out; overflow: hidden; }
.progress-fill::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.45), transparent);
  animation: shine 2.4s infinite;
}
@keyframes shine { 0% { transform: translateX(-100%); } 60%, 100% { transform: translateX(100%); } }

/* ---------- funnel + heatmap ---------- */
.funnel-track { width: 100%; background: #eef2f7; border-radius: .6rem; height: 30px; overflow: hidden; }
.funnel-fill { height: 30px; border-radius: .6rem; transition: width .8s cubic-bezier(0.25,1,0.5,1); min-width: 6px; }
.hm-grid { display: grid; gap: 3px; font-variant-numeric: tabular-nums; }
.hm-cell { height: 38px; border-radius: .45rem; display: flex; align-items: center; justify-content: center; font-size: 10px; font-weight: 600; transition: transform .15s, box-shadow .15s; }
.hm-cell:hover { transform: scale(1.1); z-index: 5; box-shadow: 0 8px 18px -6px rgba(15,23,42,0.35); }

/* ---------- modal ---------- */
.cc-modal { position: fixed; inset: 0; z-index: 50; }
.cc-modal.hidden { display: none; }
.cc-modal-backdrop { position: fixed; inset: 0; background: rgba(15,23,42,0.7); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); }
.cc-modal-wrap { position: fixed; inset: 0; z-index: 10; overflow-y: auto; }
.cc-modal-center { display: flex; min-height: 100%; align-items: center; justify-content: center; padding: 1rem; }
.cc-modal-box { position: relative; transform: none; overflow: hidden; border-radius: 1rem; background: #fff; box-shadow: 0 25px 50px -12px rgba(0,0,0,0.25); width: 100%; display: flex; flex-direction: column; max-height: 92vh; animation: modalIn .25s cubic-bezier(0.21,1.02,0.73,1); }
@keyframes modalIn { from { opacity: 0; transform: translateY(14px) scale(.98); } to { opacity: 1; transform: none; } }

/* ---------- toasts ---------- */
#toast-container { position: fixed; top: 4.5rem; right: 1rem; z-index: 100; display: flex; flex-direction: column; gap: .5rem; align-items: flex-end; }
.toast {
  display: flex; align-items: center; gap: .5rem; padding: .65rem 1rem; border-radius: .75rem;
  font-size: .85rem; font-weight: 600; color: #fff; box-shadow: 0 10px 25px -5px rgba(0,0,0,0.15);
  animation: toastIn .35s cubic-bezier(0.21,1.02,0.73,1) forwards; backdrop-filter: blur(8px);
}
.toast.leaving { animation: toastOut .3s ease forwards; }
@keyframes toastIn { from { opacity: 0; transform: translateX(30px) scale(.95); } to { opacity: 1; transform: none; } }
@keyframes toastOut { from { opacity: 1; } to { opacity: 0; transform: translateX(30px); } }

/* ---------- ฟอร์ม ---------- */
.f-label { display: block; font-size: .72rem; font-weight: 700; color: #64748b; margin-bottom: .25rem; }
.f-input, .f-select, .f-textarea {
  width: 100%; border: 1px solid #e2e8f0; border-radius: .55rem; font-size: .85rem;
  padding: .5rem .75rem; background: #fff; color: #1e293b; transition: border-color .2s, box-shadow .2s;
}
.f-input:hover, .f-select:hover, .f-textarea:hover { border-color: #93c5fd; }
.f-input:focus, .f-select:focus, .f-textarea:focus { outline: none; border-color: #2563eb; box-shadow: 0 0 0 3px rgba(37,99,235,0.12); }
.f-input[readonly] { background: #f8fafc; color: #64748b; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font-weight: 600; font-size: .82rem; border-radius: .6rem; padding: .5rem 1rem; transition: all .2s ease; cursor: pointer; white-space: nowrap; }
.btn:active { transform: scale(.97); }
.btn-primary { background: #2563eb; color: #fff; box-shadow: 0 2px 6px -2px rgba(37,99,235,0.35); }
.btn-primary:hover { background: #1d4ed8; }
.btn-ghost { background: #fff; color: #475569; border: 1px solid #e2e8f0; }
.btn-ghost:hover { background: #f8fafc; border-color: #cbd5e1; }
.btn-danger { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }
.btn-danger:hover { background: #fee2e2; }
.btn-success { background: #059669; color: #fff; box-shadow: 0 2px 6px -2px rgba(5,150,105,0.35); }
.btn-success:hover { background: #047857; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* ---------- badge / เบ็ดเตล็ด ---------- */
.ver-badge { font-size: 10px; font-weight: 700; color: #047857; background: #ecfdf5; border: 1px solid #a7f3d0; padding: 2px 8px; border-radius: 9999px; display: inline-flex; align-items: center; gap: 4px; }
.ver-dot { width: 6px; height: 6px; border-radius: 9999px; background: #10b981; animation: pulseDot 2s infinite; }
@keyframes pulseDot { 0% { box-shadow: 0 0 0 0 rgba(16,185,129,0.5); } 70% { box-shadow: 0 0 0 5px rgba(16,185,129,0); } 100% { box-shadow: 0 0 0 0 rgba(16,185,129,0); } }
.meta-pill { font-size: 10px; color: #94a3b8; background: #f8fafc; border: 1px solid #e2e8f0; padding: 2px 8px; border-radius: 9999px; }

.fade-in { animation: fadeIn .4s ease both; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.stagger > *:nth-child(1) { animation-delay: .05s; } .stagger > *:nth-child(2) { animation-delay: .1s; }
.stagger > *:nth-child(3) { animation-delay: .15s; } .stagger > *:nth-child(4) { animation-delay: .2s; }
.stagger > *:nth-child(5) { animation-delay: .25s; } .stagger > *:nth-child(6) { animation-delay: .3s; }

.skeleton { background: linear-gradient(90deg, #f1f5f9 25%, #e2e8f0 37%, #f1f5f9 63%); background-size: 400% 100%; animation: shimmer 1.4s ease infinite; border-radius: .5rem; }
@keyframes shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

/* ---------- หน้า login ---------- */
.login-card { width: 100%; max-width: 380px; animation: modalIn .35s cubic-bezier(0.21,1.02,0.73,1); }
.login-plain .panel { box-shadow: 0 10px 40px -12px rgba(15, 23, 42, .12); }
.login-hero-icon {
  width: 4.25rem; height: 4.25rem; border-radius: 1.25rem;
  display: flex; align-items: center; justify-content: center;
  color: #fff; background: linear-gradient(145deg, #0ea5e9, #0369a1);
  box-shadow: 0 12px 28px -10px rgba(3, 105, 161, .45);
}
.login-clinic-dot {
  width: 1.75rem; height: 1.75rem; border-radius: 999px;
  display: inline-flex; align-items: center; justify-content: center;
  color: #fff; box-shadow: 0 0 0 2px #fff, 0 2px 8px rgba(15, 23, 42, .12);
}
.login-field { position: relative; }
.login-field-icon {
  position: absolute; left: .75rem; top: 50%; transform: translateY(-50%);
  width: 1rem; height: 1rem; color: #94a3b8; pointer-events: none;
}
.login-status {
  display: flex; align-items: center; justify-content: center; gap: .4rem;
  font-size: 11px; color: #64748b; min-height: 1.25rem;
}
.login-status-dot {
  width: .55rem; height: .55rem; border-radius: 999px; background: #cbd5e1; flex-shrink: 0;
}
.login-status-dot.is-ok { background: #10b981; box-shadow: 0 0 0 3px rgba(16, 185, 129, .18); }
.login-status-dot.is-bad { background: #ef4444; box-shadow: 0 0 0 3px rgba(239, 68, 68, .15); }
.login-status-dot.is-demo { background: #f59e0b; box-shadow: 0 0 0 3px rgba(245, 158, 11, .18); }
.login-status-dot.is-loading { background: #94a3b8; animation: loginPulse 1s ease infinite; }
@keyframes loginPulse { 0%, 100% { opacity: .35; } 50% { opacity: 1; } }
.login-status-refresh {
  display: inline-flex; padding: .2rem; border-radius: .4rem; color: #94a3b8;
}
.login-status-refresh:hover { background: #f1f5f9; color: #475569; }
.login-role-btn {
  width: 2.25rem; height: 2.25rem; border-radius: .75rem; border: 1px solid #e2e8f0;
  display: inline-flex; align-items: center; justify-content: center; color: #64748b; background: #fff;
}
.login-role-btn:hover { border-color: #bae6fd; color: #0369a1; background: #f0f9ff; }

/* =========================================================================
 * ใบเสร็จ (พิมพ์ A4 แนวนอน: ORIGINAL | COPY — โคลนจาก Togtag Receipt)
 * ========================================================================= */
#print-area { display: none; }
.receipt-page-style {
  width: 297mm; height: 210mm; background: #fff; color: #000;
  display: flex; flex-direction: row; padding: 40px 50px; box-sizing: border-box; justify-content: center;
  font-family: 'Anuphan', sans-serif;
}
.receipt-half-style { width: 50%; padding: 10px 40px; display: flex; flex-direction: column; box-sizing: border-box; }
.receipt-separator { border-right: 1px dashed #ccc; }
.rc-title { text-align: center; font-size: 16px; font-weight: 700; margin-bottom: 6px; }
.rc-company { text-align: right; font-size: 12px; line-height: 1.4; margin-bottom: 20px; }
.rc-company .rc-cname { font-size: 14px; font-weight: 700; }
.rc-doctype { font-size: 14px; font-weight: 700; text-transform: uppercase; }
.rc-rule-2 { border-bottom: 2px solid #000; margin: 4px 0 8px; }
.rc-rule-1 { border-bottom: 1px solid #000; margin: 6px 0 8px; }
.rc-info { font-size: 12px; margin: 2px 0; display: flex; }
.rc-info b { min-width: 90px; font-weight: 600; }
.rc-items { width: 100%; border-collapse: collapse; font-size: 12px; margin-top: 10px; }
.rc-items th { text-align: left; font-weight: 700; border-bottom: 1px solid #000; padding: 4px 2px; }
.rc-items td { padding: 4px 2px; vertical-align: top; }
.rc-items .num { text-align: right; }
.rc-total-section { margin-top: auto; font-size: 12px; }
.rc-total-row { display: flex; justify-content: flex-end; padding: 2px 0; }
.rc-total-row .lbl { width: 60%; text-align: right; padding-right: 12px; }
.rc-total-row .val { width: 20%; text-align: right; font-variant-numeric: tabular-nums; }
.rc-total-row.paid { font-weight: 700; border-top: 1px solid #000; border-bottom: 3px double #000; padding: 5px 0; }
.rc-declare { font-size: 11px; margin-top: 30px; }
.rc-sign { display: flex; justify-content: space-between; margin-top: 30px; font-size: 11px; }
.rc-sig-block { width: 45%; }
.rc-sig-line { border-bottom: 1px dotted #999; height: 16px; margin: 4px 0 10px; }

@media print {
  @page { size: A4 landscape; margin: 0; }
  html { font-size: 100%; }
  body { background: #fff !important; background-image: none !important; }
  .screen-only { display: none !important; }
  #bottom-nav, #toast-container, .bg-blob { display: none !important; }
  #print-area { display: block !important; width: 100%; }
  .receipt-page { width: 100%; height: 100vh; page-break-after: always; display: flex; flex-direction: row; padding: 40px 50px; box-sizing: border-box; justify-content: center; background: #fff; }
  .receipt-half-style { width: 50%; padding: 10px 40px; }
}

/* ---------- responsive ---------- */
@media (max-width: 767px) {
  html { font-size: 100%; }
  .bg-blob { display: none; }
  .metric-card h3 { font-size: 1.6rem !important; }
  .card-hero h3 { font-size: 1.85rem !important; }
  #bottom-nav { display: flex; }
  #sidebar { display: none; }
  #mobile-header {
    display: flex; align-items: center; justify-content: space-between;
    position: sticky; top: 0; z-index: 40; padding: .55rem .9rem;
    background: rgba(255,255,255,0.92); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
    border-bottom: 1px solid #e2e8f0;
  }
  #main-area { margin-left: 0; padding: .9rem .75rem 5.5rem; }
  .section-head { padding: .8rem 1rem; }
  #toast-container { top: auto; bottom: 5.5rem; right: .75rem; left: .75rem; align-items: stretch; }
  .bnav-item { font-size: .55rem; }
}
