:root {
  --bg: #f6f4ef;
  --card: #ffffff;
  --ink: #1d2422;
  --muted: #6b7570;
  --line: #e4e0d6;
  --brand: #1f6f5c;
  --brand-soft: #e3f0eb;
  --out: #b8612a;
  --out-soft: #f8ebe1;
  --bad: #b3261e;
  --bad-soft: #fbe9e7;
  --warn: #9a6b00;
  --warn-soft: #fbf1d6;
  --radius: 14px;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--bg); }
a { color: var(--brand); }
button, input, select { font: inherit; color: inherit; }
.boot { padding: 40vh 0 0; text-align: center; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }

/* 頂部 */
.top { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: env(safe-area-inset-top) 16px 0; border-bottom: 1px solid var(--line); }
.top-row { display: flex; align-items: center; justify-content: space-between; height: 52px; max-width: 960px; margin: 0 auto; }
.brand { font-weight: 700; font-size: 18px; }
.who { display: flex; gap: 12px; align-items: center; font-size: 14px; }
.tabs, .subtabs { display: flex; gap: 4px; max-width: 960px; margin: 0 auto; overflow-x: auto; }
.tab { padding: 10px 14px; text-decoration: none; color: var(--muted); font-weight: 600; border-bottom: 3px solid transparent; white-space: nowrap; }
.tab.active { color: var(--brand); border-color: var(--brand); }
.subtabs { padding: 8px 0 10px; }
.subtab { padding: 6px 12px; border-radius: 999px; text-decoration: none; color: var(--muted); font-size: 14px; white-space: nowrap; }
.subtab.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }

.main { max-width: 960px; margin: 0 auto; padding: 16px 16px calc(32px + env(safe-area-inset-bottom)); }

/* 按鈕 */
.btn { border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 9px 14px; cursor: pointer; font-weight: 600; }
.btn:hover { border-color: var(--brand); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; padding: 12px; }
.btn:disabled { opacity: .55; cursor: default; }
.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }
.link { border: 0; background: none; color: var(--brand); cursor: pointer; padding: 4px; }
.link.danger { color: var(--bad); }

/* 表單 */
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field-label { font-size: 13px; color: var(--muted); font-weight: 600; }
.field-hint { font-size: 12px; color: var(--muted); }
.field input, .field select { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: #fff; min-height: 42px; width: 100%; }
.field input:focus, .field select:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
.check { display: flex; gap: 8px; align-items: center; font-size: 14px; }
.check input { width: 18px; height: 18px; accent-color: var(--brand); }
.form-error { color: var(--bad); font-size: 14px; min-height: 1em; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* 登入 */
.center-card { max-width: 380px; margin: 12vh auto 0; padding: 28px 24px; display: flex; flex-direction: column; gap: 14px; }
.login h2 { margin: 0 0 4px; text-align: center; }
.login-logo { display: flex; justify-content: center; }
.login-logo img { width: 64px; height: 64px; }

/* 打卡 */
.clock-wrap { text-align: center; padding: 12px 0 8px; }
.clock { font-size: 56px; font-weight: 700; letter-spacing: 1px; font-variant-numeric: tabular-nums; line-height: 1.1; }
.clock-date { font-size: 16px; color: var(--muted); }
.gps { margin: 12px auto; max-width: 520px; padding: 10px 14px; border-radius: 10px; font-size: 14px; text-align: center; }
.gps.good { background: var(--brand-soft); color: var(--brand); }
.gps.bad { background: var(--bad-soft); color: var(--bad); }
.gps.neutral { background: #eeebe3; color: var(--muted); }
.punch-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; max-width: 520px; margin: 0 auto; }
.punch-btn { border: 2px solid transparent; border-radius: 20px; padding: 30px 8px; font-size: 21px; font-weight: 700; cursor: pointer; transition: transform .08s; }
.punch-btn:active { transform: scale(.97); }
.punch-btn.in { background: var(--brand-soft); color: var(--brand); }
.punch-btn.out { background: var(--out-soft); color: var(--out); }
.punch-btn.in.suggest { background: var(--brand); color: #fff; box-shadow: 0 6px 18px rgba(31, 111, 92, .3); }
.punch-btn.out.suggest { background: var(--out); color: #fff; box-shadow: 0 6px 18px rgba(184, 97, 42, .3); }
.punch-btn:disabled { opacity: .6; }
.result { max-width: 520px; margin: 14px auto; text-align: center; border-radius: 12px; min-height: 0; }
.result:empty { display: none; }
.result.pending { color: var(--muted); padding: 10px; }
.result.good { background: var(--brand-soft); color: var(--brand); padding: 14px; }
.result.bad { background: var(--bad-soft); color: var(--bad); padding: 14px; font-weight: 600; }
.result-title { font-weight: 700; }
.result-time { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; }
.status { max-width: 520px; margin: 14px auto 0; padding: 14px 16px; }
.status-head { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }

/* 共用 */
.chip { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 13px; font-weight: 600; white-space: nowrap; }
.chip.on { background: var(--brand); color: #fff; }
.chip.off { background: #eeebe3; color: var(--muted); }
.chip.none { background: var(--warn-soft); color: var(--warn); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.tag { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 6px; background: #eeebe3; color: var(--muted); margin-left: 6px; }
.tag.red { background: var(--bad-soft); color: var(--bad); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.dot.in { background: var(--brand); }
.dot.out { background: var(--out); }
.mini-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.mini-list li { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.mini-list b { margin-left: 8px; font-variant-numeric: tabular-nums; }
.voided, .voided b { color: var(--muted); text-decoration: line-through; }
.voided .tag { text-decoration: none; }
.empty { padding: 28px; text-align: center; color: var(--muted); }

.toolbar { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar h3 { margin: 0; }
.toolbar.wrap { justify-content: flex-start; }
.toolbar.wrap .field { width: 150px; }
.list { display: flex; flex-direction: column; gap: 10px; }
.day { padding: 12px 16px; }
.day-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; }
.row-main { flex: 1; min-width: 0; }
.row-times { display: flex; gap: 14px; font-size: 14px; font-variant-numeric: tabular-nums; }
.row.inactive { opacity: .6; }
.note { padding: 12px 16px; font-size: 14px; margin-bottom: 12px; line-height: 1.6; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { color: var(--muted); font-weight: 600; background: #faf9f5; }
tr:last-child td { border-bottom: 0; }

/* 對話框 */
.modal { border: 0; border-radius: 18px; padding: 0; width: min(520px, calc(100vw - 24px)); max-height: calc(100dvh - 40px); overflow-y: auto; }
.modal-actions { position: sticky; bottom: -20px; background: #fff; padding: 12px 0 0; }
.modal::backdrop { background: rgba(20, 24, 22, .45); }
.modal-form { display: flex; flex-direction: column; gap: 14px; padding: 20px; }
.modal-form h3 { margin: 0; }
.modal-form p { margin: 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }

.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); opacity: 0; background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 999px; transition: all .25s; z-index: 50; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 560px) {
  .clock { font-size: 48px; }
  .grid2 { grid-template-columns: 1fr; }
  .toolbar.wrap .field { width: calc(50% - 6px); }
  .row { flex-wrap: wrap; }
  .row-times { order: 3; width: 100%; }
}

/* v2：班別、排班、網路 */
.shift-today { margin-top: 6px; font-weight: 600; color: var(--brand); }
.shift-today:empty { display: none; }
.chips { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.chip.good { background: var(--brand-soft); color: var(--brand); }
.chip.bad { background: var(--bad-soft); color: var(--bad); }
.field textarea { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: #fff; width: 100%; font: inherit; font-family: ui-monospace, Menlo, monospace; font-size: 14px; }
.debug { font-size: 13px; background: #fff; border: 1px dashed var(--line); border-radius: 10px; padding: 10px 12px; white-space: pre-wrap; }
.debug:empty { display: none; }
.pad { padding: 16px; }
.sched-table td, .sched-table th { padding: 6px 8px; }
.sched-table th.today { color: var(--brand); }
select.sched { border: 1px solid var(--line); border-radius: 8px; padding: 6px 4px; min-width: 92px; background: #fff; color: var(--muted); }
select.sched.set { background: var(--brand-soft); color: var(--brand); border-color: transparent; font-weight: 600; }
select.sched.off { background: #eeebe3; color: var(--muted); border-color: transparent; }
.toast.bad { background: var(--bad); }
.day-head { gap: 8px; flex-wrap: wrap; }

/* v3：班表、排休、特休 */
.main.wide { max-width: none; }
.section { margin-top: 28px; }
.group-title { margin: 14px 0 2px; color: var(--muted); }
.bad-text { color: var(--bad); font-weight: 700; }
tr.inactive td { opacity: .55; }
.leave-badge { display: inline-block; padding: 2px 8px; border-radius: 6px; font-size: 13px; font-weight: 700; color: #3a2a2a; }
.chips .leave-badge { margin: 2px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 12px 0; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px; text-align: center; display: flex; flex-direction: column; }
.stat b { font-size: 22px; }
.stat span { font-size: 12px; color: var(--muted); }

/* 員工排休月曆 */
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-head { text-align: center; font-size: 12px; color: var(--muted); padding: 4px 0; }
.cal-cell { min-height: 66px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); padding: 4px; display: flex; flex-direction: column; align-items: flex-start; gap: 1px; text-align: left; cursor: pointer; overflow: hidden; }
.cal-cell.blank { border: 0; background: transparent; cursor: default; }
.cal-cell.weekend .cal-day { color: var(--out); }
.cal-cell.full { background: #eceae4; }
.cal-cell.mine { border-color: transparent; }
.cal-day { font-weight: 700; font-size: 14px; }
.cal-code { font-weight: 800; font-size: 14px; }
.cal-others { font-size: 10px; color: var(--muted); }
.cal-names { font-size: 10px; color: var(--muted); line-height: 1.2; max-height: 2.4em; overflow: hidden; }

/* 管理員月班表 */
.roster-wrap { overflow: auto; max-height: calc(100vh - 230px); }
table.roster { border-collapse: separate; border-spacing: 0; font-size: 12px; }
table.roster th, table.roster td { padding: 2px; border-bottom: 1px solid var(--line); border-right: 1px solid var(--line); text-align: center; white-space: nowrap; }
table.roster th { position: sticky; top: 0; z-index: 2; background: #faf9f5; font-weight: 600; min-width: 38px; }
table.roster th .wd { font-weight: 400; color: var(--muted); }
table.roster th.weekend { color: var(--out); }
table.roster th.today { background: var(--brand-soft); }
table.roster .sticky { position: sticky; left: 0; z-index: 1; background: #fff; text-align: left; padding: 2px 8px; min-width: 90px; }
table.roster th.sticky { z-index: 3; background: #faf9f5; }
table.roster td.name { font-weight: 700; }
table.roster tr.group-row td { background: #fff5c2; font-weight: 700; text-align: left; padding: 4px 8px; }
table.roster tr.sum-row td { background: #f3f0e8; font-weight: 700; }
table.roster tr.sum-row td.bad { background: var(--bad-soft); color: var(--bad); }
table.roster td.conflict { outline: 2px solid var(--bad); outline-offset: -2px; }
table.roster td.out select { background: #e9e6df; }
table.roster th.count { min-width: 30px; }
table.roster td.count { color: var(--muted); font-weight: 600; }
select.cell { appearance: none; -webkit-appearance: none; border: 0; width: 38px; height: 26px; text-align: center; text-align-last: center; font-size: 12px; font-weight: 700; background: transparent; border-radius: 4px; cursor: pointer; padding: 0; }
select.cell:hover { outline: 1px solid var(--brand); }
@media (max-width: 560px) { .stats b { font-size: 18px; } .cal-cell { min-height: 58px; } }
.sheet-btns { display: flex; flex-direction: column; gap: 8px; }
.danger-btn { color: var(--bad); }
.cal-others.max { color: var(--bad); font-weight: 700; }
.modal:has(table) { width: min(760px, calc(100vw - 24px)); }
