/* ============ 基礎 ============ */
:root {
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --danger: #ef4444;
  --success: #22c55e;
  --warning: #f59e0b;
  --info: #3b82f6;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-500: #6b7280;
  --gray-700: #374151;
  --gray-900: #111827;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.1);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.1);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft JhengHei", sans-serif;
  background: var(--gray-50);
  color: var(--gray-900);
  line-height: 1.6;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
}

/* ============ 導航列 ============ */
.navbar {
  background: var(--primary);
  color: white;
  padding: 0 20px;
  display: flex;
  align-items: center;
  gap: 20px;
  height: 56px;
  box-shadow: var(--shadow-md);
  position: sticky;
  top: 0;
  z-index: 100;
}
.nav-brand { font-weight: 700; font-size: 1.1rem; white-space: nowrap; }
.nav-links { display: flex; gap: 4px; flex: 1; }
.nav-link {
  color: rgba(255,255,255,0.85);
  text-decoration: none;
  padding: 8px 14px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  transition: background 0.2s;
}
.nav-link:hover { background: rgba(255,255,255,0.15); color: white; }
.nav-user { display: flex; align-items: center; gap: 8px; font-size: 0.9rem; white-space: nowrap; }
.nav-toggle { display: none; background: none; border: none; color: white; font-size: 1.5rem; cursor: pointer; }

/* ============ 按鈕 ============ */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border: none; border-radius: var(--radius);
  font-size: 0.9rem; cursor: pointer; transition: all 0.2s; text-decoration: none;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { opacity: 0.9; }
.btn-success { background: var(--success); color: white; }
.btn-success:hover { opacity: 0.9; }
.btn-warning { background: var(--warning); color: white; }
.btn-outline { background: white; border: 1px solid var(--gray-300); color: var(--gray-700); }
.btn-outline:hover { background: var(--gray-100); }
.btn-outline.active { background: var(--primary); color: white; border-color: var(--primary); }
.btn-sm { padding: 4px 10px; font-size: 0.8rem; }
.btn-block { width: 100%; justify-content: center; }

/* ============ 表單 ============ */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 4px; font-weight: 500; font-size: 0.9rem; color: var(--gray-700); }
.form-group input, .form-group select, .form-group textarea {
  width: 100%; padding: 8px 12px; border: 1px solid var(--gray-300);
  border-radius: var(--radius); font-size: 0.9rem; font-family: inherit;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,70,229,0.1);
}
.form-row { display: flex; gap: 16px; }
.form-row .form-group { flex: 1; }

/* ============ 表格 ============ */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; background: white; border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
thead { background: var(--gray-100); }
th, td { padding: 10px 14px; text-align: left; font-size: 0.9rem; }
th { font-weight: 600; color: var(--gray-700); border-bottom: 2px solid var(--gray-200); }
td { border-bottom: 1px solid var(--gray-100); }
tr:hover td { background: var(--gray-50); }
.text-center { text-align: center; }

/* ============ 徽章 ============ */
.badge { display: inline-block; padding: 2px 10px; border-radius: 99px; font-size: 0.75rem; font-weight: 600; }
.badge-high { background: #fef2f2; color: var(--danger); }
.badge-normal { background: #fffbeb; color: #b45309; }
.badge-low { background: #f0fdf4; color: #15803d; }
.badge-pending { background: #eff6ff; color: var(--info); }
.badge-in_progress { background: #fffbeb; color: #b45309; }
.badge-completed { background: #f0fdf4; color: #15803d; }
.badge-admin { background: rgba(255,255,255,0.2); color: white; font-size: 0.7rem; }
.badge-leave-pending { background: #fffbeb; color: #b45309; }
.badge-leave-approved { background: #f0fdf4; color: #15803d; }
.badge-leave-rejected { background: #fef2f2; color: var(--danger); }
.badge-active { background: #f0fdf4; color: #15803d; }
.badge-inactive { background: var(--gray-100); color: var(--gray-500); }

/* ============ 統計卡片 ============ */
.stats-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px; margin-bottom: 24px;
}
.stat-card {
  background: white; border-radius: var(--radius); padding: 20px;
  box-shadow: var(--shadow); text-align: center; border-top: 4px solid var(--gray-300);
}
.stat-today { border-top-color: var(--info); }
.stat-soon { border-top-color: var(--warning); }
.stat-overdue { border-top-color: var(--danger); }
.stat-total { border-top-color: var(--primary); }
.stat-leave { border-top-color: #8b5cf6; }
.stat-number { font-size: 2rem; font-weight: 700; }
.stat-label { font-size: 0.85rem; color: var(--gray-500); margin-top: 4px; }

/* ============ Modal ============ */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center; z-index: 200; padding: 20px;
}
.modal-content {
  background: white; border-radius: 12px; padding: 24px; width: 100%; max-width: 500px;
  max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}
.modal-sm { max-width: 380px; }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.modal-header h3 { font-size: 1.1rem; }
.modal-close { background: none; border: none; font-size: 1.5rem; cursor: pointer; color: var(--gray-500); }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

/* ============ 頁面標題 ============ */
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; flex-wrap: wrap; gap: 12px; }
.header-actions { display: flex; gap: 12px; align-items: center; }

/* ============ 篩選列 ============ */
.filter-bar { display: flex; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.filter-bar select { padding: 6px 12px; border: 1px solid var(--gray-300); border-radius: var(--radius); font-size: 0.85rem; }

/* ============ 看板 (Kanban) ============ */
.kanban-board {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; min-height: 400px;
}
.kanban-column {
  background: var(--gray-100); border-radius: var(--radius); padding: 12px; min-height: 300px;
}
.kanban-header {
  font-weight: 700; font-size: 0.9rem; padding: 8px 12px;
  border-radius: var(--radius); margin-bottom: 12px; text-align: center;
}
.kanban-pending { background: #dbeafe; color: #1e40af; }
.kanban-progress { background: #fef3c7; color: #92400e; }
.kanban-done { background: #dcfce7; color: #166534; }

.kanban-cards { display: flex; flex-direction: column; gap: 8px; min-height: 60px; transition: background 0.2s; border-radius: var(--radius); padding: 4px; }
.kanban-cards.drag-over { background: rgba(79,70,229,0.08); outline: 2px dashed var(--primary); outline-offset: -2px; }
.kanban-card {
  background: white; border-radius: var(--radius); padding: 12px;
  box-shadow: var(--shadow); cursor: grab; transition: box-shadow 0.2s, opacity 0.2s, transform 0.15s;
  user-select: none;
}
.kanban-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.kanban-card:active { cursor: grabbing; }
.kanban-card.dragging { opacity: 0.4; transform: scale(0.95); }
.kanban-card-title { font-weight: 600; font-size: 0.9rem; margin-bottom: 6px; }
.kanban-card-meta { font-size: 0.8rem; color: var(--gray-500); display: flex; gap: 8px; flex-wrap: wrap; }
.kanban-card-actions { display: flex; gap: 4px; margin-top: 8px; }
.kanban-empty { text-align: center; padding: 30px 10px; color: var(--gray-500); font-size: 0.85rem; }

/* 看板切換按鈕 */
.view-toggle { display: flex; gap: 0; }
.view-toggle .btn { border-radius: 0; }
.view-toggle .btn:first-child { border-radius: var(--radius) 0 0 var(--radius); }
.view-toggle .btn:last-child { border-radius: 0 var(--radius) var(--radius) 0; }

/* ============ 區塊 ============ */
.section { background: white; padding: 20px; border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 20px; }
.section h3 { margin-bottom: 12px; font-size: 1rem; }
.dashboard-sections { display: grid; gap: 20px; }

/* ============ 登入頁 ============ */
.login-page {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; background: linear-gradient(135deg, var(--primary) 0%, #7c3aed 100%);
}
.login-container {
  background: white; padding: 40px; border-radius: 16px;
  width: 100%; max-width: 400px; box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}
.login-container h1 { text-align: center; margin-bottom: 24px; font-size: 1.3rem; color: var(--gray-900); }

/* ============ Alert ============ */
.alert { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 16px; font-size: 0.9rem; }
.alert-error { background: #fef2f2; color: var(--danger); border: 1px solid #fecaca; }
.alert-success { background: #f0fdf4; color: #15803d; border: 1px solid #bbf7d0; }

.text-muted { color: var(--gray-500); }
.action-btns { display: flex; gap: 4px; flex-wrap: wrap; }

/* ============ Toast 提示 ============ */
.toast {
  position: fixed; top: 72px; left: 50%; transform: translateX(-50%) translateY(-10px);
  padding: 12px 28px; border-radius: var(--radius); font-size: 0.95rem; font-weight: 500;
  z-index: 300; opacity: 0; transition: opacity 0.3s, transform 0.3s;
  box-shadow: 0 8px 24px rgba(0,0,0,0.2); white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast-success { background: #166534; color: white; }
.toast-error { background: var(--danger); color: white; }

/* ============ RWD ============ */
@media (max-width: 768px) {
  .nav-links { display: none; position: absolute; top: 56px; left: 0; right: 0; background: var(--primary); flex-direction: column; padding: 8px; z-index: 101; }
  .nav-links.open { display: flex; }
  .nav-toggle { display: block; }
  .nav-user span:first-child { display: none; }
  .page-header { flex-direction: column; align-items: stretch; }
  .filter-bar { flex-direction: column; }
  .form-row { flex-direction: column; gap: 0; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .kanban-board { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .container { padding: 12px; }
}
