:root {
  --brand: #1a56db;
  --brand-light: #3b82f6;
  --brand-dark: #0d3a91;
  --ok: #15803d;
  --ok-bg: #dcfce7;
  --warn: #c2650a;
  --warn-bg: #fef3c7;
  --danger: #c81e1e;
  --danger-bg: #fde8e8;
  --bg: #f1f4f9;
  --card: #ffffff;
  --text: #1a1d29;
  --muted: #67718a;
  --border: #e4e8f0;
  --radius: 16px;
  --shadow-sm: 0 1px 2px rgba(16,24,64,.06), 0 1px 1px rgba(16,24,64,.04);
  --shadow-md: 0 4px 14px rgba(16,24,64,.08), 0 1px 3px rgba(16,24,64,.06);
  --shadow-lg: 0 12px 32px rgba(16,24,64,.14), 0 2px 8px rgba(16,24,64,.08);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC", "Microsoft JhengHei", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); }
body { padding-bottom: 76px; min-height: 100vh; -webkit-font-smoothing: antialiased; }

a { color: var(--brand); text-decoration: none; }

/* ===== Topbar：半透明+模糊，像現代 SaaS 產品的頂列 ===== */
.topbar {
  background: linear-gradient(120deg, var(--brand) 0%, var(--brand-dark) 100%);
  color: #fff;
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: 0 4px 20px rgba(13,58,145,.25);
  backdrop-filter: blur(8px);
}
.topbar .brand { font-weight: 700; font-size: 16px; display: flex; align-items: center; gap: 8px; letter-spacing: .01em; }
.topbar .userbox { display: flex; align-items: center; gap: 9px; font-size: 13px; }
.topbar .userbox img { width: 28px; height: 28px; border-radius: 50%; border: 2px solid rgba(255,255,255,.7); box-shadow: 0 2px 6px rgba(0,0,0,.15); }
.topbar button.logout {
  background: rgba(255,255,255,.15); color: #fff; border: 1px solid rgba(255,255,255,.25); border-radius: 8px;
  padding: 6px 12px; font-size: 12px; cursor: pointer; transition: background .15s ease, transform .1s ease;
}
.topbar button.logout:hover { background: rgba(255,255,255,.28); }
.topbar button.logout:active { transform: scale(.96); }

.container { max-width: 720px; margin: 0 auto; padding: 18px 16px; }
.container.wide { max-width: min(1600px, 96vw); }

/* ===== Cards：柔和陰影取代死板邊框，卡片間有呼吸感 ===== */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow .2s ease, transform .2s ease;
  animation: cardIn .28s ease both;
}
.card h2, .card h3 { margin-top: 0; }
a.card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }

@keyframes cardIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: 1fr 1fr; }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 640px) {
  .grid.cols-2, .grid.cols-3 { grid-template-columns: 1fr; }
}

/* ===== Buttons：更明顯的按下/懸停回饋 ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--brand); color: #fff; border: none; border-radius: 11px;
  padding: 11px 18px; font-size: 15px; font-weight: 600; cursor: pointer;
  box-shadow: 0 2px 8px rgba(26,86,219,.25);
  transition: transform .08s ease, box-shadow .15s ease, opacity .15s ease, background .15s ease;
}
.btn:hover { box-shadow: 0 4px 14px rgba(26,86,219,.35); transform: translateY(-1px); }
.btn:active { transform: translateY(0) scale(0.98); box-shadow: 0 1px 4px rgba(26,86,219,.3); }
.btn:disabled { background: #c3c9d6; box-shadow: none; cursor: not-allowed; transform: none; }
.btn.secondary { background: #fff; color: var(--brand); border: 1.5px solid var(--brand); box-shadow: none; }
.btn.secondary:hover { background: #f0f5ff; box-shadow: 0 2px 8px rgba(26,86,219,.12); }
.btn.danger { background: var(--danger); box-shadow: 0 2px 8px rgba(200,30,30,.25); }
.btn.danger:hover { box-shadow: 0 4px 14px rgba(200,30,30,.35); }
.btn.ok { background: var(--ok); box-shadow: 0 2px 8px rgba(21,128,61,.25); }
.btn.ok:hover { box-shadow: 0 4px 14px rgba(21,128,61,.35); }
.btn.block { width: 100%; }
.btn.big { padding: 22px; font-size: 20px; border-radius: 18px; }

/* ===== Badges：小圓點+更飽和的底色，一眼辨識狀態 ===== */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 4px 11px; border-radius: 999px; font-size: 12px; font-weight: 700; letter-spacing: .01em; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.danger { background: var(--danger-bg); color: var(--danger); }
.badge.muted { background: #eef0f5; color: var(--muted); }
.badge.muted::before { display: none; }
.badge.brand { background: #e7effe; color: var(--brand-dark); }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 11px 10px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 700; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; }
tr:last-child td { border-bottom: none; }
tbody tr { transition: background .12s ease; }
tbody tr:hover { background: #f7f9fd; }

/* ===== 欄位較多的表格：欄寬依內容自適應，超出寬度時橫向捲動而非擠壓文字 ===== */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-scroll table { width: auto; min-width: 100%; }
.table-scroll th, .table-scroll td { white-space: nowrap; }
.table-scroll td select, .table-scroll td input:not([type="checkbox"]) { width: auto; }

/* ===== Inputs：focus 光暈取代單純換邊框色 ===== */
input, select, textarea {
  width: 100%; padding: 10px 12px; border: 1.5px solid var(--border); border-radius: 10px;
  font-size: 15px; background: #fff; color: var(--text); font-family: inherit;
  transition: border-color .15s ease, box-shadow .15s ease;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(26,86,219,.14); }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; font-weight: 600; }
.field { margin-bottom: 14px; }

.muted { color: var(--muted); }
.center { text-align: center; }
.row { display: flex; gap: 10px; align-items: center; }
.row.between { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }

/* ===== Tabbar ===== */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; background: rgba(255,255,255,.92);
  border-top: 1px solid var(--border); display: flex; z-index: 20;
  box-shadow: 0 -4px 16px rgba(16,24,64,.06); backdrop-filter: blur(10px);
}
.tabbar a {
  flex: 1; text-align: center; padding: 9px 4px 8px; color: var(--muted);
  font-size: 11px; display: flex; flex-direction: column; align-items: center; gap: 2px;
  transition: color .15s ease, transform .1s ease;
}
.tabbar a.active { color: var(--brand); font-weight: 700; }
.tabbar a:active { transform: scale(.94); }
.tabbar a .ic { font-size: 20px; transition: transform .15s ease; }
.tabbar a.active .ic { transform: translateY(-1px); }

.empty { text-align: center; color: var(--muted); padding: 34px 10px; }
.spinner { display: inline-block; width: 16px; height: 16px; border: 2px solid rgba(0,0,0,.15); border-top-color: var(--brand); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== 提示卡片（未設定/警示等狀態） ===== */
.callout {
  display: flex; align-items: flex-start; gap: 10px;
  border-radius: 12px; padding: 13px 15px; font-size: 13.5px; line-height: 1.5;
  border: 1px solid transparent;
}
.callout .callout-ic { font-size: 18px; flex: none; line-height: 1; }
.callout.info { background: #eef4ff; border-color: #d7e5fd; color: var(--brand-dark); }
.callout.warn { background: var(--warn-bg); border-color: #fde3a8; color: #8a5106; }
.callout.ok { background: var(--ok-bg); border-color: #bdeecb; color: #0f5c2c; }

/* ===== 登入頁 ===== */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; background: radial-gradient(circle at 20% 20%, #eaf1ff, var(--bg) 55%); }
.login-card { max-width: 380px; width: 100%; text-align: center; box-shadow: var(--shadow-lg); }
.login-card .logo { font-size: 40px; margin-bottom: 8px; }

/* ===== 打卡首頁 ===== */
.clock-face { text-align: center; padding: 10px 0 4px; }
.clock-face .time { font-size: 44px; font-weight: 800; letter-spacing: .02em; font-variant-numeric: tabular-nums; }
.clock-face .date { color: var(--muted); font-size: 14px; margin-top: 2px; }

.punch-btn-wrap { display: flex; justify-content: center; padding: 18px 0 6px; }
.punch-btn {
  width: 172px; height: 172px; border-radius: 50%; border: none; cursor: pointer;
  background: radial-gradient(circle at 30% 28%, #5fa3ff, var(--brand-dark));
  color: #fff; font-size: 22px; font-weight: 800; box-shadow: 0 10px 28px rgba(26,86,219,.4), inset 0 2px 6px rgba(255,255,255,.25);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  transition: transform .12s ease, box-shadow .15s ease;
}
.punch-btn:hover:not(:disabled) { transform: scale(1.02); box-shadow: 0 14px 34px rgba(26,86,219,.48), inset 0 2px 6px rgba(255,255,255,.25); }
.punch-btn:active:not(:disabled) { transform: scale(.96); }
.punch-btn:disabled { background: #c9cedb; box-shadow: none; cursor: not-allowed; }
.punch-btn.out { background: radial-gradient(circle at 30% 28%, #ffab6b, #c2410c); box-shadow: 0 10px 28px rgba(194,65,12,.4), inset 0 2px 6px rgba(255,255,255,.25); }
.punch-btn.out:hover:not(:disabled) { box-shadow: 0 14px 34px rgba(194,65,12,.48), inset 0 2px 6px rgba(255,255,255,.25); }
.punch-btn small { font-size: 12px; font-weight: 500; opacity: .9; }

.status-line { display: flex; align-items: center; justify-content: center; gap: 8px; font-size: 13px; color: var(--muted); margin-top: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; box-shadow: 0 0 0 3px rgba(0,0,0,.05); }
.dot.ok { background: var(--ok); box-shadow: 0 0 0 3px rgba(21,128,61,.15); }
.dot.bad { background: var(--danger); box-shadow: 0 0 0 3px rgba(200,30,30,.15); }
.dot.pending { background: var(--warn); box-shadow: 0 0 0 3px rgba(194,101,10,.15); }

/* ===== Timeline（今日打卡紀錄用） ===== */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline-item { position: relative; padding: 2px 0 18px 30px; }
.timeline-item::before {
  content: ""; position: absolute; left: 5px; top: 5px; width: 11px; height: 11px; border-radius: 50%;
  background: var(--brand); border: 2px solid #fff; box-shadow: 0 0 0 2px var(--brand);
}
.timeline-item.out::before { background: #c2410c; box-shadow: 0 0 0 2px #c2410c; }
.timeline-item::after {
  content: ""; position: absolute; left: 10px; top: 18px; bottom: -4px; width: 2px; background: var(--border);
}
.timeline-item:last-child::after { display: none; }
.timeline-item .tl-title { font-weight: 700; font-size: 14.5px; }
.timeline-item .tl-meta { color: var(--muted); font-size: 12.5px; margin-top: 2px; display: flex; gap: 8px; flex-wrap: wrap; }

/* ===== Tree（單位樹用） ===== */
.tree-row { display: flex; align-items: center; gap: 8px; padding: 10px 8px; border-radius: 10px; transition: background .12s ease; }
.tree-row:hover { background: #f7f9fd; }
.tree-row .tree-indent { flex: none; color: var(--border); font-size: 14px; }
.tree-row .tree-name { font-weight: 700; }
.tree-row .tree-path { color: var(--muted); font-size: 12px; }

.toast {
  position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%);
  background: #1a1d29; color: #fff; padding: 12px 20px; border-radius: 12px;
  font-size: 14px; z-index: 50; box-shadow: var(--shadow-lg); max-width: 90vw; text-align: center;
  animation: toastIn .2s ease both;
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 6px); } to { opacity: 1; transform: translate(-50%, 0); } }
