/* =========================================================
   業務銷售系統 — 行動裝置優先樣式
   主色 #1a73e8，狀態色沿用 Google Material 色票
   ========================================================= */
* { box-sizing: border-box; margin: 0; padding: 0; }

html {
  /* 錨點（如標題列的「查詢條件」）跳轉時預留固定標題列＋分頁標籤的高度，
     否則目標會捲到 .app-chrome 底下被蓋住。 */
  scroll-padding-top: 104px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang TC', 'Microsoft JhengHei', sans-serif;
  background: #f0f2f5;
  color: #333;
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}

a { text-decoration: none; color: inherit; }

/* ---- HEADER ---- */
/* 標題列與分頁標籤一起固定在畫面最上方。整塊一起 sticky，
   分頁標籤就不必寫死 header 高度當偏移量（header 高度會隨頁面內容變動）。 */
.app-chrome {
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 6px rgba(0,0,0,.25);
}
.header {
  background: #1a73e8;
  color: #fff;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.header h1 { font-size: 17px; font-weight: 600; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.back-btn { color: #fff; font-size: 22px; line-height: 1; padding: 2px 6px 2px 0; }
.header-user { font-size: 12px; opacity: .85; white-space: nowrap; }
/* header 中間的訂單搜尋框（保留標題，搜尋框收窄置中）*/
.header h1.header-title-sm { flex: 0 0 auto; font-size: 16px; font-weight: 600; white-space: nowrap; }
.header-search {
  flex: 0 1 420px; max-width: 420px; margin: 0 auto;
  display: flex; gap: 6px; align-items: center; min-width: 0;
}
.header-search input {
  flex: 1; min-width: 0; padding: 8px 12px;
  border: none; border-radius: 8px; font-size: 14px; outline: none;
  background: #fff; color: #333; font-family: inherit;
}
.header-search button {
  flex: 0 0 auto; background: rgba(255,255,255,.25); border: none; color: #fff;
  border-radius: 8px; padding: 8px 12px; cursor: pointer; font-size: 15px; line-height: 1;
}
.header-query-btn {
  background: rgba(255,255,255,.2); color: #fff; padding: 7px 10px;
  border-radius: 7px; font-size: 13px; white-space: nowrap;
}

/* 手機版優先保留訂單搜尋空間，系統名稱改由瀏覽器標題辨識即可。 */
@media (max-width: 600px) {
  .header h1.header-title-sm { display: none; }
  .header-search { flex: 1 1 auto; max-width: none; margin: 0; }
}

.logout-form { margin: 0; }
.logout-btn {
  background: rgba(255,255,255,.2);
  border: none; color: #fff;
  padding: 6px 12px; border-radius: 6px;
  cursor: pointer; font-size: 13px;
  white-space: nowrap;
}

/* ---- CONTENT ---- */
.content { padding: 14px; }

/* ---- LOGIN ---- */
.login-screen {
  background: linear-gradient(160deg, #1a73e8, #0d47a1);
  min-height: 100vh;
  display: flex; justify-content: center; align-items: center;
  margin: -14px; padding: 14px;
}
.login-card {
  background: #fff; border-radius: 18px; padding: 32px 24px;
  width: 100%; max-width: 360px;
  box-shadow: 0 10px 40px rgba(0,0,0,.18);
}
.login-logo { text-align: center; margin-bottom: 28px; }
.login-logo .logo-icon { font-size: 48px; line-height: 1; margin-bottom: 8px; }
.login-logo h2 { font-size: 22px; color: #1a73e8; font-weight: 700; }
.login-logo p { color: #999; font-size: 13px; margin-top: 4px; }

/* ---- FORM ---- */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; color: #555; margin-bottom: 6px; font-weight: 500; }
.form-group input,
.form-group select,
.form-group textarea {
  width: 100%; padding: 12px 14px;
  border: 1.5px solid #e0e0e0; border-radius: 9px;
  font-size: 15px; outline: none;
  transition: border-color .2s, box-shadow .2s;
  background: #fff; color: #333; appearance: auto;
  font-family: inherit;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: #1a73e8;
  box-shadow: 0 0 0 3px rgba(26,115,232,.12);
}
.form-group textarea { resize: none; height: 82px; line-height: 1.5; }
.form-group input[readonly] { background: #f5f5f5; color: #666; border-style: dashed; }
.required { color: #ea4335; }

/* 客戶代號＋簡稱並排：打代號自動抓出簡稱 */
.code-row { display: flex; gap: 8px; }
.code-row input:first-child { flex: 0 0 40%; }
.code-row input:last-child  { flex: 1; }
.field-hint { font-size: 12px; color: #999; margin-top: 5px; }
.field-hint.err { color: #ea4335; }

/* ---- BUTTONS ---- */
.btn {
  display: inline-block; padding: 13px 18px;
  border: none; border-radius: 9px;
  font-size: 15px; font-weight: 600;
  cursor: pointer; transition: opacity .15s, transform .1s;
  text-align: center; font-family: inherit;
}
.btn:active { opacity: .82; transform: scale(.97); }
.btn:disabled { cursor: wait; opacity: .72; }
.btn-block { display: block; width: 100%; }
.btn-primary { background: #1a73e8; color: #fff; }
.btn-sm { padding: 7px 14px; font-size: 13px; font-weight: 500; border-radius: 7px; }
.btn-success { background: #34a853; color: #fff; }
.btn-warning { background: #f9ab00; color: #fff; }
.btn-danger  { background: #ea4335; color: #fff; }
.btn-info    { background: #4285f4; color: #fff; }
.btn-gray    { background: #e0e0e0; color: #444; }
.btn.is-loading { pointer-events: none; }
.button-spinner {
  display: inline-block; width: 13px; height: 13px; margin-right: 5px;
  vertical-align: -2px; border: 2px solid rgba(255,255,255,.45);
  border-top-color: #fff; border-radius: 50%; animation: query-spin .7s linear infinite;
}
.button-spinner[hidden] { display: none; }

/* ---- NAV TABS ---- */
.nav-tabs {
  display: flex; background: #fff;
  border-bottom: 2px solid #e8e8e8;
}
.nav-tab {
  flex: 1; padding: 12px 8px;
  text-align: center; font-size: 14px; color: #777;
  cursor: pointer; border-bottom: 3px solid transparent;
  margin-bottom: -2px; font-weight: 500; transition: color .2s;
}
.nav-tab.active { color: #1a73e8; border-bottom-color: #1a73e8; }
/* 五個分頁在窄螢幕會擠成兩行，縮字級與左右內距讓它們維持單行。 */
@media (max-width: 400px) {
  .nav-tab { font-size: 12.5px; padding: 12px 3px; }
}

/* ---- CARDS ---- */
.card {
  background: #fff; border-radius: 13px; padding: 15px;
  margin-bottom: 12px;
  box-shadow: 0 1px 5px rgba(0,0,0,.07);
}
.card-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 10px; gap: 8px; }
.card-title { font-size: 15px; font-weight: 600; color: #222; line-height: 1.3; }
.card-subtitle { font-size: 12px; color: #999; margin-top: 3px; }
.result-card { border-left: 4px solid #1a73e8; padding-left: 12px; }
.result-order-no { color: #1a73e8; font-size: 16px; font-weight: 700; line-height: 1.35; }
.result-product { color: #222; font-size: 16px; font-weight: 700; line-height: 1.35; margin-top: 7px; }
.result-meta { color: #777; font-size: 12px; line-height: 1.6; margin: 3px 0 12px; }
/* 本人建立的預售紀錄（可修改／刪除） */
.card-mine { border-left: 4px solid #1a73e8; }

/* ---- 行情表：同品項下的個別報價 ---- */
.mark-quote {
  border-top: 1px solid #edf0f2;
  padding: 10px 0;
}
.mark-quote:first-of-type { border-top: none; padding-top: 0; }
.mark-quote:last-child { padding-bottom: 0; }

/* ---- STATS ROW ---- */
.stats-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.stat-item {
  flex: 1; min-width: 70px;
  background: #f6f8fc; border-radius: 8px; padding: 8px 10px;
}
.stat-label { font-size: 11px; color: #888; margin-bottom: 2px; }
.stat-value { font-size: 16px; font-weight: 700; color: #333; }
.stat-value.positive { color: #1e8e3e; }
.stat-value.zero     { color: #d93025; }

/* ---- BADGE ---- */
.badge { display: inline-block; padding: 3px 9px; border-radius: 20px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.badge-green { background: #e6f4ea; color: #1e7e34; }
.badge-red   { background: #fce8e6; color: #c5221f; }
.badge-blue  { background: #e8f0fe; color: #1557b0; }
.badge-gray  { background: #f1f3f4; color: #5f6368; }

/* ---- ACTION ROW ---- */
.action-row { display: flex; gap: 8px; justify-content: flex-end; }
.action-row form { margin: 0; }

/* ---- FILTER ROW ---- */
.filter-row { display: flex; gap: 8px; margin-bottom: 10px; }
.filter-row select,
.filter-row input {
  flex: 1; padding: 10px 12px; min-width: 0;
  border: 1.5px solid #e0e0e0; border-radius: 9px;
  font-size: 14px; background: #fff; color: #333; appearance: auto;
  outline: none; transition: border-color .2s, box-shadow .2s;
  font-family: inherit;
}
.filter-row input:focus {
  border-color: #1a73e8;
  box-shadow: 0 0 0 3px rgba(26,115,232,.12);
}
/* 所有頁面的日期欄位統一尺寸，避免手機原生日期控制項因寬度不足裁切文字。 */
input[type="date"] {
  width: 100%;
  min-width: 0;
  min-height: 45px;
  padding: 10px 12px;
  font-size: 15px;
}
.receipt-date-row > div { flex: 1 1 0; min-width: 0; }
.receipt-date-row input[type="date"] { width: 100%; }
.filter-row .btn { flex: 0 0 auto; }
.filter-label { font-size: 12px; color: #888; margin-bottom: 4px; }

@media (max-width: 400px) {
  .receipt-date-row { gap: 6px; }
}

/* ---- 預售紀錄查詢條件 ---- */
.query-card {
  background: #fff; border-radius: 13px; padding: 15px; margin-bottom: 14px;
  box-shadow: 0 1px 5px rgba(0,0,0,.07);
}
.query-title { color: #1a73e8; font-size: 16px; font-weight: 700; margin-bottom: 14px; }
.date-range { display: flex; align-items: center; gap: 8px; }
.date-range input { min-width: 0; flex: 1; }
.date-range span { color: #777; font-size: 13px; white-space: nowrap; }
.filter-group { border: 0; margin: 0 0 16px; padding: 0; }
.filter-group legend { font-size: 13px; color: #555; font-weight: 500; margin-bottom: 7px; }
.choice-btns { display: flex; flex-wrap: wrap; gap: 8px; }
.choice-btn {
  padding: 8px 12px; border: 1.5px solid #e0e0e0; border-radius: 20px;
  background: #fff; color: #444; font-size: 14px; cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
}
.choice-btn input { position: absolute; opacity: 0; pointer-events: none; }
.choice-btn.active { background: #e8f0fe; border-color: #1a73e8; color: #1557b0; font-weight: 600; }
.query-actions { display: flex; justify-content: flex-end; gap: 8px; }
.page-loading {
  position: fixed; inset: 0; z-index: 3000; display: flex;
  align-items: center; justify-content: center; background: rgba(20, 35, 55, .28);
}
.page-loading[hidden] { display: none; }
.page-loading-card {
  display: flex; align-items: center; gap: 11px; padding: 16px 20px;
  border-radius: 12px; background: #fff; color: #1557b0; font-size: 15px;
  font-weight: 600; box-shadow: 0 8px 24px rgba(0,0,0,.18);
}
.page-spinner {
  width: 21px; height: 21px; border: 3px solid #d2e3fc;
  border-top-color: #1a73e8; border-radius: 50%; animation: query-spin .7s linear infinite;
}
@keyframes query-spin { to { transform: rotate(360deg); } }

/* ---- 採購單表頭（不可改）---- */
.po-head {
  background: #fff; border-radius: 13px; padding: 13px 15px;
  margin-bottom: 12px; box-shadow: 0 1px 5px rgba(0,0,0,.07);
  border-left: 4px solid #1a73e8;
}
.po-head-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.po-head .po-no { font-size: 15px; font-weight: 700; color: #1a73e8; }
.po-head .po-meta { font-size: 12px; color: #777; margin-top: 5px; line-height: 1.7; }
.po-export-btn { white-space: nowrap; }

/* ---- INFO BOX ---- */
.info-box {
  background: #e8f0fe; border-radius: 10px; padding: 13px 14px;
  margin-bottom: 18px; font-size: 13px; color: #1557b0;
  line-height: 1.6;
}
.info-box strong { display: block; font-size: 16px; color: #1a73e8; margin-bottom: 4px; font-weight: 600; }

/* ---- DETAIL LINES ---- */
.detail-lines { font-size: 13px; color: #555; line-height: 1.9; }
.detail-lines span { color: #222; font-weight: 600; }

/* ---- EMPTY STATE ---- */
.empty-state { text-align: center; padding: 52px 16px; color: #aaa; }
.empty-state .empty-icon { font-size: 52px; margin-bottom: 12px; }
.empty-state p { font-size: 15px; }

/* ---- VALIDATION ---- */
.err-text, .validation-summary-errors {
  color: #ea4335; font-size: 13px; margin-bottom: 12px;
}
.validation-summary-errors ul { list-style: none; }
.field-validation-error { color: #ea4335; font-size: 12px; display: block; margin-top: 5px; }
.input-validation-error { border-color: #ea4335 !important; }
.validation-summary-valid { display: none; }

/* ---- REASON BUTTONS（異常原因多選）---- */
.reason-btns { display: flex; flex-wrap: wrap; gap: 8px; }
.reason-btn {
  padding: 8px 14px; border: 1.5px solid #e0e0e0; border-radius: 20px;
  background: #fff; color: #444; font-size: 14px; cursor: pointer;
  font-family: inherit; transition: background .15s, border-color .15s, color .15s;
}
.reason-btn:active { transform: scale(.97); }
.reason-btn.active { background: #e8f0fe; border-color: #1a73e8; color: #1557b0; font-weight: 600; }

/* ---- DEFECT THUMBNAILS ---- */
.defect-thumbs { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.defect-thumbs img {
  width: 88px; height: 88px; object-fit: cover;
  border-radius: 8px; border: 1px solid #e0e0e0; display: block;
  cursor: pointer;
}
.defect-edit-images { display: flex; flex-wrap: wrap; gap: 10px; }
.defect-edit-image {
  width: 108px; overflow: hidden; border: 1px solid #e0e0e0;
  border-radius: 8px; background: #fafafa; color: #555; font-size: 12px;
}
.defect-edit-image img { width: 108px; height: 88px; object-fit: cover; display: block; }
.defect-edit-image span { display: block; padding: 6px; }
.defect-edit-image input { width: auto; margin-right: 3px; vertical-align: middle; }

/* ---- 收款單附件：逐張縮圖，既有檔與待上傳檔共用同一種圖磚 ---- */
.upload-tiles { display: flex; flex-wrap: wrap; gap: 10px; }
.upload-tiles:empty { display: none; }
.upload-tile {
  width: 108px; border: 1px solid #e0e0e0; border-radius: 8px;
  background: #fafafa; overflow: hidden; font-size: 12px; color: #555;
}
.upload-tile-preview { display: block; width: 108px; height: 88px; background: #fff; }
.upload-tile-preview img { width: 108px; height: 88px; object-fit: cover; display: block; }
/* PDF 沒有縮圖，改用圖示佔位 */
.upload-tile-icon {
  display: flex; align-items: center; justify-content: center;
  width: 108px; height: 88px; font-size: 30px;
}
.upload-tile-name {
  padding: 6px 6px 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.upload-tile-size { padding: 0 6px; color: #999; font-size: 11px; }
/* 既有檔用 <label>＋checkbox、待上傳檔用 <button>，兩者外觀一致。
   選擇器刻意用兩個 class，才蓋得過 .form-group label / .form-group input 的基礎樣式。 */
.upload-tile .upload-tile-remove {
  display: flex; align-items: center; justify-content: center; gap: 4px;
  width: 100%; margin: 5px 0 0; padding: 7px 6px;
  border: none; border-top: 1px solid #eee; background: none;
  color: #ea4335; font: inherit; font-size: 12px; font-weight: 500;
  cursor: pointer; text-align: center;
}
.upload-tile .upload-tile-remove input[type="checkbox"] {
  width: auto; margin: 0; padding: 0;
  border: none; border-radius: 0; box-shadow: none;
  appearance: auto; accent-color: #ea4335;
}
/* 既有檔勾選移除後不立刻消失，維持可反悔 */
.upload-tile.removed { opacity: .45; }
.upload-tile.removed .upload-tile-name { text-decoration: line-through; }

/* ---- LIGHTBOX（圖片燈箱）---- */
.lightbox {
  position: fixed; inset: 0; z-index: 2000;
  background: rgba(0,0,0,.9);
  display: flex; align-items: center; justify-content: center;
}
.lightbox[hidden] { display: none; }
.lb-img { max-width: 92vw; max-height: 82vh; object-fit: contain; border-radius: 6px; }
.lb-close {
  position: absolute; top: 12px; right: 18px;
  font-size: 34px; line-height: 1; color: #fff;
  background: none; border: none; cursor: pointer;
}
.lb-prev, .lb-next {
  position: absolute; top: 50%; transform: translateY(-50%);
  font-size: 30px; color: #fff; background: rgba(0,0,0,.35);
  border: none; cursor: pointer; padding: 14px 18px; border-radius: 10px;
  -webkit-tap-highlight-color: transparent;
}
.lb-prev { left: 10px; }
.lb-next { right: 10px; }
.lb-count {
  position: absolute; bottom: 18px; left: 50%; transform: translateX(-50%);
  color: #fff; font-size: 14px; background: rgba(0,0,0,.45);
  padding: 4px 14px; border-radius: 20px;
}
.form-group input[type="file"] {
  padding: 10px 12px; background: #fafafa;
  border: 1.5px dashed #ccc;
}

/* ---- PAGER ---- */
.pager {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin: 4px 0 18px;
}
.pager-info { font-size: 13px; color: #777; white-space: nowrap; }
.pager .disabled { opacity: .45; pointer-events: none; }

/* ---- SECTION LABEL ---- */
.section-label {
  font-size: 12px; color: #999; font-weight: 600;
  letter-spacing: .5px; margin: 4px 0 8px;
}
.detail-section-title {
  font-size: 16px; color: #1a73e8; letter-spacing: 0;
  margin: 18px 0 10px;
}

/* ---- TOAST ---- */
.toast {
  position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%);
  background: #323232; color: #fff;
  padding: 12px 22px; border-radius: 10px;
  font-size: 14px; z-index: 9999;
  opacity: 0; transition: opacity .3s;
  pointer-events: none; white-space: nowrap;
  max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; }
