/* 顏色一律經由下面的變數取用；配色主題只改變數，不改各元件的樣式。 */
:root {
  --ink: #17212f;
  --muted: #5d6979;
  --line: #e1e6ee;
  --line-strong: #c3ccd9;
  --surface: #ffffff;
  --page: #f3f5f9;
  --accent: #2459a6;
  --accent-strong: #1b467f;
  --accent-soft: #e9f0fb;
  --on-accent: #ffffff;
  --brand: #10294a;
  --brand-2: #1a4476;
  --brand-ink: #ffffff;
  --brand-muted: #b9c8dd;
  --brand-hover: #1c3c66;
  --site: #23705a;
  --site-soft: #e3f3ed;
  --ok: #23705a;
  --ok-soft: #e3f3ed;
  --warn: #8a5a00;
  --warn-soft: #fbf0d9;
  --danger: #b03a2a;
  --danger-soft: #fbeae7;
  --dq-good: #7fdcb4;
  --dq-fair: #f5cd72;
  --dq-poor: #ffa291;
  --dq-track: var(--line);
  --border-width: 1px;
  --radius: 12px;
  --radius-small: 8px;
  --shadow: 0 1px 2px rgb(16 41 74 / 6%), 0 4px 16px rgb(16 41 74 / 6%);
  --shadow-pop: 0 8px 28px rgb(16 41 74 / 18%);
  --font: "Microsoft JhengHei UI", "Microsoft JhengHei", "PingFang TC", "Noto Sans TC", system-ui, sans-serif;
  --mono: Consolas, "Cascadia Mono", monospace;
}

/* 高對比：黑白為主，邊框加粗，連結一律加底線。 */
html[data-theme="contrast"] {
  --ink: #000000;
  --muted: #1c1c1c;
  --line: #000000;
  --line-strong: #000000;
  --surface: #ffffff;
  --page: #ffffff;
  --accent: #00308f;
  --accent-strong: #001f5c;
  --accent-soft: #ffffff;
  --brand: #000000;
  --brand-2: #000000;
  --brand-muted: #ffffff;
  --brand-hover: #333333;
  --site: #004d2c;
  --site-soft: #ffffff;
  --ok: #004d2c;
  --ok-soft: #ffffff;
  --warn: #5c3b00;
  --warn-soft: #ffffff;
  --danger: #8f0000;
  --danger-soft: #ffffff;
  --dq-good: #ffffff;
  --dq-fair: #ffffff;
  --dq-poor: #ffffff;
  --dq-track: #ffffff;
  --border-width: 2px;
  --shadow: none;
  --shadow-pop: 0 0 0 2px #000000;
}

/* 色弱友善：不靠紅綠區分狀態，改用藍與橘；狀態另外都有文字標示。 */
html[data-theme="colorblind"] {
  --accent: #1a4f8f;
  --accent-strong: #123a6b;
  --accent-soft: #dfeaf7;
  --site: #7a4a00;
  --site-soft: #fbefd8;
  --ok: #005f99;
  --ok-soft: #dcedf9;
  --warn: #6b5200;
  --warn-soft: #f7efc9;
  --danger: #a34400;
  --danger-soft: #fde9d9;
  --dq-good: #8fc8ff;
  --dq-fair: #f2d878;
  --dq-poor: #ffb07a;
}

html {
  font-size: 100%;
}

html[data-font="large"] {
  font-size: 118.75%;
}

html[data-font="xlarge"] {
  font-size: 137.5%;
}

* {
  box-sizing: border-box;
}

/* hidden 屬性一律真的隱藏（元件自己設了 display 也一樣） */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--page);
  color: var(--ink);
  font-family: var(--font);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

html[data-theme="contrast"] .content a:not(.button):not(.tile) {
  text-decoration: underline;
  text-decoration-thickness: 2px;
}

a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
summary:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.sidebar a:focus-visible,
.landing-story a:focus-visible {
  outline-color: var(--brand-ink);
}

h1 {
  margin: 0;
  font-size: 1.5rem;
  line-height: 1.35;
  letter-spacing: 0.01em;
}

h2 {
  margin: 0 0 12px;
  font-size: 1.05rem;
}

p {
  margin: 0 0 10px;
}

small {
  font-size: 0.8125rem;
}

.muted {
  color: var(--muted);
  font-size: 0.875rem;
}

.hint {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.8125rem;
}

.nowrap {
  white-space: nowrap;
}

.icon {
  flex: none;
  width: 1.25rem;
  height: 1.25rem;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  padding: 8px 16px;
  background: var(--surface);
  color: var(--accent);
  font-weight: 600;
  z-index: 30;
}

.skip-link:focus {
  left: 8px;
  top: 8px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ---------- 品牌 ---------- */
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: inherit;
}

.brand:hover {
  text-decoration: none;
}

/* 標誌放在白底的圓角方塊裡，深色側欄上才看得清楚 */
.brand-mark {
  display: grid;
  flex: none;
  place-items: center;
  width: 3.5rem;
  height: 2.5rem;
  padding: 7px 8px;
  border-radius: 10px;
  background: #ffffff;
  box-shadow: 0 1px 3px rgb(0 0 0 / 18%);
}

.brand-mark img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
}

.brand-name {
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: 0.03em;
}

.brand-sub {
  font-size: 0.75rem;
  opacity: 0.8;
}

.role-badge {
  display: inline-block;
  padding: 2px 12px;
  border: var(--border-width) solid currentColor;
  border-radius: 999px;
  font-size: 0.8125rem;
  font-weight: 600;
  white-space: nowrap;
}

/* ---------- 登入後的版面：左側選單＋右側內容 ---------- */
body.shell {
  display: grid;
  grid-template-columns: 15.5rem minmax(0, 1fr);
}

/* 左側選單收合：整個收起來，內容區用滿版面；品牌與安裝角色改顯示在上方。 */
html[data-nav="collapsed"] body.shell {
  display: block;
}

html[data-nav="collapsed"] .sidebar {
  display: none;
}

html[data-nav="collapsed"] .content {
  max-width: none;
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
  height: 100vh;
  padding: 20px 14px;
  overflow-y: auto;
  background: linear-gradient(180deg, var(--brand) 0%, var(--brand) 55%, var(--brand-2) 140%);
  color: var(--brand-ink);
}

.sidebar .brand {
  padding: 0 6px;
}

/* 本院的節點身分：一種身分一個標示（同時是母節點與子節點時就是兩個） */
.role-badges,
.role-tags {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 6px;
}

.sidebar .role-badges {
  align-self: flex-start;
  margin-left: 6px;
}

.sidebar .role-badge {
  color: var(--brand-muted);
}

.sidenav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 6px;
}

.sidenav a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 12px;
  border-radius: var(--radius-small);
  color: var(--brand-muted);
  font-size: 0.9375rem;
}

.sidenav a:hover {
  background: var(--brand-hover);
  color: var(--brand-ink);
  text-decoration: none;
}

.sidenav a[aria-current="page"] {
  background: var(--brand-ink);
  color: var(--brand);
  font-weight: 700;
}

.sidenav-group {
  margin: 16px 0 4px;
  padding: 0 12px;
  color: var(--brand-muted);
  font-size: 0.75rem;
  letter-spacing: 0.12em;
  opacity: 0.75;
}

/* 待辦數字（選單項目、工作台的功能入口、收起選單時的選單按鈕）：像通訊軟體的未讀數字。
   數字之外另有給報讀軟體的說明，滑鼠停留時也看得到是哪些事。 */
.nav-count {
  flex: none;
  min-width: 1.4rem;
  margin-left: auto;
  padding: 1px 6px;
  border: var(--border-width) solid transparent;
  border-radius: 999px;
  background: var(--danger);
  color: var(--on-accent);
  font-size: 0.75rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.4;
  text-align: center;
}

html[data-theme="contrast"] .nav-count {
  border-color: var(--on-accent);
}

.tile .nav-count {
  margin-left: 0;
  font-size: 0.8125rem;
}

.nav-toggle .nav-count {
  margin-left: 0;
}

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 100vh;
}

.appbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
  padding: 10px 32px;
  background: var(--surface);
  border-bottom: var(--border-width) solid var(--line);
}

.appbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-right: auto;
}

.appbar form {
  margin: 0;
}

.nav-toggle {
  padding: 6px 8px;
  background: none;
  font: inherit;
}

.menu-button.nav-toggle .icon {
  width: 1.35rem;
  height: 1.35rem;
  color: var(--ink);
}

.appbar-brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.03em;
}

.appbar-brand:hover {
  text-decoration: none;
}

.appbar-brand img {
  display: block;
  width: auto;
  height: 1.25rem;
}

.appbar .role-badge {
  color: var(--brand-2);
}

.content {
  flex: 1;
  width: 100%;
  max-width: 76rem;
  padding: 28px 32px 40px;
}

.footer {
  padding: 14px 32px 20px;
  color: var(--muted);
  font-size: 0.8125rem;
}

/* ---------- 下拉選單（無障礙設定、使用者） ---------- */
.menu {
  position: relative;
}

.menu-button {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border: var(--border-width) solid transparent;
  border-radius: var(--radius-small);
  color: var(--ink);
  font-size: 0.9375rem;
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.menu-button::-webkit-details-marker {
  display: none;
}

.menu-button:hover,
.menu[open] > .menu-button {
  background: var(--page);
  border-color: var(--line);
}

.menu-button .icon:last-child {
  width: 1rem;
  height: 1rem;
  color: var(--muted);
}

.menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  z-index: 20;
  min-width: 13rem;
  margin: 0;
  padding: 8px;
  background: var(--surface);
  border: var(--border-width) solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-pop);
}

.menu-panel form {
  margin: 0;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: var(--radius-small);
  background: none;
  color: var(--ink);
  font: inherit;
  font-size: 0.9375rem;
  text-align: left;
  cursor: pointer;
}

.menu-item:hover {
  background: var(--page);
  text-decoration: none;
}

.prefs-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: 19rem;
  padding: 16px;
}

.prefs-label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--muted);
}

.segmented {
  display: flex;
  border: var(--border-width) solid var(--line-strong);
  border-radius: var(--radius-small);
  overflow: hidden;
}

.segmented button {
  flex: 1;
  padding: 7px 4px;
  border: 0;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 0.875rem;
  white-space: nowrap;
  cursor: pointer;
}

.segmented button + button {
  border-left: var(--border-width) solid var(--line-strong);
}

.segmented button:hover {
  background: var(--page);
}

.segmented button[aria-pressed="true"] {
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 700;
}

.segmented button:focus-visible {
  outline-offset: -3px;
}

.avatar {
  display: grid;
  place-items: center;
  flex: none;
  width: 1.9rem;
  height: 1.9rem;
  border-radius: 50%;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 0.9rem;
  font-weight: 700;
}

.avatar-large {
  width: 3.5rem;
  height: 3.5rem;
  font-size: 1.5rem;
}

/* ---------- 未登入的版面 ---------- */
body.plain {
  display: flex;
  flex-direction: column;
}

.plainbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 32px;
  background: var(--brand);
  color: var(--brand-ink);
}

.plainbar form {
  margin: 0;
}

.plainbar .button-quiet {
  background: transparent;
  border-color: var(--brand-muted);
  color: var(--brand-ink);
}

.content-narrow {
  max-width: 34rem;
  margin: 0 auto;
  padding-top: 48px;
}

body.plain .footer {
  text-align: center;
}

/* ---------- 登入頁 ---------- */
.landing-grid {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(22rem, 0.85fr);
  min-height: 100vh;
}

.landing-story {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 32px;
  padding: 40px 56px;
  background: linear-gradient(150deg, var(--brand) 0%, var(--brand) 45%, var(--brand-2) 130%);
  color: var(--brand-ink);
}

.landing-copy {
  max-width: 36rem;
}

.landing-copy .role-badge {
  color: var(--brand-muted);
}

.landing-copy h1 {
  margin: 18px 0 16px;
  font-size: 2.1rem;
  line-height: 1.4;
  letter-spacing: 0.02em;
}

.landing-lead {
  margin: 0 0 36px;
  color: var(--brand-muted);
  font-size: 1.05rem;
  line-height: 1.9;
}

.pillars {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.pillars li {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 16px;
  border: var(--border-width) solid rgb(255 255 255 / 18%);
  border-radius: var(--radius);
  background: rgb(255 255 255 / 6%);
}

.pillars .icon {
  width: 1.6rem;
  height: 1.6rem;
  margin-bottom: 6px;
}

.pillars strong {
  font-size: 1rem;
}

.pillars span {
  color: var(--brand-muted);
  font-size: 0.8125rem;
  line-height: 1.5;
}

.landing-foot {
  margin: 0;
  color: var(--brand-muted);
  font-size: 0.8125rem;
  opacity: 0.85;
}

.landing-form {
  display: grid;
  place-items: center;
  padding: 40px 32px;
  background: var(--surface);
}

.login-card {
  width: 100%;
  max-width: 22rem;
}

.login-logo {
  display: block;
  width: auto;
  height: 1.75rem;
  margin: 0 0 2rem;
}

.login-card h2 {
  margin: 0 0 24px;
  font-size: 1.6rem;
}

.login-card .button-large {
  margin-top: 24px;
}

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 20px 0;
  color: var(--muted);
  font-size: 0.8125rem;
}

.divider::before,
.divider::after {
  content: "";
  flex: 1;
  border-top: var(--border-width) solid var(--line);
}

/* ---------- 頁首 ---------- */
.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px 20px;
  margin-bottom: 20px;
}

.page-sub {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.9375rem;
  white-space: pre-line; /* 說明比較長時可以在文字裡分行 */
}

.page-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.crumb {
  display: inline-block;
  margin-bottom: 2px;
  color: var(--muted);
  font-size: 0.8125rem;
}

.crumb::before {
  content: "‹ ";
}

.section-title {
  margin: 28px 0 12px;
  color: var(--muted);
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.12em;
}

/* ---------- 卡片 ---------- */
.card {
  margin-bottom: 20px;
  padding: 24px;
  background: var(--surface);
  border: var(--border-width) solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card-form {
  max-width: 46rem;
}

.card-table {
  padding: 0;
  overflow: hidden;
}

.card-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.card-row h2,
.card-row p {
  margin: 0;
}

.card-row .form-actions {
  margin: 0;
}

.empty {
  margin: 0;
  padding: 40px 24px;
  color: var(--muted);
  text-align: center;
}

.split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr);
  gap: 20px;
  align-items: start;
}

.error-card {
  text-align: center;
}

.error-card .form-actions {
  justify-content: center;
}

.error-code {
  margin: 0;
  color: var(--accent);
  font-size: 2.6rem;
  font-weight: 800;
  line-height: 1.2;
}

code {
  padding: 2px 8px;
  background: var(--page);
  border-radius: 6px;
  font-family: var(--mono);
  font-size: 0.9em;
}

code.secret {
  padding: 6px 14px;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  user-select: all;
}

/* ---------- 工作台 ---------- */
.welcome {
  display: flex;
  align-items: center;
  gap: 18px;
  margin-bottom: 8px;
  padding: 24px 28px;
  border-radius: var(--radius);
  background: linear-gradient(120deg, var(--brand) 0%, var(--brand-2) 120%);
  color: var(--brand-ink);
  box-shadow: var(--shadow);
}

.welcome .avatar {
  background: var(--brand-ink);
  color: var(--brand);
}

.welcome h1 {
  margin-bottom: 8px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0;
}

.chip {
  display: inline-block;
  padding: 1px 10px;
  border: var(--border-width) solid var(--line-strong);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  font-size: 0.8125rem;
  white-space: nowrap;
}

.chip-accent {
  border-color: transparent;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-weight: 600;
}

html[data-theme="contrast"] .chip-accent {
  border-color: currentColor;
}

.welcome .chip {
  border-color: rgb(255 255 255 / 35%);
  background: rgb(255 255 255 / 12%);
  color: var(--brand-ink);
}

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(17rem, 1fr));
  gap: 16px;
}

.tile {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 18px 20px;
  background: var(--surface);
  border: var(--border-width) solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  color: var(--ink);
  transition: transform 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease;
}

.tile:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-pop);
  text-decoration: none;
  transform: translateY(-2px);
}

.tile-icon {
  display: grid;
  place-items: center;
  flex: none;
  width: 2.9rem;
  height: 2.9rem;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent);
}

.tile-icon .icon {
  width: 1.5rem;
  height: 1.5rem;
}

.tile-body {
  flex: 1;
  min-width: 0;
}

.tile-title {
  display: block;
  font-size: 1.02rem;
  font-weight: 700;
}

.tile-text {
  display: block;
  color: var(--muted);
  font-size: 0.8125rem;
}

.tile-arrow {
  color: var(--line-strong);
  transition: color 0.12s ease, transform 0.12s ease;
}

.tile:hover .tile-arrow {
  color: var(--accent);
  transform: translateX(3px);
}

@media (prefers-reduced-motion: reduce) {
  .tile,
  .tile-arrow {
    transition: none;
  }

  .tile:hover,
  .tile:hover .tile-arrow {
    transform: none;
  }
}

/* ---------- 按鈕 ---------- */
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 2.625rem;
  padding: 8px 18px;
  border: var(--border-width) solid var(--accent);
  border-radius: var(--radius-small);
  background: var(--accent);
  color: var(--on-accent);
  font: inherit;
  font-size: 0.9375rem;
  font-weight: 600;
  line-height: 1.5;
  white-space: nowrap;
  cursor: pointer;
}

.button:hover {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
  text-decoration: none;
}

.button .icon {
  width: 1.1rem;
  height: 1.1rem;
}

.button-secondary,
.button-quiet {
  background: var(--surface);
  border-color: var(--line-strong);
  color: var(--ink);
}

.button-secondary:hover,
.button-quiet:hover {
  background: var(--page);
  border-color: var(--accent);
  color: var(--accent);
}

.button-quiet {
  min-height: 0;
  padding: 4px 12px;
  font-weight: 400;
}

.button-danger {
  background: var(--surface);
  border-color: var(--danger);
  color: var(--danger);
}

.button-danger:hover {
  background: var(--danger);
  border-color: var(--danger);
  color: var(--on-accent);
}

.button-small {
  min-height: 0;
  padding: 4px 12px;
  font-size: 0.875rem;
}

.button-large {
  padding: 11px 18px;
  font-size: 1rem;
}

.button-block {
  display: flex;
  width: 100%;
}

/* ---------- 訊息與標籤 ---------- */
.notice {
  margin: 0 0 16px;
  padding: 10px 14px;
  border: var(--border-width) solid var(--line);
  border-left-width: 4px;
  border-radius: var(--radius-small);
  background: var(--surface);
  font-size: 0.9375rem;
}

.notice ul {
  margin: 0;
  padding-left: 1.3em;
}

.notice-success {
  border-color: var(--ok);
  background: var(--ok-soft);
}

.notice-success::before {
  content: "完成：";
  font-weight: 700;
  color: var(--ok);
}

.notice-info {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.notice-error {
  border-color: var(--danger);
  background: var(--danger-soft);
}

p.notice-error::before {
  content: "注意：";
  font-weight: 700;
  color: var(--danger);
}

.tag {
  display: inline-block;
  padding: 1px 10px;
  border: var(--border-width) solid transparent;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
}

html[data-theme="contrast"] .tag {
  border-color: currentColor;
}

.tag-ok,
.kind-added {
  background: var(--ok-soft);
  color: var(--ok);
}

.tag-info,
.kind-changed,
.kind-improved {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.tag-warn,
.kind-fixed {
  background: var(--warn-soft);
  color: var(--warn);
}

.tag-off {
  background: var(--page);
  color: var(--muted);
  border-color: var(--line);
}

.kind-removed {
  background: var(--danger-soft);
  color: var(--danger);
}

/* ---------- 表單 ---------- */
.form label,
.toolbar label {
  display: block;
  margin: 16px 0 6px;
  font-size: 0.875rem;
  font-weight: 600;
}

.form > label:first-of-type,
.form-row label {
  margin-top: 0;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-top: 16px;
}

.form > .form-row:first-child,
.form > input[type="hidden"] + .form-row,
fieldset.plain > .form-row:first-child {
  margin-top: 0;
}

input[type="text"],
input[type="password"],
input[type="email"],
input[type="search"],
input[type="date"],
input[type="number"],
select {
  width: 100%;
  min-height: 2.625rem;
  padding: 8px 12px;
  border: var(--border-width) solid var(--line-strong);
  border-radius: var(--radius-small);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 0.9375rem;
}

input::placeholder {
  color: var(--muted);
  opacity: 0.75;
}

input:hover,
select:hover {
  border-color: var(--accent);
}

.form-static {
  margin: 0;
  padding: 9px 0;
}

.form-status {
  margin: 0 0 16px;
}

fieldset {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

fieldset.options {
  margin-top: 22px;
}

fieldset.options legend {
  margin-bottom: 8px;
  padding: 0;
  font-size: 0.875rem;
  font-weight: 600;
}

.option-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

fieldset:disabled {
  opacity: 0.7;
}

.form label.check {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin: 0;
  padding: 10px 12px;
  border: var(--border-width) solid var(--line);
  border-radius: var(--radius-small);
  font-weight: 400;
  cursor: pointer;
}

.form label.check:hover {
  border-color: var(--accent);
}

.form label.check:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.form label.check-single {
  margin-top: 22px;
}

label.check input {
  flex: none;
  width: 1.1rem;
  height: 1.1rem;
  margin-top: 0.25rem;
  accent-color: var(--accent);
}

label.check span {
  display: flex;
  flex-direction: column;
}

label.check small {
  color: var(--muted);
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-top: 24px;
}

.form-actions form {
  margin: 0;
}

/* 並排的按鈕一樣大：不因為樣式（主要、次要、低調）或字數不同而高矮寬窄不一 */
.form-actions .button:not(.button-small) {
  min-width: 8.5rem;
  min-height: 2.625rem;
  padding: 8px 18px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 10px 12px;
  padding: 16px 20px;
  border-bottom: var(--border-width) solid var(--line);
}

.toolbar label {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.78rem;
}

.toolbar input,
.toolbar select {
  width: auto;
  min-width: 9rem;
}

.toolbar input[type="search"] {
  min-width: 16rem;
}

textarea {
  display: block;
  width: 100%;
  min-height: 6rem;
  padding: 8px 12px;
  border: var(--border-width) solid var(--line-strong);
  border-radius: var(--radius-small);
  background: var(--surface);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 0.9rem;
  line-height: 1.5;
  resize: vertical;
}

textarea:hover {
  border-color: var(--accent);
}

textarea:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* 依所選的驗證方式只顯示用得到的欄位；不支援 :has() 的瀏覽器會全部顯示，仍然可以填寫。 */
.auth-field {
  margin-top: 16px;
}

@supports selector(:has(*)) {
  .auth-field {
    display: none;
  }

  form:has(#fhir_auth option[value="client_credentials"]:checked) .auth-oauth,
  form:has(#fhir_auth option[value="password"]:checked) .auth-oauth,
  form:has(#fhir_auth option[value="password"]:checked) .auth-login,
  form:has(#fhir_auth option[value="basic"]:checked) .auth-login,
  form:has(#fhir_auth option[value="bearer"]:checked) .auth-bearer {
    display: block;
  }
}

/* ---------- 名稱與內容成對的清單、統計數字 ---------- */
.kv {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 8px 24px;
  margin: 0;
}

.kv dt {
  color: var(--muted);
  font-size: 0.875rem;
}

.kv dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.kv + .form-actions,
.card > .muted + .form-actions {
  margin-top: 20px;
}

.fold {
  margin-top: 16px;
  border-top: var(--border-width) solid var(--line);
}

.fold > summary {
  padding: 12px 0 4px;
  color: var(--accent-strong);
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
}

.fold table {
  width: 100%;
  margin-top: 8px;
}

.key-text {
  display: inline-block;
  overflow-wrap: anywhere;
  letter-spacing: 0;
  font-size: 1rem;
}

.notice-flush {
  margin: 20px 0 0;
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 18px 22px;
  background: var(--surface);
  border: var(--border-width) solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.stat-value {
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1.25;
  font-variant-numeric: tabular-nums;
}

.stat-accent .stat-value {
  color: var(--accent-strong);
}

.stat-label {
  color: var(--muted);
  font-size: 0.875rem;
}

.cell-meter {
  white-space: nowrap;
}

.cell-meter meter {
  width: 7rem;
  height: 0.6rem;
  margin-right: 8px;
  vertical-align: middle;
}

.cell-meter span {
  color: var(--muted);
  font-size: 0.8125rem;
  font-variant-numeric: tabular-nums;
}

.cell-codes code {
  display: inline-block;
  margin: 2px 4px 2px 0;
}

.card-code {
  padding: 0;
  overflow: hidden;
}

.code-block {
  max-height: 72vh;
  margin: 0;
  padding: 20px 24px;
  overflow: auto;
  font-family: var(--mono);
  font-size: 0.8125rem;
  line-height: 1.55;
}

/* ---------- 表格 ---------- */
.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9375rem;
}

th,
td {
  padding: 12px 20px;
  border-bottom: var(--border-width) solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  background: var(--page);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

tbody tr:hover {
  background: var(--accent-soft);
}

tbody tr:last-child td {
  border-bottom: 0;
}

.table-plain th,
.table-plain td {
  padding: 8px 10px;
}

.table-plain th:first-child,
.table-plain td:first-child {
  padding-left: 0;
}

.table-plain th {
  background: none;
}

.table-plain tbody tr:hover {
  background: none;
}

.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.cell-sub {
  display: block;
  color: var(--muted);
  font-family: var(--mono);
}

.cell-action {
  text-align: right;
  white-space: nowrap;
}

.cell-action a {
  font-weight: 600;
}

.cell-action form {
  display: inline-block;
  margin: 0 0 0 12px;
}

.cell-json {
  white-space: nowrap;
}

/* 展開的內容放在下一列、橫跨整張表，不會把表格撐寬。 */
.detail-row {
  display: none;
}

tr:has(.json-fold[open]) + .detail-row {
  display: table-row;
}

tr:has(.json-fold[open]) > td {
  border-bottom: 0;
}

@supports not selector(:has(*)) {
  .detail-row {
    display: table-row;
  }
}

.detail-row > td {
  padding-top: 0;
}

tbody tr.detail-row:hover {
  background: none;
}

.detail-row pre {
  max-height: 22rem;
  margin: 0;
  padding: 12px 14px;
  overflow: auto;
  border: var(--border-width) solid var(--line);
  border-radius: var(--radius-small);
  background: var(--page);
  font-family: var(--mono);
  font-size: 0.8125rem;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.pagination {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 20px;
  border-top: var(--border-width) solid var(--line);
  color: var(--muted);
  font-size: 0.875rem;
}

.pagination-links {
  display: flex;
  gap: 8px;
}

/* ---------- 收合的 JSON ---------- */
.json-fold summary {
  display: inline-block;
  padding: 1px 10px;
  border: var(--border-width) solid var(--line-strong);
  border-radius: 999px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
  white-space: nowrap;
}

.json-fold summary::-webkit-details-marker {
  display: none;
}

.json-fold summary::after {
  content: "　展開";
}

.json-fold[open] summary::after {
  content: "　收合";
}

/* ---------- 資料列表 ---------- */
.facts {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 10px 24px;
  margin: 0;
}

.facts dt {
  color: var(--muted);
  font-size: 0.875rem;
}

.facts dd {
  margin: 0;
}

.facts + .notice {
  margin-top: 20px;
}

/* ---------- 系統版本 ---------- */
.version-now {
  padding: 4px 14px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 0.875rem;
}

.timeline {
  max-width: 52rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.timeline + .pagination {
  max-width: 52rem;
  padding: 0;
  border-top: 0;
}

.release {
  margin: 0 0 16px;
  padding: 20px 24px;
  background: var(--surface);
  border: var(--border-width) solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.release-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  margin-bottom: 12px;
}

.release-head h2 {
  margin: 0;
}

.release-head time {
  margin-left: auto;
  color: var(--muted);
  font-size: 0.8125rem;
}

.release-version {
  padding: 2px 10px;
  border-radius: 6px;
  background: var(--brand);
  color: var(--brand-ink);
  font-family: var(--mono);
  font-size: 0.875rem;
  font-weight: 700;
}

.changes {
  margin: 0;
  padding: 0;
  list-style: none;
}

.changes li {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 6px 0;
  font-size: 0.9375rem;
}

.changes li + li {
  border-top: var(--border-width) solid var(--line);
}

.changes .tag {
  flex: none;
}

/* ---------- 窄螢幕 ---------- */
@media (max-width: 900px) {
  body.shell {
    display: block;
  }

  .sidebar {
    position: static;
    height: auto;
    padding: 14px 16px;
  }

  .sidenav {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .sidenav-group {
    display: none;
  }

  .appbar,
  .content,
  .footer {
    padding-left: 16px;
    padding-right: 16px;
  }

  .landing-grid {
    grid-template-columns: 1fr;
  }

  .landing-story {
    padding: 28px 24px;
  }

  /* 窄螢幕先顯示登入表單，平台理念排在後面。 */
  .landing-form {
    order: -1;
  }

  .landing-copy h1 {
    font-size: 1.6rem;
  }

  .kv {
    grid-template-columns: 1fr;
    gap: 2px;
  }

  .kv dd {
    margin-bottom: 8px;
  }

  .pillars,
  .form-row,
  .option-grid,
  .split {
    grid-template-columns: 1fr;
  }

  .menu-panel {
    max-width: calc(100vw - 32px);
  }
}

/* ---------- 查詢方式切換（Restful查詢／PostgreSQL查詢） ---------- */
.switch {
  display: inline-flex;
  min-inline-size: 0;
  margin: 0;
  padding: 3px;
  border: var(--border-width) solid var(--line-strong);
  border-radius: 999px;
  background: var(--surface);
}

.switch-item {
  position: relative;
  display: inline-flex;
  align-items: center;
  padding: 6px 16px;
  border-radius: 999px;
  color: var(--ink);
  font-size: 0.875rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}

.switch-item:hover {
  background: var(--page);
  text-decoration: none;
}

.switch-item input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.switch-item.is-on,
.switch-item:has(input:checked) {
  background: var(--accent);
  color: var(--on-accent);
  cursor: default;
}

.switch-item:has(input:focus-visible) {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.switch-item.is-off,
.switch-item.is-off:hover {
  background: transparent;
  color: var(--muted);
  opacity: 0.6;
  cursor: not-allowed;
}

/* ---------- 資料總覽 ---------- */
.stat-value-text {
  font-size: 1.125rem;
  line-height: 1.95;
}

.toolbar-title {
  align-self: center;
  margin: 0 auto 0 0;
  font-size: 1.0625rem;
}

/* 標題後面跟著的標籤（例如資源清單目前看的是哪一類） */
.toolbar-title .chip {
  margin-left: 10px;
  vertical-align: 2px;
}

.card-table > .empty h2 {
  margin: 0 0 6px;
  color: var(--ink);
  font-size: 1.0625rem;
}

.card-table > .empty p {
  margin: 0;
}

/* ---------- 條件篩選 ---------- */
.split-main {
  grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr);
}

.section-title-first {
  margin-top: 0;
}

.form-row-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

/* 代碼條件：最多兩欄，落單的最後一格佔整排。每一欄至少 15rem（跟著字級放大），放不下兩欄就自動變一欄，
   提示文字才不會斷行、留一個字在下一行。50% - 8px 是扣掉 16px 欄距後的一半，用來限制最多兩欄。 */
.form-row-codes {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, max(15rem, calc(50% - 8px))), 1fr));
}

.form-row-codes > :last-child:nth-child(odd) {
  grid-column: 1 / -1;
}

.label-note {
  margin-left: 8px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.75rem;
  font-weight: 400;
}

.result-label {
  margin: 0;
  color: var(--muted);
  font-size: 0.875rem;
}

.result-value {
  margin: 2px 0 12px;
  color: var(--accent-strong);
  font-size: 3rem;
  font-weight: 700;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.result-meter {
  display: block;
  width: 100%;
  height: 0.7rem;
}

.result-sub {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.9375rem;
}

.result-foot {
  margin: 20px 0 0;
  padding-top: 12px;
  border-top: var(--border-width) solid var(--line);
  color: var(--muted);
  font-size: 0.8125rem;
}

.result > .empty {
  padding: 56px 12px;
}

.result > .empty h2 {
  margin: 0 0 6px;
  font-size: 1.0625rem;
}

.result > .empty p {
  margin: 0;
}

.breakdown {
  display: grid;
  gap: 16px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.breakdown-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.breakdown-count {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.breakdown-what {
  max-height: 4.6rem;
  margin: 2px 0 6px;
  overflow: auto;
  color: var(--muted);
  font-size: 0.875rem;
}

.breakdown meter {
  display: block;
  width: 100%;
  height: 0.45rem;
}

/* 訊息自己寫了開頭（例如「驗證通過：」）時，不再加預設的開頭 */
.notice-plain::before,
p.notice-plain::before {
  content: none;
}

.notice-success.notice-plain strong {
  color: var(--ok);
}

.notice-error.notice-plain strong {
  color: var(--danger);
}

/* ---------- 等待提示（由 static/js/app.js 在送出查詢時加上） ---------- */
.busy {
  position: fixed;
  inset: 0 0 auto;
  z-index: 100;
  pointer-events: none;
}

.busy::before {
  content: "";
  display: block;
  height: 4px;
  background-color: var(--accent-soft);
  background-image: linear-gradient(90deg, transparent, var(--accent), transparent);
  background-repeat: no-repeat;
  background-size: 40% 100%;
  animation: busy-slide 1.3s linear infinite;
}

.busy-text {
  position: absolute;
  top: 16px;
  left: 50%;
  padding: 7px 18px;
  transform: translateX(-50%);
  border-radius: 999px;
  background: var(--ink);
  color: var(--surface);
  font-size: 0.875rem;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: var(--shadow-pop);
}

html.is-busy,
html.is-busy a,
html.is-busy button {
  cursor: progress;
}

@keyframes busy-slide {
  from {
    background-position: -67% 0;
  }

  to {
    background-position: 167% 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .busy::before {
    background-image: none;
    background-color: var(--accent);
    animation: none;
  }
}

@media (max-width: 1150px) {
  .split-main {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 900px) {
  .form-row-3 {
    grid-template-columns: 1fr;
  }
}

.button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* ---------- 條件篩選：疾病碼提示與計算進度 ---------- */
.code-field {
  margin-top: 16px;
}

.combo {
  position: relative;
  margin-bottom: 8px;
}

.combo[hidden],
.combo-list[hidden] {
  display: none;
}

.combo input {
  width: 100%;
}

.combo-list {
  position: absolute;
  z-index: 30;
  top: calc(100% + 4px);
  right: 0;
  left: 0;
  max-height: 21rem;
  margin: 0;
  padding: 4px;
  overflow: auto;
  list-style: none;
  background: var(--surface);
  border: var(--border-width) solid var(--line-strong);
  border-radius: var(--radius-small);
  box-shadow: var(--shadow-pop);
}

.combo-option {
  display: grid;
  grid-template-columns: 6.5em minmax(0, 1fr) auto;
  gap: 12px;
  align-items: baseline;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
}

.combo-option:hover,
.combo-option.is-active {
  background: var(--accent-soft);
  box-shadow: inset 3px 0 0 var(--accent);
}

.combo-code {
  font-family: var(--mono);
  font-weight: 700;
}

.combo-count {
  color: var(--muted);
  font-size: 0.8125rem;
  white-space: nowrap;
}

.combo-empty {
  padding: 10px;
  color: var(--muted);
}

.progress {
  height: 6px;
  margin: 14px 0 12px;
  border-radius: 999px;
  background-color: var(--accent-soft);
  background-image: linear-gradient(90deg, transparent, var(--accent), transparent);
  background-repeat: no-repeat;
  background-size: 40% 100%;
  animation: busy-slide 1.3s linear infinite;
}

.result-progress {
  min-height: 3em;
  margin: 0 0 16px;
  font-size: 0.9375rem;
}

@media (prefers-reduced-motion: reduce) {
  .progress {
    background-image: none;
    background-color: var(--accent);
    animation: none;
  }
}

.result-list {
  max-height: 22rem;
  overflow: auto;
  border: var(--border-width) solid var(--line);
  border-radius: var(--radius-small);
}

.result-list thead th {
  position: sticky;
  top: 0;
  background: var(--surface);
}

/* 標題區：說明文字再長也不把右邊的按鈕擠到下一行 */
.page-head > div:first-child {
  flex: 1 1 24rem;
  min-width: 0;
}

.page-sub {
  max-width: 62rem;
}

.result-list th,
.result-list td {
  padding: 8px 12px;
}

.result-list code {
  font-size: 0.78rem;
  white-space: nowrap;
}

/* 條件篩選結果下面的「查詢語法」：預設收合，展開後可捲動 */
.result-query {
  margin-top: 20px;
  padding: 14px 20px;
}

.result-query summary {
  color: var(--muted);
  font-size: 0.875rem;
  cursor: pointer;
}

.result-query .code-block {
  max-height: 28rem;
  margin-top: 12px;
  padding: 12px 14px;
  border: var(--border-width) solid var(--line);
  border-radius: var(--radius-small);
  background: var(--page);
  font-size: 0.75rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* 標題上有對照資訊（滑鼠停留時顯示 FHIR 路徑） */
.path-hint {
  cursor: help;
  text-decoration: underline dotted var(--line-strong, currentColor);
  text-underline-offset: 4px;
}

/* ---------- 出庫與去識別化 ---------- */
.check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 400;
  cursor: pointer;
}

.check input {
  flex: none;
}

.check-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
  gap: 10px 20px;
  margin: 12px 0 4px;
}

.check-grid .muted {
  margin-left: auto;
  font-size: 0.8125rem;
  font-variant-numeric: tabular-nums;
}

.choice-list {
  display: grid;
  gap: 10px;
}

.choice {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 14px;
  border: var(--border-width) solid var(--line);
  border-radius: var(--radius-small);
  font-weight: 400;
  cursor: pointer;
}

.choice:has(input:checked) {
  border-color: var(--accent, var(--line-strong));
  background: var(--page);
}

.choice input {
  flex: none;
  margin-top: 4px;
}

.choice-body {
  display: grid;
  gap: 4px;
}

.rule-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.8125rem;
}

.rule-list b {
  margin-right: 6px;
  color: var(--text, inherit);
  font-weight: 600;
}

.file-list {
  display: grid;
  gap: 12px;
}

.file-item {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px 20px;
  padding: 14px 16px;
  border: var(--border-width) solid var(--line);
  border-radius: var(--radius-small);
}

.file-item > div:first-child {
  flex: 1 1 22rem;
  min-width: 0;
}

.file-item h3 {
  margin: 0 0 4px;
  font-size: 1rem;
}

.file-item p {
  margin: 2px 0 0;
}

.file-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.hash {
  font-size: 0.75rem;
  overflow-wrap: anywhere;
}

.progress-text {
  display: block;
  margin-top: 4px;
  font-size: 0.8125rem;
}

.result-actions {
  margin: 16px 0 0;
}

.file-list + .form-actions {
  margin-top: 16px;
}

.cell-date {
  color: var(--muted);
  font-size: 0.8125rem;
  font-variant-numeric: tabular-nums;
}

.form label.choice {
  display: flex;
  margin: 0;
  font-weight: 400;
}

.form label.choice:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.check-grid label.check .muted {
  font-weight: 400;
}

/* ---------- 計畫申請與 IRB 審查 ---------- */
.range {
  display: flex;
  align-items: center;
  gap: 8px;
}

.range input {
  flex: 1 1 0;
  min-width: 0;
}

.range span {
  color: var(--muted);
  font-size: 0.875rem;
}

.stack {
  display: grid;
  gap: 20px;
}

.prose {
  white-space: pre-line;
}

/* 閒置登出的提醒（session.js）：快到時間時貼在畫面上方的一條；已經登出時蓋住整頁的提示 */
.session-bar {
  position: fixed;
  top: 12px;
  left: 50%;
  z-index: 60;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px 16px;
  width: max-content;
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border: var(--border-width) solid var(--warn);
  border-radius: var(--radius);
  background: var(--warn-soft);
  color: var(--ink);
  box-shadow: 0 8px 24px rgb(0 0 0 / 18%);
  transform: translateX(-50%);
}

.session-dialog {
  width: min(30rem, calc(100vw - 32px));
  padding: 24px;
  border: var(--border-width) solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 16px 48px rgb(0 0 0 / 30%);
}

.session-dialog::backdrop {
  background: rgb(15 23 42 / 55%);
}

.session-dialog h2 {
  margin: 0 0 10px;
}

.session-dialog p {
  margin: 0 0 12px;
}

.session-dialog-note {
  min-height: 1.5em;
  color: var(--danger);
  font-weight: 600;
}

.flashes:empty {
  display: none;
}

/* 回到原來捲到的位置時（app.js 的 data-keep-scroll），提示訊息跟著畫面停在上方 */
.flashes.is-following {
  position: sticky;
  top: 72px;
  z-index: 9;
}

.flashes.is-following .notice {
  box-shadow: var(--shadow-pop);
}

/* 進度軸：一條橫的軸線。走過的打勾、現在這一步反白、還沒到的只有號碼；
   婉拒或沒有資料而結束的那一步打叉，後面不需要做的用虛線。狀態另外都有文字，不只靠顏色。 */
.track-card {
  padding: 20px 24px;
}

.track-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  margin-bottom: 22px;
}

.track-id {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 14px;
  margin: 0;
}

.track-id strong {
  font-size: 1.0625rem;
}

.track-id span {
  color: var(--muted);
  font-size: 0.875rem;
}

.track-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.track {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: track;
}

.track-step {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 0 10px;
  text-align: center;
  counter-increment: track;
}

/* 和前一步之間的連線：走到這一步了就上色 */
.track-step::before {
  content: "";
  position: absolute;
  top: 15px;
  right: 50%;
  width: 100%;
  height: 4px;
  background: var(--line);
}

.track-step:first-child::before {
  display: none;
}

.track-step.is-done::before,
.track-step.is-now::before,
.track-step.is-alert::before,
.track-step.is-stop::before {
  background: var(--ok);
}

.track-mark {
  position: relative;
  z-index: 1; /* 蓋在下一步畫過來的連線上面 */
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 2px solid var(--line-strong);
  border-radius: 50%;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.875rem;
  font-weight: 700;
  line-height: 1;
}

.track-mark::before {
  content: counter(track);
}

.track-step.is-done .track-mark {
  border-color: var(--ok);
  background: var(--ok);
  color: var(--on-accent);
}

.track-step.is-done .track-mark::before {
  content: "\2713";
}

.track-step.is-now .track-mark {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--on-accent);
  box-shadow: 0 0 0 5px var(--accent-soft);
}

.track-step.is-alert .track-mark {
  border-color: var(--warn);
  background: var(--warn);
  color: var(--on-accent);
  box-shadow: 0 0 0 5px var(--warn-soft);
}

.track-step.is-alert .track-mark::before {
  content: "!";
}

.track-step.is-stop .track-mark {
  border-color: var(--muted);
  background: var(--muted);
  color: var(--on-accent);
}

.track-step.is-stop .track-mark::before {
  content: "\2715";
}

.track-step.is-skip .track-mark {
  border-style: dashed;
}

.track-step.is-skip .track-mark::before {
  content: "\2013";
}

.track-name {
  margin-top: 8px;
  font-weight: 700;
}

.track-name a {
  color: inherit;
}

.track-step.is-now .track-name {
  color: var(--accent-strong);
}

.track-step.is-alert .track-name {
  color: var(--warn);
}

.track-step.is-todo .track-name,
.track-step.is-skip .track-name {
  color: var(--muted);
  font-weight: 600;
}

.track-text {
  color: var(--muted);
  font-size: 0.8125rem;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.track-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 20px;
  margin-top: 22px;
  padding-top: 16px;
  border-top: var(--border-width) solid var(--line);
}

.track-foot .form-actions {
  margin: 0;
}

.track-next {
  flex: 1 1 18rem;
  margin: 0;
}

.track-next strong {
  display: inline-block;
  margin-right: 12px;
  padding: 1px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 0.8125rem;
}

.track-next.is-final strong {
  background: var(--page);
  color: var(--ink);
  border: var(--border-width) solid var(--line-strong);
}

html[data-theme="contrast"] .track-next strong {
  border: var(--border-width) solid currentColor;
}

@media (max-width: 760px) {
  .track {
    grid-auto-flow: row;
    gap: 14px;
  }

  .track-step {
    display: grid;
    grid-template-columns: 34px minmax(0, 1fr);
    gap: 0 12px;
    align-items: start;
    padding: 0;
    text-align: left;
  }

  .track-step::before {
    display: none;
  }

  .track-mark {
    grid-row: span 2;
  }

  .track-name {
    margin-top: 4px;
  }
}

/* 進度軸下面需要填寫的操作（審核意見、要不要提供資料）：整個寬度，輸入框夠大 */
.card-act {
  border-left: 4px solid var(--accent);
}

.card-act h2 {
  margin-bottom: 14px;
}

.card-act .form textarea {
  min-height: 7rem;
}

.card-act > summary {
  font-weight: 700;
  cursor: pointer;
}

.card-act > summary + .form {
  margin-top: 16px;
}

/* 兩張一樣寬、一樣高的卡片並排；窄螢幕時上下排 */
.split-even {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: stretch;
}

.form-row-4 {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

@media (max-width: 1150px) {
  .form-row-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 900px) {
  .split-even,
  .form-row-4 {
    grid-template-columns: 1fr;
  }

  .split-even {
    gap: 0; /* 上下排時卡片自己的下邊距就夠了 */
  }
}

.irb-items td {
  vertical-align: top;
}

.irb-items td:first-child strong {
  margin-right: 6px;
}

.irb-file {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 10px;
}

.irb-file + .irb-file {
  margin-top: 6px;
}

.irb-file a {
  overflow-wrap: anywhere;
}

.irb-file .muted {
  font-size: 0.8125rem;
}

.irb-upload {
  display: flex;
  align-items: center;
  gap: 8px;
}

.irb-upload input[type="file"] {
  max-width: 13rem;
  font-size: 0.8125rem;
}

nav.toolbar {
  align-items: center;
}

/* 資源總覽的筆數表：橫跨整個寬度，占比的長條跟著變寬 */
.table-counts {
  width: 100%;
}

.table-counts th:first-child {
  width: 30%;
}

.table-counts .cell-date,
.table-counts .num {
  white-space: nowrap;
}

.table-counts .cell-meter meter {
  width: min(22rem, 60%);
}

/* ---------- 節點：圖示、燈號、連線光束 ----------
   燈號的顏色由 look-* 決定（連線中、失聯、等待、失敗、沒有）；狀態一律另外有文字。 */
.look-online {
  --look: var(--ok);
}

.look-offline {
  --look: var(--warn);
}

.look-waiting {
  --look: var(--accent);
}

.look-failed {
  --look: var(--danger);
}

.look-unbound,
.look-disabled {
  --look: var(--line-strong);
}

.node-art {
  position: relative;
  display: inline-grid;
  flex: none;
  place-items: center;
  width: 56px;
  height: 56px;
  border: var(--border-width) solid var(--line);
  border-radius: 16px;
  background: linear-gradient(145deg, var(--accent-soft), var(--surface));
  color: var(--accent-strong);
}

.node-art svg {
  width: 62%;
  height: 62%;
}

.node-art .chassis {
  fill: var(--surface);
  stroke: currentColor;
  stroke-width: 1.7;
}

.node-art .vent {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  opacity: 0.4;
}

.node-art .led {
  fill: var(--look, currentColor);
}

/* 角落的連線燈號 */
.node-art::after {
  content: "";
  position: absolute;
  right: -4px;
  bottom: -4px;
  width: 13px;
  height: 13px;
  border: 3px solid var(--surface);
  border-radius: 50%;
  background: var(--look, var(--line-strong));
}

.node-art-plain::after {
  display: none;
}

.node-art.look-online::after {
  animation: node-pulse 2.4s ease-out infinite;
}

@keyframes node-pulse {
  0% {
    box-shadow: 0 0 0 0 color-mix(in srgb, var(--ok) 55%, transparent);
  }

  70%,
  100% {
    box-shadow: 0 0 0 9px transparent;
  }
}

.node-art-self {
  border-color: transparent;
  background: linear-gradient(145deg, var(--brand), var(--brand-2));
  color: var(--brand-ink);
}

.node-art-parent {
  border-color: transparent;
  background: linear-gradient(145deg, var(--accent), var(--accent-strong));
  color: var(--on-accent);
}

.node-art-self .chassis,
.node-art-parent .chassis {
  fill: rgb(255 255 255 / 14%);
}

.node-art-self .vent,
.node-art-parent .vent {
  opacity: 0.6;
}

/* 還沒有的那一端：虛線的空位 */
.node-art-ghost {
  border: 2px dashed var(--line-strong);
  background: transparent;
  color: var(--muted);
}

.node-art-ghost .chassis {
  fill: none;
}

.node-art-small {
  width: 36px;
  height: 36px;
  border-radius: 10px;
}

.node-art-small::after {
  right: -3px;
  bottom: -3px;
  width: 9px;
  height: 9px;
  border-width: 2px;
}

.node-art-large {
  width: 72px;
  height: 72px;
  border-radius: 20px;
}

.node-art-large::after {
  width: 15px;
  height: 15px;
}

.signal {
  display: inline-flex;
  flex: none;
  align-items: center;
  gap: 7px;
  padding: 2px 11px 2px 9px;
  border: var(--border-width) solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
}

.signal::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--look, var(--line-strong));
}

.signal.look-online::before {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 22%, transparent);
}

.beam {
  position: relative;
  display: block;
  width: 100%;
  height: 14px;
}

.beam::before {
  content: "";
  position: absolute;
  top: 6px;
  right: 9px;
  left: 0;
  height: 2px;
  background: repeating-linear-gradient(90deg, var(--look, var(--line-strong)) 0 7px, transparent 7px 13px);
}

.beam.look-online::before {
  background: var(--look);
  opacity: 0.45;
}

.beam::after {
  content: "";
  position: absolute;
  top: 1px;
  right: 0;
  border: 6px solid transparent;
  border-right: 0;
  border-left: 10px solid var(--look, var(--line-strong));
}

.beam span {
  position: absolute;
  top: 3px;
  left: 0;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--look);
  opacity: 0;
}

.beam.look-online span {
  animation: beam-travel 2.4s linear infinite;
}

.beam.look-online span:nth-child(2) {
  animation-delay: 0.8s;
}

.beam.look-online span:nth-child(3) {
  animation-delay: 1.6s;
}

@keyframes beam-travel {
  0% {
    left: 0;
    opacity: 0;
  }

  12%,
  88% {
    opacity: 1;
  }

  100% {
    left: calc(100% - 20px);
    opacity: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .node-art.look-online::after,
  .beam.look-online span {
    animation: none;
  }

  .beam.look-online span:nth-child(2) {
    left: 45%;
    opacity: 1;
  }
}

/* ---------- 子節點管理：上方總覽＋一家一張卡 ---------- */
.fleet-hero {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 20px 32px;
  margin-bottom: 20px;
  padding: 22px 28px;
  border-radius: var(--radius);
  background: linear-gradient(120deg, var(--brand) 0%, var(--brand-2) 120%);
  color: var(--brand-ink);
  box-shadow: var(--shadow);
}

.fleet-hero-self {
  display: flex;
  align-items: center;
  gap: 16px;
}

.fleet-hero .node-art-self {
  border-color: rgb(255 255 255 / 30%);
  background: rgb(255 255 255 / 12%);
}

.fleet-hero-kicker {
  display: block;
  color: var(--brand-muted);
  font-size: 0.8125rem;
  letter-spacing: 0.08em;
}

.fleet-hero-title {
  font-size: 1.375rem;
  line-height: 1.35;
}

.fleet-hero-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 0;
}

.fleet-hero-stats div {
  min-width: 6.25rem;
  padding: 9px 16px;
  border: var(--border-width) solid rgb(255 255 255 / 18%);
  border-radius: 10px;
  background: rgb(255 255 255 / 9%);
}

.fleet-hero-stats dt {
  color: var(--brand-muted);
  font-size: 0.8125rem;
}

.fleet-hero-stats dd {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.3;
  font-variant-numeric: tabular-nums;
}

.fleet {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(19.5rem, 1fr));
  gap: 16px;
  margin: 0 0 20px;
  padding: 0;
  list-style: none;
}

.unit,
.unit-profile {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow: hidden;
}

.unit {
  padding: 22px 20px 16px;
  border: var(--border-width) solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

/* 卡片頂端的色條跟燈號同色 */
.unit::before,
.unit-profile::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 4px;
  background: var(--look, var(--line-strong));
}

.unit-head {
  display: flex;
  align-items: center;
  gap: 14px;
}

.unit-name {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
}

.unit-name strong {
  font-size: 1.0625rem;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

/* 主機名稱很長時不折行，完整名稱在提示裡 */
.unit-name .unit-host {
  overflow: hidden;
  overflow-wrap: normal;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.unit-code {
  color: var(--muted);
  font-size: 0.8125rem;
}

.unit .unit-code {
  font-family: var(--mono);
}

.unit-facts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 0;
}

.unit-facts-wide {
  grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
}

.unit-facts div {
  padding: 9px 12px;
  border: var(--border-width) solid transparent;
  border-radius: var(--radius-small);
  background: var(--page);
}

html[data-theme="contrast"] .unit-facts div {
  border-color: var(--line);
}

.unit-facts dt {
  color: var(--muted);
  font-size: 0.78rem;
}

.unit-facts dd {
  margin: 0;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.unit-blank {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 18px 16px;
  border: var(--border-width) dashed var(--line-strong);
  border-radius: var(--radius-small);
  color: var(--muted);
  font-size: 0.875rem;
}

.unit-blank strong {
  color: var(--ink);
  font-size: 0.9375rem;
}

.unit-lines {
  display: grid;
  gap: 4px;
  margin: 0;
  font-size: 0.875rem;
}

.unit-lines div {
  display: grid;
  grid-template-columns: 4.5em minmax(0, 1fr);
  gap: 14px;
}

/* 標題比較長的卡片（母節點管理） */
.unit-lines-wide div {
  grid-template-columns: 9.5em minmax(0, 1fr);
}

.unit-lines dt {
  color: var(--muted);
}

.unit-lines dd {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 14px;
  margin: 0;
}

.stat-note {
  color: var(--muted);
  font-size: 0.8125rem;
}

.state {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.state::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--line-strong);
}

.state-ok::before {
  background: var(--ok);
}

.state-bad::before {
  background: var(--danger);
}

.state-unknown::before {
  background: var(--accent);
}

.unit-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: auto;
  padding-top: 14px;
  border-top: var(--border-width) solid var(--line);
}

.unit-foot form {
  margin: 0;
}

.unit.look-disabled {
  background: var(--page);
  box-shadow: none;
}

.unit.look-disabled .unit-name strong {
  color: var(--muted);
}

.unit.look-disabled .node-art::after {
  border-color: var(--page);
}

.unit.look-disabled .unit-facts div {
  background: var(--surface);
}

.fleet-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 48px 24px;
  text-align: center;
}

.fleet-empty h2 {
  margin: 10px 0 0;
}

.fleet-empty p {
  max-width: 34rem;
  margin: 0 0 8px;
  color: var(--muted);
}

/* ---------- 母節點管理：本院 → 母節點 ---------- */
.uplink {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(12rem, 1.3fr) minmax(0, 1fr);
  align-items: center;
  gap: 12px 28px;
  margin-bottom: 20px;
  padding: 30px 28px;
  border: var(--border-width) solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(180deg, var(--accent-soft), var(--surface) 75%);
  box-shadow: var(--shadow);
}

.uplink-node,
.uplink-beam {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
  text-align: center;
}

.uplink-node {
  gap: 2px;
}

.uplink-node .node-art {
  margin-bottom: 10px;
}

.uplink-beam {
  gap: 10px;
}

.uplink-kicker {
  color: var(--muted);
  font-size: 0.8125rem;
  letter-spacing: 0.08em;
}

.uplink-node strong {
  max-width: 100%;
  font-size: 1.125rem;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.uplink-note {
  color: var(--muted);
  font-size: 0.875rem;
}

.uplink-unset .uplink-node:last-child strong {
  color: var(--muted);
  font-weight: 500;
}

/* ---------- 工作台：本院的節點身分 ---------- */
.node-overview {
  margin-top: 20px;
}

.node-overview-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 12px;
}

.node-overview-head .section-title {
  margin: 0;
}

.node-duo {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.node-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
  padding: 18px 22px 20px;
  border: var(--border-width) solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.node-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.node-kicker {
  color: var(--muted);
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.08em;
}

.node-more {
  font-size: 0.875rem;
  font-weight: 600;
}

.node-more::after {
  content: " \2192";
}

.node-big {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 2px 12px;
  margin: 0;
}

.node-big strong {
  font-size: 1.5rem;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.node-big span {
  color: var(--muted);
  font-size: 0.9375rem;
}

.node-dots {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin: 2px 0;
  padding: 0;
  list-style: none;
}

.node-dots li {
  display: flex;
}

.node-dots-more {
  color: var(--muted);
  font-size: 0.875rem;
}

.node-none {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* 工作台：本院的母節點，一家一列 */
.node-uplinks {
  display: grid;
  gap: 8px;
  margin: 2px 0;
  padding: 0;
  list-style: none;
}

.node-uplinks li {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.node-uplink-host {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.node-mini-link {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 2px 0;
}

.node-mini-link .beam {
  flex: 1;
  max-width: 11rem;
}

.node-meaning {
  margin: 0;
  color: var(--muted);
  font-size: 0.9375rem;
}

.node-alone {
  margin-top: 12px;
}

.node-empty {
  border-style: dashed;
  background: transparent;
  box-shadow: none;
}

.node-empty .node-big strong {
  color: var(--muted);
  font-weight: 500;
}

@media (max-width: 900px) {
  .node-duo,
  .uplink {
    grid-template-columns: minmax(0, 1fr);
  }

  .uplink .beam {
    display: none;
  }

  .uplink-beam .uplink-note::after {
    content: " \2193";
  }
}

/* 交付進度條、表格上方帶按鈕的標題列 */
.transfer-bar {
  display: block;
  width: 100%;
  height: 10px;
  accent-color: var(--accent);
}

.section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

/* 區塊標題底下的一行說明（例如「下載全部」與「合併下載」差在哪裡） */
.section-note {
  margin: 0 0 12px;
  font-size: 0.875rem;
}

/* 卡片的標題列：標題在左，右邊可以放切換（例如下載格式） */
.card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
  margin-bottom: 12px;
}

.card-head h2 {
  margin: 0;
}

/* 放在標題列、按鈕旁邊的切換：小一號，和小按鈕一樣高 */
.card-head .switch-item,
.section-head .switch-item {
  padding: 2px 12px;
  font-size: 0.8125rem;
}

/* 表格列裡需要多填一欄才能送出的動作：按了才在同一格展開 */
.row-more {
  display: inline-block;
  margin-left: 12px;
  text-align: left;
  vertical-align: top;
  white-space: normal;
}

.row-more > summary {
  list-style: none;
  cursor: pointer;
}

.row-more > summary::-webkit-details-marker {
  display: none;
}

.row-more > form {
  display: block;
  width: 260px;
  margin: 10px 0 4px;
}

.row-more > form input[type="text"] {
  width: 100%;
  margin-bottom: 8px;
}

/* 稽核紀錄：冷儲存的月份清單（預設收合） */
.cold > summary {
  padding: 14px 20px;
  color: var(--accent-strong);
  font-weight: 600;
  cursor: pointer;
}

.cold[open] > summary {
  border-bottom: var(--border-width) solid var(--line);
}

/* ---------- 資料品質儀表板 ---------- */
.tag-danger,
.dq-tag-poor,
.dq-tag-failed {
  background: var(--danger-soft);
  color: var(--danger);
}

.dq-tag-good {
  background: var(--ok-soft);
  color: var(--ok);
}

.dq-tag-fair {
  background: var(--warn-soft);
  color: var(--warn);
}

.dq-tag-running {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

a.tag {
  text-decoration: none;
}

a.tag:hover,
a.tag:focus-visible {
  text-decoration: underline;
}

.dq-pick {
  display: flex;
  align-items: center;
  gap: 8px;
}

.dq-pick label {
  margin: 0;
  color: var(--muted);
  font-size: 0.875rem;
  white-space: nowrap;
}

.dq-pick select {
  width: auto;
  min-width: 12rem;
}

.dq-hero {
  justify-content: flex-start;
}

.dq-hero .fleet-hero-stats {
  margin-left: auto;
}

.dq-hero .fleet-hero-stats small {
  margin-left: 2px;
  color: var(--brand-muted);
  font-size: 0.8125rem;
  font-weight: 400;
}

.dq-hero-main {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.dq-hero-main .fleet-hero-title {
  font-size: 1.5rem;
}

.dq-hero-sub {
  color: var(--brand-muted);
  font-size: 0.8125rem;
}

/* 總分：外圈是比例（100 分一圈），中間是數字 */
.dq-score {
  position: relative;
  flex: none;
  width: 8.75rem;
  height: 8.75rem;
}

.dq-ring {
  display: block;
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.dq-ring circle {
  fill: none;
  stroke-width: 9;
}

.dq-ring-track {
  stroke: rgb(255 255 255 / 18%);
}

.dq-ring-value {
  stroke: var(--brand-ink);
  stroke-linecap: round;
}

.dq-good .dq-ring-value {
  stroke: var(--dq-good);
}

.dq-fair .dq-ring-value {
  stroke: var(--dq-fair);
}

.dq-poor .dq-ring-value {
  stroke: var(--dq-poor);
}

.dq-score-text {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  margin: 0;
  line-height: 1;
}

.dq-score-text strong {
  font-size: 2.375rem;
  font-weight: 700;
}

.dq-score-text span {
  align-self: flex-end;
  margin-bottom: 3.35rem;
  color: var(--brand-muted);
  font-size: 0.875rem;
}

/* 三個面向 */
.dq-dims {
  grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
}

.dq-dim {
  gap: 6px;
}

.dq-dim .stat-label {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 2px 8px;
  color: var(--ink);
  font-size: 0.9375rem;
  font-weight: 600;
}

.dq-hint {
  color: var(--muted);
  font-size: 0.8125rem;
  font-weight: 400;
}

.dq-dim .stat-value small {
  margin-left: 2px;
  color: var(--muted);
  font-size: 1rem;
  font-weight: 600;
}

.dq-note {
  color: var(--muted);
  font-size: 0.8125rem;
}

/* 比率條：高於 90 是好的、70 到 90 普通、低於 70 需留意（顏色之外旁邊一定有數字） */
.dq-meter {
  display: block;
  width: 100%;
  height: 0.5rem;
}

.dq-meter::-webkit-meter-bar {
  height: 0.5rem;
  border: 0;
  border-radius: 999px;
  background: var(--dq-track);
}

.dq-meter::-moz-meter-bar {
  border-radius: 999px;
}

html[data-theme="contrast"] .dq-meter {
  height: 0.625rem;
  border: 1px solid var(--ink);
  border-radius: 999px;
  background: var(--dq-track);
}

html[data-theme="contrast"] .dq-meter::-webkit-meter-bar {
  height: 0.5rem;
}

.dq-meter::-webkit-meter-optimum-value,
.dq-meter::-webkit-meter-suboptimum-value,
.dq-meter::-webkit-meter-even-less-good-value {
  border-radius: 999px;
}

.dq-meter::-webkit-meter-optimum-value {
  background: var(--ok);
}

.dq-meter::-webkit-meter-suboptimum-value {
  background: var(--warn);
}

.dq-meter::-webkit-meter-even-less-good-value {
  background: var(--danger);
}

.dq-meter::-moz-meter-bar {
  border-radius: 999px;
  background: var(--ok);
}

.dq-meter:-moz-meter-sub-optimum::-moz-meter-bar {
  background: var(--warn);
}

.dq-meter:-moz-meter-sub-sub-optimum::-moz-meter-bar {
  background: var(--danger);
}

.dq-meter-bad::-webkit-meter-optimum-value {
  background: var(--danger);
}

.dq-meter-bad::-moz-meter-bar {
  background: var(--danger);
}

.cell-meter .dq-meter {
  display: inline-block;
  width: 7rem;
}

/* 欄位完整度：一類資源一張卡，一個欄位一列 */
.dq-fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(24rem, 100%), 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.dq-field-card {
  margin: 0;
  padding: 18px 22px;
}

.dq-field-card h3 {
  margin: 0 0 12px;
  font-size: 1rem;
}

.dq-field-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.dq-field-list li {
  display: grid;
  grid-template-columns: minmax(7rem, 12rem) minmax(3rem, 1fr) 3.75rem;
  align-items: center;
  gap: 12px;
  font-size: 0.9375rem;
}

.dq-field-rate {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.dq-must {
  margin-left: 6px;
  padding: 0 6px;
  border: var(--border-width) solid var(--line-strong);
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.6875rem;
  white-space: nowrap;
}

.dq-foot {
  font-size: 0.8125rem;
}

@media (max-width: 720px) {
  .dq-hero .fleet-hero-stats {
    margin-left: 0;
  }

  .dq-pick {
    flex-wrap: wrap;
  }
}

/* ---------- 資料集說明（資源總覽下方，橫跨整個寬度）：FHIR 功能聲明整理成一張表 ----------
   每一列整列可以點開；點開後的欄位清單用整個卡片的寬度。欄位位置用 --dataset-first 和表頭對齊。 */
.dataset-facts {
  padding: 16px 20px;
  border-bottom: var(--border-width) solid var(--line);
}


.table-dataset {
  --dataset-first: 40%;
  width: 100%;
}

.table-dataset .dataset-head {
  width: var(--dataset-first);
}

.table-dataset td {
  padding: 0;
}

.dataset-line {
  display: grid;
  grid-template-columns: var(--dataset-first) minmax(0, 1fr) auto;
  align-items: center;
  list-style: none;
}

.dataset-line::-webkit-details-marker {
  display: none;
}

.dataset-line > span {
  padding: 10px 20px;
}

.dataset-type span {
  display: block;
  color: var(--muted);
  font-size: 0.8125rem;
}

.dataset-count {
  font-variant-numeric: tabular-nums;
}

.fields > .dataset-line {
  cursor: pointer;
}

/* 展開的箭頭：收合時朝下，展開時朝上 */
.fields > .dataset-line::after {
  width: 7px;
  height: 7px;
  margin: 0 22px 4px 0;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  content: "";
  transform: rotate(45deg);
}

.fields[open] > .dataset-line::after {
  margin-bottom: -4px;
  transform: rotate(-135deg);
}

.fields-groups {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 8px 14px;
  margin: 0;
  padding: 2px 20px 16px;
}

.fields-groups dt {
  padding-top: 2px;
  color: var(--muted);
  font-size: 0.8125rem;
  white-space: nowrap;
}

.fields-groups dd {
  margin: 0;
}

.fields-profiles code {
  display: block;
  overflow-wrap: anywhere;
}

/* ---------- 高度有上限的卡片（資源總覽的筆數表） ----------
   列數多的時候在卡片裡捲動、表頭固定，下面的資料集說明才不會被推到很遠；列數少就照內容的高度。 */
.card-fixed {
  display: flex;
  flex-direction: column;
  max-height: 31rem;
}

.card-fixed > * {
  flex: none;
}

.card-fixed > .table-wrap {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
}

/* 表頭固定在卡片上緣；合併框線的表格捲動時框線不會跟著走，所以底線改用陰影畫 */
.card-fixed th {
  position: sticky;
  top: 0;
  z-index: 1;
  border-bottom: 0;
  box-shadow: inset 0 calc(-1 * var(--border-width)) 0 var(--line);
}

/* ---------- 一鍵複製（static/js/app.js）：值的右邊一個小圖示，複製後換成打勾 ---------- */
.kv-copy {
  align-items: center;
}

.kv-copy dd {
  display: flex;
  align-items: center;
  gap: 8px;
}

.copy-button {
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: var(--border-width) solid var(--line-strong);
  border-radius: var(--radius-small);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
}

.copy-button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.copy-button .icon {
  width: 1.05rem;
  height: 1.05rem;
}

.copy-button .icon + .icon,
.copy-button.is-copied .icon:first-child {
  display: none;
}

.copy-button.is-copied {
  border-color: var(--ok);
  color: var(--ok);
}

.copy-button.is-copied .icon + .icon {
  display: block;
}

/* 沒有剪貼簿介面時用來選取文字的暫時輸入框：放在畫面外 */
.copy-scratch {
  position: fixed;
  top: 0;
  left: -9999px;
  opacity: 0;
}
