:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --text: #1d1d1b;
  --muted: #6b6b66;
  --line: #e3e3de;
  --own: #fff4d6;
  --own-line: #e0b84a;
  --warn-bg: #fff1e8;
  --warn: #9a3d00;
  --link: #1f5fbf;
  --good: #1e7a3c;
  /* table header band, the firmer line under it, a row under the pointer */
  --head-bg: #ebeae4;
  --head-text: #2f2f2b;
  --line-strong: #c9c8c0;
  --hover: #f4f3ee;
  --gutter: clamp(16px, 4vw, 40px);
  /* chart series: dataviz reference slots 1-3, validated on #ffffff (aqua 2.82:1: direct labels + table view) */
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161615;
    --surface: #1f1f1d;
    --text: #ececea;
    --muted: #a3a39d;
    --line: #34342f;
    --own: #3a3120;
    --own-line: #b8933a;
    --warn-bg: #3a2418;
    --warn: #ffb38a;
    --link: #8ab4f8;
    --good: #7fd49a;
    --head-bg: #2c2c29;
    --head-text: #e4e4df;
    --line-strong: #4d4d46;
    --hover: #262624;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
  }
}

* { box-sizing: border-box; }
body {
  max-width: 1680px;
  margin: 0 auto;
  padding: 16px var(--gutter) 40px;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { margin: 0; font-size: 1.4rem; letter-spacing: 0.02em; }
h2 { margin: 20px 0 12px; font-size: 1.15rem; line-height: 1.3; }
/* Each section of a screen opens under a rule, so a long screen reads as parts */
main > section { margin-top: 32px; border-top: 1px solid var(--line); scroll-margin-top: 48px; }
:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; }
section > h3 { margin: 20px 0 8px; font-size: 0.95rem; }

.top {
  display: flex; flex-wrap: wrap; gap: 8px 24px; align-items: end; justify-content: space-between;
  padding-bottom: 12px; border-bottom: 1px solid var(--line);
}
.scope { margin: 2px 0 0; color: var(--muted); }
#status { margin: 0; color: var(--muted); font-size: 0.9rem; }
.stale { color: var(--warn); }
.meta { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.user { margin: 0; color: var(--muted); font-size: 0.85rem; }
button.link { padding: 0; border: 0; background: none; font: inherit; color: var(--link); cursor: pointer; }
button.link:hover { text-decoration: underline; }
@media (max-width: 640px) { .meta { align-items: flex-start; } }

/* Sign in: one centered card */
body.login { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-box {
  width: min(100%, 360px); display: flex; flex-direction: column; gap: 12px; padding: 24px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
}
.login-box .scope { margin-top: -8px; }
.login-box label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 0.9rem; }
.login-box input {
  padding: 8px 10px; font: inherit; color: var(--text);
  background: var(--bg); border: 1px solid var(--line); border-radius: 6px;
}
.login-box input:focus-visible, .login-box button:focus-visible { outline: 2px solid var(--link); outline-offset: 1px; }
.login-box button {
  padding: 9px 12px; font: inherit; font-weight: 600; color: var(--surface);
  background: var(--text); border: 0; border-radius: 6px; cursor: pointer;
}
.login-box .note, .login-box .sub { margin: 0; }

.toolbar { display: flex; gap: 12px; align-items: center; margin-top: 16px; flex-wrap: wrap; }
.toolbar label { color: var(--muted); font-size: 0.9rem; }
select {
  margin-left: 6px; padding: 6px 10px; min-height: 36px; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--line); border-radius: 6px;
}
.loading { color: var(--muted); font-size: 0.9rem; }

.note { padding: 8px 12px; border-radius: 6px; }
.warn { background: var(--warn-bg); color: var(--warn); }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 280px)); gap: 10px; }
.tiles + :is(.scroll, .charts, .chart, .note) { margin-top: 12px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; }
.tile .label { color: var(--muted); font-size: 0.82rem; }
.tile .value { font-size: 1.6rem; font-weight: 600; font-variant-numeric: tabular-nums; margin: 2px 0; }
.tile .value small { font-size: 0.9rem; font-weight: 400; color: var(--muted); }
.sub { color: var(--muted); font-size: 0.85rem; }

.scroll { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
/* A table of up to five columns is as wide as it needs (at least 44rem), not stretched across the screen */
.scroll:not(:has(> table > thead > tr:last-child > :nth-child(6))) { width: fit-content; min-width: min(100%, 44rem); max-width: 100%; }
/* A long table scrolls in its own box, so its header (and totals row) stay in view */
.scroll:has(> table > tbody > tr:nth-child(13)) { max-height: min(78vh, 48rem); }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: 7px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { color: var(--head-text); font-weight: 600; font-size: 0.8rem; white-space: nowrap; }
/* The header: a tinted band with a firm line under it, kept at the top of its box */
thead { position: sticky; top: 0; z-index: 3; }
thead th { background: var(--head-bg); vertical-align: bottom; border-bottom-color: var(--line-strong); }
tfoot { position: sticky; bottom: 0; z-index: 3; }
tfoot th { background: var(--head-bg); border-top: 1px solid var(--line-strong); border-bottom: 0; }
tbody tr:last-child td { border-bottom: 0; }
td.n, th.n { text-align: right; white-space: nowrap; }
/* A row's color is a variable, so a pinned cell (below) covers what scrolls under it with the same color */
tbody :is(td, th) { background: var(--row-bg, var(--surface)); }
tr.own { --row-bg: var(--own); --own-mark: inset 3px 0 0 var(--own-line); }
tr.own > :first-child { box-shadow: var(--own-mark); }
@media (hover: hover) { tbody tr:not(.own):not(.flag):not(.current):hover { --row-bg: var(--hover); } }
/* The name column (the first, or the one after a rank) stays put when a wide table scrolls sideways */
.scroll table:not(:has(> thead > tr:first-child > th.rank:first-child)) :is(thead tr:first-child, tbody tr, tfoot tr) > :first-child,
.scroll table:has(> thead > tr:first-child > th.rank:first-child) :is(thead tr:first-child, tbody tr, tfoot tr) > :nth-child(2) {
  position: sticky; left: 0; z-index: 1;
}
.scroll table:not(:has(> thead > tr:first-child > th.rank:first-child)) tbody tr > :first-child { box-shadow: var(--own-mark, 0 0 transparent), 1px 0 0 var(--line); }
.scroll table:has(> thead > tr:first-child > th.rank:first-child) tbody tr > :nth-child(2) { box-shadow: 1px 0 0 var(--line); }
thead tr:first-child > :is(:first-child, :nth-child(2)) { z-index: 4; }
.tag { font-size: 0.72rem; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; }
.na { color: var(--muted); cursor: help; border-bottom: 1px dotted var(--muted); }

/* A product cell stays a table cell (so it can be the pinned column): the image floats, the text beside it */
td.product { min-width: 260px; }
.product img { float: left; margin-right: 10px; }
.product > div { overflow: hidden; }
/* A listing's title in a plain cell: as wide as a product cell, so a phone doesn't squeeze it to a word a line */
td.listing { min-width: 260px; }
/* More cells a phone would squeeze: a tag never breaks inside, the leads keep room for two or three tags on a line,
   a free-text note a readable measure, and a day (with the day it is against) one line */
.tag { white-space: nowrap; }
td.leads { min-width: 14em; }
td.note-cell { min-width: 16em; }
td.day, td.day .sub { white-space: nowrap; }
/* A product's title at most three lines (Shopee titles run to 150 characters); the whole title is its tooltip, and
   a link opens the listing */
.product a, .clamp {
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; line-clamp: 3; overflow: hidden;
}
.product img { border-radius: 4px; object-fit: cover; flex: none; background: var(--line); }

.notes { margin-top: 28px; color: var(--muted); font-size: 0.85rem; max-width: 70ch; }
.notes p { margin: 6px 0; }
.empty { margin-top: 24px; color: var(--muted); }

/* One line of tabs, kept at the top of the window (edge to edge: it spans the body's gutters); on a phone it scrolls
   sideways rather than breaking names over lines, with the current tab brought into view (page.html). The line under
   them is a background, so the current tab's 2px underline covers it without overflowing. */
.screens {
  position: sticky; top: 0; z-index: 10;
  display: flex; gap: 4px; margin: 12px calc(-1 * var(--gutter)) 0; padding: 0 var(--gutter);
  overflow-x: auto; overflow-y: hidden; scrollbar-width: none;
  background: linear-gradient(var(--line), var(--line)) bottom / 100% 1px no-repeat, var(--bg);
}
.screens::-webkit-scrollbar { display: none; }
.screens a {
  flex: none; white-space: nowrap; padding: 10px 12px; color: var(--muted); border-bottom: 2px solid transparent;
}
.screens a:hover { color: var(--text); text-decoration: none; }
.screens a[aria-current="page"] { color: var(--text); border-bottom-color: var(--own-line); font-weight: 600; }
tr.flag { --row-bg: var(--warn-bg); }
.flag-tag { color: var(--warn); border-color: var(--warn); }
table caption { caption-side: top; text-align: left; padding: 14px 0 4px; }
.listings { margin: 0; padding-left: 1.1em; }
.listings li { margin: 2px 0; }
.listings .sub { white-space: nowrap; }
details.reviews { border: 1px solid var(--line); border-radius: 8px; background: var(--surface); margin: 8px 0; }
details.reviews summary { cursor: pointer; padding: 8px 12px; }
details.reviews ul { list-style: none; margin: 0; padding: 0 12px 4px; }
details.reviews li { border-top: 1px solid var(--line); padding: 8px 0; }
.tag.lead.good { color: var(--good); border-color: var(--good); }
.tag.lead.bad { color: var(--warn); border-color: var(--warn); }
td.index { position: relative; min-width: 9em; font-variant-numeric: tabular-nums; }
td.index .bar { display: inline-block; vertical-align: middle; height: 8px; margin-right: 6px;
  background: var(--line); border-radius: 2px; }
td.index .bar.over { background: var(--series-1); }
label.toggle { display: block; margin: 6px 0 8px; font-size: 0.85rem; color: var(--muted); }
th.group { text-align: center; border-bottom: 1px solid var(--line-strong); }
.trend td.current, .trend th.current { background: var(--own); }
.trend tr.current { --row-bg: var(--own); }
/* a break in a series: the days from it on are collected differently */
.trend .break { border-left: 2px solid var(--warn); }
.tile .value.name { font-size: 1.1rem; }
.spaced { margin-top: 12px; }
.chart.single { max-width: 720px; }
.organic { font-size: 0.75rem; color: var(--good); white-space: nowrap; }
td.cut { color: var(--warn); }

/* Charts (mganik/charts.py): thin marks, hairline solid grid, hover layer in CSS */
.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(460px, 100%), 1fr)); gap: 12px;
  margin-top: 16px; }
.chart { margin: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; }
.chart h3 { margin: 0 0 6px; font-size: 0.95rem; }
.chart .legend { list-style: none; display: flex; flex-wrap: wrap; gap: 4px 16px; margin: 0 0 6px; padding: 0;
  font-size: 0.85rem; }
.chart .legend li { display: flex; align-items: center; gap: 6px; }
.chart details { margin-top: 6px; font-size: 0.85rem; }
.chart summary { cursor: pointer; color: var(--muted); }
.linechart { display: block; width: 100%; height: auto; font: 12px system-ui, -apple-system, "Segoe UI", sans-serif; }
.linechart .grid { stroke: var(--line); stroke-width: 1; }
.linechart .baseline { stroke: var(--muted); stroke-width: 1; opacity: 0.6; }
.linechart .tick { fill: var(--muted); font-variant-numeric: tabular-nums; }
.linechart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.linechart .dot { stroke: var(--surface); stroke-width: 2; }
.linechart .endlabel { fill: var(--muted); }
.linechart .value { fill: var(--text); font-weight: 600; }
.linechart .hit { fill: transparent; }
.linechart .col { outline: none; }
.linechart .crosshair { stroke: var(--muted); stroke-width: 1; visibility: hidden; }
.linechart .readout { visibility: hidden; pointer-events: none; }
.linechart .readout rect { fill: var(--surface); stroke: var(--line); }
.linechart .readout text { fill: var(--muted); }
.linechart .readout .head { fill: var(--muted); font-weight: 600; }
.linechart .col:hover .crosshair, .linechart .col:focus .crosshair,
.linechart .col:hover .readout, .linechart .col:focus .readout { visibility: visible; }
.linechart .col:focus-visible .hit { stroke: var(--muted); stroke-width: 1; }
.key { stroke-width: 2; stroke-linecap: round; }
.line.s1, .key.s1 { stroke: var(--series-1); } .dot.s1 { fill: var(--series-1); }
.line.s2, .key.s2 { stroke: var(--series-2); } .dot.s2 { fill: var(--series-2); }
.line.s3, .key.s3 { stroke: var(--series-3); } .dot.s3 { fill: var(--series-3); }
/* Archive: its views as tabs under the screens' nav, and charts or tables side by side when there is room */
.views { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; margin: 16px 0 8px; }
.views a {
  padding: 4px 12px; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; background: var(--surface);
  font-size: 0.9rem;
}
.views a:hover { color: var(--text); text-decoration: none; }
.views a[aria-current="page"] { color: var(--text); border-color: var(--own-line); background: var(--own); font-weight: 600; }
.charts, .tables { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); gap: 12px; }
.tables { align-items: start; }
ol.steps { padding-left: 1.4em; max-width: 80ch; }
ol.steps li { margin: 4px 0; }
.toolbar input[type="search"] {
  margin-left: 6px; padding: 4px 8px; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--line); border-radius: 6px; width: 14em;
}
.pager { display: flex; gap: 16px; align-items: center; justify-content: center; margin: 10px 0; color: var(--muted); font-size: 0.9rem; }
.pager button[disabled] { color: var(--muted); cursor: default; text-decoration: none; }
td.name { min-width: 20em; }

/* Phone: a compact header, two tiles a row, tighter cells, and a name column narrow enough to pin */
@media (max-width: 640px) {
  body { padding-top: 12px; font-size: 14px; }
  h1 { font-size: 1.2rem; }
  h2 { font-size: 1.05rem; }
  .top { gap: 4px; padding-bottom: 8px; }
  #status { font-size: 0.8rem; line-height: 1.35; }
  .user { font-size: 0.8rem; }
  .screens { margin-top: 8px; }
  .screens a { padding: 10px 10px; }
  .toolbar { gap: 8px 12px; }
  select { min-height: 40px; }
  main > section { margin-top: 24px; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .tile { padding: 10px 12px; }
  .tile .label { font-size: 0.78rem; }
  .tile .value { font-size: 1.3rem; }
  .tile .value.name { font-size: 1rem; }
  .tile .sub { font-size: 0.78rem; }
  th, td { padding: 6px 8px; }
  td.product { min-width: 12rem; }
  .product img { width: 28px; height: 28px; margin-right: 8px; }
  /* a pinned title (the Archive's) narrow enough to leave room beside it; Position's best listing, not pinned,
     wide enough to keep a row to two or three lines */
  td.listing { min-width: 12rem; }
  td.sub.listing { min-width: 20rem; }
  td.name { min-width: 12rem; }
}

/* The download tab (/unduh): screens as checkboxes, one button */
.download-form fieldset { border: 1px solid var(--line); border-radius: 6px; padding: 8px 12px 12px; margin-inline: 0; }
.download-form legend { color: var(--muted); font-size: 0.9rem; padding: 0 4px; }
.download-form .check { display: inline-flex; gap: 6px; align-items: center; margin: 6px 16px 0 0; }
.download-form button {
  padding: 9px 14px; font: inherit; font-weight: 600; color: var(--surface);
  background: var(--text); border: 0; border-radius: 6px; cursor: pointer;
}
.download-form button:focus-visible { outline: 2px solid var(--link); outline-offset: 1px; }

/* Product lines: the line the niche select shows (its tile and its row in the lines table) */
.tile.current { border-color: var(--own-line); box-shadow: inset 0 0 0 1px var(--own-line); }
tr.current { --row-bg: var(--own); }
