:root {
  --surface-1: #fcfcfb;
  --page-plane: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --gridline: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);

  --series-1: #2a78d6; /* Reguler */
  --series-2: #1baf7a; /* Konsinyasi */
  --series-3: #eda100; /* Marketplace */
  --retur: #e34948; /* Retur — diverging red, deliberately outside the categorical set */

  --status-good: #0ca30c;
  --status-warning: #fab219;
}

@media (prefers-color-scheme: dark) {
  :root {
    --surface-1: #1a1a19;
    --page-plane: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --gridline: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.10);

    --series-1: #3987e5;
    --series-2: #199e70;
    --series-3: #c98500;
    --retur: #e66767;
  }
}

* { box-sizing: border-box; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background-color: var(--page-plane);
  color: var(--text-primary);
  margin: 0;
  padding: 24px;
}

a { color: var(--series-1); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 20px;
}

.topbar h1 {
  font-size: 22px;
  margin: 0;
}

.topbar nav a {
  margin-left: 16px;
  color: var(--text-secondary);
  font-size: 14px;
}
.topbar nav a.active { color: var(--series-1); font-weight: 600; }

.panel {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 20px;
}

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 14px;
  margin-bottom: 20px;
}

.filter-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.filter-field label {
  font-size: 12px;
  color: var(--text-muted);
}

.filter-field select,
.filter-field input {
  padding: 7px 10px;
  border-radius: 8px;
  border: 1px solid var(--baseline);
  background: var(--surface-1);
  color: var(--text-primary);
  font-size: 14px;
  min-width: 140px;
}

.btn {
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid var(--baseline);
  background: var(--surface-1);
  color: var(--text-primary);
  font-size: 14px;
  cursor: pointer;
}
.btn-primary {
  background: var(--series-1);
  border-color: var(--series-1);
  color: #fff;
}
.btn-export {
  background: var(--status-good);
  border-color: var(--status-good);
  color: #fff;
}

.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.stat-tile {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 20px;
}

.stat-tile-link {
  display: block;
  color: inherit;
  text-decoration: none;
  transition: border-color 0.15s;
}
.stat-tile-link:hover {
  border-color: var(--retur);
  text-decoration: none;
}

.stat-tile .label {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.stat-tile .value {
  font-size: 26px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.stat-tile-retur .value { color: var(--retur); }

.stat-tile .sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 6px;
}

.charts-row {
  display: grid;
  grid-template-columns: 1.3fr 1fr;
  gap: 20px;
  margin-bottom: 20px;
}

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

.panel h2 {
  font-size: 15px;
  margin: 0 0 4px 0;
}
.panel .panel-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin: 0 0 16px 0;
}

.legend {
  display: flex;
  gap: 16px;
  margin-bottom: 12px;
  font-size: 13px;
  color: var(--text-secondary);
}
.legend-item { display: flex; align-items: center; gap: 6px; }
.legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  display: inline-block;
}

.bar-tooltip { cursor: default; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th, td {
  padding: 8px 10px;
  text-align: left;
  border-bottom: 1px solid var(--gridline);
  white-space: nowrap;
}

th {
  color: var(--text-secondary);
  font-weight: 600;
  position: sticky;
  top: 0;
  background: var(--surface-1);
}

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

tbody tr:hover { background: var(--page-plane); }

.table-scroll { overflow-x: auto; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
}
.badge-reguler { background: color-mix(in srgb, var(--series-1) 16%, transparent); color: var(--series-1); }
.badge-konsinyasi { background: color-mix(in srgb, var(--series-2) 16%, transparent); color: var(--series-2); }
.badge-marketplace { background: color-mix(in srgb, var(--series-3) 24%, transparent); color: color-mix(in srgb, var(--series-3) 75%, black); }
.badge-retur { background: color-mix(in srgb, var(--retur) 16%, transparent); color: var(--retur); }
.badge-lainnya { background: var(--gridline); color: var(--text-secondary); }

.pagination {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 16px;
  font-size: 13px;
  color: var(--text-secondary);
}
.pagination a, .pagination span {
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
}
.pagination a:hover { background: var(--page-plane); text-decoration: none; }
.pagination .current { background: var(--series-1); color: #fff; border-color: var(--series-1); }

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 40px 0;
}

/* --- Monthly grouped column chart --- */
.chart-wrap {
  position: relative;
  padding-left: 56px;
}

.chart-gridlines {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 30px;
}
.gridline {
  position: absolute;
  left: 56px;
  right: 0;
  border-top: 1px solid var(--gridline);
}
.gridline-label {
  position: absolute;
  left: -56px;
  top: -7px;
  width: 48px;
  text-align: right;
  font-size: 11px;
  color: var(--text-muted);
}

.chart-columns {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  border-bottom: 1px solid var(--baseline);
  padding-bottom: 30px;
  position: relative;
}
.col-group {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
  justify-content: flex-end;
}
.col-bars {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  width: 100%;
  justify-content: center;
}
.bar {
  width: 12px;
  min-height: 2px;
  border-radius: 4px 4px 0 0;
}
.bar-reg { background: var(--series-1); }
.bar-kon { background: var(--series-2); }
.bar-mkt { background: var(--series-3); }
.bar-oth { background: var(--text-muted); }
.col-label {
  position: absolute;
  bottom: 6px;
  font-size: 11px;
  color: var(--text-muted);
  transform: translateY(24px);
}
.col-group { position: relative; }

/* --- Cabang horizontal stacked bar chart --- */
.hbar-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 640px;
  overflow-y: auto;
  padding-right: 4px;
}
.hbar-row {
  display: grid;
  grid-template-columns: 170px 1fr 90px;
  align-items: center;
  gap: 10px;
  height: 24px;
}
.hbar-label {
  font-size: 12px;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.hbar-track {
  background: var(--page-plane);
  border-radius: 4px;
  height: 14px;
}
.hbar-bar {
  display: flex;
  height: 14px;
  border-radius: 4px;
  overflow: hidden;
  gap: 2px;
}
.hbar-seg { height: 100%; }
.hbar-reg { background: var(--series-1); }
.hbar-kon { background: var(--series-2); }
.hbar-mkt { background: var(--series-3); }
.hbar-oth { background: var(--text-muted); }
.hbar-value {
  font-size: 12px;
  color: var(--text-secondary);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* --- Shared chart tooltip --- */
#chart-tooltip {
  position: fixed;
  pointer-events: none;
  background: var(--text-primary);
  color: var(--surface-1);
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 6px;
  z-index: 1000;
  display: none;
  white-space: nowrap;
}
#chart-tooltip .tt-label { opacity: 0.75; margin-bottom: 2px; }
#chart-tooltip .tt-value { font-weight: 600; font-variant-numeric: tabular-nums; }
