:root {
  --bg: #f7faff;
  --panel: #ffffff;
  --line: rgba(147, 197, 253, 0.35);
  --line-strong: rgba(96, 165, 250, 0.55);
  --text: #1f2933;
  --heading: #0f172a;
  --muted: #64748b;
  --accent: #2563eb;
  --success: #059669;
  --shadow: 0 10px 24px rgba(15, 23, 42, 0.08);

  /* chart ink & chrome */
  --chart-grid: #e4eaf4;
  --chart-axis: #cbd5e1;
  --chart-ink: #0f172a;
  --chart-ink-2: #52616f;
  --chart-muted: #7d8a99;

  /* validated categorical palette (dataviz reference, light mode) */
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  background:
    radial-gradient(circle at top left, rgba(59, 130, 246, 0.12), transparent 28%),
    radial-gradient(circle at bottom right, rgba(96, 165, 250, 0.1), transparent 30%),
    linear-gradient(180deg, #f7faff 0%, #eef4ff 100%);
  color: var(--text);
  font-family: "Inter", sans-serif;
}

button,
input,
select {
  font: inherit;
}

.demo-back {
  position: fixed;
  top: 20px;
  left: 24px;
  z-index: 999;
  padding: 10px 18px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: #ffffff;
  color: var(--heading);
  text-decoration: none;
  font-size: 0.84rem;
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.08);
  transition: background 180ms ease, border-color 180ms ease;
}

.demo-back:hover {
  background: #eff6ff;
  border-color: var(--accent);
}

.app-shell {
  max-width: 1280px;
  margin: 0 auto;
  padding: 84px 20px 40px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 20px;
  flex-wrap: wrap;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.74rem;
  font-weight: 700;
  font-family: "Chakra Petch", sans-serif;
}

h1,
h2,
h3 {
  margin: 0;
  font-family: "Chakra Petch", sans-serif;
  color: var(--heading);
}

h1 {
  font-size: clamp(2rem, 4vw, 3rem);
  line-height: 1;
}

.brand-block .lede {
  margin: 14px 0 0;
  color: var(--muted);
  line-height: 1.6;
  max-width: 62ch;
}

.header-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.primary-button {
  padding: 10px 18px;
  border-radius: 999px;
  border: none;
  background: linear-gradient(135deg, #2563eb, #60a5fa);
  color: #ffffff;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 8px 18px rgba(37, 99, 235, 0.24);
  transition: transform 180ms ease, filter 180ms ease, box-shadow 180ms ease;
}

.primary-button:hover {
  transform: translateY(-1px);
  filter: brightness(1.05);
  box-shadow: 0 12px 22px rgba(37, 99, 235, 0.28);
}

.ghost-button {
  padding: 10px 16px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: #ffffff;
  color: var(--heading);
  cursor: pointer;
  transition: transform 180ms ease, border-color 180ms ease, background 180ms ease;
}

.ghost-button:hover {
  transform: translateY(-1px);
  border-color: var(--accent);
  background: #eff6ff;
}

/* ── Step navigation ── */
.step-nav {
  display: flex;
  align-items: stretch;
  gap: 10px;
  flex-wrap: wrap;
}

.step-arrow {
  align-self: center;
  color: var(--muted);
  font-size: 1.1rem;
}

.step-tab {
  flex: 1 1 220px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.7);
  cursor: pointer;
  text-align: left;
  transition: border-color 180ms ease, background 180ms ease, box-shadow 180ms ease;
}

.step-tab:hover {
  border-color: var(--line-strong);
  background: #ffffff;
}

.step-tab.active {
  border-color: var(--accent);
  background: #ffffff;
  box-shadow: var(--shadow);
}

.step-num {
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  font-family: "Chakra Petch", sans-serif;
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--muted);
  border: 1px solid var(--chart-axis);
  background: #ffffff;
}

.step-tab.active .step-num {
  color: #ffffff;
  border-color: transparent;
  background: linear-gradient(135deg, #2563eb, #60a5fa);
}

.step-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.step-text strong {
  color: var(--heading);
  font-size: 0.92rem;
}

.step-text small {
  color: var(--muted);
  font-size: 0.74rem;
}

/* ── Panels & intros ── */
.panel {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 18px;
}

.step-view {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.step-view[hidden] {
  display: none;
}

.view-intro {
  margin-bottom: 14px;
}

.view-intro h2 {
  font-size: 1.2rem;
}

.view-intro p {
  margin: 6px 0 0;
  color: var(--muted);
  line-height: 1.55;
  max-width: 80ch;
}

.dash-intro {
  margin-bottom: 0;
}

.count-chip {
  display: inline-block;
  margin-left: 6px;
  padding: 2px 10px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: #eff6ff;
  color: var(--accent);
  font-size: 0.76rem;
  font-weight: 600;
  white-space: nowrap;
}

/* ── Tables (shared) ── */
.table-scroll {
  overflow-x: auto;
  border-radius: 12px;
  border: 1px solid var(--line);
}

.raw-scroll {
  max-height: 560px;
  overflow-y: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
}

thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #eef4ff;
  color: #475569;
  text-align: left;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 11px 10px;
  white-space: nowrap;
  border-bottom: 1px solid var(--line-strong);
}

thead th.num,
td.num {
  text-align: right;
}

td.num {
  font-variant-numeric: tabular-nums;
}

tbody td {
  padding: 9px 10px;
  border-bottom: 1px solid rgba(147, 197, 253, 0.22);
  white-space: nowrap;
  vertical-align: middle;
}

tbody tr:last-child td {
  border-bottom: none;
}

/* ── Raw table flavor ── */
.raw-table tbody tr:nth-child(even) {
  background: rgba(239, 246, 255, 0.55);
}

.raw-table .order-id {
  font-family: "Chakra Petch", sans-serif;
  color: var(--accent);
  font-size: 0.78rem;
}

.raw-table .cell-muted {
  color: var(--muted);
}

/* ── Spreadsheet look (organized report) ── */
.sheet-table {
  font-size: 0.86rem;
}

.sheet-table th,
.sheet-table td {
  border-right: 1px solid rgba(147, 197, 253, 0.28);
}

.sheet-table th:last-child,
.sheet-table td:last-child {
  border-right: none;
}

.col-letters th {
  background: #f4f8ff;
  color: #94a3b8;
  text-align: center;
  font-size: 0.68rem;
  font-family: "Chakra Petch", sans-serif;
  letter-spacing: 0.12em;
  padding: 6px 10px;
  border-bottom: 1px solid var(--line);
}

.rownum-col {
  width: 42px;
  min-width: 42px;
  text-align: center !important;
  background: #f4f8ff !important;
  color: #94a3b8 !important;
  font-family: "Chakra Petch", sans-serif;
  font-size: 0.72rem;
  border-right: 1px solid var(--line-strong) !important;
}

.sheet-table td.rownum-col {
  padding: 9px 6px;
}

.region-row td {
  background: #e8f0fe;
  color: var(--heading);
  font-weight: 700;
  font-family: "Chakra Petch", sans-serif;
  font-size: 0.8rem;
  letter-spacing: 0.04em;
}

.region-row td.rownum-col {
  font-weight: 400;
}

.subtotal-row td {
  background: rgba(239, 246, 255, 0.7);
  font-weight: 600;
  color: var(--heading);
  border-top: 1px solid var(--line-strong);
}

.grandtotal-row td {
  background: #dbeafe;
  font-weight: 700;
  color: var(--accent);
  border-top: 2px solid var(--accent);
}

.grandtotal-row td.rownum-col,
.subtotal-row td.rownum-col,
.region-row td.rownum-col {
  background: #f4f8ff !important;
  color: #94a3b8 !important;
  font-weight: 400;
}

.pct-cell {
  color: var(--muted);
}

/* ── Dashboard ── */
.stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
}

.stat-card {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-card span {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 600;
}

.stat-card strong {
  font-family: "Chakra Petch", sans-serif;
  font-size: 1.7rem;
  line-height: 1.1;
  color: var(--heading);
}

.stat-card strong.kpi-name {
  font-size: 1.25rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stat-card small {
  color: var(--muted);
  font-size: 0.76rem;
}

.stat-card.accent strong {
  color: var(--accent);
}

.chart-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.chart-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}

.chart-card.span-2 {
  grid-column: span 2;
}

.chart-card h3 {
  font-size: 0.98rem;
}

.chart-body {
  position: relative;
  min-width: 0;
}

.chart-body svg {
  display: block;
  width: 100%;
  height: auto;
}

.chart-body svg text {
  font-family: "Inter", sans-serif;
}

/* hover lift on marks */
.mark {
  transition: filter 120ms ease;
}

.mark.lifted {
  filter: brightness(1.12);
}

.hit {
  fill: transparent;
  outline: none;
  cursor: pointer;
}

.hit:focus-visible {
  stroke: var(--accent);
  stroke-width: 1.5;
  stroke-dasharray: none;
}

/* tooltip */
.chart-tip {
  position: absolute;
  z-index: 10;
  pointer-events: none;
  background: #ffffff;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  box-shadow: 0 10px 26px rgba(15, 23, 42, 0.16);
  padding: 8px 12px;
  font-size: 0.8rem;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 100ms ease;
}

.chart-tip.show {
  opacity: 1;
}

.chart-tip .tip-title {
  color: var(--muted);
  font-size: 0.72rem;
  margin-bottom: 3px;
}

.chart-tip .tip-row {
  display: flex;
  align-items: center;
  gap: 7px;
}

.chart-tip .tip-key {
  width: 12px;
  height: 3px;
  border-radius: 2px;
  flex: 0 0 auto;
}

.chart-tip .tip-value {
  font-weight: 700;
  color: var(--chart-ink);
}

.chart-tip .tip-label {
  color: var(--chart-ink-2);
}

/* legend */
.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  padding: 2px 4px 0;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 0.8rem;
  color: var(--chart-ink-2);
}

.legend-swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  flex: 0 0 auto;
}

.legend-item b {
  color: var(--chart-ink);
  font-weight: 600;
}

/* per-chart data table */
.chart-table {
  border-top: 1px solid var(--line);
  padding-top: 8px;
}

.chart-table summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.78rem;
  user-select: none;
}

.chart-table summary:hover {
  color: var(--accent);
}

.chart-table table {
  margin-top: 8px;
  font-size: 0.8rem;
}

.chart-table thead th {
  position: static;
  padding: 7px 10px;
}

.chart-table tbody td {
  padding: 6px 10px;
}

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1100;
  padding: 12px 22px;
  border-radius: 999px;
  border: 1px solid rgba(5, 150, 105, 0.35);
  background: #ffffff;
  color: var(--success);
  font-size: 0.88rem;
  font-weight: 600;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.16);
}

/* ── Responsive ── */
@media (max-width: 980px) {
  .stats-row {
    grid-template-columns: repeat(2, 1fr);
  }

  .chart-grid {
    grid-template-columns: 1fr;
  }

  .chart-card.span-2 {
    grid-column: span 1;
  }
}

@media (max-width: 720px) {
  .step-arrow {
    display: none;
  }

  .step-tab {
    flex-basis: 100%;
  }
}

@media (max-width: 620px) {
  .app-shell {
    padding-top: 76px;
  }

  .stats-row {
    grid-template-columns: 1fr;
  }
}
