/* ==========================================
   改進的手機版本 CSS
   ========================================== */

/* ------------------------------------------- */
/* 基礎和通用樣式 */
/* ------------------------------------------- */

body {
  font-family: Arial, sans-serif;
  background-color: #f4f4f9;
  color: #333;
  margin: 0;
  padding: 20px;
  padding-top: 90px;  
  display: flex;
  justify-content: center;
  min-height: 100vh;
}

.container {
  background-color: #fff;
  padding: 30px;
  border-radius: 8px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
  max-width: 800px;
  width: 100%;
  box-sizing: border-box;
  overflow-x: hidden;  /* 防止溢出 */
}

h1, h2 {
  color: #007bff;
  text-align: center;
  margin-top: 0;
}

.container h1 {
  margin-bottom: 20px;
}

/* ------------------------------------------- */
/* 主題切換開關 (手機優化版) */
/* ------------------------------------------- */

.theme-toggle-container {
  z-index: 1;
}

.theme-toggle {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  user-select: none;
  background-color: #fff;
  padding: 8px 12px;
  border-radius: 20px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.theme-toggle input {
  display: none;
}

.toggle-slider {
  position: relative;
  width: 50px;  /* 手機上縮小 */
  height: 28px;
  background-color: #ccc;
  border-radius: 34px;
  transition: background-color 0.3s ease;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2);
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background-color: #fff;
  top: 2px;
  left: 2px;
  transition: left 0.3s ease;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.theme-toggle input:checked + .toggle-slider {
  background-color: #333;
}

.theme-toggle input:checked + .toggle-slider::before {
  left: 22px;
}

.toggle-label-light,
.toggle-label-dark {
  font-size: 12px;
  font-weight: 600;
  color: #333;
  transition: color 0.3s ease;
  white-space: nowrap;
}

.toggle-label-dark {
  display: none;
}

.theme-toggle input:checked ~ .toggle-label-light {
  display: none;
}

.theme-toggle input:checked ~ .toggle-label-dark {
  display: block;
  color: #fff;
}

/* ------------------------------------------- */
/* 管理員按鈕 (手機優化版) */
/* ------------------------------------------- */

#admin-login-btn-fixed {
  z-index: 1;  /* 略低於主題切換 */
  text-decoration: none;
  text-align: center;
  line-height: normal;
  background-color: #ffc107;
  color: #333;
  padding: 8px 15px;
  font-size: 14px;
  white-space: nowrap;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  font-weight: bold;
  transition: background-color 0.3s;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

#admin-login-btn-fixed:hover {
  background-color: #e0a800;
}

/* ------------------------------------------- */
/* 控制區塊 (按鈕和篩選器) */
/* ------------------------------------------- */

.controls {
  text-align: center;
  margin-bottom: 20px;
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

button {
  padding: 10px 20px;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  font-size: 16px;
  font-weight: bold;
  transition: background-color 0.3s;
  white-space: nowrap;
}

#signin-btn {
  background-color: #28a745;
  color: white;
}

#signin-btn:hover {
  background-color: #218838;
}

#signin-btn:disabled {
  background-color: #ccc;
  color: #666;
  cursor: not-allowed;
  opacity: 0.6;
}

#signout-btn {
  background-color: #dc3545;
  color: white;
}

#signout-btn:hover {
  background-color: #c82333;
}

#signout-btn:disabled {
  background-color: #ccc;
  color: #666;
  cursor: not-allowed;
  opacity: 0.6;
}

/* 篩選器 */
.filter-controls {
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 20px 0;
  gap: 15px;
  flex-wrap: wrap;
}

.filter-controls label {
  font-weight: bold;
  font-size: 14px;
}

.filter-controls select {
  padding: 8px 12px;
  font-size: 14px;
  border: 1px solid #ddd;
  border-radius: 5px;
  cursor: pointer;
}

.filter-controls button {
  padding: 8px 16px;
  font-size: 14px;
  background-color: #007bff;
  color: white;
}

.filter-controls button:hover {
  background-color: #0056b3;
}

/* ------------------------------------------- */
/* 狀態訊息 */
/* ------------------------------------------- */

.status-message {
  text-align: center;
  padding: 10px;
  margin-bottom: 20px;
  border-radius: 5px;
  font-weight: bold;
}

.status-message.success {
  background-color: #d4edda;
  color: #155724;
  border: 1px solid #c3e6cb;
}

.status-message.error {
  background-color: #f8d7da;
  color: #721c24;
  border: 1px solid #f5c6cb;
}

/* ------------------------------------------- */
/* 今日狀態顯示區塊 */
/* ------------------------------------------- */

.status-display {
  text-align: center;
  padding: 15px;
  margin-bottom: 20px;
  border-radius: 8px;
  font-size: 1.1em;
  font-weight: bold;
  border: 2px solid #ddd;
  background-color: #e9ecef;
}

.status-display.signed-in {
  background-color: #d4edda;
  color: #155724;
  border-color: #c3e6cb;
}

.status-display.signed-out {
  background-color: #ffe8d4;
  color: #856404;
  border-color: #ffc107;
}

.status-display.not-punched {
  background-color: #f8d7da;
  color: #721c24;
  border-color: #f5c6cb;
}

/* ------------------------------------------- */
/* 表格樣式 */
/* ------------------------------------------- */

table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 15px;
  font-size: 14px;
  box-sizing: border-box;
}

th, td {
  padding: 12px;
  text-align: center;
  border-bottom: 1px solid #ddd;
  box-sizing: border-box;
}

th {
  background-color: #f2f2f2;
  color: #333;
  font-weight: bold;
}

tbody tr:hover {
  background-color: #f9f9f9;
}

#history-table td:nth-child(1) {
  font-family: 'Consolas', 'Courier New', monospace;
}

#history-table td:nth-child(2),
#history-table td:nth-child(3) {
  font-family: 'Consolas', 'Courier New', monospace;
}

#history-table td:nth-child(4) {
  font-family: 'Consolas', 'Courier New', monospace;
  min-width: 60px;
}

/* ==========================================
   手機 RWD (max-width: 768px)
   ========================================== */

@media (max-width: 768px) {
  body {
    padding: 10px;
	padding-top: 10px; 
  }

  .container {
    padding: 15px;
    margin-top: 0px;  /* 為固定按鈕留出空間 */
  }

  /* 調整固定按鈕位置，避免重疊 */
  .theme-toggle-container {
    top: 10px;
    left: 10px;
  }

  .theme-toggle {
    padding: 6px 10px;
    gap: 8px;
  }

  .toggle-slider {
    width: 45px;
    height: 26px;
  }

  .toggle-slider::before {
    width: 22px;
    height: 22px;
  }

  .theme-toggle input:checked + .toggle-slider::before {
    left: 21px;
  }

  .toggle-label-light,
  .toggle-label-dark {
    font-size: 11px;
  }

  #admin-login-btn-fixed {
    top: 10px;
    right: 10px;
    font-size: 12px;
    padding: 6px 10px;
  }

  /* 簽到簽退按鈕改為垂直排列 */
  .controls {
    flex-direction: column;
    gap: 8px;
  }

  .controls button {
    width: 100%;
    padding: 12px 16px;
    font-size: 15px;
  }

  /* 篩選器在手機上垂直排列 */
  .filter-controls {
    flex-direction: column;
    gap: 10px;
  }

  .filter-controls label {
    width: 100%;
    text-align: left;
  }

  .filter-controls select,
  .filter-controls button {
    width: 100%;
    box-sizing: border-box;
  }

  /* 表格允許水平捲動，但不要讓內容溢出 */
  .container {
    overflow-x: auto;
    overflow-y: visible;
  }

  table {
    min-width: 100%;
    table-layout: auto;
  }

  th, td {
    padding: 8px;
    font-size: 12px;
    word-wrap: break-word;
  }

  #history-table td:nth-child(4) {
    min-width: 50px;
  }
}

@media (max-width: 480px) {
  .container {
    padding: 10px;
    margin-top: 80px;
  }

  .theme-toggle {
    padding: 5px 8px;
    gap: 6px;
  }

  .toggle-label-light,
  .toggle-label-dark {
    font-size: 10px;
  }

  .toggle-slider {
    width: 40px;
    height: 24px;
  }

  #admin-login-btn-fixed {
    font-size: 11px;
    padding: 5px 8px;
  }

  .controls button {
    padding: 10px 12px;
    font-size: 14px;
  }

  .filter-controls {
    gap: 8px;
  }

  th, td {
    padding: 6px;
    font-size: 11px;
  }
}

/* ==========================================
   Dark Mode 主題
   ========================================== */

body.dark-mode {
  background-color: #1a1a1a;
  color: #e0e0e0;
}

body.dark-mode .container {
  background-color: #2a2a2a;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

body.dark-mode h1,
body.dark-mode h2 {
  color: #64b5f6;
}

body.dark-mode .status-message.success {
  background-color: #1b5e20;
  color: #c8e6c9;
  border-color: #81c784;
}

body.dark-mode .status-message.error {
  background-color: #b71c1c;
  color: #ffcdd2;
  border-color: #ef5350;
}

body.dark-mode table {
  background-color: #333;
  color: #e0e0e0;
}

body.dark-mode th {
  background-color: #444;
  color: #e0e0e0;
}

body.dark-mode tbody tr:hover {
  background-color: #3a3a3a;
}

body.dark-mode .filter-controls select {
  background-color: #333;
  color: #e0e0e0;
  border: 1px solid #555;
}

body.dark-mode .theme-toggle {
  background-color: #333;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

body.dark-mode .toggle-label-light,
body.dark-mode .toggle-label-dark {
  color: #e0e0e0;
}

/* ==========================================
   排序功能樣式
   ========================================== */

.sort-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  user-select: none;
  transition: color 0.2s ease;
}

.sort-header:hover {
  color: #007bff;
}

.sort-icon {
  display: inline-block;
  font-size: 12px;
  width: 16px;
  height: 16px;
  text-align: center;
  line-height: 16px;
  transition: transform 0.2s ease;
}

/* 排序狀態樣式 */
.sort-header.active-asc .sort-icon::before {
  content: '↑';
  display: inline-block;
}

.sort-header.active-desc .sort-icon::before {
  content: '↓';
  display: inline-block;
}

.sort-header.active-asc .sort-icon,
.sort-header.active-desc .sort-icon {
  color: #007bff;
}

/* Dark Mode 下的排序樣式 */
body.dark-mode .sort-header:hover {
  color: #64b5f6;
}

body.dark-mode .sort-header.active-asc .sort-icon,
body.dark-mode .sort-header.active-desc .sort-icon {
  color: #64b5f6;
}

@media (max-width: 480px) {
  .sort-icon {
    font-size: 10px;
  }
}


/* 固定在最上方的 header，包含主題切換 + 管理員登入 */
.fixed-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 60px;              /* header 高度，可依喜好調整 */
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  z-index: 1000;
  background-color: #f4f4f9;  /* 淺色模式背景 */
}

body.dark-mode .fixed-header {
  background-color: #1a1a1a;
}

