:root {
  --navy: #16267B;
  --navy-2: #2a3d9c;
  --sky: #6494DE;
  --pale: #ECF2FB;
  --bg: #F3F5FA;
  --card: #FFFFFF;
  --text: #1B2033;
  --muted: #667085;
  --line: #E3E7EF;
  --green: #12A150;
  --yellow: #E0A100;
  --red: #E0352B;
  --green-bg: #E5F6EC;
  --yellow-bg: #FFF5D6;
  --red-bg: #FDE8E6;
  --blue-bg: #E7EEFC;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0F1220;
    --card: #1A1F33;
    --text: #E8EAF2;
    --muted: #9AA3B8;
    --line: #2A3150;
    --pale: #222A4A;
    --green-bg: #133524;
    --yellow-bg: #3A3010;
    --red-bg: #3D1A18;
    --blue-bg: #1D2747;
    --shadow: none;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  min-height: 100vh;
  -webkit-text-size-adjust: 100%;
}
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* 上方品牌列 */
#top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + var(--safe-t)) 16px 10px;
  background: var(--navy); color: #fff;
  box-shadow: 0 2px 0 0 var(--sky);
}
#top .mark { width: 34px; height: 34px; border-radius: 8px; background: #fff; }
.top-text { flex: 1; min-width: 0; }
.brand { font-weight: 700; font-size: 16px; letter-spacing: .5px; }
.who { font-size: 13px; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  border: 0; background: transparent; width: 40px; height: 40px; border-radius: 10px;
  display: inline-flex; align-items: center; justify-content: center; font-size: 18px; cursor: pointer;
}
#top .icon-btn:active { background: rgba(255,255,255,.15); }
#refresh.spin svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

main { padding: 14px 16px calc(96px + var(--safe-b)); max-width: 640px; margin: 0 auto; }
.loading { text-align: center; color: var(--muted); padding: 60px 0; }

/* 下方分頁 */
#tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
}
#tabs button {
  border: 0; background: none; padding: 8px 0 6px; display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 12px; color: var(--muted); cursor: pointer;
}
#tabs svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
#tabs button.on { color: var(--navy); font-weight: 700; }
@media (prefers-color-scheme: dark) { #tabs button.on { color: var(--sky); } }

/* 標題與區塊 */
.hero { margin: 4px 0 14px; }
.hero .date { font-size: 26px; font-weight: 800; letter-spacing: .5px; }
.hero .hello { color: var(--muted); font-size: 14px; }
h3.sec { font-size: 15px; margin: 22px 0 8px; display: flex; align-items: center; gap: 8px; }
h3.sec .count { background: var(--pale); color: var(--navy); border-radius: 999px; padding: 0 8px; font-size: 13px; }
@media (prefers-color-scheme: dark) { h3.sec .count { color: var(--sky); } }
.empty { text-align: center; color: var(--muted); padding: 22px 12px; background: var(--card); border-radius: 14px; border: 1px dashed var(--line); font-size: 14px; }
.notice { background: var(--yellow-bg); border-radius: 12px; padding: 10px 12px; font-size: 14px; margin-bottom: 12px; }
.notice.bad { background: var(--red-bg); }
.notice.info { background: var(--blue-bg); }

/* 卡片 */
.card {
  display: block; width: 100%; text-align: left; background: var(--card); border: 0; border-radius: 14px;
  padding: 12px 14px 12px 16px; margin-bottom: 10px; box-shadow: var(--shadow); position: relative; overflow: hidden;
}
button.card { cursor: pointer; }
button.card:active { transform: scale(.99); }
.task::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 5px; background: var(--green); }
.task.u1::before { background: var(--yellow); }
.task.u2::before { background: var(--red); }
.task.st1::before { background: var(--sky); }
.task.st2::before { background: var(--line); }
.task .r1 { display: flex; gap: 8px; align-items: flex-start; }
.task .title { flex: 1; font-weight: 700; font-size: 16px; line-height: 1.4; word-break: break-word; }
.task.st2 .title { color: var(--muted); }
.task .meta { font-size: 13px; color: var(--muted); margin-top: 4px; }
.task .left { font-size: 13px; font-weight: 700; margin-top: 2px; }
.left.red { color: var(--red); }
.left.yellow { color: var(--yellow); }
.left.green { color: var(--green); }

.chip { display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.chip.s0 { background: var(--blue-bg); color: var(--navy); }
.chip.s1 { background: var(--green-bg); color: var(--green); }
.chip.s2 { background: var(--line); color: var(--muted); }
.chip.ret { background: var(--red-bg); color: var(--red); }
@media (prefers-color-scheme: dark) { .chip.s0 { color: var(--sky); } }

.card.ev { display: flex; align-items: flex-start; gap: 4px; padding: 6px 8px 6px 10px; }
.ev .tick {
  flex: none; width: 26px; height: 26px; margin: 8px 4px 0 0; border-radius: 50%; border: 2px solid var(--line);
  background: var(--card); color: #fff; font-size: 15px; font-weight: 800; line-height: 1; cursor: pointer; padding: 0;
}
.ev.done .tick { background: var(--green); border-color: var(--green); }
.ev-main { flex: 1; min-width: 0; display: flex; gap: 12px; align-items: flex-start; text-align: left; border: 0; background: none; padding: 6px 4px; cursor: pointer; }
.ev .time { min-width: 48px; font-weight: 700; color: var(--navy); font-variant-numeric: tabular-nums; }
@media (prefers-color-scheme: dark) { .ev .time { color: var(--sky); } }
.ev .body { flex: 1; min-width: 0; }
.ev .t { font-weight: 600; word-break: break-word; }
.ev .n { font-size: 13px; color: var(--muted); white-space: pre-wrap; word-break: break-word; }
.ev.done .t { text-decoration: line-through; color: var(--muted); }
.day-head { font-weight: 700; margin: 18px 0 8px; font-size: 14px; color: var(--muted); }
.day-head.today { color: var(--navy); }
@media (prefers-color-scheme: dark) { .day-head.today { color: var(--sky); } }

/* 切換與篩選 */
.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--card); border-radius: 12px; padding: 4px; box-shadow: var(--shadow); margin-bottom: 12px; }
.seg button { border: 0; background: none; padding: 8px 0; border-radius: 9px; font-weight: 600; color: var(--muted); cursor: pointer; }
.seg button.on { background: var(--navy); color: #fff; }
.chips { display: flex; gap: 8px; margin-bottom: 12px; overflow-x: auto; }
.chips button { border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 6px 14px; font-size: 14px; white-space: nowrap; cursor: pointer; }
.chips button.on { border-color: var(--navy); background: var(--navy); color: #fff; }

.fab {
  position: fixed; right: 16px; bottom: calc(76px + var(--safe-b)); z-index: 9;
  border: 0; border-radius: 999px; background: var(--navy); color: #fff; font-weight: 700;
  padding: 14px 20px; box-shadow: 0 6px 16px rgba(22, 38, 123, .35); cursor: pointer;
}

/* 按鈕與表單 */
.btn {
  display: block; width: 100%; border: 0; border-radius: 12px; padding: 13px 16px; font-weight: 700; font-size: 16px;
  background: var(--navy); color: #fff; cursor: pointer; margin-top: 10px;
}
.btn:disabled { opacity: .55; }
.btn.ghost { background: var(--pale); color: var(--navy); }
.btn.green { background: var(--green); }
.btn.red { background: var(--red); }
.btn.line { background: transparent; color: var(--red); border: 1px solid var(--line); }
@media (prefers-color-scheme: dark) { .btn.ghost { color: var(--text); } }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
label.f { display: block; font-size: 14px; font-weight: 600; margin: 14px 0 6px; }
input.in, textarea.in, select.in {
  width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; font: inherit; font-size: 16px;
  background: var(--card); color: var(--text);
}
textarea.in { min-height: 96px; resize: vertical; }
.in:focus { outline: 2px solid var(--sky); outline-offset: 0; border-color: transparent; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.check { display: flex; align-items: center; gap: 10px; margin-top: 14px; font-size: 15px; }
.check input { width: 22px; height: 22px; accent-color: var(--navy); }
.hint { font-size: 13px; color: var(--muted); margin-top: 6px; }
.top-hint { margin: 0 0 4px; }

/* 月曆 */
.cal-head { display: flex; align-items: center; gap: 4px; margin: 2px 0 8px; }
.cal-head b { flex: 1; text-align: center; font-size: 18px; }
.cal-head .icon-btn { font-size: 28px; color: var(--navy); }
@media (prefers-color-scheme: dark) { .cal-head .icon-btn { color: var(--sky); } }
.mini { border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 4px 12px; font-size: 13px; cursor: pointer; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; background: var(--card); border-radius: 14px; padding: 8px 6px; box-shadow: var(--shadow); }
.cal-w { text-align: center; font-size: 12px; color: var(--muted); padding-bottom: 4px; font-weight: 700; }
.cal-w.off, .cal-d.off .num { color: var(--red); }
.cal-d {
  border: 0; background: none; border-radius: 10px; padding: 4px 0 3px; min-height: 58px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 1px; min-width: 0;
}
.cal-d .num { font-weight: 700; font-size: 15px; width: 28px; height: 28px; line-height: 28px; border-radius: 50%; text-align: center; }
.cal-d.today .num { background: var(--navy); color: #fff; }
.cal-d.off.today .num { background: var(--red); color: #fff; }
.cal-d.sel { background: var(--pale); outline: 2px solid var(--sky); }
.cal-d .hol { font-size: 9px; line-height: 1.1; color: var(--red); max-width: 100%; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; min-height: 10px; padding: 0 2px; }
.cal-d .hol.work { color: var(--muted); }
.cal-d .marks { display: flex; gap: 2px; min-height: 16px; }
.ev-n, .tk-n { display: inline-block; min-width: 16px; height: 16px; line-height: 16px; border-radius: 8px; font-size: 11px; font-style: normal; font-weight: 800; color: #fff; text-align: center; padding: 0 3px; }
.ev-n { background: var(--navy); }
.tk-n { background: var(--yellow); }
@media (prefers-color-scheme: dark) { .ev-n { background: var(--sky); } }
.cal-legend { font-size: 12px; color: var(--muted); margin: 8px 2px 0; }
.red-t { color: var(--red); font-weight: 700; }

/* 表單細節 */
.inline { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin-top: 10px; font-size: 15px; }
.inline .hint { flex-basis: 100%; margin-top: 0; }
.in.num { width: 76px; text-align: center; padding: 9px 6px; }
.in.md { width: 110px; padding: 9px 8px; }
.check.sub { margin-left: 32px; margin-top: 6px; }
.check input:disabled + * , .check input:disabled { opacity: .5; }
.summary { margin-top: 10px; padding: 8px 12px; border-radius: 10px; background: var(--blue-bg); color: var(--navy); font-weight: 700; font-size: 14px; }
@media (prefers-color-scheme: dark) { .summary { color: var(--sky); } }
.people { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 2px 12px 10px; max-height: 240px; overflow-y: auto; }
.light-line { margin-top: 10px; font-size: 14px; }
.gap-top { margin-top: 18px; }
input:disabled, select:disabled { opacity: .55; }
.wd-row { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-top: 10px; }
.wd-row label { display: block; }
.wd-row input { position: absolute; opacity: 0; pointer-events: none; }
.wd-row span {
  display: flex; align-items: center; justify-content: center; height: 40px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--card); font-weight: 700; cursor: pointer;
}
.wd-row input:checked + span { background: var(--navy); border-color: var(--navy); color: #fff; }
.wd-row input:focus-visible + span { outline: 2px solid var(--sky); }

/* 登入 */
.login { text-align: center; padding-top: 24px; }
.login img { width: 96px; height: 96px; border-radius: 22px; background: #fff; box-shadow: var(--shadow); }
.login h1 { font-size: 22px; margin: 16px 0 4px; }
.login p { color: var(--muted); margin: 0 0 18px; font-size: 14px; }
.login .in { text-align: center; font-size: 22px; letter-spacing: 3px; text-transform: uppercase; }
.steps { text-align: left; background: var(--blue-bg); border-radius: 12px; padding: 12px 14px; font-size: 14px; margin-bottom: 16px; }
.steps ol { margin: 6px 0 0; padding-left: 20px; }

/* 詳細內容（從下方滑出） */
#sheet { position: fixed; inset: 0; z-index: 20; }
.sheet-bg { position: absolute; inset: 0; background: rgba(10, 14, 30, .45); }
.sheet-card {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 92vh; overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: var(--bg); border-radius: 18px 18px 0 0; padding: 0 16px calc(24px + var(--safe-b));
  max-width: 640px; margin: 0 auto; animation: up .2s ease-out;
}
@keyframes up { from { transform: translateY(40px); opacity: .5; } }
.sheet-head { position: sticky; top: 0; background: var(--bg); display: flex; align-items: center; gap: 8px; padding: 14px 0 8px; z-index: 1; }
.sheet-head h2 { flex: 1; margin: 0; font-size: 18px; line-height: 1.35; word-break: break-word; }
.kv { background: var(--card); border-radius: 14px; padding: 4px 14px; box-shadow: var(--shadow); }
.kv .row { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 15px; }
.kv .row:last-child { border-bottom: 0; }
.kv .k { width: 72px; flex: none; color: var(--muted); }
.kv .v { flex: 1; min-width: 0; word-break: break-word; }
.block { background: var(--card); border-radius: 14px; padding: 12px 14px; box-shadow: var(--shadow); margin-top: 12px; white-space: pre-wrap; word-break: break-word; font-size: 15px; }
.block.red { background: var(--red-bg); }
.block.green { background: var(--green-bg); }
.block .bt { font-weight: 700; display: block; margin-bottom: 4px; white-space: normal; }
.photos { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 10px; }
.photos img, .photos .ph { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 10px; background: var(--line); cursor: pointer; display: block; }
.photos .ph { position: relative; }
.photos .ph img { cursor: default; }
.photos .ph button { position: absolute; top: 4px; right: 4px; border: 0; border-radius: 999px; width: 26px; height: 26px; background: rgba(0,0,0,.6); color: #fff; font-size: 14px; }
.pick { display: flex; align-items: center; justify-content: center; gap: 8px; border: 2px dashed var(--line); border-radius: 12px; padding: 14px; margin-top: 10px; color: var(--navy); font-weight: 700; cursor: pointer; }
@media (prefers-color-scheme: dark) { .pick { color: var(--sky); } }
.pick input { display: none; }

#viewer { position: fixed; inset: 0; z-index: 30; background: rgba(0,0,0,.92); display: flex; align-items: center; justify-content: center; }
#viewer img { max-width: 100%; max-height: 100%; }

#toast {
  position: fixed; left: 50%; bottom: calc(86px + var(--safe-b)); transform: translateX(-50%); z-index: 40;
  background: #1B2033; color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px; max-width: calc(100% - 32px);
  box-shadow: 0 6px 18px rgba(0,0,0,.25);
}
#toast.bad { background: var(--red); }

.profile { display: flex; gap: 14px; align-items: center; }
.avatar { width: 52px; height: 52px; border-radius: 50%; background: var(--navy); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 22px; flex: none; }
.profile .n { font-weight: 800; font-size: 18px; }
.profile .r { color: var(--muted); font-size: 14px; }
.ok-line { color: var(--green); font-weight: 700; }
.foot { text-align: center; color: var(--muted); font-size: 12px; margin-top: 28px; }
