/* 通用元件樣式 - 卡片、導航、麵包屑、表單、Modal、Toast */

/* 卡片元件 - 用於內容區塊 */
.card {
  background: var(--surface);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 8px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

/* 導航元件 - 主選單 */
.nav {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--text-secondary);
}

/* 麵包屑導航 - 頁面路徑 */
#breadcrumb ol {
  display: flex;
  list-style: none;
  padding: 8px 16px;
  margin: 0;
  background: var(--bg);
}

#breadcrumb li {
  margin-right: 8px;
}

#breadcrumb li:not(:last-child)::after {
  content: '>';
  margin-left: 8px;
  color: var(--text-secondary);
}

/* 表單元件 - 輸入框、按鈕 */
.form-group {
  margin-bottom: 16px;
}

.form-control {
  width: 100%;
  padding: 12px;
  border: 2px solid var(--text-secondary);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 16px;
}

.btn {
  min-height: 44px;
  padding: 12px 24px;
  border: none;
  border-radius: 12px;
  font-weight: 600;
  font-size: 17px;
  cursor: pointer;
  transition: all 0.2s ease-in-out;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover {
  opacity: 0.8;
}

/* 危險/刪除按鈕樣式 */
.btn-danger {
  background: #dc3545;
  color: white;
}

.btn-danger:hover {
  background: #c82333;
  opacity: 0.9;
}

/* 按鈕載入狀態 */
.btn-loading {
  position: relative;
  pointer-events: none;
  opacity: 0.7;
}

.btn-loading .loading-spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid currentColor;
  border-radius: 50%;
  border-top-color: transparent;
  animation: btn-spinner 0.8s linear infinite;
  margin-right: 6px;
  vertical-align: middle;
}

@keyframes btn-spinner {
  to {
    transform: rotate(360deg);
  }
}

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

/* Modal 元件 - 彈出視窗 */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-content {
  background: var(--surface);
  border-radius: 16px;
  padding: 24px;
  overflow: auto;
}

/* Toast 通知 - 替代 alert/confirm */
.toast {
  position: fixed;
  top: 20px;
  right: 20px;
  background: var(--surface);
  border: 1px solid var(--text-secondary);
  border-radius: 8px;
  padding: 12px 16px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  z-index: 1001;
  opacity: 0;
  transform: translateX(100%);
  transition: all 0.3s ease;
}

/* 面料換算工具結果區塊 */
.fabric-convert-result {
  background: #f5f5f5;
  color: #333;
}

.fabric-convert-result h3 {
  color: #333;
}

.fabric-convert-result strong {
  color: #333;
}

.fabric-result-value {
  font-size: 1.2rem;
  color: #007AFF;
  margin-top: 4px;
}

/* 暗黑模式：面料換算工具 */
body.dark-mode .fabric-convert-result,
body.dark .fabric-convert-result {
  background: #2c2c2e;
  color: #e0e0e0;
}

body.dark-mode .fabric-convert-result h3,
body.dark .fabric-convert-result h3 {
  color: #e0e0e0;
}

body.dark-mode .fabric-convert-result strong,
body.dark .fabric-convert-result strong {
  color: #e0e0e0;
}

body.dark-mode .fabric-result-value,
body.dark .fabric-result-value {
  color: #4dabf7;
}

.toast.show {
  opacity: 1;
  transform: translateX(0);
}

/* 掃描器介面 */
.scanner {
  position: relative;
  width: 100%;
  max-width: 400px;
  margin: 0 auto;
}

#scanVideo {
  width: 100%;
  height: auto;
  border-radius: 12px;
  background: #000;
}

/* ========================================
   搜尋篩選列 - 用於列表頁面頂部的搜尋區塊
   ======================================== */

.search-filter-row {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.search-filter-row .search-input-wrapper {
  flex: 1;
  min-width: 200px;
  position: relative;
}

.search-filter-row .filter-select {
  width: auto;
  min-width: 120px;
}

.search-filter-row .filter-date {
  width: auto;
  min-width: 130px;
  max-width: 160px;
  box-sizing: border-box;
}

.search-filter-row .filter-btn {
  white-space: nowrap;
}

.search-filter-row .scan-btn {
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* 日期區塊包裝器 */
.search-filter-row .date-range-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 1;
  min-width: 0;
}

.search-filter-row .date-range-wrapper .date-separator {
  color: var(--text-secondary, #666);
  font-size: 0.875rem;
  flex-shrink: 0;
}

/* 日期欄位（含標籤） */
.search-filter-row .date-field {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.search-filter-row .date-field .date-label {
  display: none; /* 電腦版隱藏標籤 */
}

/* 按鈕群組 */
.search-filter-row .btn-group {
  display: flex;
  gap: 8px;
}

/* ========== 手機版響應式 ========== */
@media (max-width: 768px) {
  .search-filter-row {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    overflow: hidden;
  }
  
  .search-filter-row .search-input-wrapper {
    width: 100%;
    min-width: 0;
  }
  
  /* 篩選下拉選單區塊 */
  .search-filter-row .filter-selects {
    display: flex;
    gap: 8px;
    width: 100%;
    max-width: 100%;
  }
  
  .search-filter-row .filter-selects .filter-select {
    flex: 1;
    min-width: 0;
    width: auto;
    max-width: 100%;
    box-sizing: border-box;
  }
  
  /* 日期範圍區塊 - 手機版改為垂直排列 */
  .search-filter-row .date-range-wrapper {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
  }
  
  .search-filter-row .date-range-wrapper .date-field {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    width: 100%;
  }
  
  .search-filter-row .date-range-wrapper .date-field .date-label {
    display: block; /* 手機版顯示標籤 */
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary, #666);
  }
  
  .search-filter-row .date-range-wrapper .filter-date {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
    font-size: 16px; /* 防止 iOS 自動縮放 */
    padding: 12px;
  }
  
  .search-filter-row .date-range-wrapper .date-separator {
    display: none; /* 手機版隱藏分隔符 */
  }
  
  /* 按鈕群組 - 佔滿寬度 */
  .search-filter-row .btn-group {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
  }
  
  .search-filter-row .btn-group .btn {
    flex: 1;
    min-width: 0;
  }
  
  /* 掃描按鈕與搜尋輸入框同行 */
  .search-filter-row .search-row {
    display: flex;
    gap: 8px;
    width: 100%;
    max-width: 100%;
    width: 100%;
  }
  
  .search-filter-row .search-row .search-input-wrapper {
    flex: 1;
  }
  
  .search-filter-row .search-row .scan-btn {
    flex-shrink: 0;
  }
}

/* ========== 小螢幕手機優化 ========== */
@media (max-width: 480px) {
  .search-filter-row .filter-selects {
    flex-direction: column;
  }
  
  .search-filter-row .filter-selects .filter-select {
    width: 100%;
  }
}
