/* =========================================================
   診所工作日誌 — 設計系統
   語意化色彩 token（淺色 / 深色）、8px 間距、行動優先
   ========================================================= */
:root {
  color-scheme: light dark;
  --bg: #f3f6f8;
  --surface: #ffffff;
  --surface-2: #f7f9fa;
  --surface-3: #eef2f4;
  --text: #0f172a;
  --text-2: #475569;
  --text-3: #64748b;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;

  --brand: #0f766e;
  --brand-hover: #115e59;
  --brand-soft: #e6f4f2;
  --brand-text: #0f766e;
  --on-brand: #ffffff;

  --blue: #1d4ed8;   --blue-soft: #eff6ff;
  --green: #15803d;  --green-soft: #f0fdf4;
  --rose: #be123c;   --rose-soft: #fff1f2;
  --amber: #b45309;  --amber-soft: #fffbeb;
  --danger: #b91c1c; --danger-soft: #fef2f2;

  --radius-sm: 10px;
  --radius: 14px;
  --radius-lg: 20px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .05);
  --shadow: 0 1px 3px rgba(15, 23, 42, .06), 0 4px 12px rgba(15, 23, 42, .05);
  --shadow-lg: 0 8px 30px rgba(15, 23, 42, .12);
  --ease: cubic-bezier(.2, .8, .2, 1);

  --topbar-h: 56px;
  --bottomnav-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

/* 深色：使用者手動選擇，或「跟隨系統」且系統為深色 */
:root[data-theme="dark"] {
  color-scheme: dark;
    --bg: #0b1215;
    --surface: #111b1f;
    --surface-2: #152227;
    --surface-3: #1b2a30;
    --text: #e6edf0;
    --text-2: #aebdc4;
    --text-3: #8b9ca4;
    --border: #22323a;
    --border-strong: #2e434c;

    --brand: #14b8a6;
    --brand-hover: #2dd4bf;
    --brand-soft: #0f2e2b;
    --brand-text: #5eead4;
    --on-brand: #042f2a;

    --blue: #93c5fd;   --blue-soft: #10203a;
    --green: #86efac;  --green-soft: #0e2618;
    --rose: #fda4af;   --rose-soft: #2c1119;
    --amber: #fcd34d;  --amber-soft: #2b1f08;
    --danger: #fca5a5; --danger-soft: #2c1212;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow: 0 1px 3px rgba(0, 0, 0, .35), 0 4px 12px rgba(0, 0, 0, .25);
    --shadow-lg: 0 8px 30px rgba(0, 0, 0, .5);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
      --bg: #0b1215;
      --surface: #111b1f;
      --surface-2: #152227;
      --surface-3: #1b2a30;
      --text: #e6edf0;
      --text-2: #aebdc4;
      --text-3: #8b9ca4;
      --border: #22323a;
      --border-strong: #2e434c;

      --brand: #14b8a6;
      --brand-hover: #2dd4bf;
      --brand-soft: #0f2e2b;
      --brand-text: #5eead4;
      --on-brand: #042f2a;

      --blue: #93c5fd;   --blue-soft: #10203a;
      --green: #86efac;  --green-soft: #0e2618;
      --rose: #fda4af;   --rose-soft: #2c1119;
      --amber: #fcd34d;  --amber-soft: #2b1f08;
      --danger: #fca5a5; --danger-soft: #2c1212;

      --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
      --shadow: 0 1px 3px rgba(0, 0, 0, .35), 0 4px 12px rgba(0, 0, 0, .25);
      --shadow-lg: 0 8px 30px rgba(0, 0, 0, .5);
  }
}
:root[data-theme="light"] { color-scheme: light; }

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: calc(var(--topbar-h) + 16px); }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(var(--bottomnav-h) + var(--safe-b) + 16px);
}
body.no-nav { padding-bottom: calc(var(--safe-b) + 16px); }
a { color: var(--brand-text); text-underline-offset: 3px; }
h1, h2, h3 { line-height: 1.3; margin: 0; letter-spacing: .01em; }
h1 { font-size: 1.375rem; font-weight: 700; }
h2 { font-size: 1.0625rem; font-weight: 700; }
h3 { font-size: 1rem; font-weight: 600; }
p { margin: 0 0 .75rem; }
.icon { flex-shrink: 0; vertical-align: middle; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--text-3); }
.small { font-size: .875rem; }
.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: .8125rem; word-break: break-all; }
.nowrap { white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
[hidden] { display: none !important; }
.desktop-only { display: none !important; }
@media (min-width: 1024px) { .desktop-only { display: inline-flex !important; } .mobile-only { display: none !important; } }

:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; border-radius: 6px; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  height: calc(var(--topbar-h) + env(safe-area-inset-top, 0px));
  padding: env(safe-area-inset-top, 0px) 16px 0;
  display: flex; align-items: center; gap: 12px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font-weight: 700; font-size: 1.0625rem; }
.brand-mark {
  display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 10px;
  background: linear-gradient(135deg, var(--brand), #0891b2); color: #fff;
}
.topbar-spacer { flex: 1; }
.avatar-link { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); border-radius: 999px; padding: 4px; }
.avatar-link .who { display: none; text-align: right; line-height: 1.25; }
.avatar-link .who small { display: block; color: var(--text-3); font-size: .75rem; }
.avatar {
  display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 50%;
  background: var(--brand-soft); color: var(--brand-text); font-weight: 700; font-size: .9375rem; flex-shrink: 0;
}
.avatar-lg { width: 64px; height: 64px; font-size: 1.5rem; }

/* ---------- Bottom nav (mobile) ---------- */
.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; justify-content: space-around;
  height: calc(var(--bottomnav-h) + var(--safe-b));
  padding: 6px 8px var(--safe-b);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-top: 1px solid var(--border);
}
.bottomnav a {
  position: relative; flex: 1; max-width: 96px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 48px; border-radius: 12px;
  color: var(--text-3); text-decoration: none; font-size: .75rem; font-weight: 600;
  transition: color .15s var(--ease);
}
.bottomnav a[aria-current="page"] { color: var(--brand-text); }
.bottomnav a[aria-current="page"] .icon { stroke-width: 2.4; }
.bottomnav .nav-add .icon-wrap {
  display: grid; place-items: center; width: 44px; height: 32px; border-radius: 12px;
  background: var(--brand); color: var(--on-brand); box-shadow: var(--shadow);
}
.bottomnav .nav-add { color: var(--brand-text); }
.badge-dot {
  position: absolute; top: 2px; left: calc(50% + 6px);
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px;
  background: var(--rose); color: #fff; font-size: .6875rem; line-height: 18px; text-align: center; font-weight: 700;
}
:root[data-theme="dark"] .badge-dot { color: #2c1119; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .badge-dot { color: #2c1119; } }

/* ---------- Layout ---------- */
.container { max-width: 880px; margin: 0 auto; padding: 16px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin: 4px 0 16px; }
.page-head p { margin: 4px 0 0; color: var(--text-3); font-size: .9375rem; }
.back-link { display: inline-flex; align-items: center; gap: 4px; min-height: 44px; color: var(--text-2); text-decoration: none; font-weight: 600; font-size: .9375rem; }
.back-link:hover { color: var(--text); }
.stack > * + * { margin-top: 12px; }
.section-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 24px 0 10px; }
.section-title h2 { font-size: 1rem; color: var(--text-2); }

/* ---------- Card ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow-sm);
}
.card + .card { margin-top: 12px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px; border-radius: 12px;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; font-size: .9375rem; text-decoration: none; cursor: pointer;
  transition: background .15s var(--ease), border-color .15s var(--ease), transform .1s var(--ease), box-shadow .15s var(--ease);
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { background: var(--surface-3); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .6; cursor: progress; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--on-brand); box-shadow: 0 1px 2px rgba(15, 118, 110, .3); }
.btn-primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); }
.btn-danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); background: var(--surface); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-3); color: var(--text); }
.btn-block { display: flex; width: 100%; }
.btn-lg { min-height: 52px; font-size: 1rem; border-radius: 14px; }
.btn-sm { min-height: 36px; padding: 0 12px; font-size: .875rem; border-radius: 10px; }
.linklike { background: none; border: 0; padding: 0; color: var(--brand-text); text-decoration: underline; cursor: pointer; font: inherit; }
form.inline { display: inline; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- Chips / badges ---------- */
.chip-row { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding: 2px; margin: 0 -2px; }
.chip-row::-webkit-scrollbar { display: none; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; flex-shrink: 0;
  min-height: 36px; padding: 0 14px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text-2);
  font-size: .875rem; font-weight: 600; text-decoration: none; white-space: nowrap;
  transition: background .15s var(--ease), color .15s var(--ease), border-color .15s var(--ease);
}
a.chip:hover { border-color: var(--border-strong); color: var(--text); }
.chip.is-active { background: var(--text); border-color: var(--text); color: var(--surface); }
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 999px; font-size: .75rem; font-weight: 700; white-space: nowrap;
  background: var(--surface-3); color: var(--text-2);
}
.badge-brand { background: var(--brand-soft); color: var(--brand-text); }
.badge-ok { background: var(--green-soft); color: var(--green); }
.badge-warn { background: var(--amber-soft); color: var(--amber); }
.badge-danger { background: var(--rose-soft); color: var(--rose); }

/* tone helpers for the four log fields */
.tone-blue { --tone: var(--blue); --tone-soft: var(--blue-soft); }
.tone-green { --tone: var(--green); --tone-soft: var(--green-soft); }
.tone-rose { --tone: var(--rose); --tone-soft: var(--rose-soft); }
.tone-amber { --tone: var(--amber); --tone-soft: var(--amber-soft); }
.tone-icon {
  display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 10px;
  background: var(--tone-soft); color: var(--tone); flex-shrink: 0;
}

/* ---------- Alerts / toast ---------- */
.alert { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 12px; margin-bottom: 16px; font-size: .9375rem; }
.alert .icon { margin-top: 2px; }
.alert-error { background: var(--danger-soft); color: var(--danger); border: 1px solid color-mix(in srgb, var(--danger) 25%, transparent); }
.alert-info { background: var(--brand-soft); color: var(--brand-text); border: 1px solid color-mix(in srgb, var(--brand) 25%, transparent); }
.toast {
  position: fixed; z-index: 50; left: 50%; top: calc(var(--topbar-h) + env(safe-area-inset-top, 0px) + 12px);
  transform: translateX(-50%);
  display: flex; align-items: center; gap: 10px;
  padding: 10px 18px; border-radius: 999px;
  background: var(--text); color: var(--surface); box-shadow: var(--shadow-lg);
  font-weight: 600; font-size: .9375rem;
  animation: toast-in .25s var(--ease), toast-out .3s var(--ease) 2.7s forwards;
}
.toast .icon { color: #5eead4; }
:root[data-theme="dark"] .toast .icon { color: var(--brand); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .toast .icon { color: var(--brand); } }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, -8px); } }
@keyframes toast-out { to { opacity: 0; transform: translate(-50%, -8px); visibility: hidden; } }

/* ---------- Forms ---------- */
label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: .9375rem; color: var(--text); }
.label-row { display: flex; align-items: center; gap: 10px; }
.hint { font-size: .8125rem; color: var(--text-3); font-weight: 400; }
input, select, textarea {
  font: inherit; font-size: 16px; font-weight: 400; color: var(--text);
  width: 100%; min-height: 46px; padding: 10px 12px;
  border: 1px solid var(--border-strong); border-radius: 12px; background: var(--surface);
  transition: border-color .15s var(--ease), box-shadow .15s var(--ease);
}
input::placeholder, textarea::placeholder { color: var(--text-3); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 4px color-mix(in srgb, var(--brand) 18%, transparent); }
textarea { resize: vertical; min-height: 96px; line-height: 1.6; }
textarea[data-autosize] { resize: none; overflow-y: hidden; }
select { appearance: none; -webkit-appearance: none; padding-right: 40px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; }
label.check { flex-direction: row; align-items: center; gap: 10px; font-weight: 500; min-height: 44px; cursor: pointer; }
label.check input { width: 22px; height: 22px; min-height: 0; accent-color: var(--brand); }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid { display: grid; gap: 14px; }
.field-card { padding: 14px; }
.field-card label { gap: 10px; }
.search-box { position: relative; }
.search-box .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-3); pointer-events: none; }
.search-box input { padding-left: 40px; }
.sticky-actions {
  position: sticky; bottom: calc(var(--bottomnav-h) + var(--safe-b) + 8px); z-index: 5;
  display: flex; gap: 10px; margin-top: 16px; padding: 10px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow-lg);
}
.sticky-actions .btn-primary { flex: 1; }

/* ---------- Dashboard ---------- */
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; box-shadow: var(--shadow-sm); display: flex; flex-direction: column; gap: 8px;
}
.stat-top { display: flex; align-items: center; justify-content: space-between; gap: 6px; color: var(--text-2); font-size: .875rem; font-weight: 600; }
.stat:not(.stat-primary) .tone-icon { width: 28px; height: 28px; border-radius: 8px; }
@media (max-width: 639px) {
  .stat:not(.stat-primary) { padding: 12px; }
  .stat:not(.stat-primary) .stat-top { flex-direction: column-reverse; align-items: flex-start; gap: 8px; white-space: nowrap; }
}
.stat-value { font-size: 1.625rem; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.stat-value small { font-size: .9375rem; font-weight: 600; color: var(--text-3); }
.stat-primary { grid-column: 1 / -1; }
/* 使用原生 <progress>（CSP 禁止 inline style，無法用 style="width:%"） */
progress.progress { -webkit-appearance: none; appearance: none; display: block; width: 100%; height: 8px; border: 0; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
progress.progress::-webkit-progress-bar { background: var(--surface-3); border-radius: 999px; }
progress.progress::-webkit-progress-value { background: linear-gradient(90deg, var(--brand), #0891b2); border-radius: 999px; }
progress.progress::-moz-progress-bar { background: linear-gradient(90deg, var(--brand), #0891b2); border-radius: 999px; }
.unit-status { display: flex; flex-wrap: wrap; gap: 6px; }
.unit-pill {
  display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px; border-radius: 999px;
  font-size: .8125rem; font-weight: 600; text-decoration: none;
  background: var(--surface-3); color: var(--text-3);
}
.unit-pill.done { background: var(--green-soft); color: var(--green); }
.today-cta { display: flex; align-items: center; gap: 14px; }
.today-cta .tone-icon { width: 44px; height: 44px; border-radius: 14px; }
.today-cta .grow { flex: 1; min-width: 0; }
.today-cta h2 { font-size: 1rem; }
.today-cta p { margin: 2px 0 0; color: var(--text-3); font-size: .875rem; }

/* ---------- Filters ---------- */
.filters { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; margin: 20px 0 8px; }
.filter-more summary { list-style: none; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; min-height: 36px; color: var(--text-2); font-weight: 600; font-size: .875rem; }
.filter-more summary::-webkit-details-marker { display: none; }
.filter-more[open] summary { margin-bottom: 8px; }
.filter-form { display: grid; gap: 10px; }

/* ---------- Log list ---------- */
.day-head {
  position: sticky; top: calc(var(--topbar-h) + env(safe-area-inset-top, 0px)); z-index: 4;
  display: flex; align-items: baseline; gap: 8px;
  margin: 20px -16px 8px; padding: 8px 16px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.day-head h2 { font-size: .9375rem; }
.day-head span { color: var(--text-3); font-size: .8125rem; }
.log-card {
  position: relative; display: block; text-decoration: none; color: inherit;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 10px; box-shadow: var(--shadow-sm);
  transition: border-color .15s var(--ease), box-shadow .2s var(--ease), transform .1s var(--ease);
}
.log-card:hover { border-color: var(--border-strong); box-shadow: var(--shadow); }
.log-card:active { transform: scale(.99); }
.log-card.has-issue::before {
  content: ""; position: absolute; left: 0; top: 14px; bottom: 14px; width: 4px; border-radius: 0 4px 4px 0; background: var(--rose);
}
.log-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.log-meta .time { display: inline-flex; align-items: center; gap: 4px; color: var(--text-2); font-weight: 600; font-size: .875rem; }
.log-meta .author { color: var(--text-3); font-size: .875rem; }
.log-meta .spacer { flex: 1; }
.log-line { display: flex; gap: 10px; align-items: flex-start; font-size: .9375rem; line-height: 1.5; }
.log-line + .log-line { margin-top: 6px; }
.log-line .icon { color: var(--tone); margin-top: 3px; }
.log-line .txt { min-width: 0; color: var(--text); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.empty {
  text-align: center; color: var(--text-3); padding: 48px 16px;
  background: var(--surface); border: 1px dashed var(--border-strong); border-radius: var(--radius);
}
.empty .icon { color: var(--text-3); margin-bottom: 8px; }
.empty h2 { color: var(--text-2); font-size: 1rem; margin-bottom: 4px; }

/* ---------- Log detail ---------- */
.detail-head { display: flex; flex-direction: column; gap: 10px; }
.detail-meta { display: flex; flex-wrap: wrap; gap: 6px 16px; color: var(--text-3); font-size: .875rem; }
.detail-meta span { display: inline-flex; align-items: center; gap: 6px; }
.field-section { display: flex; gap: 12px; align-items: flex-start; }
.field-section + .field-section { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border); }
.field-section .body { flex: 1; min-width: 0; }
.field-section h3 { font-size: .875rem; color: var(--tone); margin: 4px 0 6px; }
.field-body { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.7; }
.field-body.is-empty { color: var(--text-3); }

.comments { display: flex; flex-direction: column; gap: 12px; }
.comment { display: flex; gap: 10px; align-items: flex-start; }
.comment .bubble { flex: 1; min-width: 0; background: var(--surface-2); border: 1px solid var(--border); border-radius: 4px 14px 14px 14px; padding: 10px 14px; }
.comment .bubble-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: .8125rem; color: var(--text-3); margin-bottom: 2px; }
.comment .bubble-head strong { color: var(--text); font-size: .875rem; }
.comment-form { display: flex; gap: 8px; align-items: flex-end; margin-top: 14px; }
.comment-form textarea { min-height: 46px; }
.comment-form .btn { flex-shrink: 0; }
.revision { padding: 12px 0; border-top: 1px solid var(--border); font-size: .875rem; }
.revision .field-body { padding: 0; }
details.card > summary { cursor: pointer; font-weight: 600; list-style: none; display: flex; align-items: center; gap: 8px; min-height: 28px; }
details.card > summary::-webkit-details-marker { display: none; }

/* ---------- Admin: lists ---------- */
.list { display: flex; flex-direction: column; }
.list-item { display: flex; gap: 12px; align-items: center; padding: 12px 0; }
.list-item + .list-item { border-top: 1px solid var(--border); }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .title { font-weight: 600; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.list-item .sub { color: var(--text-3); font-size: .8125rem; overflow-wrap: anywhere; }
.list-item.is-inactive { opacity: .55; }
.request-card { border-left: 4px solid var(--amber); }
.request-card .form-grid { margin-top: 12px; }
.unit-row { display: flex; gap: 10px; align-items: center; padding: 10px 0; }
.unit-row + .unit-row { border-top: 1px solid var(--border); }
.unit-row input[name="name"] { flex: 1; }
.unit-row label.check { white-space: nowrap; }

.table-wrap { overflow-x: auto; margin: 0 -16px; padding: 0 16px; }
table { width: 100%; border-collapse: collapse; font-size: .875rem; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--text-3); font-weight: 600; font-size: .8125rem; white-space: nowrap; }
tr.warn-row td { background: var(--amber-soft); }
td.detail { max-width: 280px; color: var(--text-2); }

/* ---------- Me ---------- */
.profile { display: flex; align-items: center; gap: 16px; }
.menu { display: flex; flex-direction: column; }
.menu a, .menu button {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 52px; padding: 0 4px;
  background: none; border: 0; border-top: 1px solid var(--border);
  color: var(--text); font: inherit; font-weight: 500; text-decoration: none; text-align: left; cursor: pointer;
}
.menu > :first-child, .menu > form:first-child button { border-top: 0; }
.menu .icon { color: var(--text-3); }
.menu .chev { margin-left: auto; }
.menu .danger { color: var(--danger); }
.menu .danger .icon { color: var(--danger); }

/* ---------- Auth pages ---------- */
.auth-page {
  min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px;
  background:
    radial-gradient(1200px 600px at 10% -10%, color-mix(in srgb, var(--brand) 18%, transparent), transparent 60%),
    radial-gradient(900px 500px at 110% 110%, color-mix(in srgb, #0891b2 16%, transparent), transparent 60%),
    var(--bg);
}
.auth-card {
  width: 100%; max-width: 400px; text-align: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: 24px;
  padding: 36px 24px 28px; box-shadow: var(--shadow-lg);
}
.auth-card .brand-mark { width: 56px; height: 56px; border-radius: 16px; margin-bottom: 16px; }
.auth-card h1 { font-size: 1.5rem; margin-bottom: 6px; }
.auth-card .lead { color: var(--text-3); margin-bottom: 24px; }
.btn-google { width: 100%; min-height: 54px; font-size: 1rem; border-radius: 14px; gap: 12px; }
.auth-foot { margin-top: 20px; font-size: .8125rem; color: var(--text-3); }
.auth-foot a { color: var(--text-3); }
.state-card { text-align: center; padding: 40px 20px; }
.state-icon { display: inline-grid; place-items: center; width: 56px; height: 56px; border-radius: 18px; margin-bottom: 14px; }
.prose h2 { font-size: 1rem; margin: 20px 0 8px; color: var(--brand-text); }
.prose ul { padding-left: 1.25rem; margin: 0 0 .75rem; }
.prose li + li { margin-top: 4px; }

/* ---------- Sidebar (desktop ≥1024) ---------- */
.sidebar { display: none; }

/* ---------- Page grid: main + side panel ---------- */
.page-grid { display: block; }
.page-grid > .side-col { margin-bottom: 16px; }
.page-grid.detail > .side-col { margin-top: 12px; margin-bottom: 0; }
.field-grid { display: grid; gap: 12px; }
.field-grid > .card + .card { margin-top: 0; }
.admin-grid { display: block; }

/* ---------- Tablet (≥640) ---------- */
@media (min-width: 640px) {
  .container { padding: 24px 28px; max-width: 1100px; }
  .filter-form { grid-template-columns: 1fr 1fr auto; align-items: end; }
  .form-grid.cols-2 { grid-template-columns: 1fr 1fr; }
  .form-grid .span-2 { grid-column: 1 / -1; }
  .day-head { margin-left: -28px; margin-right: -28px; padding-left: 28px; padding-right: 28px; }
  .table-wrap { margin: 0; padding: 0; }
  .field-grid { grid-template-columns: 1fr 1fr; }
  .list-grid { display: grid; grid-template-columns: 1fr 1fr; column-gap: 24px; }
  .list-grid .list-item + .list-item { border-top: 0; }
  .list-grid .list-item { border-bottom: 1px solid var(--border); }
}

/* ---------- Desktop (≥1024)：左側欄 + 雙欄內容 ---------- */
@media (min-width: 1024px) {
  :root { --sidebar-w: 248px; }
  body { padding-bottom: 32px; padding-left: var(--sidebar-w); }
  .topbar, .bottomnav { display: none; }
  .toast { top: 20px; left: calc(50% + var(--sidebar-w) / 2); }

  .sidebar {
    display: flex; flex-direction: column; gap: 4px;
    position: fixed; inset: 0 auto 0 0; z-index: 30; width: var(--sidebar-w);
    padding: 20px 14px 16px; background: var(--surface); border-right: 1px solid var(--border);
  }
  .sidebar .brand { padding: 4px 8px 20px; }
  .sidebar nav { display: flex; flex-direction: column; gap: 2px; }
  .sidebar nav a {
    display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 0 12px; border-radius: 12px;
    color: var(--text-2); text-decoration: none; font-weight: 600; font-size: .9375rem;
    transition: background .15s var(--ease), color .15s var(--ease);
  }
  .sidebar nav a:hover { background: var(--surface-3); color: var(--text); }
  .sidebar nav a[aria-current="page"] { background: var(--brand-soft); color: var(--brand-text); }
  .sidebar nav .badge-dot { position: static; margin-left: auto; }
  .sidebar .nav-cta { margin: 0 0 14px; }
  .sidebar .nav-label { margin: 16px 12px 6px; font-size: .75rem; font-weight: 700; color: var(--text-3); letter-spacing: .06em; }
  .sidebar .user-card {
    margin-top: auto; display: flex; align-items: center; gap: 10px;
    padding: 10px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface-2);
  }
  .sidebar .user-card a.who { flex: 1; min-width: 0; color: var(--text); text-decoration: none; line-height: 1.3; }
  .sidebar .user-card .who strong { display: block; font-size: .9375rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .sidebar .user-card .who small { color: var(--text-3); font-size: .75rem; }
  .sidebar .user-card button { width: 36px; height: 36px; min-height: 0; padding: 0; border-radius: 10px; }

  .container { max-width: 1600px; padding: 32px 40px; }
  .container.narrow { max-width: 820px; margin-left: 0; }
  .page-head { margin-top: 0; }
  .day-head { top: 0; margin-left: -12px; margin-right: -12px; padding-left: 12px; padding-right: 12px; border-radius: 10px; }


  .sticky-actions { bottom: 16px; justify-content: flex-end; }
  .sticky-actions .btn-primary { flex: 0 0 auto; min-width: 200px; }
  .admin-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 28px; align-items: start; }
  .admin-grid .section-title:first-child { margin-top: 0; }
}

/* 雙欄：1280px 以上才啟用，避免平板橫式主欄過窄 */
@media (min-width: 1280px) {
  .page-grid { display: grid; grid-template-columns: minmax(0, 1fr) 360px; grid-template-areas: "main side"; gap: 28px; align-items: start; }
  .page-grid > .main-col { grid-area: main; min-width: 0; }
  .page-grid > .side-col { grid-area: side; position: sticky; top: 24px; margin: 0; }
  .page-grid.detail { grid-template-columns: minmax(0, 1fr) 400px; }
  .page-grid.detail > .side-col { margin: 0; max-height: calc(100vh - 48px); overflow-y: auto; }
  .side-col .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .side-col .stat:not(.stat-primary) { padding: 12px; }
  .side-col .stat:not(.stat-primary) .stat-top { flex-direction: column-reverse; align-items: flex-start; gap: 8px; white-space: nowrap; }
  .side-col .card + .card, .side-col .stats + .card { margin-top: 12px; }
  .page-grid .filters { margin-top: 0; }
}

@media (min-width: 1440px) {
  .page-grid { grid-template-columns: minmax(0, 1fr) 400px; }
  .field-grid { gap: 16px; }
}

/* ---------- Motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
  .toast { animation: none; }
}

/* ---------- Utilities ---------- */
.mt-8 { margin-top: 8px; }
.card.menu { padding-top: 4px; padding-bottom: 4px; }
.card ul { margin: 8px 0 14px; padding-left: 1.25rem; }
.card ul li + li { margin-top: 4px; }
.auth-card.prose { max-width: 640px; text-align: left; }
.mt-12 { margin-top: 12px; }

/* ---------- 新留言提醒：閃爍紅燈 ----------
   約 1.2 秒閃一次（遠低於 WCAG 每秒 3 次的上限）；
   開啟「減少動態效果」時改為恆亮不閃。 */
.blink-light {
  display: inline-block; flex-shrink: 0;
  width: 10px; height: 10px; border-radius: 50%;
  background: #ef4444;
  box-shadow: 0 0 6px 2px rgba(239, 68, 68, .75);
  animation: blink-light 1.2s ease-in-out infinite;
}
.blink-light-lg { width: 14px; height: 14px; }
@keyframes blink-light {
  0%, 100% { opacity: 1; transform: scale(1); box-shadow: 0 0 0 0 rgba(239, 68, 68, .55), 0 0 8px 3px rgba(239, 68, 68, .85); }
  50% { opacity: .3; transform: scale(.85); box-shadow: 0 0 0 8px rgba(239, 68, 68, 0), 0 0 2px 0 rgba(239, 68, 68, .2); }
}
@media (prefers-reduced-motion: reduce) {
  .blink-light { animation: none; opacity: 1; }
}
/* 底部導覽列：紅燈在圖示右上角 */
.bottomnav .blink-light { position: absolute; top: 6px; left: calc(50% + 8px); }
/* 側邊欄：紅燈靠右 */
.sidebar nav .blink-light { margin-left: auto; }

.badge-new { background: var(--rose-soft); color: var(--rose); gap: 6px; }
.badge-new .blink-light { width: 8px; height: 8px; }
.log-card.has-unread { border-color: color-mix(in srgb, #ef4444 45%, var(--border)); box-shadow: 0 0 0 3px color-mix(in srgb, #ef4444 12%, transparent); }

.unread-card { border-color: color-mix(in srgb, #ef4444 40%, var(--border)); background: linear-gradient(180deg, var(--rose-soft), var(--surface) 70%); }
.unread-head { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.unread-head h2 { font-size: 1rem; color: var(--rose); }
.unread-head p { margin: 2px 0 0; font-size: .8125rem; color: var(--text-3); }
.unread-list { display: flex; flex-direction: column; }
.unread-list a {
  display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 0 4px;
  color: var(--text); text-decoration: none; font-size: .9375rem; border-top: 1px solid var(--border);
}
.unread-list a:hover { color: var(--rose); }
.unread-list .icon { color: var(--rose); }
.unread-list .badge { margin-left: auto; }
.unread-list .chev { color: var(--text-3); }

.comment.is-new .bubble { border-color: color-mix(in srgb, #ef4444 45%, var(--border)); background: var(--rose-soft); }

/* ---------- 亮暗模式切換 ---------- */
.icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px; min-height: 0; padding: 0;
  border-radius: 12px; border: 1px solid transparent; background: transparent; color: var(--text-2); cursor: pointer;
  transition: background .15s var(--ease), color .15s var(--ease);
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.theme-toggle .i-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .i-sun { display: inline; }
:root[data-theme="dark"] .theme-toggle .i-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .i-sun { display: inline; }
  :root:not([data-theme="light"]) .theme-toggle .i-moon { display: none; }
}
.segmented { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 4px; border-radius: 14px; background: var(--surface-3); }
.segmented button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px;
  border: 0; border-radius: 10px; background: transparent; color: var(--text-2); font: inherit; font-size: .875rem; font-weight: 600; cursor: pointer;
  transition: background .15s var(--ease), color .15s var(--ease), box-shadow .15s var(--ease);
}
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.sidebar .segmented { margin-bottom: 10px; }
.sidebar .segmented button { min-height: 34px; font-size: .8125rem; }
.sidebar .segmented button span { display: none; }

/* ---------- 自動刷新提示 ---------- */
.update-banner {
  position: fixed; z-index: 50; left: 50%; top: calc(var(--topbar-h) + env(safe-area-inset-top, 0px) + 12px);
  transform: translateX(-50%);
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 44px; padding: 0 18px; border-radius: 999px; border: 0;
  background: var(--brand); color: var(--on-brand); box-shadow: var(--shadow-lg);
  font: inherit; font-weight: 700; font-size: .9375rem; cursor: pointer;
  animation: toast-in .25s var(--ease);
}
@media (min-width: 1024px) { .update-banner { top: 20px; left: calc(50% + var(--sidebar-w) / 2); } }
.side-col > * + * { margin-top: 12px; }

/* ---------- 院長閱讀狀態 ---------- */
.badge.read-read { background: var(--green-soft); color: var(--green); }
.badge.read-stale { background: var(--amber-soft); color: var(--amber); }
.badge.read-unread { background: var(--surface-3); color: var(--text-3); }
.read-line {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 12px; font-size: .9375rem;
}
.read-line .num { color: inherit; opacity: .8; font-size: .875rem; }
.read-line.read-read { background: var(--green-soft); color: var(--green); }
.read-line.read-stale { background: var(--amber-soft); color: var(--amber); }
.read-line.read-unread { background: var(--surface-3); color: var(--text-2); }
