/* 五百戶科技 500net 人資管理系統 — 樣式 */
* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --bg: #f3f4f6;
  --surface: #ffffff;
  --border: #e5e7eb;
  --text: #111827;
  --text-muted: #6b7280;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #3b82f6;
  --sidebar-w: 240px;
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --radius: 8px;
}
body {
  font-family: -apple-system, "Microsoft JhengHei", "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text); font-size: 14px;
  min-height: 100vh;
}
button { font: inherit; cursor: pointer; }
input, select, textarea { font: inherit; }
a { color: var(--primary); text-decoration: none; }
.loading { padding: 40px; text-align: center; color: var(--text-muted); }

/* ===== 登入 ===== */
.login-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 50%, #06b6d4 100%);
  padding: 20px;
}
.login-box {
  background: white; border-radius: 12px; padding: 36px; width: 100%; max-width: 380px;
  box-shadow: 0 20px 40px rgba(0,0,0,.15);
}
.login-box h1 { font-size: 22px; margin-bottom: 6px; color: var(--primary); }
.login-box .sub { color: var(--text-muted); margin-bottom: 24px; font-size: 13px; }
.login-box .field { margin-bottom: 14px; }
.login-box label { display: block; margin-bottom: 6px; font-size: 13px; color: var(--text-muted); }
.login-box input { width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 6px; }
.login-box button {
  width: 100%; padding: 11px; background: var(--primary); color: white; border: 0; border-radius: 6px; font-weight: 600;
  margin-top: 8px;
}
.login-box button:hover { background: var(--primary-dark); }
.login-box .tip { margin-top: 18px; padding: 12px; background: #eff6ff; border-radius: 6px; font-size: 12px; color: #1e40af; }
.login-box .tip b { display: inline-block; min-width: 64px; }
.login-box .version-tag { margin-top: 14px; text-align: center; font-size: 11px; color: #9ca3af; letter-spacing: 0.5px; font-family: monospace; }

/* ===== Layout ===== */
.layout { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }

.sidebar { background: #0f172a; color: #e5e7eb; padding: 18px 0; position: relative; }
.sidebar-close { display: none; position: absolute; top: 10px; right: 10px; background: transparent; border: 0; color: #cbd5e1; font-size: 22px; line-height: 1; padding: 6px 10px; cursor: pointer; border-radius: 5px; }
.sidebar-close:hover { background: #1e293b; color: #fff; }
.sidebar .brand { padding: 0 20px 18px; border-bottom: 1px solid #1e293b; }
.sidebar .brand h2 { font-size: 16px; color: #fff; }
.sidebar .brand .v { font-size: 11px; color: #64748b; margin-top: 2px; }
.sidebar nav { padding: 12px 0; }
.sidebar nav .group-title { padding: 12px 20px 6px; font-size: 11px; color: #64748b; text-transform: uppercase; letter-spacing: .5px; }
.sidebar nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 20px; color: #cbd5e1; font-size: 13px;
  border-left: 3px solid transparent;
}
.sidebar nav a:hover { background: #1e293b; color: #fff; }
.sidebar nav a.active { background: #1e293b; color: #fff; border-left-color: var(--primary); }
.sidebar nav a .ico { width: 18px; text-align: center; }

.topbar {
  background: white; padding: 12px 24px; border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
}
.topbar h1 { font-size: 18px; }
.topbar .user { display: flex; align-items: center; gap: 12px; }
.topbar .user .avatar {
  width: 32px; height: 32px; border-radius: 50%; background: var(--primary); color: white;
  display: flex; align-items: center; justify-content: center; font-weight: 600;
}
.topbar .user .name { font-size: 13px; }
.topbar .user .role { font-size: 11px; color: var(--text-muted); }
.topbar .user button { background: transparent; border: 1px solid var(--border); padding: 5px 10px; border-radius: 5px; color: var(--text-muted); font-size: 12px; }

.main { display: flex; flex-direction: column; min-width: 0; }
.content { padding: 20px 24px; flex: 1; overflow: auto; }

/* ===== Card / common ===== */
.card { background: var(--surface); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); margin-bottom: 16px; }
.card h2 { font-size: 15px; margin-bottom: 12px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.row.between { justify-content: space-between; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
/* 巢狀 grid(card 內的 grid)不要重複加 margin */
.card .grid-2, .card .grid-3, .card .grid-4 { margin-bottom: 0; }
@media (max-width: 768px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}

.btn { padding: 7px 14px; background: var(--primary); color: white; border: 0; border-radius: 5px; font-size: 13px; }
.btn:hover { background: var(--primary-dark); }
.btn.secondary { background: white; color: var(--text); border: 1px solid var(--border); }
.btn.secondary:hover { background: var(--bg); }
.btn.success { background: var(--success); }
.btn.danger { background: var(--danger); }
.btn.warning { background: var(--warning); }
.btn.sm { padding: 4px 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

input, select, textarea {
  padding: 7px 10px; border: 1px solid var(--border); border-radius: 5px; background: white;
  width: 100%; font-size: 13px;
}
textarea { resize: vertical; min-height: 60px; }
label { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 4px; }
.field { margin-bottom: 10px; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--border); }
th { background: #f9fafb; font-weight: 600; color: var(--text-muted); font-size: 12px; }
tbody tr:hover { background: #fafafa; }
.table-wrap { overflow-x: auto; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 500; }
.badge.pending { background: #fef3c7; color: #92400e; }
.badge.approved { background: #d1fae5; color: #065f46; }
.badge.rejected { background: #fee2e2; color: #991b1b; }
.badge.cancelled { background: #e5e7eb; color: #374151; }
.badge.active { background: #d1fae5; color: #065f46; }
.badge.inactive { background: #e5e7eb; color: #374151; }
.badge.warn { background: #fef3c7; color: #92400e; }
.badge.danger { background: #fee2e2; color: #991b1b; }

.muted { color: var(--text-muted); }
.empty { padding: 40px; text-align: center; color: var(--text-muted); }

/* KPI */
.kpi { background: white; padding: 16px; border-radius: var(--radius); box-shadow: var(--shadow); }
.kpi .label { font-size: 12px; color: var(--text-muted); }
.kpi .value { font-size: 26px; font-weight: 700; color: var(--text); margin-top: 4px; }
.kpi .sub { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.kpi.primary { border-left: 3px solid var(--primary); }
.kpi.success { border-left: 3px solid var(--success); }
.kpi.warning { border-left: 3px solid var(--warning); }
.kpi.danger { border-left: 3px solid var(--danger); }

/* Modal */
.modal-mask {
  position: fixed; inset: 0; background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px;
}
.modal {
  background: white; border-radius: 10px; padding: 22px; width: 100%; max-width: 540px;
  max-height: 90vh; overflow: auto;
}
.modal h3 { font-size: 16px; margin-bottom: 14px; padding-bottom: 10px; border-bottom: 1px solid var(--border); }
.modal .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--border); }

/* Toast */
#toast { position: fixed; top: 20px; right: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--text); color: white; padding: 10px 16px; border-radius: 6px;
  font-size: 13px; box-shadow: 0 4px 12px rgba(0,0,0,.15); animation: slideIn .25s ease;
}
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.warn { background: var(--warning); }
@keyframes slideIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: translateX(0); } }

/* 組織樹 */
.org-tree ul { list-style: none; padding-left: 22px; border-left: 1px dashed #cbd5e1; margin-left: 8px; }
.org-tree > ul { padding-left: 0; border-left: 0; margin-left: 0; }
.org-tree li { padding: 4px 0; }
.org-tree .node { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; background: #eff6ff; border-radius: 5px; border: 1px solid #bfdbfe; }
.org-tree .node .count { font-size: 11px; color: var(--text-muted); }

/* 打卡 */
.clock-card { text-align: center; padding: 30px 20px; }
.clock-card .now { font-size: 36px; font-weight: 700; color: var(--primary); font-variant-numeric: tabular-nums; }
.clock-card .date { color: var(--text-muted); margin-bottom: 18px; }
.clock-buttons { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin: 12px 0; }
.clock-buttons .btn { padding: 14px 28px; font-size: 15px; }
.gps-status { padding: 10px; background: #f0fdf4; border: 1px solid #86efac; color: #14532d; border-radius: 6px; font-size: 12px; margin-top: 10px; }
.gps-status.bad { background: #fef2f2; border-color: #fca5a5; color: #7f1d1d; }

/* Mobile (P15) */
@media (max-width: 768px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .sidebar.open {
    display: block;
    position: fixed; inset: 0 30% 0 0;
    z-index: 50;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .sidebar.open .sidebar-close { display: inline-block; }
  .topbar { padding: 10px 12px; }
  .topbar h1 { font-size: 15px; }
  .topbar .user { gap: 6px; }
  .topbar .user .name, .topbar .user .role { display: none; }   /* 只留頭像 + 登出 */
  .topbar .user button { padding: 4px 8px; font-size: 11px; }
  .topbar .menu-btn { display: inline-flex; }
  .content { padding: 12px; }

  /* Modal 改全螢幕(避免被 200vh 內容撐爆) */
  .modal-mask { padding: 0; align-items: stretch; }
  .modal { max-width: 100%; max-height: 100vh; border-radius: 0; padding: 16px; }

  /* 打卡卡片緊湊化 */
  .clock-card { padding: 16px 10px; }
  .clock-card .now { font-size: 28px; }
  .clock-card .date { font-size: 12px; margin-bottom: 12px; }
  .clock-buttons { gap: 8px; flex-direction: column; }       /* 改直排,避免按鈕擠 */
  .clock-buttons .btn { padding: 12px 0; font-size: 14px; width: 100%; }

  /* KPI 字級縮 */
  .kpi { padding: 12px; }
  .kpi .value { font-size: 22px; }

  /* table 在 mobile 仍可橫向捲 */
  .table-wrap { -webkit-overflow-scrolling: touch; }
  table { font-size: 12px; }
  th, td { padding: 6px 8px; }

  /* Toast 縮 */
  #toast { top: 10px; right: 10px; left: 10px; }
  .toast { font-size: 12px; padding: 8px 12px; }
}
.menu-btn { display: none; background: transparent; border: 0; font-size: 22px; padding: 4px 8px; }
@media (max-width: 768px) { .menu-btn { display: inline-block; } }
