:root {
  font-family: 'Noto Sans TC', 'Microsoft JhengHei', sans-serif;
  color: #1b2b3a;
  line-height: 1.6;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  background-color: #90e26b;
  background-image: url('./background.png'),
    linear-gradient(120deg, #90e26b, #a6f0a2);
  background-size: cover, 100%;
  background-position: center;
  background-repeat: no-repeat;
  background-attachment: fixed;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow-x: hidden; /* 防止橫向滾動 */
}

.hero {
  width: min(1200px, 95%);
  padding: 2rem 1rem;
}

.clock-card {
  background: #fff;
  border-radius: 60px;
  padding: 3rem 4rem;
  box-shadow: 0 20px 60px rgba(12, 74, 110, 0.2);
  text-align: center;
}

.clock-card .label {
  font-size: 1.25rem;
  margin-bottom: 0.5rem;
}

#date-display {
  font-size: clamp(2rem, 5vw, 4rem);
  margin: 0.25rem 0;
  font-weight: 600;
}

#time-display {
  font-size: clamp(2rem, 4vw, 3.5rem);
  margin: 0.25rem 0 2rem;
  font-weight: 500;
}

.code-label {
  font-size: 1.3rem;
  font-weight: 600;
  margin-right: 0.5rem;
}

#code-input {
  width: 300px;
  max-width: 80%;
  font-size: 1.2rem;
  padding: 0.6rem 0.8rem;
  border: 3px solid #1b2b3a;
  border-radius: 8px;
  margin-top: 0.5rem;
  text-align: center;
}

#code-status {
  margin-top: 0.5rem;
  color: #64748b;
  font-size: 0.95rem;
  min-height: 1.2rem;
}

#code-status.error {
  color: #dc2626;
}

.actions {
  display: flex;
  gap: 1.5rem;
  justify-content: center;
  margin: 2rem 0 1rem;
}

.actions button {
  width: 180px;
  padding: 0.9rem 0;
  border: none;
  border-radius: 999px;
  font-size: 1.2rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
  color: #fff;
}

.actions button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.actions button:disabled:hover {
  transform: none;
  box-shadow: none;
}

.actions button.primary {
  background: #2b7df1;
}

.actions button.secondary {
  background: #ff944d;
}

.actions button.tertiary {
  background: #10b981;
  color: white;
}

.back-btn {
  background: #64748b;
  color: white;
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
}

.back-btn:hover {
  background: #475569;
}

.info-text {
  font-size: 0.9rem;
  color: #64748b;
  margin: 0.5rem 0;
}

.info-text.error {
  color: #dc2626;
}

form {
  text-align: left;
  max-width: 500px;
  margin: 0 auto;
}

form label {
  display: block;
  margin: 1rem 0 0.5rem;
  font-weight: 600;
}

form input,
form select,
form textarea {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  font-size: 1rem;
  font-family: inherit;
}

form textarea {
  resize: vertical;
  min-height: 80px;
}

form button[type="submit"] {
  margin-top: 1.5rem;
  width: 100%;
  padding: 1rem 2rem;
  border: none;
  border-radius: 12px;
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
  color: #fff;
  background: #2b7df1;
  box-shadow: 0 4px 12px rgba(43, 125, 241, 0.3);
}

form button[type="submit"]:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(43, 125, 241, 0.4);
  background: #1e6bd8;
}

form button[type="submit"]:active {
  transform: translateY(0);
  box-shadow: 0 2px 8px rgba(43, 125, 241, 0.3);
}

.status-pending {
  color: #f59e0b;
}

.status-approved {
  color: #10b981;
}

.status-rejected {
  color: #dc2626;
}

.actions button:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 25px rgba(0, 0, 0, 0.15);
}

.message {
  min-height: 1.25rem;
  font-weight: 600;
  word-wrap: break-word;
  word-break: break-word;
  white-space: pre-wrap; /* 保留換行符號 */
}

.message.success-in {
  color: #2b7df1;
}

.message.success-out {
  color: #ff7a1a;
}

.message.error {
  color: #dc2626;
}

.records {
  margin-top: 2rem;
  text-align: left;
}

.records h3 {
  margin-bottom: 1rem;
  font-size: 1.4rem;
}

table {
  width: 100%;
  border-collapse: collapse;
  border-radius: 15px;
  overflow: hidden;
}

thead {
  background: #eef4ff;
}

th,
td {
  padding: 0.85rem 1rem;
  text-align: left;
}

tbody tr:nth-child(odd) {
  background: #f9fbff;
}

tbody tr:nth-child(even) {
  background: #fff;
}

tbody tr:hover {
  background: #e6f0ff;
}

.empty {
  text-align: center;
  color: #94a3b8;
  font-style: italic;
}

/* 管理員介面樣式 */
.container {
  width: min(1200px, 95%);
  padding: 2rem 1rem;
  margin: 0 auto;
}

.card {
  background: #fff;
  border-radius: 20px;
  padding: 2rem;
  margin-bottom: 2rem;
  box-shadow: 0 10px 30px rgba(12, 74, 110, 0.15);
  overflow: visible; /* 確保內容不被截斷 */
  min-width: 0; /* 允許flex項目縮小 */
}

.card h1,
.card h2 {
  margin-top: 0;
  margin-bottom: 1.5rem;
  color: #1b2b3a;
}

.card form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.card label {
  font-weight: 600;
  color: #1b2b3a;
  margin-bottom: 0.5rem;
}

.card input {
  width: 100%;
  padding: 0.75rem;
  border: 2px solid #e2e8f0;
  border-radius: 8px;
  font-size: 1rem;
  transition: border-color 0.2s;
}

.card input:focus {
  outline: none;
  border-color: #2b7df1;
}

.card button {
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.card button.primary {
  background: #2b7df1;
  color: #fff;
}

.card button.secondary {
  background: #64748b;
  color: #fff;
}

.card button:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.card button.hidden {
  display: none;
}

.message {
  margin-top: 1rem;
  padding: 0.75rem;
  border-radius: 8px;
  font-weight: 500;
}

.message.error {
  background: #fee2e2;
  color: #dc2626;
}

.calendar {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1.5rem;
  align-items: flex-end;
}

.calendar label {
  display: block;
  margin-bottom: 0.5rem;
}

.calendar input,
.calendar button {
  flex: 1;
  min-width: 150px;
}

.table-actions {
  display: flex;
  gap: 0.5rem;
}

.table-actions button {
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
}

.table-actions button[data-action="edit"] {
  background: #2b7df1;
  color: #fff;
}

.table-actions button[data-action="delete"] {
  background: #dc2626;
  color: #fff;
}

.table-actions button:hover {
  opacity: 0.8;
  transform: translateY(-1px);
}

/* 請假申請管理過濾器樣式 */
.leave-filter-container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  gap: 0.5rem;
  width: 100%;
  box-sizing: border-box;
}

.leave-filter-options {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  flex-direction: row;
  overflow: visible;
}

.filter-label {
  margin: 0;
  font-size: 0.9rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  white-space: nowrap;
  flex-shrink: 0;
  min-width: max-content;
  max-width: 100%;
  overflow: visible;
  text-overflow: clip;
}

.filter-label input[type="radio"] {
  vertical-align: middle;
  margin: 0;
  flex-shrink: 0;
  width: auto;
}

.filter-label span {
  display: inline-block;
  vertical-align: middle;
  white-space: nowrap;
  word-break: keep-all;
  overflow: visible;
  text-overflow: clip;
  max-width: none;
  width: auto;
}

.refresh-btn {
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  white-space: nowrap;
}

/* 響應式設計 */
@media (max-width: 768px) {
  /* 主頁面手機優化 */
  .hero {
    width: 100%;
    padding: 1rem 0.5rem;
  }

  .clock-card {
    border-radius: 30px;
    padding: 1.5rem;
  }

  .clock-card .label {
    font-size: 1rem;
  }

  #date-display {
    font-size: 1.8rem;
  }

  #time-display {
    font-size: 1.5rem;
    margin-bottom: 1.5rem;
  }

  .code-label {
    font-size: 1.1rem;
  }

  #code-input {
    width: 100%;
    max-width: 100%;
    font-size: 16px; /* 防止 iOS 自動縮放 */
    padding: 0.75rem;
  }

  .actions {
    flex-direction: column;
    gap: 1rem;
    margin: 1.5rem 0;
  }

  .actions button {
    width: 100%;
    padding: 1rem;
    font-size: 1.1rem;
  }

  .records {
    margin-top: 1.5rem;
  }

  .records h3 {
    font-size: 1.2rem;
  }

  /* 表格改為可橫向滾動 */
  .records {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .records table {
    min-width: 500px;
    font-size: 0.9rem;
  }

  .records th,
  .records td {
    padding: 0.6rem 0.5rem;
    white-space: nowrap;
  }

  /* 管理員介面手機優化 */
  .container {
    padding: 1rem 0.5rem;
  }

  .card {
    padding: 1.5rem;
    border-radius: 15px;
    margin-bottom: 1.5rem;
    overflow-x: auto;
    overflow-y: visible; /* 確保垂直方向內容不被截斷 */
  }

  .card h1 {
    font-size: 1.5rem;
  }

  .card h2 {
    font-size: 1.25rem;
  }

  /* 請假申請管理過濾器優化 */
  .leave-filter-container {
    flex-direction: column;
    align-items: stretch;
    gap: 1rem;
  }

  .leave-filter-container {
    flex-direction: column;
    align-items: stretch;
    gap: 1rem;
    width: 100%;
    box-sizing: border-box;
  }

  .leave-filter-options {
    width: 100%;
    flex-wrap: wrap;
    gap: 1rem;
    justify-content: flex-start;
    overflow: visible;
    display: flex;
    align-items: center;
    box-sizing: border-box;
  }

  .filter-label {
    font-size: 1rem;
    flex: none;
    white-space: nowrap;
    word-break: keep-all;
    overflow: visible;
    text-overflow: clip;
    min-width: max-content;
    width: auto;
    max-width: 100%;
    box-sizing: border-box;
    padding: 0.25rem 0;
  }

  .filter-label input[type="radio"] {
    flex-shrink: 0;
    margin-right: 0.5rem;
  }

  .filter-label span {
    white-space: nowrap;
    word-break: keep-all;
    overflow: visible;
    text-overflow: clip;
    max-width: none;
    width: auto;
    display: inline;
    box-sizing: border-box;
  }

  .refresh-btn {
    width: 100%;
    margin-top: 0;
  }

  /* 所有表格改為可橫向滾動 */
  .card > div[style*="overflow-x: auto"] {
    -webkit-overflow-scrolling: touch;
  }

  table {
    min-width: 700px;
    font-size: 0.85rem;
  }

  th,
  td {
    padding: 0.6rem 0.5rem;
    white-space: nowrap;
  }

  /* 表單優化 */
  .card form {
    gap: 0.75rem;
  }

  .card input,
  .card select,
  .card textarea {
    font-size: 16px; /* 防止 iOS 自動縮放 */
    width: 100%;
  }

  /* 查詢區域優化 */
  .calendar {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
  }

  .calendar label {
    margin-bottom: 0.25rem;
  }

  .calendar input,
  .calendar button {
    width: 100%;
    min-width: auto;
  }

  /* 按鈕優化 */
  .card button {
    width: 100%;
    padding: 0.875rem;
  }

  .table-actions {
    flex-direction: column;
    gap: 0.5rem;
  }

  .table-actions button {
    width: 100%;
    padding: 0.6rem;
  }

  /* 請假申請頁面優化 */
  form {
    max-width: 100%;
  }

  .back-btn {
    width: 100%;
    padding: 0.75rem;
    font-size: 1rem;
  }
}

@media (max-width: 480px) {
  .hero {
    padding: 0.5rem;
  }

  .clock-card {
    padding: 1.25rem;
    border-radius: 20px;
  }

  #date-display {
    font-size: 1.5rem;
  }

  #time-display {
    font-size: 1.3rem;
  }

  .container {
    padding: 0.5rem;
  }

  .card {
    padding: 1rem;
    border-radius: 12px;
  }

  .card h1 {
    font-size: 1.3rem;
  }

  .card h2 {
    font-size: 1.1rem;
  }

  table {
    min-width: 600px;
    font-size: 0.8rem;
  }

  th,
  td {
    padding: 0.5rem 0.4rem;
    font-size: 0.8rem;
  }

  .actions button {
    font-size: 1rem;
    padding: 0.875rem;
  }

  .message {
    font-size: 0.9rem;
    padding: 0.625rem;
    word-break: break-word;
  }

  /* 請假申請管理過濾器在更小螢幕上優化 */
  .filter-label {
    font-size: 0.9rem;
    gap: 0.5rem;
    white-space: nowrap;
    word-break: keep-all;
    overflow: visible;
    flex-shrink: 0;
  }

  .filter-label span {
    white-space: nowrap;
    word-break: keep-all;
    overflow: visible;
    text-overflow: clip;
  }

  .leave-filter-options {
    gap: 0.75rem;
    flex-wrap: wrap;
    overflow: visible;
  }
}

/* 確保所有表格在手機上可以橫向滾動 */
@media (max-width: 768px) {
  /* 所有包含表格的容器都應該可橫向滾動 */
  .records,
  .card > div[style*="overflow-x: auto"],
  section.card > div[style*="overflow-x: auto"] {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    margin: 0 -1.5rem;
    padding: 0 1.5rem;
  }

  /* 確保表格容器不會溢出 */
  .card {
    overflow: visible;
  }

  /* 防止文字溢出 */
  th, td {
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 200px;
  }

  /* 操作列保持較小寬度 */
  .table-actions {
    min-width: 120px;
  }
}

/* 更小的手機螢幕優化 */
@media (max-width: 360px) {
  .clock-card {
    padding: 1rem;
  }

  #date-display {
    font-size: 1.3rem;
  }

  #time-display {
    font-size: 1.1rem;
  }

  .actions button {
    font-size: 0.95rem;
    padding: 0.75rem;
  }

  table {
    min-width: 550px;
    font-size: 0.75rem;
  }

  th, td {
    padding: 0.4rem 0.3rem;
  }
}

