:root {
  color-scheme: dark;
  --bg: #050b14;
  --surface: rgba(13, 27, 44, 0.94);
  --line: #28415f;
  --line-bright: #3d6da6;
  --text: #f3f7fd;
  --muted: #93a4b9;
  --primary: #3c6df2;
  --cyan: #30d5d2;
  --teal: #2ec5a7;
  --amber: #f0a43a;
  --red: #ed5a5f;
  --shadow: 0 20px 52px rgba(0, 0, 0, 0.34);
  font-family: Inter, "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { width: 100%; max-width: 100%; min-height: 100%; overflow-x: clip; background: var(--bg); }
body { min-height: 100vh; margin: 0; background: radial-gradient(circle at 50% -20%, rgba(42, 87, 156, 0.18), transparent 40%), var(--bg); color: var(--text); overscroll-behavior-x: none; }
#app, .app-shell { width: 100%; max-width: 100%; min-width: 0; }
button, input, select { font: inherit; letter-spacing: 0; }
button { color: inherit; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid #64a5ff; outline-offset: 2px; }

.app-shell { min-height: 100vh; overflow-x: clip; padding-bottom: 84px; }
.topbar { position: sticky; z-index: 20; top: 0; width: 100%; max-width: 100%; min-width: 0; display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 68px; padding: 10px max(18px, env(safe-area-inset-right)) 10px max(18px, env(safe-area-inset-left)); border-bottom: 1px solid rgba(74, 112, 158, 0.38); background: rgba(5, 12, 22, 0.92); backdrop-filter: blur(16px); }
.brand { display: flex; align-items: center; min-width: 0; gap: 10px; }
.brand-mark { position: relative; flex: 0 0 44px; width: 44px; height: 44px; overflow: hidden; border: 1px solid rgba(74, 135, 207, 0.62); border-radius: 6px; background: linear-gradient(145deg, rgba(27, 64, 104, 0.62), rgba(6, 20, 35, 0.92)); box-shadow: inset 0 0 14px rgba(53, 119, 215, 0.14), 0 0 8px rgba(53, 130, 235, 0.08); }
.brand-mark img { position: absolute; width: 68px; height: 68px; left: 50%; top: 50%; transform: translate(-50%, -47%); object-fit: contain; filter: drop-shadow(0 3px 5px rgba(0, 0, 0, 0.22)); }
.brand-text { min-width: 0; }
.brand-name, .brand-context { margin: 0; }
.brand-name { font-weight: 800; }
.brand-context { margin-top: 2px; color: var(--muted); font-size: 0.72rem; }
.topbar-actions, .header-actions, .modal-actions { min-width: 0; display: flex; align-items: center; gap: 9px; }
.user-chip { color: #b8c8dc; font-size: 0.82rem; }

.page { width: 100%; max-width: 1080px; min-width: 0; margin: 0 auto; padding: 24px max(18px, env(safe-area-inset-right)) 34px max(18px, env(safe-area-inset-left)); }
.page-header { min-width: 0; display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 22px; }
.page-header > *, .section-heading > *, .task-entry > *, .task-row > *, .product-row > *, .recent-row > * { min-width: 0; max-width: 100%; }
.page-title { max-width: 100%; margin: 4px 0 0; overflow-wrap: anywhere; font-size: clamp(1.4rem, 3vw, 2rem); line-height: 1.2; }
.page-subtitle { max-width: 100%; margin: 7px 0 0; overflow-wrap: anywhere; color: var(--muted); font-size: 0.88rem; line-height: 1.55; }
.section { margin-top: 22px; }
.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.section-title { margin: 0; font-size: 1.05rem; }
.section-meta { color: var(--muted); font-size: 0.78rem; }

.login-page { min-height: 100vh; display: grid; place-items: center; padding: max(24px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left)); overflow: hidden; }
.login-page::before, .login-page::after { content: ""; position: fixed; pointer-events: none; opacity: 0.48; }
.login-page::before { inset: 24px; border: 1px solid rgba(64, 117, 185, 0.18); clip-path: polygon(0 0, 18% 0, 20% 2px, 80% 2px, 82% 0, 100% 0, 100% 28%, calc(100% - 2px) 30%, calc(100% - 2px) 70%, 100% 72%, 100% 100%, 82% 100%, 80% calc(100% - 2px), 20% calc(100% - 2px), 18% 100%, 0 100%); }
.login-page::after { width: 340px; height: 340px; border-radius: 50%; background: rgba(43, 92, 176, 0.14); filter: blur(80px); }
.login-panel { position: relative; z-index: 1; width: min(420px, 100%); }
.tech-panel { padding: 32px; border: 1px solid rgba(72, 118, 174, 0.58); border-radius: 8px; background: linear-gradient(150deg, rgba(16, 34, 56, 0.96), rgba(7, 17, 30, 0.98)); box-shadow: var(--shadow), inset 0 1px rgba(143, 186, 239, 0.08); }
.login-brand-lockup { display: grid; justify-items: center; margin: -4px 0 28px; }
.login-brand-lockup h1 { position: relative; margin: 8px 0 0; text-align: center; font-size: 1.7rem; line-height: 1.2; }
.login-brand-lockup h1::after { content: ""; display: block; width: 52px; height: 1px; margin: 13px auto 0; background: linear-gradient(90deg, transparent, rgba(81, 156, 255, 0.92), rgba(48, 213, 210, 0.72), transparent); box-shadow: 0 0 9px rgba(74, 141, 245, 0.24); }
.login-logo-emblem { position: relative; isolation: isolate; width: 132px; height: 132px; display: grid; place-items: center; }
.login-logo-emblem::before { content: ""; position: absolute; z-index: -2; inset: 8px; clip-path: polygon(18% 0, 82% 0, 100% 18%, 100% 82%, 82% 100%, 18% 100%, 0 82%, 0 18%); background: linear-gradient(145deg, rgba(27, 64, 104, 0.62), rgba(6, 20, 35, 0.9)); box-shadow: inset 0 0 26px rgba(53, 119, 215, 0.18); }
.login-logo-emblem::after { content: ""; position: absolute; z-index: -1; inset: 0; background: linear-gradient(#5b9eff, #5b9eff) 50% 0 / 44% 1px no-repeat, linear-gradient(#5b9eff, #5b9eff) 50% 100% / 44% 1px no-repeat, linear-gradient(#38d2d0, #38d2d0) 0 50% / 1px 44% no-repeat, linear-gradient(#38d2d0, #38d2d0) 100% 50% / 1px 44% no-repeat; opacity: 0.62; clip-path: polygon(18% 0, 82% 0, 100% 18%, 100% 82%, 82% 100%, 18% 100%, 0 82%, 0 18%); filter: drop-shadow(0 0 6px rgba(53, 130, 235, 0.2)); }
.login-logo-emblem img { position: absolute; width: 190px; height: 190px; left: 50%; top: 50%; transform: translate(-50%, -47%); object-fit: contain; filter: drop-shadow(0 7px 10px rgba(0, 0, 0, 0.24)) drop-shadow(0 0 5px rgba(54, 158, 230, 0.14)); }

.field { display: grid; gap: 7px; margin-bottom: 16px; }
.field label { color: #b9c7d8; font-size: 0.82rem; font-weight: 700; }
.input, .select { width: 100%; min-height: 46px; padding: 10px 13px; border: 1px solid var(--line); border-radius: 6px; background: #091422; color: var(--text); appearance: auto; }
.input::placeholder { color: #60748d; }
.input:hover, .select:hover { border-color: var(--line-bright); }
.input:focus, .select:focus { border-color: #5688f6; box-shadow: inset 0 0 0 1px rgba(86, 136, 246, 0.35); }
.input-large { min-height: 52px; font-size: 1rem; }

.btn { min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 9px 16px; border: 1px solid transparent; border-radius: 6px; cursor: pointer; font-weight: 800; transition: border-color 140ms ease, background 140ms ease, transform 140ms ease; }
.btn:hover:not(:disabled) { transform: translateY(-1px); }
.btn:disabled { cursor: not-allowed; opacity: 0.42; }
.btn-primary { border-color: #5d81ff; background: linear-gradient(135deg, #357cf4, #5644df); color: #fff; box-shadow: inset 0 1px rgba(255,255,255,0.15), 0 7px 20px rgba(45, 86, 226, 0.2); }
.btn-secondary { border-color: var(--line); background: #132238; color: #eaf1fb; }
.btn-outline { border-color: #4779b5; background: transparent; color: #d4e4f7; }
.btn-danger { border-color: #9e3e45; background: rgba(138, 43, 51, 0.3); color: #ffb4b7; }
.btn-link { min-height: 34px; padding: 4px; background: transparent; color: #7eb0ff; }
.btn-block { width: 100%; margin-top: 10px; }

.task-entry-grid { display: grid; gap: 10px; margin-bottom: 26px; }
.task-entry { width: 100%; max-width: 100%; min-height: 92px; display: grid; grid-template-columns: 50px minmax(0,1fr) auto; align-items: center; gap: 14px; padding: 15px 18px; border: 1px solid var(--line); border-radius: 7px; background: linear-gradient(135deg, rgba(18, 37, 60, 0.96), rgba(10, 24, 40, 0.96)); text-align: left; cursor: pointer; }
.task-entry:hover { border-color: #4e7fb9; }
.task-entry.primary-entry { border-color: rgba(66, 119, 225, 0.78); }
.entry-icon { width: 50px; height: 50px; display: grid; place-items: center; border: 1px solid #4279c4; border-radius: 6px; background: rgba(38, 91, 184, 0.2); color: #7db7ff; font-size: 1.65rem; }
.task-entry strong, .task-entry small { display: block; }
.task-entry strong { font-size: 1.05rem; }
.task-entry small { margin-top: 5px; overflow-wrap: anywhere; color: var(--muted); }
.entry-chevron { color: #8da8c8; font-size: 1.8rem; }

.status-band { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 1px; overflow: hidden; border: 1px solid var(--line); border-radius: 7px; background: var(--line); }
.status-band.compact-status { grid-template-columns: repeat(3, minmax(0,1fr)); margin-bottom: 18px; }
.status-band.settings-status { grid-template-columns: repeat(5, minmax(0,1fr)); }
.status-item { min-height: 72px; padding: 13px 15px; background: var(--surface); }
.status-label { color: var(--muted); font-size: 0.75rem; }
.status-value { margin-top: 5px; font-size: 1.18rem; font-weight: 900; }
.badge { display: inline-flex; align-items: center; width: fit-content; min-height: 25px; padding: 3px 8px; border: 1px solid #53677d; border-radius: 999px; background: rgba(75, 91, 110, 0.22); color: #c5d1dd; font-size: 0.72rem; font-weight: 800; white-space: nowrap; }
.badge-green { border-color: #257f73; background: rgba(25, 119, 105, 0.22); color: #68e4d0; }
.badge-amber { border-color: #a0671e; background: rgba(155, 93, 14, 0.22); color: #ffc66d; }

.task-list, .product-list, .recent-list { width: 100%; max-width: 100%; min-width: 0; display: grid; gap: 8px; }
.task-row, .product-row, .recent-row { width: 100%; max-width: 100%; min-width: 0; display: grid; align-items: center; gap: 13px; padding: 14px 15px; border: 1px solid #263e5a; border-radius: 7px; background: var(--surface); }
.task-row { grid-template-columns: minmax(0,1fr) auto; }
.product-row { grid-template-columns: minmax(0,1fr) auto auto; }
.recent-row { grid-template-columns: minmax(0,1fr) auto; }
.row-main { min-width: 0; }
.row-title { overflow: hidden; margin: 0; font-weight: 800; text-overflow: ellipsis; white-space: nowrap; }
.row-meta { min-width: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin-top: 7px; color: var(--muted); font-size: 0.76rem; }
.row-meta > span { min-width: 0; max-width: 100%; overflow-wrap: anywhere; }
.quantity { min-width: 58px; text-align: right; }
.quantity strong { display: block; margin-top: 3px; font-size: 1.1rem; }
.recent-row span { display: block; margin-top: 4px; color: var(--muted); font-size: 0.75rem; }
.recent-result { display: flex; align-items: center; gap: 9px; }
.recent-result .badge { margin-top: 0; }

.toolbar { display: grid; gap: 10px; }
.search-fields { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 10px; }
.search-field { margin-bottom: 0; }
.search-actions { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 8px; }
.search-entry-actions .btn { width: 100%; }
.source-status { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 1px; overflow: hidden; border: 1px solid #275b68; border-radius: 7px; background: #275b68; }
.source-status > div { min-width: 0; padding: 11px 13px; background: rgba(10, 35, 45, 0.94); }
.source-status span, .source-status strong { display: block; }
.source-status span { color: #84aaa9; font-size: 0.72rem; }
.source-status strong { overflow: hidden; margin-top: 5px; color: #86e0d5; font-size: 0.84rem; text-overflow: ellipsis; white-space: nowrap; }
.segmented { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); padding: 3px; border: 1px solid var(--line); border-radius: 6px; background: #07111e; }
.segment { min-height: 40px; border: 0; border-radius: 4px; background: transparent; color: var(--muted); cursor: pointer; }
.segment.active { background: #172c48; color: #fff; box-shadow: inset 0 0 0 1px #315b8e; }
.sync-bar { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-top: 14px; padding: 10px 13px; border: 1px solid #235d67; border-radius: 6px; background: rgba(17, 84, 91, 0.19); color: #7de4e1; }
.sync-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--teal); box-shadow: 0 0 10px rgba(46,197,167,0.6); }
.sync-dot.pending { background: var(--amber); }
.sync-dot.error { background: var(--red); }
.notice { max-width: 100%; padding: 12px 14px; overflow-wrap: anywhere; border-left: 3px solid #3f78c1; background: rgba(38, 79, 127, 0.16); color: #c1d2e7; line-height: 1.55; }
.notice-warning { border-color: var(--amber); background: rgba(133, 84, 13, 0.18); }
.empty { padding: 24px 16px; border: 1px dashed #36506d; border-radius: 7px; color: var(--muted); text-align: center; }

.summary-cards, .summary-grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 10px; }
.summary-card, .summary-cell { min-height: 112px; padding: 17px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); }
.summary-card span, .summary-cell span { color: var(--muted); font-size: 0.8rem; }
.summary-card strong, .summary-cell strong { display: block; margin-top: 13px; font-size: 2rem; }
.difference-card { border-color: #8a434b; }
.difference-card strong { color: #ff8d91; }
.summary-actions { max-width: 620px; }
.completion-panel { width: min(620px,100%); margin: 10vh auto 0; padding: 30px; border: 1px solid var(--line-bright); border-radius: 8px; background: var(--surface); text-align: center; }
.completion-icon { width: 58px; height: 58px; display: grid; place-items: center; margin: 0 auto 16px; border: 1px solid #238e80; border-radius: 50%; color: #69e4d1; font-size: 1.5rem; }
.completion-panel h1 { margin: 0; }
.completion-panel p { color: var(--muted); }
.completion-panel .modal-actions { justify-content: center; }

.modal-backdrop { position: fixed; z-index: 50; inset: 0; width: 100%; max-width: 100%; overflow-x: clip; display: grid; place-items: end center; padding: 20px; background: rgba(0, 5, 12, 0.72); backdrop-filter: blur(8px); }
.modal { width: 100%; max-width: 580px; min-width: 0; max-height: min(88vh, 780px); overflow: auto; padding: 21px; border: 1px solid #35587e; border-radius: 8px; background: #0b1828; box-shadow: var(--shadow); }
.modal h2 { margin: 0 0 7px; font-size: 1.3rem; }
.modal > p { color: var(--muted); }
.form-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 0 12px; }
.field.full { grid-column: 1 / -1; }
.upload-zone { padding: 15px; border: 1px dashed #3b648f; border-radius: 7px; background: #071321; }
.progress { width: 100%; accent-color: var(--primary); }
.entry-list { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 12px; }
.entry-list h3 { font-size: 0.92rem; }
.entry-row { min-width: 0; display: flex; justify-content: space-between; gap: 10px; padding: 10px 0; border-bottom: 1px solid rgba(45,70,99,0.6); }
.entry-row > :first-child { min-width: 0; overflow-wrap: anywhere; }
.entry-row span { margin-left: 10px; color: var(--muted); font-size: 0.75rem; }

.scanner-backdrop { position: fixed; z-index: 70; inset: 0; width: 100%; max-width: 100%; overflow: hidden; background: #02060b; color: #fff; }
.scanner-panel { min-height: 100%; height: 100dvh; display: grid; grid-template-rows: auto minmax(300px,1fr) auto; }
.scanner-header, .scanner-footer { padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 16px max(16px, env(safe-area-inset-left)); background: #071321; }
.scanner-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; border-bottom: 1px solid var(--line); }
.scanner-header h2 { margin: 0; font-size: 1.2rem; }
.scanner-header p { margin: 5px 0 0; color: #9eb0c5; font-size: 0.84rem; }
.scanner-close { width: 46px; min-width: 46px; height: 46px; padding: 0; font-size: 1.6rem; }
.scanner-view { position: relative; min-height: 0; overflow: hidden; background: #000; }
.scanner-view video { width: 100%; height: 100%; object-fit: cover; }
.scanner-target { position: absolute; width: calc(100% - 24px); max-width: 760px; height: clamp(210px, 46vh, 420px); left: 50%; top: 44%; transform: translate(-50%,-50%); border: 3px solid rgba(255,255,255,0.94); border-radius: 8px; box-shadow: 0 0 0 9999px rgba(0,0,0,0.24), 0 0 20px rgba(80,151,255,0.24); }
.scanner-target::after { content: ""; position: absolute; left: 7%; right: 7%; top: 50%; height: 2px; background: #5f9fff; box-shadow: 0 0 12px #4c8fff; }
.scanner-footer { display: grid; gap: 6px; padding-bottom: max(18px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.scanner-footer span { color: #9eb0c5; overflow-wrap: anywhere; }

.report-wrap { width: 100%; max-width: 100%; overflow-x: auto; overflow-y: hidden; overscroll-behavior-inline: contain; border: 1px solid var(--line); border-radius: 7px; }
.report-table { width: 100%; border-collapse: collapse; min-width: 760px; }
.report-table th, .report-table td { padding: 10px; border-bottom: 1px solid var(--line); text-align: left; }
.report-table th { background: #10243a; color: #b8c8dc; font-size: 0.76rem; }
.report-table .num { text-align: right; }
.report-table .difference { color: #ff9699; font-weight: 800; }

.bottom-nav { position: fixed; z-index: 30; left: 50%; bottom: 0; width: 100%; max-width: 680px; min-width: 0; transform: translateX(-50%); display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); padding: 7px max(8px, env(safe-area-inset-right)) max(7px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left)); border: 1px solid rgba(56,88,124,0.65); border-bottom: 0; background: rgba(5,13,23,0.96); backdrop-filter: blur(14px); }
.nav-button { min-height: 50px; border: 0; background: transparent; color: #7e91a8; cursor: pointer; }
.nav-button.active { color: #70b9ff; }
.nav-symbol { display: block; margin-bottom: 2px; }

.toast-region { position: fixed; z-index: 100; right: 14px; bottom: 90px; left: 14px; min-width: 0; display: grid; justify-items: end; gap: 8px; pointer-events: none; }
.toast { width: min(360px, 100%); max-width: 100%; padding: 12px 15px; overflow-wrap: anywhere; border: 1px solid #28796f; border-radius: 6px; background: #0c2b2a; box-shadow: var(--shadow); color: #baf7ec; }
.toast.error { border-color: #9d3d45; background: #32171c; color: #ffc0c3; }

.busy-overlay { position: fixed; z-index: 90; inset: 0; width: 100%; max-width: 100%; display: grid; place-items: center; padding: 20px; background: rgba(2, 8, 16, 0.48); backdrop-filter: blur(3px); }
.busy-card { width: min(320px, 100%); display: grid; justify-items: center; gap: 9px; padding: 20px; border: 1px solid #3b6291; border-radius: 8px; background: #0b1929; box-shadow: var(--shadow); text-align: center; }
.busy-card > span:last-child { color: var(--muted); font-size: 0.78rem; }
.busy-spinner { width: 26px; height: 26px; border: 3px solid rgba(105, 161, 232, 0.22); border-top-color: #65a3f5; border-radius: 50%; animation: busy-spin 800ms linear infinite; }
@keyframes busy-spin { to { transform: rotate(360deg); } }

@media (max-width: 760px) {
  .page { padding-top: 18px; }
  .topbar { min-height: 62px; }
  .brand-context { max-width: 170px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .user-chip { display: none; }
  .page-header { align-items: flex-start; }
  .header-actions { flex-direction: column; align-items: stretch; }
  .status-band, .status-band.settings-status { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .search-fields { grid-template-columns: 1fr; }
  .source-status { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .product-row { grid-template-columns: minmax(0,1fr) auto; }
  .product-row .row-action { grid-column: 1 / -1; }
  .product-row .row-action .btn { width: 100%; }
  .summary-cards, .summary-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .form-grid { grid-template-columns: 1fr; }
  .field.full { grid-column: auto; }
  .modal { padding-bottom: max(22px, env(safe-area-inset-bottom)); }
  .modal-actions { flex-wrap: wrap; }
  .modal-actions .btn { flex: 1 1 140px; }
  .scanner-target { width: calc(100% - 20px); height: clamp(230px, 48vh, 390px); top: 43%; }
}

@media (max-width: 420px) {
  .tech-panel { padding: 24px 18px; }
  .task-entry { grid-template-columns: 46px minmax(0,1fr) auto; padding: 13px; }
  .entry-icon { width: 46px; height: 46px; }
  .task-row { grid-template-columns: 1fr; }
  .task-row > .btn { width: 100%; }
  .page-header { flex-direction: column; }
  .page-header > * { width: 100%; }
  .header-actions { width: 100%; }
}
