:root {
  color-scheme: light;
  --page: #f5f5f2;
  --surface: #fff;
  --rail: #fcfcfa;
  --raised: #f4f4f1;
  --hover: #efefeb;
  --ink: #242824;
  --text: #535952;
  --muted: #656b63;
  --line: #e2e4de;
  --control-line: #cdd1c8;
  --accent: #9c412a;
  --accent-hover: #80331f;
  --accent-soft: #f8eee8;
  --success: #356047;
  --success-soft: #eff5ef;
  --danger: #983b31;
  --danger-soft: #fbefec;
  --radius: 8px;
  --panel-radius: 16px;
  --sans: "Avenir Next", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  --ease: cubic-bezier(.22, 1, .36, 1);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--page); color: var(--ink); font: 400 14px/1.5 var(--sans); }
body:has(dialog[open]) { overflow: hidden; }
button, input, select, textarea { font: inherit; }
button, select, summary { cursor: pointer; }
button:disabled, input:disabled { cursor: default; opacity: .55; }
a { color: inherit; text-decoration: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
h1, h2, h3, p, dl, dd, figure { margin: 0; }
h1, h2, h3, strong { font-weight: 600; }
h1 { font-size: 36px; line-height: 1.2; }
h2 { font-size: 17px; line-height: 1.4; }
h3 { font-size: 16px; }
.startup { margin: 12vh auto 0; padding: 16px; text-align: center; color: var(--text); }
.icon-library { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon {
  display: block;
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.workspace { display: grid; grid-template-columns: 240px minmax(0, 1fr); min-height: 100dvh; }
.sidebar {
  position: sticky;
  top: 0;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 24px 16px 20px;
  background: var(--rail);
  border-right: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; width: fit-content; font-size: 20px; font-weight: 600; line-height: 1.1; }
.brand small { display: block; margin-top: 4px; color: var(--muted); font-size: 12px; font-weight: 500; }
.brand-mark { flex: 0 0 32px; width: 32px; height: 32px; position: relative; border: 1px solid currentColor; border-radius: 50%; overflow: hidden; }
.brand-mark::before { content: ""; position: absolute; top: 6px; left: 10px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.brand-mark::after { content: ""; position: absolute; top: 15px; left: -6px; width: 38px; height: 18px; border: 1px solid currentColor; border-radius: 50%; transform: rotate(-23deg); }
.sidebar .brand { margin: 8px 12px 32px; }
.sidebar nav { display: grid; gap: 4px; }
.sidebar nav a {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 8px 12px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: var(--text);
  font-weight: 500;
  white-space: nowrap;
}
.sidebar nav a:hover, .sidebar-action:hover { background: var(--raised); color: var(--ink); }
.sidebar nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.sidebar nav a[aria-current="page"]::before { content: ""; position: absolute; inset: 12px auto 12px 0; width: 2px; border-radius: 2px; background: currentColor; }
.sidebar .sidebar-action { margin-top: auto; justify-content: flex-start; color: var(--text); }
main { width: min(100%, 1480px); margin-inline: auto; padding: 40px 32px 64px; }
.page-header { display: flex; align-items: center; justify-content: space-between; gap: 24px; margin-bottom: 32px; }
.page-header p { color: var(--text); margin-top: 8px; }

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 8px 12px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--ink);
  font-weight: 600;
  line-height: 20px;
  text-align: center;
  white-space: nowrap;
}
.primary { color: #fff; background: var(--accent); border-color: var(--accent); }
.primary:hover:enabled { background: var(--accent-hover); border-color: var(--accent-hover); }
.secondary { background: var(--surface); border-color: var(--control-line); }
.secondary:hover:where(:enabled, a), .text-button:hover:where(:enabled, a), .close-button:hover { background: var(--raised); }
.text-button { color: var(--text); }
.danger { color: var(--danger); }
.danger:hover:enabled { background: var(--danger-soft); }
.button, .sidebar nav a, input, select, textarea { transition: background-color 140ms var(--ease), border-color 140ms var(--ease), color 140ms var(--ease); }

.metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-bottom: 24px;
  border: 1px solid var(--line);
  border-radius: var(--panel-radius);
  background: var(--surface);
}
.metrics > div { min-width: 0; padding: 16px 24px; }
.metrics > div + div { border-left: 1px solid var(--line); }
.metrics dt { color: var(--text); font-size: 13px; }
.metrics dd { margin-top: 8px; font-size: 32px; line-height: 1.15; font-weight: 500; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.metrics small { color: var(--muted); font-size: 12px; font-weight: 500; white-space: nowrap; }
.surface { border: 1px solid var(--line); border-radius: var(--panel-radius); background: var(--surface); }
.surface-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 64px; padding: 12px 24px; }
.surface-bar > :where(a, button) { min-height: 36px; padding-block: 4px; }
.count { margin-left: 8px; color: var(--muted); font-size: 13px; font-weight: 500; font-variant-numeric: tabular-nums; }
.search { position: relative; width: min(100%, 260px); }
.search input { margin: 0; padding-left: 40px; }
.search .icon { position: absolute; top: 50%; left: 12px; transform: translateY(-50%); color: var(--muted); pointer-events: none; }

.table-wrap { width: 100%; overflow-x: auto; border-radius: 0 0 var(--panel-radius) var(--panel-radius); }
.table-wrap:focus-visible { outline-offset: -2px; }
table { width: 100%; border-collapse: collapse; text-align: left; font-variant-numeric: tabular-nums; }
th, td { padding: 12px; vertical-align: middle; }
th:first-child, td:first-child { padding-left: 24px; }
th:last-child, td:last-child { padding-right: 24px; }
thead th { border-block: 1px solid var(--line); background: var(--raised); color: var(--text); font-size: 12px; font-weight: 600; }
tbody td, tbody th { border-bottom: 1px solid var(--line); }
tbody tr:last-child > * { border-bottom: 0; }
tbody tr:hover { background: var(--rail); }
.numeric, .actions-heading, .row-actions { text-align: right; }
td.numeric, td.row-actions, td time { white-space: nowrap; }
.table-label { display: none; }
td .button { min-height: 32px; padding: 4px 8px; }
.row-actions .button + .button, .quote-setup .button + .button { margin-left: 4px; }
.muted { display: block; color: var(--muted); font-size: 12px; margin-top: 4px; }
.row-heading { min-width: 112px; font-weight: 600; overflow-wrap: anywhere; }
.row-heading .muted { font-weight: 400; }
.product-name { display: flex; align-items: center; gap: 12px; }
.thumbnail { display: grid; place-items: center; width: 40px; height: 40px; flex: 0 0 40px; object-fit: cover; background: var(--raised); color: var(--muted); border-radius: var(--radius); }
.currency-code { font-size: 15px; }
.rate-value, .price-value { font-size: 16px; }
.price-value, .price-heading { color: var(--accent); }
.rate-status { display: inline-flex; align-items: center; gap: 8px; color: var(--text); }
.rate-status::before { content: ""; width: 8px; height: 8px; flex: 0 0 8px; border-radius: 50%; background: var(--muted); }
.rate-status.synced::before { background: var(--success); }
.rate-status.pending::before { background: var(--accent); }

.empty { display: grid; justify-items: center; align-content: center; gap: 8px; min-height: 224px; padding: 32px 24px; text-align: center; }
.surface-bar + .empty, .table-wrap + .empty { border-top: 1px solid var(--line); }
.empty h2, .empty h3 { font-size: 20px; }
.empty p, .field-help { color: var(--text); }
.empty .button { margin-top: 8px; }
.empty.compact { min-height: 176px; }
.empty-icon { display: grid; place-items: center; width: 40px; height: 40px; margin-bottom: 4px; border-radius: var(--radius); background: var(--raised); color: var(--muted); }
.catalog-empty { grid-template-columns: minmax(0, 1fr) minmax(160px, .7fr); align-items: center; justify-items: stretch; gap: 24px; min-height: 252px; padding: 32px clamp(24px, 5vw, 64px); text-align: left; }
.catalog-empty h3 { font-size: 24px; }
.empty-copy p { margin-top: 8px; }
.empty-copy .button { margin-top: 16px; }
.catalog-empty.is-searching { display: grid; grid-template-columns: 1fr; min-height: 176px; text-align: center; }
.is-searching .parcel { display: none; }
.parcel {
  position: relative;
  justify-self: center;
  width: 156px;
  height: 96px;
  margin-top: 24px;
  border: 1px solid #d5c8bb;
  border-radius: 0 0 8px 8px;
  background: #e8dbcc;
  box-shadow: 0 12px 20px -16px #403b33;
}
.parcel::before {
  content: "";
  position: absolute;
  inset: auto -1px 100%;
  height: 28px;
  clip-path: polygon(10% 0, 90% 0, 100% 100%, 0 100%);
  background: #d7c6b5;
}
.parcel::after { content: ""; position: absolute; inset: -28px auto auto 50%; width: 28px; height: 68px; transform: translateX(-50%); background: #b68264; }
.parcel-label { position: absolute; z-index: 1; bottom: 12px; right: 12px; width: 60px; padding: 8px; border: 1px solid #d5c8bb; border-radius: 4px; background: #fffcf6; }
.parcel-label i { display: block; width: 24px; height: 2px; margin-bottom: 4px; background: #8b8074; }
.parcel-label i:nth-child(2) { width: 16px; }
.parcel-label i:last-child { width: 100%; height: 8px; margin-bottom: 0; background: repeating-linear-gradient(90deg, #39352e 0 1px, transparent 1px 3px, #39352e 3px 5px, transparent 5px 7px); }

.selectors { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; padding: 20px 24px; margin-bottom: 24px; }
.formula { margin-top: 16px; padding: 12px 16px; border: 1px solid var(--line); border-radius: var(--radius); color: var(--text); }
.formula p { margin-top: 8px; }
.notice, .form-error, .quote-status { padding: 12px 16px; border: 1px solid var(--line); border-radius: var(--radius); }
.notice { margin-bottom: 16px; color: var(--success); background: var(--success-soft); }
.notice.error, .form-error, .quote-status.error { color: var(--danger); background: var(--danger-soft); }
.quote-status { margin-bottom: 16px; color: var(--text); background: var(--surface); }

label { display: block; min-width: 0; color: var(--text); font-size: 13px; font-weight: 600; }
input, textarea, select {
  display: block;
  width: 100%;
  min-width: 0;
  min-height: 40px;
  margin-top: 4px;
  padding: 8px 12px;
  border: 1px solid var(--control-line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font-size: 14px;
  font-weight: 400;
}
input:hover, textarea:hover, select:enabled:hover { border-color: var(--muted); }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 1; }
input[readonly] { background: var(--raised); }
textarea { resize: vertical; }

.select-control { display: block; position: relative; margin-block-start: 4px; }
.select-control > select {
  appearance: none;
  margin: 0;
  padding-inline-end: 40px;
  text-overflow: ellipsis;
}
.select-control > .icon {
  position: absolute;
  inset-block: 0;
  inset-inline-end: 12px;
  margin-block: auto;
  color: var(--muted);
  pointer-events: none;
}
.select-control > select:enabled:hover { background-color: var(--rail); }
.select-control > select:is(:focus-visible, :open) { border-color: var(--accent); }
.select-control > select:is(:focus-visible, :open) + .icon { color: var(--accent); }
.select-control > select:open + .icon { rotate: 180deg; }
.select-control > select:required:invalid { color: var(--muted); }
.select-control > select:disabled { background-color: var(--raised); color: var(--muted); cursor: default; }

@supports (appearance: base-select) and selector(select::picker(select)) {
  @media (hover: hover) and (pointer: fine) and (forced-colors: none) {
    .select-control > select, .select-control > select::picker(select) { appearance: base-select; }
    .select-control > select { display: flex; align-items: center; }
    .select-control > select::picker-icon { display: none; }
    .select-control > select::picker(select) {
      inline-size: anchor-size(self-inline);
      margin-block: 4px;
      padding: 4px;
      border: 1px solid var(--control-line);
      border-radius: var(--radius);
      background: var(--surface);
      color: var(--ink);
      box-shadow: 0 6px 20px rgb(26 29 24 / 10%);
      overscroll-behavior: contain;
    }
    .select-control option {
      min-block-size: 36px;
      padding: 4px 8px;
      border-radius: 4px;
      overflow-wrap: anywhere;
      cursor: pointer;
    }
    .select-control option:where(:enabled):hover { background-color: var(--raised); }
    .select-control option:checked { background-color: var(--accent-soft); color: var(--accent); }
    .select-control option:focus-visible { outline-offset: -2px; }
    .select-control option::checkmark { order: 1; margin-inline-start: auto; }
  }
}

@media (pointer: coarse) {
  .select-control > select { min-height: 44px; }
}

@media (forced-colors: active) {
  .select-control > select { appearance: auto; padding-inline-end: 12px; }
  .select-control > .icon { display: none; }
}

.login-view { display: grid; place-items: center; min-height: 100dvh; padding: 24px; }
.login-card { width: min(100%, 432px); padding: 32px; border: 1px solid var(--line); border-radius: var(--panel-radius); background: var(--surface); box-shadow: 0 8px 24px rgb(26 29 24 / 5%); }
.login-card h1 { margin-top: 32px; font-size: 28px; }
.login-intro { margin: 8px 0 24px; color: var(--text); }
.login-card button { justify-content: space-between; width: 100%; margin-top: 16px; }
.login-card .form-error { margin-top: 12px; }

dialog {
  width: min(880px, calc(100% - 32px));
  max-width: none;
  max-height: min(90dvh, 960px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--panel-radius);
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 12px 40px rgb(26 29 24 / 12%);
}
dialog::backdrop { background: rgb(26 29 24 / 42%); }
.market-dialog { width: min(608px, calc(100% - 32px)); }
.dialog-form { display: flex; flex-direction: column; max-height: min(90dvh - 2px, 958px); }
.dialog-header, .dialog-footer { display: flex; align-items: center; justify-content: space-between; flex: none; gap: 8px; padding: 12px 24px; }
.dialog-header { border-bottom: 1px solid var(--line); }
.dialog-header h2 { font-size: 22px; }
.dialog-footer { border-top: 1px solid var(--line); }
.footer-actions { display: flex; gap: 8px; margin-left: auto; }
.close-button { width: 36px; min-height: 36px; padding: 4px; color: var(--text); }
.section-nav { display: flex; flex: none; gap: 4px; padding: 4px 16px; border-bottom: 1px solid var(--line); background: var(--rail); }
.section-nav .button { min-height: 36px; padding-block: 4px; font-size: 13px; }
.dialog-body { overflow: auto; overscroll-behavior: contain; padding: 24px; scroll-padding-block: 16px; }
.dialog-error { margin: 0 24px 12px; overflow: auto; max-height: 24dvh; }
fieldset { margin: 0; padding: 0; border: 0; min-width: 0; }
.dialog-body > fieldset + fieldset { margin-top: 24px; }
.dialog-body > fieldset:focus { outline-offset: 4px; }
fieldset legend { padding: 0; margin-bottom: 12px; font-size: 15px; font-weight: 600; }
.fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; }
.market-dialog .field-help { margin-top: 12px; }
.exchange-toggle { display: flex; align-items: center; gap: 8px; min-height: 36px; margin-top: 12px; cursor: pointer; }
.exchange-toggle input { width: 16px; height: 16px; min-height: 0; margin: 0; padding: 0; accent-color: var(--accent); }
.span-all { grid-column: 1 / -1; }
.field-help { margin-bottom: 8px; font-size: 13px; }
.image-upload-tile { position: relative; width: 80px; height: 80px; }
.image-dropzone {
  display: grid;
  grid-template: minmax(0, 1fr) / minmax(0, 1fr);
  place-items: center;
  width: 100%;
  height: 100%;
  padding: 0;
  overflow: hidden;
  border: 1px dashed var(--control-line);
  border-radius: var(--radius);
  background: var(--rail);
  color: var(--text);
  font-size: 12px;
  transition: background-color 140ms var(--ease), border-color 140ms var(--ease);
}
.image-upload-prompt { display: grid; justify-items: center; gap: 4px; }
.image-dropzone:has(img:not([hidden])) { border-style: solid; border-color: var(--line); }
.image-dropzone img { display: block; width: 100%; height: 100%; grid-area: 1 / 1; object-fit: cover; }
.image-upload-replace {
  grid-area: 1 / 1;
  align-self: end;
  width: 100%;
  padding: 2px 0;
  background: var(--surface);
  color: var(--ink);
  opacity: 0;
}
.image-dropzone:is(:hover:enabled, :focus-visible) .image-upload-replace,
.image-upload-tile.is-dragging .image-upload-replace { opacity: 1; }
.image-dropzone:hover:enabled { border-color: var(--muted); background: var(--raised); }
.image-upload-tile.is-dragging .image-dropzone:enabled {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}
.image-upload-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface);
  color: var(--ink);
}
.image-upload-remove:hover:enabled { background: var(--raised); }
.image-filename { margin-top: 8px; color: var(--text); font-size: 13px; overflow-wrap: anywhere; }
.image-error { margin-top: 8px; }
.sku-block { margin-bottom: 12px; padding: 16px; border: 1px solid var(--line); border-radius: var(--panel-radius); background: var(--rail); }
.sku-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.sku-header .button { min-height: 36px; padding: 4px 8px; }
.sku-overrides { border-top: 1px solid var(--line); padding-top: 12px; }
.sku-overrides summary, .formula summary { width: fit-content; font-weight: 600; }
.sku-overrides .field-help { margin-top: 8px; }
.dimensions .fields { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.dimensions legend { margin-bottom: 4px; font-size: 13px; }

@media (max-width: 1080px) {
  .workspace { grid-template-columns: 184px minmax(0, 1fr); }
  main { padding-inline: 24px; }
  :where(#quote-table, #market-table) table { min-width: 688px; }
}

@media (max-width: 760px) {
  .workspace { display: block; }
  .sidebar { position: static; height: auto; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; padding: 12px 16px 8px; border: 0; border-bottom: 1px solid var(--line); }
  .sidebar .brand { margin: 0; }
  .sidebar .sidebar-action { margin-top: 0; }
  .sidebar nav { grid-row: 2; grid-column: 1 / -1; grid-template-columns: repeat(5, minmax(max-content, 1fr)); }
  .sidebar nav a { justify-content: center; gap: 4px; min-height: 44px; padding-inline: 4px; font-size: 13px; }
  .sidebar nav a[aria-current="page"]::before { inset: auto 16px 0; width: auto; height: 2px; }
  main { padding: 24px 16px 40px; }
  .page-header { gap: 12px; margin-bottom: 24px; }
  h1 { font-size: 28px; }
  .surface-bar { padding-inline: 16px; }
  .metrics > div { padding: 12px; }
  .metrics dd { font-size: 24px; }
  .selectors { padding: 16px; }
  .table-wrap { overflow: visible; }
  .table-wrap table, tbody { display: block; min-width: 0; }
  thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  tbody tr {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px 16px;
    padding: 16px;
    border-top: 1px solid var(--line);
  }
  .table-wrap tbody :is(td, th) { min-width: 0; padding: 0; border: 0; text-align: left; white-space: normal; overflow-wrap: anywhere; }
  tbody .row-heading, tbody .row-actions, .quote-setup { grid-column: 1 / -1; }
  .table-wrap tbody .row-actions { text-align: right; }
  td .button { min-height: 44px; }
  .table-label { display: block; margin-bottom: 4px; color: var(--muted); font-size: 12px; font-weight: 400; }
  #quote-rows td:has(.price-value) { grid-column: 1 / -1; }
  .price-value { font-size: 22px; }
}

@media (max-width: 480px) {
  .sidebar nav a { padding-inline: 2px; font-size: 12px; }
  .sidebar nav .icon { display: none; }
  .page-header { align-items: flex-start; flex-direction: column; }
  .button { min-height: 44px; }
  .metrics dt { font-size: 12px; }
  .metrics small { display: block; margin-top: 4px; }
  .surface-bar { padding-inline: 12px; }
  #products .surface-bar { flex-wrap: wrap; }
  .search { width: 100%; }
  .catalog-empty { grid-template-columns: minmax(0, 1fr); min-height: 0; padding: 24px; }
  .catalog-empty .parcel { grid-row: 1; justify-self: start; transform: scale(.64); transform-origin: left bottom; margin-top: -28px; }
  .is-searching { gap: 0; }
  .selectors { grid-template-columns: 1fr; gap: 12px; }
  .login-card { padding: 24px; }
  dialog { width: calc(100% - 16px); }
  .dialog-header, .dialog-footer, .dialog-body { padding-inline: 12px; }
  .dialog-error { margin-inline: 12px; }
  .section-nav { padding-inline: 4px; justify-content: space-between; }
  .section-nav .button { min-height: 44px; padding-inline: 8px; }
  .dialog-body input:not([type="checkbox"]), .dialog-body textarea, .dialog-body select, .login-card input { font-size: 16px; }
  .market-dialog .fields, .sku-block > .fields { grid-template-columns: 1fr; }
  .sku-block { padding: 12px; }
}

@media (max-height: 520px) {
  dialog { max-height: calc(100dvh - 16px); }
  .dialog-form { max-height: calc(100dvh - 18px); }
}

@media (prefers-reduced-motion: reduce) {
  .button, .sidebar nav a, input, select, textarea, .image-dropzone { transition: none; }
}
