/* 工讀生打卡：冷色紙卡＋墨藍，一個主要動作 */
:root {
  --ink: #1c2430;
  --ink-soft: #3a4452;
  --muted: #5d6673;
  --paper: #f4f5f2;
  --surface: #ffffff;
  --rule: #d3d8de;
  --rule-soft: #e6e9ec;
  --accent: #2b4a7a;
  --accent-deep: #1f3860;
  --accent-wash: #e9eef6;
  --error: #8f3a2c;
  --radius-s: 4px;
  --radius-m: 8px;
  --font: "IBM Plex Sans", "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { font-size: 16px; }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--paper);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); }
a:hover { color: var(--accent-deep); }

.num { font-variant-numeric: tabular-nums; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- 頂部列 ---- */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--rule);
}
.topbar-inner {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 28px;
  height: 60px;
  display: flex;
  align-items: center;
  gap: 36px;
}
.brand {
  font-weight: 600;
  font-size: 1.05rem;
  letter-spacing: 0.04em;
  color: var(--ink);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand-mark {
  width: 14px;
  height: 18px;
  border: 2px solid var(--accent);
  border-radius: 2px;
  position: relative;
}
.brand-mark::after {
  content: "";
  position: absolute;
  left: 2px; right: 2px; top: 4px;
  height: 2px;
  background: var(--accent);
}
.nav { display: flex; gap: 4px; flex: 1; }
.nav a {
  color: var(--ink-soft);
  text-decoration: none;
  padding: 18px 12px;
  border-bottom: 2px solid transparent;
  font-size: 0.95rem;
  white-space: nowrap;
}
.nav a:hover { color: var(--ink); }
.nav a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--accent); font-weight: 500; }
.userbox { display: flex; align-items: center; gap: 14px; white-space: nowrap; color: var(--muted); font-size: 0.9rem; }

/* ---- 版面 ---- */
.page {
  max-width: 1120px;
  margin: 0 auto;
  padding: 36px 28px 64px;
}
.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 28px;
  flex-wrap: wrap;
}
h1 { font-size: 1.6rem; font-weight: 600; margin: 0; line-height: 1.3; }
h2 { font-size: 1.1rem; font-weight: 600; margin: 0 0 14px; }
.sub { color: var(--muted); margin: 4px 0 0; font-size: 0.95rem; }

.panel {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius-m);
  padding: 24px 28px;
}
.panel + .panel { margin-top: 24px; }
.stack > * + * { margin-top: 24px; }

/* ---- 按鈕 ---- */
.btn {
  font: inherit;
  font-size: 0.95rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-s);
  border: 1px solid var(--rule);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { border-color: var(--ink-soft); color: var(--ink); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-deep); border-color: var(--accent-deep); color: #fff; }
.btn-link { border-color: transparent; background: none; color: var(--accent); padding: 4px 6px; }
.btn-link:hover { border-color: transparent; text-decoration: underline; color: var(--accent-deep); }
.btn-sm { font-size: 0.85rem; padding: 4px 10px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* ---- 表單 ---- */
label.field { display: block; }
.field-label { display: block; font-size: 0.9rem; color: var(--ink-soft); margin-bottom: 6px; font-weight: 500; }
.field-hint { display: block; font-size: 0.82rem; color: var(--muted); margin-top: 4px; }
input, textarea, select {
  font: inherit;
  font-size: 0.95rem;
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--rule);
  border-radius: var(--radius-s);
  background: var(--surface);
  color: var(--ink);
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-wash); }
textarea { resize: vertical; min-height: 96px; line-height: 1.5; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 20px; }
.form-grid .span-2 { grid-column: 1 / -1; }
.form-error { color: var(--error); font-size: 0.9rem; margin: 12px 0 0; min-height: 1.2em; }
.form-error:empty { display: none; }

/* ---- 提示訊息 ---- */
.flash {
  position: fixed;
  top: 72px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 10px 18px;
  border-radius: var(--radius-s);
  font-size: 0.92rem;
  z-index: 50;
  max-width: 90vw;
}
.flash.is-error { background: var(--error); }
.flash[hidden] { display: none; }

/* ---- 月份切換 ---- */
.month-switch { display: inline-flex; align-items: center; border: 1px solid var(--rule); border-radius: var(--radius-s); background: var(--surface); }
.month-switch button { font: inherit; border: 0; background: none; padding: 7px 12px; cursor: pointer; color: var(--ink-soft); }
.month-switch button:hover { color: var(--ink); background: var(--paper); }
.month-switch .month-label { padding: 7px 14px; border-left: 1px solid var(--rule); border-right: 1px solid var(--rule); min-width: 136px; text-align: center; font-weight: 500; }

/* ---- 數字摘要 ---- */
.figures { display: flex; gap: 0; border: 1px solid var(--rule); border-radius: var(--radius-m); background: var(--surface); margin-bottom: 24px; }
.figure { padding: 16px 28px; flex: 1; }
.figure + .figure { border-left: 1px solid var(--rule-soft); }
.figure-label { font-size: 0.85rem; color: var(--muted); }
.figure-value { font-size: 1.5rem; font-weight: 500; font-variant-numeric: tabular-nums; line-height: 1.4; }
.figure-value small { font-size: 0.9rem; color: var(--muted); font-weight: 400; margin-left: 2px; }

/* ---- 表格 ---- */
.table-wrap { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius-m); overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.93rem; }
th, td { padding: 11px 14px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--rule-soft); }
th { font-weight: 500; color: var(--muted); font-size: 0.85rem; background: #fafbfa; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
td.r, th.r { text-align: right; font-variant-numeric: tabular-nums; }
td.nowrap { white-space: nowrap; }
td.task { max-width: 340px; white-space: pre-wrap; word-break: break-word; }
tfoot td { font-weight: 600; border-top: 1px solid var(--rule); border-bottom: 0; background: #fafbfa; }
.table-mid td { vertical-align: middle; }
.empty { padding: 36px 20px; text-align: center; color: var(--muted); }
.row-inactive td { color: var(--muted); }

/* ---- 標籤（中性，不用燈號色） ---- */
.tag {
  display: inline-block;
  font-size: 0.78rem;
  line-height: 1.5;
  padding: 1px 8px;
  border: 1px solid var(--rule);
  border-radius: 3px;
  color: var(--ink-soft);
  background: var(--surface);
  white-space: nowrap;
  margin: 1px 4px 1px 0;
}
.tag-solid { background: var(--accent-wash); border-color: #c9d4e6; color: var(--accent-deep); }
.tag-pending { border-style: dashed; color: var(--muted); }
.tag-reason { background: #f1f2f4; border-color: #dfe2e6; color: var(--ink); }

/* ---- 對話框 ---- */
dialog {
  border: 1px solid var(--rule);
  border-radius: var(--radius-m);
  padding: 0;
  width: min(560px, 92vw);
  color: var(--ink);
  box-shadow: 0 18px 48px rgba(28, 36, 48, 0.22);
}
dialog::backdrop { background: rgba(28, 36, 48, 0.4); }
.dialog-body { padding: 24px 28px 8px; }
.dialog-body h2 { margin-bottom: 18px; }
.dialog-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 28px 24px; }

/* ---- 登入 ---- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(400px, 100%); background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius-m); padding: 36px 36px 32px; }
.login-card .brand { margin-bottom: 26px; font-size: 1.2rem; }
.login-card .field + .field { margin-top: 16px; }
.login-card .btn { width: 100%; margin-top: 24px; padding: 10px 16px; }

/* ---- 打卡首頁 ---- */
.clock-layout { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 24px; align-items: start; }
.timecard { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius-m); overflow: hidden; }
.timecard-head { padding: 28px 36px 8px; }
.timecard-date { color: var(--muted); font-size: 1rem; }
.timecard-now { font-size: 4.6rem; font-weight: 300; letter-spacing: 0.02em; font-variant-numeric: tabular-nums; line-height: 1.1; margin-top: 4px; }
.timecard-state { display: flex; align-items: baseline; gap: 14px; padding: 18px 36px; border-top: 1px dashed var(--rule); margin-top: 22px; }
.state-label { font-weight: 600; font-size: 1.1rem; }
.state-detail { color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.elapsed { font-size: 1.1rem; font-weight: 500; color: var(--accent-deep); }
.punch {
  display: block;
  width: 100%;
  border: 0;
  border-top: 1px solid var(--accent-deep);
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-size: 1.5rem;
  font-weight: 500;
  letter-spacing: 0.12em;
  padding: 28px 20px;
  cursor: pointer;
}
.punch:hover { background: var(--accent-deep); }
.punch:disabled { opacity: 0.6; cursor: progress; }
.punch-hint { display: block; font-size: 0.85rem; letter-spacing: 0; font-weight: 400; opacity: 0.8; margin-top: 4px; }
.checkout-form, .stale-form { padding: 22px 36px 30px; border-top: 1px solid var(--rule); background: #fafbfa; }
.checkout-form .btn-row, .stale-form .btn-row { margin-top: 16px; }
.stale-note { padding: 14px 16px; border-left: 3px solid var(--accent); background: var(--accent-wash); margin-bottom: 18px; color: var(--ink); }
.side h2 { font-size: 1rem; }
.side .figure-value { font-size: 1.7rem; }
.side-list { margin: 0; padding: 0; list-style: none; }
.side-list li { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--rule-soft); font-variant-numeric: tabular-nums; font-size: 0.93rem; }
.side-list li:last-child { border-bottom: 0; }

/* ---- 明細 ---- */
.metrics { font-variant-numeric: tabular-nums; white-space: nowrap; font-size: 0.88rem; color: var(--ink-soft); }
.metrics b { color: var(--ink); font-weight: 500; }
.commit-msg { white-space: pre-wrap; word-break: break-word; max-width: 420px; }
.sha { font-family: "IBM Plex Mono", ui-monospace, monospace; font-size: 0.85rem; color: var(--muted); }
.settings-group + .settings-group { margin-top: 28px; padding-top: 24px; border-top: 1px solid var(--rule-soft); }
.settings-group p { margin: -8px 0 16px; color: var(--muted); font-size: 0.9rem; }

@media (max-width: 860px) {
  .clock-layout { grid-template-columns: 1fr; }
  .topbar-inner { gap: 16px; padding: 0 16px; overflow-x: auto; }
  .page { padding: 24px 16px 48px; }
  .brand { white-space: nowrap; }
  .nav a { padding: 18px 8px; }
  .timecard-head, .timecard-state, .checkout-form, .stale-form { padding-left: 20px; padding-right: 20px; }
  .timecard-now { font-size: 3.4rem; }
  .figures { flex-direction: column; }
  .figure + .figure { border-left: 0; border-top: 1px solid var(--rule-soft); }
  .form-grid { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

@media (max-width: 480px) {
  #user-name { display: none; }
}
