/* 管理儀表板 視覺系統
   配色與元件沿用庭芳各系統同一套語彙(交班系統、物資管理系統、示範站)：暖白底、墨綠灰字、庭芳洋紅。
   基礎 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); }

/* 空狀態與轉圈圈同高(100px)：院生頁跳下一位時轉圈圈換成「還沒有紀錄」版面不會抖(Jacky 2026-09-25) */
.empty { min-height: 100px; box-sizing: border-box; display: grid; align-content: center; justify-items: center; padding: var(--s4); text-align: center; color: var(--muted); }  /* 用 grid 不用 flex column：中文純文字當匿名 flex item 會被一字一行折起來 */
.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 { min-height: 100px; box-sizing: border-box; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--s3); padding: 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); }

/* ══ 儀表板自己的元件 ══════════════════════════════════════ */
.admin-link { font-size: var(--fs-sm); font-weight: 700; color: var(--primary-dark); text-decoration: none;
              padding: 6px 12px; border-radius: 999px; background: var(--primary-soft); margin-right: var(--s3); }
.admin-link:hover { background: color-mix(in srgb, var(--primary) 18%, var(--surface)); }
.me { display: flex; align-items: center; }
/* 手機版不出現「管理」(Jacky 2026-09-26)，只在電腦版的右上角 */
@media (max-width: 719px) { .admin-link { display: none !important; } }
table.money tbody tr:not(.sum):hover td { background: color-mix(in srgb, var(--surface-2) 60%, var(--surface)); }   /* 不透明：黏住的格子底下有內容捲過去 */

/* 圖表的顏色(dataviz 預設分類色第 1、2 格，已跑 validate_palette 亮暗兩種都通過)。
   喜大人＝第 1 格藍、庭芳＝第 2 格橘，顏色跟著機構走，不跟著排名走。 */
:root { --s-joyelder: #2a78d6; --s-tinfun: #eb6834; --s-single: #2a78d6; --grid: #E3E6E1; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --s-joyelder: #3987e5; --s-tinfun: #d95926; --s-single: #3987e5; --grid: #2E3432; } }
:root[data-theme="dark"] { --s-joyelder: #3987e5; --s-tinfun: #d95926; --s-single: #3987e5; --grid: #2E3432; }

/* ── 抓取狀態列(定案 5) ── */
.fetch { display: flex; align-items: center; gap: var(--s2); font-size: var(--fs-sm); color: var(--muted); margin-bottom: var(--s4); flex-wrap: wrap; }
.fetch .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); flex: none; }
.fetch.bad { color: var(--late); font-weight: 600; }
.fetch.bad .dot { background: var(--late); }
.fetch b { font-variant-numeric: tabular-nums; }

/* ── 首頁卡片 ── */
.block-card { display: block; text-decoration: none; color: inherit; transition: border-color .15s, transform .06s; }
.block-card:hover { border-color: color-mix(in srgb, var(--primary) 45%, var(--line)); }
.block-card:active { transform: scale(.995); }
.block-head { display: flex; align-items: center; gap: var(--s2); margin-bottom: var(--s3); }
.block-head h2 { font-size: var(--fs-lg); font-weight: 800; }
.block-head .chev { margin-left: auto; color: var(--ph); }
.block-head .chev svg { width: 20px; height: 20px; display: block; }
.hero { display: flex; align-items: baseline; gap: var(--s2); flex-wrap: wrap; }
.hero .label { font-size: var(--fs-sm); color: var(--muted); font-weight: 600; width: 100%; }
.hero .num { font-size: 48px; font-weight: 800; letter-spacing: -.01em; line-height: 1.05; font-variant-numeric: tabular-nums; }
.hero .unit { font-size: var(--fs-md); color: var(--muted); font-weight: 600; }
.kpis { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s3); margin-top: var(--s4); }
.kpi { background: var(--surface-2); border-radius: var(--r-md); padding: 10px 12px; }
.kpi .label { font-size: var(--fs-xs); color: var(--muted); font-weight: 600; }
.kpi .v { font-size: var(--fs-xl); font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.3; }
.kpi .sub { font-size: var(--fs-xs); color: var(--muted); font-variant-numeric: tabular-nums; }
.orgs { display: flex; gap: var(--s4); margin-top: var(--s3); font-size: var(--fs-sm); color: var(--ink-2); flex-wrap: wrap; }
.orgs span { display: inline-flex; align-items: center; gap: 6px; font-variant-numeric: tabular-nums; }
.sw { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex: none; }
.spark { margin-top: var(--s1); }
@media (min-width: 720px) { .kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); } }

/* ── 圖表 ── */
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart text { font-family: var(--font); font-size: 11px; fill: var(--muted); font-variant-numeric: tabular-nums; }
.chart text.unit { font-weight: 600; }
.spark-title { font-size: var(--fs-sm); font-weight: 700; color: var(--muted); margin-top: var(--s4); }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .hit { fill: transparent; cursor: default; }
.chart .hit:hover + .bar-group path, .chart g.col:hover path { opacity: .85; }
.legend { display: flex; gap: var(--s4); font-size: var(--fs-sm); color: var(--ink-2); margin: var(--s2) 0 var(--s3); flex-wrap: wrap; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.tip { position: fixed; z-index: 90; pointer-events: none; background: var(--ink); color: var(--bg); border-radius: 10px;
       padding: 8px 10px; font-size: var(--fs-sm); line-height: 1.5; box-shadow: var(--shadow-2); max-width: 240px; font-variant-numeric: tabular-nums; }
.tip b { display: block; margin-bottom: 2px; }
.tip .r { display: flex; align-items: center; gap: 6px; justify-content: space-between; }
.tip .r span:last-child { margin-left: var(--s3); font-weight: 700; }

/* ── 費用表：凍結四周(Jacky 2026-09-26)──
   上方標題列、左邊第一欄、底部合計列固定，只有中間的數字上下左右捲。
   捲的是表格自己的框(限高在畫面內)，不是整頁。
   border-collapse 用 separate：collapse 的時候黏住的格子框線會跟著捲走。 */
.tbl-wrap { overflow: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
            max-height: min(70vh, 560px); border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface); }
.tbl-wrap table.grid { border: 0; border-radius: 0; min-width: 640px; border-collapse: separate; border-spacing: 0; overflow: visible; }
table.money td.n, table.money th.n { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.money thead th { position: sticky; top: 0; z-index: 2; background: var(--surface-2); }
table.money th:first-child, table.money td:first-child { position: sticky; left: 0; z-index: 1; background: var(--surface); white-space: nowrap;
  box-shadow: 1px 0 0 var(--line); }
table.money tr.sum td { position: sticky; bottom: 0; z-index: 2; border-top: 0; box-shadow: 0 -2px 0 var(--line-2); font-weight: 800; background: var(--surface-2); }
table.money thead th:first-child, table.money tr.sum td:first-child { z-index: 3; background: var(--surface-2); }
table.money td.sub { background: color-mix(in srgb, var(--surface-2) 55%, var(--surface)); font-weight: 700; }
table.money tr.sum td.sub { background: var(--surface-2); }
table.money td.tot { font-weight: 800; }
table.money tr.link { cursor: pointer; }
table.money tr.link td:first-child a { font-weight: 700; text-decoration: none; }
.note { font-size: var(--fs-xs); color: var(--muted); margin-top: var(--s2); line-height: 1.7; }
.rate { font-size: var(--fs-sm); color: var(--muted); margin-bottom: var(--s2); }

/* ── 來源狀態(明細頁底下) ── */
.sources { display: grid; gap: var(--s2); }
.src { display: flex; gap: var(--s2); align-items: flex-start; font-size: var(--fs-sm); padding: 10px 12px; border-radius: var(--r-md); background: var(--surface-2); }
.src b { white-space: nowrap; }
.src .msg { color: var(--muted); flex: 1; min-width: 0; }
.src.bad { background: var(--late-soft); color: var(--late); }
.src.bad .msg { color: var(--late); }
.src.warn { background: var(--warn-soft); color: var(--warn); }
.src.warn .msg { color: var(--warn); }

/* ── 管理頁 ── */
.admin-tabs { display: flex; gap: 4px; margin-bottom: var(--s4); border-bottom: 1px solid var(--line); padding-bottom: var(--s2); overflow-x: auto; }
.admin-tabs .tab { padding: 8px 16px; border-radius: 999px; font-weight: 600; color: var(--muted); text-decoration: none; white-space: nowrap; }
.admin-tabs .tab[aria-current="page"] { background: var(--primary-soft); color: var(--primary-dark); }
table.grid { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); overflow: hidden; font-size: var(--fs-sm); }
table.grid th, table.grid td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
table.grid th { background: var(--surface-2); color: var(--muted); font-weight: 700; font-size: var(--fs-xs); letter-spacing: .04em; white-space: nowrap; }
table.grid tr:last-child td { border-bottom: 0; }
table.grid tr.off td { color: var(--muted); }
table.grid select { width: auto; padding: 6px 10px; }
.toolbar { display: flex; align-items: flex-end; gap: var(--s3); margin-bottom: var(--s3); flex-wrap: wrap; }
.toolbar .spacer { flex: 1; }
.toolbar .field { min-width: 130px; }
.hint { color: var(--muted); font-size: var(--fs-sm); }
.pick { max-height: 46vh; overflow: auto; border: 1px solid var(--line); border-radius: var(--r-md); margin: var(--s3) 0; }
.pick-row { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); cursor: pointer; }
.pick-row:last-child { border-bottom: 0; }
.pick-row input { width: 18px; height: 18px; flex: none; }
/* 膠囊選項(角色、區塊)：「按鈕」一律做成膠囊 */
.pills { display: flex; gap: 6px; flex-wrap: wrap; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 6px 14px; border-radius: 999px; border: 1.5px solid var(--line-2);
        background: var(--surface); cursor: pointer; font-size: var(--fs-sm); font-weight: 600; color: var(--ink-2); user-select: none; }
.pill input { position: absolute; opacity: 0; pointer-events: none; }
.pill:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); color: var(--primary-dark); }
.pill:has(input:disabled) { opacity: .5; cursor: default; }
.pill:has(input:focus-visible) { outline: 3px solid var(--focus); outline-offset: 2px; }
.load-more { display: block; margin: var(--s3) auto 0; }
@media (max-width: 719px) {
  table.grid.stack thead { display: none; }
  table.grid.stack tr { display: grid; grid-template-columns: 1fr auto; gap: 4px 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
  table.grid.stack td { border: 0; padding: 0; }
  table.grid.stack td[data-full] { grid-column: 1 / -1; }
}
