/* ============================================================
   中壢店 POS — CSS
   沿用 checkout_doGet.js L62-366 的 tokens / 佈局
   ============================================================ */

:root {
  --bg:           #F7F4EF;
  --card:         #FFFFFF;
  --accent:       #C8864A;
  --accent-light: #F5E6D6;
  --text:         #1C1C1C;
  --text-sub:     #777;
  --border:       #E8E2D9;
  --success:      #3D7A5B;
  --success-bg:   #EAF4EE;
  --error:        #C0392B;
  --error-bg:     #FDECEA;
  --warn:         #9A6F00;
  --warn-bg:      #FFFBF0;
  --radius:       12px;
  --header-h:     56px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Noto Sans TC', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding-bottom: 80px;
}

/* ── Header ── */
.header {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  height: var(--header-h);
  background: var(--text);
  display: flex; align-items: center;
  padding: 0 16px; gap: 12px;
}
.header-title {
  color: #fff; font-size: 15px; font-weight: 700; flex: 1;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.btn-header {
  background: transparent; border: 1px solid rgba(255,255,255,.3);
  color: #fff; font-size: 12px; padding: 6px 10px; border-radius: 6px;
  cursor: pointer; font-family: inherit;
}
.btn-header:hover { background: rgba(255,255,255,.1); }
.net-badge {
  display: flex; align-items: center; gap: 5px;
  padding: 4px 10px; border-radius: 20px;
  font-size: 12px; font-weight: 700;
  transition: all .3s; white-space: nowrap;
}
.net-badge.online  { background: #1a3d2b; color: #5cb87a; }
.net-badge.offline { background: #3d1a1a; color: #e05c5c; animation: blink 1.2s infinite; }
.net-badge.syncing { background: #3d3000; color: #e0b84a; }
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:.5} }
.net-dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }

.offline-bar {
  position: fixed; top: var(--header-h); left: 0; right: 0; z-index: 99;
  background: var(--error-bg); border-bottom: 2px solid var(--error);
  padding: 8px 16px; display: none;
  align-items: center; justify-content: space-between; gap: 12px;
}
.offline-bar.show { display: flex; }
.offline-bar-text { font-size: 13px; color: var(--error); font-weight: 600; }
.btn-resend {
  padding: 6px 14px; border-radius: 20px;
  background: var(--error); color: #fff;
  border: none; font-size: 12px; font-weight: 700;
  cursor: pointer; font-family: inherit; white-space: nowrap;
}
.btn-resend:disabled { opacity: .5; cursor: not-allowed; }

/* ── 主容器 ── */
.main-wrap {
  margin-top: var(--header-h);
  max-width: 600px; margin-left: auto; margin-right: auto;
  padding: 0 12px;
}

/* ── Tab ── */
.tabs {
  display: grid; grid-template-columns: 1fr 1fr;
  margin: 12px 0 16px; border-radius: var(--radius);
  overflow: hidden; border: 1.5px solid var(--border);
  background: var(--card);
}
.tab-btn {
  padding: 12px; border: none; background: transparent;
  font-family: inherit; font-size: 14px; font-weight: 600;
  color: var(--text-sub); cursor: pointer; transition: all .2s;
}
.tab-btn.active { background: var(--text); color: #fff; }

/* ── Section ── */
.section {
  background: var(--card); border-radius: var(--radius);
  border: 1.5px solid var(--border); margin-bottom: 12px;
  overflow: hidden;
}
.section-title {
  font-size: 11px; font-weight: 700; letter-spacing: 2px;
  color: var(--text-sub); text-transform: uppercase;
  padding: 12px 16px 8px; border-bottom: 1px solid var(--border);
}

/* ── 表單欄位 ── */
.field { padding: 10px 16px; border-bottom: 1px solid var(--border); }
.field:last-child { border-bottom: none; }
.field-label {
  font-size: 12px; font-weight: 700; color: var(--text-sub);
  margin-bottom: 6px; display: flex; align-items: center; gap: 4px;
}
.req { color: var(--error); }
.field-row   { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.field-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }

.input, .select {
  width: 100%; padding: 10px 12px;
  border: 1.5px solid var(--border); border-radius: 8px;
  font-size: 14px; font-family: inherit; color: var(--text);
  background: #fff; outline: none;
  transition: border-color .2s;
  -webkit-appearance: none;
}
.input:focus, .select:focus { border-color: var(--accent); }
.input.error, .select.error { border-color: var(--error); }
.input[readonly] { background: var(--bg); color: var(--text-sub); cursor: default; }

.hint { font-size: 11px; color: var(--text-sub); margin-top: 4px; }
.hint.success { color: var(--success); }
.hint.error   { color: var(--error); }
.hint.warn    { color: var(--warn); }

/* 建議價 */
.suggest-box {
  background: var(--accent-light); border-radius: 8px;
  padding: 8px 12px; margin-top: 6px;
  font-size: 13px; color: #7A5030; display: none;
}
.suggest-box.show { display: block; }
.suggest-val { font-size: 18px; font-weight: 900; color: var(--accent); }

/* 折現切換 */
.toggle-row { display: flex; align-items: center; gap: 8px; }
.toggle { position: relative; width: 44px; height: 24px; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; inset: 0; background: var(--border);
  border-radius: 24px; cursor: pointer; transition: .3s;
}
.slider:before {
  content: ''; position: absolute;
  height: 18px; width: 18px;
  left: 3px; bottom: 3px;
  background: #fff; border-radius: 50%; transition: .3s;
}
.toggle input:checked + .slider { background: var(--accent); }
.toggle input:checked + .slider:before { transform: translateX(20px); }
.toggle-label { font-size: 13px; color: var(--text-sub); }
.toggle input:checked ~ .toggle-label { color: var(--accent); font-weight: 700; }

/* 零售品項 */
.item-row {
  border-bottom: 1px solid var(--border); padding: 12px 16px;
  position: relative;
}
.item-row:last-child { border-bottom: none; }
.item-row-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 8px;
}
.item-num {
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--text); color: #fff;
  font-size: 12px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.btn-remove-item {
  border: none; background: none; color: var(--error);
  font-size: 18px; cursor: pointer; padding: 0 4px; line-height: 1;
}

.search-wrap { position: relative; }
.search-results {
  position: absolute; top: 100%; left: 0; right: 0; z-index: 50;
  background: #fff; border: 1.5px solid var(--accent);
  border-radius: 0 0 8px 8px; max-height: 200px; overflow-y: auto;
  box-shadow: 0 4px 12px rgba(0,0,0,.1);
  display: none;
}
.search-results.show { display: block; }
.search-item {
  padding: 10px 12px; cursor: pointer;
  border-bottom: 1px solid var(--border); font-size: 13px;
}
.search-item:hover { background: var(--accent-light); }
.search-item:last-child { border-bottom: none; }
.search-item .code { font-size: 11px; color: var(--text-sub); }

.btn-add-item {
  width: 100%; padding: 12px; border: 2px dashed var(--border);
  border-radius: var(--radius); background: transparent;
  color: var(--accent); font-size: 14px; font-weight: 700;
  cursor: pointer; font-family: inherit;
  margin-bottom: 12px; transition: all .2s;
}
.btn-add-item:hover { border-color: var(--accent); background: var(--accent-light); }

.summary-box {
  background: var(--text); color: #fff;
  border-radius: var(--radius); padding: 16px;
  margin-bottom: 12px;
}
.summary-row {
  display: flex; justify-content: space-between;
  font-size: 13px; margin-bottom: 6px; color: #aaa;
}
.summary-row.total {
  font-size: 18px; font-weight: 900; color: #fff;
  margin-bottom: 0; margin-top: 8px; padding-top: 8px;
  border-top: 1px solid #333;
}
.summary-row.total .label { color: #fff; }

.btn-submit {
  width: 100%; padding: 16px;
  background: var(--accent); color: #fff; border: none;
  border-radius: var(--radius); font-size: 16px; font-weight: 900;
  font-family: inherit; cursor: pointer; letter-spacing: 1px;
  transition: all .2s; margin-bottom: 8px;
}
.btn-submit:hover { filter: brightness(1.1); }
.btn-submit:active { transform: scale(.98); }
.btn-submit:disabled { background: #bbb; cursor: not-allowed; filter: none; }

.btn-clear {
  width: 100%; padding: 10px;
  background: transparent; border: 1.5px solid var(--border);
  border-radius: var(--radius); font-size: 13px;
  color: var(--text-sub); cursor: pointer; font-family: inherit;
}
.btn-clear:hover { background: var(--bg); }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  padding: 12px 20px; border-radius: 24px;
  font-size: 14px; font-weight: 700; white-space: nowrap;
  box-shadow: 0 4px 16px rgba(0,0,0,.2);
  z-index: 9999; opacity: 0; transition: opacity .3s;
  pointer-events: none;
}
.toast.show { opacity: 1; }
.toast.success { background: var(--success); color: #fff; }
.toast.error   { background: var(--error); color: #fff; }
.toast.warn    { background: var(--warn); color: #fff; }
.toast.info    { background: var(--text); color: #fff; }

.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.5);
  z-index: 200; display: none; align-items: center; justify-content: center;
  padding: 16px;
}
.modal-overlay.show { display: flex; }
.modal {
  background: #fff; border-radius: var(--radius);
  width: 100%; max-width: 400px; overflow: hidden;
}
.modal-header {
  background: var(--text); color: #fff;
  padding: 14px 16px; font-size: 15px; font-weight: 700;
}
.modal-body { padding: 16px; max-height: 60vh; overflow-y: auto; }
.modal-summary-row {
  display: flex; justify-content: space-between;
  padding: 6px 0; border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.modal-summary-row:last-child { border-bottom: none; }
.modal-summary-label { color: var(--text-sub); }
.modal-summary-val { font-weight: 700; }
.modal-footer {
  display: grid; grid-template-columns: 1fr 1fr; gap: 0;
  border-top: 1.5px solid var(--border);
}
.modal-btn {
  padding: 14px; border: none; font-family: inherit;
  font-size: 14px; font-weight: 700; cursor: pointer;
}
.modal-btn.cancel { background: var(--bg); color: var(--text-sub); }
.modal-btn.confirm { background: var(--accent); color: #fff; }
