/* 全域樣式 */
* { box-sizing: border-box; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Microsoft JhengHei', sans-serif; }

/* 安全區域 */
.safe-top { padding-top: env(safe-area-inset-top); }
.safe-bottom { padding-bottom: env(safe-area-inset-bottom); }

/* 底部導航列 */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 50;
  background: white;
  border-top: 1px solid #e5e7eb;
  padding-bottom: env(safe-area-inset-bottom);
  box-shadow: 0 -4px 12px rgba(0,0,0,0.08);
}

/* 底部間距（為底部導航留空間） */
.pb-nav { padding-bottom: calc(4.5rem + env(safe-area-inset-bottom)); }

/* 卡片樣式 */
.card {
  background: white;
  border-radius: 12px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08), 0 2px 8px rgba(0,0,0,0.04);
  overflow: hidden;
}

.card-hover {
  transition: box-shadow 0.2s, transform 0.2s;
  cursor: pointer;
}
.card-hover:hover {
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  transform: translateY(-1px);
}
.card-hover:active {
  transform: translateY(0);
}

/* 統計卡片 */
.stat-card {
  background: white;
  border-radius: 12px;
  padding: 1.25rem;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
  border-left: 4px solid;
  transition: transform 0.2s;
}
.stat-card:hover { transform: translateY(-2px); }

/* 主要按鈕 */
.btn-primary {
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  color: white;
  border: none;
  border-radius: 10px;
  padding: 0.75rem 1.5rem;
  font-weight: 600;
  font-size: 0.9375rem;
  cursor: pointer;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}
.btn-primary:hover { background: linear-gradient(135deg, #1d4ed8, #1e40af); box-shadow: 0 4px 12px rgba(37,99,235,0.4); }
.btn-primary:active { transform: scale(0.98); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }

.btn-secondary {
  background: white;
  color: #374151;
  border: 1.5px solid #d1d5db;
  border-radius: 10px;
  padding: 0.75rem 1.5rem;
  font-weight: 600;
  font-size: 0.9375rem;
  cursor: pointer;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}
.btn-secondary:hover { border-color: #2563eb; color: #2563eb; background: #eff6ff; }

.btn-danger {
  background: #ef4444;
  color: white;
  border: none;
  border-radius: 10px;
  padding: 0.75rem 1.5rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-danger:hover { background: #dc2626; }

/* 表單樣式 */
.form-group { margin-bottom: 1rem; }
.form-label {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  color: #374151;
  margin-bottom: 0.375rem;
}
.form-label .required { color: #ef4444; margin-left: 0.25rem; }
.form-input {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1.5px solid #e5e7eb;
  border-radius: 10px;
  font-size: 1rem;
  color: #111827;
  background: white;
  transition: border-color 0.2s, box-shadow 0.2s;
  -webkit-appearance: none;
}
.form-input:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37,99,235,0.15);
}
.form-input::placeholder { color: #9ca3af; }
.form-input.error { border-color: #ef4444; }
.form-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2.5rem;
}
.form-error { color: #ef4444; font-size: 0.75rem; margin-top: 0.25rem; }

/* 狀態標籤 */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.25rem 0.625rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

/* 浮動新增按鈕 */
.fab {
  position: fixed;
  bottom: calc(5rem + env(safe-area-inset-bottom));
  right: 1.5rem;
  width: 3.5rem;
  height: 3.5rem;
  border-radius: 999px;
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  color: white;
  border: none;
  box-shadow: 0 4px 16px rgba(37,99,235,0.5);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  transition: all 0.2s;
  z-index: 40;
}
.fab:hover { transform: scale(1.1); box-shadow: 0 8px 24px rgba(37,99,235,0.6); }
.fab:active { transform: scale(0.95); }

/* 頁面標題 */
.page-header {
  background: white;
  border-bottom: 1px solid #e5e7eb;
  padding: 1rem 1.25rem;
  position: sticky;
  top: 0;
  z-index: 30;
}

/* 模態框 */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fadeIn 0.2s;
}
@media (min-width: 640px) {
  .modal-overlay { align-items: center; }
}
.modal-content {
  background: white;
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  animation: slideUp 0.3s;
  padding-bottom: env(safe-area-inset-bottom);
}
@media (min-width: 640px) {
  .modal-content {
    border-radius: 16px;
    max-width: 600px;
    margin: 1rem;
  }
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid #e5e7eb;
  position: sticky;
  top: 0;
  background: white;
  z-index: 1;
}

/* 側邊欄（管理員用） */
.sidebar {
  width: 260px;
  background: #1e3a8a;
  color: white;
  min-height: 100vh;
  position: fixed;
  left: 0;
  top: 0;
  z-index: 50;
  transition: transform 0.3s;
  overflow-y: auto;
}
.sidebar.hidden { transform: translateX(-100%); }
.sidebar-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.875rem 1.25rem;
  color: rgba(255,255,255,0.8);
  cursor: pointer;
  transition: all 0.2s;
  border-radius: 8px;
  margin: 0.125rem 0.5rem;
}
.sidebar-item:hover { background: rgba(255,255,255,0.1); color: white; }
.sidebar-item.active { background: rgba(255,255,255,0.2); color: white; font-weight: 600; }

.admin-content { margin-left: 260px; min-height: 100vh; }
@media (max-width: 1024px) { .admin-content { margin-left: 0; } }

/* 手機版標題欄 */
.mobile-header {
  background: white;
  border-bottom: 1px solid #e5e7eb;
  padding: 0.875rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 30;
}

/* 搜尋欄 */
.search-box {
  display: flex;
  align-items: center;
  background: #f3f4f6;
  border-radius: 10px;
  padding: 0.625rem 1rem;
  gap: 0.5rem;
}
.search-box input {
  background: transparent;
  border: none;
  outline: none;
  flex: 1;
  font-size: 0.9375rem;
  color: #111827;
}

/* 分頁器 */
.pagination { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.pagination button {
  padding: 0.5rem 0.75rem;
  border: 1.5px solid #e5e7eb;
  border-radius: 8px;
  background: white;
  color: #374151;
  cursor: pointer;
  font-size: 0.875rem;
  transition: all 0.2s;
}
.pagination button:hover { border-color: #2563eb; color: #2563eb; }
.pagination button.active { background: #2563eb; border-color: #2563eb; color: white; }
.pagination button:disabled { opacity: 0.4; cursor: not-allowed; }

/* 表格 */
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  text-align: left;
  padding: 0.875rem 1rem;
  font-size: 0.8125rem;
  font-weight: 600;
  color: #6b7280;
  background: #f9fafb;
  border-bottom: 1px solid #e5e7eb;
  white-space: nowrap;
}
.data-table td {
  padding: 0.875rem 1rem;
  border-bottom: 1px solid #f3f4f6;
  font-size: 0.9375rem;
  color: #374151;
}
.data-table tr:hover td { background: #f9fafb; }

/* 動畫 */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
@keyframes slideIn { from { transform: translateX(-100%); } to { transform: translateX(0); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.5} }

.loading-spin { animation: spin 1s linear infinite; }
.loading-pulse { animation: pulse 2s ease-in-out infinite; }

/* Toast 通知 */
.toast {
  position: fixed;
  top: calc(1rem + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  background: #1f2937;
  color: white;
  padding: 0.875rem 1.5rem;
  border-radius: 12px;
  font-size: 0.9375rem;
  font-weight: 500;
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
  max-width: 90vw;
  text-align: center;
  animation: fadeIn 0.3s;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.toast.success { background: #065f46; }
.toast.error { background: #991b1b; }
.toast.warning { background: #92400e; }

/* 空狀態 */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem 1.5rem;
  text-align: center;
  color: #9ca3af;
}
.empty-state i { font-size: 3rem; margin-bottom: 1rem; opacity: 0.5; }

/* 篩選標籤 */
.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.375rem 0.875rem;
  border: 1.5px solid #e5e7eb;
  border-radius: 999px;
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
  background: white;
  color: #4b5563;
}
.filter-chip.active { background: #dbeafe; border-color: #2563eb; color: #1d4ed8; }
.filter-chip:hover { border-color: #93c5fd; }

/* 步驟指示器 */
.step-indicator {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  overflow-x: auto;
  padding: 0.5rem 0;
}
.step {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex-shrink: 0;
}
.step-circle {
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8125rem;
  font-weight: 700;
  transition: all 0.3s;
}
.step-circle.pending { background: #f3f4f6; color: #9ca3af; border: 2px solid #e5e7eb; }
.step-circle.active { background: #2563eb; color: white; box-shadow: 0 0 0 4px rgba(37,99,235,0.2); }
.step-circle.done { background: #10b981; color: white; }
.step-line { width: 1.5rem; height: 2px; background: #e5e7eb; }
.step-line.done { background: #10b981; }

/* 多選標籤 */
.tag-input-area {
  border: 1.5px solid #e5e7eb;
  border-radius: 10px;
  padding: 0.5rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
  min-height: 3rem;
  cursor: text;
  transition: border-color 0.2s;
}
.tag-input-area:focus-within { border-color: #2563eb; box-shadow: 0 0 0 3px rgba(37,99,235,0.15); }
.tag {
  background: #dbeafe;
  color: #1e40af;
  border-radius: 999px;
  padding: 0.25rem 0.625rem;
  font-size: 0.8125rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.25rem;
}
.tag button { background: none; border: none; cursor: pointer; color: #1e40af; padding: 0; font-size: 0.875rem; }
.tag button:hover { color: #dc2626; }

/* 產品選擇 */
.product-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem;
  border: 1.5px solid #e5e7eb;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s;
}
.product-item:hover { border-color: #93c5fd; background: #f8faff; }
.product-item.selected { border-color: #2563eb; background: #eff6ff; }
.product-item .checkbox {
  width: 1.25rem;
  height: 1.25rem;
  border: 2px solid #d1d5db;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
}
.product-item.selected .checkbox { background: #2563eb; border-color: #2563eb; color: white; }

/* 手機版優化 */
@media (max-width: 640px) {
  .form-input, .btn-primary, .btn-secondary { font-size: 1rem; }
  .data-table { display: none; }
  .mobile-card-list { display: block; }
}
@media (min-width: 641px) {
  .mobile-card-list { display: none; }
}

/* 頁籤 */
.tabs { display: flex; border-bottom: 2px solid #e5e7eb; gap: 0; overflow-x: auto; }
.tab-btn {
  padding: 0.75rem 1.25rem;
  font-size: 0.9375rem;
  font-weight: 500;
  color: #6b7280;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s;
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
}
.tab-btn.active { color: #2563eb; border-bottom-color: #2563eb; font-weight: 600; }
.tab-btn:hover { color: #1d4ed8; }

/* 手風琴 */
.accordion-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  cursor: pointer;
  transition: background 0.2s;
}
.accordion-header:hover { background: #f9fafb; }
.accordion-content { overflow: hidden; transition: max-height 0.3s ease; }

/* 通知紅點 */
.notification-dot {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 0.75rem;
  height: 0.75rem;
  background: #ef4444;
  border-radius: 50%;
  border: 2px solid white;
}

/* 管理員側邊欄遮罩 */
.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 49;
  display: none;
}
.sidebar-overlay.show { display: block; }

/* 拖曳排序 */
tr.drag-over td {
  background: #eff6ff;
  border-top: 2px solid #3b82f6;
}
tr.drag-row { transition: opacity 0.15s; }
