:root {
  --bg: #f3efe8;
  --paper: rgba(255, 252, 248, 0.94);
  --paper-strong: rgba(255, 254, 251, 0.985);
  --ink: #171c21;
  --muted: #6a6e72;
  --line: rgba(23, 28, 33, 0.08);
  --accent: #9f5535;
  --accent-soft: rgba(159, 85, 53, 0.10);
  --accent-2: #0e5c65;
  --accent-3: #b88935;
  --success: #227f55;
  --danger: #b43a3a;
  --shadow: 0 22px 64px rgba(30, 28, 25, 0.08);
  --shadow-soft: 0 12px 28px rgba(30, 28, 25, 0.06);
  --radius-xl: 26px;
  --radius-lg: 20px;
  --radius-md: 16px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Noto Sans SC", "Manrope", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(159, 85, 53, 0.10), transparent 22%),
    radial-gradient(circle at 86% 10%, rgba(184, 137, 53, 0.08), transparent 18%),
    radial-gradient(circle at bottom right, rgba(14, 92, 101, 0.08), transparent 20%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.10), transparent 24%),
    var(--bg);
  color: var(--ink);
}

.app-shell {
  display: grid;
  grid-template-columns: 296px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  padding: 28px 22px;
  border-right: 1px solid var(--line);
  background:
    linear-gradient(180deg, rgba(255, 252, 248, 0.97) 0%, rgba(246, 241, 233, 0.92) 100%);
  backdrop-filter: blur(16px);
  position: sticky;
  top: 0;
  height: 100vh;
  box-shadow: inset -1px 0 0 rgba(255,255,255,0.4);
}

.brand-kicker,
.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 10px;
  font-weight: 800;
  color: var(--accent);
}

.brand h1,
.section-heading h2 {
  margin: 8px 0 10px;
  font-size: 30px;
  line-height: 1.02;
  letter-spacing: -0.04em;
}

.brand p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.data-coverage {
  margin-top: 8px;
  font-size: 11px !important;
  line-height: 1.55;
  display: grid;
  gap: 2px;
}

.data-coverage span {
  display: block;
}

.nav {
  display: grid;
  gap: 10px;
  margin: 32px 0;
}

.nav-button {
  border: 0;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  text-align: left;
  font: inherit;
  background: rgba(255, 255, 255, 0.34);
  color: var(--ink);
  cursor: pointer;
  transition: background 0.18s ease, transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
  border: 1px solid transparent;
}

.nav-button:hover {
  background: rgba(185, 98, 62, 0.08);
  transform: translateX(2px);
  border-color: rgba(185, 98, 62, 0.16);
}

.nav-button.active {
  background: linear-gradient(135deg, var(--accent) 0%, #864528 100%);
  color: white;
  box-shadow: 0 14px 28px rgba(159, 85, 53, 0.18);
}

.filter-panel {
  display: grid;
  gap: 14px;
  padding: 18px 16px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.42);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.65);
}

.filter-subgroup {
  display: grid;
  gap: 14px;
}

.filter-subgroup.hidden {
  display: none;
}

.filter-panel h2 {
  margin: 0 0 4px;
  font-size: 16px;
}

.filter-panel label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

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

.quick-filter-grid label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

select,
.search {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 11px 13px;
  background: rgba(255, 255, 255, 0.88);
  color: var(--ink);
  font: inherit;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6);
  transition: border-color 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
}

select:focus,
.search:focus,
input[type="number"]:focus {
  outline: none;
  border-color: rgba(185, 98, 62, 0.32);
  box-shadow: 0 0 0 4px rgba(185, 98, 62, 0.08), inset 0 1px 0 rgba(255,255,255,0.7);
  background: rgba(255, 255, 255, 0.96);
}

.main-content {
  padding: 30px 32px 48px;
}

.view {
  display: none;
  gap: 24px;
}

.view.active {
  display: grid;
  align-content: start;
}

.section-heading {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 20px;
}

.section-heading h2 {
  font-size: 34px;
  margin-bottom: 0;
  font-weight: 900;
}

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

#otherCostCards {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.platform-selector {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.platform-pill {
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255, 254, 251, 0.96) 0%, rgba(250, 246, 240, 0.93) 100%);
  border-radius: var(--radius-lg);
  padding: 16px 15px 14px;
  display: grid;
  gap: 9px;
  cursor: pointer;
  text-align: left;
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}

.platform-pill:hover,
.platform-pill.active {
  transform: translateY(-2px);
  box-shadow: 0 16px 28px rgba(23, 28, 33, 0.08);
  border-color: rgba(188, 107, 70, 0.35);
}

.platform-pill.active {
  background: linear-gradient(135deg, rgba(188, 107, 70, 0.14) 0%, rgba(28, 110, 120, 0.10) 100%);
}

.platform-pill-trend {
  height: 28px;
  overflow: hidden;
}

.platform-pill-trend .metric-sparkline-svg {
  width: 100%;
  height: 28px;
}

.platform-pill.theme-amz,
.platform-card-shell.theme-amz {
  border-color: rgba(185, 98, 62, 0.22);
}

.platform-pill.theme-wf,
.platform-card-shell.theme-wf {
  border-color: rgba(15, 109, 119, 0.24);
}

.platform-pill.theme-temu,
.platform-card-shell.theme-temu {
  border-color: rgba(210, 160, 86, 0.28);
}

.platform-pill.theme-amz.active {
  background: linear-gradient(135deg, rgba(185, 98, 62, 0.20) 0%, rgba(185, 98, 62, 0.08) 100%);
}

.platform-pill.theme-wf.active {
  background: linear-gradient(135deg, rgba(15, 109, 119, 0.18) 0%, rgba(15, 109, 119, 0.08) 100%);
}

.platform-pill.theme-temu.active {
  background: linear-gradient(135deg, rgba(210, 160, 86, 0.24) 0%, rgba(210, 160, 86, 0.10) 100%);
}

.pill-title {
  font-weight: 800;
  font-size: 14px;
  letter-spacing: 0.02em;
}

.pill-sales {
  font-size: 23px;
  font-weight: 800;
  letter-spacing: -0.03em;
}

.pill-profit {
  font-size: 13px;
  font-weight: 700;
}

.pill-profit.up {
  color: var(--success);
}

.pill-profit.down {
  color: var(--danger);
}

.metric-card,
.panel {
  background: linear-gradient(180deg, var(--paper-strong) 0%, var(--paper) 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-soft);
}

.metric-card {
  padding: 22px 20px 20px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 124px auto;
  gap: 12px;
  align-items: start;
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}

.interactive-card {
  cursor: pointer;
}

.metric-card:hover,
.panel:hover {
  transform: translateY(-1px);
  box-shadow: 0 18px 34px rgba(23, 28, 33, 0.08);
  border-color: rgba(159, 85, 53, 0.12);
}

.metric-card.compact .metric-value {
  font-size: 24px;
}

.metric-label {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-weight: 800;
}

.metric-value {
  margin: 10px 0 0;
  font-size: 32px;
  line-height: 1;
  font-weight: 800;
  letter-spacing: -0.04em;
}

.metric-main {
  min-width: 0;
}

.metric-sparkline {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  align-self: stretch;
}

.metric-sparkline-svg {
  width: 116px;
  height: 42px;
}

.sparkline-empty {
  width: 116px;
  height: 42px;
}

.metric-subvalue {
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.metric-note {
  margin-top: 10px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

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

.metric-mini-item {
  display: grid;
  gap: 3px;
  overflow: hidden;
  padding: 10px 11px;
  border-radius: 14px;
  background: rgba(255,255,255,0.46);
  border: 1px solid rgba(27, 32, 38, 0.05);
}

.metric-mini-item span {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.metric-mini-item strong {
  font-size: 15px;
  color: var(--ink);
  letter-spacing: -0.02em;
}

.metric-mini-trend {
  margin-top: 3px;
  height: 28px;
  overflow: hidden;
}

.metric-mini-trend .metric-sparkline-svg {
  width: 100%;
  height: 28px;
}

.metric-mini-item em {
  font-style: normal;
  font-size: 11px;
  color: var(--muted);
}

.metric-compare {
  min-width: 110px;
  text-align: right;
  font-size: 11px;
  color: var(--muted);
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(255,255,255,0.48);
  border: 1px solid rgba(27, 32, 38, 0.05);
}

.metric-compare strong {
  display: block;
  font-size: 15px;
  margin-top: 6px;
}

#otherCostCards .metric-card {
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
}

#otherCostCards .metric-sparkline {
  justify-content: flex-start;
}

#otherCostCards .metric-compare {
  min-width: 0;
  text-align: left;
}

#otherCostCards .metric-value {
  font-size: 22px;
}

.metric-compare.up strong {
  color: var(--success);
}

.metric-compare.down strong {
  color: var(--danger);
}

.metric-compare.flat strong {
  color: var(--muted);
}

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

.chart-grid.single,
.panel.wide {
  grid-column: 1 / -1;
}

.panel {
  padding: 20px 20px 18px;
  overflow: hidden;
}

.matrix-wrap {
  overflow: auto;
  border-radius: 16px;
}

.matrix-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 11px;
}

.matrix-table th,
.matrix-table td {
  border-bottom: 1px solid var(--line);
  padding: 11px 9px;
  text-align: center;
  white-space: nowrap;
}

.matrix-table th:first-child,
.matrix-table td:first-child {
  text-align: left;
  position: sticky;
  left: 0;
  background: var(--paper);
  z-index: 1;
}

.matrix-cell {
  border-radius: 12px;
  color: #fff;
  font-weight: 700;
  display: inline-flex;
  min-width: 70px;
  justify-content: center;
  padding: 7px 9px;
  letter-spacing: -0.01em;
}

.matrix-divider td {
  border-top: 2px solid rgba(28, 29, 33, 0.08);
}

.matrix-cell.refund {
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);
}

.matrix-primary-row td,
.matrix-primary-row td:first-child {
  background: rgba(15, 109, 119, 0.07);
}

.matrix-cell.primary {
  box-shadow: 0 0 0 2px rgba(15, 109, 119, 0.22);
  min-width: 76px;
}

.compact-panel {
  padding-top: 16px;
  padding-bottom: 16px;
}

.chart-fallback {
  min-height: 280px;
  border: 1px dashed rgba(28, 29, 33, 0.14);
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(255, 253, 249, 0.9), rgba(244, 239, 230, 0.85));
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 20px;
  font-size: 14px;
  line-height: 1.7;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  gap: 14px;
}

.panel-header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.panel-subtitle {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.panel-header h3 {
  margin: 0;
  font-size: 19px;
  letter-spacing: -0.02em;
}

canvas {
  min-height: 290px;
}

.ghost-action {
  border: 1px solid rgba(28, 29, 33, 0.12);
  background: rgba(255, 255, 255, 0.86);
  color: var(--ink);
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.18s ease, background 0.18s ease, border-color 0.18s ease;
}

.ghost-action:hover {
  transform: translateY(-1px);
  background: rgba(185, 98, 62, 0.08);
  border-color: rgba(185, 98, 62, 0.18);
}

.ghost-action.hidden {
  display: none;
}

.table-wrap {
  overflow: auto;
  border-radius: 16px;
  background: rgba(255,255,255,0.24);
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  font-size: 13px;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  background: rgba(255, 251, 246, 0.98);
  z-index: 1;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  cursor: pointer;
  box-shadow: inset 0 -1px 0 rgba(27, 32, 38, 0.04);
}

tbody tr {
  transition: background 0.15s ease;
}

tbody tr:hover {
  background: rgba(185, 98, 62, 0.05);
}

th.sortable::after {
  content: " ↕";
  color: var(--muted);
  font-size: 11px;
}

th.sorted-asc::after {
  content: " ↑";
  color: var(--accent);
}

th.sorted-desc::after {
  content: " ↓";
  color: var(--accent);
}

.table-filter-chip {
  appearance: none;
  border: 1px solid rgba(28, 29, 33, 0.12);
  background: linear-gradient(180deg, rgba(159, 85, 53, 0.12), rgba(159, 85, 53, 0.08));
  color: var(--ink);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.16s ease, background 0.16s ease, border-color 0.16s ease;
}

.table-filter-chip:hover {
  background: rgba(213, 147, 114, 0.22);
  transform: translateY(-1px);
  border-color: rgba(185, 98, 62, 0.22);
}

td.num,
th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.sku-grid {
  display: grid;
  grid-template-columns: 1.2fr 0.9fr;
  gap: 20px;
}

.sku-shared-filter-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px 16px;
}

.sku-shared-filter-grid label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

.subtab-bar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  padding: 4px 0 2px;
}

.subtab-button {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.88);
  color: var(--ink);
  border-radius: 999px;
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
}

.subtab-button:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-soft);
}

.subtab-button.active {
  background: linear-gradient(135deg, var(--accent) 0%, #864528 100%);
  color: #fff;
  border-color: transparent;
  box-shadow: var(--shadow);
}

.sku-tab-view {
  display: none;
  gap: 20px;
}

.sku-tab-view.active {
  display: grid;
}

.pricing-form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px 16px;
}

.pricing-form-grid label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

.toggle-field {
  align-content: end;
}

.toggle-field span {
  color: var(--muted);
}

.inline-toggle-field {
  display: grid;
  gap: 6px;
}

.inline-toggle-input {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}

.mini-toggle {
  display: inline-flex !important;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  color: var(--muted);
  font-size: 12px !important;
}

input[type="number"] {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 11px 12px;
  background: rgba(255,255,255,0.9);
  color: var(--ink);
  font: inherit;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 700;
}

.chip.ok {
  background: rgba(31, 122, 69, 0.12);
  color: var(--success);
}

.chip.warn {
  background: rgba(176, 49, 49, 0.12);
  color: var(--danger);
}

canvas {
  width: 100% !important;
  max-height: 360px;
}

@media (max-width: 1200px) {
  .card-grid,
  .chart-grid,
  .sku-grid,
  .sku-shared-filter-grid,
  .platform-selector,
  .quick-filter-grid {
    grid-template-columns: 1fr;
  }

  #otherCostCards {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

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

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .main-content {
    padding: 20px;
  }

  .panel-header {
    align-items: start;
    flex-direction: column;
  }
}
