:root {
  --bg: #f4f1ea;
  --card: #ffffff;
  --ink: #1d2a2f;
  --muted: #56656b;
  --line: #ddd7cb;
  --soft: #f8f6f1;
  --brand: #0e6b62;
  --brand-dark: #0a534c;
  --brand-soft: #e1f0ec;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --warn: #8a5a00;
  --warn-soft: #fff4dc;
  --gC: #a14d06; --gC-bg: #fdecc8;
  --gB: #0e6b62; --gB-bg: #d8efe9;
  --gA: #276b2b; --gA-bg: #dcefd8;
  --radius: 14px;
  --nav-h: 66px;
  color-scheme: light;
}
* { box-sizing: border-box; }
html { font-size: 18px; -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  line-height: 1.55;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--brand); }
.boot { padding: 40vh 16px 0; text-align: center; color: var(--muted); }
.muted { color: var(--muted); }
.hidden { display: none !important; }

/* ---------- 版面 ---------- */
.top {
  position: sticky; top: 0; z-index: 20; background: var(--brand); color: #fff;
  display: flex; align-items: center; gap: 12px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
}
.top .org { font-weight: 700; font-size: 19px; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top .me-btn {
  background: rgba(255,255,255,.16); border: 0; color: #fff; border-radius: 999px;
  padding: 6px 14px; min-height: 40px; font-size: 16px; display: flex; align-items: center; gap: 6px;
}
main { max-width: 780px; margin: 0 auto; padding: 16px 16px calc(var(--nav-h) + 40px + env(safe-area-inset-bottom)); }
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; background: #fff;
  border-top: 1px solid var(--line); display: flex; justify-content: center;
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs .in { display: flex; width: 100%; max-width: 780px; }
.tabs button {
  flex: 1; border: 0; background: none; height: var(--nav-h); display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 2px; color: var(--muted); font-size: 15px; font-weight: 600;
}
.tabs button svg { width: 26px; height: 26px; }
.tabs button.on { color: var(--brand); }
.tabs button.on svg { stroke-width: 2.4; }
h2.ttl { font-size: 22px; margin: 4px 0 12px; }
.sec-t { font-size: 16px; font-weight: 700; color: var(--muted); margin: 20px 4px 8px; }

/* ---------- 按鈕、輸入 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 52px; padding: 0 20px; border-radius: var(--radius); border: 1.5px solid var(--line);
  background: #fff; font-size: 18px; font-weight: 600; color: var(--ink);
}
.btn svg { width: 22px; height: 22px; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:active { background: var(--brand-dark); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: #f0c5c0; }
.btn.block { display: flex; width: 100%; }
.btn.small { min-height: 42px; padding: 0 14px; font-size: 16px; border-radius: 12px; }
.btn:disabled { opacity: .45; cursor: default; }
.btns { display: flex; flex-wrap: wrap; gap: 10px; }
.btns .sp { flex: 1; }
.btns.acts { margin-top: 12px; }
.link { background: none; border: 0; color: var(--brand); padding: 6px 4px; font-size: 16px; min-height: 40px; }
.link.danger { color: var(--danger); }
input[type=text], input[type=tel], input[type=email], input[type=search], input[type=date], input[type=month], input:not([type]), textarea, select {
  width: 100%; min-height: 52px; padding: 10px 14px; border: 1.5px solid var(--line); border-radius: 12px;
  background: #fff; font-size: 18px; outline: none;
}
textarea { resize: vertical; min-height: 52px; line-height: 1.5; }
input:focus, textarea:focus, select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
label.f { display: block; font-size: 16px; font-weight: 600; color: var(--muted); margin: 14px 2px 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; min-height: 42px; padding: 0 14px;
  border-radius: 999px; border: 1.5px solid var(--line); background: #fff; font-size: 16px; font-weight: 600;
}
.chip.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.g { display: inline-flex; align-items: center; justify-content: center; min-width: 30px; height: 26px; padding: 0 7px;
  border-radius: 8px; font-size: 15px; font-weight: 800; }
.g.C { color: var(--gC); background: var(--gC-bg); }
.g.B { color: var(--gB); background: var(--gB-bg); }
.g.A { color: var(--gA); background: var(--gA-bg); }
.tag { display: inline-block; font-size: 14px; padding: 1px 8px; border-radius: 6px; background: #ece8df; color: var(--muted); font-weight: 600; }
.tag.lost { background: #ece8df; }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 16px; }
.empty { text-align: center; color: var(--muted); padding: 28px 8px; }
.msg-err { color: var(--danger); font-size: 16px; margin-top: 8px; }

/* ---------- 登入 ---------- */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 420px; background: #fff; border-radius: 24px; padding: 32px 22px; text-align: center; border: 1px solid var(--line); }
.login-card .logo { width: 72px; height: 72px; margin: 0 auto 12px; }
.login-card h1 { font-size: 26px; margin: 0 0 24px; }
.login-card .or { color: var(--muted); font-size: 15px; margin: 18px 0; }
.login-card #gbtn { display: flex; justify-content: center; min-height: 44px; }
.login-card .note { font-size: 16px; color: var(--muted); margin-top: 16px; }

/* ---------- 記今天 ---------- */
.datebar { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.datebar .nav { width: 52px; height: 52px; border-radius: 14px; border: 1.5px solid var(--line); background: #fff; display: flex; align-items: center; justify-content: center; }
.datebar .nav svg { width: 24px; height: 24px; }
.datebar .nav:disabled { opacity: .35; }
.datebar .day { flex: 1; position: relative; text-align: center; font-size: 21px; font-weight: 700; background: #fff; border: 1.5px solid var(--line); border-radius: 14px; min-height: 52px; display: flex; align-items: center; justify-content: center; gap: 8px; }
.datebar .day input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; min-height: 0; padding: 0; border: 0; }
/* 不是今天：日期換底色，一眼看得出在補記別天 */
.datebar.past .day { background: var(--warn-soft); border-color: #e8c98a; color: var(--warn); }
.back-today { margin: 8px 0 4px; }
.day-sum { text-align: center; color: var(--muted); font-size: 16px; margin: 4px 0 14px; min-height: 24px; }
.day-sum b { color: var(--ink); font-size: 18px; }
.pk-banner { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; background: var(--brand-soft); border-radius: 14px; padding: 12px 14px; margin-bottom: 14px; }
.pk-banner .t { flex: 1 1 100%; font-weight: 600; }
.pcard { background: #fff; border: 1px solid var(--line); border-radius: 18px; margin-bottom: 16px; overflow: hidden; }
.pc-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px; background: var(--soft); border-bottom: 1px solid var(--line); }
.pc-title { flex: 1; min-width: 0; font-size: 19px; }
.pc-title span { margin-left: 8px; }
.pc-count { font-size: 15px; color: var(--muted); white-space: nowrap; }
.known { padding: 12px 16px 4px; }
.known .lbl, .sub-t { font-size: 15px; color: var(--muted); font-weight: 700; margin-bottom: 8px; }
.sub-t { padding: 12px 16px 0; margin-bottom: 0; }
.known .chip .g { height: 24px; min-width: 26px; font-size: 15px; padding: 0 5px; }
.row { display: flex; gap: 10px; padding: 12px 16px; border-top: 1px solid #efebe3; }
.rows > .row:first-child { border-top: 0; }
.rn { flex: none; width: 30px; height: 30px; margin-top: 11px; border-radius: 50%; background: #ece8df; color: var(--muted);
  font-size: 15px; font-weight: 700; display: flex; align-items: center; justify-content: center; }
.row.saved .rn { background: var(--brand-soft); color: var(--brand); }
.rn.re { background: var(--gB-bg); color: var(--gB); font-size: 15px; }
.row-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.row-line { display: flex; gap: 8px; }
.row-line .in-name { flex: 1; min-width: 0; }
.row-line .in-phone { flex: 1.2; min-width: 0; }
.row input, .row textarea { padding: 10px 12px; }
.row-foot { display: flex; align-items: center; gap: 8px; min-height: 30px; }
.row-foot .st { font-size: 15px; color: var(--muted); }
.row-foot .st.ok { color: var(--brand); font-weight: 700; }
.row-foot .st.err { color: var(--danger); font-weight: 700; }
.row-foot .st.warn { color: var(--warn); font-weight: 700; }
.row-foot .sp { flex: 1; }
.row-foot .link { min-height: 44px; padding: 2px 10px; }
.row .tags { display: flex; flex-wrap: wrap; gap: 8px; }
.row .tags .chip { min-height: 44px; font-size: 16px; padding: 0 13px; }
.row.blank .row-foot { display: none; }
/* 有打字還沒存：橘色邊；存失敗：紅色 */
.row.unsaved { background: #fffaf0; box-shadow: inset 4px 0 0 #e2a54d; }
.row.failed { background: var(--danger-soft); box-shadow: inset 4px 0 0 var(--danger); }
.pcard { scroll-margin-top: 76px; }
.v-name { display: flex; align-items: center; gap: 8px; font-size: 19px; min-height: 30px; margin-top: 10px; }
.dup { display: none; }
.dup.show { display: block; background: var(--warn-soft); border-radius: 12px; padding: 12px; }
.dup .dt { font-weight: 700; margin-bottom: 8px; }
.dup-item { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px dashed #e8d9b5; }
.dup-item .di { flex: 1; min-width: 0; }
.dup-item small { display: block; color: var(--muted); font-size: 15px; }
.add-place { margin-top: 4px; }

/* ---------- 名單 ---------- */
.search { position: relative; margin-bottom: 12px; }
.search input { padding-left: 46px; }
.search svg { position: absolute; left: 14px; top: 15px; width: 22px; height: 22px; color: var(--muted); }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 14px; }
.seg button { border: 1.5px solid var(--line); background: #fff; border-radius: 14px; min-height: 64px; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.2; }
.seg button .s1 { font-size: 20px; font-weight: 800; }
.seg button .s2 { font-size: 15px; color: var(--muted); }
.seg button.on.C { background: var(--gC-bg); border-color: var(--gC); }
.seg button.on.B { background: var(--gB-bg); border-color: var(--gB); }
.seg button.on.A { background: var(--gA-bg); border-color: var(--gA); }
.seg button.on .s1 { color: var(--ink); }
.clist { background: #fff; border: 1px solid var(--line); border-radius: 18px; overflow: hidden; }
.crow { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-top: 1px solid #efebe3; background: #fff; width: 100%; text-align: left; border-left: 0; border-right: 0; border-bottom: 0; }
.clist > .crow:first-child { border-top: 0; }
.crow .cm { flex: 1; min-width: 0; }
.crow .cn { font-size: 19px; font-weight: 700; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.crow .cs { font-size: 15px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.crow.open { background: var(--soft); }
.ccard { border-top: 1px solid var(--line); background: var(--soft); padding: 4px 16px 18px; }
.info { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 12px 0; font-size: 17px; }
.info dt { color: var(--muted); font-weight: 600; }
.info dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.cc-box { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; margin-top: 12px; }
.cc-box h4 { margin: 0 0 8px; font-size: 16px; color: var(--muted); }
.tl { list-style: none; margin: 0; padding: 0; }
.tl li { padding: 10px 0; border-top: 1px solid #efebe3; display: flex; gap: 10px; }
.tl li:first-child { border-top: 0; }
.tl .d { flex: none; width: 54px; color: var(--muted); font-size: 15px; font-weight: 700; padding-top: 2px; }
.tl .b { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.tl .b .k { font-size: 15px; color: var(--muted); }
.deal { display: flex; gap: 10px; align-items: center; padding: 8px 0; border-top: 1px solid #efebe3; }
.deal:first-child { border-top: 0; }
.deal .b { flex: 1; min-width: 0; }
.more-row { text-align: center; padding: 14px; }

/* ---------- 成績、團隊 ---------- */
.stats { display: flex; flex-direction: column; gap: 10px; }
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 14px; min-width: 0; }
.stat .k { font-size: 16px; color: var(--muted); font-weight: 700; }
.stat .v { font-size: 28px; font-weight: 800; line-height: 1.25; margin: 2px 0; overflow-wrap: anywhere; }
.stat .f { font-size: 15px; color: var(--muted); }
.stat-grid .stat .v { font-size: 25px; }
.cv { display: grid; grid-template-columns: 48px 1fr 60px; grid-template-areas: "k bar v" ". f f"; align-items: center; gap: 2px 10px; margin-top: 10px; }
.cv-k { grid-area: k; font-weight: 800; }
.cv .bar { grid-area: bar; height: 22px; background: #efebe3; border-radius: 8px; overflow: hidden; }
.cv .bar i { display: block; height: 100%; border-radius: 8px; }
.cv-v { grid-area: v; text-align: right; font-size: 22px; font-weight: 800; }
.cv-f { grid-area: f; font-size: 15px; color: var(--muted); }
.mini { display: grid; grid-template-columns: repeat(auto-fit, minmax(84px, 1fr)); gap: 6px; margin-top: 10px; }
.mini > div { background: var(--soft); border-radius: 10px; padding: 6px 4px; text-align: center; min-width: 0; }
.mini span { display: block; font-size: 15px; color: var(--muted); font-weight: 600; line-height: 1.3; }
.mini b { display: block; font-size: 19px; line-height: 1.3; white-space: nowrap; }
.mini small { display: block; font-size: 15px; color: var(--muted); }
.mini > div.low { background: var(--danger-soft); }
.mini > div.low b { color: var(--danger); }
.cx-user { padding: 14px 0; border-top: 1px solid #efebe3; }
.cx-user > small { display: block; color: var(--muted); font-size: 15px; margin-top: 6px; }
.cx-head { width: 100%; border: 0; background: none; padding: 0; display: flex; align-items: center; gap: 10px; text-align: left; }
.cx-n { flex: 1; min-width: 0; }
.cx-n b { font-size: 19px; color: var(--brand); text-decoration: underline; text-underline-offset: 3px; }
.cx-n span { font-size: 15px; color: var(--muted); margin-left: 6px; }
.cx-rate { text-align: right; line-height: 1.2; }
.cx-rate b { display: block; font-size: 24px; }
.cx-rate span { font-size: 15px; color: var(--muted); font-weight: 600; }
.cx-rate.low b { color: var(--danger); }
.funnel { display: flex; flex-direction: column; gap: 8px; }
.fb { display: flex; align-items: center; gap: 10px; }
.fb .bar { flex: 1; height: 26px; background: #efebe3; border-radius: 8px; overflow: hidden; }
.fb .bar i { display: block; height: 100%; border-radius: 8px; }
.fb .n { width: 56px; text-align: right; font-weight: 700; }
.yearbar { display: flex; align-items: center; justify-content: center; gap: 10px; margin-bottom: 14px; }
.yearbar b { font-size: 20px; min-width: 90px; text-align: center; }
.mcard { background: #fff; border: 1px solid var(--line); border-radius: 16px; margin-bottom: 10px; overflow: hidden; }
.mc-head { width: 100%; text-align: left; border: 0; background: #fff; padding: 14px 16px; display: block; }
.mc-name { font-size: 19px; font-weight: 700; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.mc-name .rk { font-size: 15px; color: var(--muted); font-weight: 600; }
.mc-line { font-size: 15px; color: var(--muted); margin-top: 4px; }
.mc-line b { color: var(--ink); }
.mc-body { padding: 0 16px 16px; }
.cx-row { display: flex; gap: 10px; align-items: flex-start; padding: 10px 0; border-top: 1px solid #efebe3; }
.cx-row .b { flex: 1; min-width: 0; }
.cx-row small { display: block; color: var(--muted); font-size: 15px; }
.st-match { color: var(--gA); background: var(--gA-bg); }
.st-miss { color: var(--danger); background: var(--danger-soft); }
.st-title { color: var(--warn); background: var(--warn-soft); }
.st-alone { color: var(--muted); background: #ece8df; }
.pill { display: inline-block; font-size: 14px; font-weight: 700; padding: 2px 8px; border-radius: 6px; white-space: nowrap; }
.ptable .pp { display: flex; gap: 10px; padding: 10px 0; border-top: 1px solid #efebe3; }
.ptable .pp .nm { width: 96px; flex: none; font-weight: 700; overflow-wrap: anywhere; }
.ptable .pp .us { flex: 1; min-width: 0; font-size: 16px; }
.ptable .pp.solo .nm { color: var(--danger); }

/* ---------- 頁尾 ---------- */
.foot { text-align: center; font-size: 15px; color: var(--muted); margin-top: 36px; display: flex; justify-content: center; flex-wrap: wrap; gap: 4px 14px; }
.foot button { background: none; border: 0; color: var(--muted); text-decoration: underline; font-size: 15px; padding: 6px 2px; }

/* ---------- 對話框 ---------- */
dialog.sheet {
  border: 0; padding: 0; border-radius: 22px 22px 0 0; width: 100%; max-width: 640px; max-height: 92vh;
  margin: auto auto 0; background: #fff; color: var(--ink);
}
dialog.sheet::backdrop { background: rgba(20, 30, 32, .45); }
.sh-head { position: sticky; top: 0; background: #fff; display: flex; align-items: center; gap: 10px; padding: 16px 16px 12px; border-bottom: 1px solid var(--line); z-index: 2; }
.sh-head h3 { flex: 1; margin: 0; font-size: 21px; }
.sh-head .x { width: 44px; height: 44px; border: 0; background: #f0ece4; border-radius: 50%; font-size: 22px; line-height: 1; }
.sh-body { padding: 4px 16px calc(24px + env(safe-area-inset-bottom)); overflow-y: auto; }
.sugg { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.list-line { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid #efebe3; }
.list-line:first-child { border-top: 0; }
.list-line .b { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.list-line small { display: block; color: var(--muted); font-size: 15px; }
.meter { height: 14px; background: #efebe3; border-radius: 7px; overflow: hidden; margin: 10px 0; }
.meter i { display: block; height: 100%; background: var(--brand); }
.toast { position: fixed; left: 50%; top: calc(env(safe-area-inset-top) + 70px); transform: translateX(-50%); background: #1d2a2f; color: #fff;
  padding: 10px 18px; border-radius: 999px; font-size: 16px; z-index: 100; max-width: calc(100% - 32px); text-align: center; }

@media (min-width: 700px) {
  dialog.sheet { border-radius: 22px; margin: auto; }
}
/* 手機、平板打字時：底下分頁列收起來、上面標題不黏著，鍵盤上方的空間全部給打字 */
@media (pointer: coarse) {
  body.typing .tabs { display: none; }
  body.typing .top { position: static; }
}
