/* 醫護站紀錄：以 iPad 直式、手指操作為主。所有點得到的東西至少 44px 高。 */

:root {
  --bg: #F3F5F4;
  --surface: #FFFFFF;
  --surface-2: #F7F9F8;
  --ink: #17262A;
  --muted: #5D6E72;
  --line: #D6DEDD;
  --accent: #0E6B66;
  --accent-ink: #FFFFFF;
  --accent-soft: #DCEEEB;
  --warn: #B45309;
  --warn-soft: #FCEFD9;
  --ok: #2F7D4F;
  --ok-soft: #E1F1E6;
  --danger: #B42318;
  --shadow: 0 1px 2px rgba(23, 38, 42, .06), 0 4px 16px rgba(23, 38, 42, .05);
  --top-h: 60px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0F1719;
    --surface: #172226;
    --surface-2: #1B2A2E;
    --ink: #E4EDED;
    --muted: #93A5A8;
    --line: #2A3B3F;
    --accent: #4FB8AE;
    --accent-ink: #062421;
    --accent-soft: #163538;
    --warn: #F0A54A;
    --warn-soft: #3A2A12;
    --ok: #6CC08A;
    --ok-soft: #173323;
    --danger: #F07167;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.5 -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
}

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 14px; }

/* ---------- 上方標題列 ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}

.topbar-in {
  max-width: 1040px;
  margin: 0 auto;
  min-height: 60px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px max(16px, env(safe-area-inset-right)) 6px max(16px, env(safe-area-inset-left));
}

.back {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 44px;
  padding: 0 12px 0 6px;
  margin-left: -6px;
  border-radius: 12px;
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}
.back span { font-size: 28px; line-height: 1; margin-top: -3px; }
.back:active { background: var(--accent-soft); }

.title-wrap { flex: 1; min-width: 0; }
h1 {
  margin: 0;
  font-size: 19px;
  font-weight: 700;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.title-meta { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 2px; }
.title-meta:empty { display: none; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 15px;
  white-space: nowrap;
}
.pill .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ok); flex: none; }
.pill-busy .dot { background: var(--accent); animation: pulse 1.1s ease-in-out infinite; }
.pill-off .dot { background: var(--warn); }
.pill-off { border-color: color-mix(in srgb, var(--warn) 45%, var(--line)); }
.pill-err .dot { background: var(--danger); }
.pill-err { color: var(--danger); }
@keyframes pulse { 50% { opacity: .3; } }

/* ---------- 小標籤 ---------- */

.miss, .rs {
  display: inline-flex;
  align-items: center;
  height: 24px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}
.miss { background: var(--warn-soft); color: var(--warn); }
.miss.done { background: var(--ok-soft); color: var(--ok); }
.rs { padding: 0; font-weight: 500; color: var(--muted); }
.rs::before { content: ''; width: 7px; height: 7px; border-radius: 50%; margin-right: 6px; background: currentColor; }
.rs-ok { color: var(--ok); }
.rs-wait { color: var(--warn); }
.rs-err { color: var(--danger); }

/* ---------- 橫幅 ---------- */

.banners {
  max-width: 1040px;
  margin: 0 auto;
  padding: 12px max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
  display: grid;
  gap: 10px;
}
.banners:empty { display: none; }
.banner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px 12px 16px;
  border-radius: 14px;
  font-size: 15px;
  line-height: 1.45;
}
.banner > div { flex: 1; }
.banner p { margin: 2px 0 0; }
.banner-test { background: var(--warn-soft); color: color-mix(in srgb, var(--warn) 80%, var(--ink)); }
.banner-install, .banner-update { background: var(--accent-soft); }
.banner-x {
  flex: none;
  align-self: flex-start;
  width: 40px; height: 40px;
  margin: -6px -6px 0 0;
  border: 0;
  border-radius: 10px;
  background: transparent;
  font-size: 24px;
  color: var(--muted);
}
.ios-share {
  display: inline-block;
  width: 15px; height: 18px;
  margin: 0 4px -3px;
  background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 15 18'%3E%3Cpath d='M7.5 0 3.6 3.9l1 1 2.2-2.2V11h1.4V2.7l2.2 2.2 1-1z'/%3E%3Cpath d='M1 6.5h3.5v1.4H2.4v8.7h10.2V7.9h-2.1V6.5H14V18H1z'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 15 18'%3E%3Cpath d='M7.5 0 3.6 3.9l1 1 2.2-2.2V11h1.4V2.7l2.2 2.2 1-1z'/%3E%3Cpath d='M1 6.5h3.5v1.4H2.4v8.7h10.2V7.9h-2.1V6.5H14V18H1z'/%3E%3C/svg%3E") center / contain no-repeat;
}

/* ---------- 按鈕 ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 18px;
  border-radius: 12px;
  border: 1.5px solid transparent;
  font-weight: 600;
  white-space: nowrap;
}
.btn:disabled { opacity: .55; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:active { filter: brightness(.92); }
.btn-soft { background: var(--accent-soft); color: var(--accent); }
.btn-ghost { background: transparent; border-color: var(--line); }
.btn-danger-ghost { background: transparent; border-color: color-mix(in srgb, var(--danger) 40%, var(--line)); color: var(--danger); }
.btn-big { width: 100%; min-height: 62px; font-size: 19px; border-radius: 16px; }
.btn-big .plus { font-size: 24px; font-weight: 400; }

.btn-float {
  position: fixed;
  z-index: 15;
  right: max(18px, env(safe-area-inset-right));
  bottom: calc(18px + env(safe-area-inset-bottom));
  min-height: 52px;
  padding: 0 22px;
  border-radius: 999px;
  background: var(--warn);
  color: #fff;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .22);
  font-size: 16px;
}
@media (prefers-color-scheme: dark) { .btn-float { color: #1B1206; } }

/* ---------- 列表 ---------- */

.view {
  max-width: 1040px;
  margin: 0 auto;
  padding: 16px max(16px, env(safe-area-inset-right)) 96px max(16px, env(safe-area-inset-left));
}

.list-top { margin: 4px 0 18px; }
.day { font-size: 14px; font-weight: 600; color: var(--muted); margin: 22px 4px 8px; }
.cards { display: grid; gap: 10px; }
.card {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 76px;
  padding: 14px 18px;
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
  text-decoration: none;
}
.card:active { background: var(--surface-2); }
.card-main { flex: 1; min-width: 0; }
.card-title { font-size: 18px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-title.muted { font-weight: 500; }
.card-sub { font-size: 14px; color: var(--muted); margin-top: 2px; }
.card-side { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; flex: none; }

.empty { text-align: center; padding: 48px 16px; }
.empty p { margin: 6px 0; }

.fatal { max-width: 560px; margin: 40px auto; padding: 0 20px; }

/* ---------- 單筆紀錄 ---------- */

.secnav {
  position: sticky;
  top: var(--top-h);
  z-index: 10;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  margin: -16px calc(-1 * max(16px, env(safe-area-inset-left))) 14px;
  padding: 10px max(16px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.secnav::-webkit-scrollbar { display: none; }
.secchip {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 12px 0 16px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  text-decoration: none;
  font-weight: 600;
  font-size: 16px;
}
.secchip-dim { color: var(--muted); font-weight: 500; padding-right: 16px; }
.chip-badge {
  min-width: 26px; height: 26px;
  padding: 0 7px;
  border-radius: 999px;
  display: inline-grid;
  place-items: center;
  font-size: 13px;
  background: var(--warn);
  color: #fff;
}
.chip-badge.done { background: var(--ok-soft); color: var(--ok); }
@media (prefers-color-scheme: dark) { .chip-badge { color: #1B1206; } }

.sec {
  background: var(--surface);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 18px 20px 6px;
  margin-bottom: 18px;
  scroll-margin-top: calc(var(--top-h) + 76px);
}
.sec-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.sec h2 { margin: 0; font-size: 22px; }
.sec-badge {
  font-size: 14px;
  font-weight: 600;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--warn-soft);
  color: var(--warn);
}
.sec-badge.done { background: var(--ok-soft); color: var(--ok); }
.sec-note { color: var(--muted); font-size: 15px; margin: 0 0 12px; }

.grp { padding: 4px 0 8px; }
.grp + .grp { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 14px; }
.grp-title {
  margin: 6px 0 12px;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: .04em;
  color: var(--accent);
}

.field {
  position: relative;
  padding: 2px 0 2px 14px;
  margin: 0 0 20px -14px;
  border-radius: 4px;
  scroll-margin-top: calc(var(--top-h) + 90px);
}
.field.is-missing { box-shadow: inset 3px 0 0 var(--warn); }
.field.flash { animation: flash 1.2s ease-out; }
@keyframes flash {
  0%, 30% { background: var(--warn-soft); }
  100% { background: transparent; }
}

.f-head { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 10px; margin-bottom: 10px; }
.f-label { font-weight: 600; font-size: 17px; }
.f-req, .f-kind, .f-tent {
  font-size: 12.5px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 6px;
  line-height: 1.4;
}
.f-req { background: var(--ok-soft); color: var(--ok); }
.f-req::after { content: '✓ 必填已填'; }
.is-missing .f-req { background: var(--warn-soft); color: var(--warn); }
.is-missing .f-req::after { content: '必填'; }
.f-kind { color: var(--muted); background: var(--surface-2); border: 1px solid var(--line); }
.f-tent { color: var(--muted); border: 1px dashed var(--muted); }
.f-hint { margin: 8px 0 0; font-size: 14px; color: var(--muted); }

.chips { display: flex; flex-wrap: wrap; gap: 10px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 48px;
  padding: 8px 16px;
  border-radius: 12px;
  border: 1.5px solid var(--line);
  background: var(--surface-2);
  font-size: 16.5px;
  line-height: 1.25;
  text-align: left;
  transition: background-color .12s, border-color .12s, color .12s;
}
.chip:active { transform: scale(.98); }
.chip[aria-checked="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}
.chip[aria-checked="true"]::before { content: '✓'; font-weight: 700; }

.orphan { display: block; margin-top: 8px; font-size: 14px; color: var(--warn); }

.inp {
  width: 100%;
  min-height: 50px;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1.5px solid var(--line);
  background: var(--surface-2);
  font-size: 17px;   /* 小於 16px 時 iPhone 一點輸入框就會自己放大畫面 */
}
textarea.inp { resize: vertical; line-height: 1.5; }
.inp:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
.inp-num { width: 130px; }
.with-unit { display: inline-flex; align-items: center; gap: 10px; }
.unit { color: var(--muted); }
.dt-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.inp-dt { width: auto; min-width: 230px; flex: 0 1 280px; -webkit-appearance: none; appearance: none; }
.inp-dt::-webkit-date-and-time-value { text-align: left; }

.more {
  margin: 0 0 14px;
  padding: 12px 14px;
  border: 1.5px dashed var(--line);
  border-radius: 12px;
  color: var(--muted);
  font-size: 15px;
}

.sec-pending { background: transparent; box-shadow: none; border: 1.5px dashed var(--line); }
.pending-list {
  list-style: none;
  margin: 0 0 14px;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 8px;
}
.pending-list li {
  display: flex;
  flex-direction: column;
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--surface);
  opacity: .8;
}
.pending-list b { font-weight: 600; }
.pending-list span { font-size: 13px; color: var(--muted); }

.rec-foot { padding: 8px 4px 24px; display: grid; gap: 12px; justify-items: start; }

/* 寬螢幕（iPad 橫放、電腦）：區塊目錄放左邊 */
@media (min-width: 1100px) {
  .rec { display: grid; grid-template-columns: 220px 1fr; gap: 24px; align-items: start; }
  .secnav {
    flex-direction: column;
    overflow: visible;
    margin: 0;
    padding: 0;
    top: calc(var(--top-h) + 16px);
    background: none;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    border: 0;
  }
  .secchip { justify-content: space-between; border-radius: 14px; }
  .sec { scroll-margin-top: calc(var(--top-h) + 16px); }
  .field { scroll-margin-top: calc(var(--top-h) + 40px); }
}

/* 手機：再緊湊一點 */
@media (max-width: 520px) {
  .sec { padding: 16px 16px 4px; border-radius: 18px; }
  .chip { padding: 8px 13px; font-size: 16px; }
  .chips { gap: 8px; }
  .pill { padding: 0 11px; font-size: 14px; }
  .sec h2 { font-size: 20px; }
  .banner { font-size: 14px; padding: 9px 12px; }
}

/* ---------- 「這台裝置」視窗 ---------- */

.sheet {
  width: min(520px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  border: 0;
  border-radius: 20px;
  padding: 24px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}
.sheet::backdrop { background: rgba(10, 20, 22, .45); }
.sheet h2 { margin: 0 0 14px; font-size: 21px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; margin: 0 0 18px; font-size: 15px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-all; }
.sheet-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.danger-zone { margin-top: 20px; border-top: 1px solid var(--line); padding-top: 12px; }
.danger-zone summary { min-height: 44px; display: flex; align-items: center; color: var(--danger); cursor: pointer; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  z-index: 50;
  transform: translate(-50%, 20px);
  max-width: calc(100vw - 32px);
  padding: 12px 18px;
  border-radius: 12px;
  background: var(--ink);
  color: var(--bg);
  font-size: 15px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
