/* 顏色與字體一律引用泰昌堂內部系統共用樣式 tct-ui.css 的 --tct-* 變數，
   正本在 湯agent/000_Agent/skills/tct-internal-ui/tct-ui.css，本檔不自創配色。
   --alert / --muted 是本專案自訂的狀態功能色，不屬於泰昌堂 CIS。

   版面以「平板橫放」為主要設計對象（醫師端一屏完成、不用滑動），
   手機與桌機自動收合成單欄。 */
:root {
  --brand-green: var(--tct-green);
  --brand-gold: var(--tct-gold);
  --brand-bg: var(--tct-bg);
  --brand-ink: var(--tct-ink);
  --alert: #C0392B;
  --muted: #9A9A93;
  /* 人形圖左右半邊的標示色：鏡像之後畫面左右會換邊，同一隻手至少顏色永遠一樣。
     跟 --alert／--muted 一樣是本專案的功能色，不是泰昌堂 CIS 的品牌色。
     赭紅取自共用樣式的狀態色 danger；靛藍是配它的對比色，紅藍最好分辨。 */
  --side-left: #B24B3C;
  --side-right: #3B6E8F;
  --radius: var(--tct-radius);        /* 8px：按鈕、輸入框 */
  --radius-lg: var(--tct-radius-lg);  /* 14px：床卡這種平板觸控大物件 */
  --font-display: var(--tct-font-display);
  --font-body: var(--tct-font);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--brand-bg);
  color: var(--brand-ink);
  font-family: var(--font-body);
  font-size: 17px;
  line-height: 1.5;
}

h1, h2, h3 { font-family: var(--font-display); color: var(--brand-green); margin: 0 0 .4em; }
h2 { font-size: 19px; }
h3 { font-size: 17px; }

.wrap { max-width: 1180px; margin: 0 auto; padding: 12px; }

.topbar {
  display: flex; align-items: center; gap: 12px;
  min-height: 60px; padding: 6px 18px; background: var(--brand-green); color: #fff;
  flex-wrap: wrap;
}
/* 左邊是圓印 logo ＋「泰昌堂｜針灸計時」，樣式走 tct-ui.css 的 .tct-brand */
.topbar h1 { color: #fff; font-size: 18px; margin: 0; }
.topbar #site-name { font-size: 16px; opacity: .9; }
.topbar #clock { font-size: 16px; opacity: .9; font-variant-numeric: tabular-nums; }
/* 連線斷掉時的警示：畫面上的倒數還在跑，但那是舊資料，要讓櫃檯看得出來 */
.conn { background: #fff; color: var(--alert); font-weight: 700; padding: 4px 12px; border-radius: 999px; font-size: 15px; }
.topbar nav { margin-left: auto; display: flex; gap: 8px; }
.topbar nav a {
  color: #fff; text-decoration: none; padding: 6px 14px;
  border: 1px solid rgba(255,255,255,.5); border-radius: 999px; font-size: 15px;
}
.topbar nav a.active { background: #fff; color: var(--brand-green); }

.card {
  background: #fff; border: 1px solid rgba(43,46,41,.12);
  border-radius: var(--radius-lg); padding: 14px; margin-bottom: 14px;
}
.card.tight { padding: 12px; margin-bottom: 12px; }

/* 觸控目標：平板上手指要好按，至少 52px */
.btn {
  min-height: 52px; padding: 10px 18px; font-size: 17px;
  border: 1.5px solid var(--brand-green); border-radius: var(--radius);
  background: #fff; color: var(--brand-green);
  font-family: var(--font-body); cursor: pointer;
}
/* 按下去要有感覺：全域關了 tap highlight，沒有這條平板上按了完全沒變化 */
.btn { transition: transform .06s ease, filter .06s ease; }
.btn:active:not(:disabled) { transform: scale(.95); filter: brightness(.88); }
.btn:disabled { border-color: var(--muted); color: var(--muted); background: #f2f1ec; cursor: not-allowed; }
.btn-primary { background: var(--brand-green); color: #fff; }
.btn-primary:disabled { background: var(--muted); border-color: var(--muted); color: #fff; }
.btn-ghost { border-color: var(--brand-gold); color: var(--brand-ink); }
.btn.selected { background: var(--brand-green); color: #fff; }
.btn-sm { min-height: 40px; padding: 6px 12px; font-size: 15px; }
.btn-lg { min-height: 64px; font-size: 20px; font-weight: 700; }

.row { display: flex; flex-wrap: wrap; gap: 10px; }

/* 醫師端選位置的按鈕：用狀態顏色區分，不用灰化 */
.pos-btn { min-width: 104px; }
.pos-btn.pos-waiting { background: #FDF8EC; border-color: var(--brand-gold); color: var(--brand-ink); }
.btn.pos-btn.pos-in_progress:disabled { background: var(--brand-green); border-color: var(--brand-green); color: #fff; }
.btn.pos-btn.pos-alarm:disabled { background: var(--alert); border-color: var(--alert); color: #fff; }
.btn.pos-btn.pos-cleaning:disabled { background: #E1DED4; border-color: var(--muted); color: #5a5d56; }
.pos-btn.selected { background: var(--brand-green); color: #fff; border-color: var(--brand-green); box-shadow: 0 0 0 3px rgba(87,123,83,.28); }
/* 助理已經標明「是這位醫師的病人」的床，用金色外框讓醫師一眼認出 */
.pos-btn.mine:not(.selected) { box-shadow: 0 0 0 3px var(--brand-gold); border-color: var(--brand-gold); }
.row.tight { gap: 8px; }
.muted-text { font-size: 14px; color: #5a5d56; }

/* --- 醫師端：平板橫放兩欄，左邊人形圖、右邊操作 --- */
.doctor-layout {
  display: grid;
  grid-template-columns: minmax(330px, 47%) 1fr;
  gap: 14px;
  align-items: start;
}
/* 右欄在「床位兩排＋三位醫師＋數字鍵盤」時最高，原本送出鈕會掉出 1024x768 一屏約 13px。
   卡片內距／間距與鍵盤下方各省一點（合計約 30px），觸控按鈕大小不動 */
.doctor-layout .card.tight { padding: 10px; margin-bottom: 8px; }
.doctor-layout .card.tight h2 { margin: 0 0 6px; }
.doctor-layout .keypad-inline { margin-bottom: 8px; }
@media (max-width: 860px) {
  .doctor-layout { grid-template-columns: 1fr; }
}

.bodymaps { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; justify-items: center; position: relative; }
/* 人形圖高度跟著視窗走，換一台平板也不會需要捲動 */
.bodymaps svg { height: 41vh; width: auto; max-width: 100%; display: block; }
/* iPad Safari 的網址列會吃掉高度，dvh 才是「真正看得到」的高度 */
@supports (height: 1dvh) {
  .bodymaps svg { height: 40dvh; }
  .detail-panel .bodymaps svg { height: 44dvh; }
}
.bodymap-caption { text-align: center; font-size: 19px; color: var(--brand-ink); margin-bottom: 2px; font-weight: 700; }
.bodymap-caption strong { font-size: 26px; color: var(--brand-green); }
/* 「（面向你）」「（背對你）」：塞在標頭同一行，不多佔一列高度 */
.bodymap-caption .view-hint { font-size: 16px; font-weight: 500; color: var(--muted); }

/* 剛剛點了哪裡：浮在人形圖上約 1.5 秒，點錯邊當下就看得到。
   absolute 是刻意的——左欄在 iPad 1024x768 剛好滿，回饋條不能佔到高度 */
.map-flash {
  position: absolute; left: 50%; bottom: 2px; transform: translateX(-50%);
  padding: 6px 16px; border-radius: var(--radius);
  background: var(--brand-ink); color: #fff;
  font-size: 17px; font-weight: 700; white-space: nowrap;
  box-shadow: 0 2px 10px rgba(43,46,41,.3);
  pointer-events: none; animation: flash-in .12s ease-out;
}
.map-flash.side-left { background: var(--side-left); }
.map-flash.side-right { background: var(--side-right); }
@keyframes flash-in { from { opacity: 0; transform: translate(-50%, 6px); } }
@media (prefers-reduced-motion: reduce) { .map-flash { animation: none; } }
/* 預留數字鍵盤的高度（三排 0～20），展開時版面不會整個跳動。
   人形圖 41vh 是配合第三排量出來的：iPad 1024x768 左欄剛好不捲動 */
.numpad-host { min-height: 176px; }

/* 合計針數：金色橫條，是醫師送出前最後確認的那個數字 */
.total-bar {
  margin-top: 8px; padding: 8px 14px; border-radius: var(--radius-lg);
  background: var(--brand-gold); color: var(--brand-ink);
  font-size: 17px; text-align: center; font-weight: 700;
}
.total-bar strong { font-size: 30px; font-family: var(--font-display); }
.total-bar.is-zero { background: #EDE9DE; color: var(--muted); }

/* 唯讀的人形圖（櫃檯端看詳情用） */
.region.read-only { cursor: default; }
.region.read-only:hover { fill: #EDE9DE; }
.region.read-only.has-needles:hover { fill: var(--brand-gold); }
.badge.read-only { cursor: default; }

/* 櫃檯端點卡片看部位詳情 */
.bed.clickable { cursor: pointer; }
.detail-overlay {
  position: fixed; inset: 0; background: rgba(43,46,41,.55);
  display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 20;
}
.detail-panel {
  background: #fff; border-radius: var(--radius-lg); padding: 16px;
  width: min(560px, 100%); max-height: 92vh; overflow: auto;
}
.detail-panel .bodymaps svg { height: 46vh; }
.region { fill: #EDE9DE; stroke: var(--brand-green); stroke-width: 1.5; cursor: pointer; transition: fill .15s; }
.region:hover { fill: var(--brand-gold); }
.region.has-needles { fill: var(--brand-gold); }
/* 字級是 SVG 使用者座標（viewBox 200 寬），不是螢幕 px */
.region-label { font-size: 15px; font-weight: 700; fill: var(--brand-ink); pointer-events: none; }
/* 左右分色：框線與部位名稱一起標，正面圖鏡像換邊後同一隻手還是同一個顏色 */
.region.side-left { stroke: var(--side-left); stroke-width: 2.5; }
.region.side-right { stroke: var(--side-right); stroke-width: 2.5; }
.region-label.side-left { fill: var(--side-left); }
.region-label.side-right { fill: var(--side-right); }

.badge { cursor: pointer; font-family: var(--font-body); font-size: 19px; font-weight: 700; }
.badge circle { fill: #fff; stroke: var(--brand-green); stroke-width: 2; }
.badge.zero circle { stroke: var(--muted); }
.badge.zero text { fill: var(--muted); }
.badge text { fill: var(--brand-green); text-anchor: middle; dominant-baseline: central; }

/* 數字鍵盤：點徽章後展開，一點即填 */
.numpad {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px;
  margin-top: 8px; padding: 10px; background: #fff;
  border: 2px solid var(--brand-gold); border-radius: var(--radius-lg);
}
.numpad button { min-height: 36px; font-size: 18px; padding: 2px; }
.numpad-title { grid-column: 1 / -1; font-weight: 700; color: var(--brand-green); }

/* --- 櫃檯端 --- */
.beds { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
@media (max-width: 700px) { .beds { grid-template-columns: 1fr; } }

.zone-title { font-family: var(--font-display); color: var(--brand-green); font-size: 16px; margin: 6px 2px; }

.bed { border-radius: var(--radius-lg); padding: 14px; border: 2px solid; background: #fff; }
.bed .bed-no { font-family: var(--font-display); font-size: 24px; font-weight: 700; }
.bed .countdown { font-size: 46px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: 1px; line-height: 1.1; }
.bed .meta { font-size: 15px; color: #5a5d56; }

.bed.empty { border-color: rgba(43,46,41,.15); color: var(--muted); }
.bed.waiting { border-color: var(--brand-gold); background: #FDF8EC; }
.bed.in_progress { border-color: var(--brand-green); background: #EDF2EB; }
.bed.in_progress .countdown { color: var(--brand-green); }
.bed.cleaning { border-color: var(--muted); background: #F3F2ED; }
.bed.alarm { border-color: var(--alert); background: var(--alert); color: #fff; animation: flash 1s steps(1) infinite; }
.bed.alarm .bed-no, .bed.alarm .meta { color: #fff; }
.bed.seat .bed-no::after { content: ' ・座位'; font-size: 14px; font-family: var(--font-body); color: var(--muted); font-weight: 400; }
.bed.seat.alarm .bed-no::after { color: #fff; }

@keyframes flash {
  0%, 49% { background: var(--alert); }
  50%, 100% { background: #8E2A1F; }
}
@media (prefers-reduced-motion: reduce) { .bed.alarm { animation: none; } }

/* --- 統計 --- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 12px; }
.stat { background: #fff; border: 1px solid rgba(43,46,41,.12); border-radius: var(--radius-lg); padding: 14px; }
.stat .value { font-size: 32px; font-weight: 700; color: var(--brand-green); font-variant-numeric: tabular-nums; }
.stat .label { font-size: 14px; color: #5a5d56; }
.stat-head {
  font-family: var(--font-display); color: var(--brand-green); font-size: 16px; font-weight: 700;
  padding-bottom: 6px; margin-bottom: 8px; border-bottom: 1px solid rgba(43,46,41,.1);
}
.stat-duo { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; text-align: center; }
.stat-duo > div + div { border-left: 1px solid rgba(43,46,41,.1); }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 7px 9px; border-bottom: 1px solid rgba(43,46,41,.1); }
th { color: var(--brand-green); font-weight: 700; }
td.closed-cell { background: #F0EEE7; color: var(--muted); font-size: 14px; }
input, select {
  font-family: var(--font-body); font-size: 16px; padding: 8px;
  border: 1px solid rgba(43,46,41,.25); border-radius: var(--radius); background: #fff;
}

.heat { display: grid; grid-template-columns: repeat(24, 1fr); gap: 2px; }
.heat div { aspect-ratio: 1; border-radius: 3px; background: #EDE9DE; }
.heat-labels { display: grid; grid-template-columns: repeat(24, 1fr); gap: 2px; font-size: 10px; color: var(--muted); text-align: center; }

/* 系統自己的對話框，取代瀏覽器內建的 alert/confirm/prompt */
.dialog-overlay {
  position: fixed; inset: 0; background: rgba(43,46,41,.55);
  display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 60;
}
.dialog-panel {
  background: #fff; border-radius: var(--radius-lg); padding: 20px 22px;
  width: min(460px, 100%); box-shadow: 0 12px 40px rgba(43,46,41,.3);
}
.dialog-panel h2 { margin: 0 0 .4em; }
.dialog-message { margin: 0; color: #5a5d56; font-size: 16px; white-space: pre-line; }
.btn-danger { background: var(--alert); border-color: var(--alert); color: #fff; }

/* 自製的日期範圍選擇器（datepicker.js），取代原生 <input type="date"> */
.dp-trigger { font-variant-numeric: tabular-nums; font-size: 16px; }
.dp-panel { width: min(440px, 100%); max-height: 94vh; overflow: auto; }
.dp-quick { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.dp-quick .btn { flex: 1 1 0; min-width: 64px; font-size: 16px; }
.dp-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.dp-title {
  flex: 1; text-align: center; font-family: var(--font-display); font-size: 18px;
  color: var(--brand-green); font-weight: var(--tct-weight-title);
}
.dp-nav { min-width: 44px; font-size: 22px; line-height: 1; }
.dp-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.dp-weekday { text-align: center; font-size: 16px; color: var(--tct-ink-2); padding: 4px 0; }
.dp-day {
  min-height: 44px; font-size: 16px; font-family: var(--font-body); font-variant-numeric: tabular-nums;
  border: 1px solid transparent; border-radius: var(--radius); background: #fff; color: var(--brand-ink);
  cursor: pointer; padding: 0;
}
.dp-day:hover { background: var(--tct-green-soft); }
.dp-day.other-month { color: var(--muted); }
.dp-day.in-range { background: var(--tct-green-soft); }
.dp-day.today { border-color: var(--brand-green); }
.dp-day.start, .dp-day.end { background: var(--brand-green); color: #fff; font-weight: 700; }
.dp-day:focus-visible { outline: 2px solid var(--brand-gold); outline-offset: 1px; }
.dp-foot {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px;
  margin-top: 14px; padding-top: 12px; border-top: 1px solid rgba(43,46,41,.1);
}
.dp-summary { font-size: 16px; font-weight: 700; color: var(--brand-ink); font-variant-numeric: tabular-nums; }

/* 時間到的全畫面提示：櫃檯忙起來很容易漏掉一個小小的紅卡片 */
.alarm-overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(192,57,43,.94); color: #fff;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 24px; gap: 14px;
  animation: alarm-pulse 1.1s ease-in-out infinite;
}
@keyframes alarm-pulse {
  0%, 100% { background: rgba(192,57,43,.94); }
  50% { background: rgba(142,42,31,.96); }
}
@media (prefers-reduced-motion: reduce) { .alarm-overlay { animation: none; } }

.alarm-overlay .alarm-title {
  font-family: var(--font-display); font-size: clamp(40px, 9vw, 84px); font-weight: 700; line-height: 1.1;
  text-align: center;
}
.alarm-overlay .alarm-sub { font-size: clamp(17px, 2.6vw, 22px); opacity: .95; text-align: center; }
.alarm-overlay .alarm-actions { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; margin-top: 8px; }
.alarm-overlay .btn {
  background: #fff; color: var(--alert); border-color: #fff; font-weight: 700;
  min-height: 62px; font-size: 19px; padding: 12px 26px;
}
.alarm-overlay .btn-quiet { background: transparent; color: #fff; border-color: rgba(255,255,255,.75); }

/* 送出後的提示：浮在畫面上，不佔版面高度（醫師端不能因此變成要捲動） */
.toast {
  position: fixed; top: 64px; left: 50%; transform: translateX(-50%);
  background: var(--brand-green); color: #fff;
  padding: 12px 22px; border-radius: 999px; font-size: 17px;
  box-shadow: 0 6px 20px rgba(43,46,41,.25); z-index: 30;
}

.hidden { display: none !important; }

/* --- 合計針數鍵盤（不分部位的醫師用）---
   佔的位置就是人形圖那半邊，所以尺寸抓成一屏內排得下、手指按得到。 */
.keypad-display {
  margin: 6px 0 10px; padding: 10px; border-radius: var(--radius-lg);
  background: var(--brand-gold); color: var(--brand-ink); text-align: center;
}
.keypad-display.is-zero { background: #EDE9DE; color: var(--muted); }
.keypad-num { font-family: var(--font-display); font-size: 64px; font-weight: 700; line-height: 1; }
.keypad-unit { font-size: 20px; margin-left: 6px; }

.keypad-quick { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }

/* 合計模式的部位標籤：七顆一排塞不下平板左欄，固定四＋三兩排，寬度一致好點 */
.area-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 10px; }
.btn-area { min-height: 44px; padding: 4px 6px; font-size: 18px; font-weight: 700; }
.btn-area.selected { border-color: var(--brand-gold); background: var(--brand-gold); color: var(--brand-ink); }

/* 櫃檯看部位時，合計紀錄勾的標籤用金色小籤列出來 */
.area-tags { margin-top: 8px; font-size: 15px; color: #5a5d56; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.area-tag {
  display: inline-block; padding: 2px 10px; border-radius: 999px;
  background: var(--brand-gold); color: var(--brand-ink); font-size: 15px; font-weight: 700;
}
.btn-quick { min-height: 46px; min-width: 60px; font-size: 19px; font-weight: 700; }

.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.btn-key { min-height: 58px; font-size: 26px; font-weight: 700; font-family: var(--font-display); }
.btn-key-alt { font-size: 18px; font-family: var(--font-body); color: #5a5d56; }

.unspec-chip {
  display: inline-block; margin-left: 6px; padding: 1px 8px; border-radius: 999px;
  background: rgba(255, 255, 255, .55); font-size: 13px; font-weight: 400;
}

/* 電針要提醒收針的人先拔電極、後續治療要提醒去叫醫師，都用金色跟其他資訊區分出來 */
.electro-chip, .followup-chip {
  display: inline-block; margin-left: 6px; padding: 1px 8px; border-radius: 999px;
  background: var(--brand-gold); color: var(--brand-ink); font-size: 13px; font-weight: 700;
}

/* --- 左上角的院區／樓層切換（只出現在設定頁）--- */
.site-switch { display: flex; align-items: center; gap: 8px; }
.switch-clinic-label { font-size: 16px; opacity: .9; }
.topbar .switch-select {
  background: rgba(255, 255, 255, .16); color: #fff;
  border: 1px solid rgba(255, 255, 255, .5); border-radius: 999px;
  padding: 5px 10px; font-family: inherit;
}
.topbar .switch-select option { color: var(--brand-ink); }
/* 院區不常切，做小做淡；樓層是主要的切換，做大一點好按 */
.topbar .switch-clinic { font-size: 15px; opacity: .85; }
.topbar .switch-floor { font-size: 17px; font-weight: 700; }

/* 直接打合計的數字鍵。放在右欄（原本有一段空白），
   所以人形圖完全不用縮，醫師端照樣一屏不用捲。 */
.keypad-inline {
  display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; margin-bottom: 12px;
}
.btn-key-sm {
  min-height: 46px; padding: 4px; font-size: 22px; font-weight: 700;
  font-family: var(--font-display);
}
.btn-key-sm.btn-key-alt { font-size: 15px; font-family: var(--font-body); color: #5a5d56; }
