/* =========================================================
   業務銷售系統 — 行動裝置優先樣式
   主色 #1a73e8，狀態色沿用 Google Material 色票
   ========================================================= */
* { box-sizing: border-box; margin: 0; padding: 0; }

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 ---- */
.header {
  background: #1a73e8;
  color: #fff;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 6px rgba(0,0,0,.25);
}
.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;
}

.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-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; }

/* ---- NAV TABS ---- */
.nav-tabs {
  display: flex; background: #fff;
  border-bottom: 2px solid #e8e8e8;
  position: sticky; top: 52px; z-index: 90;
}
.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; }

/* ---- 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; }
/* 本人建立的預售紀錄（可修改／刪除） */
.card-mine { border-left: 4px solid #1a73e8; }

/* ---- 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);
}
.filter-row .btn { flex: 0 0 auto; }
.filter-label { font-size: 12px; color: #888; margin-bottom: 4px; }

/* ---- 採購單表頭（不可改）---- */
.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 .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; }

/* ---- 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;
}

/* ---- 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;
}

/* ---- 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; }
