:root {
  --bg: #f3f6f4;
  --panel: #ffffff;
  --panel-soft: #f7faf8;
  --ink: #111827;
  --muted: #64748b;
  --line: #dbe3dd;
  --deep: #17251f;
  --deep-2: #22352c;
  --sales: #f97316;
  --orders: #16a34a;
  --accent: #0f766e;
  --danger: #b42318;
  --shadow: 0 14px 34px rgba(23, 37, 31, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(15, 118, 110, 0.08) 0%, transparent 290px),
    var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
  transition:
    opacity 140ms ease,
    transform 140ms ease,
    border-color 140ms ease,
    background 140ms ease,
    color 140ms ease;
}

button:hover,
a.hero-link:hover,
a.download-button:hover {
  opacity: 0.9;
}

button:active {
  transform: scale(0.95);
}

h1,
h2,
p {
  margin-top: 0;
}

.board-shell,
.settings-shell {
  width: min(1500px, calc(100% - 36px));
  margin: 0 auto;
  padding: 20px 0 40px;
}

.settings-shell {
  width: min(1180px, calc(100% - 36px));
}

.board-hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 18px;
  padding: 18px;
  margin-bottom: 12px;
  border: 1px solid rgba(23, 37, 31, 0.08);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.hero-main {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 14px;
}

.brand-mark {
  display: grid;
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 8px;
  background: var(--deep);
  color: #f8fafc;
  font-size: 20px;
  font-weight: 900;
}

h1 {
  margin-bottom: 4px;
  color: #0f1f19;
  font-size: clamp(26px, 3vw, 38px);
  line-height: 1.05;
  letter-spacing: 0;
}

.lede {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.hero-side {
  display: flex;
  align-items: center;
  justify-content: end;
  gap: 10px;
}

.latest-fetch-time {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.hero-action,
.hero-link,
.ghost-button {
  min-height: 40px;
  padding: 9px 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--deep);
  text-decoration: none;
  box-shadow: 0 6px 16px rgba(15, 23, 42, 0.05);
}

.hero-action {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border-color: rgba(249, 115, 22, 0.38);
  background: #fff7ed;
  color: #9a3412;
  font-weight: 900;
}

.hero-action:disabled {
  cursor: wait;
  opacity: 0.92;
}

.hero-link {
  display: inline-flex;
  align-items: center;
  color: var(--accent);
  font-weight: 800;
}

.fetch-status-icon {
  position: relative;
  display: none;
  width: 16px;
  height: 16px;
  border-radius: 999px;
}

.fetch-status-icon.is-running,
.fetch-status-icon.is-success,
.fetch-status-icon.is-error {
  display: inline-grid;
  place-items: center;
}

.fetch-status-icon.is-running {
  border: 2px solid #fed7aa;
  border-top-color: var(--sales);
  animation: spin 800ms linear infinite;
}

.fetch-status-icon.is-success {
  background: #16a34a;
}

.fetch-status-icon.is-success::after {
  content: "";
  width: 8px;
  height: 5px;
  border-left: 2px solid #fff;
  border-bottom: 2px solid #fff;
  transform: rotate(-45deg);
}

.fetch-status-icon.is-error {
  background: #dc2626;
}

.fetch-status-icon.is-error::after {
  content: "!";
  color: #fff;
  font-size: 11px;
  font-weight: 900;
  line-height: 1;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.command-band {
  display: grid;
  grid-template-columns: 190px minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 12px;
  padding: 14px;
  margin-bottom: 12px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--deep) 0%, var(--deep-2) 100%);
  box-shadow: var(--shadow);
}

.eyebrow,
.panel-tag,
.command-label,
.summary-card span {
  display: inline-block;
  margin: 0 0 6px;
  color: #0f766e;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0;
}

.command-label {
  color: #99f6e4;
}

.scope-block strong {
  display: block;
  overflow-wrap: anywhere;
  color: #f8fafc;
  font-size: 24px;
  line-height: 1.1;
}

.shop-strip {
  display: flex;
  min-width: 0;
  gap: 8px;
  overflow-x: auto;
}

.shop-chip,
.range-pills button {
  min-height: 36px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
  color: #dbeafe;
  font-size: 13px;
  font-weight: 800;
}

.shop-chip {
  max-width: 160px;
  min-width: 84px;
  padding: 8px 10px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.shop-chip.is-active,
.range-pills button.is-active {
  border-color: transparent;
  background: #ccfbf1;
  color: var(--deep);
}

#shop-select {
  display: none;
}

.range-pills {
  display: flex;
  gap: 8px;
  flex-wrap: nowrap;
}

.range-pills button {
  padding: 8px 12px;
  white-space: nowrap;
}

.summary-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr)) minmax(170px, 0.72fr);
  gap: 12px;
  margin-bottom: 12px;
}

.summary-card,
.chart-panel,
.settings-panel,
.card,
.modal-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.summary-card {
  position: relative;
  min-width: 0;
  padding: 15px;
  overflow: hidden;
}

.summary-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 100%;
  background: #94a3b8;
}

.summary-sales::before {
  background: var(--sales);
}

.summary-orders::before {
  background: var(--orders);
}

.summary-card strong {
  display: block;
  margin: 6px 0;
  overflow: hidden;
  font-size: clamp(24px, 3vw, 42px);
  line-height: 1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.summary-card small,
.meta {
  color: var(--muted);
  font-size: 13px;
}

.summary-toggle-card {
  display: grid;
  align-content: start;
  gap: 10px;
}

.metric-switch {
  display: grid;
  gap: 8px;
}

.metric-switch button {
  min-height: 36px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--deep);
  font-size: 13px;
  font-weight: 900;
  transition: opacity 140ms ease, transform 140ms ease, border-color 140ms ease, background 140ms ease;
}

.metric-switch button:hover {
  opacity: 0.9;
}

.metric-switch button:active {
  transform: scale(0.95);
}

.metric-switch button.is-active {
  border-color: transparent;
  background: #c1fbd4;
  color: #0f1f19;
}

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

.charts-pair[hidden],
.sku-panel[hidden] {
  display: none;
}

.overview-dashboard {
  display: grid;
  gap: 12px;
}

.overview-dashboard[hidden] {
  display: none;
}

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

.chart-panel {
  min-width: 0;
  padding: 16px;
}

.sales-panel {
  border-top: 4px solid var(--sales);
}

.orders-panel {
  border-top: 4px solid var(--orders);
}

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

.panel-heading h2 {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 0;
  font-size: clamp(19px, 2.4vw, 27px);
  line-height: 1.08;
}

.panel-total {
  color: var(--muted);
  font-size: 0.68em;
  font-weight: 900;
}

.panel-chip,
.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 5px 9px;
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.sales-chip {
  color: #9a3412;
  background: #ffedd5;
}

.orders-chip,
.status-pill.is-active {
  color: #166534;
  background: #dcfce7;
}

.sku-chip {
  color: #0f1f19;
  background: #c1fbd4;
}

.status-pill.is-disabled {
  color: #92400e;
  background: #fef3c7;
}

.status-pill.is-danger {
  color: var(--danger);
  background: #fee2e2;
}

.chart-shell {
  min-height: 0;
}

.chart-svg {
  width: 100%;
  height: auto;
  overflow: visible;
}

.grid-line {
  stroke: rgba(17, 24, 39, 0.08);
  stroke-width: 1;
}

.grid-label,
.axis-label {
  fill: rgba(17, 24, 39, 0.52);
  font-size: 11px;
}

.bar-point .tooltip {
  opacity: 0;
  pointer-events: none;
  transition: opacity 120ms ease;
}

.bar-point.is-hovered .tooltip {
  opacity: 1;
}

.tooltip rect {
  fill: rgba(17, 24, 39, 0.92);
}

.tooltip text {
  fill: #fff;
  font-size: 12px;
}

.empty-state {
  display: grid;
  min-height: 240px;
  place-items: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
}

.sku-panel {
  border-top: 4px solid var(--accent);
}

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

.sku-row {
  display: grid;
  grid-template-columns: 42px minmax(150px, 220px) minmax(0, 1fr);
  gap: 14px;
  align-items: center;
  min-height: 118px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfb;
}

.sku-rank {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border-radius: 999px;
  background: var(--deep);
  color: #fff;
  font-size: 13px;
  font-weight: 900;
}

.sku-product {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  min-width: 0;
}

.sku-image-link {
  display: grid;
  width: 72px;
  height: 72px;
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  text-decoration: none;
}

.sku-image-link img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.sku-image-placeholder {
  padding: 8px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-align: center;
}

.sku-product-meta {
  display: grid;
  gap: 2px;
  min-width: 0;
  font-size: 12px;
}

.sku-product-meta span {
  color: var(--muted);
  font-weight: 800;
}

.sku-product-meta a,
.sku-product-meta > span:nth-child(2),
.sku-product-meta > span:nth-child(4) {
  overflow: hidden;
  color: var(--deep);
  font-weight: 900;
  text-overflow: ellipsis;
  text-decoration: none;
  white-space: nowrap;
}

.sku-product-meta a:hover {
  text-decoration: underline;
}

.sku-bar-area {
  display: grid;
  gap: 9px;
  min-width: 0;
}

.sku-name {
  overflow: hidden;
  color: #0f1f19;
  font-size: 14px;
  font-weight: 900;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sku-bar-track {
  position: relative;
  height: 18px;
  overflow: hidden;
  border-radius: 999px;
  background: #e2e8f0;
}

.sku-bar-track span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent) 0%, #c1fbd4 100%);
}

.sku-row-metrics {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  align-items: baseline;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.sku-row-metrics strong {
  color: #0f1f19;
  font-size: 18px;
}

/* Settings page */
.settings-body {
  background:
    linear-gradient(180deg, rgba(23, 37, 31, 0.08) 0%, transparent 260px),
    #eef2f0;
}

.settings-topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 18px;
  padding: 20px;
  margin-bottom: 14px;
  border-radius: 8px;
  color: #f8fafc;
  background: linear-gradient(135deg, #17251f 0%, #243a30 100%);
  box-shadow: var(--shadow);
}

.settings-topbar .eyebrow {
  color: #99f6e4;
}

.settings-topbar h1 {
  margin: 0;
  color: #fff;
  font-size: clamp(32px, 4vw, 50px);
}

.settings-topbar .hero-link {
  align-self: start;
  border-color: rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  box-shadow: none;
}

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

.section-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.section-head h2 {
  margin-bottom: 0;
  font-size: 24px;
}

.section-copy {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.count-pill {
  min-height: 30px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f8fafc;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}

.settings-inline-form {
  display: grid;
  grid-template-columns: minmax(220px, 320px) auto 1fr;
  align-items: end;
  gap: 12px;
}

.settings-inline-form label,
.stack label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

input,
.settings-panel select {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fff;
  color: var(--ink);
  outline: none;
  transition:
    border-color 140ms ease,
    box-shadow 140ms ease;
}

input:focus,
.settings-panel select:focus,
#shop-select:focus {
  border-color: #4f46e5;
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.18);
}

.settings-inline-form button,
.settings-actions button,
.stack button,
.card-actions button,
.logs-summary button {
  min-height: 38px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
}

.settings-actions {
  display: flex;
  justify-content: flex-start;
  padding-top: 12px;
  margin-top: 10px;
  border-top: 1px solid var(--line);
}

.stack {
  display: grid;
  gap: 10px;
}

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

.store-table {
  display: grid;
  gap: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.store-header,
.store-row {
  display: grid;
  grid-template-columns: minmax(180px, 1.2fr) minmax(220px, 1.4fr) minmax(130px, 0.7fr) auto;
  gap: 14px;
}

.store-header {
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: #f8fafc;
  color: #64748b;
  font-size: 12px;
  font-weight: 900;
}

.store-row {
  align-items: center;
  min-height: 72px;
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
}

.store-row:last-child {
  border-bottom: 0;
}

.store-row:hover {
  background: #fbfdfb;
}

.store-main,
.store-accounts,
.store-state {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.store-main strong,
.log-row strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.store-accounts span {
  overflow: hidden;
  color: #334155;
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.row-actions button {
  min-height: 34px;
  padding: 7px 10px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #fff;
  color: #1e293b;
  font-weight: 800;
}

.row-actions button:disabled {
  border-color: #e2e8f0;
  background: #f8fafc;
  color: #94a3b8;
  cursor: not-allowed;
}

.row-actions .danger-button,
.card-actions .danger-button {
  border-color: #fecaca;
  background: #fff;
  color: var(--danger);
}

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

.test-result {
  min-height: 38px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 13px;
}

.test-result.is-running {
  color: #0f766e;
  background: #ccfbf1;
}

.test-result.is-success {
  color: #166534;
  background: #dcfce7;
}

.test-result.is-error {
  color: var(--danger);
  background: #fee2e2;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(17, 24, 39, 0.45);
}

.modal-backdrop[hidden] {
  display: none;
}

.modal-card {
  width: min(520px, 100%);
  max-height: min(760px, calc(100vh - 36px));
  overflow: auto;
  padding: 18px;
}

.modal-wide {
  width: min(860px, 100%);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

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

.icon-button {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--ink);
  font-size: 22px;
  line-height: 1;
}

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.modal-actions .link-button {
  border-color: #d0d7e2;
  background: #f8fafc;
  color: var(--accent);
}

.modal-actions button:disabled {
  border-color: #d0d7e2;
  background: #e5e7eb;
  color: #94a3b8;
  cursor: not-allowed;
}

.logs-action {
  display: flex;
  flex-wrap: wrap;
  justify-content: end;
  gap: 8px;
}

.logs-action span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.download-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 8px 11px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 900;
  text-decoration: none;
}

.log-list {
  display: grid;
  gap: 0;
  margin-top: 4px;
}

.log-row {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(160px, 0.9fr) minmax(190px, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 11px 0;
  border-top: 1px solid var(--line);
}

.log-error {
  grid-column: 1 / -1;
  padding: 8px 10px;
  border-radius: 8px;
  background: #fef2f2;
  color: var(--danger);
  font-size: 13px;
}

.empty-inline {
  margin: 0;
  padding: 18px;
  color: var(--muted);
  text-align: center;
}

.cards {
  display: grid;
  gap: 10px;
}

.card {
  padding: 14px;
}

.shop-card > div:first-child,
.log-card > div:first-child,
.card-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

@media (max-width: 1180px) {
  .command-band {
    grid-template-columns: 1fr;
  }

  .shop-strip {
    display: none;
  }

  #shop-select {
    display: block;
    width: 100%;
    min-height: 40px;
    padding: 9px 12px;
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.08);
    color: #f8fafc;
  }

  #shop-select option {
    color: #111827;
  }
}

@media (max-width: 900px) {
  .summary-row,
  .charts-pair,
  .overview-shop {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 820px) {
  .settings-topbar,
  .section-head {
    align-items: start;
    grid-template-columns: 1fr;
  }

  .form-grid,
  .settings-inline-form {
    grid-template-columns: 1fr;
    width: 100%;
  }

  .settings-topbar .hero-link {
    justify-self: start;
  }

  .section-head {
    display: grid;
  }

  .store-header {
    display: none;
  }

  .store-row,
  .log-row,
  .sku-row {
    grid-template-columns: 1fr;
  }

  .row-actions {
    justify-content: start;
  }

  .logs-action {
    justify-items: start;
    justify-content: start;
  }
}

@media (max-width: 640px) {
  .board-shell,
  .settings-shell {
    width: min(100% - 20px, 1440px);
    padding-top: 14px;
  }

  .board-hero,
  .hero-side,
  .summary-row,
  .charts-pair,
  .overview-shop {
    grid-template-columns: 1fr;
  }

  .hero-side {
    justify-content: start;
    flex-wrap: wrap;
  }

  .range-pills {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .sku-product {
    grid-template-columns: 64px minmax(0, 1fr);
  }

  .sku-image-link {
    width: 64px;
    height: 64px;
  }
}
