:root {
  --bg: #f6f7f4; --surface: #ffffff; --surface-2: #eef1ea; --border: #d9ded3;
  --text: #1d2420; --text-2: #4c5650; --muted: #78827b;
  --brand: #2f6b3a; --brand-ink: #ffffff; --brand-soft: #e3efe3;
  --star: #e2a100; --star-off: #cfd5cc;
  --good: #1f7a3a; --warn: #a86400; --bad: #b3261e;
  --s1: #2a78d6; --s2: #eb6834;
  --radius: 12px; --shadow: 0 1px 2px rgba(0,0,0,.06), 0 2px 8px rgba(0,0,0,.04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141614; --surface: #1d201d; --surface-2: #262a26; --border: #353a35;
    --text: #eef1ec; --text-2: #c2c8c1; --muted: #8f978f;
    --brand: #5fa66c; --brand-ink: #0d1a10; --brand-soft: #23352626;
    --star: #f0b429; --star-off: #474d47;
    --good: #5cc27a; --warn: #e0a040; --bad: #ef6a60;
    --s1: #3987e5; --s2: #d95926;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC", "Microsoft JhengHei", "Noto Sans TC", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
a { color: var(--brand); }
header.top {
  position: sticky; top: 0; z-index: 10; background: var(--brand); color: var(--brand-ink);
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
header.top h1 { font-size: 17px; margin: 0; font-weight: 650; flex: 1; min-width: 160px; }
header.top .who { font-size: 13px; opacity: .9; }
main { max-width: 980px; margin: 0 auto; padding: 16px; padding-bottom: 96px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow); }
.card h2 { margin: 0 0 6px; font-size: 17px; }
.card h3 { margin: 14px 0 6px; font-size: 15px; }
.muted { color: var(--muted); font-size: 13px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
button, .btn {
  font: inherit; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 8px 14px; border-radius: 10px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px;
  min-height: 40px;
}
button:hover { border-color: var(--brand); }
button.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); font-weight: 600; }
button.danger { color: var(--bad); }
button.small { padding: 4px 10px; min-height: 32px; font-size: 13px; }
button:disabled { opacity: .5; cursor: default; }
input[type=text], input[type=email], input[type=number], select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; width: 100%;
}
textarea { min-height: 84px; resize: vertical; }
label.chk { display: inline-flex; gap: 6px; align-items: center; font-size: 14px; margin-right: 12px; white-space: nowrap; }
.pill { display: inline-block; font-size: 12px; padding: 2px 9px; border-radius: 999px; background: var(--surface-2); color: var(--text-2); white-space: nowrap; }
.pill.ok { background: color-mix(in srgb, var(--good) 15%, transparent); color: var(--good); }
.pill.draft { background: color-mix(in srgb, var(--warn) 15%, transparent); color: var(--warn); }
.pill.none { background: var(--surface-2); color: var(--muted); }

/* Reviewer */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 10px; scrollbar-width: thin; }
.chip { flex: none; border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 6px 12px; font-size: 14px; cursor: pointer; min-height: 36px; }
.chip.active { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.chip .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--star-off); margin-right: 6px; vertical-align: middle; }
.chip .dot.full { background: var(--good); } .chip .dot.part { background: var(--warn); }
.q { padding: 12px 0; border-top: 1px solid var(--border); }
.q:first-of-type { border-top: 0; }
.q .qt { margin-bottom: 8px; }
.q .req { color: var(--bad); }
.stars { display: flex; gap: 4px; }
.stars button { border: 0; background: transparent; font-size: 30px; line-height: 1; padding: 2px 4px; min-height: 44px; color: var(--star-off); }
.stars button.on { color: var(--star); }
.stars .lbl { font-size: 13px; color: var(--muted); align-self: center; margin-left: 6px; }
.choices { display: flex; gap: 8px; flex-wrap: wrap; }
.choices button.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.bar-bottom {
  position: fixed; left: 0; right: 0; bottom: 0; background: var(--surface); border-top: 1px solid var(--border);
  padding: 10px 16px; padding-bottom: max(10px, env(safe-area-inset-bottom)); display: flex; gap: 10px; align-items: center; z-index: 10; flex-wrap: wrap;
}
.bar-bottom .status { font-size: 13px; color: var(--muted); flex: 1; min-width: 120px; }
.missing { outline: 2px solid var(--bad); outline-offset: 4px; border-radius: 6px; }
.banner { padding: 10px 14px; border-radius: 10px; margin-bottom: 12px; font-size: 14px; }
.banner.info { background: var(--brand-soft); border: 1px solid var(--border); }
.banner.warn { background: color-mix(in srgb, var(--warn) 12%, transparent); border: 1px solid color-mix(in srgb, var(--warn) 40%, transparent); }
.banner.err { background: color-mix(in srgb, var(--bad) 12%, transparent); border: 1px solid color-mix(in srgb, var(--bad) 40%, transparent); }
.progress { height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--brand); border-radius: 999px; }

/* Admin */
nav.tabs { display: flex; gap: 4px; overflow-x: auto; background: var(--surface); border-bottom: 1px solid var(--border); padding: 0 12px; position: sticky; top: 52px; z-index: 9; }
nav.tabs button { border: 0; border-bottom: 3px solid transparent; border-radius: 0; background: transparent; padding: 12px 12px; white-space: nowrap; }
nav.tabs button.active { border-bottom-color: var(--brand); color: var(--brand); font-weight: 600; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .02em; cursor: default; }
th.sort { cursor: pointer; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.grade { display: inline-grid; place-items: center; min-width: 30px; height: 26px; padding: 0 6px; border-radius: 6px; font-weight: 700; font-size: 14px; background: var(--surface-2); }
.grade.A { background: color-mix(in srgb, var(--good) 20%, transparent); color: var(--good); }
.grade.B { background: color-mix(in srgb, var(--s1) 18%, transparent); color: var(--s1); }
.grade.C { background: var(--surface-2); }
.grade.D, .grade.E { background: color-mix(in srgb, var(--bad) 15%, transparent); color: var(--bad); }
.delta.up { color: var(--good); } .delta.down { color: var(--bad); } .delta.flat { color: var(--muted); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin: 10px 0; }
.kpi { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; }
.kpi .v { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi .l { font-size: 12px; color: var(--muted); }
.legend { display: flex; gap: 14px; font-size: 13px; color: var(--text-2); margin: 6px 0; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -1px; margin-right: 5px; }
.qbar { display: grid; grid-template-columns: minmax(140px, 1.3fr) 2fr; gap: 6px 12px; align-items: center; margin: 4px 0 10px; }
.qbar .qlabel { font-size: 13px; color: var(--text-2); }
.qbar .bars { position: relative; }
.qbar .b { height: 10px; border-radius: 0 4px 4px 0; margin: 2px 0; position: relative; }
.qbar .b span { position: absolute; left: calc(100% + 6px); top: -4px; font-size: 12px; color: var(--text-2); white-space: nowrap; font-variant-numeric: tabular-nums; }
.qbar .b.cur { background: var(--s1); } .qbar .b.prev { background: var(--s2); }
.comment { border-left: 3px solid var(--border); padding: 4px 10px; margin: 6px 0; font-size: 14px; white-space: pre-wrap; }
.comment .by { font-size: 12px; color: var(--muted); }
.summary-text { background: var(--surface-2); border-radius: 10px; padding: 12px 14px; font-size: 14px; }
.summary-text ul { margin: 6px 0; padding-left: 20px; }
.hidden { display: none !important; }
.tip { position: fixed; pointer-events: none; background: var(--text); color: var(--bg); font-size: 12px; padding: 4px 8px; border-radius: 6px; z-index: 100; }
code.link { font-size: 12px; word-break: break-all; background: var(--surface-2); padding: 2px 6px; border-radius: 6px; }
details summary { cursor: pointer; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 640px) { .grid2 { grid-template-columns: 1fr; } .qbar { grid-template-columns: 1fr; } nav.tabs { top: 0; position: static; } }

@media print {
  :root { --bg: #fff; --surface: #fff; --text: #000; --text-2: #222; --muted: #555; --border: #bbb; --surface-2: #f1f1f1; color-scheme: light; }
  header.top, nav.tabs, .no-print, .bar-bottom { display: none !important; }
  main { max-width: none; padding: 0; }
  .card { box-shadow: none; border: 0; padding: 0 0 12px; page-break-inside: auto; }
  .print-break { page-break-before: always; }
  .print-only { display: block !important; }
  body { font-size: 12px; }
  .qbar .b { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .grade, .kpi { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
.print-only { display: none; }
.table-wrap td:first-child b { white-space: nowrap; }
#ptable { min-width: 1180px; }
#ptable select { min-width: 130px; }
#ptable input[type=text], #ptable input[type=email] { padding: 6px 8px; }

/* ---------- 個人總結 summary sheet (mirrors the Excel layout) ---------- */
.xsheet { background: #fff; color: #000; font-family: Calibri, "Microsoft JhengHei", "PingFang TC", "Noto Sans TC", Arial, sans-serif; font-size: 13px;
  padding: 28px 32px; border: 1px solid var(--border); border-radius: 6px; margin-bottom: 16px; overflow-x: auto; color-scheme: light; }
.xsheet .xs-h1 { font-family: Arial, "Microsoft JhengHei", sans-serif; font-weight: 700; font-size: 18px; line-height: 1.35; }
.xsheet .xs-info { display: flex; gap: 120px; margin: 14px 0 18px; flex-wrap: wrap; }
.xsheet table { border-collapse: collapse; width: auto; font-size: 12px; }
.xsheet td, .xsheet th { border: 1px solid #000; padding: 1px 8px; text-transform: none; letter-spacing: 0; color: #000; font-size: 12px; vertical-align: middle; }
.xsheet .xs-box { border: 2px solid #000; }
.xsheet .xs-box td { padding: 0 6px; height: 16px; font-size: 11px; }
.xsheet .xs-box td:first-child { width: 72px; }
.xsheet .xs-box td.c { width: 78px; text-align: center; }
.xsheet .xs-grades td:first-child { width: 100px; }
.xsheet .b { font-weight: 700; }
.xsheet .xs-main { display: flex; gap: 22px; align-items: flex-start; }
.xsheet .xs-tbl { min-width: 780px; }
.xsheet .xs-tbl th { background: #bdd7ee; font-weight: 700; text-align: center; min-width: 76px; height: 18px; }
.xsheet .xs-tbl th.l { text-align: left; min-width: 380px; }
.xsheet .xs-tbl td { text-align: center; height: 28px; }
.xsheet .xs-tbl td.l { text-align: left; }
.xsheet .xs-tbl tr.tot td { background: #ddebf7; font-weight: 700; }
.xsheet .xs-prior { min-width: 92px; }
.xsheet .xs-prior td.pl { font-weight: 700; text-align: left; height: 18px; }
.xsheet .xs-sect { margin-top: 30px; background: #d9d9d9; border: 1px solid #000; font-weight: 700; padding: 3px 4px; max-width: 784px; }
.xsheet .xs-sect.boxed { margin-top: 26px; }
.xsheet .xs-cm { padding: 2px 2px; max-width: 784px; white-space: pre-wrap; }
.xsheet .xs-by { color: #555; font-size: 11px; }
.xsheet .xs-bossbox { border: 1px solid #000; border-top: 0; min-height: 150px; padding: 4px 4px 14px; max-width: 784px; box-sizing: border-box; }
.xsheet .xs-bossbox p { margin: 0 0 2px; white-space: pre-wrap; line-height: 1.6; }
@media print {
  @page { size: letter landscape; margin: 0.45in; }
  .xsheet { border: 0; padding: 0; margin: 0; overflow: visible; }
  .xsheet .xs-tbl th, .xsheet .xs-tbl tr.tot td, .xsheet .xs-sect { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
.xsheet .xs-note { font-size: 10px; color: #555; margin-top: 4px; font-style: italic; }
@media print { #toast { display: none !important; } }
.legend-note { margin-top: 6px; font-size: 13px; color: var(--text-2); background: var(--surface-2); border-radius: 8px; padding: 4px 10px; display: inline-block; }
header.top .logo { height: 36px; width: auto; background: #fff; border-radius: 8px; padding: 3px 6px; flex: none; }
@media print { header.top .logo { display: none; } }
