/* ---------- 基礎 ---------- */
:root {
  --bg:        #f4f5f7;
  --surface:   #ffffff;
  --line:      #e2e5ea;
  --text:      #16202e;
  --muted:     #6b7787;
  --accent:    #1f6feb;
  --in:        #0f8a5f;
  --in-soft:   #e6f5ee;
  --out:       #c2410c;
  --out-soft:  #fdf0e7;
  --warn:      #b45309;
  --warn-soft: #fdf6e3;
  --err:       #b91c1c;
  --err-soft:  #fdeaea;
  --radius:    14px;
  --shadow:    0 1px 2px rgba(16,24,40,.05), 0 4px 14px rgba(16,24,40,.06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:        #0f141b;
    --surface:   #171e28;
    --line:      #2a3542;
    --text:      #e7ecf3;
    --muted:     #94a3b5;
    --accent:    #5b9bff;
    --in:        #34d399;
    --in-soft:   #10291f;
    --out:       #fb923c;
    --out-soft:  #2b1a0f;
    --warn:      #fbbf24;
    --warn-soft: #2a2110;
    --err:       #f87171;
    --err-soft:  #2c1414;
    --shadow:    0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.3);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI",
        "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  -webkit-text-size-adjust: 100%;
  padding-bottom: env(safe-area-inset-bottom);
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

main {
  max-width: 960px;
  margin: 0 auto;
  padding: 18px 16px 48px;
}
main.narrow { max-width: 460px; }
main.wide   { max-width: 1200px; }

h1 { font-size: 1.35rem; margin: 0 0 16px; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; margin: 28px 0 10px; letter-spacing: -.01em; }

/* ---------- 頁首 ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap;
  padding: 10px 16px calc(10px + env(safe-area-inset-top));
  padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 650; color: var(--text); }
.brand:hover { text-decoration: none; }
.topbar nav { display: flex; gap: 4px; flex-wrap: wrap; }
.topbar nav a {
  padding: 6px 11px; border-radius: 999px; font-size: .9rem; color: var(--text);
}
.topbar nav a:hover { background: var(--bg); text-decoration: none; }
.topbar nav a.muted { color: var(--muted); }

.subnav {
  display: flex; gap: 4px; flex-wrap: wrap;
  margin: 0 0 20px; padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}
.subnav a {
  padding: 6px 12px; border-radius: 999px;
  font-size: .9rem; color: var(--muted);
}
.subnav a:hover { background: var(--surface); text-decoration: none; }
.subnav a.on { background: var(--accent); color: #fff; }

.foot {
  text-align: center; color: var(--muted);
  font-size: .78rem; padding: 0 16px 28px;
}

/* ---------- 卡片 ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 16px;
}
.card.pad0 { padding: 0; overflow: hidden; }

/* ---------- 打卡主畫面 ---------- */
.clock-now {
  text-align: center;
  padding: 6px 0 18px;
}
.clock-now .time {
  font-size: 3.1rem; font-weight: 300; letter-spacing: -.03em;
  font-variant-numeric: tabular-nums; line-height: 1.1;
}
.clock-now .date { color: var(--muted); font-size: .95rem; }

.status-pill {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 6px 14px; border-radius: 999px;
  font-size: .88rem; font-weight: 600;
}
.status-pill.working { background: var(--in-soft);  color: var(--in); }
.status-pill.off     { background: var(--bg);       color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.dot.live { animation: pulse 2s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: .3 } }

.punch-btn {
  display: block; width: 100%;
  border: 0; border-radius: var(--radius);
  padding: 24px 16px;
  font-size: 1.5rem; font-weight: 650; letter-spacing: .02em;
  color: #fff; cursor: pointer;
  transition: transform .1s ease, filter .15s ease;
  font-family: inherit;
}
.punch-btn:active { transform: scale(.985); }
.punch-btn[disabled] { opacity: .55; cursor: not-allowed; }
.punch-btn.in  { background: var(--in); }
.punch-btn.out { background: var(--out); }
/* 切換案件是次要動作：低調一點，避免跟下班打卡搶注意力 */
.punch-btn.switch {
  margin-top: 10px; padding: 15px 16px; font-size: 1.05rem;
  background: transparent; color: var(--accent);
  border: 1px solid var(--line);
}
.punch-btn.switch small { opacity: .75; }
.punch-btn small {
  display: block; font-size: .82rem; font-weight: 400;
  opacity: .85; margin-top: 5px; letter-spacing: 0;
}

.geo-line {
  display: flex; align-items: center; gap: 8px;
  font-size: .84rem; color: var(--muted);
  margin-top: 12px; min-height: 22px;
}
.geo-line.err { color: var(--warn); }

/* ---------- 表單 ---------- */
label.field { display: block; margin-bottom: 14px; }
label.field > span {
  display: block; font-size: .85rem; color: var(--muted);
  margin-bottom: 5px; font-weight: 500;
}
input[type=text], input[type=password], input[type=date], input[type=month],
input[type=number], input[type=datetime-local], select, textarea {
  width: 100%; padding: 11px 12px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); color: var(--text);
  font: inherit; font-size: 16px; /* 16px 可避免 iOS 自動放大 */
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent;
}
textarea { min-height: 76px; resize: vertical; }

.btn {
  display: inline-block; border: 1px solid var(--line);
  background: var(--surface); color: var(--text);
  padding: 10px 18px; border-radius: 10px;
  font: inherit; font-weight: 550; cursor: pointer;
}
.btn:hover { text-decoration: none; border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger  { background: var(--err-soft); border-color: transparent; color: var(--err); }
.btn.sm      { padding: 5px 11px; font-size: .84rem; }

.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.row > * { flex: 1 1 150px; }
.row > .shrink { flex: 0 0 auto; }

/* ---------- 表格 ---------- */
.tablewrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td {
  padding: 9px 12px; text-align: left;
  border-bottom: 1px solid var(--line); white-space: nowrap;
}
th { font-size: .78rem; color: var(--muted); font-weight: 600; letter-spacing: .02em; }
tbody tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.wrap { white-space: normal; min-width: 140px; }
tr.total td { font-weight: 650; background: var(--bg); }

/* ---------- 統計方塊 ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; }
.stat {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 16px;
}
.stat .k { font-size: .78rem; color: var(--muted); }
.stat .v {
  font-size: 1.5rem; font-weight: 600; letter-spacing: -.02em;
  font-variant-numeric: tabular-nums; margin-top: 2px;
}

/* ---------- 標籤／提示 ---------- */
.tag {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: .75rem; font-weight: 600; background: var(--bg); color: var(--muted);
}
.tag.in     { background: var(--in-soft);   color: var(--in); }
.tag.out    { background: var(--out-soft);  color: var(--out); }
.tag.switch { background: transparent; color: var(--accent); box-shadow: inset 0 0 0 1px currentColor; }
.tag.warn  { background: var(--warn-soft); color: var(--warn); }
.tag.err   { background: var(--err-soft);  color: var(--err); }

.flash {
  padding: 11px 14px; border-radius: 10px;
  margin-bottom: 16px; font-size: .9rem;
}
.flash-ok   { background: var(--in-soft);   color: var(--in); }
.flash-warn { background: var(--warn-soft); color: var(--warn); }
.flash-err  { background: var(--err-soft);  color: var(--err); }

/* ---------- 未處理筆數小紅點 ---------- */
.badge {
  display: inline-block; min-width: 18px; padding: 0 5px;
  margin-left: 5px; border-radius: 999px;
  background: var(--err); color: #fff;
  font-size: .7rem; font-weight: 700; line-height: 18px; text-align: center;
  vertical-align: text-top;
}

/* ---------- 分頁切換 ---------- */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 18px; }
.tabs a {
  flex: 1 1 auto; text-align: center;
  padding: 10px 14px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface);
  color: var(--text); font-size: .92rem; font-weight: 550;
}
.tabs a:hover { text-decoration: none; border-color: var(--muted); }
.tabs a.on { background: var(--accent); border-color: var(--accent); color: #fff; }

.muted { color: var(--muted); }
.small { font-size: .84rem; }
.empty { text-align: center; color: var(--muted); padding: 34px 16px; }
.hint  { font-size: .82rem; color: var(--muted); margin-top: 6px; }
