/* cdrm 掛號後台：醫療系統風格設計（單一淺色主題，色彩僅輔助、一律搭配文字標籤） */

:root {
  color-scheme: light;
  /* 品牌與底色 */
  --brand: #0E7490;          /* 醫療藍綠 */
  --brand-deep: #155E75;
  --brand-tint: #E0F2FE;
  --page: #F1F5F8;           /* 診間冷灰藍底 */
  --surface: #FFFFFF;
  --hairline: #E2E8F0;
  --row-line: #EEF2F7;
  /* 墨色（文字一律用墨色，不用狀態色） */
  --ink: #0F172A;
  --ink-2: #475569;
  --ink-3: #64748B;
  /* 狀態色（固定保留，不挪作他用；一律搭配文字） */
  --st-waiting-bg: #FEF3C7; --st-waiting-fg: #92400E;
  --st-called-bg: #CFFAFE;  --st-called-fg: #155E75;
  --st-done-bg: #DCFCE7;    --st-done-fg: #166534;
  --st-muted-bg: #F1F5F9;   --st-muted-fg: #475569;
  --st-orange-bg: #FFEDD5;  --st-orange-fg: #9A3412;
  --danger: #B91C1C;
  --focus-ring: rgba(14, 116, 144, 0.35);
}

* { box-sizing: border-box; }
html { height: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--page);
  color: var(--ink);
  font-family: system-ui, -apple-system, "PingFang TC", "Microsoft JhengHei", "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand-deep); }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 4px; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- 通用卡片與按鈕 ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: 12px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.05);
}
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 10px 18px;
  border-radius: 8px; border: 1px solid transparent;
  font-size: 16px; font-weight: 600; cursor: pointer;
  text-decoration: none;
}
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-deep); }
.btn-block { width: 100%; }
.btn-ghost-inverse {
  background: rgba(255, 255, 255, 0.12); color: #fff;
  border-color: rgba(255, 255, 255, 0.45);
  min-height: 38px; padding: 6px 14px; font-size: 15px;
}
.btn-ghost-inverse:hover { background: rgba(255, 255, 255, 0.22); }

/* ---------- 頂欄 ---------- */
.appbar { background: linear-gradient(180deg, var(--brand) 0%, var(--brand-deep) 100%); color: #fff; }
.appbar-inner {
  max-width: 1080px; margin: 0 auto; padding: 12px 20px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.appbar-tools { display: flex; align-items: center; gap: 10px; }
.lang-select {
  min-height: 38px; padding: 5px 10px; font-size: 14.5px;
  background: rgba(255, 255, 255, 0.14); color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.45); border-radius: 8px;
}
/* 下拉選單展開時是系統原生樣式，選項要用深色字才看得見 */
.lang-select option { color: var(--ink); background: #fff; }
.login-lang { display: flex; justify-content: center; margin-top: 14px; }
.login-lang .lang-select {
  background: #fff; color: var(--ink); border-color: #CBD5E1;
}
.logo-mark { width: 34px; height: 34px; flex: none; color: currentColor; }
.brand-name { font-size: 18px; font-weight: 700; letter-spacing: 0.02em; }
.brand-sub { font-size: 12.5px; opacity: 0.85; }

/* ---------- 版面 ---------- */
.page { max-width: 1080px; margin: 0 auto; padding: 20px; display: grid; gap: 16px; }
.page-narrow { max-width: 760px; }

/* ---------- 目前看診（叫號板） ---------- */
.now-serving { padding: 18px 22px; border-left: 4px solid var(--brand); }
.ns-label { font-size: 13px; font-weight: 700; color: var(--ink-3); letter-spacing: 0.08em; }
.ns-body { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.ns-number {
  font-size: clamp(44px, 7vw, 64px); font-weight: 800; line-height: 1.1;
  color: var(--brand-deep);
}
.ns-idle .ns-number { color: var(--ink-3); }
.ns-unit { font-size: 20px; font-weight: 700; color: var(--ink-2); }
.ns-who { margin-left: 8px; align-self: center; }
.ns-name { font-size: 19px; font-weight: 700; }
.ns-time { font-size: 14px; color: var(--ink-3); }

/* ---------- 統計數字卡 ---------- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.tile { display: flex; align-items: center; gap: 12px; padding: 14px 16px; }
.tile-icon {
  width: 38px; height: 38px; flex: none; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 17px; font-weight: 800;
}
.tile-brand { background: var(--brand-tint); color: var(--brand-deep); }
.tile-amber { background: var(--st-waiting-bg); color: var(--st-waiting-fg); }
.tile-green { background: var(--st-done-bg); color: var(--st-done-fg); }
.tile-orange { background: var(--st-orange-bg); color: var(--st-orange-fg); }
.tile-label { font-size: 13px; color: var(--ink-2); }
.tile-value { font-size: 27px; font-weight: 800; line-height: 1.15; color: var(--ink); }

/* ---------- 佇列表格 ---------- */
.list-card { padding: 6px 0 0; overflow: hidden; }
.list-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 20px 10px; flex-wrap: wrap;
}
.list-head h2 { margin: 0; font-size: 17px; }
.list-tools { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.sync-note { font-size: 13px; color: var(--ink-3); }
select {
  min-height: 40px; padding: 6px 10px; font-size: 15px;
  border: 1px solid var(--hairline); border-radius: 8px;
  background: var(--surface); color: var(--ink);
}
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 15.5px; }
thead th {
  text-align: left; font-size: 12.5px; font-weight: 700; color: var(--ink-3);
  letter-spacing: 0.04em; padding: 8px 14px; border-bottom: 1px solid var(--hairline);
  background: #F8FAFC; white-space: nowrap;
}
tbody td { padding: 12px 14px; border-bottom: 1px solid var(--row-line); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #F8FAFC; }
tr.row-called { background: #F0FDFF; box-shadow: inset 3px 0 0 var(--brand); }
tr.row-called:hover { background: #E6FBFF; }
tr.row-terminal { color: var(--ink-3); }
tr.row-terminal .name-link { color: var(--ink-3); }
.col-num { width: 64px; }
.col-time { width: 96px; font-variant-numeric: tabular-nums; color: var(--ink-2); white-space: nowrap; }
.num-link {
  font-variant-numeric: tabular-nums; font-size: 17px; font-weight: 800;
  color: var(--brand-deep); text-decoration: none;
}
.name-link { color: var(--ink); font-weight: 600; text-decoration: none; }
.name-link:hover, .num-link:hover { text-decoration: underline; }
.uname { margin-left: 8px; font-size: 13px; color: var(--ink-3); }
.col-chief { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.placeholder { color: var(--ink-3); }
.list-foot { padding: 10px 20px 14px; font-size: 13px; color: var(--ink-3); border-top: 1px solid var(--row-line); }

/* 狀態徽章：色點＋文字並用 */
.badge {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 3px 11px; border-radius: 999px; font-size: 13.5px; font-weight: 700;
  white-space: nowrap;
}
.badge .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge-waiting { background: var(--st-waiting-bg); color: var(--st-waiting-fg); }
.badge-called { background: var(--st-called-bg); color: var(--st-called-fg); }
.badge-done { background: var(--st-done-bg); color: var(--st-done-fg); }
.badge-muted { background: var(--st-muted-bg); color: var(--st-muted-fg); }
@media (prefers-reduced-motion: no-preference) {
  .badge-called .dot { animation: pulse 1.6s ease-in-out infinite; }
  @keyframes pulse { 50% { opacity: 0.35; } }
}

/* 自述完成度 */
.desc-state { font-size: 14px; font-weight: 700; white-space: nowrap; }
.desc-none { color: var(--ink-3); }
.desc-partial { color: var(--st-orange-fg); }
.desc-full { color: var(--st-done-fg); }

/* 空狀態 */
.empty-state { text-align: center; padding: 48px 20px 56px; color: var(--ink-2); }
.empty-state .logo-mark { width: 44px; height: 44px; color: var(--brand); opacity: 0.55; }
.empty-state p { margin: 10px 0 0; font-size: 17px; font-weight: 600; }
.empty-state .sub { font-size: 14px; font-weight: 400; color: var(--ink-3); }

/* ---------- 登入頁 ---------- */
.login-wrap { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card { width: 100%; max-width: 400px; padding: 28px; }
.login-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; color: var(--brand-deep); }
.login-brand .logo-mark { width: 44px; height: 44px; }
.login-brand h1 { margin: 0; font-size: 21px; color: var(--ink); }
.login-brand .sub { margin: 2px 0 0; font-size: 13.5px; color: var(--ink-3); }
.field-label { display: block; font-size: 14px; font-weight: 700; color: var(--ink-2); margin: 6px 0 6px; }
input[type="password"] {
  width: 100%; min-height: 46px; padding: 10px 14px; font-size: 16px;
  border: 1px solid #CBD5E1; border-radius: 8px; background: #fff; color: var(--ink);
  margin-bottom: 14px;
}
input[type="password"]:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--focus-ring); outline: none; }
.alert {
  background: #FEF2F2; color: var(--danger); border: 1px solid #FECACA;
  border-radius: 8px; padding: 10px 14px; font-size: 14.5px; font-weight: 600; margin-bottom: 14px;
}
.login-note { margin: 14px 0 0; font-size: 13px; color: var(--ink-3); text-align: center; }
.nf-title { margin: 0 0 6px; font-size: 40px; color: var(--brand-deep); }

/* ---------- 病人明細 ---------- */
.back-link { display: inline-block; font-size: 15px; text-decoration: none; font-weight: 600; }
.back-link:hover { text-decoration: underline; }
.patient-head { display: flex; align-items: center; gap: 20px; padding: 20px 22px; }
.ph-num { display: flex; align-items: baseline; gap: 6px; }
.ph-name { font-size: 21px; font-weight: 800; }
.ph-meta { font-size: 14px; color: var(--ink-3); margin: 2px 0 8px; }
.card-title { margin: 0 0 12px; font-size: 15.5px; color: var(--ink-2); }
.page-narrow .card { padding: 18px 22px; }
.page-narrow .patient-head { padding: 20px 22px; }

.timeline { display: flex; gap: 10px; flex-wrap: wrap; }
.tl-step {
  flex: 1; min-width: 130px; display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; border: 1px solid var(--hairline); border-radius: 10px;
  color: var(--ink-3); background: #FAFCFE;
}
.tl-step.tl-on { color: var(--ink); border-color: #BAE6FD; background: #F0F9FF; }
.tl-dot { width: 9px; height: 9px; border-radius: 50%; background: #CBD5E1; flex: none; }
.tl-on .tl-dot { background: var(--brand); }
.tl-label { font-weight: 700; font-size: 14.5px; }
.tl-time { margin-left: auto; font-variant-numeric: tabular-nums; font-size: 14.5px; }

.desc-row { display: grid; grid-template-columns: 110px 1fr; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--row-line); }
.desc-row:last-of-type { border-bottom: 0; }
.desc-key { font-size: 14.5px; font-weight: 700; color: var(--ink-2); }
.req { color: var(--danger); margin-left: 2px; }
.desc-val { font-size: 15.5px; }
.desc-missing { color: var(--st-orange-fg); font-weight: 700; }
.raw-box { margin-top: 14px; }
.raw-box summary { cursor: pointer; font-size: 14px; color: var(--ink-2); font-weight: 600; }
.raw-box pre {
  margin: 8px 0 0; padding: 12px 14px; background: #F8FAFC; border: 1px solid var(--hairline);
  border-radius: 8px; font-size: 14px; white-space: pre-wrap; word-break: break-word;
  font-family: inherit;
}
.desc-upd { margin-top: 10px; font-size: 13px; color: var(--ink-3); }
.empty-desc { color: var(--ink-2); font-size: 15.5px; }
.empty-desc .sub { font-size: 13.5px; color: var(--ink-3); }

/* ---------- 響應式 ---------- */
@media (max-width: 760px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .page { padding: 14px; gap: 12px; }
  .appbar-inner { padding: 10px 14px; }
  .patient-head { flex-direction: row; }
  .desc-row { grid-template-columns: 96px 1fr; }
  .col-chief { max-width: 160px; }
}
