:root {
  --brand: #0f5c4d;
  --brand-2: #127a66;
  --brand-soft: #e3f1ed;
  --bg: #f5f7f6;
  --card: #ffffff;
  --text: #1c2522;
  --muted: #66736f;
  --line: #dfe5e3;
  --red: #b42318; --red-soft: #fdecea;
  --amber: #a15c00; --amber-soft: #fff4e0;
  --green: #1a7f37; --green-soft: #e6f4ea;
  --blue: #1f5fbf; --blue-soft: #e8f0fc;
  --purple: #6b3fa0; --purple-soft: #f1eafa;
  --radius: 14px;
  --tabbar-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111615; --card: #1a2120; --text: #e8eeec; --muted: #9aa8a4; --line: #2c3634;
    --brand-soft: #173a33; --red-soft: #3a1b18; --amber-soft: #3a2c12; --green-soft: #173222; --blue-soft: #18263d; --purple-soft: #2b2038;
    --brand-2: #3fb59b;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  font-size: 16px; line-height: 1.5; -webkit-text-size-adjust: 100%;
}
body.modal-open { overflow: hidden; }
h1 { font-size: 1.4rem; margin: 0 0 .75rem; }
h2 { font-size: 1.1rem; margin: 1rem 0 .5rem; }
h3 { font-size: 1.05rem; margin: 0; }
h4 { margin: 1rem 0 .4rem; font-size: .95rem; }
input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea {
  width: 100%; padding: .7rem .8rem; border: 1px solid var(--line); border-radius: 10px; background: var(--card); min-height: 46px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-2); outline-offset: 0; border-color: transparent; }
a { color: var(--brand-2); }

/* 版面 */
.app { min-height: 100vh; }
.main { padding: 16px 16px calc(var(--tabbar-h) + 24px + env(safe-area-inset-bottom)); max-width: 1100px; margin: 0 auto; }
.sidebar { display: none; }
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom); background: var(--card); border-top: 1px solid var(--line);
  display: flex; z-index: 20;
}
.tabbar a, .tabbar button {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  text-decoration: none; color: var(--muted); font-size: .72rem; background: none; border: 0; padding: 0;
}
.tabbar .ico { font-size: 1.25rem; line-height: 1; }
.tabbar .on { color: var(--brand); font-weight: 600; }
.more-menu { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 19; display: flex; align-items: flex-end; }
.more-grid {
  width: 100%; background: var(--card); padding: 16px 16px calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom));
  border-radius: 18px 18px 0 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
}
.more-grid a { display: flex; flex-direction: column; align-items: center; padding: 12px 4px; border-radius: 12px; text-decoration: none; color: var(--text); background: var(--bg); font-size: .85rem; }
.more-grid .ico { font-size: 1.3rem; }
@media (min-width: 900px) {
  .app { display: grid; grid-template-columns: 230px 1fr; }
  .sidebar { display: block; position: sticky; top: 0; align-self: start; height: 100vh; overflow: auto; background: var(--card); border-right: 1px solid var(--line); padding: 16px 12px; }
  .sidebar nav a { display: flex; gap: 10px; align-items: center; padding: 9px 12px; border-radius: 10px; color: var(--text); text-decoration: none; }
  .sidebar nav a.on { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
  .sidebar .ico { width: 1.2rem; text-align: center; color: var(--muted); }
  .tabbar, .more-menu { display: none; }
  .main { padding: 24px 32px 48px; width: 100%; min-width: 0; }
}
.brand { display: flex; gap: 10px; align-items: center; padding: 4px 8px 16px; }
.brand img { width: 40px; height: 40px; border-radius: 10px; }

/* 元件 */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin: 10px 0; }
.card.sub { background: var(--bg); }
.card.clickable { cursor: pointer; }
.section { margin: 18px 0; }
.section-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: .55rem 1rem;
  border-radius: 10px; border: 1px solid transparent; cursor: pointer; font-weight: 600; white-space: nowrap;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: #111; color: #fff; }
.btn-secondary { background: #111; color: #fff; }
.btn-ghost { background: transparent; border-color: #111; color: var(--text); }
.btn.block { width: 100%; margin-top: 12px; min-height: 52px; font-size: 1.05rem; }
.btn.big { min-height: 56px; font-size: 1.05rem; flex: 1; }
@media (prefers-color-scheme: dark) { .btn-primary, .btn-secondary { border-color: #555; } .btn-ghost { border-color: #888; } }
.link { background: none; border: 0; color: var(--brand-2); cursor: pointer; padding: 4px; text-decoration: underline; }
.link.danger { color: var(--red); }
.icon-btn { background: none; border: 1px solid var(--line); border-radius: 10px; min-width: 40px; min-height: 40px; cursor: pointer; }
.field { display: block; margin: 10px 0; }
.field-label { display: block; font-size: .88rem; color: var(--muted); margin-bottom: 4px; }
.field-label em { color: var(--red); font-style: normal; }
.field-hint { display: block; font-size: .8rem; color: var(--muted); margin-top: 3px; }
.segmented { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.segmented button, .chip {
  border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: .45rem .9rem; min-height: 40px; cursor: pointer;
}
.segmented button.on, .chip.on { background: #111; border-color: #111; color: #fff; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.badge { display: inline-block; font-size: .75rem; padding: 2px 8px; border-radius: 999px; margin-left: 4px; vertical-align: middle; white-space: nowrap; }
.badge-gray { background: var(--bg); color: var(--muted); border: 1px solid var(--line); }
.badge-green { background: var(--green-soft); color: var(--green); }
.badge-amber { background: var(--amber-soft); color: var(--amber); }
.badge-red { background: var(--red-soft); color: var(--red); }
.badge-blue { background: var(--blue-soft); color: var(--blue); }
.badge-purple { background: var(--purple-soft); color: var(--purple); }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.right { text-align: right; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.row-between.wrap, .row-wrap { flex-wrap: wrap; }
.row-wrap { display: flex; gap: 8px; align-items: center; margin: 8px 0; }
.row-wrap input, .row-wrap select { width: auto; }
.row-end { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
.spacer { flex: 1; }
.full { flex-basis: 100%; }
.empty { padding: 20px; text-align: center; color: var(--muted); background: var(--card); border: 1px dashed var(--line); border-radius: var(--radius); margin: 8px 0; }
.loading { padding: 24px; text-align: center; color: var(--muted); }
.error-box { background: var(--red-soft); color: var(--red); padding: 10px 12px; border-radius: 10px; margin: 8px 0; }
.note-box { background: var(--blue-soft); color: var(--text); padding: 10px 12px; border-radius: 10px; margin: 8px 0; font-size: .9rem; }
.note-box.warn { background: var(--amber-soft); }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin: 10px 0; align-items: center; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.stat-label { font-size: .8rem; color: var(--muted); }
.stat-value { font-size: 1.35rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-sub { font-size: .78rem; color: var(--muted); }
.stat-amber { border-color: var(--amber); }
.stat-red .stat-value { color: var(--red); }
.stat-green .stat-value { color: var(--green); }
.money { font-variant-numeric: tabular-nums; }
.month-picker { display: flex; gap: 6px; align-items: center; }
.month-picker input { width: auto; }
.date-inline { width: auto; }

/* 首頁 */
.hello { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.hello h1 { margin: 0; }
.quick { display: flex; gap: 10px; margin: 14px 0; flex-wrap: wrap; }
.cal-status { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; }
.appt-main { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.appt-time { font-weight: 700; font-variant-numeric: tabular-nums; }
.appt-title { flex: 1; }
.item-lines { list-style: none; margin: 8px 0 0; padding: 0; }
.item-lines li { display: flex; justify-content: space-between; gap: 8px; padding: 6px 0; border-top: 1px solid var(--line); font-size: .92rem; }
.item-lines li.voided { color: var(--muted); text-decoration: line-through; }

/* 登錄表單 */
.visit-form .item-card { border: 1px solid var(--line); border-left: 4px solid var(--brand-2); border-radius: 12px; padding: 12px; margin: 12px 0; background: var(--bg); }
.item-head { display: flex; justify-content: space-between; align-items: center; }
.add-items { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 12px 0; }
.reason-box { background: var(--amber-soft); border-radius: 10px; padding: 4px 10px; margin: 8px 0; }
.picked { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; background: var(--brand-soft); border-radius: 10px; }
.pick-list { display: flex; flex-direction: column; gap: 6px; margin: 8px 0; }
.pick-item { display: flex; flex-direction: column; align-items: flex-start; text-align: left; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); cursor: pointer; }
.file-picker { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.file-row { display: flex; gap: 8px; font-size: .88rem; }
.attach-list { padding-left: 18px; margin: 4px 0; }
.inline-form { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.inline-form input, .inline-form select { flex: 1 1 140px; width: auto; }
.kv { display: grid; gap: 6px; }
.kv > div { display: flex; gap: 10px; flex-wrap: wrap; }
.kv span:first-child { color: var(--muted); min-width: 110px; }
.export-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }

/* 薪資 */
.payroll-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.lines { margin: 0; }
.lines > div { display: flex; justify-content: space-between; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.lines dt { color: var(--muted); }
.lines dd { margin: 0; font-variant-numeric: tabular-nums; }
.lines .total dt, .lines .total dd { color: var(--text); font-weight: 700; }
.lines .grand { font-size: 1.15rem; border-bottom: 0; }
.adj-list { font-size: .85rem; color: var(--muted); padding-left: 18px; }

/* 表格：手機上變卡片 */
.table-wrap { overflow-x: auto; margin: 8px 0; }
table { width: 100%; border-collapse: collapse; background: var(--card); border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); }
th, td { padding: 9px 10px; text-align: left; border-bottom: 1px solid var(--line); font-size: .9rem; vertical-align: top; }
th { background: var(--bg); color: var(--muted); font-weight: 600; font-size: .8rem; white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--brand-soft); }
@media (max-width: 700px) {
  table, thead, tbody, tr, td { display: block; border: 0; }
  thead { display: none; }
  table { background: transparent; }
  tr { background: var(--card); border: 1px solid var(--line); border-radius: 12px; margin-bottom: 8px; padding: 6px 10px; }
  td { display: flex; justify-content: space-between; gap: 10px; padding: 4px 0; border: 0; text-align: right; }
  td::before { content: attr(data-label); color: var(--muted); text-align: left; font-size: .82rem; }
  td:empty { display: none; }
  td.num { text-align: right; }
}

/* 視窗 */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.modal { background: var(--card); width: 100%; max-height: 92vh; overflow: auto; border-radius: 18px 18px 0 0; padding-bottom: env(safe-area-inset-bottom); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--card); z-index: 1; }
.modal-body { padding: 12px 16px 20px; }
.dialog-msg { font-size: 1.02rem; white-space: pre-wrap; }
@media (min-width: 700px) {
  .modal-backdrop { align-items: center; }
  .modal { max-width: 560px; border-radius: 18px; }
  .modal-wide { max-width: 760px; }
  .modal-small { max-width: 420px; }
}
.toasts { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom)); z-index: 60; display: flex; flex-direction: column; gap: 8px; width: min(92vw, 420px); }
.toast { padding: 12px 14px; border-radius: 12px; background: #1c2522; color: #fff; box-shadow: 0 6px 20px rgba(0,0,0,.2); }
.toast-warn { background: #7a4a00; }
.toast-error { background: #9b1c12; }

/* 登入 */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { width: 100%; max-width: 400px; text-align: left; }
.login-card h1 { margin-top: 8px; }
.logo-big { width: 72px; height: 72px; border-radius: 18px; }

.demo-banner { background: var(--amber-soft); color: var(--amber); border: 1px dashed var(--amber); border-radius: 10px; padding: 8px 12px; margin-bottom: 12px; font-weight: 600; text-align: center; }

.temp-pw { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 1.4rem; letter-spacing: 1px; background: var(--bg); border: 1px dashed var(--line); border-radius: 10px; padding: 12px; text-align: center; user-select: all; }
