/* 通用元件樣式 - 卡片、導航、麵包屑、表單、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%;
  }
}

/* ========================================
   稅率輸入欄位與免稅按鈕
   ======================================== */

.tax-rate-input-group {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.tax-rate-input-group .form-control {
  flex: 1;
  min-width: 0;
}

.tax-exempt-btn {
  flex-shrink: 0;
  min-width: 60px;
  padding: 8px 12px;
  font-size: 14px;
  font-weight: 500;
  border: 2px solid var(--primary, #007AFF);
  background: transparent;
  color: var(--primary, #007AFF);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.tax-exempt-btn:hover {
  background: var(--primary, #007AFF);
  color: white;
}

.tax-exempt-btn.active {
  background: #28a745;
  border-color: #28a745;
  color: white;
}

.tax-exempt-btn.active:hover {
  background: #218838;
  border-color: #218838;
}

@media (max-width: 540px) {
  .tax-rate-input-group {
    gap: 6px;
  }
  
  .tax-exempt-btn {
    min-width: 50px;
    padding: 6px 10px;
    font-size: 13px;
  }
}

/* ========================================
   進貨單/出貨單明細項目 - 數量/單位/單價/折扣率區塊
   ======================================== */

/* 桌面版：四欄並排 */
.item-quantity-price-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr;
  gap: 16px;
}

/* 平板版：四欄但縮小間距 */
@media (max-width: 768px) {
  .item-quantity-price-grid {
    gap: 10px;
  }
  
  .item-quantity-price-grid .form-group {
    margin-bottom: 8px;
  }
  
  .item-quantity-price-grid .form-control {
    padding: 10px 8px;
    font-size: 15px;
  }
  
  .item-quantity-price-grid label {
    font-size: 12px;
    margin-bottom: 4px;
  }
}

/* 手機版：改為兩欄排列 */
@media (max-width: 540px) {
  .item-quantity-price-grid {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
  
  .item-quantity-price-grid .form-group {
    margin-bottom: 6px;
  }
  
  .item-quantity-price-grid .form-control {
    padding: 8px 6px;
    font-size: 14px;
    min-height: 40px;
  }
  
  .item-quantity-price-grid label {
    font-size: 11px;
    margin-bottom: 2px;
    white-space: nowrap;
  }
}

/* ========================================
   出貨單多疋設定區塊 - 疋號/數量/存放位置/移除
   ======================================== */

/* 出貨單多疋項目 - 桌面版 */
.shipment-roll-item {
  display: grid;
  grid-template-columns: 1fr 1.2fr 2fr auto;
  gap: 8px;
  margin-bottom: 8px;
  padding: 10px;
  background: var(--surface, #fff);
  border-radius: 6px;
  border: 1px solid var(--border-color, #ddd);
  align-items: end;
}

.shipment-roll-item .roll-field {
  position: relative;
}

.shipment-roll-item .roll-field label {
  display: block;
  font-size: 11px;
  color: var(--text-secondary, #666);
  margin-bottom: 4px;
}

.shipment-roll-item .roll-field .form-control {
  font-size: 14px;
  padding: 8px;
  min-height: 38px;
}

.shipment-roll-item .roll-field-action {
  display: flex;
  align-items: flex-end;
}

.shipment-roll-item .roll-remove-btn {
  min-height: 38px;
  padding: 6px 10px;
  font-size: 13px;
  white-space: nowrap;
}

/* 出貨單多疋下拉選單樣式 */
.shipment-roll-item .roll-label-dropdown,
.shipment-roll-item .roll-location-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 1001;
  background: var(--surface, #fff);
  border: 1px solid #ddd;
  border-radius: 8px;
  max-height: 200px;
  overflow-y: auto;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

/* 出貨單多疋 - 平板版 */
@media (max-width: 768px) {
  .shipment-roll-item {
    grid-template-columns: 1fr 1.2fr 1.8fr auto;
    gap: 6px;
    padding: 8px;
  }
  
  .shipment-roll-item .roll-field .form-control {
    padding: 6px;
    font-size: 13px;
    min-height: 36px;
  }
  
  .shipment-roll-item .roll-remove-btn {
    min-height: 36px;
    padding: 4px 8px;
    font-size: 12px;
  }
}

/* 出貨單多疋 - 手機版：改為兩行排列 */
@media (max-width: 540px) {
  .shipment-roll-item {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 10px;
  }
  
  /* 第一行：疋號、數量、移除按鈕 */
  .shipment-roll-item .roll-field-number,
  .shipment-roll-item .roll-field-quantity {
    display: inline-block;
    width: calc(35% - 4px);
    vertical-align: top;
  }
  
  .shipment-roll-item .roll-field-action {
    display: inline-block;
    width: 28%;
    vertical-align: top;
  }
  
  /* 第二行：存放位置獨佔一行 */
  .shipment-roll-item .roll-field-location {
    width: 100%;
    margin-top: 4px;
  }
  
  .shipment-roll-item .roll-field .form-control {
    padding: 8px;
    font-size: 14px;
    min-height: 40px;
  }
  
  .shipment-roll-item .roll-field label {
    font-size: 11px;
    margin-bottom: 2px;
  }
  
  .shipment-roll-item .roll-remove-btn {
    width: 100%;
    min-height: 40px;
    padding: 8px;
    font-size: 13px;
  }
}

/* 極小螢幕優化 */
@media (max-width: 380px) {
  .shipment-roll-item .roll-field-number,
  .shipment-roll-item .roll-field-quantity {
    width: calc(40% - 4px);
  }
  
  .shipment-roll-item .roll-field-action {
    width: 18%;
  }
  
  .shipment-roll-item .roll-remove-btn {
    padding: 6px 4px;
    font-size: 12px;
  }
}

/* ========================================
   進貨單多疋設定區塊 - 疋號/數量/型態/存放位置/移除
   ======================================== */

/* 進貨單多疋項目 - 桌面版 */
.roll-item {
  margin-bottom: 10px;
  padding: 12px;
  background: var(--surface, #fff);
  border-radius: 6px;
  border: 1px solid var(--border-color, #ddd);
}

.roll-item-row1 {
  display: grid;
  grid-template-columns: 1fr 1.2fr 1.2fr auto;
  gap: 10px;
  align-items: end;
}

.roll-item-row2 {
  margin-top: 8px;
}

.roll-field {
  position: relative;
}

.roll-field label {
  display: block;
  font-size: 12px;
  color: var(--text-secondary, #666);
  margin-bottom: 4px;
}

.roll-field .form-control {
  font-size: 14px;
  padding: 8px 10px;
  min-height: 40px;
}

.roll-field-action {
  display: flex;
  align-items: flex-end;
}

.roll-field-action .btn {
  min-height: 40px;
  padding: 8px 12px;
  font-size: 13px;
  white-space: nowrap;
}

/* 進貨單多疋下拉選單樣式 */
.roll-location-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 1000;
  background: var(--surface, #fff);
  border: 1px solid #ddd;
  border-radius: 8px;
  max-height: 200px;
  overflow-y: auto;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

/* 進貨單多疋 - 平板版 */
@media (max-width: 768px) {
  .roll-item {
    padding: 10px;
  }
  
  .roll-item-row1 {
    gap: 8px;
  }
  
  .roll-field .form-control {
    padding: 6px 8px;
    font-size: 13px;
    min-height: 38px;
  }
  
  .roll-field label {
    font-size: 11px;
    margin-bottom: 2px;
  }
  
  .roll-field-action .btn {
    min-height: 38px;
    padding: 6px 10px;
    font-size: 12px;
  }
}

/* 進貨單多疋 - 手機版：改為兩行排列 */
@media (max-width: 540px) {
  .roll-item {
    padding: 10px;
  }
  
  .roll-item-row1 {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr auto;
    gap: 6px;
  }
  
  .roll-field .form-control {
    padding: 8px 6px;
    font-size: 14px;
    min-height: 40px;
  }
  
  .roll-field label {
    font-size: 10px;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  
  .roll-field-action .btn {
    min-height: 40px;
    padding: 6px 8px;
    font-size: 12px;
  }
  
  .roll-item-row2 {
    margin-top: 6px;
  }
}

/* 極小螢幕優化 */
@media (max-width: 380px) {
  .roll-item-row1 {
    grid-template-columns: 1fr 1fr;
    gap: 6px;
  }
  
  .roll-field-type {
    grid-column: 1 / 2;
    grid-row: 2;
  }
  
  .roll-field-action {
    grid-column: 2 / 3;
    grid-row: 2;
  }
  
  .roll-field-action .btn {
    width: 100%;
  }
}

/* ========================================
   多疋設定容器樣式優化
   ======================================== */

.rolls-setting-container {
  border: 1px solid var(--border-color, #ddd);
  padding: 16px;
  border-radius: 8px;
  background: var(--bg-light, #f8f9fa);
}

@media (max-width: 540px) {
  .rolls-setting-container {
    padding: 10px;
    border-radius: 6px;
  }
  
  .rolls-summary {
    font-size: 13px !important;
    padding: 6px !important;
  }
  
  .add-roll-btn {
    width: 100%;
    margin-top: 10px !important;
  }
}
