/* ===== 肝都黑了 出缺勤系統 — shadcn-like 暗色/亮色 token ===== */
:root {
  --bg: #ffffff;
  --bg-elev: #f8f9fb;
  --bg-card: #ffffff;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --text: #0f172a;
  --text-muted: #64748b;
  --text-dim: #94a3b8;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-fg: #ffffff;
  --success: #16a34a;
  --warning: #ca8a04;
  --danger: #dc2626;
  --info: #0891b2;
  --ring: rgba(37, 99, 235, 0.35);
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 4px 12px rgba(15, 23, 42, 0.04);
  --radius: 10px;
  --radius-sm: 6px;
  --radius-lg: 14px;
}

[data-theme="dark"] {
  --bg: #0a0b0e;
  --bg-elev: #15161a;
  --bg-card: #15161a;
  --border: #2a2b30;
  --border-strong: #3a3b41;
  --text: #eaeaea;
  --text-muted: #a8a8ad;
  --text-dim: #6b6c72;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --primary-fg: #ffffff;
  --success: #22c55e;
  --warning: #eab308;
  --danger: #ef4444;
  --info: #06b6d4;
  --ring: rgba(59, 130, 246, 0.45);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 12px rgba(0, 0, 0, 0.3);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

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

button { font-family: inherit; }

.boot-loading {
  display: flex; align-items: center; justify-content: center;
  height: 100vh; color: var(--text-muted); font-size: 14px;
}

/* ===== Layout ===== */
.app-shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  grid-template-rows: 56px 1fr;
  grid-template-areas:
    "sidebar topbar"
    "sidebar main";
  height: 100vh;
}
.topbar {
  grid-area: topbar;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
}
.topbar-title { font-weight: 600; font-size: 15px; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }

.sidebar {
  grid-area: sidebar;
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  padding: 16px 12px;
  overflow-y: auto;
}
.sidebar-brand {
  font-weight: 700; font-size: 14px; padding: 8px 10px; margin-bottom: 12px;
  letter-spacing: 0.3px;
}
.sidebar-brand small { display: block; color: var(--text-dim); font-weight: 400; font-size: 11px; margin-top: 2px; }
.sidebar-section { margin-bottom: 16px; }
.sidebar-section-title {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.6px;
  color: var(--text-dim); padding: 4px 10px; margin-bottom: 4px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--radius-sm);
  color: var(--text); cursor: pointer; font-size: 13px;
  transition: background 0.1s ease;
}
.nav-item:hover { background: var(--bg-card); text-decoration: none; }
.nav-item.active { background: var(--primary); color: var(--primary-fg); font-weight: 500; }
.nav-item.active:hover { background: var(--primary-hover); }
.nav-icon { width: 16px; height: 16px; flex-shrink: 0; opacity: 0.85; }

.main {
  grid-area: main;
  overflow-y: auto;
  padding: 24px;
  background: var(--bg);
}
.page { max-width: 1100px; margin: 0 auto; }
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px;
  flex-wrap: wrap; gap: 12px;
}
.page-title { font-size: 20px; font-weight: 600; margin: 0; }
.page-subtitle { color: var(--text-muted); font-size: 13px; margin: 4px 0 0; }

/* Mobile */
@media (max-width: 768px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: 56px 1fr;
    grid-template-areas:
      "topbar"
      "main";
  }
  .sidebar {
    position: fixed; top: 56px; left: 0; bottom: 0; width: 260px; z-index: 50;
    transform: translateX(-100%); transition: transform 0.2s ease;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop {
    position: fixed; top: 56px; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.4); z-index: 40;
  }
  .main { padding: 16px; }
}

/* ===== Card / form ===== */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 16px; }
.card-title { font-size: 15px; font-weight: 600; margin: 0 0 12px; }

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

.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 6px; color: var(--text); }
input, select, textarea {
  width: 100%;
  padding: 8px 12px;
  font-size: 14px;
  font-family: inherit;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--ring);
}
.field { margin-bottom: 14px; }
.field-help { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; font-size: 14px; font-weight: 500;
  background: var(--bg-card); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  cursor: pointer; text-decoration: none;
  transition: background 0.1s ease, border-color 0.1s ease, transform 0.05s ease;
}
.btn:hover { background: var(--bg-elev); text-decoration: none; }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: var(--primary-fg); border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-success { background: var(--success); color: white; border-color: var(--success); }
.btn-danger { background: var(--danger); color: white; border-color: var(--danger); }
.btn-ghost { background: transparent; border: 1px solid transparent; }
.btn-ghost:hover { background: var(--bg-elev); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-lg { padding: 14px 24px; font-size: 16px; }
.btn-block { width: 100%; }

/* ===== Table ===== */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th, .tbl td {
  padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.tbl thead th {
  background: var(--bg-elev); color: var(--text-muted); font-weight: 500;
  font-size: 12px; text-transform: uppercase; letter-spacing: 0.4px;
}
.tbl tbody tr:hover { background: var(--bg-elev); }
.tbl tbody tr:last-child td { border-bottom: 0; }

/* ===== Badge ===== */
.badge {
  display: inline-flex; align-items: center;
  padding: 2px 8px; font-size: 11px; font-weight: 500;
  border-radius: 999px; border: 1px solid var(--border-strong);
  background: var(--bg-elev); color: var(--text-muted);
}
.badge-success { background: rgba(34, 197, 94, 0.12); color: var(--success); border-color: rgba(34, 197, 94, 0.4); }
.badge-warning { background: rgba(234, 179, 8, 0.12); color: var(--warning); border-color: rgba(234, 179, 8, 0.4); }
.badge-danger  { background: rgba(239, 68, 68, 0.12); color: var(--danger);  border-color: rgba(239, 68, 68, 0.4); }
.badge-info    { background: rgba(6, 182, 212, 0.12); color: var(--info);    border-color: rgba(6, 182, 212, 0.4); }
.badge-primary { background: rgba(59, 130, 246, 0.12); color: var(--primary); border-color: rgba(59, 130, 246, 0.4); }

/* ===== Toast ===== */
.toast-stack {
  position: fixed; top: 16px; right: 16px; z-index: 1000;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  background: var(--bg-card); border: 1px solid var(--border-strong);
  padding: 10px 14px; border-radius: var(--radius-sm); box-shadow: var(--shadow);
  font-size: 13px; min-width: 240px; max-width: 360px;
  animation: slideIn 0.15s ease;
}
.toast-success { border-left: 4px solid var(--success); }
.toast-error   { border-left: 4px solid var(--danger); }
.toast-info    { border-left: 4px solid var(--info); }
@keyframes slideIn {
  from { transform: translateX(20px); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}

/* ===== Login page ===== */
.login-bg {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--bg) 0%, var(--bg-elev) 100%);
  padding: 24px;
}
.login-card {
  width: 100%; max-width: 380px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 32px;
  box-shadow: var(--shadow);
}
.login-brand {
  text-align: center; margin-bottom: 24px;
}
.login-brand h1 { font-size: 18px; margin: 8px 0 4px; }
.login-brand p { font-size: 12px; color: var(--text-muted); margin: 0; }

/* ===== Punch (大按鈕) ===== */
.punch-hero {
  display: flex; flex-direction: column; align-items: center; gap: 24px;
  padding: 32px 16px;
}
.punch-clock { font-size: 48px; font-weight: 700; font-variant-numeric: tabular-nums; }
.punch-date  { color: var(--text-muted); font-size: 15px; }
.punch-btn {
  width: 220px; height: 220px; border-radius: 50%;
  background: var(--primary); color: var(--primary-fg);
  border: 0; font-size: 24px; font-weight: 700;
  cursor: pointer; box-shadow: 0 8px 24px rgba(59, 130, 246, 0.35);
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}
.punch-btn:hover { transform: scale(1.02); box-shadow: 0 12px 32px rgba(59, 130, 246, 0.45); }
.punch-btn:active { transform: scale(0.98); }
.punch-btn:disabled { opacity: 0.6; cursor: not-allowed; }
.punch-btn.btn-out { background: var(--warning); box-shadow: 0 8px 24px rgba(234, 179, 8, 0.35); }
.punch-status {
  display: flex; gap: 24px; justify-content: center; flex-wrap: wrap;
  margin-top: 16px;
}
.punch-status-item { text-align: center; }
.punch-status-item small { color: var(--text-muted); font-size: 12px; }
.punch-status-item strong { display: block; font-size: 18px; margin-top: 4px; font-variant-numeric: tabular-nums; }
.punch-info { text-align: center; color: var(--text-muted); font-size: 13px; }

/* ===== Calendar ===== */
.cal {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px;
  background: var(--bg-card); padding: 8px; border-radius: var(--radius); border: 1px solid var(--border);
}
.cal-head { text-align: center; font-size: 12px; color: var(--text-muted); padding: 6px 0; font-weight: 500; }
.cal-cell {
  min-height: 80px; padding: 6px; border-radius: var(--radius-sm);
  background: var(--bg-elev); border: 1px solid transparent;
  font-size: 12px; display: flex; flex-direction: column; gap: 2px;
}
.cal-cell.today { border-color: var(--primary); }
.cal-cell.empty { background: transparent; }
.cal-day { font-weight: 600; font-size: 13px; }
.cal-tag { font-size: 10px; padding: 1px 4px; border-radius: 3px; background: var(--primary); color: white; }
.cal-tag.leave { background: var(--warning); }
.cal-tag.off   { background: var(--text-dim); }

/* ===== Stats ===== */
.stat-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
}
.stat-label { color: var(--text-muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.4px; }
.stat-value { font-size: 28px; font-weight: 700; margin: 6px 0 0; font-variant-numeric: tabular-nums; }
.stat-foot  { color: var(--text-muted); font-size: 12px; margin-top: 6px; }

/* ===== Bar chart simple ===== */
.bar-row { display: grid; grid-template-columns: 100px 1fr 60px; align-items: center; gap: 10px; padding: 4px 0; font-size: 12px; }
.bar-track { height: 8px; background: var(--bg-elev); border-radius: 4px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--primary); border-radius: 4px; }

/* ===== Misc ===== */
.muted { color: var(--text-muted); }
.dim   { color: var(--text-dim); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.flex-grow { flex-grow: 1; }
.gap-2 { gap: 8px; } .gap-3 { gap: 12px; } .gap-4 { gap: 16px; }
.mt-2 { margin-top: 8px; } .mt-3 { margin-top: 12px; } .mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; } .mb-3 { margin-bottom: 12px; } .mb-4 { margin-bottom: 16px; }
.hidden { display: none !important; }
.empty-state { text-align: center; padding: 32px 16px; color: var(--text-muted); }

.theme-toggle {
  background: transparent; border: 1px solid var(--border-strong); color: var(--text);
  width: 32px; height: 32px; border-radius: var(--radius-sm); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.theme-toggle:hover { background: var(--bg-elev); }

.kbd {
  font-family: ui-monospace, SFMono-Regular, monospace;
  background: var(--bg-elev); border: 1px solid var(--border-strong);
  padding: 1px 5px; border-radius: 3px; font-size: 11px;
}

/* hamburger for mobile */
.hamburger {
  background: transparent; border: 0; color: var(--text); cursor: pointer;
  display: none; padding: 4px 8px; font-size: 18px;
}
@media (max-width: 768px) { .hamburger { display: block; } }

/* PWA-friendly safe area */
@supports (padding: max(0px)) {
  .topbar { padding-left: max(20px, env(safe-area-inset-left)); padding-right: max(20px, env(safe-area-inset-right)); }
  .main   { padding-left: max(24px, env(safe-area-inset-left)); padding-right: max(24px, env(safe-area-inset-right)); padding-bottom: max(24px, env(safe-area-inset-bottom)); }
}
