/* ===== 色彩與基本設定 ===== */
:root {
  --bg: #f4f1ec;
  --surface: #ffffff;
  --surface-2: #f9f7f3;
  --topbar: #fbfaf7;
  --line: #e6e1d9;
  --line-strong: #d9d3c9;
  --text: #2b2926;
  --muted: #8a8279;
  --accent: #d6322b;
  --accent-hover: #bd2a24;
  --accent-soft: #f6dfdc;
  --accent-disabled: #dba9a2;
  --tab-active: #ece8e1;
  --ok: #2f7d4f;
  --warn: #b26a12;
  --bad: #c0392b;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow: 0 1px 2px rgba(60, 50, 40, .04);
  --font: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.6 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
h1, h2, h3 { margin: 0; font-weight: 700; letter-spacing: .02em; }
svg.icon { width: 20px; height: 20px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ===== 頁首（電腦版） ===== */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--topbar);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 1040px; margin: 0 auto;
  display: flex; align-items: center; gap: 16px;
  height: 60px; padding: 0 24px;
}
.brand { font-weight: 700; font-size: 18px; text-decoration: none; white-space: nowrap; }
.who { color: var(--muted); font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tabs { margin-left: auto; display: flex; align-items: center; gap: 4px; }
.tab {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: 8px;
  text-decoration: none; color: #5d574f; font-size: 16px; white-space: nowrap;
}
.tab:hover { background: var(--surface-2); color: var(--text); }
.tab.active { background: var(--tab-active); color: var(--text); }
.tab .badge { margin-left: 2px; }
.logout {
  display: inline-flex; align-items: center; gap: 8px;
  margin-left: 20px; padding: 8px 6px;
  background: none; border: 0; color: var(--text); font: inherit; cursor: pointer;
}

/* ===== 底部分頁列（手機版） ===== */
.bottombar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: none;
  background: var(--topbar);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottombar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 0 7px; text-decoration: none; color: var(--muted); font-size: 12px; position: relative;
}
.bottombar a.active { color: var(--accent); }
.bottombar svg.icon { width: 24px; height: 24px; }
.bottombar .dot {
  position: absolute; top: 4px; left: calc(50% + 8px);
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--accent); color: #fff; font-size: 11px; line-height: 18px; text-align: center;
}

/* ===== 版面 ===== */
.page { max-width: 1040px; margin: 0 auto; padding: 40px 24px 64px; }
.page.narrow { max-width: 880px; }
.page-head { margin: 0 0 22px; }
.page-title { font-size: 30px; line-height: 1.3; }
.page-sub { margin: 6px 0 0; color: var(--muted); font-size: 16px; }
.section-title { font-size: 17px; margin: 28px 0 10px; color: #4a453f; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-2 > * { min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.ok { color: var(--ok); }
.warn { color: var(--warn); }
.bad { color: var(--bad); }

/* ===== 卡片與清單列（參考圖的主要元件） ===== */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
}
.card + .card { margin-top: 16px; }
.list {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.row {
  display: flex; align-items: center; gap: 16px;
  min-height: 96px; padding: 16px 20px;
  border-top: 1px solid var(--line);
  text-decoration: none; color: inherit;
}
.row:first-child { border-top: 0; }
a.row:hover { background: var(--surface-2); }
.row.compact { min-height: 64px; padding: 12px 20px; }
.row-main { flex: 1; min-width: 0; }
.row-title { font-size: 18px; line-height: 1.45; }
.row-sub { margin-top: 2px; color: var(--muted); font-size: 16px; }
.row-sub .sep { margin: 0 6px; }
.row-value { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.row-value strong { font-size: 22px; font-weight: 600; }
.row-value .denom { color: var(--muted); font-size: 16px; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.chev { color: #6f6961; width: 18px; height: 18px; }
.empty { padding: 28px 20px; text-align: center; color: var(--muted); }

.badge {
  display: inline-block; padding: 1px 9px; border-radius: 999px;
  font-size: 13px; line-height: 20px; white-space: nowrap;
  background: var(--tab-active); color: #5d574f;
}
.badge.pending { background: #fbeed9; color: var(--warn); }
.badge.approved, .badge.ok { background: #e3f1e7; color: var(--ok); }
.badge.rejected, .badge.bad { background: var(--accent-soft); color: var(--bad); }
.badge.cancelled { background: var(--tab-active); color: var(--muted); }
.badge.count { background: var(--accent); color: #fff; }

.notice {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 18px; margin-bottom: 16px;
  background: #fdf5ea; border: 1px solid #f0dcbc; border-radius: var(--radius);
  text-decoration: none;
}
.notice strong { flex: 1; font-weight: 600; }

/* ===== 首頁 ===== */
.today { display: flex; gap: 0; }
.today .slot { flex: 1; padding: 6px 0; }
.today .slot + .slot { border-left: 1px solid var(--line); padding-left: 20px; }
.today .label { color: var(--muted); font-size: 14px; }
.today .time { font-size: 28px; font-weight: 600; font-variant-numeric: tabular-nums; }
.quick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.quick a {
  display: flex; flex-direction: column; align-items: flex-start; gap: 10px;
  padding: 16px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line);
  text-decoration: none;
}
.quick a:hover { border-color: var(--line-strong); }
.quick .q-icon {
  display: grid; place-items: center; width: 38px; height: 38px; border-radius: 10px;
  background: var(--accent-soft); color: var(--accent);
}
.code-box { font-size: 30px; font-weight: 700; letter-spacing: .25em; font-variant-numeric: tabular-nums; margin: 6px 0; }

/* ===== 表格（電腦版用） ===== */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 15px; }
th, td { padding: 11px 14px; border-top: 1px solid var(--line); text-align: left; vertical-align: top; }
thead th { border-top: 0; color: var(--muted); font-weight: 500; font-size: 14px; background: var(--surface-2); white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.weekend td { color: var(--muted); }

/* ===== 表單 ===== */
.form-card { max-width: 560px; }
.field { margin-bottom: 18px; }
.field label, form p label { display: block; margin-bottom: 8px; font-size: 16px; }
input[type=text], input[type=password], input[type=number], input[type=email], input[type=date],
input[type=time], input[type=datetime-local], input[type=month], input[type=file], select, textarea {
  width: 100%; min-height: 52px; padding: 12px 14px;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  font: inherit; font-size: 16px;
  -webkit-appearance: none; appearance: none;
}
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' fill='none' stroke='%238a8279' stroke-width='1.8'%3E%3Cpath d='M1 1.5l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center; padding-right: 38px;
}
textarea { min-height: 96px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--accent); }
form p { margin: 0 0 18px; }
.helptext { display: block; margin-top: 6px; color: var(--muted); font-size: 14px; }
.errorlist { margin: 6px 0; padding: 0; list-style: none; color: var(--bad); font-size: 14px; }
.errorlist.nonfield { padding: 12px 14px; background: var(--accent-soft); border-radius: var(--radius); margin-bottom: 16px; }

.btn, button.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 22px; border-radius: var(--radius);
  background: var(--accent); color: #fff; border: 1px solid var(--accent);
  font: inherit; font-size: 16px; text-decoration: none; cursor: pointer;
}
.btn:hover { background: var(--accent-hover); }
.btn:disabled { background: var(--accent-disabled); border-color: var(--accent-disabled); cursor: default; }
.btn.block { width: 100%; min-height: 58px; font-size: 19px; }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--line-strong); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { min-height: 36px; padding: 0 14px; font-size: 14px; }
.btn.danger { background: transparent; color: var(--bad); border-color: #e6b8b2; }
.btn.line { background: #06c755; border-color: #06c755; }
.btn.line:hover { background: #05b04b; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
form.inline { display: inline; margin: 0; }

.messages { list-style: none; padding: 0; margin: 0 0 18px; }
.messages li {
  padding: 12px 16px; margin-bottom: 8px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--muted);
}
.messages li.success { border-left-color: var(--ok); }
.messages li.error { border-left-color: var(--bad); }
.messages li.warning { border-left-color: var(--warn); }

/* ===== 登入頁（參考圖 2） ===== */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 32px 16px; }
.auth-card {
  width: 100%; max-width: 560px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg);
  padding: 32px 30px 28px;
}
.logo { display: flex; flex-direction: column; align-items: center; margin-bottom: 18px; }
.logo-block {
  background: var(--accent); color: #fff;
  font-weight: 900; font-size: 46px; line-height: 1; letter-spacing: .02em;
  padding: 6px 18px 4px; text-transform: uppercase;
}
.logo-name { color: var(--accent); font-weight: 800; font-size: 26px; letter-spacing: .08em; margin-top: 2px; }
.auth-title { text-align: center; font-size: 26px; margin-top: 8px; }
.auth-sub { text-align: center; color: var(--muted); margin: 6px 0 22px; font-size: 17px; }
.auth-help { text-align: center; color: var(--muted); font-size: 15px; margin: 20px 0 0; }
.auth-alt { text-align: center; margin: 18px 0 0; }
.auth-alt a { text-decoration: underline; text-underline-offset: 3px; }
.divider { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 14px; margin: 18px 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }

/* ===== 薪資單 ===== */
.payslip-total { display: flex; justify-content: space-between; align-items: baseline; padding: 18px 20px; }
.payslip-total strong { font-size: 30px; font-variant-numeric: tabular-nums; }

/* ===== 顯示切換 ===== */
.mobile-only { display: none; }

/* ===== 平板以下 ===== */
@media (max-width: 900px) {
  .tab { padding: 8px 10px; }
  .who { display: none; }
}

/* ===== 手機 ===== */
@media (max-width: 720px) {
  body { font-size: 16px; }
  .desktop-only { display: none !important; }
  .mobile-only { display: block; }
  .bottombar { display: flex; }
  .topbar-inner { height: 54px; padding: 0 16px; }
  .who { display: block; margin-left: auto; font-size: 14px; }
  .page { padding: 22px 16px calc(92px + env(safe-area-inset-bottom)); }
  .page-title { font-size: 24px; }
  .page-sub { font-size: 15px; }
  .grid-2 { grid-template-columns: 1fr; gap: 16px; }
  .quick { grid-template-columns: 1fr 1fr; gap: 10px; }
  .row { min-height: 76px; padding: 14px 16px; gap: 12px; }
  .row.compact { min-height: 58px; padding: 10px 16px; }
  .row-title { font-size: 16px; }
  .row-sub { font-size: 14px; }
  .row-value strong { font-size: 20px; }
  .row-value .denom { font-size: 14px; }
  .card { padding: 16px; }
  .today .time { font-size: 24px; }
  .btn { min-height: 50px; }
  .actions.stack-mobile { flex-direction: column; align-items: stretch; }
  .actions.stack-mobile .btn { width: 100%; }
  .form-card { max-width: none; }
  .auth { place-items: start center; padding-top: 24px; }
  .auth-card { padding: 26px 20px 22px; }
  .logo-block { font-size: 40px; }
  .logo-name { font-size: 22px; }
  .auth-title { font-size: 24px; }
}

@media print {
  .topbar, .bottombar, .no-print { display: none !important; }
  body { background: #fff; }
  .page { padding: 0; }
  .card, .list { border: 0; box-shadow: none; }
}
