/*
 * 糖人街國際 ERP — Trade Console
 * 現代企業控制台,參考 SAP Fiori / Linear / Stripe Dashboard
 * Typography: Inter (en) + Noto Sans TC (zh) + JetBrains Mono (numerics)
 * 紀律 > 裝飾。1px hairline,3px 圓角,深普魯士藍主色,純白卡面,冷灰背景。
 */

/* ============================================================
 * 0. THEME TOKENS
 * ============================================================ */
:root {
  /* Canvas & surfaces — cool greys */
  --canvas:      #F8FAFC;   /* page background */
  --surface:     #FFFFFF;   /* cards, dialogs */
  --surface-2:   #F1F5F9;   /* table headers, wells, inactive tabs */
  --surface-3:   #E2E8F0;   /* hover, subtle dividers */
  --surface-4:   #CBD5E1;   /* stronger dividers */

  /* Ink — cool slate text scale */
  --ink-1:       #0F172A;   /* primary headings & numerics */
  --ink-2:       #334155;   /* body */
  --ink-3:       #64748B;   /* labels, captions */
  --ink-4:       #94A3B8;   /* placeholders, disabled */
  --ink-on-dark: #F8FAFC;   /* text on dark surfaces */

  /* Rules */
  --rule:         #E2E8F0;
  --rule-strong:  #CBD5E1;
  --rule-faint:   #EEF2F6;

  /* Brand — deep prussian. Used for primary actions, focus rings, key accents. */
  --brand:        #1D3557;
  --brand-deep:   #14253E;
  --brand-hover:  #284969;
  --brand-soft:   #DBE2EC;   /* tint backgrounds */
  --brand-ghost:  #EEF2F8;
  --brand-ring:   rgba(29, 53, 87, 0.18);

  /* Status — sober, predictable, ERP-standard */
  --success:      #047857;
  --success-deep: #065F46;
  --success-soft: #D1FAE5;
  --success-ghost:#ECFDF5;

  --warn:         #B45309;
  --warn-deep:    #92400E;
  --warn-soft:    #FED7AA;
  --warn-ghost:   #FFFBEB;

  --danger:       #B91C1C;
  --danger-deep:  #991B1B;
  --danger-soft:  #FECACA;
  --danger-ghost: #FEF2F2;

  --info:         #1E40AF;
  --info-soft:    #DBEAFE;
  --info-ghost:   #EFF6FF;

  /* The 進貨 inbound family — kept warm to retain a slice of brand identity. */
  --rust:         #B45309;
  --rust-deep:    #92400E;
  --rust-soft:    #FED7AA;
  --rust-ghost:   #FFF7ED;

  /* Return flow — destructive-adjacent but distinct from danger */
  --return:       #C2410C;
  --return-soft:  #FED7AA;
  --return-ghost: #FFF7ED;

  /* Shadows */
  --shadow-xs:    0 1px 1px rgba(15, 23, 42, 0.04);
  --shadow-sm:    0 1px 2px rgba(15, 23, 42, 0.06), 0 1px 3px rgba(15, 23, 42, 0.04);
  --shadow-md:    0 4px 10px rgba(15, 23, 42, 0.08), 0 2px 4px rgba(15, 23, 42, 0.04);
  --shadow-lg:    0 16px 36px rgba(15, 23, 42, 0.14), 0 4px 12px rgba(15, 23, 42, 0.08);

  /* Radii */
  --r-sm: 3px;
  --r-md: 4px;
  --r-lg: 6px;
}

/* PDA High-Contrast subtheme */
html[data-pda="1"] {
  --canvas:      #FFFFFF;
  --surface:     #FFFFFF;
  --surface-2:   #F1F5F9;
  --ink-1:       #000000;
  --ink-2:       #111827;
  --brand:       #1D4ED8;       /* punchier blue for warehouse glare */
  --brand-deep:  #1E3A8A;
  --danger:      #DC2626;
  --success:     #047857;
  --rust:        #C2410C;
  --rule-strong: #94A3B8;
}

/* ============================================================
 * 1. RESET & BASE
 * ============================================================ */
html, body { height: 100%; }
html {
  -webkit-tap-highlight-color: transparent;
  background: var(--canvas);
}
body {
  margin: 0;
  font-family: Inter, "Noto Sans TC", system-ui, -apple-system, sans-serif;
  font-feature-settings: "cv11", "ss01", "ss03";
  font-size: 14px;
  line-height: 1.45;
  color: var(--ink-2);
  background: var(--canvas);
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: contain;
  -moz-osx-font-smoothing: grayscale;
  -webkit-font-smoothing: antialiased;
}

::selection { background: var(--brand); color: #fff; }

/* ============================================================
 * 2. TYPOGRAPHY — discipline over drama
 * ============================================================ */
h1, h2, h3, h4 {
  font-family: Inter, "Noto Sans TC", system-ui, sans-serif;
  font-weight: 700;
  letter-spacing: -0.011em;
  color: var(--ink-1);
}
h1 { font-size: 1.375rem; line-height: 1.25; }
h2 { font-size: 1.125rem; line-height: 1.3; }
h3 { font-size: 1rem;     line-height: 1.35; }

/* Hero/large title on mobile (iOS-style) */
.large-title {
  font-family: Inter, "Noto Sans TC", system-ui, sans-serif !important;
  font-weight: 800 !important;
  font-size: 26px !important;
  line-height: 1.15 !important;
  letter-spacing: -0.018em !important;
  color: var(--ink-1) !important;
}
.large-subtitle {
  font-family: Inter, "Noto Sans TC", sans-serif !important;
  font-size: 13px !important;
  color: var(--ink-3) !important;
  margin-top: 4px !important;
  font-weight: 400 !important;
}

/* Numerals: tabular monospace everywhere they appear */
.num, .font-mono, .tabular, [class*="font-mono"], code, kbd,
input[type="number"], input[type="date"], td.num, table .num {
  font-family: "JetBrains Mono", "SF Mono", "Consolas", monospace;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum", "zero", "ss02";
}

/* Section / column headers — small-caps technical labels */
table th {
  font-family: Inter, "Noto Sans TC", sans-serif;
  font-weight: 600;
  color: var(--ink-3);
  font-size: 11.5px;
  letter-spacing: 0.04em;
  background: var(--surface-2);
  border-bottom: 1px solid var(--rule) !important;
  text-align: left;
}
table td { color: var(--ink-2); }
table tfoot td {
  background: var(--surface-2);
  border-top: 1px solid var(--rule);
  font-weight: 600;
  color: var(--ink-1);
}
table { border-collapse: separate; border-spacing: 0; }
table tr:hover td:not(.no-hover) { background: var(--surface-2); }

/* Links */
a { color: var(--brand); text-decoration: none; }
a:hover { color: var(--brand-deep); text-decoration: underline; text-underline-offset: 3px; }

/* ============================================================
 * 3. TAILWIND OVERRIDES — bind markup to new tokens
 * ============================================================ */

/* Surfaces */
.bg-white          { background-color: var(--surface) !important; }
.bg-slate-50       { background-color: var(--canvas) !important; }
.bg-slate-100      { background-color: var(--surface-2) !important; }
.bg-slate-200      { background-color: var(--surface-3) !important; }
.bg-slate-900,
.bg-slate-800      { background-color: #0F172A !important; }
.bg-white\/95,
.bg-white\/90      { background-color: rgba(255, 255, 255, 0.92) !important; backdrop-filter: blur(8px); }

/* Borders */
.border-slate-100  { border-color: var(--rule-faint) !important; }
.border-slate-200,
.border-slate-300  { border-color: var(--rule) !important; }
.divide-slate-100 > * + * { border-top-color: var(--rule-faint) !important; }
.divide-slate-200 > * + * { border-top-color: var(--rule) !important; }

/* Text colors */
.text-slate-900    { color: var(--ink-1) !important; }
.text-slate-800,
.text-slate-700    { color: var(--ink-2) !important; }
.text-slate-600,
.text-slate-500    { color: var(--ink-3) !important; }
.text-slate-400    { color: var(--ink-4) !important; }
.text-slate-300    { color: var(--surface-4) !important; }
.text-white        { color: var(--ink-on-dark) !important; }

/* Blue family → brand */
.bg-blue-600,
.bg-blue-700                  { background-color: var(--brand) !important; color: #fff !important; }
.active\:bg-blue-700:active,
.hover\:bg-blue-700:hover     { background-color: var(--brand-deep) !important; }
.text-blue-600,
.text-blue-700,
.text-blue-800                { color: var(--brand) !important; }
.bg-blue-50,
.bg-blue-100                  { background-color: var(--brand-ghost) !important; }
.border-blue-200,
.border-blue-300,
.border-blue-400,
.border-blue-500              { border-color: var(--brand) !important; }
.focus\:ring-blue-500:focus   { box-shadow: 0 0 0 3px var(--brand-ring) !important; }

/* Green / emerald → success */
.bg-green-50,
.bg-emerald-50,
.bg-green-100,
.bg-emerald-100          { background-color: var(--success-ghost) !important; }
.bg-green-600,
.bg-green-700,
.active\:bg-green-700:active { background-color: var(--success) !important; color: #fff !important; }
.text-green-600,
.text-green-700,
.text-green-800,
.text-green-900,
.text-emerald-600,
.text-emerald-700        { color: var(--success-deep) !important; }
.border-green-200,
.border-emerald-200      { border-color: var(--success) !important; }

/* Red → danger */
.bg-red-50,
.bg-red-100              { background-color: var(--danger-ghost) !important; }
.bg-red-600,
.bg-red-700              { background-color: var(--danger) !important; color: #fff !important; }
.text-red-500,
.text-red-600,
.text-red-700,
.text-red-800            { color: var(--danger) !important; }
.border-red-200,
.border-red-300          { border-color: var(--danger) !important; }

/* Amber / yellow → warn */
.bg-amber-50,
.bg-amber-100,
.bg-yellow-50,
.bg-yellow-100           { background-color: var(--warn-ghost) !important; }
.bg-amber-500,
.bg-amber-600            { background-color: var(--warn) !important; color: #fff !important; }
.text-amber-500,
.text-amber-600,
.text-amber-700,
.text-amber-800,
.text-amber-900,
.text-yellow-700,
.text-yellow-800         { color: var(--warn-deep) !important; }
.border-amber-200,
.border-amber-300,
.border-yellow-200,
.border-yellow-300       { border-color: var(--warn) !important; }

/* Orange (退貨 family) → return / rust */
.bg-orange-50,
.bg-orange-100           { background-color: var(--return-ghost) !important; }
.bg-orange-600,
.bg-orange-700           { background-color: var(--return) !important; color: #fff !important; }
.text-orange-500,
.text-orange-600,
.text-orange-700,
.text-orange-800,
.text-orange-900         { color: var(--return) !important; }
.border-orange-200,
.border-orange-300,
.border-orange-400,
.border-orange-500       { border-color: var(--return) !important; }

/* Rose, indigo — fold into brand family */
.bg-rose-50              { background-color: var(--danger-ghost) !important; }
.text-rose-700           { color: var(--danger-deep) !important; }
.bg-indigo-50            { background-color: var(--brand-ghost) !important; }
.text-indigo-700         { color: var(--brand) !important; }

/* Inputs */
input, select, textarea {
  background: var(--surface) !important;
  border: 1px solid var(--rule) !important;
  color: var(--ink-1);
  border-radius: var(--r-md) !important;
  font-family: inherit;
  transition: border-color 100ms, box-shadow 100ms;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--brand) !important;
  box-shadow: 0 0 0 3px var(--brand-ring) !important;
}
input[type="checkbox"], input[type="radio"] { accent-color: var(--brand); }
input::placeholder, textarea::placeholder { color: var(--ink-4); }

/* Buttons — Tailwind utility classes get our radii */
button { font-family: inherit; }
[class*="rounded-lg"][class*="bg-"],
[class*="rounded-md"][class*="bg-"] {
  border-radius: var(--r-md) !important;
  transition: background-color 120ms, transform 80ms, box-shadow 120ms;
}
[class*="bg-blue-6"]:not(:disabled):active,
[class*="bg-blue-7"]:not(:disabled):active,
[class*="bg-green-6"]:not(:disabled):active,
[class*="bg-green-7"]:not(:disabled):active,
[class*="bg-red-6"]:not(:disabled):active,
[class*="bg-red-7"]:not(:disabled):active,
[class*="bg-orange-6"]:not(:disabled):active,
[class*="bg-orange-7"]:not(:disabled):active { transform: translateY(0.5px); }

/* Radii normalization */
.rounded, .rounded-md, .rounded-lg { border-radius: var(--r-md) !important; }
.rounded-xl, .rounded-2xl, .rounded-3xl { border-radius: var(--r-lg) !important; }
.rounded-full { border-radius: 9999px !important; }

/* Kill any leftover gradient backgrounds — Trade Console is flat */
[class*="bg-gradient"] { background-image: none !important; }

/* Shadows — restrained */
.shadow-sm, .shadow            { box-shadow: var(--shadow-xs) !important; }
.shadow-md                     { box-shadow: var(--shadow-sm) !important; }
.shadow-lg                     { box-shadow: var(--shadow-md) !important; }
.shadow-xl, .shadow-2xl        { box-shadow: var(--shadow-lg) !important; }

/* ============================================================
 * 4. LAYOUT PRIMITIVES
 * ============================================================ */
.pt-safe { padding-top: env(safe-area-inset-top); }
.pb-safe { padding-bottom: env(safe-area-inset-bottom); }
.pl-safe { padding-left: env(safe-area-inset-left); }
.pr-safe { padding-right: env(safe-area-inset-right); }
.tap-target { min-width: 44px; min-height: 44px; }
.tap-feedback {
  transition: transform 110ms ease, background-color 100ms ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.tap-feedback:active { transform: scale(0.97); }

/* ============================================================
 * 5. CARD — the workhorse surface
 * ============================================================ */
.card {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-xs);
}

/* ============================================================
 * 6. PILLS — status flags
 * ============================================================ */
.pill {
  display: inline-flex; align-items: center; gap: 0.25rem;
  padding: 2px 8px;
  border-radius: 3px;
  font-family: Inter, "Noto Sans TC", sans-serif;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.012em;
  line-height: 1.5;
  border: 1px solid transparent;
}
.pill-draft     { color: var(--ink-3);       background: var(--surface-2);   border-color: var(--rule); }
.pill-confirmed { color: var(--brand);       background: var(--brand-ghost); border-color: var(--brand-soft); }
.pill-success   { color: var(--success-deep);background: var(--success-ghost);border-color: var(--success-soft); }
.pill-warn      { color: var(--warn-deep);   background: var(--warn-ghost);  border-color: var(--warn-soft); }
.pill-danger    { color: var(--danger-deep); background: var(--danger-ghost);border-color: var(--danger-soft); }

/* ============================================================
 * 7. NAV
 * ============================================================ */
.nav-link {
  display: flex; align-items: center; gap: 0.625rem;
  padding: 6px 10px;
  border-radius: var(--r-sm);
  color: var(--ink-2);
  font-weight: 500;
  font-size: 13px;
  letter-spacing: -0.005em;
  transition: background 100ms, color 100ms;
}
.nav-link:hover { background: var(--surface-3); color: var(--ink-1); text-decoration: none; }
.nav-link.active {
  background: var(--brand-ghost);
  color: var(--brand);
  font-weight: 600;
}
.nav-link.active .nav-icon { color: var(--brand); }
.nav-icon { width: 18px; height: 18px; flex-shrink: 0; color: var(--ink-3); transition: color 100ms; }
.nav-link:hover .nav-icon { color: var(--ink-1); }

/* Bottom tab bar */
.bottom-tab {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 12px 6px;
  color: var(--ink-3);
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.02em;
  transition: color 120ms;
  position: relative;
}
.bottom-tab.active { color: var(--brand); }
.bottom-tab.active::before {
  content: ''; position: absolute; top: 0; left: 50%;
  width: 24px; height: 2px;
  background: var(--brand);
  transform: translateX(-50%);
  border-radius: 0 0 2px 2px;
}
.bottom-tab svg { transition: transform 140ms ease; }
.bottom-tab.active svg { transform: scale(1.06); }
.bottom-tab:active svg { transform: scale(0.93); }

.tab.active { background: var(--brand-ghost); color: var(--brand); }
.tab.active .tab-icon { color: var(--brand); }

/* ============================================================
 * 8. SIDEBAR — clean enterprise navigation panel
 * ============================================================ */
.app-sidebar {
  background: var(--surface) !important;
  color: var(--ink-2) !important;
  border-right: 1px solid var(--rule);
}
.app-sidebar-mast {
  padding: 16px 18px 14px;
  border-bottom: 1px solid var(--rule);
  background: var(--surface);
}
.app-sidebar-eyebrow {
  font-family: "JetBrains Mono", monospace;
  font-size: 9.5px;
  letter-spacing: 0.18em;
  color: var(--ink-4);
  font-weight: 500;
  text-transform: uppercase;
}
.app-sidebar-title {
  font-family: Inter, "Noto Sans TC", sans-serif;
  font-weight: 800;
  font-size: 22px;
  line-height: 1.1;
  letter-spacing: -0.02em;
  color: var(--ink-1);
  margin-top: 2px;
}
.app-sidebar-en {
  font-family: "JetBrains Mono", monospace;
  font-weight: 600;
  font-size: 9.5px;
  letter-spacing: 0.22em;
  color: var(--brand);
  margin-top: 4px;
  text-transform: uppercase;
}
.app-sidebar-rule { display: none; }   /* no decorative rule in Trade Console */
.app-sidebar-sub {
  font-size: 11.5px;
  color: var(--ink-3);
  letter-spacing: 0.01em;
  margin-top: 8px;
}

.app-nav-section {
  font-family: Inter, "Noto Sans TC", sans-serif;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.1em;
  color: var(--ink-4);
  padding: 8px 14px 4px;
  margin-top: 12px;
  text-transform: uppercase;
}

.app-sidebar .nav-link {
  color: var(--ink-2);
  margin: 0 8px;
  padding: 6px 10px;
  border-radius: var(--r-sm);
}
.app-sidebar .nav-link:hover { background: var(--surface-2); color: var(--ink-1); }
.app-sidebar .nav-link.active {
  background: var(--brand-ghost);
  color: var(--brand);
  font-weight: 600;
}
.app-sidebar .nav-link.active .nav-icon { color: var(--brand); }
.app-sidebar .nav-icon { color: var(--ink-3); }
.app-sidebar .nav-link:hover .nav-icon { color: var(--ink-1); }

.app-sidebar-foot {
  padding: 12px 16px;
  border-top: 1px solid var(--rule);
  background: var(--surface);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.app-sidebar-who {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-1);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.app-sidebar-role {
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
  letter-spacing: 0.08em;
  color: var(--ink-3);
  margin-top: 2px;
  text-transform: uppercase;
}
.app-sidebar-logout {
  font-family: Inter, "Noto Sans TC", sans-serif;
  font-size: 11.5px;
  font-weight: 500;
  color: var(--ink-3);
  padding: 5px 9px;
  border: 1px solid var(--rule);
  border-radius: var(--r-sm);
  background: transparent;
  transition: all 100ms;
}
.app-sidebar-logout:hover {
  color: var(--danger);
  border-color: var(--danger);
  background: var(--danger-ghost);
}

/* Mobile drawer backdrop */
.app-drawer-backdrop {
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(2px);
}

/* ============================================================
 * 9. MOBILE TOP BAR
 * ============================================================ */
.app-topbar {
  background: var(--surface) !important;
  border-bottom: 1px solid var(--rule);
  box-shadow: var(--shadow-xs);
}
.app-topbar-inner {
  height: 44px;
  display: flex; align-items: center; justify-content: center;
  position: relative;
}
.viewer-topbar-logout {
  position: absolute;
  right: 12px; top: 50%;
  transform: translateY(-50%);
  font-size: 12px;
  font-weight: 600;
  color: var(--danger);
  border: 1px solid var(--danger-soft);
  background: var(--danger-ghost);
  border-radius: var(--r-sm);
  padding: 4px 12px;
}
.viewer-topbar-logout:active { transform: translateY(-50%) scale(0.96); }
.app-topbar-mark {
  font-family: Inter, "Noto Sans TC", sans-serif;
  font-weight: 800;
  font-size: 15px;
  letter-spacing: -0.012em;
  color: var(--ink-1);
}

.app-bottombar {
  background: var(--surface) !important;
  border-top: 1px solid var(--rule);
  backdrop-filter: blur(8px);
  box-shadow: 0 -1px 2px rgba(15, 23, 42, 0.04);
}

/* FAB — brand prussian, restrained */
.app-fab {
  margin-top: -24px;
  width: 52px; height: 52px;
  background: var(--brand);
  color: #fff;
  border: none;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  box-shadow:
    0 0 0 3px var(--surface),
    0 6px 16px rgba(15, 23, 42, 0.18);
  transition: background 120ms, transform 90ms, box-shadow 120ms;
}
.app-fab:active {
  background: var(--brand-deep);
  transform: translateY(1px) scale(0.97);
  box-shadow:
    0 0 0 3px var(--surface),
    0 2px 4px rgba(15, 23, 42, 0.2);
}

/* ============================================================
 * 10. SHEETS / DIALOG / TOAST
 * ============================================================ */
.sheet-backdrop {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, 0.45);
  z-index: 70;
  animation: backdrop-in 180ms ease-out;
}
.sheet-backdrop.closing { animation: backdrop-out 160ms ease-in forwards; }
.sheet-panel {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: var(--surface);
  border-top: 1px solid var(--rule);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  max-height: 80vh; overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: sheet-in 260ms cubic-bezier(0.32, 0.72, 0, 1);
}
.sheet-backdrop.closing .sheet-panel { animation: sheet-out 200ms cubic-bezier(0.32, 0.72, 0, 1) forwards; }
.sheet-handle {
  width: 36px; height: 4px;
  background: var(--surface-4);
  border-radius: 2px;
  margin: 8px auto 0;
}
@keyframes backdrop-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes backdrop-out { to { opacity: 0; } }
@keyframes sheet-in  { from { transform: translateY(100%); } to { transform: translateY(0); } }
@keyframes sheet-out { to { transform: translateY(100%); } }

.sheet-action {
  display: flex; flex-direction: column; align-items: center;
  padding: 14px 8px;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r-md);
  color: var(--ink-1);
  font-size: 12px; font-weight: 500;
  transition: background 100ms, border-color 100ms;
}
.sheet-action:active { background: var(--surface-2); border-color: var(--rule-strong); transform: translateY(0.5px); }
.action-icon {
  width: 44px; height: 44px;
  border-radius: var(--r-md);
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 4px;
}

/* Dialog */
.dialog-backdrop {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, 0.55);
  z-index: 75;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  animation: backdrop-in 160ms ease-out;
}
.dialog-backdrop.closing { animation: backdrop-out 140ms ease-in forwards; }
.dialog-backdrop > div {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  max-width: 520px;
  width: 100%;
  max-height: 88vh;
  display: flex; flex-direction: column;
  animation: dialog-in 200ms cubic-bezier(0.32, 0.72, 0, 1);
}
.dialog-backdrop.closing > div { animation: dialog-out 180ms cubic-bezier(0.32, 0.72, 0, 1) forwards; }
@keyframes dialog-in  { from { opacity: 0; transform: scale(0.97) translateY(4px); } to { opacity: 1; transform: scale(1) translateY(0); } }
@keyframes dialog-out { to { opacity: 0; transform: scale(0.98) translateY(2px); } }
@media (max-width: 767px) {
  .dialog-backdrop { padding: 0; align-items: flex-end; }
  .dialog-backdrop > div { max-width: 100%; max-height: 92vh; border-radius: var(--r-lg) var(--r-lg) 0 0; }
}

/* Toast */
#toast-host {
  position: fixed;
  bottom: max(env(safe-area-inset-bottom), 16px); left: 50%;
  transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px;
  z-index: 90; width: min(420px, calc(100% - 32px));
}
.toast {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-left: 3px solid var(--ink-3);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-md);
  font-size: 13px;
  color: var(--ink-1);
  animation: toast-in 200ms cubic-bezier(0.32, 0.72, 0, 1);
}
.toast.toast-out { animation: toast-out 150ms ease-in forwards; }
.toast-info    { border-left-color: var(--brand); }
.toast-success { border-left-color: var(--success); }
.toast-warn    { border-left-color: var(--warn); }
.toast-error   { border-left-color: var(--danger); }
.toast-icon    { width: 18px; height: 18px; flex-shrink: 0; margin-top: 1px; color: var(--ink-2); }
.toast-info .toast-icon    { color: var(--brand); }
.toast-success .toast-icon { color: var(--success); }
.toast-warn .toast-icon    { color: var(--warn); }
.toast-error .toast-icon   { color: var(--danger); }
.toast-close { margin-left: auto; padding: 0 .25rem; color: var(--ink-3); font-size: 1.125rem; line-height: 1; }
.toast-close:hover { color: var(--ink-1); }
@keyframes toast-in  { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(8px); } }

/* ============================================================
 * 11. STATE — busy / spinner / skeleton
 * ============================================================ */
.btn-busy { position: relative; pointer-events: none; opacity: 0.72; }
.btn-busy::after { content: ''; position: absolute; inset: 0; border-radius: inherit; background: var(--ink-1); opacity: 0.06; }
.spinner {
  display: inline-block; width: 14px; height: 14px;
  border: 2px solid currentColor; border-right-color: transparent;
  border-radius: 50%;
  animation: spin 700ms linear infinite;
  vertical-align: -2px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.skeleton {
  background: linear-gradient(90deg, var(--surface-2) 0%, var(--surface-3) 50%, var(--surface-2) 100%);
  background-size: 200% 100%;
  animation: skeleton 1.4s ease-in-out infinite;
  border-radius: 3px;
}
@keyframes skeleton { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ============================================================
 * 12. LIST CARD
 * ============================================================ */
.list-card {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r-md);
  padding: 12px;
  transition: transform 110ms, background 100ms, border-color 100ms;
  box-shadow: var(--shadow-xs);
}
.list-card:active { transform: scale(0.99); background: var(--surface-2); border-color: var(--rule-strong); }

/* ============================================================
 * 13. PTR
 * ============================================================ */
.ptr-indicator {
  position: fixed; top: 0; left: 50%;
  transform: translate(-50%, -40px);
  display: flex; align-items: center; gap: 6px;
  padding: 6px 12px;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r-md);
  font-size: 12px;
  color: var(--ink-2);
  z-index: 60;
  transition: transform 220ms cubic-bezier(0.32, 0.72, 0, 1);
  box-shadow: var(--shadow-sm);
}
.ptr-indicator.visible { transform: translate(-50%, 60px); }
.ptr-indicator.spinning .ptr-arrow { animation: spin 700ms linear infinite; }
.ptr-arrow { width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; }

/* ============================================================
 * 14. SCAN — confirm overlay + running total + mode pills
 *     Personality concentration: keep this strong, the rest sober.
 * ============================================================ */
.scan-confirm {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--success);
  color: #fff;
  z-index: 95;
  flex-direction: column; gap: 8px;
  animation: stamp-in 180ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
.scan-confirm.error { background: var(--danger); }
.scan-confirm.warn  { background: var(--warn); }
.scan-confirm.info  { background: var(--brand); }
@keyframes stamp-in {
  from { opacity: 0; transform: scale(0.97); }
  to   { opacity: 1; transform: scale(1); }
}
.scan-confirm-title {
  font-family: Inter, "Noto Sans TC", sans-serif;
  font-weight: 800;
  font-size: clamp(28px, 8vw, 48px);
  letter-spacing: -0.014em;
  text-align: center;
  padding: 0 24px;
}
.scan-confirm-sub {
  font-family: Inter, "Noto Sans TC", sans-serif;
  font-size: 0.95rem;
  opacity: 0.95;
  letter-spacing: 0.01em;
}

/* Sticky running-total bar */
.scan-running-total {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 18px;
  background: var(--ink-1);
  color: var(--ink-on-dark);
  border-top: 1px solid var(--brand-deep);
  border-bottom: 1px solid var(--brand-deep);
}
.scan-running-total .qty-big {
  font-family: "JetBrains Mono", monospace;
  font-weight: 700;
  font-size: 30px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.018em;
  color: #fff;
}
.scan-running-total .amount {
  font-family: "JetBrains Mono", monospace;
  font-weight: 500;
  font-size: 18px;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  color: rgba(255, 255, 255, 0.78);
}

/* Mode pill — segmented control feel */
.mode-pill {
  display: inline-flex; align-items: center; gap: 0.375rem;
  padding: 6px 12px;
  border: 1px solid var(--rule);
  background: var(--surface);
  color: var(--ink-3);
  font-family: Inter, "Noto Sans TC", sans-serif;
  font-size: 12.5px;
  font-weight: 500;
  letter-spacing: 0;
  border-radius: var(--r-md);
  touch-action: manipulation;
  transition: all 120ms;
}
.mode-pill:active { transform: scale(0.97); }
.mode-pill.active-query   { background: var(--surface-2);    color: var(--ink-1);       border-color: var(--rule-strong); font-weight: 600; }
.mode-pill.active-ship    { background: var(--success-ghost); color: var(--success-deep);border-color: var(--success);    font-weight: 600; }
.mode-pill.active-receive { background: var(--rust-ghost);    color: var(--rust-deep);   border-color: var(--rust);       font-weight: 600; }
.mode-pill.active-return  { background: var(--return-ghost);  color: var(--return);      border-color: var(--return);     font-weight: 600; }

/* Long-press submit */
.long-press { position: relative; overflow: hidden; isolation: isolate; }
.long-press::after {
  content: '';
  position: absolute; left: 0; top: 0; bottom: 0;
  background: rgba(255, 255, 255, 0.22);
  width: 0;
  transition: width 0ms linear;
  pointer-events: none;
  z-index: 0;
}
.long-press.pressing::after { width: 100%; transition: width 900ms linear; }
.long-press > * { position: relative; z-index: 1; }

/* qty-cell */
.qty-cell {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 36px; padding: 4px 10px;
  background: var(--surface-2);
  border: 1px solid var(--rule);
  border-radius: var(--r-sm);
  font-family: "JetBrains Mono", monospace;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: background 100ms;
}
.qty-cell:active { background: var(--surface-3); }

/* Swipe-to-delete */
.swipe-row {
  position: relative;
  background: var(--surface);
  transition: transform 200ms cubic-bezier(0.32, 0.72, 0, 1), background 100ms;
  touch-action: pan-y;
}
.swipe-row.swiping { transition: none; }
.swipe-row::after {
  content: '刪除';
  position: absolute; right: 0; top: 0; bottom: 0;
  width: 88px;
  background: var(--danger);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-family: Inter, "Noto Sans TC", sans-serif;
  font-weight: 600;
  letter-spacing: 0.04em;
  transform: translateX(100%);
  transition: transform 220ms cubic-bezier(0.32, 0.72, 0, 1);
  z-index: -1;
}
.swipe-row.swiping-armed::after,
.swipe-row.swiping::after { transform: translateX(0); }

/* Numpad */
.numpad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.numpad button {
  font-family: "JetBrains Mono", monospace;
  font-size: 21px;
  font-weight: 600;
  padding: 13px 0;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r-md);
  color: var(--ink-1);
  transition: background 100ms, transform 80ms;
}
.numpad button:active { background: var(--surface-2); transform: translateY(0.5px); }
.numpad button.numpad-action {
  background: var(--danger-ghost);
  color: var(--danger);
  border-color: var(--danger-soft);
}

/* Ripple */
.ripple { position: relative; overflow: hidden; }
.ripple-effect {
  position: absolute;
  border-radius: 50%;
  pointer-events: none;
  background: rgba(29, 53, 87, 0.12);
  animation: ripple 600ms ease-out;
}
@keyframes ripple {
  0%   { transform: scale(0); opacity: 0.5; }
  100% { transform: scale(2.4); opacity: 0; }
}

/* ============================================================
 * 14b. SCAN WORK-CONSOLE — the 3-zone scan page architecture
 *      Mode color paints header band, input ring, and submit CTA.
 * ============================================================ */

.scan-frame {
  /* On mobile we leave space at bottom for the fixed action bar */
  padding-bottom: 0;
  position: relative;
}
@media (max-width: 767px) {
  /* Reserve room for fixed action bar (≈68px) + bottom-tab (64px) + safe-area */
  .scan-frame { padding-bottom: calc(68px + 64px + env(safe-area-inset-bottom)); }
}

/* ---- Header band — mode-colored, slim ---- */
.scan-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px;
  border: 1px solid var(--rule);
  border-bottom-width: 3px;
  border-radius: var(--r-md);
  background: var(--surface);
  margin-bottom: 10px;
  gap: 12px;
  flex-wrap: wrap;
}
.scan-header-title {
  display: flex; align-items: center; gap: 10px;
  font-size: 15px;
  font-weight: 700;
  color: var(--ink-1);
  letter-spacing: -0.011em;
}
.scan-header-title .mode-mark {
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.14em;
  padding: 2px 7px;
  border-radius: 2px;
  text-transform: uppercase;
}
.scan-header-meta {
  display: flex; align-items: center; gap: 10px;
  font-size: 12px;
  color: var(--ink-3);
}
.scan-pda-toggle {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11.5px;
  color: var(--ink-2);
  padding: 4px 8px;
  border: 1px solid var(--rule);
  border-radius: var(--r-sm);
  background: var(--surface);
  white-space: nowrap;
}
.scan-pda-toggle input { margin: 0; }

/* ---- Scan input zone — big, mode-ringed ---- */
.scan-input-zone {
  display: flex; align-items: stretch; gap: 8px;
  margin-bottom: 8px;
}
.scan-input-zone .scan-input {
  flex: 1;
  font-family: "JetBrains Mono", monospace;
  font-size: 15px;
  letter-spacing: 0.01em;
  padding: 12px 14px !important;
  border: 1px solid var(--rule) !important;
  border-radius: var(--r-md) !important;
  background: var(--surface) !important;
  color: var(--ink-1);
}
.scan-input-zone .scan-clear {
  padding: 0 14px;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r-md);
  color: var(--ink-2);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  transition: all 100ms;
}
.scan-input-zone .scan-clear:hover { background: var(--surface-2); color: var(--ink-1); }
.scan-input-zone .scan-clear:active { transform: translateY(0.5px); }

.scan-status {
  font-size: 12px;
  color: var(--ink-3);
  font-family: "JetBrains Mono", monospace;
  min-height: 16px;
  margin: -2px 0 10px;
  padding: 0 2px;
  word-break: break-all;
}

/* ---- Ticker — sticky running totals ---- */
.scan-ticker {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 12px 18px;
  background: var(--ink-1);
  color: #fff;
  border-radius: var(--r-md);
  margin-bottom: 12px;
  gap: 8px;
}
.scan-ticker .ticker-stat { display: flex; flex-direction: column; gap: 4px; }
.scan-ticker .ticker-label {
  font-family: Inter, "Noto Sans TC", sans-serif;
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.12em;
  color: rgba(255, 255, 255, 0.62);
  text-transform: uppercase;
}
.scan-ticker .ticker-value {
  font-family: "JetBrains Mono", monospace;
  font-weight: 700;
  font-size: 26px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.022em;
  color: #fff;
}
.scan-ticker .ticker-stat:last-child .ticker-value { color: rgba(255, 255, 255, 0.85); }
.scan-ticker .ticker-stat:last-child { text-align: right; align-items: flex-end; }
@media (min-width: 768px) {
  .scan-ticker { grid-template-columns: repeat(4, 1fr); }
  .scan-ticker .ticker-stat:last-child { text-align: left; align-items: flex-start; }
}

/* ---- List zone — table on desktop, cards on mobile ---- */
.scan-list-table {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r-md);
  overflow: hidden;
  margin-bottom: 12px;
}
.scan-list-table table { width: 100%; font-size: 13.5px; }
.scan-list-table th { padding: 10px 14px; }
.scan-list-table td { padding: 11px 14px; border-bottom: 1px solid var(--rule-faint); }
.scan-list-table tr:last-child td { border-bottom: none; }
.scan-list-table .qty-controls { display: inline-flex; align-items: center; gap: 6px; }
.scan-list-table .qty-btn {
  width: 30px; height: 30px;
  border: 1px solid var(--rule);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--ink-1);
  font-family: "JetBrains Mono", monospace;
  font-weight: 700;
  line-height: 1;
  transition: all 100ms;
}
.scan-list-table .qty-btn:hover { border-color: var(--rule-strong); background: var(--surface-2); }
.scan-list-table .qty-btn:active { transform: translateY(0.5px); }

.scan-list-cards { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.scan-card {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r-md);
  padding: 10px 12px;
  box-shadow: var(--shadow-xs);
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px 12px;
  align-items: center;
}
.scan-card-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--ink-1);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.scan-card-meta {
  font-family: "JetBrains Mono", monospace;
  font-size: 11.5px;
  color: var(--ink-3);
  letter-spacing: 0.012em;
}
.scan-card-sub {
  text-align: right;
  font-family: "JetBrains Mono", monospace;
  font-weight: 600;
  font-size: 15px;
  color: var(--ink-1);
  font-variant-numeric: tabular-nums;
}
.scan-card-controls {
  grid-column: 1 / -1;
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px;
  margin-top: 6px;
  padding-top: 8px;
  border-top: 1px solid var(--rule-faint);
}
.scan-card-controls .qty-grp { display: inline-flex; align-items: center; gap: 8px; }
.scan-card-controls .qty-btn {
  width: 36px; height: 36px;
  border-radius: var(--r-sm);
  font-size: 18px;
  font-family: "JetBrains Mono", monospace;
  font-weight: 700;
  line-height: 1;
  border: 1px solid var(--rule);
  background: var(--surface);
  color: var(--ink-1);
}
.scan-card-controls .qty-btn:active { transform: translateY(0.5px); }
.scan-card-controls .qty-btn.minus { background: var(--danger-ghost); color: var(--danger); border-color: var(--danger-soft); }
.scan-card-controls .qty-btn.plus  { background: var(--success-ghost); color: var(--success-deep); border-color: var(--success-soft); }
.scan-card-controls .rm-btn {
  background: transparent;
  color: var(--ink-3);
  font-size: 18px;
  width: 36px; height: 36px;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
}
.scan-card-controls .rm-btn:hover { color: var(--danger); border-color: var(--danger-soft); }
.scan-list-cards .empty-state {
  padding: 32px 16px;
  text-align: center;
  font-size: 13px;
  color: var(--ink-4);
  background: var(--surface);
  border: 1px dashed var(--rule-strong);
  border-radius: var(--r-md);
}

/* ---- Meta — collapsible details for date/note/attachments ---- */
.scan-meta {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r-md);
  margin-bottom: 8px;
  box-shadow: var(--shadow-xs);
}
.scan-meta > summary {
  list-style: none;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-2);
  user-select: none;
}
.scan-meta > summary::-webkit-details-marker { display: none; }
.scan-meta > summary .chev {
  width: 16px; height: 16px;
  transition: transform 160ms;
  color: var(--ink-3);
}
.scan-meta[open] > summary .chev { transform: rotate(180deg); }
.scan-meta[open] > summary { border-bottom: 1px solid var(--rule); }
.scan-meta-body { padding: 12px 14px 14px; }

/* ---- Banner-style chips between zones ---- */
.scan-banner {
  padding: 9px 12px;
  border-radius: var(--r-md);
  font-size: 12.5px;
  color: var(--ink-2);
  margin-bottom: 10px;
  display: flex; align-items: center; gap: 8px;
}
.scan-banner.banner-info {  background: var(--brand-ghost);   border: 1px solid var(--brand-soft);   color: var(--brand-deep); }
.scan-banner.banner-rust {  background: var(--rust-ghost);    border: 1px solid var(--rust-soft);    color: var(--rust-deep); }
.scan-banner.banner-return {background: var(--return-ghost);  border: 1px solid var(--return-soft);  color: var(--return); }

/* ---- Bind-tracking button — secondary CTA ---- */
.scan-bind-tracking {
  width: 100%;
  margin-bottom: 8px;
  padding: 11px 14px;
  background: var(--surface);
  border: 1px dashed var(--rust);
  border-radius: var(--r-md);
  color: var(--rust-deep);
  font-weight: 500;
  font-size: 13px;
  transition: all 120ms;
}
.scan-bind-tracking.bound {
  background: var(--rust-ghost);
  border-style: solid;
  color: var(--rust-deep);
  font-weight: 600;
}
.scan-bind-tracking:hover { background: var(--rust-ghost); }

/* ---- Bottom action bar — sticky on desktop, fixed on mobile ---- */
.scan-actions {
  display: flex; align-items: center; justify-content: flex-end;
  gap: 8px;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r-md);
  margin-top: 8px;
}
.scan-actions .scan-action-cancel {
  padding: 10px 16px;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r-md);
  color: var(--ink-2);
  font-size: 13.5px;
  font-weight: 500;
  transition: all 100ms;
}
.scan-actions .scan-action-cancel:hover { background: var(--surface-2); color: var(--ink-1); }
.scan-actions .scan-action-submit {
  flex: 1; max-width: 320px;
  padding: 11px 18px;
  background: var(--brand);
  color: #fff;
  border: none;
  border-radius: var(--r-md);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.02em;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: background 100ms, transform 80ms;
}
.scan-actions .scan-action-submit:active { transform: translateY(0.5px); }
@media (max-width: 767px) {
  .scan-actions {
    position: fixed;
    left: 0; right: 0;
    bottom: calc(64px + env(safe-area-inset-bottom));   /* above bottom-tab bar */
    margin: 0;
    border-radius: 0;
    border-left: none; border-right: none; border-bottom: none;
    border-top: 1px solid var(--rule);
    box-shadow: 0 -4px 12px rgba(15, 23, 42, 0.06);
    z-index: 30;
  }
  .scan-actions .scan-action-submit { flex: 1; max-width: none; }
}

/* ---- Mode color theming ---- */
/* SHIP — green */
.scan-frame.mode-ship .scan-header { border-bottom-color: var(--success); background: var(--success-ghost); }
.scan-frame.mode-ship .scan-header-title { color: var(--success-deep); }
.scan-frame.mode-ship .scan-header-title .mode-mark { background: var(--success); color: #fff; }
.scan-frame.mode-ship .scan-input:focus { border-color: var(--success) !important; box-shadow: 0 0 0 3px rgba(4, 120, 87, 0.18) !important; }
.scan-frame.mode-ship .scan-action-submit { background: var(--success); }
.scan-frame.mode-ship .scan-action-submit:active { background: var(--success-deep); }

/* RECEIVE — rust */
.scan-frame.mode-receive .scan-header { border-bottom-color: var(--rust); background: var(--rust-ghost); }
.scan-frame.mode-receive .scan-header-title { color: var(--rust-deep); }
.scan-frame.mode-receive .scan-header-title .mode-mark { background: var(--rust); color: #fff; }
.scan-frame.mode-receive .scan-input:focus { border-color: var(--rust) !important; box-shadow: 0 0 0 3px rgba(180, 83, 9, 0.18) !important; }
.scan-frame.mode-receive .scan-action-submit { background: var(--rust); }
.scan-frame.mode-receive .scan-action-submit:active { background: var(--rust-deep); }

/* RETURN — return-orange */
.scan-frame.mode-return .scan-header { border-bottom-color: var(--return); background: var(--return-ghost); }
.scan-frame.mode-return .scan-header-title { color: var(--return); }
.scan-frame.mode-return .scan-header-title .mode-mark { background: var(--return); color: #fff; }
.scan-frame.mode-return .scan-input:focus { border-color: var(--return) !important; box-shadow: 0 0 0 3px rgba(194, 65, 12, 0.18) !important; }
.scan-frame.mode-return .scan-action-submit { background: var(--return); }
.scan-frame.mode-return .scan-action-submit:active { background: var(--return); filter: brightness(0.88); }

/* ============================================================
 * 15. STRICT-MODE LOCK — clear, sober, professional notice
 * ============================================================ */
#qx-strict-lock {
  background: var(--return-ghost) !important;
  border: 1px solid var(--return) !important;
  border-left: 4px solid var(--return) !important;
  border-radius: var(--r-md);
  padding: 20px 16px !important;
}
#qx-strict-lock svg { color: var(--return) !important; }

/* ============================================================
 * 16. LOGIN PAGE — sober shopfront
 * ============================================================ */
.login-page {
  background:
    radial-gradient(ellipse 70% 50% at 50% 20%, var(--surface) 0%, var(--canvas) 60%),
    var(--canvas);
  position: relative;
}
.login-page::before { display: none; }   /* no decorative blob */
.login-frame { position: relative; z-index: 1; }

.login-masthead { text-align: center; margin-bottom: 28px; }
.login-logo {
  display: block;
  width: 96px;
  height: 96px;
  object-fit: contain;
  margin: 0 auto 14px;
  filter: drop-shadow(0 4px 10px rgba(15, 23, 42, 0.18));
}
.app-sidebar-logo {
  display: block;
  width: 64px;
  height: 64px;
  object-fit: contain;
  margin: 0 auto 10px;
}
.login-eyebrow {
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
  letter-spacing: 0.22em;
  color: var(--ink-3);
  margin-bottom: 12px;
  text-transform: uppercase;
}
.login-title {
  font-family: Inter, "Noto Sans TC", sans-serif;
  font-weight: 800;
  font-size: clamp(34px, 7vw, 44px);
  line-height: 1.05;
  letter-spacing: -0.025em;
  color: var(--ink-1);
  margin: 0;
}
.login-title-en {
  display: block;
  font-family: "JetBrains Mono", monospace;
  font-weight: 600;
  font-size: 10.5px;
  letter-spacing: 0.28em;
  color: var(--brand);
  margin-top: 12px;
  text-transform: uppercase;
}
.login-rule {
  width: 36px; height: 2px;
  background: var(--brand);
  margin: 16px auto 12px;
  border-radius: 1px;
}
.login-tagline {
  font-family: Inter, "Noto Sans TC", sans-serif;
  font-size: 13px;
  color: var(--ink-3);
  letter-spacing: 0.08em;
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r-lg);
  padding: 28px 24px 20px;
  box-shadow: var(--shadow-md);
  position: relative;
}
.login-card::before { display: none; }    /* no inner double rule */
.login-card > * { position: relative; z-index: 1; }
.login-label {
  display: block;
  font-family: Inter, "Noto Sans TC", sans-serif;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--ink-3);
  text-transform: uppercase;
  margin-bottom: 6px;
}
.login-input {
  width: 100%;
  padding: 10px 12px;
  background: var(--surface) !important;
  border: 1px solid var(--rule) !important;
  border-radius: var(--r-md) !important;
  font-size: 14.5px;
  color: var(--ink-1);
  font-family: Inter, "Noto Sans TC", sans-serif;
}
.login-input:focus {
  outline: none;
  border-color: var(--brand) !important;
  box-shadow: 0 0 0 3px var(--brand-ring) !important;
}
.login-submit {
  margin-top: 4px;
  width: 100%;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px;
  background: var(--brand);
  color: #fff;
  border: none;
  border-radius: var(--r-md);
  font-family: Inter, "Noto Sans TC", sans-serif;
  font-weight: 600;
  font-size: 14px;
  letter-spacing: 0.04em;
  transition: background 120ms, transform 80ms;
  box-shadow: var(--shadow-xs);
}
.login-submit:hover { background: var(--brand-hover); }
.login-submit:active { transform: translateY(0.5px); background: var(--brand-deep); }
.login-error {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--danger-deep);
  padding: 8px 10px;
  background: var(--danger-ghost);
  border-left: 3px solid var(--danger);
  border-radius: var(--r-sm);
}
.login-foot {
  margin-top: 24px;
  text-align: center;
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
  letter-spacing: 0.12em;
  color: var(--ink-4);
  text-transform: uppercase;
}
.login-foot-sep { color: var(--rule-strong); margin: 0 0.4em; }

/* ============================================================
 * Product thumbnails — list rows + card + scan result + dialog
 * ============================================================ */
.product-thumb {
  width: 40px; height: 40px;
  object-fit: cover;
  border-radius: var(--r-sm);
  background: var(--surface-2);
  border: 1px solid var(--rule);
  display: block;
  flex-shrink: 0;
}
.product-thumb-lg {
  width: 96px; height: 96px;
  object-fit: cover;
  border-radius: var(--r-md);
  background: var(--surface-2);
  border: 1px solid var(--rule);
  display: block;
  flex-shrink: 0;
}
.product-thumb-empty {
  position: relative;
  background:
    linear-gradient(135deg, transparent 47%, var(--rule) 47%, var(--rule) 53%, transparent 53%),
    var(--surface-2);
}
/* Image that failed to load after retries — show a neutral placeholder instead of broken-img icon */
img.thumb-failed {
  background: var(--surface-2);
  position: relative;
}
img.thumb-failed::after {
  content: '圖';
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: var(--ink-4); font-size: 12px;
  background: var(--surface-2);
}
.product-thumb-empty::after {
  /* small dimensional cue — Material image-placeholder vibe */
  content: '';
  position: absolute;
  top: 50%; left: 50%;
  width: 38%; height: 26%;
  border: 1.5px solid var(--rule-strong);
  border-radius: 2px;
  transform: translate(-50%, -50%);
}

/* ============================================================
 * Mini camera scanner — small floating viewfinder for quickX pages
 * ============================================================ */
.scan-cam-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 44px;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r-md);
  color: var(--ink-2);
  flex-shrink: 0;
  transition: all 100ms;
}
.scan-cam-btn:hover { background: var(--surface-2); color: var(--ink-1); }
.scan-cam-btn:active { transform: translateY(0.5px); }
.scan-cam-btn.active { background: var(--brand-ghost); color: var(--brand); border-color: var(--brand); }
.scan-cam-btn svg { width: 20px; height: 20px; }

.scan-cam-popover {
  position: fixed;
  z-index: 65;
  width: 240px;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
@media (min-width: 768px) {
  .scan-cam-popover { right: 24px; bottom: 24px; }
}
@media (max-width: 767px) {
  /* Above bottom-tab bar and scan-actions on mobile, right edge */
  .scan-cam-popover { right: 8px; bottom: calc(64px + 68px + env(safe-area-inset-bottom) + 8px); }
}
.scan-cam-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 10px;
  background: var(--ink-1);
  color: #fff;
  font-family: Inter, "Noto Sans TC", sans-serif;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.06em;
}
.scan-cam-header button {
  color: rgba(255,255,255,0.75);
  background: transparent;
  border: none;
  font-size: 18px;
  line-height: 1;
  padding: 2px 6px;
}
.scan-cam-header button:hover { color: #fff; }
.scan-cam-viewfinder {
  width: 240px;
  height: 200px;
  background: #000;
  position: relative;
  overflow: hidden;
}
.scan-cam-viewfinder video {
  width: 100% !important;
  height: 100% !important;
  object-fit: cover;
}
.scan-cam-hint {
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
  color: var(--ink-3);
  text-align: center;
  padding: 4px 6px 6px;
  letter-spacing: 0.04em;
}
.scan-cam-flash {
  position: absolute; inset: 0;
  background: rgba(76, 175, 80, 0.45);
  pointer-events: none;
  animation: scan-cam-flash 220ms ease-out;
}
@keyframes scan-cam-flash {
  from { opacity: 1; } to { opacity: 0; }
}

/* ============================================================
 * Inventory: view-mode switcher (全部商品 / 依貨架)
 * ============================================================ */
.inv-view-switch { background: var(--surface); }
.inv-view-btn {
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-3);
  background: var(--surface);
  border: none;
  border-right: 1px solid var(--rule);
  transition: all 100ms;
  font-family: inherit;
  white-space: nowrap;
}
.inv-view-btn:last-child { border-right: none; }
.inv-view-btn:hover { background: var(--surface-2); color: var(--ink-1); }
.inv-view-btn.active {
  background: var(--brand);
  color: #fff;
  font-weight: 600;
}

/* ============================================================
 * Inventory: UNCAT (未分類) highlighting
 * ============================================================ */
.uncat-row td { background: rgba(180, 83, 9, 0.04); }
.uncat-row:hover td { background: var(--warn-ghost) !important; }
.uncat-card { border-left: 3px solid var(--warn); background: rgba(180, 83, 9, 0.03); }

/* ============================================================
 * 17. SCROLLBAR
 * ============================================================ */
* { scrollbar-width: thin; scrollbar-color: var(--surface-4) transparent; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: var(--surface-4);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
*::-webkit-scrollbar-thumb:hover { background: var(--ink-4); background-clip: padding-box; }

/* ============================================================
 * 18. PRINT
 * ============================================================ */
@media print {
  body { background: white; }
  .nav-link, .bottom-tab, .sheet-backdrop, .dialog-backdrop, #toast-host, .scan-confirm, .app-topbar, .app-bottombar, .app-sidebar { display: none !important; }
}

/* ============================================================
 * 19. MOTION REDUCE
 * ============================================================ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
