:root {
  --primary: #e85a4f;
  --blue: #3498db;
  --blue-dark: #2980b9;
  --green: #27ae60;
  --teal: #16a085;
  --orange: #e67e22;
  --gray-nav: #5d6d7e;
  --border: #dce4ec;
  --bg: #f4f6f8;
  --text: #2c3e50;
  --tooltip-bg: #2c3e50;
  /* 全站內容比例（項目名稱／內文／輸入框／用藥單一併套用） */
  --ui-scale: 2;
  /* 裝置版面：手機預設 → 平板／桌面用 media 覆寫 */
  --page-max: 480px;
  --page-gutter: 14px;
  --brand-size: 1.35rem;
  --section-title-size: 1.1rem;
  --nav-gap: 10px;
  --nav-btn-pad-y: 18px;
  --nav-btn-font: 0.95rem;
  --nav-icon-size: 1.4rem;
  --search-input-pad: 12px 14px;
  --table-font: 0.9rem;
  --auth-card-max: 420px;
  /* rem sizes inherit --ui-scale via html font-size; do not stack again */
  --id-search-scale: 1;
}

html {
  font-size: calc(16px * var(--ui-scale));
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Microsoft JhengHei', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  -webkit-tap-highlight-color: transparent;
}

.page {
  max-width: var(--page-max);
  width: 100%;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  background: #fff;
  box-shadow: 0 0 24px rgba(0, 0, 0, 0.06);
}

.header {
  position: relative;
  text-align: center;
  padding: 14px var(--page-gutter) 8px;
  border-bottom: 1px solid var(--border);
}

.header h1 {
  margin: 0;
  font-size: var(--brand-size);
  color: var(--primary);
  font-weight: 700;
}

.header .logo {
  font-size: 0.75rem;
  color: #95a5a6;
  line-height: 1;
}

.header .logo i {
  font-size: inherit;
  color: inherit;
}

.header--with-lang {
  /* rem scales with --ui-scale so 「繁體中文」 etc. stay clear of title */
  padding-right: 9.5rem;
}

.header-lang {
  position: absolute;
  top: 10px;
  right: 10px;
  margin: 0;
  z-index: 1100;
  pointer-events: auto;
}

.header-lang .lang-select-label {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.header-lang select,
.header-lang .lang-select {
  width: max-content;
  max-width: none;
  min-width: 6.5em;
  padding: 3px 1.75em 3px 8px;
  font-size: 0.78rem;
  overflow: visible;
}

.section-title {
  text-align: center;
  font-size: var(--section-title-size);
  margin: 16px 0 12px;
  font-weight: 600;
}

.nav-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--nav-gap);
  padding: 0 var(--page-gutter) 16px;
}

.nav-grid--n-0 {
  display: none;
  padding: 0;
}

.nav-grid--n-1 {
  grid-template-columns: 1fr;
}

.nav-grid--n-2 {
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.nav-grid--n-2 .nav-btn {
  min-height: 108px;
  gap: 8px;
  padding: 20px 10px;
  font-size: 1rem;
}

.nav-grid--n-2 .nav-btn i {
  font-size: 1.5rem;
}

.nav-grid--n-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.nav-grid--n-3 .nav-btn {
  gap: 4px;
  padding: 14px 6px;
  font-size: 0.86rem;
}

.nav-grid--n-3 .nav-btn i {
  font-size: 1.15rem;
}

.nav-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: var(--nav-btn-pad-y) 8px;
  border: none;
  border-radius: 8px;
  color: #fff;
  font-size: var(--nav-btn-font);
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}

.nav-btn i {
  font-size: var(--nav-icon-size);
}

.nav-btn.treatment { background: var(--gray-nav); }
.nav-btn.freeze { background: var(--blue); }
.nav-btn.image { background: var(--green); }
.nav-btn.lab { background: var(--teal); }
.nav-btn.files { background: var(--orange); }
.nav-grid--n-5 .nav-btn.files {
  grid-column: 1 / -1;
}
.nav-btn.is-active {
  box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.45);
}
.nav-btn.disabled {
  opacity: 0.45;
  pointer-events: none;
}

/* 前台帳號登入 */
body.portal-locked {
  overflow: hidden;
}

body.portal-locked > :not(.portal-auth-overlay) {
  visibility: hidden;
}

.portal-auth-overlay {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: grid;
  place-items: center;
  padding: 20px;
  background:
    radial-gradient(circle at top left, rgba(232, 90, 79, 0.11), transparent 32%),
    linear-gradient(145deg, #edf3f7, #f8fafb);
}

.portal-auth-overlay[hidden] {
  display: none;
}

.portal-auth-card {
  width: min(100%, var(--auth-card-max));
  padding: 30px 26px;
  border: 1px solid #e2e8ee;
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 18px 50px rgba(44, 62, 80, 0.13);
}

.portal-auth-icon {
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  margin-bottom: 16px;
  border-radius: 16px;
  color: #fff;
  background: linear-gradient(135deg, var(--primary), #c84339);
  font-size: 1.35rem;
}

.portal-auth-card h1 {
  margin: 0 0 8px;
  color: var(--primary);
  font-size: 1.55rem;
}

.portal-auth-card p {
  margin: 0 0 20px;
  color: #6d7c89;
  line-height: 1.6;
}

.portal-auth-card label {
  display: block;
  margin: 12px 0 6px;
  font-weight: 700;
}

.portal-auth-card input {
  width: 100%;
  padding: 13px 14px;
  border: 1px solid var(--border);
  border-radius: 9px;
  font-size: 1rem;
}

.password-field {
  position: relative;
}

.password-field input {
  padding-right: 48px;
}

.password-toggle {
  position: absolute;
  top: 50%;
  right: 8px;
  width: 36px;
  height: 36px;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: #71808d;
  font-size: 1rem;
  cursor: pointer;
  transform: translateY(-50%);
}

.password-toggle:hover,
.password-toggle:focus-visible {
  color: var(--text);
  background: #edf2f5;
  outline: none;
}

.portal-auth-card > button[type='submit'],
.portal-auth-card > button[type='button'] {
  width: 100%;
  margin-top: 18px;
  padding: 13px;
  border: none;
  border-radius: 9px;
  color: #fff;
  background: var(--blue);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
}

.portal-auth-card > button[type='button'] {
  margin-top: 8px;
  color: var(--text);
  background: #edf2f5;
}

.portal-auth-error {
  margin: 12px 0 0 !important;
  color: #b43c33 !important;
  font-weight: 700;
}

.portal-session-bar {
  position: fixed;
  top: 8px;
  left: 8px;
  z-index: 999;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 7px;
  max-width: calc(100vw - 120px);
  padding: 6px 9px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 3px 12px rgba(44, 62, 80, 0.1);
  color: #52616d;
  font-size: 0.76rem;
  box-sizing: border-box;
}

.portal-session-bar button {
  padding: 3px 7px;
  border: none;
  border-radius: 999px;
  color: #fff;
  background: var(--primary);
  cursor: pointer;
}

.portal-session-transfers {
  padding: 3px 7px;
  border-radius: 999px;
  color: #fff;
  background: var(--orange);
  font-weight: 700;
  text-decoration: none;
}

.portal-session-account {
  max-width: min(42vw, 180px);
  overflow: hidden;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 上傳下載頁 */
.files-panel {
  padding: 0 14px 22px;
}

.files-agent-picker {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
  font-weight: 700;
}

.files-agent-picker[hidden] {
  display: none;
}

.files-agent-picker select {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: #fff;
  font-size: 0.95rem;
}

.files-upload-card,
.files-list-card {
  margin-bottom: 14px;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 5px 18px rgba(44, 62, 80, 0.06);
}

.files-upload-card {
  border-top: 5px solid var(--orange);
}

.files-upload-card h3,
.files-list-card h3 {
  margin: 0 0 6px;
}

.files-upload-card p,
.files-list-card p {
  margin: 0 0 12px;
  color: #71808d;
  font-size: 0.86rem;
}

.files-upload-card input[type='file'] {
  width: 100%;
  margin-bottom: 12px;
  padding: 12px;
  border: 2px dashed #edbd91;
  border-radius: 10px;
  background: #fff8f1;
}

.btn-files-primary,
.btn-files-refresh,
.btn-files-download,
.btn-files-edit,
.btn-files-delete {
  padding: 10px 14px;
  border: none;
  border-radius: 8px;
  font-weight: 700;
  cursor: pointer;
}

.btn-files-primary:disabled,
.btn-files-download:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.btn-files-primary {
  width: 100%;
  color: #fff;
  background: var(--orange);
}

.files-list-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.btn-files-refresh {
  color: var(--text);
  background: #edf2f5;
}

.files-list {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.files-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: #fbfcfd;
}

.files-item-selector {
  width: 19px;
  height: 19px;
  flex: 0 0 auto;
  accent-color: var(--teal);
  cursor: pointer;
}

.files-item-info {
  min-width: 0;
  flex: 1;
}

.files-item-info strong,
.files-item-info span {
  display: block;
  overflow-wrap: anywhere;
}

.files-item-info span {
  margin-top: 3px;
  color: #71808d;
  font-size: 0.78rem;
}

.btn-files-download {
  flex: 0 0 auto;
  color: #fff;
  background: var(--teal);
}

.btn-files-edit {
  color: #fff;
  background: var(--blue);
}

.btn-files-delete {
  color: #fff;
  background: #c0392b;
}

.files-item-actions {
  display: flex;
  flex: 0 0 auto;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

@media (max-width: 420px) {
  .files-item {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .files-item-actions {
    width: 100%;
  }
}

.files-message {
  padding: 10px 0;
  color: #71808d;
  text-align: center;
}

.search-box {
  padding: 0 var(--page-gutter) 8px;
}

.search-row {
  display: flex;
  gap: calc(8px * var(--id-search-scale));
  align-items: stretch;
}

.search-row input,
#idNumber {
  flex: 1;
  min-width: 0;
  padding: calc(12px * var(--id-search-scale)) calc(14px * var(--id-search-scale));
  border: 1px solid var(--border);
  border-radius: calc(6px * var(--id-search-scale));
  font-size: calc(1rem * var(--id-search-scale));
  line-height: 1.35;
  min-height: calc(44px * var(--id-search-scale));
}

.search-row button,
#btnSearch {
  padding: 0 calc(18px * var(--id-search-scale));
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: calc(6px * var(--id-search-scale));
  font-size: calc(1rem * var(--id-search-scale));
  cursor: pointer;
  white-space: nowrap;
  min-height: calc(44px * var(--id-search-scale));
}

.search-hint {
  text-align: center;
  font-size: calc(0.8rem * var(--id-search-scale));
  color: #7f8c8d;
  margin: calc(8px * var(--id-search-scale)) 0 calc(14px * var(--id-search-scale));
}

.data-table {
  width: calc(100% - (var(--page-gutter) * 2));
  margin: 0 var(--page-gutter) 24px;
  border-collapse: collapse;
  font-size: var(--table-font);
}

.data-table th,
.data-table td {
  border: 1px solid var(--border);
  padding: 10px 8px;
  text-align: center;
}

.data-table th {
  background: #5d6d7e;
  color: #fff;
  font-weight: 600;
}

.data-table .btn-detail-outline {
  background: #fff;
  color: var(--blue);
  border: 1px solid var(--blue);
}

.table-wrap {
  margin: 0 14px 24px;
  overflow-x: auto;
}

.btn-detail {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: 4px;
  font-size: 0.85rem;
  cursor: pointer;
  text-decoration: none;
}

.empty-msg,
.error-msg {
  text-align: center;
  padding: 24px 16px;
  color: #7f8c8d;
}

.error-msg { color: #c0392b; }

.loading {
  text-align: center;
  padding: 20px;
  color: #95a5a6;
}

.select-course-hint {
  text-align: center;
  font-size: 0.9rem;
  color: #5d6d7e;
  margin: -6px 14px 12px;
}

/* 用藥日曆頁：固定框架，僅中間表格可捲動 */
html.schedule-layout {
  position: fixed;
  inset: 0;
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  height: 100svh;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  background: var(--bg);
}

body.schedule-page {
  position: fixed;
  inset: 0;
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  height: 100svh;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  background: var(--bg);
}

.schedule-shell {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  height: 100svh;
  max-width: 100vw;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  background: #fff;
  contain: layout size style;
}

.schedule-header {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 40;
  background: #fff;
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
  touch-action: manipulation;
}

.schedule-header .header {
  padding: 10px 14px 4px;
  border: none;
}

.schedule-page .top-bar {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  padding: 4px 14px 8px;
  border: none;
}

.back-link {
  font-size: 0.88rem;
  color: var(--blue);
  text-decoration: none;
}

.schedule-page .course-id {
  font-size: 0.95rem;
  font-weight: 600;
}

.schedule-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 14px 10px;
  font-size: 0.78rem;
  color: #7f8c8d;
  flex-wrap: wrap;
}

.lang-select-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text);
  font-size: 0.85rem;
  position: relative;
  z-index: 1100;
}

.lang-select-wrap select {
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.85rem;
}

.schedule-overlay-msg {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(255, 255, 255, 0.92);
  text-align: center;
}

.schedule-overlay-msg[hidden] {
  display: none !important;
}

/* 中間表格區：上下由 JS 量測 header/footer 高度後定位 */
.schedule-table-panel {
  position: absolute;
  left: 0;
  right: 0;
  top: var(--schedule-header-h, 132px);
  bottom: var(--schedule-footer-h, 100px);
  overflow: hidden;
  touch-action: none;
  background: #fff;
  z-index: 10;
}

.schedule-scroll {
  width: 100%;
  height: 100%;
  overflow: scroll;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: none;
  touch-action: pan-x pan-y;
  contain: strict;
}

.schedule-scroll[hidden] {
  display: none !important;
}

.schedule-scroll.scrolled-x .schedule-table .corner-th,
.schedule-scroll.scrolled-x .schedule-table td.label {
  box-shadow: 4px 0 6px rgba(0, 0, 0, 0.1);
}

.schedule-scroll.scrolled-y .schedule-table thead th {
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.08);
}

.schedule-footer {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 40;
  background: #fff;
  border-top: 1px solid var(--border);
  padding: 0 0 env(safe-area-inset-bottom, 0);
  box-shadow: 0 -1px 4px rgba(0, 0, 0, 0.05);
  max-height: min(32vh, 240px);
  overflow-y: auto;
  overscroll-behavior: none;
  touch-action: pan-y;
}

/* 手機 RWD */
@media (max-width: 430px) {
  .schedule-header .header {
    padding: 8px 12px 2px;
  }

  .schedule-header .header h1 {
    font-size: 1.15rem;
  }

  .schedule-page .top-bar {
    padding: 2px 12px 6px;
  }

  .schedule-toolbar {
    padding: 4px 12px 8px;
    font-size: 0.72rem;
    gap: 6px;
  }

  .schedule-table {
    --label-w: 108px;
    --date-w: 66px;
    font-size: 0.76rem;
  }

  .schedule-table th,
  .schedule-table td {
    padding: 6px 6px;
  }

  .schedule-footer {
    max-height: min(28vh, 200px);
  }

  .prepare-note {
    margin: 8px 10px;
    padding: 10px 12px;
    font-size: 0.82rem;
  }
}

@media (max-width: 360px) {
  .schedule-table {
    --label-w: 92px;
    --date-w: 58px;
    font-size: 0.72rem;
  }
}

@media (orientation: landscape) and (max-height: 500px) {
  .schedule-header .header h1 {
    font-size: 1rem;
  }

  .schedule-toolbar {
    display: none;
  }

  .schedule-footer {
    max-height: min(36vh, 160px);
  }
}

@media (orientation: landscape) {
  .schedule-scroll {
    touch-action: pan-x pan-y;
  }
  .schedule-table {
    font-size: 0.78rem;
  }
  .schedule-table th,
  .schedule-table td {
    padding: 6px 8px;
  }
  .schedule-footer {
    max-height: min(28vh, 200px);
  }
}

/* 小手機 */
@media (max-width: 360px) {
  :root {
    --page-gutter: 10px;
    --brand-size: 1.2rem;
    --section-title-size: 1rem;
    --nav-btn-pad-y: 14px;
    --nav-btn-font: 0.88rem;
    --nav-icon-size: 1.2rem;
    --table-font: 0.82rem;
    --auth-card-max: 100%;
  }

  .portal-auth-card {
    padding: 22px 16px;
  }

  .portal-auth-card h1 {
    font-size: 1.3rem;
  }

  .search-row {
    flex-direction: column;
  }

  .search-row button,
  #btnSearch {
    width: 100%;
    min-height: calc(44px * var(--id-search-scale));
  }
}

/* 平板 */
@media (min-width: 768px) {
  :root {
    --page-max: 720px;
    --page-gutter: 20px;
    --brand-size: 1.55rem;
    --section-title-size: 1.25rem;
    --nav-gap: 14px;
    --nav-btn-pad-y: 22px;
    --nav-btn-font: 1.02rem;
    --nav-icon-size: 1.55rem;
    --search-input-pad: 14px 16px;
    --table-font: 0.95rem;
    --auth-card-max: 460px;
  }

  .schedule-shell {
    left: 0;
    margin-left: 0;
    margin-right: 0;
  }

  .schedule-table {
    --label-w: 148px;
    --date-w: 80px;
    font-size: 0.88rem;
  }

  .nav-grid--n-4,
  .nav-grid--n-5,
  .nav-grid--n-6 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .nav-grid--n-5 .nav-btn.files {
    grid-column: auto;
  }

  .portal-auth-overlay {
    padding: 32px;
  }
}

/* 桌面 */
@media (min-width: 1024px) {
  :root {
    --page-max: 100%;
    --page-gutter: 28px;
    --brand-size: 1.7rem;
    --section-title-size: 1.35rem;
    --nav-gap: 16px;
    --nav-btn-pad-y: 26px;
    --nav-btn-font: 1.08rem;
    --nav-icon-size: 1.7rem;
    --table-font: 1rem;
    --auth-card-max: 480px;
  }

  body {
    background: #fff;
  }

  .page {
    max-width: none;
    width: 100%;
    box-shadow: none;
  }

  .nav-grid--n-4,
  .nav-grid--n-5,
  .nav-grid--n-6 {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .schedule-shell {
    left: 0;
  }

  .schedule-table {
    --label-w: 148px;
    --date-w: 80px;
    font-size: 0.88rem;
  }

  .schedule-table th,
  .schedule-table td {
    padding: 8px 8px;
  }

  .schedule-page .top-bar {
    font-size: 0.95rem;
  }

  .schedule-toolbar {
    font-size: 0.85rem;
  }

  .prepare-note {
    font-size: 0.9rem;
  }

  .prepare-note h3 {
    font-size: 0.95rem;
  }

  .header {
    padding-top: 20px;
    padding-bottom: 12px;
  }

  .data-table th,
  .data-table td {
    padding: 12px 10px;
  }
}

/* 大桌面（含 1920×1080） */
@media (min-width: 1280px) {
  :root {
    --page-gutter: clamp(24px, 4vw, 48px);
    --brand-size: 1.85rem;
  }

  .schedule-table {
    --label-w: 160px;
    --date-w: 88px;
    font-size: 0.9rem;
  }
}

@media (min-width: 1600px) {
  :root {
    --page-gutter: clamp(32px, 5vw, 64px);
    --brand-size: 2rem;
    --nav-btn-pad-y: 28px;
    --nav-btn-font: 1.12rem;
    --nav-icon-size: 1.8rem;
  }

  .nav-grid--n-5,
  .nav-grid--n-6 {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .schedule-table {
    --label-w: 176px;
    --date-w: 96px;
    font-size: 0.95rem;
  }
}

.prepare-note {
  margin: 10px 14px 8px;
  padding: 12px 14px;
  background: #fff8e6;
  border: 1px solid #f0d78c;
  border-radius: 8px;
  font-size: 0.88rem;
  line-height: 1.55;
}

.note-fallback {
  font-size: 0.8rem;
  color: #7f8c8d;
  margin: 0 0 8px;
}

.note-empty {
  color: #95a5a6;
  margin: 0;
}

.prepare-note h3 {
  margin: 0 0 8px;
  font-size: 0.95rem;
  color: #b7950b;
}

.prepare-note .note-body {
  white-space: pre-wrap;
  word-break: break-word;
}

/* 資料庫 HTML 注意事項：保留顏色、標題、列表（標題已在 prepare_note 內） */
.prepare-note .note-body--html {
  white-space: normal;
}

.prepare-note .note-body--html h1,
.prepare-note .note-body--html h2,
.prepare-note .note-body--html h3,
.prepare-note .note-body--html h4,
.prepare-note .note-body--html h5,
.prepare-note .note-body--html h6 {
  margin: 0.45em 0 0.25em;
  font-weight: 700;
  color: inherit;
  line-height: 1.45;
}

.prepare-note .note-body--html h6 {
  font-size: 1em;
}

.prepare-note .note-body--html p {
  margin: 0.35em 0;
}

.prepare-note .note-body--html ol,
.prepare-note .note-body--html ul {
  margin: 0.35em 0 0.35em 1.2em;
  padding: 0;
}

.prepare-note .note-body--html li {
  margin: 0.2em 0;
}

.prepare-note .note-body--html b,
.prepare-note .note-body--html strong {
  font-weight: 700;
}

.schedule-table {
  --grid-color: #c8d0d8;
  --grid-line: 1px;
  --grid-line-strong: 1px;
  --label-w: 132px;
  --date-w: 76px;
  border-collapse: separate;
  border-spacing: 0;
  width: max-content;
  font-size: 0.82rem;
  table-layout: fixed;
}

.schedule-table .col-label {
  width: var(--label-w);
}

.schedule-table .col-date {
  width: var(--date-w);
}

.schedule-table th,
.schedule-table td {
  border: var(--grid-line) solid var(--grid-color);
  padding: 7px 9px;
  text-align: center;
  white-space: nowrap;
  box-sizing: border-box;
  height: 36px;
  vertical-align: middle;
}

.schedule-table td.label {
  position: -webkit-sticky;
  position: sticky;
  left: 0;
  z-index: 2;
  height: auto;
  min-height: 36px;
  text-align: left;
  background: #fafbfc;
  background-clip: padding-box;
  font-weight: 500;
  width: var(--label-w);
  box-sizing: border-box;
  word-break: break-word;
  white-space: normal;
  line-height: 1.35;
  vertical-align: top;
  border-right: var(--grid-line-strong) solid #a8b4c0;
  -webkit-transform: translateZ(0);
  transform: translateZ(0);
}

.schedule-table tbody tr:nth-child(even) td.label {
  background: #f0f2f4;
}

/* 每種藥品列底部分隔（細線） */
.schedule-table tbody tr {
  border-bottom: var(--grid-line) solid #b0bcc8;
}

.schedule-table thead th {
  position: -webkit-sticky;
  position: sticky;
  top: 0;
  background: #ecf0f1;
  background-clip: padding-box;
  font-weight: 600;
  z-index: 3;
  border-bottom: var(--grid-line-strong) solid #a8b4c0;
  height: 36px;
  box-sizing: border-box;
  -webkit-transform: translateZ(0);
  transform: translateZ(0);
}

.schedule-table .corner-th {
  position: -webkit-sticky;
  position: sticky;
  left: 0;
  top: 0;
  z-index: 5;
  background: #dce3e8;
  background-clip: padding-box;
  text-align: center;
  border-right: var(--grid-line-strong) solid #a8b4c0;
  -webkit-transform: translateZ(0);
  transform: translateZ(0);
}

.schedule-table tbody tr:nth-child(even) td:not(.label) {
  background: #f8f9fa;
}

.cell-has-data {
  cursor: help;
  position: relative;
}

.cell-has-data:active {
  background: #e8f4fc;
}

.tooltip {
  position: fixed;
  z-index: 1000;
  background: var(--tooltip-bg);
  color: #fff;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 0.9rem;
  pointer-events: none;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.15s, transform 0.15s;
  max-width: 240px;
  text-align: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}

.tooltip.visible {
  opacity: 1;
  transform: translateY(0);
}

.schedule-page .footer-close {
  display: block;
  margin: 8px 14px 12px auto;
  padding: 10px 20px;
  background: #5d6d7e;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 0.95rem;
  cursor: pointer;
}

.ready-msg {
  margin: 12px 14px;
  padding: 12px 14px;
  background: #e8f8f0;
  color: #0a7a4a;
  border-radius: 8px;
  font-size: 0.92rem;
  text-align: center;
}

.module-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 14px 12px;
  padding: 12px 14px;
  background: #5d6d7e;
  color: #fff;
  border-radius: 8px;
  font-weight: 600;
}

.page-footer {
  padding: 8px 14px 24px;
}

.btn-home {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 14px;
  border-radius: 8px;
  background: #5d6d7e;
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  text-decoration: none;
}

.list-hint {
  margin: 0 var(--page-gutter) calc(10px * var(--id-search-scale));
  font-size: calc(0.88rem * var(--id-search-scale));
  color: #7f8c8d;
  text-align: center;
}

.page-treatment .cycle-item summary {
  font-size: 1rem;
  padding: 16px;
}

.cycle-list {
  padding: 0 14px 16px;
}

.cycle-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 10px;
  overflow: hidden;
  background: #fff;
}

.cycle-item summary {
  list-style: none;
  cursor: pointer;
  padding: 14px 16px;
  font-weight: 600;
  background: #f8f9fa;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.cycle-item summary::-webkit-details-marker { display: none; }

.cycle-item summary::after {
  content: '\f078';
  font-family: 'Font Awesome 6 Free';
  font-weight: 900;
  color: #7f8c8d;
  transition: transform 0.2s;
}

.cycle-item[open] summary::after { transform: rotate(180deg); }

.cycle-body {
  padding: 12px 16px 16px;
}

.cycle-field {
  display: flex;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px dashed #ecf0f1;
  font-size: 0.92rem;
}

.cycle-label {
  min-width: 6.5em;
  color: var(--primary);
  font-weight: 600;
}

.cycle-value { flex: 1; }

.btn-detail.block {
  display: inline-flex;
  margin-top: 12px;
}

.module-results {
  padding: 0 14px 20px;
}

.result-count {
  font-size: 0.9rem;
  color: #7f8c8d;
  margin: 0 0 12px;
}

.info-card,
.image-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 12px;
  background: #fff;
}

.info-card h3 {
  margin: 0 0 10px;
  font-size: 1rem;
}

.field-list div {
  display: flex;
  gap: 8px;
  padding: 4px 0;
  font-size: 0.92rem;
}

.field-list dt {
  min-width: 5em;
  color: #7f8c8d;
}

.field-list dd { margin: 0; flex: 1; }

.badge {
  display: inline-block;
  margin-left: 6px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #ecf0f1;
  font-size: 0.8rem;
  font-weight: 600;
}

.card-image {
  display: block;
  max-width: 100%;
  margin-top: 10px;
  border-radius: 8px;
}

.card-image.wide { width: 100%; }

.image-section { margin-bottom: 18px; }

.image-section-title {
  margin: 0 0 10px;
  padding: 8px 12px;
  background: linear-gradient(90deg, #8e44ad, #9b59b6);
  color: #fff;
  border-radius: 8px;
  font-size: 0.95rem;
}

.image-card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  font-weight: 600;
}

.image-type-badge {
  font-size: 0.8rem;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--teal);
  color: #fff;
}

/* 影像資料分類頁 */
.page-images .images-toolbar {
  display: flex;
  align-items: center;
  margin: 0 14px 14px;
  padding-bottom: 4px;
}

.page-images .images-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.image-type-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 0 14px 10px;
}

.image-type-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 88px;
  padding: 14px 8px;
  border: none;
  border-radius: 8px;
  background: var(--blue);
  color: #fff;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: box-shadow 0.15s, opacity 0.15s;
}

.image-type-btn i {
  font-size: 1.35rem;
}

.image-type-btn.is-active {
  box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.55);
}

.image-type-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-show-all-images {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: calc(100% - 28px);
  margin: 0 14px 16px;
  padding: 14px;
  border: 2px solid var(--blue);
  border-radius: 8px;
  background: #fff;
  color: var(--blue);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-show-all-images.is-active {
  background: #ebf5fb;
  box-shadow: inset 0 0 0 1px var(--blue);
}

.page-images .page-footer {
  margin-top: 8px;
}

/* 檢驗報告分類頁 */
.module-bar-reports {
  background: var(--teal);
  margin-top: 0;
}

.report-type-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 0 14px 10px;
}

.report-type-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  min-height: 52px;
  padding: 14px 16px;
  border: none;
  border-radius: 8px;
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: box-shadow 0.15s, opacity 0.15s;
}

.report-type-btn.report-semen { background: var(--gray-nav); }
.report-type-btn.report-pgta { background: var(--blue); }
.report-type-btn.report-blood { background: var(--teal); }
.report-type-btn.report-default { background: #7f8c8d; }

.report-type-btn.is-active {
  box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.55);
}

.btn-show-all-reports {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: calc(100% - 28px);
  margin: 0 14px 16px;
  padding: 14px;
  border: 2px solid var(--teal);
  border-radius: 8px;
  background: #fff;
  color: var(--teal);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-show-all-reports.is-active {
  background: #e8f8f5;
  box-shadow: inset 0 0 0 1px var(--teal);
}

.report-date-group {
  margin-bottom: 16px;
}

.report-date-head {
  margin: 0 0 8px;
  padding: 10px 14px;
  background: linear-gradient(90deg, #8e44ad, #9b59b6);
  color: #fff;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.report-detail {
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 8px;
  background: #fff;
  overflow: hidden;
}

.report-detail summary {
  list-style: none;
  cursor: pointer;
  padding: 14px 16px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
  background: #f8f9fa;
}

.report-detail summary::-webkit-details-marker { display: none; }

.report-detail summary::after {
  content: '\f078';
  font-family: 'Font Awesome 6 Free';
  font-weight: 900;
  margin-left: auto;
  color: #7f8c8d;
  transition: transform 0.2s;
}

.report-detail[open] summary::after { transform: rotate(180deg); }

.report-detail-body {
  padding: 12px 16px 16px;
}

.report-frame.inline {
  width: 100%;
  min-height: 50vh;
  border: none;
  border-radius: 8px;
}

.report-content-text {
  padding: 12px 14px;
  border-radius: 8px;
  background: #f4f6f8;
  border-left: 3px solid var(--teal);
  font-size: 0.95rem;
  line-height: 1.7;
  word-break: break-word;
}

.page-reports .page-footer {
  margin-top: 8px;
}

/* 冷凍資訊頁 */
.module-bar-freeze {
  background: var(--blue);
  margin-top: 0;
}

.btn-freeze-load {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: calc(100% - 28px);
  margin: 0 14px 16px;
  padding: 14px;
  border: none;
  border-radius: 8px;
  background: var(--green);
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}

.freeze-results-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px 10px;
}

.freeze-results-head h3 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
}

.result-badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 999px;
  background: #1abc9c;
  color: #fff;
  font-size: 0.82rem;
  font-weight: 600;
}

.freeze-results {
  padding: 0 14px 20px;
}

.freeze-card {
  border: 1px solid var(--border);
  border-left: 4px solid var(--green);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 14px;
  background: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.freeze-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}

.freeze-card-head h3 {
  margin: 0;
  font-size: 1rem;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
}

.freeze-count-badge {
  flex-shrink: 0;
  padding: 4px 10px;
  border-radius: 999px;
  background: #ecf0f1;
  color: #5d6d7e;
  font-size: 0.82rem;
  font-weight: 600;
}

.freeze-field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  padding: 10px 12px;
  border-radius: 8px;
  background: #f4f6f8;
  border-left: 3px solid var(--blue);
}

.freeze-field-label {
  color: #7f8c8d;
  font-size: 0.9rem;
  font-weight: 600;
}

.freeze-field-value {
  font-size: 0.95rem;
  font-weight: 600;
  text-align: right;
}

.freeze-quality {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 6px;
  background: #d6eaf8;
  color: var(--blue-dark);
}

.freeze-card-image {
  margin-top: 12px;
}

.page-freeze .page-footer {
  margin-top: 8px;
}

.report-row {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 8px;
  align-items: center;
  padding: 14px;
  margin-bottom: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  text-align: left;
  font: inherit;
}

.report-title { font-weight: 600; }

.report-date { color: #7f8c8d; font-size: 0.9rem; }

.empty-msg.inline {
  padding: 8px 0;
  margin: 0;
  background: none;
}

.modal[hidden] { display: none !important; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
}

.modal-panel {
  position: relative;
  width: min(100%, 520px);
  max-height: 90vh;
  background: #fff;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 { margin: 0; font-size: 1rem; }

.modal-header button {
  border: none;
  background: none;
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
}

.modal-body {
  padding: 12px 16px;
  overflow: auto;
  flex: 1;
}

.modal-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  text-align: right;
}

.btn-modal-close {
  padding: 10px 24px;
  border: none;
  border-radius: 6px;
  background: #5d6d7e;
  color: #fff;
  cursor: pointer;
}

.btn-modal-confirm {
  padding: 10px 24px;
  border: none;
  border-radius: 6px;
  background: var(--blue);
  color: #fff;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 600;
}

#phoneModalInput {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 1rem;
}

.report-frame {
  width: 100%;
  min-height: 60vh;
  border: none;
}
