/* Zira Spa – เว็บแอปพนักงาน (Step 3: โครงหน้าจอ) */
:root {
  --bg: #EEF2F1; --surface: #FFFFFF; --ink: #1E2B2F; --muted: #5F6E72; --line: #D5DDDC; --line-hour: #B9C6C4;
  --jade: #1F6F66; --jade-soft: #DCEEEA; --jade-ink: #14524B;
  --unpaid: #C7372F; --unpaid-soft: #FBE7E5; --partial: #B7791F; --partial-soft: #FBF0DC; --paid: #2E7D4F; --paid-soft: #E1F2E7;
  --now: #D2362B; --closed: #E7EBEA; --dirty: #B7791F; --dirty-soft: #FFF4DF;
  --slot-h: 48px; --head1: 46px; --head2: 22px; --head-h: calc(var(--head1) + var(--head2)); --time-w: 64px; --col-w: 150px; --col-max: 180px; --side-w: 25%;
  --radius: 6px;
  font-family: "IBM Plex Sans Thai", "Noto Sans Thai", "Leelawadee UI", Tahoma, sans-serif;
  color: var(--ink); background: var(--bg);
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { display: flex; flex-direction: column; font-size: 14px; line-height: 1.45; }
button, select, input { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--jade); outline-offset: 2px; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- แถบบน ---------- */
.top { display: flex; align-items: center; gap: 12px; padding: 8px 14px; background: var(--surface); border-bottom: 1px solid var(--line); flex-wrap: nowrap; min-width: 0; }
.brand { display: flex; flex-direction: column; line-height: 1.15; margin-right: 4px; white-space: nowrap; }
.brand b { font-weight: 700; font-size: 17px; color: var(--jade-ink); }
.brand span { font-size: 13px; color: var(--muted); }
.today-btn, .primary, .icon-btn { white-space: nowrap; }
.field { display: flex; align-items: center; gap: 6px; }
.field select, .field input { border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius); padding: 6px 10px; min-height: 36px; }
.icon-btn { border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius); min-width: 36px; min-height: 36px; cursor: pointer; }
.today-btn { border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius); padding: 6px 12px; min-height: 36px; cursor: pointer; }
.stats { display: flex; gap: 6px; margin-left: auto; flex-wrap: nowrap; min-width: 0; overflow: hidden; }
.stat { display: flex; align-items: baseline; gap: 5px; padding: 5px 10px; border-radius: 999px; background: var(--bg); white-space: nowrap; }
.stat b { font-size: 16px; font-variant-numeric: tabular-nums; }
.stat small { color: var(--muted); font-size: 13px; }
.stat.warn { background: var(--dirty-soft); }
.primary { background: var(--jade); color: #fff; border: 0; border-radius: var(--radius); padding: 8px 16px; min-height: 38px; font-weight: 600; cursor: pointer; }
.primary:hover { background: var(--jade-ink); }
.user { display: flex; align-items: center; gap: 8px; color: var(--muted); white-space: nowrap; }
.user .who-am-i { display: flex; flex-direction: column; line-height: 1.2; font-size: 13px; }
.user .who-am-i b { color: var(--ink); font-weight: 600; }
.user .logout { border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius); padding: 4px 8px; font-size: 12px; cursor: pointer; }
.sync { font-size: 12px; color: var(--muted); }
.sync.saving::before { content: "● "; color: var(--partial); }
.sync.ok::before { content: "● "; color: var(--paid); }

/* ---------- พื้นที่หลัก 75 / 25 ---------- */
.main { flex: 1; display: flex; min-height: 0; }
.board { flex: 1 1 75%; min-width: 0; overflow: auto; position: relative; background: var(--surface); }
.side { flex: 0 0 var(--side-w); max-width: 380px; min-width: 260px; border-left: 1px solid var(--line); background: var(--bg); overflow: auto; padding: 12px; }

/* ---------- ตารางห้อง: แกน X = ห้อง/เตียง, แกน Y = เวลา (30 นาที) ---------- */
.sched { display: grid; position: relative; width: max-content;
  grid-template-columns: var(--time-w) repeat(var(--cols), minmax(var(--col-w), var(--col-max)));   /* 1 ช่อง = 1 เตียง · ไม่ยืดเต็มจอ */
  grid-template-rows: var(--head1) var(--head2) repeat(var(--slots), var(--slot-h)); }
.corner { grid-column: 1; grid-row: 1 / span 2; position: sticky; top: 0; left: 0; z-index: 6; background: var(--surface); border-bottom: 1px solid var(--line-hour); border-right: 1px solid var(--line); }
.room-head { position: sticky; top: 0; z-index: 5; background: var(--surface); border-bottom: 1px solid var(--line); border-left: 2px solid var(--line-hour);
  padding: 6px 10px; display: flex; flex-direction: column; justify-content: center; gap: 2px; }
.room-head .name { font-weight: 700; font-size: 15px; display: flex; align-items: baseline; gap: 6px; }
.room-head .bed { font-weight: 500; color: var(--muted); font-size: 13px; }
.room-head .state { font-size: 12px; color: var(--paid); }
.room-head .state::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: currentColor; margin-right: 5px; vertical-align: 1px; }
.room-head.dirty { background: var(--dirty-soft); }
.room-head.dirty .state { color: var(--dirty); font-weight: 600; }
.room-head.dirty.late .state { color: var(--unpaid); }
.room-head.solo { border-bottom-color: var(--line-hour); }
.bed-head { grid-row: 2; position: sticky; top: var(--head1); z-index: 5; background: var(--surface); border-bottom: 1px solid var(--line-hour);
  border-left: 1px dashed var(--line-hour); font-size: 12px; color: var(--muted); text-align: center; line-height: var(--head2); }
.bed-head.first { border-left: 2px solid var(--line-hour); }
.room-head.dirty + .bed-head, .bed-head.dirty { background: var(--dirty-soft); }
.time { grid-column: 1; position: sticky; left: 0; z-index: 3; background: var(--surface); border-right: 1px solid var(--line);
  font-size: 12px; color: var(--muted); text-align: right; padding: 0 8px; transform: translateY(-0.7em); }
.time.hour { color: var(--ink); font-weight: 600; font-size: 13px; }
.lane { grid-row: 3 / -1; border-left: 2px solid var(--line-hour); position: relative;
  background-image: repeating-linear-gradient(to bottom, transparent 0, transparent calc(var(--slot-h) * 2 - 1px), var(--line-hour) calc(var(--slot-h) * 2 - 1px), var(--line-hour) calc(var(--slot-h) * 2)),
                    repeating-linear-gradient(to bottom, transparent 0, transparent calc(var(--slot-h) - 1px), var(--line) calc(var(--slot-h) - 1px), var(--line) var(--slot-h)); }
.lane.bed { border-left: 1px dashed var(--line-hour); }
.lane.drop { background-color: var(--jade-soft); }
.lane.dirty-now { background-color: #FFFBF3; }

/* ช่วงเวลาที่ผ่านไปแล้ว (09:00 → ตอนนี้) = เทาอ่อน · วันในอดีต --past-min = ทั้งวัน · วันในอนาคต = 0 */
.past { grid-column: 2 / -1; grid-row: 3 / -1; align-self: start; height: calc(var(--past-min) / 30 * var(--slot-h));
  background: rgba(95, 110, 114, .10); z-index: 1; pointer-events: none; }

/* ---------- บล็อกการจอง ---------- */
.bk { margin: 2px 4px; z-index: 2; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line-hour); border-left: 6px solid var(--unpaid);
  padding: 4px 8px; overflow: hidden; display: flex; flex-direction: column; gap: 1px; cursor: pointer; text-align: left; font-size: 13px; }
.bk:hover { border-color: var(--ink); border-left-color: inherit; }
.bk.pay-unpaid { border-left-color: var(--unpaid); }
.bk.pay-partial { border-left-color: var(--partial); }
.bk.pay-paid { border-left-color: var(--paid); }
.bk.st-in_service { background: var(--jade-soft); }
.bk.st-closed { background: var(--closed); color: var(--muted); }
.bk .when { display: flex; justify-content: space-between; gap: 6px; font-weight: 600; font-variant-numeric: tabular-nums; }
.bk .when small { font-weight: 500; color: var(--muted); }
.bk .who { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bk .who .th { font-weight: 500; color: var(--jade-ink); }
.bk .pkg { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bk .money { display: grid; grid-template-columns: repeat(3, auto); justify-content: space-between; gap: 6px; font-variant-numeric: tabular-nums; margin-top: 2px; }
.bk .money > div { display: flex; flex-direction: column; line-height: 1.15; white-space: nowrap; }
.bk .money span { color: var(--muted); font-size: 10.5px; }
.bk .money b { color: var(--ink); font-weight: 600; font-size: 12.5px; }
.bk .money .due b { color: var(--unpaid); }
.bk.pay-paid .money .due b { color: var(--muted); }
/* บล็อก 60 นาที: เหลือเฉพาะยอดค้าง (สีขอบซ้ายบอกสถานะชำระอยู่แล้ว) */
.bk.mid .money { grid-template-columns: auto; justify-content: start; }
.bk.mid .money > div:not(.due) { display: none; }
.bk.mid .money .due { flex-direction: row; gap: 5px; align-items: baseline; }
.bk.mid .money .due span { font-size: 12px; }
.bk .tags { display: flex; gap: 4px; flex-wrap: wrap; margin-top: auto; padding-top: 3px; }
.badge { font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 999px; white-space: nowrap; }
.badge.unpaid { background: var(--unpaid-soft); color: var(--unpaid); }
.badge.partial { background: var(--partial-soft); color: #8A5A10; }
.badge.paid { background: var(--paid-soft); color: var(--paid); }
.badge.health { background: #FFE9E6; color: #A1281F; }
.badge.form { background: var(--bg); color: var(--muted); }
.badge.live { background: var(--jade); color: #fff; }
/* บล็อกสั้น (30 นาที): เหลือเวลา + ชื่อ */
.bk.short .pkg, .bk.short .money, .bk.short .tags { display: none; }
.bk.short { padding: 2px 8px; font-size: 12px; gap: 0; }
.bk.short .when small { display: none; }
/* เกินเวลาแต่ยังไม่ปิดคิว */
.bk.overtime { border-color: var(--now); box-shadow: 0 0 0 2px var(--now) inset; animation: ot 1.1s steps(2, jump-none) infinite; }
@keyframes ot { 50% { box-shadow: 0 0 0 2px transparent inset; background: #FFE9E6; } }
.bk.saving { opacity: .65; }

/* ---------- เส้นเวลาปัจจุบัน (แนวนอน) ---------- */
.now-line { position: absolute; left: var(--time-w); right: 0; height: 0; border-top: 2px solid var(--now); z-index: 4; pointer-events: none;
  top: calc(var(--head-h) + var(--now-min) / 30 * var(--slot-h)); }
.now-line::before { content: attr(data-time); position: absolute; left: calc(var(--time-w) * -1); top: -11px; width: calc(var(--time-w) - 6px);
  text-align: right; font-size: 12px; font-weight: 700; color: #fff; background: var(--now); border-radius: 4px; padding: 1px 4px; }

/* ---------- แถบหมอนวด ---------- */
.side h2 { font-size: 15px; margin: 6px 0 8px; display: flex; justify-content: space-between; align-items: baseline; }
.side h2 small { color: var(--muted); font-weight: 500; font-size: 13px; }
.side section + section { margin-top: 18px; }
.side .hint { color: var(--muted); font-size: 12px; margin: -4px 0 8px; }
.tp { display: flex; align-items: center; gap: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 7px 10px; margin-bottom: 6px; }
.tp[draggable="true"] { cursor: grab; }
.tp[draggable="true"]:active { cursor: grabbing; }
.tp .order { width: 24px; height: 24px; border-radius: 50%; background: var(--jade); color: #fff; font-size: 12px; font-weight: 700; display: grid; place-items: center; flex: none; }
.tp .info { flex: 1; min-width: 0; }
.tp .nm { font-weight: 600; }
.tp .sub { font-size: 12px; color: var(--muted); }
.tp .count { display: flex; gap: 10px; font-size: 12px; margin-top: 2px; font-variant-numeric: tabular-nums; }
.tp .count b { font-size: 13px; color: var(--ink); }
.tp .count span { color: var(--muted); }
.tp .act { border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius); padding: 4px 10px; font-size: 12px; cursor: pointer; white-space: nowrap; }
.tp.busy { background: var(--jade-soft); border-color: transparent; }
.tp.out, .tp.leave { background: transparent; border-style: dashed; }
.tp.out .nm, .tp.leave .nm { color: var(--muted); font-weight: 500; }
.side-toggle { display: none; }

/* ---------- คำอธิบายสัญลักษณ์ ---------- */
.legend { display: flex; gap: 14px; flex-wrap: wrap; padding: 6px 16px; font-size: 12px; color: var(--muted); background: var(--surface); border-top: 1px solid var(--line); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }

/* ---------- แท็บเล็ตแนวนอน / จอเล็ก: แถบหมอนวดเป็นแผงเลื่อนเข้า ---------- */
@media (max-width: 1100px) {
  :root { --col-w: 140px; --col-max: 160px; }
  .side { position: fixed; right: 0; top: 0; bottom: 0; width: 320px; max-width: 85vw; z-index: 20; transform: translateX(100%); transition: transform .2s; box-shadow: -8px 0 24px rgba(30, 43, 47, .18); }
  .side.open { transform: none; }
  .side-toggle { display: inline-block; }
  .stats .stat.opt { display: none; }
  .user .who-am-i .sync { display: none; }
  .brand { display: none; }
  .top { gap: 8px; padding: 8px 10px; }
}
@media (prefers-reduced-motion: reduce) {
  .bk.overtime { animation: none; box-shadow: 0 0 0 3px var(--now) inset; }
  .side { transition: none; }
}
.bk.mid .pkg { display: none; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- v3.1: ปุ่มจองใหม่สีแดง · สลับภาษา · คิวปรับลำดับได้ ---------- */
.primary.new { background: #C62828; }
.primary.new:hover { background: #A31F1F; }
.lang-switch { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.lang-switch button { border: 0; background: var(--surface); padding: 4px 9px; font-size: 12px; cursor: pointer; color: var(--muted); }
.lang-switch button[aria-pressed="true"] { background: var(--jade); color: #fff; font-weight: 600; }
.tp.q { padding-left: 4px; }
.tp .handle { color: var(--line-hour); font-size: 16px; cursor: grab; padding: 0 2px; user-select: none; }
.tp .move { display: flex; flex-direction: column; gap: 2px; }
.tp .move button { border: 1px solid var(--line); background: var(--surface); border-radius: 4px; width: 28px; height: 20px; font-size: 10px; line-height: 1; cursor: pointer; padding: 0; color: var(--muted); }
.tp .move button:hover:not(:disabled) { border-color: var(--jade); color: var(--jade); }
.tp .move button:disabled { opacity: .35; cursor: default; }
.tp .count em { font-style: normal; color: var(--muted); }
.tp.q.dragging { opacity: .45; }
.tp.q.drop-before { box-shadow: 0 -3px 0 var(--jade); }
.tp.q.moved { background: var(--jade-soft); transition: background .6s; }
@media (prefers-reduced-motion: reduce) { .tp.q.moved { transition: none; } }

/* ---------- v3.2: แท็บหน้า · ไปช่วยสาขาอื่น · เรียกจากสาขาอื่น · หน้าทุกสาขา ---------- */
.tabs { display: flex; gap: 2px; background: var(--bg); border-radius: var(--radius); padding: 3px; }
.tabs a { padding: 5px 10px; border-radius: 4px; color: var(--muted); text-decoration: none; font-size: 13px; white-space: nowrap; }
.tabs a[aria-current="page"] { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 0 0 1px var(--line); }
.side h2 .mini { margin-left: auto; font-size: 12px; font-weight: 500; border: 1px solid var(--jade); color: var(--jade); background: var(--surface); border-radius: 999px; padding: 2px 10px; cursor: pointer; }
.side h2 { gap: 8px; }
.tp.away { background: transparent; border: 1px solid var(--jade); border-left-width: 4px; }
.tp.away .sub + .sub { margin-top: 0; }
.dlg { border: 0; border-radius: 10px; padding: 0; width: min(520px, 92vw); color: var(--ink); box-shadow: 0 18px 50px rgba(30, 43, 47, .28); }
.dlg::backdrop { background: rgba(30, 43, 47, .35); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px 4px; }
.dlg h3 { margin: 0; font-size: 17px; }
.dlg .hint { padding: 0 18px; margin: 0 0 6px; color: var(--muted); font-size: 12.5px; }
.dlg section { padding: 8px 18px 4px; border-top: 1px solid var(--line); }
.dlg h4 { margin: 4px 0 6px; font-size: 14px; display: flex; justify-content: space-between; }
.dlg h4 small { color: var(--muted); font-weight: 500; }
.dlg ul { list-style: none; margin: 0 0 6px; padding: 0; }
.dlg li { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 7px 0; border-bottom: 1px dashed var(--line); }
.dlg li:last-child { border-bottom: 0; }
.dlg li small { display: block; color: var(--muted); font-size: 12px; }
.dlg li .done { font-size: 11.5px; color: var(--partial); margin-left: auto; text-align: right; }
.dlg .empty { color: var(--muted); font-size: 13px; margin: 2px 0 10px; }
.dlg section:last-child { padding-bottom: 14px; }
.primary.sm { min-height: 30px; padding: 4px 14px; font-size: 13px; }
/* หน้าทุกสาขา */
.page { flex: 1; overflow: auto; padding: 18px 22px 28px; }
.page h1 { font-size: 20px; margin: 0 0 2px; }
.page .meta { color: var(--muted); font-size: 13px; margin: 0 0 14px; }
.page h2 { font-size: 16px; margin: 26px 0 8px; display: flex; gap: 12px; align-items: baseline; }
.page h2 small { color: var(--muted); font-weight: 500; font-size: 13px; }
.tbl-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
table.tbl { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
.tbl th { text-align: right; font-weight: 600; color: var(--muted); font-size: 12.5px; padding: 9px 12px; border-bottom: 1px solid var(--line-hour); white-space: nowrap; background: var(--surface); }
.tbl td { text-align: right; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl th:first-child, .tbl td:first-child, .tbl .l { text-align: left; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tr.me td { background: #F6FAF9; }
.tbl td.warn { color: var(--dirty); font-weight: 600; }
.tbl td.alert { color: var(--unpaid); font-weight: 700; }
.tbl td .names { color: var(--muted); font-size: 12.5px; }
.tbl .bar { display: inline-block; width: 64px; height: 6px; background: var(--bg); border-radius: 3px; vertical-align: middle; margin-left: 8px; overflow: hidden; }
.tbl .bar i { display: block; height: 100%; background: var(--jade); }
.tag-call { color: var(--jade-ink); font-weight: 600; }

/* ---------- Step 4: ล็อกอิน · ข้อความแจ้ง · วางเพื่อมอบงาน ---------- */
.login { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; background: var(--bg); }
.login[hidden] { display: none; }
body.locked .top, body.locked .main, body.locked .legend, body.locked .page { visibility: hidden; }
.login-box { width: min(360px, 90vw); background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 24px; display: flex; flex-direction: column; gap: 12px; }
.login-box h1 { font-size: 18px; margin: 0; }
.login-box label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.login-box input { border: 1px solid var(--line); border-radius: var(--radius); padding: 9px 10px; font: inherit; color: var(--ink); }
.login-msg { min-height: 1.4em; margin: 0; font-size: 13px; color: var(--unpaid); }
.login-box .lang-switch { align-self: flex-end; }
.toasts { position: fixed; right: 16px; bottom: 44px; z-index: 60; display: flex; flex-direction: column; gap: 8px; max-width: min(420px, 90vw); }
.toast { background: var(--ink); color: #fff; padding: 9px 14px; border-radius: 8px; font-size: 13px; box-shadow: 0 6px 18px rgba(30, 43, 47, .25); }
.toast.ok { background: var(--jade); } .toast.warn { background: #8A5A10; } .toast.err { background: var(--unpaid); }
.bk.drop-on { outline: 3px dashed var(--jade); outline-offset: -3px; }
