/* ============================================================
   打卡鐘 Punch-in — 打卡印章 / 時間卡 美學
   紙感米白底 × 墨黑文字 × 朱紅印章
   ============================================================ */

:root {
  --paper: #f4efe6;
  --paper-2: #ede6d8;
  --card: #fbf8f1;
  --ink: #2b2620;
  --ink-soft: #6b6257;
  --ink-faint: #a89e8f;
  --seal: #c93a2b;        /* 朱紅印章 */
  --seal-dark: #a92b1e;
  --seal-soft: #f3d9d3;
  --green: #3a7d5c;
  --green-soft: #dcebe2;
  --amber: #b98a1e;
  --amber-soft: #f3e7c4;
  --line: #ddd3c0;
  --shadow: 0 10px 30px rgba(80, 62, 40, 0.12);
  --radius: 18px;
  --font-body: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  --font-serif: "Noto Serif TC", "Songti TC", serif;
  --font-mono: "IBM Plex Mono", "SFMono-Regular", Consolas, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  min-height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

/* 紙感背景：細格紋 + 邊緣暈染 */
body {
  background-image:
    radial-gradient(ellipse 120% 60% at 50% -10%, rgba(201, 58, 43, 0.06), transparent 60%),
    radial-gradient(ellipse 100% 50% at 50% 110%, rgba(58, 125, 92, 0.05), transparent 60%),
    repeating-linear-gradient(0deg, transparent 0 31px, rgba(107, 98, 87, 0.045) 31px 32px),
    repeating-linear-gradient(90deg, transparent 0 31px, rgba(107, 98, 87, 0.045) 31px 32px);
}

.hidden { display: none !important; }

/* ============ 共用元件 ============ */
.paper-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.btn {
  font-family: var(--font-body);
  font-weight: 700;
  border: none;
  cursor: pointer;
  border-radius: 12px;
  padding: 12px 20px;
  font-size: 15px;
  transition: transform 0.12s ease, box-shadow 0.2s ease, background 0.2s ease, opacity 0.2s;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: translateY(1px) scale(0.99); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-primary {
  background: var(--seal);
  color: #fff;
  box-shadow: 0 4px 0 var(--seal-dark), 0 8px 18px rgba(201, 58, 43, 0.3);
}
.btn-primary:hover:not(:disabled) { background: var(--seal-dark); }

.btn-ghost {
  background: transparent;
  color: var(--ink-soft);
  border: 1.5px solid var(--line);
}
.btn-ghost:hover:not(:disabled) { border-color: var(--ink-faint); color: var(--ink); }

.btn-block { width: 100%; }
.btn-sm { padding: 8px 14px; font-size: 13px; border-radius: 10px; }

/* Toast */
.toast {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%) translateY(-80px);
  background: var(--ink);
  color: #fff;
  padding: 12px 22px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 500;
  z-index: 200;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  transition: transform 0.35s cubic-bezier(0.2, 0.9, 0.3, 1.2);
  max-width: 90vw;
  text-align: center;
}
.toast.show { transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--seal); }
.toast.success { background: var(--green); }

/* ============ 登入頁 ============ */
.login-view {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 400px;
  padding: 40px 32px 28px;
  animation: rise-in 0.5s ease both;
}
@keyframes rise-in {
  from { opacity: 0; transform: translateY(18px); }
  to { opacity: 1; transform: translateY(0); }
}

.brand { text-align: center; margin-bottom: 28px; }
.brand-mark {
  position: relative;
  width: 72px;
  height: 72px;
  margin: 0 auto 14px;
  display: grid;
  place-items: center;
  color: var(--seal);
}
.brand-ring {
  position: absolute;
  inset: 0;
  border: 3px dashed currentColor;
  border-radius: 50%;
  animation: spin 24s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.brand-mark svg { width: 34px; height: 34px; }

.brand-title {
  font-family: var(--font-serif);
  font-weight: 900;
  font-size: 34px;
  letter-spacing: 6px;
  text-indent: 6px;
  color: var(--ink);
}
.brand-sub {
  margin-top: 6px;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 3px;
  color: var(--ink-faint);
}

.stack { display: flex; flex-direction: column; gap: 16px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-soft);
  letter-spacing: 1px;
}
.field input {
  font-family: var(--font-body);
  font-size: 16px;
  padding: 13px 14px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.field input:focus {
  border-color: var(--seal);
  box-shadow: 0 0 0 3px rgba(201, 58, 43, 0.12);
}
.login-hint {
  margin-top: 20px;
  text-align: center;
  font-size: 12px;
  color: var(--ink-faint);
}

/* ============ 主應用佈局 ============ */
.app-view {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 560px;
  margin: 0 auto;
  padding: 0 16px;
}
.app-header { margin-top: 14px; padding: 12px 16px; border-radius: 16px; }
.app-header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.app-brand { display: flex; align-items: center; gap: 10px; }
.brand-mark.small {
  width: 36px;
  height: 36px;
  margin: 0;
}
.brand-mark.small svg { width: 18px; height: 18px; }
.app-name { font-family: var(--font-serif); font-weight: 900; font-size: 17px; letter-spacing: 2px; }
.app-user { font-size: 12px; color: var(--ink-soft); }

.tab-bar { display: flex; gap: 4px; }
.tab {
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 700;
  padding: 7px 12px;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
  -webkit-tap-highlight-color: transparent;
}
.tab:hover { background: var(--paper-2); color: var(--ink); }
.tab.active { background: var(--ink); color: var(--paper); }
.tab-logout { color: var(--seal); }

.app-main {
  flex: 1;
  padding: 18px 0 30px;
  animation: fade-in 0.3s ease;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.app-footer {
  display: flex;
  justify-content: space-between;
  padding: 14px 4px 26px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-faint);
  letter-spacing: 1px;
}

/* ============ 今日頁 ============ */
.home-date {
  text-align: center;
  margin-bottom: 6px;
}
.home-date .date-main {
  font-family: var(--font-serif);
  font-weight: 900;
  font-size: 24px;
  letter-spacing: 1px;
}
.home-date .date-sub {
  font-size: 13px;
  color: var(--ink-soft);
  margin-top: 2px;
}

/* 大時鐘 */
.clock-wrap {
  display: flex;
  justify-content: center;
  margin: 8px 0 4px;
}
.clock {
  font-family: var(--font-mono);
  font-size: clamp(52px, 16vw, 72px);
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  position: relative;
}
.clock .colon { animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0.25; } }

/* 打卡大按鈕 — 印章 */
.punch-zone {
  display: grid;
  place-items: center;
  padding: 18px 0 8px;
}
.punch-btn {
  position: relative;
  width: 220px;
  height: 220px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  font-family: var(--font-serif);
  font-weight: 900;
  display: grid;
  place-items: center;
  transition: transform 0.18s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.25s;
  -webkit-tap-highlight-color: transparent;
  animation: rise-in 0.55s 0.1s ease both;
}
.punch-btn .punch-inner {
  width: 178px;
  height: 178px;
  border-radius: 50%;
  border: 2px dashed rgba(255, 255, 255, 0.55);
  display: grid;
  place-items: center;
  flex-direction: column;
  gap: 4px;
}
.punch-btn .punch-label { font-size: 30px; letter-spacing: 6px; text-indent: 6px; }
.punch-btn .punch-time { font-family: var(--font-mono); font-size: 13px; font-weight: 500; letter-spacing: 1px; opacity: 0.85; }

.punch-btn.check-in {
  background: radial-gradient(circle at 32% 28%, #d6452f, var(--seal) 55%, var(--seal-dark));
  color: #fff;
  box-shadow: 0 14px 34px rgba(201, 58, 43, 0.4), inset 0 2px 6px rgba(255, 255, 255, 0.35);
}
.punch-btn.check-in:hover { transform: scale(1.05) rotate(-2deg); }
.punch-btn.check-in:active { transform: scale(0.96); }

.punch-btn.check-out {
  background: radial-gradient(circle at 32% 28%, #4a8f6b, var(--green) 55%, #2c6147);
  color: #fff;
  box-shadow: 0 14px 34px rgba(58, 125, 92, 0.4), inset 0 2px 6px rgba(255, 255, 255, 0.35);
}
.punch-btn.check-out:hover { transform: scale(1.05) rotate(2deg); }
.punch-btn.check-out:active { transform: scale(0.96); }

.punch-btn.disabled {
  background: var(--ink-soft);
  box-shadow: 0 8px 20px rgba(43, 38, 32, 0.25);
  cursor: default;
}
.punch-btn.disabled:hover { transform: none; }

/* 印章動畫 */
.stamp-anim {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(3) rotate(-18deg);
  pointer-events: none;
  z-index: 150;
  font-family: var(--font-serif);
  font-weight: 900;
  font-size: 42px;
  letter-spacing: 8px;
  color: var(--seal);
  border: 5px solid var(--seal);
  border-radius: 10px;
  padding: 10px 22px;
  background: rgba(244, 239, 230, 0.92);
  opacity: 0;
}
.stamp-anim.show {
  animation: stamp 0.6s cubic-bezier(0.2, 0.9, 0.3, 1.4) both;
}
@keyframes stamp {
  0% { transform: translate(-50%, -50%) scale(3) rotate(-18deg); opacity: 0; }
  55% { transform: translate(-50%, -50%) scale(0.95) rotate(-8deg); opacity: 1; }
  75% { transform: translate(-50%, -50%) scale(1.04) rotate(-6deg); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(1) rotate(-8deg); opacity: 0.9; }
}

/* 今日資訊卡 */
.today-card {
  margin-top: 16px;
  padding: 18px;
  animation: rise-in 0.5s 0.2s ease both;
}
.today-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 14px;
}
.today-item {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  text-align: center;
}
.today-item .k {
  font-size: 12px;
  color: var(--ink-soft);
  letter-spacing: 1px;
}
.today-item .v {
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 700;
  margin-top: 4px;
}
.today-item .v.empty { color: var(--ink-faint); font-size: 16px; }

/* 狀態徽章 */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
}
.badge.normal { background: var(--green-soft); color: var(--green); }
.badge.late, .badge.late_early_leave { background: var(--amber-soft); color: var(--amber); }
.badge.early_leave { background: var(--seal-soft); color: var(--seal); }
.badge.absent { background: var(--paper-2); color: var(--ink-faint); }

.today-status { text-align: center; }
.today-status .big {
  font-family: var(--font-serif);
  font-weight: 900;
  font-size: 20px;
  letter-spacing: 2px;
}

/* 工時進度條 */
.work-bar {
  margin-top: 12px;
}
.work-bar .bar-track {
  height: 10px;
  background: var(--paper-2);
  border-radius: 999px;
  overflow: hidden;
}
.work-bar .bar-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--green), #4f9d78);
  border-radius: 999px;
  transition: width 0.8s cubic-bezier(0.3, 1, 0.4, 1);
}
.work-bar .bar-caption {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--ink-soft);
  margin-top: 6px;
}

/* ============ 歷史頁 ============ */
.month-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.month-nav .month-label {
  font-family: var(--font-serif);
  font-weight: 900;
  font-size: 20px;
  letter-spacing: 1px;
}
.month-nav button {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1.5px solid var(--line);
  background: var(--card);
  color: var(--ink);
  font-size: 17px;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}
.month-nav button:hover { background: var(--paper-2); border-color: var(--ink-faint); }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 18px;
}
.stat-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 8px;
  text-align: center;
  box-shadow: 0 4px 12px rgba(80, 62, 40, 0.07);
}
.stat-card .n {
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 700;
  line-height: 1.1;
}
.stat-card .t { font-size: 11px; color: var(--ink-soft); margin-top: 3px; }

.record-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.record-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 13px 15px;
  animation: rise-in 0.35s ease both;
}
.record-item .r-date {
  font-weight: 700;
  font-size: 14px;
}
.record-item .r-week {
  font-size: 11px;
  color: var(--ink-faint);
}
.record-item .r-time {
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 500;
  text-align: right;
}
.record-item .r-time .sep { color: var(--ink-faint); }
.record-item .r-hours {
  font-size: 11px;
  color: var(--ink-soft);
  margin-top: 2px;
}

.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--ink-faint);
}
.empty-state .big { font-size: 40px; margin-bottom: 10px; }

/* ============ 管理頁 ============ */
.page-title {
  font-family: var(--font-serif);
  font-weight: 900;
  font-size: 24px;
  letter-spacing: 1px;
  margin-bottom: 4px;
}
.page-sub {
  font-size: 13px;
  color: var(--ink-soft);
  margin-bottom: 18px;
}

.admin-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.data-table-wrap {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 4px 14px rgba(80, 62, 40, 0.08);
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.data-table th {
  text-align: left;
  padding: 11px 12px;
  background: var(--paper-2);
  font-size: 12px;
  color: var(--ink-soft);
  letter-spacing: 0.5px;
  white-space: nowrap;
}
.data-table td {
  padding: 11px 12px;
  border-top: 1px solid var(--line);
  vertical-align: middle;
}
.data-table .mono { font-family: var(--font-mono); }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.icon-btn {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink-soft);
  cursor: pointer;
  font-size: 14px;
  transition: all 0.15s;
}
.icon-btn:hover { color: var(--ink); border-color: var(--ink-faint); }
.icon-btn.danger:hover { color: var(--seal); border-color: var(--seal); }

/* 篩選列 */
.filter-bar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}
.filter-bar input, .filter-bar select {
  font-family: var(--font-body);
  font-size: 14px;
  padding: 10px 12px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  color: var(--ink);
  outline: none;
}
.filter-bar input:focus, .filter-bar select:focus { border-color: var(--seal); }

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(43, 38, 32, 0.45);
  backdrop-filter: blur(3px);
  display: grid;
  place-items: center;
  z-index: 100;
  padding: 20px;
  animation: fade-in 0.2s ease;
}
.modal {
  width: 100%;
  max-width: 420px;
  max-height: 88dvh;
  overflow-y: auto;
  padding: 26px;
  animation: rise-in 0.3s ease both;
}
.modal h3 {
  font-family: var(--font-serif);
  font-weight: 900;
  font-size: 20px;
  letter-spacing: 1px;
  margin-bottom: 18px;
}
.modal .stack { gap: 12px; }
.modal .btn-row { display: flex; gap: 10px; margin-top: 8px; }
.modal .btn-row .btn { flex: 1; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* 切換開關 */
.toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  user-select: none;
}
.toggle input { display: none; }
.toggle .track {
  width: 44px;
  height: 24px;
  border-radius: 999px;
  background: var(--paper-2);
  position: relative;
  transition: background 0.2s;
  flex-shrink: 0;
}
.toggle .track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  transition: transform 0.2s;
}
.toggle input:checked + .track { background: var(--green); }
.toggle input:checked + .track::after { transform: translateX(20px); }

/* 響應式 */
@media (max-width: 480px) {
  .app-header { border-radius: 14px; }
  .tab-bar { width: 100%; justify-content: flex-end; }
  .punch-btn { width: 190px; height: 190px; }
  .punch-btn .punch-inner { width: 152px; height: 152px; }
  .punch-btn .punch-label { font-size: 26px; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
}

/* 列印用（管理匯出畫面） */
@media print {
  .app-header, .app-footer, .admin-actions, .filter-bar, .tab-bar { display: none; }
  body { background: #fff; }
  .data-table-wrap { box-shadow: none; border: 1px solid #ccc; }
}
