/* 顧展系統：手機優先，從 375px 起，用 min-width 向上擴展 */
:root {
  --paper: #F6F2E9;
  --card: #FFFDF8;
  --line: #DDD5C3;
  --ink: #1F2A24;
  --ink2: #5B665F;
  --brand: #2D6A4F;
  --brand-d: #1B4332;
  --brand-l: #D8EBDD;
  --accent: #F4A261;
  --danger: #C0492F;
  --shadow: 0 1px 0 rgba(31,42,36,.06), 0 6px 18px -10px rgba(31,42,36,.25);
  --serif: 'Noto Serif TC', 'Songti TC', serif;
  --sans: 'Noto Sans TC', 'PingFang TC', system-ui, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, Menlo, monospace;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font: 400 16px/1.6 var(--sans);
  padding-bottom: calc(68px + env(safe-area-inset-bottom));
}
[hidden] { display: none !important; }
h1, h2, h3 { font-family: var(--serif); font-weight: 700; margin: 0; line-height: 1.3; }
h2 { font-size: 18px; margin: 22px 0 10px; color: var(--brand-d); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.mono { font-family: var(--mono); font-feature-settings: 'tnum'; }
.i { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.i.sm { width: 18px; height: 18px; }
.muted { color: var(--ink2); }
.small { font-size: 15px; }

/* 版頭與導覽 */
.top {
  position: sticky; top: 0; z-index: 20; background: var(--brand); color: #fff;
  display: flex; align-items: center; gap: 12px; padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top));
}
.top .brand { font: 700 18px var(--serif); letter-spacing: .04em; flex: 1; }
.top .who { display: flex; align-items: center; gap: 6px; font-size: 15px; background: rgba(255,255,255,.14); border: 0; color: #fff; border-radius: 22px; padding: 6px 12px; min-height: 44px; }
.net { display: flex; align-items: center; gap: 6px; background: var(--accent); color: var(--ink); font-size: 15px; font-weight: 500; padding: 8px 16px; }
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; background: var(--card);
  border-top: 1px solid var(--line); display: grid; grid-template-columns: repeat(6, 1fr);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 60px; text-decoration: none; color: var(--ink2); font-size: 13px;
}
.nav a[aria-current="page"] { color: var(--brand); font-weight: 700; box-shadow: inset 0 3px 0 var(--brand); }
main { padding: 8px 16px 24px; max-width: 980px; margin: 0 auto; }
.page-title { display: flex; align-items: center; gap: 10px; margin: 16px 0 4px; }
.page-title h1 { font-size: 22px; flex: 1; }

/* 元件 */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; box-shadow: var(--shadow); }
.card + .card { margin-top: 10px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 18px;
  border-radius: 10px; border: 1px solid var(--brand); background: var(--brand); color: #fff; font-weight: 500;
}
.btn:active { background: var(--brand-d); }
.btn.ghost { background: transparent; color: var(--brand); }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn.sm { min-height: 44px; padding: 0 14px; font-size: 15px; }
.btn.block { width: 100%; }
.iconbtn { width: 44px; height: 44px; display: inline-flex; align-items: center; justify-content: center; border: 1px solid var(--line); background: var(--card); border-radius: 10px; color: var(--ink); }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.sp { flex: 1; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--c, var(--brand)); color: #fff; border-radius: 8px; padding: 2px 10px 2px 8px; font-size: 15px; line-height: 1.7; white-space: nowrap; }
.chip .i { width: 16px; height: 16px; }
.pill { display: inline-block; border-radius: 8px; padding: 0 9px; font-size: 14px; background: var(--c, var(--brand-l)); color: var(--ink); line-height: 1.8; white-space: nowrap; }
.pill.warn { background: var(--accent); }
.name-chip { display: inline-block; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 0 9px; font-size: 15px; line-height: 1.8; }
.name-chip.me { background: var(--brand-l); border-color: var(--brand); font-weight: 700; }

label.f { display: block; font-size: 15px; color: var(--ink2); margin: 12px 0 4px; }
.in, select.in, textarea.in {
  width: 100%; min-height: 46px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; font-size: 16px;
}
textarea.in { min-height: 96px; resize: vertical; }
.in:focus { outline: 2px solid var(--brand); outline-offset: 0; border-color: var(--brand); }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; font-size: 16px; }
.check input { width: 22px; height: 22px; accent-color: var(--brand); }

/* 現場 */
.hero { background: var(--brand); color: #fff; border-radius: 14px; padding: 16px 18px; margin-top: 10px; display: grid; grid-template-columns: 1fr auto; align-items: end; gap: 4px 12px; }
.hero .lab { font-size: 15px; opacity: .85; grid-column: 1 / -1; }
.hero .num { font: 700 64px/1 var(--mono); }
.hero .unit { font: 700 20px var(--serif); padding-bottom: 6px; }
.hero .sub { grid-column: 1 / -1; font-size: 15px; opacity: .9; border-top: 1px solid rgba(255,255,255,.25); margin-top: 8px; padding-top: 8px; display: flex; justify-content: space-between; }
.type-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tbtn {
  min-height: 76px; border: 0; border-radius: 12px; background: var(--c); color: #fff; display: flex; flex-direction: column;
  align-items: flex-start; justify-content: center; gap: 4px; padding: 10px 14px; font: 700 17px var(--sans); text-align: left;
  box-shadow: 0 3px 0 rgba(0,0,0,.22); touch-action: manipulation;
}
.tbtn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0,0,0,.22); }
.tbtn .i { width: 26px; height: 26px; }
.tbtn small { font-weight: 400; font-size: 13px; opacity: .9; }
.vrow { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; align-items: center; padding: 10px 0; border-top: 1px solid var(--line); }
.vrow:first-child { border-top: 0; }
.vrow .meta { font-size: 15px; color: var(--ink2); }
.badge-in { background: var(--accent); color: var(--ink); border-radius: 8px; padding: 0 8px; font-size: 14px; font-weight: 700; }
.empty { text-align: center; color: var(--ink2); padding: 22px 0; font-size: 15px; }

/* 週排班 */
.weeknav { display: flex; align-items: center; gap: 8px; }
.weeknav .t { flex: 1; text-align: center; font: 700 17px var(--serif); }
.day { padding: 0; overflow: hidden; }
.day + .day { margin-top: 10px; }
.day-h { display: flex; align-items: baseline; gap: 8px; padding: 10px 16px; background: #EFE9DB; border-bottom: 1px solid var(--line); }
.day-h b { font: 700 18px var(--mono); }
.day-h.today { background: var(--brand-l); }
.cell { display: grid; grid-template-columns: 92px 1fr; gap: 6px 10px; padding: 8px 16px; border-top: 1px solid var(--line); align-items: start; width: 100%; text-align: left; background: none; border-left: 0; border-right: 0; border-bottom: 0; min-height: 52px; }
.day-h + .cell { border-top: 0; }
.cell .shn { font-size: 14px; }
.cell .names { display: flex; flex-wrap: wrap; gap: 6px; min-height: 28px; align-items: center; }
.cell .hint { color: var(--ink2); font-size: 14px; }
button.cell:active { background: var(--brand-l); }

/* 月曆 */
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal .wd { text-align: center; font-size: 14px; color: var(--ink2); padding: 4px 0; }
.cal .d { min-height: 64px; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 4px; display: flex; flex-direction: column; gap: 3px; text-decoration: none; color: var(--ink); overflow: hidden; }
.cal .d.blank { background: transparent; border-color: transparent; }
.cal .d.today { border: 2px solid var(--brand); }
.cal .d .n { font: 500 14px var(--mono); }
.cal .d .dots { display: flex; flex-wrap: wrap; gap: 2px; }
.cal .d .dots i { width: 9px; height: 9px; border-radius: 3px; background: var(--c); border: 1px solid rgba(0,0,0,.15); }
.cal .d .ppl { font: 700 12px var(--mono); color: var(--brand-d); margin-top: auto; }
.cal .d .lg { width: 8px; height: 8px; border-radius: 50%; background: var(--brand); display: inline-block; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 12px; font-size: 14px; color: var(--ink2); margin-top: 10px; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -1px; margin-right: 4px; background: var(--c); border: 1px solid rgba(0,0,0,.15); }

/* 日誌 */
.log h3 { font-size: 16px; }
.log .txt { white-space: pre-wrap; font-size: 15px; margin: 6px 0 0; }
.log .lab { font-size: 14px; color: var(--ink2); margin-top: 8px; }
.log .issue { border-left: 4px solid var(--accent); padding-left: 10px; margin-top: 8px; }

/* 統計 */
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.stat .v { font: 700 30px/1.1 var(--mono); color: var(--brand-d); }
.stat .l { font-size: 14px; color: var(--ink2); }
.bar { display: grid; grid-template-columns: 96px 1fr 52px; gap: 8px; align-items: center; padding: 4px 0; font-size: 15px; }
.bar .track { height: 18px; background: #EFE9DB; border-radius: 6px; overflow: hidden; }
.bar .fill { height: 100%; background: var(--c, var(--brand)); border-radius: 6px; }
.bar .v { font: 500 14px var(--mono); text-align: right; }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg button { min-height: 44px; padding: 0 14px; border-radius: 22px; border: 1px solid var(--line); background: var(--card); }
.seg button[aria-pressed="true"] { background: var(--brand); color: #fff; border-color: var(--brand); }
.cols { display: flex; align-items: flex-end; gap: 3px; height: 110px; padding-top: 8px; }
.cols .c { flex: 1; background: var(--brand); border-radius: 4px 4px 0 0; min-height: 2px; position: relative; }
.cols-x { display: flex; gap: 3px; font: 500 11px var(--mono); color: var(--ink2); }
.cols-x span { flex: 1; text-align: center; overflow: hidden; }

.card.bk.off { opacity: .6; }
.cal .d .bkn { font: 700 12px var(--mono); color: var(--ink2); }

/* 快速標籤列 */
.tagpick { margin: 0 0 12px; }
.tagpick .opts { margin-top: 6px; }
.tagbtn { min-height: 44px; padding: 0 16px; border-radius: 22px; border: 1px solid var(--line); background: var(--card); font-size: 16px; touch-action: manipulation; }
.tagbtn[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--ink); font-weight: 700; }

/* 單選色塊（年齡層、性別） */
.opts { display: flex; flex-wrap: wrap; gap: 8px; }
.opt input { position: absolute; opacity: 0; pointer-events: none; }
.opt span { display: inline-flex; align-items: center; min-height: 44px; padding: 0 16px; border: 1px solid var(--line); border-radius: 22px; background: var(--card); font-size: 16px; }
.opt input:checked + span { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 700; }
.opt input:focus-visible + span { outline: 2px solid var(--brand-d); outline-offset: 2px; }

/* 底部彈出層 */
.sheet-bg { position: fixed; inset: 0; z-index: 50; background: rgba(31,42,36,.45); display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--paper); width: 100%; max-width: 560px; border-radius: 18px 18px 0 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); max-height: 90vh; overflow: auto; animation: up .18s ease-out; }
@keyframes up { from { transform: translateY(40px); opacity: .6; } to { transform: none; opacity: 1; } }
.sheet h3 { font-size: 19px; margin-bottom: 4px; }
.stepper { display: flex; align-items: center; justify-content: center; gap: 14px; margin: 16px 0; }
.stepper .iconbtn { width: 56px; height: 56px; }
.stepper input { width: 110px; text-align: center; font: 700 40px var(--mono); border: 0; border-bottom: 2px solid var(--brand); background: transparent; min-height: 56px; }
.quick { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.quick button { min-height: 44px; min-width: 56px; border-radius: 22px; border: 1px solid var(--line); background: var(--card); font: 500 16px var(--mono); }
.toast { position: fixed; left: 12px; right: 12px; bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 60; max-width: 520px; margin: 0 auto; background: var(--ink); color: #fff; border-radius: 12px; padding: 10px 14px; display: flex; align-items: center; gap: 12px; }
.toast button { background: transparent; border: 1px solid rgba(255,255,255,.5); color: #fff; border-radius: 8px; min-height: 44px; padding: 0 14px; }

/* 登入 */
.login { max-width: 420px; margin: 0 auto; padding: 28px 16px; }
.login h1 { font-size: 28px; color: var(--brand-d); }
.names { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 14px 0; }
.names button { min-height: 52px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); font-size: 17px; }
.names button[aria-pressed="true"] { border: 2px solid var(--brand); background: var(--brand-l); font-weight: 700; }
.pin { font: 700 32px var(--mono); letter-spacing: .4em; text-align: center; }
.err { color: var(--danger); font-size: 15px; min-height: 24px; margin-top: 6px; }

@media (min-width: 700px) {
  .type-grid { grid-template-columns: repeat(3, 1fr); }
  .stats-grid { grid-template-columns: repeat(4, 1fr); }
  .cal .d { min-height: 92px; padding: 6px 8px; }
  .cell { grid-template-columns: 120px 1fr; }
  .sheet-bg { align-items: center; }
  .sheet { border-radius: 18px; }
}
@media (min-width: 900px) {
  body { padding-bottom: 0; }
  .nav { position: static; display: flex; gap: 4px; max-width: 980px; margin: 0 auto; border: 0; background: transparent; padding: 8px 16px 0; }
  .nav a { flex-direction: row; gap: 8px; min-height: 44px; padding: 0 16px; border-radius: 10px; font-size: 16px; }
  .nav a[aria-current="page"] { background: var(--brand-l); box-shadow: none; }
  .toast { bottom: 24px; }
  .week-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .week-grid .day + .day { margin-top: 0; }
}
@media (prefers-reduced-motion: reduce) { .sheet { animation: none; } .tbtn:active { transform: none; } }
@media print {
  .top, .nav, .btn, .iconbtn, .toast, .net { display: none !important; }
  body { background: #fff; padding: 0; }
}
