:root {
  color-scheme: light;
  --ink: #14251f;
  --muted: #66756f;
  --paper: #fffdf8;
  --canvas: #f1f0e8;
  --green: #16372f;
  --green-2: #27584c;
  --mint: #dff0e7;
  --amber: #e9a23b;
  --amber-soft: #fff1d7;
  --red: #a13e35;
  --red-soft: #fbe8e4;
  --line: #d9ddd7;
  --shadow: 0 12px 30px rgba(20, 37, 31, 0.08);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC", "Noto Sans TC", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { background: var(--canvas); }

body {
  margin: 0;
  min-width: 320px;
  overflow-x: hidden;
  color: var(--ink);
  background:
    radial-gradient(circle at 95% 2%, rgba(233, 162, 59, 0.14), transparent 28rem),
    var(--canvas);
}

.login-screen {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-screen[hidden] { display: none; }

.login-card {
  width: min(100%, 420px);
  display: grid;
  gap: 12px;
  padding: 28px;
  border-radius: 24px;
  background: var(--surface, #fff);
  box-shadow: 0 18px 48px rgba(22, 55, 47, 0.14);
}

.login-card .brand-mark { margin-bottom: 4px; }
.login-card h1, .login-card p { margin: 0; }
.login-card input { width: 100%; box-sizing: border-box; }

button, input, select { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.app-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(16px + env(safe-area-inset-top)) 18px 16px;
  color: white;
  background: var(--green);
}

.brand-mark {
  display: grid;
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  place-items: center;
  border: 1px solid rgba(255,255,255,.38);
  border-radius: 14px;
  color: var(--green);
  background: #f7dca9;
  font-weight: 900;
  font-size: 20px;
}

.eyebrow, .step-label, .meta-label {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .12em;
  text-transform: uppercase;
}

.app-header .eyebrow { color: #b8d2c8; font-size: 10px; }
.app-header h1 { margin: 3px 0 0; font-size: clamp(18px, 5vw, 23px); line-height: 1.2; }

.app-shell {
  width: min(100%, 680px);
  margin: 0 auto;
  padding: 22px 16px calc(104px + env(safe-area-inset-bottom));
}

.view-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-bottom: 22px;
  padding: 4px;
  border-radius: 15px;
  background: #dde2dd;
}
.view-tab {
  min-height: 44px;
  border: 0;
  border-radius: 11px;
  color: var(--muted);
  background: transparent;
  font-weight: 900;
  cursor: pointer;
}
.view-tab.active { color: var(--green); background: var(--paper); box-shadow: 0 3px 10px rgba(20,37,31,.08); }

.section-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.section-heading h2 { margin: 3px 0 0; font-size: 21px; }
.compact-heading { align-items: center; }
.demo-badge, .status-chip {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 5px 9px;
  border-radius: 999px;
  color: var(--green);
  background: var(--mint);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.entry-grid { display: grid; gap: 9px; }
.entry-card {
  display: grid;
  grid-template-columns: 48px 1fr auto;
  align-items: center;
  width: 100%;
  min-height: 72px;
  padding: 10px 15px 10px 10px;
  border: 1px solid var(--line);
  border-radius: 17px;
  color: var(--ink);
  background: var(--paper);
  box-shadow: 0 4px 14px rgba(20,37,31,.035);
  text-align: left;
  cursor: pointer;
}

.entry-card:active { transform: scale(.99); }
.entry-card.active { border-color: #9bbcaf; }
.entry-icon {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 12px;
  color: var(--green);
  background: var(--mint);
  font-weight: 900;
  font-size: 14px;
}
.entry-copy { display: grid; gap: 2px; }
.entry-copy strong { font-size: 17px; }
.entry-copy small { color: var(--muted); font-size: 13px; }

.search-card, .tracking-card, .package-card {
  margin-top: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

label { display: block; margin-bottom: 8px; font-size: 14px; font-weight: 800; }
.search-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
input, select {
  width: 100%;
  min-width: 0;
  min-height: 52px;
  padding: 0 13px;
  border: 1px solid #bfc7c2;
  border-radius: 13px;
  color: var(--ink);
  background: white;
  font-size: 17px;
}
input:focus, select:focus { outline: 3px solid rgba(39, 88, 76, .18); border-color: var(--green-2); }
.field-hint { margin: 9px 0 0; color: var(--muted); font-size: 12px; }
.inline-error { margin: 9px 0 0; color: var(--red); font-size: 13px; font-weight: 700; }

.primary-button, .secondary-button {
  min-height: 52px;
  padding: 0 18px;
  border: 0;
  border-radius: 14px;
  font-weight: 900;
  cursor: pointer;
}
.primary-button { color: white; background: var(--green); }
.primary-button:disabled { color: #94a19c; background: #dfe4e1; cursor: not-allowed; }
.secondary-button { border: 1px solid #b9c2bd; color: var(--green); background: white; }
.compact { min-width: 76px; }

.result-section { margin-top: 27px; scroll-margin-top: 12px; }
.tracking-card { margin-top: 0; }
.tracking-number {
  margin: 5px 0 17px;
  overflow-wrap: anywhere;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: clamp(25px, 8vw, 39px);
  font-weight: 900;
  letter-spacing: .02em;
  line-height: 1.16;
}
.lookup-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 0; }
.lookup-meta div { padding: 10px; border-radius: 12px; background: #f1f3ef; }
dt { color: var(--muted); font-size: 12px; font-weight: 700; }
dd { margin: 3px 0 0; overflow-wrap: anywhere; font-weight: 800; }
.candidate-instruction { margin: 18px 0 8px; font-weight: 800; }
.candidate-list { display: grid; gap: 8px; }
.candidate-button {
  min-height: 54px;
  padding: 10px 13px;
  border: 1px solid #9bbcaf;
  border-radius: 13px;
  color: var(--green);
  background: #f6fbf8;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 16px;
  font-weight: 900;
  overflow-wrap: anywhere;
  cursor: pointer;
}

.package-card { margin-top: 0; padding: 0; overflow: hidden; }
.package-summary { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 16px; border-bottom: 1px solid var(--line); }
.package-summary div { display: grid; gap: 5px; padding: 11px; border-radius: 12px; background: #f1f3ef; }
.package-summary div > span:first-child { color: var(--muted); font-size: 12px; font-weight: 700; }
.identity-block { padding: 18px; color: white; background: var(--green); }
.identity-block .meta-label { color: #b8d2c8; }
.buyer-name { margin: 3px 0 17px; font-size: clamp(34px, 11vw, 52px); font-weight: 950; line-height: 1.08; }
.merchant-label { margin-top: 5px; }
.merchant-name { margin: 3px 0 0; font-size: clamp(24px, 7vw, 35px); font-weight: 900; line-height: 1.18; }
.record-list { display: grid; gap: 12px; padding: 16px; }
.record-card { overflow: hidden; border: 1px solid var(--line); border-radius: 17px; background: white; }
.record-card .identity-block { padding: 16px; }
.record-card .buyer-name { margin-bottom: 14px; }
.record-number { margin: 0 0 8px; color: #b8d2c8; font-size: 11px; font-family: ui-monospace, monospace; overflow-wrap: anywhere; }
.record-details { display: grid; gap: 8px; padding: 12px; }
.record-details dl { display: grid; gap: 8px; margin: 0; }
.record-details dl div { padding: 10px; border-radius: 12px; background: #f1f3ef; }
.product-visual img { display: block; width: 100%; max-height: 260px; margin-top: 8px; border-radius: 14px; object-fit: cover; background: #eee; }
.warning-banner, .unmatched-panel { display: grid; gap: 4px; margin: 0 16px 2px; padding: 13px; border-radius: 13px; }
.warning-banner { color: #704505; background: var(--amber-soft); }
.warning-banner span, .unmatched-panel { font-size: 13px; }
.unmatched-panel { color: var(--red); background: var(--red-soft); }
.batch-inline { margin: 0 16px 16px; padding: 15px; border: 1px solid var(--line); border-radius: 17px; background: #f8f7f2; }
.batch-id-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 7px 0 12px; }
.batch-id-row > strong { font-family: ui-monospace, monospace; font-size: 20px; overflow-wrap: anywhere; }
.batch-counts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 0; }
.batch-counts div { padding: 9px 7px; border-radius: 10px; background: white; text-align: center; }
.batch-counts dd { font-size: 20px; }
.text-button { width: 100%; min-height: 46px; margin-top: 10px; border: 1px solid #9bbcaf; border-radius: 12px; color: var(--green); background: white; font-weight: 900; cursor: pointer; }
.package-list { display: grid; gap: 7px; margin-top: 10px; }
.package-list-item { display: grid; gap: 4px; padding: 10px; border-radius: 11px; background: white; }
.package-list-item strong { font-family: ui-monospace, monospace; overflow-wrap: anywhere; }
.package-list-item small { color: var(--muted); overflow-wrap: anywhere; }
.action-note { margin: 0; padding: 13px 16px; color: var(--muted); background: #f5f4ee; font-size: 13px; font-weight: 700; }

.status-chip.pending { color: #7a4b05; background: var(--amber-soft); }
.status-chip.missing { color: var(--red); background: var(--red-soft); }
.status-chip.neutral { color: #56635e; background: #e8ebe9; }
.status-chip.stocked { color: #215c48; background: #d8f0e5; }
.status-chip.partial { color: #684c00; background: #f8e8ac; }

.overview-note { margin: -3px 0 14px; color: var(--muted); font-size: 13px; }
.batch-overview-list { display: grid; gap: 13px; }
.batch-card { padding: 15px; border: 1px solid var(--line); border-radius: 19px; background: var(--paper); box-shadow: var(--shadow); }
.batch-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.batch-card h3 { margin: 3px 0 0; font-family: ui-monospace, monospace; font-size: 21px; overflow-wrap: anywhere; }
.batch-card .batch-counts { margin-top: 13px; }
.batch-card-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; margin-top: 10px; }
.batch-card-actions button { min-height: 46px; padding: 0 9px; border-radius: 12px; font-weight: 900; cursor: pointer; }
.batch-card-actions .secondary-button { min-height: 46px; }
.inspection-note { margin: 10px 0 0; color: var(--muted); font-size: 12px; }

.action-bar {
  position: fixed;
  z-index: 10;
  right: 0;
  bottom: 0;
  left: 0;
  display: grid;
  grid-template-columns: minmax(110px, .7fr) minmax(170px, 1.3fr);
  gap: 9px;
  width: min(100%, 680px);
  margin: 0 auto;
  padding: 11px 16px calc(11px + env(safe-area-inset-bottom));
  border-top: 1px solid rgba(20,37,31,.1);
  background: rgba(255,253,248,.96);
  backdrop-filter: blur(10px);
}

.toast {
  position: fixed;
  z-index: 30;
  top: calc(14px + env(safe-area-inset-top));
  left: 50%;
  width: min(calc(100% - 32px), 460px);
  padding: 14px 16px;
  transform: translateX(-50%);
  border-radius: 14px;
  color: white;
  background: #0e2a22;
  box-shadow: var(--shadow);
  text-align: center;
  font-weight: 900;
}

.capture-dialog {
  width: min(100% - 20px, 520px);
  max-height: calc(100dvh - 20px);
  margin: auto auto 10px;
  padding: 0;
  border: 0;
  border-radius: 22px;
  color: var(--ink);
  background: var(--paper);
}
.capture-dialog::backdrop { background: rgba(8, 21, 17, .68); backdrop-filter: blur(2px); }
.dialog-sheet { padding: 10px 18px calc(18px + env(safe-area-inset-bottom)); }
.dialog-handle { width: 42px; height: 5px; margin: 0 auto 18px; border-radius: 999px; background: #ccd2ce; }
.dialog-sheet h2 { margin: 3px 0 7px; }
.dialog-description { margin: 0 0 14px; color: var(--muted); }
.privacy-notice { display: grid; gap: 4px; margin-bottom: 14px; padding: 12px; border-radius: 13px; color: #215c48; background: var(--mint); font-size: 13px; }
.dialog-actions { display: grid; grid-template-columns: 1fr 1.35fr; gap: 8px; margin-top: 16px; }
.capture-dialog .dialog-sheet { max-height: calc(100dvh - 20px); overflow-y: auto; overscroll-behavior: contain; }
.camera-stage { position: relative; min-height: clamp(340px, 58dvh, 520px); overflow: hidden; border-radius: 17px; background: #07100d; }
.camera-stage video, #barcode-reader { display: block; width: 100%; height: clamp(340px, 58dvh, 520px); object-fit: contain; }
#barcode-reader video { width: 100% !important; height: 100% !important; object-fit: contain; }
#barcode-reader img { display: none !important; }
#barcode-reader:not([hidden]) ~ .scan-guide { display: none; }
.scan-guide { position: absolute; z-index: 2; top: 50%; right: 4%; left: 4%; height: 52%; transform: translateY(-50%); border: 3px solid #f5c56d; border-radius: 13px; box-shadow: 0 0 0 999px rgba(0,0,0,.2); pointer-events: none; transition: border-color .15s ease, box-shadow .15s ease; }
.camera-stage.scan-success .scan-guide { border-color: #70e0ae; box-shadow: 0 0 0 999px rgba(0,0,0,.16), 0 0 22px rgba(112,224,174,.85); }
.camera-controls { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 9px; align-items: center; margin-top: 9px; }
.camera-controls .secondary-button { min-height: 44px; padding: 0 14px; }
.zoom-control { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 9px; align-items: center; min-height: 44px; margin: 0; padding: 0 12px; border: 1px solid var(--line); border-radius: 12px; background: white; }
.zoom-control span { font-size: 13px; font-weight: 900; }
.zoom-control input { width: 100%; min-width: 0; accent-color: var(--green); }
.capture-status { margin: 10px 0 0; padding: 10px 12px; border-radius: 12px; color: var(--muted); background: #eef1ee; font-size: 13px; font-weight: 800; }
.capture-status[data-tone="success"] { color: #215c48; background: var(--mint); }
.capture-status[data-tone="warning"] { color: #704505; background: var(--amber-soft); }
.recognition-result { margin-top: 12px; padding: 13px; border: 1px solid var(--line); border-radius: 15px; background: white; }
.recognition-result label { margin-top: 3px; }
.ocr-source-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.ocr-preview { display: block; width: 100%; max-height: 34dvh; margin-top: 12px; border-radius: 15px; object-fit: contain; background: #e7e9e6; }
.ocr-progress { margin-top: 12px; }
.ocr-progress > div { height: 9px; overflow: hidden; border-radius: 999px; background: #dfe4e1; }
.ocr-progress span { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--green-2); transition: width .2s ease; }
.ocr-progress p { margin: 7px 0 0; color: var(--muted); font-size: 13px; font-weight: 800; }
.hidden-reader { position: fixed; top: -10000px; left: -10000px; width: 320px; height: 240px; overflow: hidden; opacity: 0; pointer-events: none; }
.candidate-button.selected { border-color: var(--green); box-shadow: 0 0 0 2px rgba(39,88,76,.2); }
.compact-more { min-height: 40px; margin-top: 7px; }
.ocr-dialog-actions { grid-template-columns: repeat(3, 1fr); }

@media (min-width: 700px) {
  .app-header { justify-content: center; }
  .entry-grid { grid-template-columns: repeat(3, 1fr); }
  .entry-card { grid-template-columns: 42px 1fr; padding-right: 10px; }
  .entry-card > :last-child { display: none; }
  .record-details { grid-template-columns: 1.05fr .95fr; }
}

@media (max-width: 359px) {
  .app-shell { padding-right: 12px; padding-left: 12px; }
  .demo-badge { display: none; }
  .search-row { grid-template-columns: 1fr; }
  .compact { width: 100%; }
  .lookup-meta { grid-template-columns: 1fr; }
  .batch-counts { grid-template-columns: 1fr; }
  .batch-counts div { display: flex; align-items: center; justify-content: space-between; text-align: left; }
  .batch-counts dd { margin-top: 0; }
  .batch-card-actions { grid-template-columns: 1fr; }
  .action-bar { padding-right: 12px; padding-left: 12px; }
  .ocr-source-actions, .ocr-dialog-actions, .camera-controls { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
