/* 同仁交班系統 視覺系統
   配色與元件沿用庭芳各系統同一套語彙(中央、示範站、物資管理系統)：暖白底、墨綠灰字、庭芳洋紅。
   token 與基礎元件照物資管理系統複製，交班系統自己的元件寫在檔尾。手機優先，電腦同樣好用。 */
:root {
  --bg: #F7F7F3; --surface: #FFFFFF; --surface-2: #F1F2EE; --ink: #303735; --ink-2: #4A524F;
  --muted: #66706D; --ph: #9AA19E; --line: #E3E6E1; --line-2: #D5DAD4;
  --primary: #E4007F; --primary-dark: #B10063; --primary-soft: #FDEEF6; --on-primary: #FFFFFF;
  --ok: #1E6B3C; --ok-soft: #E6F3EA; --warn: #9A5B00; --warn-soft: #FFF3DD; --late: #B3261E; --late-soft: #FCEBE8;
  --focus: rgba(228,0,127,.22);
  --shadow-1: 0 1px 2px rgba(48,55,53,.05), 0 6px 20px rgba(48,55,53,.06);
  --shadow-2: 0 12px 40px rgba(48,55,53,.22);
  --r-lg: 18px; --r-md: 12px; --r-sm: 8px;
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px;
  --fs-xs: 12px; --fs-sm: 14px; --fs-md: 16px; --fs-lg: 18px; --fs-xl: 22px; --fs-2xl: 28px;
  --font: "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", system-ui, -apple-system, sans-serif;
  --mono: ui-monospace, "SF Mono", "Menlo", "Consolas", monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #151817; --surface: #1D2120; --surface-2: #252a28; --ink: #ECEEEB; --ink-2: #CDD2CE;
    --muted: #9AA39F; --ph: #6F7874; --line: #2E3432; --line-2: #3A413E;
    --primary: #FF4DA6; --primary-dark: #FF7ABD; --primary-soft: #3A1C2B; --on-primary: #1B0A12;
    --ok: #6FD19A; --ok-soft: #173325; --warn: #F2B357; --warn-soft: #3A2C12; --late: #FF8A80; --late-soft: #3D1C1A;
    --focus: rgba(255,77,166,.3);
    --shadow-1: 0 1px 2px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.25); --shadow-2: 0 12px 40px rgba(0,0,0,.5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #151817; --surface: #1D2120; --surface-2: #252a28; --ink: #ECEEEB; --ink-2: #CDD2CE;
  --muted: #9AA39F; --ph: #6F7874; --line: #2E3432; --line-2: #3A413E;
  --primary: #FF4DA6; --primary-dark: #FF7ABD; --primary-soft: #3A1C2B; --on-primary: #1B0A12;
  --ok: #6FD19A; --ok-soft: #173325; --warn: #F2B357; --warn-soft: #3A2C12; --late: #FF8A80; --late-soft: #3D1C1A;
  --focus: rgba(255,77,166,.3); color-scheme: dark;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
/* [hidden] 的預設權重最低，任何自己寫的 display 都蓋得過它，所以要 !important */
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { font-family: var(--font); font-size: var(--fs-md); line-height: 1.6; color: var(--ink); background: var(--bg);
       min-height: 100vh; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary-dark); }
.mono { font-family: var(--mono); letter-spacing: .01em; font-variant-numeric: tabular-nums; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

/* ── 卡片、按鈕、輸入 ── */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-1); padding: var(--s4); }
.card + .card { margin-top: var(--s3); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 0; cursor: pointer; font-weight: 700;
       background: var(--primary); color: var(--on-primary); padding: 11px 20px; border-radius: 999px; transition: background .15s, transform .06s;
       box-shadow: 0 2px 8px color-mix(in srgb, var(--primary) 28%, transparent); white-space: nowrap; }
.btn:hover { background: var(--primary-dark); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .4; cursor: default; box-shadow: none; transform: none; }
.btn.ghost { background: var(--surface); color: var(--ink); border: 1.5px solid var(--line-2); box-shadow: none; }
.btn.ghost:hover { border-color: var(--primary); color: var(--primary-dark); background: var(--primary-soft); }
.btn.danger { background: var(--surface); color: var(--late); border: 1.5px solid color-mix(in srgb, var(--late) 40%, var(--line)); box-shadow: none; }
.btn.small { padding: 6px 14px; font-size: var(--fs-sm); }
.btn.block { width: 100%; }
.btn svg { width: 20px; height: 20px; flex: none; }
.actions { display: flex; gap: var(--s2); margin-top: var(--s4); }
.actions .btn { flex: 1; }
.field { display: block; }
.field > span { display: block; font-size: var(--fs-sm); font-weight: 600; color: var(--muted); margin-bottom: 6px; }
input[type=text], input[type=search], input[type=number], input[type=date], input[type=tel], select, textarea {
  width: 100%; background: var(--surface); border: 1.5px solid var(--line-2); border-radius: var(--r-md); padding: 10px 12px; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--focus); }
input::placeholder { color: var(--ph); }

.empty { padding: var(--s6) var(--s4); text-align: center; color: var(--muted); }
.empty svg { width: 40px; height: 40px; opacity: .45; margin-bottom: var(--s2); }

.chip { display: inline-flex; align-items: center; gap: 4px; font-size: var(--fs-xs); font-weight: 700; border-radius: 999px; padding: 2px 9px; line-height: 1.6; white-space: nowrap; }
.chip.ok { background: var(--ok-soft); color: var(--ok); } .chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.late { background: var(--late-soft); color: var(--late); } .chip.muted { background: var(--surface-2); color: var(--muted); }
.chip.primary { background: var(--primary-soft); color: var(--primary-dark); }
.banner { border-radius: var(--r-md); padding: 12px 14px; display: flex; gap: var(--s3); align-items: flex-start; margin-bottom: var(--s3); font-size: var(--fs-sm); }
.banner b { display: block; font-size: var(--fs-md); }
.banner.late { background: var(--late-soft); color: var(--late); } .banner.warn { background: var(--warn-soft); color: var(--warn); }
.banner.ok { background: var(--ok-soft); color: var(--ok); } .banner.info { background: var(--primary-soft); color: var(--primary-dark); }
.banner .btn { margin-left: auto; }
/* ── 彈窗與 toast ── */
.modal-bg { position: fixed; inset: 0; z-index: 70; background: rgba(21,24,23,.5); display: flex; align-items: center; justify-content: center; padding: var(--s4); }
.modal { background: var(--surface); border-radius: var(--r-lg); padding: var(--s5); width: 100%; max-width: 420px; box-shadow: var(--shadow-2); max-height: 86vh; overflow: auto; }
.modal h3 { font-size: var(--fs-lg); margin-bottom: var(--s3); }
.toast { position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 80; background: var(--ink); color: var(--bg);
         padding: 12px 18px; border-radius: 14px; box-shadow: var(--shadow-2); font-weight: 600; max-width: calc(100vw - 32px); text-align: center; }
.toast .tfno { font-family: var(--mono); font-size: var(--fs-xl); display: block; }
@media (min-width: 720px) { .toast { bottom: 32px; } }
.spinner { width: 36px; height: 36px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--primary); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading { display: flex; flex-direction: column; align-items: center; gap: var(--s3); padding: var(--s6) var(--s4); color: var(--muted); }

/* ── 登入頁(版面照示範站 demo.tinfun.org.tw，Jacky 指定的各系統登入範本)── */
.gate { max-width: 26rem; margin: 0 auto; padding: 1.5rem 1.25rem 2.5rem; text-align: center; }
.gate .logo { width: 88px; height: 88px; border-radius: 50%; display: block; margin: 0 auto .7rem; box-shadow: 0 6px 18px rgba(48,55,53,.16); }
.gate h1 { font-size: 1.45rem; margin-bottom: 1rem; }
.gate .card { --欄寬: 200px; max-width: 16rem; margin: 0 auto; padding: 1.5rem 1.4rem; text-align: left; }
.gate .field { width: var(--欄寬); margin: 0 auto 1.1rem; }
.gate #code { font-size: 28px; letter-spacing: 12px; text-align: center; padding: 10px 0 10px 12px; border-width: 2px; }
.gate .login-actions { display: flex; gap: .6rem; width: var(--欄寬); margin: 0 auto; }
.gate .login-actions .btn { flex: 1 1 0; padding: .85em 0; font-size: 1.05rem; }
.gate .login-actions .btn svg { width: 30px; height: 30px; }
.gate .forgot { width: var(--欄寬); margin: 1rem auto 0; text-align: right; font-size: .875rem; }
.gate .forgot a { color: var(--muted); text-underline-offset: 3px; }
.gate .notice { max-width: 22rem; margin: 1rem auto 0; }

/* ══ 交班系統自己的元件 ══════════════════════════════════════ */

/* ── 頂欄：左邊品牌，右邊名字選單(手機)或一排文字連結(電腦) ── */
.top { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 90%, transparent);
       backdrop-filter: saturate(1.2) blur(10px); -webkit-backdrop-filter: saturate(1.2) blur(10px); border-bottom: 1px solid var(--line); }
.top-in { max-width: 880px; margin: 0 auto; padding: var(--s2) var(--s4); display: flex; align-items: center; gap: var(--s3); min-height: 56px; }
.brand { display: flex; align-items: center; gap: var(--s2); font-weight: 800; font-size: var(--fs-lg); letter-spacing: .02em;
         white-space: nowrap; color: var(--ink); text-decoration: none; }
.brand img { width: 32px; height: 32px; border-radius: 50%; }
.me { margin-left: auto; position: relative; }
.me-links { display: flex; align-items: center; gap: var(--s4); font-size: var(--fs-sm); white-space: nowrap; }
.me-links b { color: var(--ink); }
.me-links a, .me-links button { color: var(--ink-2); text-decoration: underline; text-underline-offset: 3px; background: none; border: 0;
                                padding: 4px 0; font: inherit; cursor: pointer; }
.me-links a:hover, .me-links button:hover { color: var(--primary-dark); }
.me-btn { border: 1px solid var(--line-2); background: var(--surface); border-radius: 999px; padding: 6px 14px;
          display: none; align-items: center; gap: 6px; cursor: pointer; font-size: var(--fs-sm); color: var(--ink-2); }
.menu { position: absolute; right: 0; top: calc(100% + 6px); background: var(--surface); border: 1px solid var(--line);
        border-radius: var(--r-md); box-shadow: var(--shadow-2); min-width: 200px; padding: 6px; z-index: 30; }
.menu button, .menu a { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 12px;
        border-radius: var(--r-sm); cursor: pointer; color: var(--ink); text-decoration: none; font-size: var(--fs-md); }
.menu button:hover, .menu a:hover { background: var(--surface-2); }
@media (max-width: 719px) {
  .me-links { display: none; }
  .me-btn { display: flex; }
  .top { background: var(--bg); }
  .brand span { font-size: var(--fs-md); }
}
@media (min-width: 720px) { .menu { display: none !important; } }

main { max-width: 880px; margin: 0 auto; padding: var(--s4) var(--s4) calc(var(--s6) + env(safe-area-inset-bottom)); }
.page-title { font-size: var(--fs-xl); font-weight: 800; letter-spacing: .01em; }
.section-title { font-size: var(--fs-sm); font-weight: 700; color: var(--muted); letter-spacing: .08em; margin: var(--s5) 0 var(--s3);
                 display: flex; align-items: center; gap: var(--s2); }
.section-title a { margin-left: auto; font-weight: 600; letter-spacing: 0; }
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); text-decoration: none; font-weight: 600;
        font-size: var(--fs-sm); padding: 6px 0; margin-bottom: var(--s2); }
.back svg { width: 18px; height: 18px; }
.back:hover { color: var(--primary-dark); }
.head-row { display: flex; align-items: center; gap: var(--s3); margin-bottom: var(--s3); }

/* ── 首頁上半：四個生活班，手機兩欄、電腦四欄 ── */
.class-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--s3); }
@media (min-width: 720px) { .class-grid { grid-template-columns: repeat(4, 1fr); } }
.class-btn { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--s2);
             min-height: 120px; padding: var(--s4); border-radius: var(--r-lg); background: var(--surface);
             border: 1px solid var(--line); box-shadow: var(--shadow-1); color: var(--ink); text-decoration: none;
             transition: transform .08s, border-color .15s, box-shadow .15s; }
.class-btn:hover { border-color: color-mix(in srgb, var(--primary) 45%, var(--line)); }
.class-btn:active { transform: scale(.98); }
.class-btn .num { width: 52px; height: 52px; border-radius: 16px; display: grid; place-items: center;
                  background: var(--primary-soft); color: var(--primary-dark); font-size: var(--fs-2xl); font-weight: 800; }
.class-btn b { font-size: var(--fs-lg); }
.class-btn small { color: var(--muted); font-size: var(--fs-xs); }

/* ── 院生名單 ── */
.list { display: flex; flex-direction: column; gap: var(--s2); }
.row-link { display: flex; align-items: center; gap: var(--s3); padding: 14px var(--s4); background: var(--surface);
            border: 1px solid var(--line); border-radius: var(--r-md); color: var(--ink); text-decoration: none; min-height: 64px; }
.row-link:hover { border-color: color-mix(in srgb, var(--primary) 45%, var(--line)); }
.row-link .body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.row-link .name { font-weight: 700; font-size: var(--fs-lg); line-height: 1.35; }
/* 最近一則放名字下面，手機上才有空間；最多兩行 */
.row-link .latest { color: var(--ink-2); font-size: var(--fs-sm); line-height: 1.5; overflow: hidden;
                    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
/* 最近一則：內容在前、時間在後，時間用庭芳洋紅區分(Jacky 2026-09-24) */
.row-link .latest .when { color: var(--primary-dark); margin-left: 8px; font-size: var(--fs-xs); font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }
.row-link .latest.none { color: var(--ph); }
.row-link .chev { color: var(--ph); flex: none; }
.row-link .chev svg { width: 18px; height: 18px; display: block; }

/* ── 院生頁：上面紀錄、下面寫 ── */
.composer { position: sticky; bottom: 0; z-index: 10; background: var(--bg); padding: var(--s3) 0 calc(var(--s3) + env(safe-area-inset-bottom));
            border-top: 1px solid var(--line); margin-top: var(--s4); }
.composer textarea { min-height: 96px; resize: vertical; line-height: 1.6; font-size: var(--fs-md); }
.composer .bar { display: flex; gap: var(--s2); margin-top: var(--s2); align-items: center; }
.composer .bar .btn.send { margin-left: auto; min-width: 7em; }
.mic { width: 52px; height: 52px; border-radius: 50%; padding: 0; flex: none; }
.mic svg { width: 26px; height: 26px; }
.mic.rec { background: var(--late); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--late) 45%, transparent); } 50% { box-shadow: 0 0 0 10px transparent; } }
.rec-time { font-variant-numeric: tabular-nums; color: var(--late); font-weight: 700; font-size: var(--fs-sm); }
.hint { color: var(--muted); font-size: var(--fs-sm); }

.entries { display: flex; flex-direction: column; gap: var(--s3); }
.entry { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: var(--s3) var(--s4); }
.entry .meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; font-size: var(--fs-xs); color: var(--muted); margin-bottom: 6px; }
.entry .meta b { color: var(--ink-2); font-size: var(--fs-sm); }
.entry .text { white-space: pre-wrap; word-break: break-word; font-size: var(--fs-md); }
.entry .more { margin-top: var(--s2); font-size: var(--fs-sm); }
.entry .more summary { cursor: pointer; color: var(--muted); }
.entry .more .orig { margin-top: 6px; padding: var(--s2) var(--s3); background: var(--surface-2); border-radius: var(--r-sm);
                     white-space: pre-wrap; color: var(--ink-2); }
.entry .tools { margin-top: var(--s2); display: flex; gap: var(--s2); }
.entry.mine { border-left: 3px solid var(--primary); }
.load-more { display: block; margin: var(--s3) auto 0; }

/* ── 總結 ── */
.summary { white-space: pre-wrap; word-break: break-word; line-height: 1.75; }
.summary-card .meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: var(--s3); font-size: var(--fs-sm); color: var(--muted); }
.alert { display: block; background: var(--late-soft); color: var(--late); border-radius: var(--r-md); padding: 12px 14px;
         font-weight: 700; margin-bottom: var(--s3); text-decoration: none; }
.alert small { display: block; font-weight: 500; }

/* 已修改：可以點的小標籤；修改歷史放卡片裡 */
button.chip { border: 0; cursor: pointer; font: inherit; font-size: var(--fs-xs); font-weight: 700; }
button.chip[aria-expanded="true"] { background: var(--primary-soft); color: var(--primary-dark); }
.history .orig { margin-top: 6px; padding: var(--s2) var(--s3); background: var(--surface-2); border-radius: var(--r-sm); white-space: pre-wrap; color: var(--ink-2); font-size: var(--fs-sm); }
.history .orig .meta { margin-bottom: 2px; }
.modal textarea { width: 100%; min-height: 140px; }

/* 院生頁紀錄：內容在前，作者、時間、標籤在下面一行；時間用洋紅(Jacky 2026-09-24) */
.entry .meta.after { margin: 8px 0 0; }
.entry .meta .when { color: var(--primary-dark); font-weight: 600; font-variant-numeric: tabular-nums; }

/* 生活班名單頁：頂欄以下的「回首頁＋班名」黏住不動，只有名單捲動(Jacky 2026-09-24)。
   top 對齊頂欄實際高度(app.js 量好放進 --top-h)；底色蓋住捲上來的卡片 */
.sticky-head { position: sticky; top: var(--top-h, 57px); z-index: 15; background: var(--bg);
               margin: calc(-1 * var(--s4)) calc(-1 * var(--s4)) var(--s3); padding: var(--s4) var(--s4) var(--s3);
               border-bottom: 1px solid var(--line); }
.sticky-head .head-row { margin-bottom: 0; }
