:root {
  --bg: #f3f5f7;
  --card: #ffffff;
  --text: #17202a;
  --muted: #667085;
  --muted-2: #98a2b3;
  --line: #e4e7ec;
  --line-soft: #eef1f4;
  --brand: #0f766e;
  --brand-dark: #115e59;
  --brand-soft: #ecfdf5;
  --green: #067647;
  --green-soft: #ecfdf3;
  --amber: #b54708;
  --amber-soft: #fffaeb;
  --red: #b42318;
  --red-soft: #fef3f2;
  --blue: #175cd3;
  --blue-soft: #eff8ff;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 8px 24px rgba(16, 24, 40, .05);
  --radius: 16px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background:
    radial-gradient(1100px 420px at 12% -10%, rgba(15, 118, 110, .08), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea { font: inherit; }
button { cursor: pointer; }
code { font-family: var(--mono); font-size: .92em; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); }

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 14px 30px;
  background: rgba(255, 255, 255, .9);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo {
  width: 38px; height: 38px; border-radius: 11px;
  display: grid; place-items: center;
  background: linear-gradient(145deg, #0f766e, #115e59);
  color: #fff; font-weight: 800; font-size: 20px;
  box-shadow: 0 4px 12px rgba(15, 118, 110, .25);
}
.brand-name { font-weight: 750; font-size: 15px; letter-spacing: -.01em; }
.brand-name span { color: var(--muted); font-weight: 500; }
.brand-sub { color: var(--muted-2); font-size: 11px; margin-top: 1px; }
.top-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.updated { color: var(--muted); font-size: 12px; white-space: nowrap; }

.mode-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 9px; border-radius: 999px;
  font-size: 11px; font-weight: 650;
  background: var(--amber-soft); color: var(--amber);
  border: 1px solid #fedf89;
}
.mode-badge.live { background: var(--green-soft); color: var(--green); border-color: #abefc6; }
.mode-badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 13px;
  border-radius: 9px; border: 1px solid transparent;
  font-size: 13px; font-weight: 600;
  transition: background .15s ease, border-color .15s ease, transform .1s ease;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--brand); color: #fff; box-shadow: 0 1px 2px rgba(15, 118, 110, .25); }
.btn-primary:hover { background: var(--brand-dark); }
.btn-ghost { background: #fff; color: var(--text); border-color: var(--line); }
.btn-ghost:hover { background: #f9fafb; border-color: #d0d5dd; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn svg { flex: none; }
.btn.spinning svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.page { max-width: 1480px; margin: 0 auto; padding: 24px 30px 56px; }
.hero { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; padding: 8px 2px 20px; }
.hero h1 { margin: 0; font-size: 28px; line-height: 1.2; letter-spacing: -.025em; }
.hero p { margin: 7px 0 0; color: var(--muted); font-size: 13px; max-width: 830px; }
.hero-note { color: var(--muted); font-size: 12px; text-align: right; max-width: 340px; }

.banner { border-radius: 12px; padding: 11px 14px; margin: 0 0 16px; font-size: 13px; border: 1px solid; }
.banner-error { background: var(--red-soft); border-color: #fecdca; color: var(--red); }
.banner-warn { background: var(--amber-soft); border-color: #fedf89; color: var(--amber); }
.banner ul { margin: 6px 0 0; padding-left: 18px; }

.kpis { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; margin-bottom: 18px; }
.kpi {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 14px 16px; box-shadow: var(--shadow); min-width: 0;
}
.kpi-label { color: var(--muted); font-size: 11px; font-weight: 600; letter-spacing: .02em; }
.kpi-value { font-size: 25px; font-weight: 750; letter-spacing: -.03em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi-sub { color: var(--muted-2); font-size: 11px; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi.accent .kpi-value { color: var(--brand); }
.kpi.warn .kpi-value { color: var(--amber); }
.kpi.danger .kpi-value { color: var(--red); }

.toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.search {
  display: flex; align-items: center; gap: 8px;
  height: 38px; min-width: 300px; flex: 1; max-width: 440px;
  padding: 0 12px; background: #fff; border: 1px solid var(--line); border-radius: 10px;
  color: var(--muted);
}
.search:focus-within { border-color: #99f6e4; box-shadow: 0 0 0 3px rgba(15, 118, 110, .1); }
.search input { border: 0; outline: 0; background: transparent; width: 100%; color: var(--text); font-size: 13px; }
.segmented { display: inline-flex; background: #e9edf1; border-radius: 10px; padding: 3px; gap: 2px; }
.segmented button {
  border: 0; background: transparent; color: var(--muted);
  height: 30px; padding: 0 12px; border-radius: 8px; font-size: 12px; font-weight: 600;
}
.segmented button.active { background: #fff; color: var(--text); box-shadow: 0 1px 3px rgba(16, 24, 40, .12); }
.toolbar-right { margin-left: auto; color: var(--muted); font-size: 12px; }

.regions { display: flex; flex-direction: column; gap: 18px; }
.panel {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; padding: 18px 20px 12px; }
.panel-title { display: flex; align-items: center; gap: 12px; min-width: 0; }
.region-icon {
  width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center;
  font-weight: 800; font-size: 15px; flex: none;
}
.region-icon.global { background: var(--brand-soft); color: var(--brand); }
.region-icon.us { background: var(--blue-soft); color: var(--blue); }
.panel-title h2 { margin: 0; font-size: 17px; letter-spacing: -.01em; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.panel-title p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.pill {
  display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 999px;
  font-size: 10px; font-weight: 650; background: #f2f4f7; color: var(--muted); letter-spacing: .01em;
}
.panel-stats { display: flex; gap: 18px; flex-wrap: wrap; justify-content: flex-end; }
.panel-stat { min-width: 72px; text-align: right; }
.panel-stat .label { color: var(--muted-2); font-size: 10px; font-weight: 600; }
.panel-stat .value { font-size: 17px; font-weight: 720; font-variant-numeric: tabular-nums; margin-top: 1px; }
.panel-stat .value.brand { color: var(--brand); }
.panel-stat .value.up { color: var(--green); }
.panel-stat .value.down { color: var(--red); }

.formula-line {
  margin: 0 20px 12px; padding: 8px 11px; border-radius: 9px;
  background: #f8fafc; border: 1px dashed #dbe2e8;
  color: var(--muted); font-size: 11.5px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
}
.formula-line code { color: var(--brand); background: #ecfdf5; padding: 1px 6px; border-radius: 5px; }
.formula-line .edit { margin-left: auto; color: var(--brand); font-weight: 600; cursor: pointer; border: 0; background: none; font-size: 11.5px; }

.table-wrap { overflow: auto; max-height: 72vh; }
table { width: 100%; border-collapse: separate; border-spacing: 0; min-width: 1020px; }
th {
  position: sticky; top: 0; z-index: 3;
  padding: 9px 12px; background: #f8fafc;
  border-top: 1px solid var(--line-soft); border-bottom: 1px solid var(--line);
  color: var(--muted); font-size: 11px; font-weight: 650; text-align: left; white-space: nowrap;
}
th.num, td.num { text-align: right; }
th.col-final { background: #ecfdf5; color: var(--brand-dark); }
td {
  padding: 10px 12px; border-bottom: 1px solid var(--line-soft);
  vertical-align: middle; font-size: 13px;
}
tbody tr:hover td { background: #fbfdfc; }
tbody tr:last-child td { border-bottom: 0; }
td.col-final { background: #f7fefb; }
tbody tr:hover td.col-final { background: #f0fdf9; }
.product-cell { min-width: 310px; max-width: 380px; vertical-align: top; padding-top: 12px; }
.product-inner { display: flex; align-items: flex-start; gap: 10px; min-width: 0; }
.thumb {
  width: 38px; height: 38px; border-radius: 9px; object-fit: cover;
  background: #f2f4f7; border: 1px solid var(--line); flex: none;
}
.thumb.placeholder { display: grid; place-items: center; color: var(--muted-2); font-weight: 700; }
.p-name { font-size: 12.5px; font-weight: 650; line-height: 1.35; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.v-name { color: var(--muted); font-size: 11px; margin-top: 2px; line-height: 1.3; }
.sku { font-family: var(--mono); font-size: 11.5px; color: #475467; white-space: nowrap; }
.num-main { font-weight: 650; font-variant-numeric: tabular-nums; }
.num-main.strong { font-size: 14px; }
.num-main.brand { color: var(--brand); }
.num-main.amber { color: var(--amber); }
.num-sub { color: var(--muted-2); font-size: 10px; margin-top: 1px; font-variant-numeric: tabular-nums; }
.zero { color: #c4c9d1; }
.delta-wrap { display: inline-flex; flex-direction: column; align-items: flex-end; gap: 1px; }
.delta { display: inline-flex; justify-content: center; min-width: 54px; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 700; font-variant-numeric: tabular-nums; }
.delta.up { background: var(--green-soft); color: var(--green); }
.delta.down { background: var(--red-soft); color: var(--red); }
.delta.flat { background: #f2f4f7; color: var(--muted); }
.delta-label { color: var(--muted-2); font-size: 9.5px; }
.status { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 999px; font-size: 10.5px; font-weight: 650; white-space: nowrap; }
.status-ok { background: var(--green-soft); color: var(--green); }
.status-low { background: var(--amber-soft); color: var(--amber); }
.status-out { background: var(--red-soft); color: var(--red); }
.status-empty { background: #f2f4f7; color: var(--muted); }
.empty { padding: 34px 20px; color: var(--muted); text-align: center; font-size: 13px; }

.footer { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-top: 18px; color: var(--muted-2); font-size: 11px; }

.overlay { position: fixed; inset: 0; background: rgba(15, 23, 42, .34); z-index: 90; backdrop-filter: blur(2px); }
.drawer {
  position: fixed; top: 0; right: 0; z-index: 100;
  width: 540px; max-width: 94vw; height: 100vh;
  background: #fff; box-shadow: -20px 0 60px rgba(16, 24, 40, .18);
  display: flex; flex-direction: column;
}
.drawer-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 20px 22px 14px; border-bottom: 1px solid var(--line); }
.drawer-head h2 { margin: 0; font-size: 18px; letter-spacing: -.02em; }
.drawer-head p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.icon-btn { width: 32px; height: 32px; border: 1px solid var(--line); background: #fff; border-radius: 8px; font-size: 20px; line-height: 1; color: var(--muted); }
.icon-btn:hover { background: #f9fafb; }
.drawer-body { padding: 16px 22px; overflow: auto; flex: 1; }
.drawer-foot { display: flex; justify-content: space-between; gap: 10px; padding: 14px 22px; border-top: 1px solid var(--line); background: #fbfcfd; }
.region-tabs { display: inline-flex; background: #e9edf1; border-radius: 10px; padding: 3px; gap: 2px; margin-bottom: 16px; }
.region-tabs button { border: 0; background: transparent; color: var(--muted); height: 30px; padding: 0 14px; border-radius: 8px; font-size: 12px; font-weight: 650; }
.region-tabs button.active { background: #fff; color: var(--text); box-shadow: 0 1px 3px rgba(16, 24, 40, .12); }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; min-width: 0; }
.field > span { color: #344054; font-size: 12px; font-weight: 650; }
.field input, .field textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 9px;
  padding: 9px 11px; background: #fff; color: var(--text); outline: none;
}
.field textarea { font-family: var(--mono); font-size: 12.5px; line-height: 1.6; resize: vertical; }
.field input:focus, .field textarea:focus { border-color: #99f6e4; box-shadow: 0 0 0 3px rgba(15, 118, 110, .1); }
.field input:disabled { background: #f9fafb; color: var(--muted); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: -4px 0 14px; }
.chip { border: 1px solid #dbe2e8; background: #f8fafc; color: #475467; border-radius: 7px; padding: 3px 7px; font-family: var(--mono); font-size: 10.5px; }
.chip:hover { background: #ecfdf5; border-color: #99f6e4; color: var(--brand-dark); }
.hint { color: var(--muted); font-size: 11px; line-height: 1.6; margin: 0 0 16px; }
.preview-head { display: flex; align-items: center; justify-content: space-between; margin: 4px 0 8px; }
.preview-head h3 { margin: 0; font-size: 13px; }
.preview { border: 1px solid var(--line); border-radius: 10px; overflow: auto; margin-bottom: 16px; min-height: 80px; }
.preview table { min-width: 0; width: 100%; }
.preview th, .preview td { padding: 7px 9px; font-size: 11px; }
.preview th { position: static; background: #f8fafc; }
.preview .err { color: var(--red); font-size: 11px; padding: 10px; }
.preview-empty { margin: 0; padding: 10px; color: var(--muted); font-size: 12px; }
body.no-scroll { overflow: hidden; }
.skeleton { position: relative; overflow: hidden; }
.skeleton::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, rgba(15, 118, 110, .07), transparent);
  animation: shimmer 1.4s infinite;
}
@keyframes shimmer { from { transform: translateX(-100%); } to { transform: translateX(100%); } }
.skeleton-line { height: 11px; border-radius: 6px; background: #eef1f4; margin: 9px 0; }
.skeleton-line.short { width: 42%; }
.skeleton-line.big { width: 64%; height: 22px; }
.skeleton-panel { padding: 48px 20px; text-align: center; color: var(--muted); font-size: 13px; }

.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
  z-index: 200; background: #101828; color: #fff; border-radius: 10px;
  padding: 10px 16px; font-size: 12.5px; box-shadow: 0 12px 30px rgba(16, 24, 40, .25);
  max-width: 90vw; text-align: center;
}
.toast.error { background: var(--red); }

@media (max-width: 1240px) {
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .panel-head { flex-direction: column; }
  .panel-stats { justify-content: flex-start; }
}
@media (max-width: 820px) {
  .topbar { padding: 12px 16px; align-items: flex-start; }
  .page { padding: 18px 16px 42px; }
  .hero { flex-direction: column; align-items: flex-start; }
  .hero-note { text-align: left; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .search { min-width: 0; width: 100%; max-width: none; }
  .toolbar-right { margin-left: 0; }
  .drawer { width: 100%; }
}
