/* =================
   基本佈局設定
   ================= */
* {
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Arial",
    sans-serif;
  max-width: 800px;
  margin: 0 auto;
  padding: 20px;
  background-color: #f5f5f5;
  line-height: 1.6;
}

/* =================
   導航欄樣式
   ================= */
.navbar {
  background: white;
  padding: 15px 30px;
  border-radius: 10px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  margin-bottom: 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.navbar h1 {
  margin: 0;
  color: #333;
  font-size: 1.5em;
  font-weight: 600;
}

.nav-buttons {
  display: flex;
  gap: 10px;
  align-items: center;
}

.nav-btn {
  padding: 10px 20px;
  border: none;
  border-radius: 5px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s ease;
  background: #e0e0e0;
  color: #666;
}

.nav-btn.active {
  background: #99a0ff;
  color: white;
  box-shadow: 0 2px 8px rgba(153, 160, 255, 0.3);
}

.nav-btn:hover:not(.active) {
  background: #d0d0d0;
  transform: translateY(-1px);
}

.nav-btn:active {
  transform: translateY(0);
}

/* Google Sheets 連結按鈕 */
.nav-link {
  padding: 10px 20px;
  border: 2px solid #99a0ff;
  border-radius: 5px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s ease;
  background: transparent;
  color: #99a0ff;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.nav-link:hover {
  background: #99a0ff;
  color: white;
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(153, 160, 255, 0.3);
}

.nav-link:active {
  transform: translateY(0);
}

/* =================
   頁面容器樣式
   ================= */
.page {
  display: none;
  background: white;
  padding: 30px;
  border-radius: 10px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  animation: fadeIn 0.3s ease-out;
}

.page.active {
  display: block;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.page h2 {
  color: #333;
  margin-top: 0;
  margin-bottom: 25px;
  text-align: center;
  font-weight: 600;
}

/* =================
   表單樣式
   ================= */
.input-group {
  margin-bottom: 20px;
}

label {
  display: block;
  margin-bottom: 8px;
  font-weight: 500;
  color: #555;
  font-size: 14px;
}

input[type="text"],
input[type="number"],
input[type="tel"],
select {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid #e1e5e9;
  border-radius: 6px;
  font-size: 16px;
  background-color: white;
  transition: all 0.3s ease;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
}

/* 隱藏數字輸入框的旋轉按鈕 */
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

input[type="number"] {
  -moz-appearance: textfield;
}

input[type="text"]:focus,
input[type="number"]:focus,
input[type="tel"]:focus,
select:focus {
  outline: none;
  border-color: #99a0ff;
  box-shadow: 0 0 0 3px rgba(153, 160, 255, 0.1);
}

input[type="text"]:hover,
input[type="number"]:hover,
input[type="tel"]:hover,
select:hover {
  border-color: #c5c9d0;
}

/* 佔位符樣式 */
input::placeholder {
  color: #a0a0a0;
  opacity: 1;
}

/* 下拉選單樣式 */
select {
  color: #999;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='m6 8 4 4 4-4'/%3e%3c/svg%3e");
  background-position: right 12px center;
  background-repeat: no-repeat;
  background-size: 16px;
  padding-right: 40px;
}

select:valid {
  color: #333;
}

option[value=""] {
  color: #999;
  font-style: italic;
}

option {
  color: #333;
  background-color: white;
}

/* optgroup 樣式 */
optgroup {
  font-weight: bold;
  color: #666;
  background-color: #f8f9fa;
  font-style: normal;
}

/* 選項懸停效果 */
option:hover {
  background-color: #f0f0f0;
}

/* =================
   按鈕樣式
   ================= */
.button-group {
  margin-top: 30px;
  text-align: center;
  display: flex;
  gap: 15px;
  justify-content: center;
  flex-wrap: wrap;
}

button {
  padding: 12px 24px;
  border: none;
  border-radius: 6px;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s ease;
  min-width: 120px;
  position: relative;
  overflow: hidden;
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

button[type="submit"] {
  background: #99a0ff;
  color: white;
}

button[type="submit"]:hover:not(:disabled) {
  background: #858cff;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(153, 160, 255, 0.4);
}

button[type="reset"] {
  background: #6c6c9e;
  color: white;
}

button[type="reset"]:hover:not(:disabled) {
  background: #5a5a8a;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(108, 108, 158, 0.4);
}

button:active:not(:disabled) {
  transform: translateY(0);
}

/* =================
   表格樣式
   ================= */

/* 【重要】表格容器 - 這是解決跑版的關鍵 */
.table-container {
  position: relative;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-top: 20px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  background: white;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.data-table th,
.data-table td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid #e5e7eb;
}

.data-table th {
  background-color: #99a0ff;
  color: white;
  font-weight: 600;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.data-table tr:last-child td {
  border-bottom: none;
}

.data-table tr:hover {
  background-color: #f8f9fa;
}

.data-table button {
  background: #ff6b6b;
  color: white;
  border: none;
  padding: 6px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  min-width: auto;
  transition: background-color 0.2s ease;
}

.data-table button:hover {
  background: #ff5252;
}

/* 欄位標識樣式 */
.col-time { min-width: 80px; }
.col-item { min-width: 80px; }
.col-qty { min-width: 50px; text-align: center; }
.col-user { min-width: 80px; }
.col-location { min-width: 80px; }
.col-ptag { min-width: 80px; }
.col-sticker { min-width: 80px; }
.col-action { min-width: 60px; text-align: center; }

/* 手機版資訊提示 */
.mobile-info {
  text-align: center;
  padding: 10px;
  background: #f8f9fa;
  border-radius: 4px;
  margin-top: 15px;
  display: none;
}

/* =================
   載入動畫
   ================= */
.loading {
  text-align: center;
  padding: 40px 20px;
  color: #666;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.loading::after {
  content: "";
  width: 20px;
  height: 20px;
  border: 2px solid #f3f3f3;
  border-top: 2px solid #99a0ff;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

/* =================
   訊息樣式
   ================= */
.message {
  padding: 16px 20px;
  border-radius: 6px;
  margin: 15px 0;
  display: none;
  font-weight: 500;
  position: relative;
  animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.message.success {
  background-color: #ecfdf5;
  color: #065f46;
  border: 1px solid #a7f3d0;
  border-left: 4px solid #10b981;
}

.message.error {
  background-color: #fef2f2;
  color: #991b1b;
  border: 1px solid #fecaca;
  border-left: 4px solid #ef4444;
}

.message.info {
  background-color: #eff6ff;
  color: #1e40af;
  border: 1px solid #bfdbfe;
  border-left: 4px solid #3b82f6;
}

/* =================
   響應式設計
   ================= */
@media (max-width: 768px) {
  body {
    padding: 15px;
  }

  .navbar {
    padding: 15px 20px;
  }

  .page {
    padding: 25px 20px;
  }
  
  /* 平板尺寸 - 隱藏次要欄位 */
  .data-table .col-location,
  .data-table .col-ptag,
  .data-table .col-sticker {
    display: none;
  }
}

@media (max-width: 600px) {
  body {
    padding: 10px;
  }

  .navbar {
    flex-direction: column;
    gap: 15px;
    padding: 15px;
  }

  .nav-buttons {
    width: 100%;
    justify-content: center;
    flex-wrap: wrap;
  }

  .nav-btn,
  .nav-link {
    flex: 1;
    text-align: center;
    min-width: 100px;
    font-size: 13px;
    padding: 8px 16px;
    margin: 2px;
  }

  .page {
    padding: 20px 15px;
  }

  .button-group {
    flex-direction: column;
    align-items: center;
  }

  .button-group button {
    width: 100%;
    max-width: 280px;
    margin: 5px 0;
  }

  .data-table {
    font-size: 12px;
  }

  .data-table th,
  .data-table td {
    padding: 6px 8px;
  }

  /* 只顯示：時間、貨號、數量、操作 */
  .data-table .col-user,
  .data-table .col-location,
  .data-table .col-ptag,
  .data-table .col-sticker {
    display: none;
  }
  
  /* 調整剩餘欄位的寬度 */
  .data-table .col-time {
    width: 80px;
    font-size: 10px;
  }
  
  .data-table .col-item {
    width: 80px;
    font-size: 11px;
  }
  
  .data-table .col-qty {
    width: 50px;
    text-align: center;
  }
  
  .data-table .col-action {
    width: 60px;
  }
  
  .data-table button {
    padding: 4px 8px;
    font-size: 10px;
  }
  
  /* 顯示手機版提示 */
  .mobile-info {
    display: block;
  }
}

@media (max-width: 480px) {
  .navbar h1 {
    font-size: 1.3em;
  }

  .nav-btn {
    font-size: 12px;
    padding: 8px 12px;
  }

  .nav-link {
    font-size: 12px;
    padding: 8px 12px;
  }

  .page h2 {
    font-size: 1.4em;
  }

  input[type="text"],
  input[type="number"],
  input[type="tel"],
  select {
    font-size: 16px; /* 防止 iOS Safari 縮放 */
    padding: 12px 14px;
  }

  button {
    font-size: 15px;
    padding: 12px 20px;
  }
  
  /* 超小螢幕進一步縮小表格字體 */
  .data-table {
    font-size: 11px;
  }
  
  .data-table th,
  .data-table td {
    padding: 4px 6px;
  }
  
  .data-table .col-time {
    width: 70px;
    font-size: 9px;
  }
  
  .data-table .col-item {
    width: 70px;
    font-size: 10px;
  }
  
  .data-table .col-qty {
    width: 40px;
  }
  
  .data-table .col-action {
    width: 50px;
  }
  
  .data-table button {
    padding: 3px 6px;
    font-size: 9px;
  }
}

/* =================
   無障礙設計
   ================= */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* 高對比度模式支援 */
@media (prefers-contrast: high) {
  input[type="text"],
  input[type="number"],
  input[type="tel"],
  select {
    border-width: 3px;
  }

  button {
    border: 2px solid transparent;
  }

  button[type="submit"] {
    border-color: #333;
  }
}

/* 深色模式支援 */
@media (prefers-color-scheme: dark) {
  body {
    background-color: #1a1a1a;
    color: #e5e5e5;
  }

  .navbar,
  .page {
    background: #2d2d2d;
    color: #e5e5e5;
  }

  .navbar h1,
  .page h2 {
    color: #f0f0f0;
  }

  input[type="text"],
  input[type="number"],
  input[type="tel"],
  select {
    background-color: #3a3a3a;
    border-color: #4a4a4a;
    color: #e5e5e5;
  }

  /* 深色模式下拉選單特殊處理 */
  select {
    color: #ffffff !important;
    background-color: #2d2d2d !important;
    border-color: #666666 !important;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
  }

  select option {
    background-color: #2d2d2d !important;
    color: #ffffff !important;
    padding: 8px 12px;
  }

  select optgroup {
    background-color: #1a1a1a !important;
    color: #99a0ff !important;
    font-weight: bold;
    font-size: 14px;
  }

  /* 選中狀態 */
  select option:checked,
  select option:hover {
    background-color: #99a0ff !important;
    color: #ffffff !important;
  }

  /* 強制覆蓋系統樣式 */
  select:valid {
    color: #ffffff !important;
  }

  /* 預設選項樣式 */
  select option[value=""] {
    color: #cccccc !important;
    font-style: italic;
  }

  .data-table {
    background: #2d2d2d;
  }

  .data-table tr:hover {
    background-color: #3a3a3a;
  }
  
  .mobile-info {
    background: #3a3a3a;
    color: #e5e5e5;
  }
}