:root {
  --page: #f4f5f2;
  --surface: #ffffff;
  --ink: #1c2630;
  --muted: #5e6a74;
  --rule: #d8ddd6;
  --action: #24577a;
  --action-ink: #ffffff;
  --minus: #9a3b2e;
  --warn-bg: #fbf3e2;
  --error-bg: #fbe9e6;
  --shopee: #e8542e;
  --tiktok: #0e8f9b;
  --tokopedia: #2e9b3a;
  --other: #7a7f86;
  color-scheme: light;
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --page: #141a1f; --surface: #1c242b; --ink: #e5e9ec; --muted: #9aa5ae; --rule: #2e3841;
    --action: #7fb3d9; --action-ink: #10202c; --minus: #e59a8c; --warn-bg: #2f2a1d; --error-bg: #3a2420;
    --shopee: #f07a59; --tiktok: #35b8c3; --tokopedia: #5cc067; --other: #a0a6ad;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --page: #141a1f; --surface: #1c242b; --ink: #e5e9ec; --muted: #9aa5ae; --rule: #2e3841;
  --action: #7fb3d9; --action-ink: #10202c; --minus: #e59a8c; --warn-bg: #2f2a1d; --error-bg: #3a2420;
  --shopee: #f07a59; --tiktok: #35b8c3; --tokopedia: #5cc067; --other: #a0a6ad;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: inherit; }
html { scroll-padding-top: env(safe-area-inset-top, 0px); }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 400 1rem/1.5 "Public Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-variant-numeric: tabular-nums;
}

.page { max-width: 68rem; margin: 0 auto; padding: 2.5rem 1.25rem 4rem; }

h1 { font-size: 2rem; line-height: 1.15; font-weight: 700; margin: 0 0 .5rem; letter-spacing: -0.01em; }
h2 { font-size: 1.125rem; font-weight: 700; margin: 0 0 .75rem; }
.lede { margin: 0; color: var(--muted); max-width: 38rem; }
.muted { color: var(--muted); }
code { font-size: .9em; }

/* Header + upload */
.masthead {
  display: flex; flex-wrap: wrap; gap: 1.5rem; align-items: flex-end; justify-content: space-between;
  padding-bottom: 1.75rem; border-bottom: 2px solid var(--ink); margin-bottom: 1.75rem;
}
.upload { display: flex; flex-direction: column; align-items: flex-start; gap: .35rem; cursor: pointer; }
.upload input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.upload-button {
  background: var(--action); color: var(--action-ink); font-weight: 600;
  padding: .7rem 1.2rem; border-radius: 6px;
}
.upload:focus-within .upload-button { outline: 3px solid var(--action); outline-offset: 3px; }
.upload.dragging .upload-button { outline: 3px dashed var(--action); outline-offset: 4px; }
.upload-hint { font-size: .875rem; color: var(--muted); max-width: 16rem; overflow-wrap: anywhere; }

.error { background: var(--error-bg); padding: .9rem 1rem; border-radius: 6px; margin: 0 0 1.5rem; }
.empty { padding: 2rem 0; max-width: 38rem; }

/* Periode */
.period { display: flex; flex-wrap: wrap; align-items: end; gap: .75rem 1.25rem; margin-bottom: 2rem; }
.period label { display: flex; flex-direction: column; font-size: .875rem; color: var(--muted); gap: .25rem; }
.period input, .period button {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--rule); border-radius: 6px; padding: .5rem .65rem;
}
.period button { cursor: pointer; font-weight: 600; }
.period input:focus-visible, .period button:focus-visible, summary:focus-visible {
  outline: 3px solid var(--action); outline-offset: 2px;
}

/* Ringkasan: laporan net revenue + channel */
.overview { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 2.5rem; margin-bottom: 3rem; }
@media (max-width: 760px) { .overview { grid-template-columns: 1fr; } }

.caption { margin: -.5rem 0 1rem; color: var(--muted); }

/* Laporan bergaya pembukuan: angka disusun seperti hitungan, garis ganda di hasil akhir */
#statement { width: 100%; border-collapse: collapse; }
#statement th { text-align: left; font-weight: 400; padding: .55rem 0; }
#statement td { text-align: right; padding: .55rem 0 .55rem 1rem; white-space: nowrap; }
#statement tbody tr + tr { border-top: 1px solid var(--rule); }
#statement tr.minus td { color: var(--minus); }
#statement tfoot tr:first-child th,
#statement tfoot tr:first-child td {
  border-top: 2px solid var(--ink); padding-top: .9rem; font-weight: 700;
}
#statement tfoot tr:first-child td {
  font-size: clamp(1.6rem, 4vw, 2.25rem); line-height: 1.1;
  border-bottom: 4px double var(--ink); padding-bottom: .4rem;
}
#statement tfoot tr:first-child th { font-size: 1.125rem; vertical-align: bottom; padding-bottom: .5rem; }
#statement .meta td { text-align: right; color: var(--muted); font-size: .9rem; padding-top: .6rem; }
.footnote { font-size: .875rem; color: var(--muted); margin: 1.25rem 0 0; max-width: 34rem; }

.channel + .channel { margin-top: 1.25rem; }
.channel-head { display: flex; justify-content: space-between; gap: 1rem; font-weight: 600; }
.channel-amount { white-space: nowrap; }
.bar { height: .6rem; background: var(--rule); border-radius: 3px; margin: .4rem 0; overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--channel, var(--other)); }
.channel-meta { margin: 0; font-size: .875rem; color: var(--muted); }
.channel.shopee { --channel: var(--shopee); }
.channel.tiktok { --channel: var(--tiktok); }
.channel.tokopedia { --channel: var(--tokopedia); }

/* Tabel produk */
section + section { margin-top: 2.5rem; }
.table-wrap { overflow-x: auto; }
.products { width: 100%; border-collapse: collapse; background: var(--surface); }
.products th, .products td { padding: .65rem .75rem; text-align: left; border-bottom: 1px solid var(--rule); vertical-align: top; }
.products thead th { font-size: .875rem; font-weight: 600; color: var(--muted); border-bottom: 2px solid var(--ink); }
.products .num { text-align: right; white-space: nowrap; }
.products .rank { color: var(--muted); width: 2.5rem; }
.product-name { display: block; }
.sku { display: block; font-size: .8125rem; color: var(--muted); }
.none { color: var(--muted); }

details summary { cursor: pointer; font-weight: 700; font-size: 1.125rem; margin-bottom: .75rem; }

/* Catatan kualitas data */
.quality { margin: 0; padding: 0; list-style: none; max-width: 52rem; }
.quality li { padding: .6rem .8rem; border-left: 3px solid var(--rule); margin-bottom: .5rem; }
.quality li.warning, .quality li.skipped { border-left-color: #c58a1b; background: var(--warn-bg); }
.quality li.duplicate { border-left-color: var(--action); }
.quality .lines { display: block; font-size: .8125rem; color: var(--muted); margin-top: .15rem; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

.overview > section { margin-top: 0; }
.products td:nth-child(2) { min-width: 12rem; }
@media (max-width: 600px) {
  .products th:last-child, .products td:last-child, .products .wide { display: none; }
  .products th, .products td { padding: .6rem .4rem; }
  .products td:nth-child(2) { min-width: 8.5rem; }
  .products .rank { width: 1.5rem; }
}
