/* 原香居 寄存系統 */
:root {
  color-scheme: light;
  --bg: #F4F1EA;
  --surface: #FFFFFF;
  --surface-2: #FAF8F4;
  --text: #1E2320;
  --muted: #5F6661;
  --border: #E1DBD0;
  --border-strong: #CBC2B2;
  --primary: #2F5D50;
  --primary-hover: #264C41;
  --primary-soft: #E2EDE8;
  --deposit: #2B7553;
  --deposit-hover: #22603F;
  --deposit-soft: #E2F1E9;
  --pickup: #A85A17;
  --pickup-hover: #8E4A10;
  --pickup-soft: #FBEEDF;
  --danger: #B42318;
  --danger-hover: #971C13;
  --danger-soft: #FDECEA;
  --warn-bg: #FFF4D6;
  --warn-text: #6E4A00;
  --focus: #1F6FEB;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(30, 35, 32, .06), 0 4px 14px rgba(30, 35, 32, .05);
  --font: "Microsoft JhengHei", "微軟正黑體", "PingFang TC", "Noto Sans TC", system-ui, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
}
a { color: var(--primary); }
h1 { font-size: 26px; line-height: 1.3; margin: 4px 0 12px; }
h2, h3 { line-height: 1.35; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row-warn td { background: var(--warn-bg); }
.strong { font-weight: 700; }
.text-danger { color: var(--danger); }

/* ---------- 版面 ---------- */
.offline-banner {
  position: sticky; top: 0; z-index: 30;
  background: var(--danger); color: #fff; text-align: center;
  padding: 8px 12px; font-weight: 700;
}
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 20px;
  background: var(--primary); color: #fff;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .12);
}
.brand {
  display: flex; align-items: center; gap: 10px;
  color: #fff; text-decoration: none; font-weight: 700; font-size: 19px; white-space: nowrap;
}
.brand img { width: 34px; height: 34px; border-radius: 9px; background: #fff; }
.nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav-link {
  color: rgba(255, 255, 255, .9); text-decoration: none;
  padding: 8px 16px; border-radius: 999px; font-weight: 600; white-space: nowrap;
}
.nav-link:hover { background: rgba(255, 255, 255, .14); }
.nav-link[aria-current="page"] { background: #fff; color: var(--primary); }
.user-box { display: flex; align-items: center; gap: 10px; white-space: nowrap; font-size: 15px; }
.view { max-width: 1100px; margin: 0 auto; padding: 20px 16px 96px; }
.page-narrow { max-width: 780px; margin: 0 auto; }
.back-link { display: inline-block; margin-bottom: 10px; text-decoration: none; font-weight: 600; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.card-title { font-size: 19px; margin: 0 0 12px; }
.section-title { font-size: 16px; color: var(--muted); margin: 20px 0 8px; font-weight: 600; }
.empty {
  text-align: center; padding: 28px 16px; color: var(--muted);
  background: var(--surface); border: 1px dashed var(--border-strong); border-radius: var(--radius);
}
.empty p { margin: 0 0 12px; }
.empty p:last-child { margin-bottom: 0; }
.error-box {
  background: var(--danger-soft); color: var(--danger);
  padding: 14px 16px; border-radius: 12px; font-weight: 600;
}
.warn {
  background: var(--warn-bg); color: var(--warn-text);
  padding: 10px 14px; border-radius: 10px; font-weight: 600; margin: 0 0 10px;
}
.chip {
  display: inline-block; padding: 2px 10px; border-radius: 999px;
  background: var(--primary-soft); color: var(--primary); font-size: 14px; font-weight: 600; white-space: nowrap;
}
.chip-muted { background: #ECE8E1; color: var(--muted); }

/* ---------- 按鈕 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4em;
  min-height: 46px; padding: 0 18px;
  border-radius: 10px; border: 1px solid transparent;
  font: inherit; font-weight: 700; line-height: 1.2;
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background-color .15s, border-color .15s;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-secondary { background: var(--primary-soft); color: var(--primary); }
.btn-secondary:hover:not(:disabled) { border-color: var(--primary); }
.btn-ghost { background: #fff; border-color: var(--border-strong); color: var(--text); }
.btn-ghost:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.btn-deposit { background: var(--deposit); color: #fff; }
.btn-deposit:hover:not(:disabled) { background: var(--deposit-hover); }
.btn-pickup { background: var(--pickup); color: #fff; }
.btn-pickup:hover:not(:disabled) { background: var(--pickup-hover); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: var(--danger-hover); }
.btn-on-dark { background: transparent; color: #fff; border-color: rgba(255, 255, 255, .55); }
.btn-on-dark:hover { background: rgba(255, 255, 255, .14); }
.btn-link {
  background: none; border: none; color: var(--primary);
  text-decoration: underline; min-height: 0; padding: 4px 6px; font-weight: 600;
}
.btn-sm { min-height: 38px; padding: 0 12px; font-size: 15px; }
.btn-lg { min-height: 54px; padding: 0 22px; font-size: 18px; }
.btn-xl { min-height: 66px; padding: 0 24px; font-size: 20px; flex: 1; }
.btn-block { width: 100%; }
.icon-btn {
  width: 40px; height: 40px; flex: none;
  border-radius: 10px; border: 1px solid var(--border-strong); background: #fff;
  font: inherit; font-size: 20px; line-height: 1; cursor: pointer; color: var(--text);
}
.icon-btn:disabled { opacity: .35; cursor: not-allowed; }

/* ---------- 表單 ---------- */
input, select, textarea {
  font: inherit; color: var(--text);
  width: 100%; min-height: 46px; padding: 8px 12px;
  border: 1px solid var(--border-strong); border-radius: 10px; background: #fff;
}
textarea { min-height: 70px; resize: vertical; }
input[type="file"] { padding: 9px; }
input:focus, select:focus, textarea:focus {
  outline: 3px solid rgba(47, 93, 80, .22); outline-offset: 0; border-color: var(--primary);
}
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > label { font-weight: 600; font-size: 15px; }
.hint { margin: 0; color: var(--muted); font-size: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 16px; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; flex-wrap: wrap; }
.form-error { color: var(--danger); font-weight: 700; margin: 0 0 12px; }
.sub-form { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--border); }
.sub-form h3 { margin: 0 0 12px; font-size: 17px; }
.danger-zone { border-color: #F0C6C1; }

/* ---------- 登入 ---------- */
.login-wrap { min-height: 78vh; display: grid; place-items: center; }
.login-card {
  width: min(400px, 100%);
  background: #fff; border: 1px solid var(--border); border-radius: 18px;
  padding: 28px; box-shadow: var(--shadow); text-align: center;
}
.login-card .field { text-align: left; }
.login-logo { width: 76px; height: 76px; border-radius: 18px; }
.login-card h1 { font-size: 24px; margin: 12px 0 22px; }

/* ---------- 櫃台 ---------- */
.counter-head { display: flex; gap: 12px; align-items: stretch; }
.search-wrap { flex: 1; }
.search-input { min-height: 62px; font-size: 21px; padding: 0 18px; border-width: 2px; border-radius: 14px; }
.result-list { display: flex; flex-direction: column; gap: 8px; }
.result-row {
  display: grid; grid-template-columns: 56px minmax(0, 1fr) auto; align-items: center; gap: 14px;
  min-height: 66px; padding: 12px 16px;
  background: #fff; border: 1px solid var(--border); border-radius: 12px;
  color: inherit; text-decoration: none;
}
.result-row:hover, .result-row.is-active { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-soft); }
.r-code { color: var(--muted); font-size: 15px; font-variant-numeric: tabular-nums; }
.r-main { display: flex; flex-direction: column; min-width: 0; }
.r-name { font-size: 19px; font-weight: 700; }
.r-phone { color: var(--muted); font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { padding: 4px 12px; border-radius: 999px; font-size: 15px; font-weight: 700; white-space: nowrap; }
.badge-stock { background: var(--deposit-soft); color: var(--deposit); }
.badge-none { background: #ECE8E1; color: var(--muted); font-weight: 500; }

/* ---------- 客戶頁 ---------- */
.cust-title { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.cust-title h1 { margin: 0; }
.cust-edit { margin-left: auto; }
.cust-info { display: grid; grid-template-columns: 56px minmax(0, 1fr); gap: 6px 12px; margin: 14px 0 0; }
.cust-info:empty { display: none; }
.cust-info dt { color: var(--muted); }
.cust-info dd { margin: 0; overflow-wrap: anywhere; }
.stock-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
.stock-tile { border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; background: var(--surface-2); }
.stock-name { font-weight: 600; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.stock-qty { color: var(--muted); }
.stock-qty strong { font-size: 34px; line-height: 1.2; color: var(--deposit); font-variant-numeric: tabular-nums; }
.action-row { display: flex; gap: 12px; margin-top: 18px; }

.history { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.hist {
  position: relative;
  border: 1px solid var(--border); border-left: 5px solid var(--deposit); border-radius: 10px;
  padding: 12px 14px; background: #fff;
}
.hist-pickup { border-left-color: var(--pickup); }
.hist-top { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding-right: 64px; }
.hist-top time { font-variant-numeric: tabular-nums; }
.hist-cust { font-weight: 700; text-decoration: none; }
.hist-items { margin-top: 6px; font-size: 17px; }
.hist-note { background: var(--surface-2); padding: 4px 10px; border-radius: 6px; margin-top: 6px; font-size: 15px; }
.hist-meta { color: var(--muted); font-size: 14px; margin-top: 4px; }
.hist-void { position: absolute; top: 8px; right: 8px; }
.tag { display: inline-block; padding: 2px 10px; border-radius: 6px; font-size: 14px; font-weight: 700; }
.tag-deposit { background: var(--deposit-soft); color: var(--deposit); }
.tag-pickup { background: var(--pickup-soft); color: var(--pickup); }
.tag-opening { background: var(--primary-soft); color: var(--primary); }
.sig-thumb {
  display: block; margin-top: 8px; padding: 4px;
  border: 1px solid var(--border); border-radius: 8px; background: #fff; cursor: zoom-in;
}
.sig-thumb img { display: block; height: 56px; width: auto; max-width: 220px; }
.is-voided { background: #F6F4F0; border-left-color: var(--border-strong); }
.is-voided .hist-items, .is-voided time { text-decoration: line-through; color: var(--muted); }
.void-note { margin-top: 6px; color: var(--danger); font-size: 14px; font-weight: 600; }

/* ---------- 對話框 ---------- */
.modal {
  padding: 0; border: none; border-radius: 16px;
  width: min(560px, calc(100vw - 24px)); max-height: calc(100dvh - 24px);
  color: var(--text); box-shadow: 0 24px 60px rgba(0, 0, 0, .25);
}
.modal[open] { display: flex; flex-direction: column; }
.modal-wide { width: min(780px, calc(100vw - 24px)); }
.modal::backdrop { background: rgba(20, 24, 22, .5); }
.modal-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 20px; border-bottom: 1px solid var(--border);
}
.modal-head h2 { margin: 0; font-size: 20px; }
.modal-body { padding: 16px 20px; overflow: auto; flex: 1 1 auto; }
.modal-foot {
  display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap;
  padding: 14px 20px; border-top: 1px solid var(--border); background: var(--surface-2);
}
.confirm-msg { margin: 0; font-size: 18px; }
.void-preview { background: var(--surface-2); border-radius: 10px; padding: 10px 14px; margin-bottom: 10px; }

.qty-list { display: flex; flex-direction: column; }
.qty-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 0; border-bottom: 1px solid var(--border);
}
.qty-row:last-child { border-bottom: none; }
.qty-label { display: flex; flex-direction: column; }
.qty-name { font-size: 18px; font-weight: 600; }
.qty-note { color: var(--muted); font-size: 14px; }
.qty-row.has-qty .qty-name { color: var(--primary); }
.stepper { display: flex; align-items: center; gap: 6px; }
.step-btn {
  width: 48px; height: 48px; flex: none;
  border-radius: 10px; border: 1px solid var(--border-strong); background: #fff;
  font: inherit; font-size: 26px; line-height: 1; cursor: pointer; color: var(--text);
}
.step-btn:active { background: var(--surface-2); }
.qty-input {
  width: 74px; min-height: 48px; padding: 4px;
  text-align: center; font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums;
}
.summary { margin: 12px 0 0; font-size: 18px; font-weight: 700; color: var(--primary); }

.sig-block { margin: 16px 0; }
.sig-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.sig-label { font-weight: 700; }
.sig-canvas {
  display: block; width: 100%; height: 220px;
  background: #fff; border: 2px dashed var(--border-strong); border-radius: 12px;
  touch-action: none; cursor: crosshair;
}
.sig-view { background: #fff; border: 1px solid var(--border); border-radius: 12px; padding: 8px; text-align: center; }
.sig-view img { max-width: 100%; height: auto; }

/* ---------- 寄存總覽 ---------- */
.tile-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-bottom: 16px; }
.tile { background: #fff; border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; }
.tile-name { font-weight: 600; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.tile-qty { color: var(--muted); }
.tile-qty strong { font-size: 30px; line-height: 1.25; color: var(--primary); font-variant-numeric: tabular-nums; }
.tile-sub { color: var(--muted); font-size: 14px; }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; margin: 8px 0; }
.toolbar input { flex: 2 1 240px; width: auto; }
.toolbar select { flex: 1 1 160px; width: auto; }
.table-wrap { overflow-x: auto; background: #fff; border: 1px solid var(--border); border-radius: var(--radius); }
.table { width: 100%; border-collapse: collapse; font-size: 15px; }
.table th, .table td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
.table th { background: var(--surface-2); font-weight: 700; }
.table tr:last-child td { border-bottom: none; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.row-link { cursor: pointer; }
.row-link:hover { background: var(--primary-soft); }
.row-link a { font-weight: 700; text-decoration: none; }

/* ---------- 期初補登 ---------- */
.opening-top { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 0 16px; }
.ac-wrap { position: relative; margin-bottom: 12px; }
.ac-list {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 10;
  background: #fff; border: 1px solid var(--border-strong); border-radius: 12px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, .12); max-height: 380px; overflow: auto;
}
.ac-item {
  display: flex; gap: 12px; align-items: center; width: 100%;
  padding: 12px 14px; border: none; border-bottom: 1px solid var(--border);
  background: none; font: inherit; color: inherit; text-align: left; cursor: pointer;
}
.ac-item:last-child { border-bottom: none; }
.ac-item.is-active, .ac-item:hover { background: var(--primary-soft); }
.ac-empty {
  padding: 14px; display: flex; gap: 12px; align-items: center; justify-content: space-between;
  flex-wrap: wrap; color: var(--muted);
}
.picked-card {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  background: var(--primary-soft); border-radius: 10px; padding: 10px 14px; margin-bottom: 10px; font-size: 18px;
}
.opening-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; margin: 6px 0 12px; }
.opening-cell { display: flex; flex-direction: column; gap: 4px; font-weight: 600; }
.opening-cell .qty-input { width: 100%; }

/* ---------- 產品、帳號 ---------- */
.prod-list { list-style: none; margin: 0; padding: 0; }
.prod-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.prod-row:last-child { border-bottom: none; }
.order-btns { display: flex; gap: 4px; width: 84px; }
.prod-name { flex: 1; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.prod-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.is-inactive { opacity: .7; }
.add-product-row { display: grid; grid-template-columns: minmax(0, 1fr) 120px auto; gap: 12px; align-items: end; }
.add-product-row .field { margin-bottom: 0; }
.user-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.user-main { display: flex; flex-direction: column; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- 提示訊息 ---------- */
.toast-root {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 1000;
  display: flex; flex-direction: column; gap: 8px;
  width: min(560px, calc(100vw - 32px)); pointer-events: none;
}
.toast {
  background: #1E2320; color: #fff; padding: 12px 16px; border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .2); font-weight: 600;
  transition: opacity .3s, transform .3s;
}
.toast-error { background: var(--danger); }
.toast-hide { opacity: 0; transform: translateY(8px); }

/* ---------- 手機 ---------- */
@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; gap: 6px 10px; padding: 8px 12px; }
  .nav { order: 3; flex-basis: 100%; }
  .user-box { margin-left: auto; }
  .user-name { display: none; }
}
@media (max-width: 640px) {
  body { font-size: 16px; }
  h1 { font-size: 23px; }
  .view { padding: 14px 12px 96px; }
  .card { padding: 16px; }
  .counter-head, .action-row { flex-direction: column; }
  .form-grid, .opening-top, .add-product-row { grid-template-columns: minmax(0, 1fr); }
  .result-row { grid-template-columns: 40px minmax(0, 1fr) auto; gap: 10px; padding: 10px 12px; }
  .qty-row { flex-wrap: wrap; }
  .modal-body { padding: 14px; }
  .modal-head, .modal-foot { padding: 12px 14px; }
  .step-btn { width: 44px; height: 44px; }
  .qty-input { width: 64px; }
}
