:root {
  color-scheme: light;
  --bg: #f5f6f3;
  --surface: #ffffff;
  --surface-strong: #eef3f0;
  --ink: #18201d;
  --muted: #68736d;
  --line: #d8ded7;
  --teal: #10766f;
  --teal-dark: #0b514d;
  --gold: #b87913;
  --rose: #ba4d4d;
  --blue: #3867a8;
  --shadow: 0 14px 36px rgba(25, 37, 33, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", "Microsoft JhengHei", system-ui, sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1640px, calc(100vw - 28px));
  margin: 0 auto;
  padding: 22px 0 34px;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 520px);
  gap: 24px;
  align-items: end;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--teal);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 34px;
  line-height: 1.15;
}

h2 {
  font-size: 18px;
  line-height: 1.25;
}

h3 {
  font-size: 14px;
  line-height: 1.25;
}

.source-meta {
  margin-top: 8px;
  color: var(--muted);
  font-size: 14px;
}

.refresh-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
}

.refresh-progress {
  display: grid;
  grid-template-columns: minmax(180px, 320px) auto;
  gap: 8px;
  align-items: center;
  margin-top: 10px;
}

.refresh-progress[hidden] {
  display: none;
}

.refresh-progress-track {
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--line);
}

.refresh-progress-bar {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--teal);
  transition: width 240ms ease;
}

.search-panel label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.search-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 42px;
  gap: 8px;
}

input[type="search"],
input[type="number"],
input[type="text"],
input[type="file"],
select {
  width: 100%;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  outline: none;
}

input[type="search"],
input[type="number"],
input[type="text"] {
  padding: 0 12px;
}

input[type="file"] {
  padding: 8px 10px;
}

select {
  padding: 0 10px;
}

input:focus,
select:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(16, 118, 111, 0.14);
}

#clearSearch {
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  font-size: 24px;
  line-height: 1;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin: 14px 0;
}

.metric,
.panel,
.product-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metric {
  min-height: 92px;
  padding: 14px 16px;
}

.metric span,
.metric small {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.metric strong {
  display: block;
  margin: 7px 0 2px;
  font-size: 28px;
  line-height: 1.15;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(720px, 1.25fr) minmax(360px, 0.75fr);
  gap: 14px;
  margin-bottom: 14px;
}

.panel {
  padding: 14px;
  margin-bottom: 14px;
}

.collapsible-panel > summary {
  cursor: pointer;
  list-style: none;
}

.collapsible-panel > summary::-webkit-details-marker {
  display: none;
}

.panel-wide {
  min-width: 0;
}

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

.panel-heading.compact {
  align-items: center;
}

.panel-heading p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.toolbar,
.action-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.action-row {
  margin: -4px 0 14px;
}

.action-row button,
.ghost-button,
.primary-link {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--teal-dark);
  padding: 0 12px;
  font-size: 13px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}

.primary-link {
  border-color: var(--teal);
  background: var(--teal);
  color: #fff;
}

.segmented {
  display: inline-flex;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  gap: 2px;
}

.segmented button {
  min-width: 64px;
  height: 32px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.segmented button.active {
  background: #fff;
  color: var(--teal-dark);
  box-shadow: 0 1px 6px rgba(26, 39, 35, 0.1);
}

.rule-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
}

.compact-rule-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.rule-sections {
  display: grid;
  gap: 14px;
}

.rule-section {
  display: grid;
  gap: 9px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.rule-section:first-child {
  border-top: 0;
  padding-top: 0;
}

.rule-section h3 {
  color: var(--teal-dark);
}

.field,
.checkbox-field {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.field span,
.checkbox-field span {
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
}

.field small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.checkbox-field {
  align-content: start;
  grid-template-columns: 18px minmax(0, 1fr);
  gap: 8px;
  padding-top: 26px;
}

.compact-check {
  align-content: center;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 10px;
}

.checkbox-field input {
  width: 18px;
  height: 18px;
  margin: 1px 0 0;
}

.rule-table-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin: 10px 0 10px;
}

.rule-details {
  margin-top: 14px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.rule-details > summary {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  list-style: none;
}

.rule-details > summary::-webkit-details-marker {
  display: none;
}

.rule-details > summary span {
  color: var(--teal-dark);
  font-size: 14px;
  font-weight: 900;
}

.upload-shell {
  max-width: 1380px;
}

.upload-topbar {
  grid-template-columns: 1fr;
}

.upload-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin: 14px 0;
}

.upload-panel {
  min-width: 0;
}

.upload-list {
  display: grid;
  gap: 10px;
}

.upload-card {
  display: grid;
  grid-template-columns: minmax(180px, 0.8fr) minmax(220px, 1fr) auto;
  gap: 10px;
  align-items: center;
  min-height: 86px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
}

.upload-card h3 {
  color: var(--teal-dark);
}

.upload-card p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.upload-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.upload-card small {
  grid-column: 1 / -1;
  min-height: 16px;
}

.upload-error {
  color: var(--rose);
  font-weight: 700;
}

.upload-settings-panel {
  overflow: hidden;
  max-height: min(82vh, 760px);
  overflow-y: auto;
}

.upload-settings-summary {
  margin-top: 14px;
}

.upload-settings-dialog {
  width: min(1040px, calc(100vw - 28px));
}

.settings-tabs {
  display: inline-flex;
  width: fit-content;
  max-width: 100%;
  gap: 2px;
  padding: 3px;
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  overflow-x: auto;
}

.settings-tabs button {
  min-width: 96px;
  height: 34px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.settings-tabs button.active {
  background: #fff;
  color: var(--teal-dark);
  box-shadow: 0 1px 6px rgba(26, 39, 35, 0.1);
}

.settings-grid {
  display: block;
}

.settings-grid article {
  min-width: 0;
  display: none;
  gap: 8px;
}

.settings-grid article.active {
  display: grid;
}

.settings-tab-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.settings-grid h3 {
  color: var(--teal-dark);
}

.mini-table {
  max-height: min(56vh, 520px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.mini-table table {
  min-width: 100%;
}

.mini-table th,
.mini-table td {
  padding: 8px 10px;
  white-space: nowrap;
}

.mini-table input[type="text"],
.mini-table select {
  min-width: 120px;
  height: 34px;
}

.switch-field {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 78px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
}

.switch-field input {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--teal);
}

.mini-table .row-button {
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--rose);
  padding: 0 10px;
  font-size: 12px;
  font-weight: 700;
}

.mini-table p {
  padding: 12px;
}

.analysis-settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 260px));
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.color-heading {
  margin-top: 12px;
}

.type-color-table {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.type-color-row {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) 52px 84px;
  gap: 10px;
  align-items: center;
}

.type-color-row span {
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
}

.type-color-row input[type="color"] {
  width: 52px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 3px;
}

.type-color-row code {
  color: var(--muted);
  font-family: Consolas, monospace;
  font-size: 12px;
  font-weight: 800;
}

.report-shell {
  max-width: 1760px;
}

.report-topbar .search-row {
  grid-template-columns: minmax(0, 1fr) 42px 42px;
}

#scanReportSearch {
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--teal-dark);
  font-size: 20px;
  font-weight: 800;
  line-height: 1;
}

#clearReportSearch {
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  font-size: 24px;
  line-height: 1;
}

.report-kpi-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.report-filter-panel {
  margin-top: 14px;
}

.report-filters {
  display: grid;
  grid-template-columns: minmax(140px, 0.8fr) minmax(220px, 1.3fr) repeat(2, minmax(132px, 0.8fr)) minmax(170px, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.report-filters label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.report-filters .check-row {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  white-space: nowrap;
}

.report-filters input[type="checkbox"] {
  width: 18px;
  height: 18px;
}

.report-layout {
  display: grid;
  grid-template-columns: minmax(760px, 1fr) minmax(360px, 440px);
  gap: 14px;
  align-items: start;
}

.report-table-panel,
.report-detail-panel {
  min-width: 0;
}

.report-table-wrap {
  overflow: auto;
  max-height: calc(100vh - 330px);
  min-height: 460px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.report-table {
  width: 100%;
  min-width: 1180px;
  border-collapse: collapse;
  font-size: 13px;
}

.report-table th,
.report-table td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.report-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-strong);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.report-table tr {
  cursor: pointer;
}

.report-table tr:hover,
.report-table tr.active {
  background: #f0f7f4;
}

.report-table td strong,
.report-table td span {
  display: block;
}

.report-table td span {
  margin-top: 3px;
  color: var(--muted);
}

.number-cell {
  text-align: right !important;
  white-space: nowrap;
}

.status-pill {
  display: inline-flex;
  min-height: 24px;
  align-items: center;
  border-radius: 999px;
  padding: 0 8px;
  background: var(--surface-strong);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.status-pill.ok {
  background: #e6f4ef;
  color: var(--teal-dark);
}

.status-pill.danger {
  background: #f8e9e9;
  color: var(--rose);
}

.report-detail-empty {
  display: grid;
  min-height: 220px;
  place-items: center;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
}

.report-detail-title {
  display: grid;
  gap: 7px;
  margin-bottom: 12px;
}

.report-detail-title h2 {
  font-size: 20px;
  line-height: 1.3;
}

.report-detail-title p {
  color: var(--muted);
  font-size: 13px;
}

.report-detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.report-detail-row {
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.report-detail-row span,
.report-detail-row strong {
  display: block;
}

.report-detail-row span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.report-detail-row strong {
  margin-top: 4px;
  overflow-wrap: anywhere;
  font-size: 13px;
}

.report-note {
  margin-top: 12px;
}

.report-note h3 {
  margin-bottom: 6px;
  color: var(--muted);
}

.report-note pre {
  max-height: 220px;
  overflow: auto;
  margin: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font: 13px/1.55 "Segoe UI", "Microsoft JhengHei", system-ui, sans-serif;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.report-mobile-layout {
  grid-template-columns: 1fr;
}

.report-list-panel {
  min-width: 0;
}

.report-card-list {
  display: grid;
  gap: 12px;
}

.report-empty {
  margin: 0;
  padding: 32px 12px;
  color: var(--muted);
  text-align: center;
}

.report-order-card {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-left: 5px solid var(--blue);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 8px 22px rgba(25, 37, 33, 0.07);
  cursor: pointer;
}

.report-order-card.selected {
  border-left-color: var(--teal);
  background: #f6fffb;
}

.report-card-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: start;
}

.report-select-check {
  display: inline-grid;
  grid-template-columns: 24px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  min-width: 0;
}

.report-select-check input {
  width: 20px;
  height: 20px;
  margin: 0;
  accent-color: var(--teal);
}

.report-select-check small,
.report-card-grid span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.report-select-check strong {
  display: block;
  color: var(--blue);
  font-size: 21px;
  line-height: 1.1;
}

.report-card-tags {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 5px;
}

.report-tag {
  display: inline-flex;
  min-height: 24px;
  align-items: center;
  border-radius: 999px;
  padding: 0 8px;
  background: var(--surface-strong);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.report-tag.blue {
  background: #e8f0fb;
  color: var(--blue);
}

.report-tag.cyan {
  background: #e3f5f4;
  color: var(--teal-dark);
}

.report-card-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.report-card-grid-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.report-card-grid > div {
  min-width: 0;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
}

.report-card-grid strong {
  display: block;
  margin-top: 3px;
  overflow-wrap: anywhere;
  font-size: 16px;
  line-height: 1.2;
}

.danger-text {
  color: var(--rose);
}

.report-card-vendor,
.report-card-note {
  margin: 0;
  overflow-wrap: anywhere;
  font-size: 13px;
  line-height: 1.45;
}

.report-card-vendor {
  color: var(--teal-dark);
  font-weight: 800;
}

.report-card-note {
  padding-top: 9px;
  border-top: 1px dashed var(--line);
  color: var(--muted);
}

.report-selection-bar {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 1000;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto auto auto;
  gap: 8px;
  align-items: center;
  padding: 10px 14px;
  border-top: 3px solid var(--teal);
  background: #fff;
  box-shadow: 0 -10px 24px rgba(25, 37, 33, 0.12);
}

.report-selection-bar[hidden] {
  display: none;
}

.report-selection-bar span,
.report-selection-bar strong {
  display: block;
}

.report-selection-bar span {
  color: var(--muted);
  font-size: 12px;
}

.report-selection-bar strong {
  max-width: 100%;
  overflow: hidden;
  color: var(--blue);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.report-dialog {
  width: min(980px, calc(100vw - 22px));
  max-height: min(86vh, 900px);
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
}

.report-dialog::backdrop {
  background: rgba(14, 21, 19, 0.48);
}

.report-dialog-panel {
  max-height: min(86vh, 900px);
  overflow: auto;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  box-shadow: var(--shadow);
}

.report-dialog .report-detail-title p {
  max-height: 130px;
  overflow: auto;
  margin: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  white-space: pre-wrap;
}

.report-detail-table-wrap {
  overflow: auto;
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.report-detail-table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
  font-size: 13px;
}

.report-detail-table th,
.report-detail-table td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.report-detail-table th {
  position: sticky;
  top: 0;
  background: var(--surface-strong);
  color: var(--muted);
  font-size: 12px;
}

.report-detail-table td strong,
.report-detail-table td span {
  display: block;
}

.report-detail-table td span {
  margin-top: 3px;
  color: var(--muted);
}

.report-dialog-actions {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.scanner-dialog {
  width: min(520px, calc(100vw - 22px));
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
}

.scanner-dialog::backdrop {
  background: rgba(14, 21, 19, 0.48);
}

.scanner-panel {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  box-shadow: var(--shadow);
}

.scanner-reader {
  overflow: hidden;
  min-height: 280px;
  border-radius: 8px;
  background: #000;
}

#printArea,
#printAreaLabels {
  display: none;
}

@media print {
  body,
  html {
    margin: 0 !important;
    padding: 0 !important;
    background: white !important;
  }

  body > :not(#printArea):not(#printAreaLabels) {
    display: none !important;
  }

  body.print-mode-po #printArea {
    display: block !important;
  }

  body.print-mode-label #printAreaLabels {
    display: block !important;
  }

  #printArea {
    width: 100%;
    font-family: "Microsoft JhengHei", Arial, sans-serif;
    color: black;
  }

  .po-page {
    page-break-after: always;
  }

  .po-page:last-of-type {
    page-break-after: avoid !important;
  }

  .print-title {
    margin-bottom: 5px;
    font-size: 13px;
    font-weight: bold;
  }

  .excel-table {
    display: table !important;
    width: 100% !important;
    margin-bottom: 10px !important;
    border-collapse: collapse !important;
    table-layout: fixed;
  }

  .excel-table th,
  .excel-table td {
    padding: 4px !important;
    border: 1px solid #000 !important;
    font-size: 12px;
    text-align: center;
    vertical-align: middle;
    word-wrap: break-word;
  }

  .excel-table th {
    background-color: #f2f2f2 !important;
    print-color-adjust: exact !important;
    -webkit-print-color-adjust: exact !important;
  }

  .po-header {
    display: flex;
    align-items: stretch;
    justify-content: space-between;
    margin-bottom: 10px;
  }

  .po-num {
    display: flex;
    width: 25%;
    align-items: center;
    justify-content: flex-start;
    font-size: 24px;
    font-weight: bold;
  }

  .po-memo {
    flex: 1;
    display: flex;
    align-items: center;
    padding: 0 10px;
    font-size: 13px;
    text-align: left;
    white-space: pre-wrap;
  }

  .po-barcode {
    display: flex;
    width: 30%;
    align-items: center;
    justify-content: flex-end;
    text-align: right;
  }

  .po-barcode svg {
    max-width: 100%;
    max-height: 45px;
  }

  .print-instruction {
    margin-bottom: 3px;
    font-size: 12px;
  }

  .print-box {
    display: flex;
    margin-bottom: 10px;
    padding: 5px;
    border: 1px solid #000;
    font-size: 12px;
    line-height: 1.4;
  }

  .print-box-title {
    display: flex;
    width: 70px;
    align-items: center;
    justify-content: center;
    margin-right: 8px;
    padding-right: 8px;
    border-right: 1px solid #000;
    font-weight: bold;
    text-align: center;
  }

  .col-barcode { width: 12%; }
  .col-name { width: 20%; text-align: left !important; }
  .col-style { width: 10%; text-align: left !important; }
  .col-loc { width: 8%; }
  .col-label-blank { width: 4%; }
  .col-qty { width: 5%; color: red !important; font-weight: bold; -webkit-print-color-adjust: exact !important; }
  .col-blank { width: 4.5%; }
  .col-note { width: 13%; }
  .col-stock { width: 5%; font-weight: bold; }
  .col-fmt { width: 5%; font-weight: bold; }
  .col-dd { width: 5%; font-weight: bold; }
  .excel-table tr { page-break-inside: avoid; }

  #printAreaLabels {
    font-family: "Microsoft JhengHei", sans-serif;
    color: black;
  }

  .lbl-page {
    position: relative;
    overflow: hidden;
    box-sizing: border-box;
    width: 50mm;
    height: 19.5mm;
    margin: 0;
    padding: 0;
    page-break-after: always;
    page-break-inside: avoid;
    background: white;
  }

  .lbl-page:last-of-type {
    page-break-after: avoid !important;
  }

  .lbl-qr {
    position: absolute;
    top: 1.5mm;
    left: 1.5mm;
    width: 12mm;
    height: 12mm;
  }

  .lbl-qr img,
  .lbl-qr canvas {
    display: block;
    width: 12mm !important;
    height: 12mm !important;
    margin: 0;
    padding: 0;
  }

  .lbl-date {
    position: absolute;
    top: 14mm;
    left: 1.5mm;
    width: 12mm;
    margin: 0;
    padding: 0;
    font-size: 5pt;
    font-weight: bold;
    line-height: 1.1;
    text-align: center;
  }

  .lbl-barcode {
    position: absolute;
    top: 2mm;
    left: 15mm;
    width: 24mm;
    margin: 0;
    padding: 0;
    font-size: 8.5pt;
    font-weight: bold;
    line-height: 1;
  }

  .lbl-style {
    position: absolute;
    top: 6mm;
    left: 15mm;
    display: -webkit-box;
    overflow: hidden;
    width: 24mm;
    height: 7mm;
    margin: 0;
    padding: 0;
    font-size: 7.5pt;
    line-height: 1.1;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
  }

  .lbl-loc {
    position: absolute;
    top: 14mm;
    left: 15mm;
    width: 24mm;
    margin: 0;
    padding: 0;
    font-size: 9pt;
    font-weight: bold;
    line-height: 1;
  }

  .lbl-corner-line {
    position: absolute;
    top: 0;
    right: 0;
    overflow: hidden;
    width: 10mm;
    height: 10mm;
  }
}

.rule-details > summary em {
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
}

.min-rules {
  display: grid;
  gap: 8px;
}

.min-rule {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 36px;
  gap: 8px;
  align-items: end;
}

.prefix-rule {
  grid-template-columns: minmax(0, 1fr) 36px;
}

.min-rule label {
  display: grid;
  gap: 5px;
}

.min-rule span {
  color: var(--muted);
  font-size: 12px;
}

.min-rule button {
  width: 36px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--rose);
  font-size: 20px;
}

.chart {
  min-height: 300px;
  overflow-x: auto;
  padding: 8px 0 4px;
}

.bar-chart {
  min-width: 760px;
  height: 280px;
  display: grid;
  grid-template-columns: repeat(var(--count), minmax(54px, 1fr));
  gap: 10px;
  align-items: end;
}

.bar-item {
  display: grid;
  grid-template-rows: 1fr auto auto;
  min-width: 0;
  height: 100%;
  text-align: center;
}

.bar-track {
  position: relative;
  align-self: stretch;
  display: flex;
  align-items: end;
  justify-content: center;
  border-bottom: 1px solid var(--line);
}

.bar-fill {
  width: min(48px, 72%);
  min-height: 6px;
  border-radius: 7px 7px 0 0;
  background: linear-gradient(180deg, var(--teal), var(--teal-dark));
}

.bar-item:nth-child(2n) .bar-fill {
  background: linear-gradient(180deg, var(--gold), #80520d);
}

.bar-item:nth-child(3n) .bar-fill {
  background: linear-gradient(180deg, var(--blue), #264775);
}

.bar-value {
  margin-top: 8px;
  color: var(--ink);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.bar-label {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.table-wrap {
  overflow-x: auto;
  border-top: 1px solid var(--line);
  margin-top: 12px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th,
td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-weight: 700;
  white-space: nowrap;
}

td.num,
th.num {
  text-align: right;
}

.rank-list {
  display: grid;
  gap: 8px;
  max-height: 430px;
  overflow: auto;
  padding-right: 4px;
}

.rank-item {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.vendor-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
}

.vendor-summary {
  width: 100%;
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) minmax(96px, auto);
  gap: 12px;
  align-items: center;
  padding: 12px;
  color: inherit;
  text-align: left;
  transition: border-color 0.16s ease, background 0.16s ease, transform 0.16s ease;
}

.vendor-summary:hover {
  border-color: rgba(16, 118, 111, 0.45);
  background: #fbfdfb;
  transform: translateY(-1px);
}

.vendor-item summary {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  cursor: pointer;
  list-style: none;
}

.vendor-item summary::-webkit-details-marker {
  display: none;
}

.vendor-products {
  display: grid;
  gap: 8px;
  padding: 0 10px 10px 54px;
}

.vendor-product {
  display: grid;
  gap: 3px;
  border-top: 1px solid var(--line);
  padding-top: 8px;
  color: var(--muted);
  font-size: 12px;
}

.vendor-product strong {
  color: var(--ink);
  font-size: 13px;
  line-height: 1.35;
}

.vendor-code-link {
  color: var(--teal-dark);
  font-weight: 800;
  text-decoration: none;
}

.vendor-code-link:hover {
  text-decoration: underline;
}

.clear-vendor {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--teal);
  border-radius: 8px;
  background: #eef8f6;
  color: var(--teal-dark);
  font-size: 13px;
  font-weight: 800;
}

.active-vendor {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(16, 118, 111, 0.12);
}

.compact-list {
  display: grid;
  gap: 8px;
  max-height: 360px;
  overflow: auto;
}

.summary-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.vendor-ranking-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.summary-actions select {
  width: 190px;
  height: 36px;
  font-size: 13px;
}

.compact-row {
  display: grid;
  grid-template-columns: minmax(260px, 1.4fr) minmax(80px, 140px) repeat(6, minmax(74px, 110px));
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 10px;
  color: var(--ink);
  text-align: left;
}

.compact-row strong,
.compact-row em {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.compact-row em {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
}

.compact-row .num {
  text-align: right;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.note-text {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 12px;
}

.rank-number {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: #eef4f2;
  color: var(--teal-dark);
  font-weight: 800;
  font-size: 13px;
}

.rank-name {
  min-width: 0;
  display: grid;
  gap: 6px;
}

.rank-name strong {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
  color: var(--ink);
  font-size: 15px;
  line-height: 1.25;
}

.rank-name strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.product-title strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.vendor-stock-rate {
  color: var(--rose);
  font-size: 13px;
  font-style: normal;
  font-weight: 900;
  white-space: nowrap;
}

.vendor-summary-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.vendor-summary-meta b {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 3px 7px;
  border-radius: 999px;
  background: #f3f6f3;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.rank-name span,
.product-title span,
.muted {
  color: var(--muted);
  font-size: 12px;
}

.incoming-highlight {
  color: var(--rose);
  font-weight: 900;
}

.rank-value {
  align-self: stretch;
  display: grid;
  place-items: center end;
  min-width: 96px;
  padding-left: 12px;
  border-left: 1px solid var(--line);
  color: var(--ink);
  font-size: 15px;
  font-weight: 900;
  white-space: nowrap;
}

.product-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.product-card {
  display: grid;
  gap: 12px;
  padding: 14px;
}

.new-product-card {
  border-color: rgba(186, 77, 77, 0.58);
  box-shadow: 0 0 0 3px rgba(186, 77, 77, 0.12), var(--shadow);
}

.load-more {
  grid-column: 1 / -1;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--teal-dark);
  font-size: 14px;
  font-weight: 800;
}

.product-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.product-title {
  display: grid;
  min-width: 0;
  gap: 3px;
}

.product-head > .pill {
  flex: 0 0 auto;
  white-space: nowrap;
}

.product-code {
  color: var(--teal-dark);
  font-size: 13px;
  font-weight: 800;
}

.code-button {
  display: inline;
  width: auto;
  height: auto;
  border: 0;
  background: transparent;
  padding: 0;
  text-align: left;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.product-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.meta-row {
  width: 100%;
}

.meta-row-1,
.meta-row-2,
.meta-row-3 {
  flex-wrap: nowrap;
}

.meta-row .pill {
  min-width: 0;
}

.vendor-code-pill {
  align-items: baseline;
  gap: 3px;
}

.pill {
  display: inline-flex;
  max-width: 100%;
  min-height: 24px;
  align-items: center;
  border-radius: 999px;
  border: 1px solid var(--line);
  padding: 3px 8px;
  color: var(--muted);
  font-size: 12px;
}

.feature-pill {
  border-color: rgba(184, 121, 19, 0.45);
  background: #fff8e8;
  color: #7a4e0d;
  font-weight: 900;
}

.discount-pill {
  border-color: rgba(186, 77, 77, 0.38);
  background: #fff2f2;
  color: var(--rose);
}

.cost-pill {
  border-color: rgba(56, 103, 168, 0.3);
  background: #f2f6fc;
  color: var(--blue);
  font-weight: 900;
}

.profit-pill {
  border-color: rgba(16, 118, 111, 0.3);
  background: #eef8f6;
  color: var(--teal-dark);
  font-weight: 900;
}

.bulk-pill {
  border-color: rgba(186, 77, 77, 0.45);
  background: #ffecec;
  color: var(--rose);
  font-weight: 900;
}

.new-product-pill {
  border-color: rgba(186, 77, 77, 0.4);
  background: #fff0f0;
  color: var(--rose);
  font-weight: 900;
}

.last-purchase-pill {
  border-color: rgba(16, 118, 111, 0.32);
  background: #eef8f6;
  color: var(--teal-dark);
  font-weight: 900;
}

.no-purchase-pill {
  border-style: dashed;
}

.status-buy {
  border-color: rgba(186, 77, 77, 0.32);
  background: #fff4f4;
  color: var(--rose);
  font-weight: 800;
}

.status-ok {
  border-color: rgba(16, 118, 111, 0.24);
  background: #f1f8f6;
  color: var(--teal-dark);
  font-weight: 800;
}

.product-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.sales-window-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.mini-stat {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfb;
  padding: 6px 8px;
  color: var(--ink);
  font-size: 12px;
  font-weight: 800;
  text-align: left;
}

button.mini-stat {
  cursor: pointer;
}

button.mini-stat:hover {
  border-color: var(--teal);
  box-shadow: 0 0 0 2px rgba(16, 118, 111, 0.1);
}

.mini-stat b {
  display: block;
  margin-bottom: 2px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.master-sales {
  font-weight: 900;
}

.sales-7 {
  border-color: rgba(16, 118, 111, 0.34);
  background: #edf8f5;
  color: var(--teal-dark);
}

.sales-15 {
  border-color: rgba(56, 103, 168, 0.34);
  background: #f0f5fc;
  color: var(--blue);
}

.sales-30 {
  border-color: rgba(184, 121, 19, 0.34);
  background: #fff7e8;
  color: #7a4e0d;
}

.allocation-sales {
  border-color: rgba(184, 121, 19, 0.34);
  background: #fffaf0;
  color: #7a4e0d;
}

.festival-note {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  border-left: 3px solid var(--gold);
  background: #fffaf0;
  padding: 8px 10px;
  color: var(--rose);
  font-size: 12px;
  font-weight: 900;
}

.festival-note strong {
  color: var(--rose);
}

.product-stats div {
  min-width: 0;
  border-top: 3px solid var(--teal);
  background: #f7f9f6;
  padding: 8px;
  border-radius: 6px;
}

.product-stats div:nth-child(2) {
  border-top-color: var(--gold);
}

.product-stats div:nth-child(3) {
  border-top-color: var(--blue);
}

.product-stats div:nth-child(4) {
  border-top-color: var(--rose);
}

.product-stats span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.product-stats strong {
  display: block;
  margin-top: 4px;
  font-size: 15px;
  white-space: nowrap;
}

.purchase-controls {
  display: grid;
  grid-template-columns: minmax(120px, 180px) auto;
  gap: 10px;
  align-items: end;
}

.purchase-controls label {
  display: grid;
  gap: 5px;
}

.purchase-controls span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.purchase-controls input[type="number"] {
  height: 36px;
}

.inline-check {
  grid-template-columns: 18px auto;
  align-items: center;
  padding-bottom: 8px;
}

.inline-check input {
  width: 18px;
  height: 18px;
  margin: 0;
}

.explain {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.sparkline {
  width: 100%;
  height: 44px;
}

.empty-state {
  padding: 28px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
}

.settings-dialog {
  width: min(560px, calc(100vw - 28px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  box-shadow: 0 24px 80px rgba(24, 32, 29, 0.22);
}

.settings-dialog.is-open {
  display: block;
}

.settings-dialog::backdrop {
  background: rgba(24, 32, 29, 0.28);
}

.settings-panel {
  padding: 16px;
  background: #fff;
}

.help-dialog {
  width: min(860px, calc(100vw - 28px));
}

.history-dialog {
  width: min(1180px, calc(100vw - 28px));
}

.history-panel {
  max-height: min(82vh, 820px);
  overflow: auto;
  padding-top: 0;
}

.history-panel .panel-heading {
  position: sticky;
  top: 0;
  z-index: 5;
  margin: 0 -16px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.history-content {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 14px;
  padding-top: 14px;
}

.history-column {
  display: grid;
  gap: 8px;
  align-content: start;
}

.history-column-head {
  position: sticky;
  top: 72px;
  z-index: 4;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
  border-bottom: 1px solid var(--line);
  background: #fff;
  padding: 8px 0;
}

.history-column-head h3 {
  margin: 0;
  font-size: 16px;
}

.history-column-head span {
  color: var(--muted);
  font-size: 12px;
}

.history-tree {
  display: grid;
  gap: 6px;
  font-size: 13px;
}

.history-tree details {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.history-tree summary {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  min-height: 34px;
  align-items: center;
  padding: 7px 9px;
  color: var(--ink);
  cursor: pointer;
  list-style: none;
}

.history-tree summary::-webkit-details-marker {
  display: none;
}

.history-tree summary::before {
  content: "▸";
  color: var(--muted);
}

.history-tree details[open] > summary::before {
  content: "▾";
}

.history-tree summary span {
  flex: 1;
  min-width: 0;
}

.history-tree summary b {
  font-weight: 900;
}

.history-month,
.history-day {
  margin: 0 6px 6px 18px;
}

.history-day summary {
  background: #f7f9f6;
}

.history-details {
  display: grid;
  gap: 3px;
  padding: 0 9px 8px 28px;
}

.history-detail-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
}

.history-detail-row span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.help-content {
  display: grid;
  gap: 16px;
  max-height: min(70vh, 720px);
  overflow: auto;
  padding-right: 4px;
}

.help-content section {
  display: grid;
  gap: 8px;
}

.help-content table {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  display: table;
}

.help-content th {
  width: 150px;
}

.help-content ul {
  margin: 0;
  padding-left: 20px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.65;
}

@media (max-width: 1180px) {
  .topbar,
  .content-grid,
  .upload-grid,
  .settings-grid {
    grid-template-columns: 1fr;
  }

  .kpi-grid,
  .product-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .rule-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .app-shell {
    width: min(100vw - 20px, 1500px);
    padding-top: 18px;
  }

  h1 {
    font-size: 28px;
  }

  .kpi-grid,
  .rule-grid,
  .compact-rule-grid,
  .analysis-settings-grid,
  .product-grid,
  .upload-card,
  .product-stats,
  .compact-row,
  .sales-window-grid,
  .purchase-controls,
  .min-rule {
    grid-template-columns: 1fr;
  }

  .panel-heading {
    display: grid;
  }

  .summary-actions {
    display: grid;
    grid-template-columns: 1fr auto auto;
    width: 100%;
  }

  .summary-actions select {
    width: 100%;
  }

  .vendor-ranking-actions {
    grid-template-columns: 1fr;
  }

  .vendor-ranking-actions .segmented {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .vendor-summary {
    grid-template-columns: 30px minmax(0, 1fr);
  }

  .vendor-summary .rank-value {
    grid-column: 2;
    justify-content: start;
    place-items: center start;
    min-width: 0;
    padding-left: 0;
    border-left: 0;
    color: var(--teal-dark);
  }

  .segmented,
  .toolbar,
  .action-row {
    width: 100%;
  }

  .segmented button,
  .toolbar select {
    flex: 1;
  }

  .meta-row-1,
  .meta-row-2,
  .meta-row-3 {
    flex-wrap: wrap;
  }

  .history-content {
    grid-template-columns: 1fr;
  }

  .history-column-head {
    top: 86px;
  }

  .checkbox-field {
    padding-top: 0;
  }
}

.copy-toast {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 1000;
  max-width: min(420px, calc(100vw - 36px));
  padding: 10px 14px;
  border: 1px solid #9fc8bf;
  border-radius: 8px;
  background: #f1fbf8;
  color: var(--teal-dark);
  box-shadow: var(--shadow);
  font-size: 15px;
  font-weight: 700;
  line-height: 1.35;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-8px);
  transition: opacity 0.16s ease, transform 0.16s ease;
}

.copy-toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 1180px) {
  .report-kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .report-filters {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .report-layout {
    grid-template-columns: 1fr;
  }

  .report-table-wrap {
    max-height: none;
  }
}

@media (max-width: 760px) {
  .report-kpi-grid,
  .report-filters,
  .report-detail-grid {
    grid-template-columns: 1fr;
  }

  .report-topbar {
    grid-template-columns: 1fr;
  }

  .report-table-wrap {
    min-height: 360px;
  }

  .report-shell {
    width: min(100vw - 16px, 1760px);
    padding-bottom: 96px;
  }

  .report-card-head {
    display: grid;
  }

  .report-card-tags {
    justify-content: flex-start;
  }

  .report-card-grid,
  .report-card-grid-3 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .report-selection-bar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .report-selection-bar > div {
    grid-column: 1 / -1;
  }

  .report-selection-bar button {
    justify-content: center;
  }

  .report-selection-bar .primary-link {
    grid-column: 1 / -1;
  }

  .report-dialog {
    width: calc(100vw - 14px);
    max-height: 90vh;
  }

  .report-dialog-panel {
    max-height: 90vh;
    padding: 10px;
  }

  .report-dialog-actions {
    grid-template-columns: 1fr;
  }
}
