:root {
  color-scheme: dark;
  --ink: #f3f6f7;
  --muted: #93a0aa;
  --faint: #66737e;
  --canvas: #0d1113;
  --surface: #141a1e;
  --surface-raised: #1a2227;
  --surface-soft: #202a30;
  --line: #2d3940;
  --line-strong: #41515b;
  --accent: #ef774b;
  --accent-strong: #ff8b61;
  --success: #52d59b;
  --warning: #e8b95e;
  --danger: #f4777d;
  --blue: #76a9fa;
  --radius-sm: 7px;
  --radius: 12px;
  --radius-lg: 18px;
  --sans: "Aptos", "Segoe UI Variable", "Segoe UI", sans-serif;
  --mono: "Cascadia Code", "SFMono-Regular", Consolas, monospace;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--canvas); scroll-behavior: smooth; }
body {
  margin: 0;
  min-width: 320px;
  min-height: 100dvh;
  color: var(--ink);
  background:
    radial-gradient(circle at 15% -10%, rgb(239 119 75 / .09), transparent 32rem),
    var(--canvas);
  font-family: var(--sans);
  font-size: 15px;
}
button, input, select, textarea { font: inherit; }
button { color: inherit; }
[hidden] { display: none !important; }
code, pre { font-family: var(--mono); }

.skip-link {
  position: fixed;
  top: 8px;
  left: 8px;
  z-index: 100;
  padding: 10px 14px;
  color: #111;
  background: var(--accent-strong);
  border-radius: var(--radius-sm);
  transform: translateY(-160%);
}
.skip-link:focus { transform: translateY(0); }

.shell { min-height: 100dvh; }
.topbar {
  min-height: 68px;
  display: grid;
  grid-template-columns: minmax(250px, .8fr) minmax(340px, 1.25fr) auto;
  align-items: center;
  gap: 18px;
  padding: 10px 24px;
  border-bottom: 1px solid var(--line);
  background: rgb(15 20 23 / .94);
  backdrop-filter: blur(16px);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 11px; min-width: 0; }
.brand-mark {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  color: #1b1715;
  background: var(--accent);
  border-radius: 9px 9px 9px 3px;
  font-weight: 800;
}
.brand strong { display: block; font-size: 15px; letter-spacing: -.01em; }
.brand small { display: block; margin-top: 2px; color: var(--muted); font-size: 12px; }
.target {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  height: 40px;
  padding: 0 13px;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: var(--radius);
}
.target span { color: var(--faint); font-size: 11px; text-transform: uppercase; letter-spacing: .08em; white-space: nowrap; }
.target code { min-width: 0; overflow: hidden; color: var(--muted); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.session-actions { display: flex; align-items: center; justify-content: end; gap: 8px; }
.session-state {
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}
.session-state.ready { color: var(--success); border-color: rgb(82 213 155 / .45); }

.workflow {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1px;
  max-width: 1500px;
  margin: 0 auto;
  padding: 18px 24px 0;
}
.workflow-step {
  min-height: 54px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  border: 0;
  border-bottom: 2px solid var(--line);
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  text-align: left;
  font-weight: 600;
  transition: color .2s ease, border-color .2s ease, background .2s ease;
}
.workflow-step span { color: var(--faint); font-family: var(--mono); font-size: 11px; }
.workflow-step:hover { color: var(--ink); background: rgb(255 255 255 / .02); }
.workflow-step.active { color: var(--ink); border-bottom-color: var(--accent); }
.workflow-step.completed span { color: var(--success); }

.workspace {
  width: min(1500px, 100%);
  min-height: calc(100dvh - 140px);
  display: grid;
  grid-template-columns: minmax(520px, .92fr) minmax(520px, 1.08fr);
  gap: 18px;
  margin: 0 auto;
  padding: 18px 24px 28px;
}
.workbench, .exchange {
  min-width: 0;
  border: 1px solid var(--line);
  background: rgb(20 26 30 / .88);
  box-shadow: 0 24px 70px rgb(0 0 0 / .2);
}
.workbench { border-radius: var(--radius-lg); overflow: hidden; }
.step-panel { min-height: 650px; padding: 30px; }
.panel-heading { max-width: 670px; margin-bottom: 26px; }
.panel-heading.compact { margin-bottom: 20px; }
.eyebrow { margin: 0 0 8px; color: var(--accent); font-size: 11px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; }
.panel-heading h1 { margin: 0; font-size: clamp(26px, 3vw, 38px); line-height: 1.05; letter-spacing: -.035em; }
.panel-heading p:last-child { max-width: 64ch; margin: 12px 0 0; color: var(--muted); line-height: 1.6; }
.panel-heading code { color: var(--blue); font-size: .9em; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.field-group { min-width: 0; display: grid; gap: 7px; }
.field-group.wide, .form-actions.wide { grid-column: 1 / -1; }
.field-group > span { color: #c6d0d5; font-size: 13px; font-weight: 600; }
.field-group small { color: var(--faint); line-height: 1.45; }
input, select, textarea {
  width: 100%;
  min-height: 43px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  outline: 0;
  color: var(--ink);
  background: #101619;
  padding: 10px 12px;
  transition: border-color .2s ease, box-shadow .2s ease;
}
textarea { resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgb(239 119 75 / .12); }
input::placeholder { color: #5f6a72; }
.inline-field { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
.form-actions { display: flex; justify-content: flex-start; padding-top: 4px; }

.button {
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 650;
  transition: transform .15s ease, background .2s ease, border-color .2s ease, color .2s ease;
}
.button:hover:not(:disabled) { transform: translateY(-1px); }
.button:active:not(:disabled) { transform: translateY(1px); }
.button:focus-visible, .workflow-step:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
.button:disabled { opacity: .45; cursor: not-allowed; }
.button.primary { min-height: 43px; color: #1d1714; background: var(--accent); }
.button.primary:hover:not(:disabled) { background: var(--accent-strong); }
.button.quiet { border-color: var(--line); color: var(--muted); background: var(--surface-raised); }
.button.quiet:hover:not(:disabled) { color: var(--ink); border-color: var(--line-strong); }
.button.quiet.danger:hover:not(:disabled) { color: var(--danger); border-color: rgb(244 119 125 / .55); }
.button.warning { min-height: 43px; color: #1d1911; background: var(--warning); }

.notice {
  margin-top: 24px;
  padding: 14px 16px;
  border-left: 3px solid var(--warning);
  color: #c8c0ad;
  background: rgb(232 185 94 / .08);
  line-height: 1.55;
  font-size: 13px;
}
.notice strong { color: #e6dac0; }
.notice code { color: var(--warning); }

.search-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; margin-bottom: 16px; }
.summary-line { margin-bottom: 10px; color: var(--muted); font-size: 13px; }
.product-list { display: grid; gap: 8px; }
.product-card {
  width: 100%;
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr) auto;
  gap: 13px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: inherit;
  background: #11171a;
  text-align: left;
  cursor: pointer;
  transition: border-color .2s ease, background .2s ease, transform .15s ease;
}
.product-card:hover { border-color: var(--line-strong); background: #182126; transform: translateX(2px); }
.product-card.selected { border-color: var(--accent); background: rgb(239 119 75 / .07); }
.product-card img { width: 58px; height: 58px; display: block; object-fit: contain; border-radius: 8px; background: #edf0ed; }
.product-card strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.product-meta { display: flex; flex-wrap: wrap; gap: 7px 12px; margin-top: 6px; color: var(--muted); font-size: 12px; }
.company-tag { color: var(--blue); font-family: var(--mono); }
.stock.in { color: var(--success); }
.stock.out { color: var(--danger); }
.product-price { color: var(--ink); font-variant-numeric: tabular-nums; font-weight: 700; white-space: nowrap; }
.pager { display: flex; align-items: center; justify-content: center; gap: 12px; margin-top: 16px; color: var(--muted); font-size: 12px; }

.selected-product {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  margin-bottom: 20px;
  padding: 14px 16px;
  border: 1px solid rgb(118 169 250 / .35);
  border-radius: var(--radius);
  background: rgb(118 169 250 / .07);
}
.selected-product.empty { color: var(--muted); border-color: var(--line); background: var(--surface); }
.selected-product strong { display: block; margin-bottom: 4px; }
.selected-product small { color: var(--muted); }
.selected-product b { font-variant-numeric: tabular-nums; }

.tracking-search { margin-bottom: 18px; }
.tracking-overview {
  min-height: 128px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #11171a;
}
.tracking-overview.empty { display: grid; place-items: center; color: var(--muted); }
.tracking-stat { min-width: 0; }
.tracking-stat span { display: block; margin-bottom: 5px; color: var(--faint); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; }
.tracking-stat strong { display: block; overflow-wrap: anywhere; }
.retry-box { margin-top: 18px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.retry-box summary { padding: 14px 16px; color: var(--warning); cursor: pointer; font-weight: 650; }
.retry-form { padding: 4px 16px 18px; }

.exchange {
  min-height: 650px;
  display: grid;
  grid-template-rows: auto auto minmax(150px, .7fr) minmax(240px, 1.3fr);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.exchange-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.exchange-heading .eyebrow { display: block; margin-bottom: 4px; }
.exchange-heading strong { display: block; }
.exchange-meta { min-width: 0; display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto; gap: 10px; align-items: center; padding: 10px 20px; border-bottom: 1px solid var(--line); color: var(--muted); font-family: var(--mono); font-size: 11px; }
.exchange-meta code { overflow: hidden; color: var(--blue); text-overflow: ellipsis; white-space: nowrap; }
.exchange-meta .ok { color: var(--success); }
.exchange-meta .error { color: var(--danger); }
.exchange-block { min-height: 0; display: grid; grid-template-rows: auto minmax(0, 1fr); border-bottom: 1px solid var(--line); }
.exchange-block:last-child { border-bottom: 0; }
.exchange-label { padding: 9px 20px; color: var(--faint); background: var(--surface-raised); font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.exchange pre { min-height: 0; margin: 0; padding: 16px 20px; overflow: auto; color: #d8e1e5; background: #101517; font-size: 12px; line-height: 1.6; white-space: pre-wrap; overflow-wrap: anywhere; }

.empty-state { padding: 32px 20px; color: var(--muted); text-align: center; border: 1px dashed var(--line); border-radius: var(--radius); }
.loading-row { padding: 18px; color: var(--muted); background: linear-gradient(90deg, transparent, rgb(255 255 255 / .03), transparent); background-size: 200% 100%; animation: loading 1.2s linear infinite; }
@keyframes loading { to { background-position: -200% 0; } }

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 50;
  max-width: min(430px, calc(100vw - 44px));
  padding: 12px 15px;
  border: 1px solid var(--line-strong);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  color: var(--ink);
  background: #222c31;
  box-shadow: 0 20px 60px rgb(0 0 0 / .45);
  line-height: 1.45;
}
.toast.error { border-left-color: var(--danger); }

@media (max-width: 1120px) {
  .topbar { grid-template-columns: minmax(240px, 1fr) auto; }
  .target { grid-column: 1 / -1; grid-row: 2; }
  .workspace { grid-template-columns: 1fr; }
  .exchange { min-height: 720px; }
}
@media (max-width: 720px) {
  .topbar { position: static; grid-template-columns: 1fr; padding: 12px 16px; }
  .target { grid-column: auto; grid-row: auto; }
  .session-actions { justify-content: flex-start; flex-wrap: wrap; }
  .workflow { padding: 10px 14px 0; overflow-x: auto; }
  .workflow-step { min-width: 145px; }
  .workspace { padding: 14px; }
  .step-panel { min-height: auto; padding: 22px 18px 28px; }
  .form-grid { grid-template-columns: 1fr; }
  .field-group.wide, .form-actions.wide { grid-column: auto; }
  .product-card { grid-template-columns: 48px minmax(0, 1fr); }
  .product-card img { width: 48px; height: 48px; }
  .product-price { grid-column: 2; }
  .selected-product { grid-template-columns: 1fr; }
  .exchange-meta { grid-template-columns: auto minmax(0, 1fr); }
  .tracking-overview { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; scroll-behavior: auto !important; transition: none !important; }
}

