/* styles.css - all styling for the Resell Tracker dashboard (no inline styles anywhere: the CSP
   in _headers is style-src 'self').

   The look: a quiet ledger. Cool paper background, hairline borders instead of shadows, one teal
   accent (matches the app icon), a serif for the profit figure and headings, the system sans for
   everything else. Numbers are tabular so columns line up. No web fonts: both stacks are fonts
   already on the device.

   Colour jobs (keep them separate):
     --accent          the selected period, the primary button, focus rings, the chart line
     --good / --bad    profit sign only (always paired with a minus sign or a word, never colour alone)
     --warn*           "needs a cost" only
     --ebay / --lysted platform identity, only ever as a dot or a bar, never as text colour

   Layout: mobile first (works from 320px, designed at 375px). From 900px the hero + chart sit
   beside the totals and platform panels, and the sales list becomes a real table.
   Radius scale: 6px chips, 8px controls, 12px panels, 99px pills. Spacing on a 4px grid.
   Light/dark follow prefers-color-scheme; motion is limited to short colour fades and is removed
   under prefers-reduced-motion. */

:root {
  color-scheme: light dark;
  --paper: #f2f4f1; --surface: #fcfdfb; --surface-2: #e8ece8;
  --ink: #17201d; --muted: #56645f; --line: #dbe1dd; --line-strong: #bcc7c1;
  --accent: #0e6b63; --accent-ink: #ffffff; --accent-soft: #0e6b631f;
  --good: #17713f; --bad: #b0281f;
  --warn: #7d5200; --warn-bg: #f7ebc6;
  --ebay: #2563c9; --lysted: #c9620e;
  --serif: ui-serif, "New York", "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0f1513; --surface: #161d1a; --surface-2: #1f2925;
    --ink: #e4ebe7; --muted: #98a7a1; --line: #27322e; --line-strong: #3d4b46;
    --accent: #56c2b4; --accent-ink: #06211d; --accent-soft: #56c2b426;
    --good: #62cc8f; --bad: #f28b82;
    --warn: #f0c869; --warn-bg: #3a2e0e;
    --ebay: #6ea8f7; --lysted: #f2a35e;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font: 15px/1.5 var(--sans);
  padding-bottom: env(safe-area-inset-bottom);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
h1, h2, p, dl, dd, ul, fieldset { margin: 0; padding: 0; }
ul { list-style: none; }
fieldset { border: 0; min-width: 0; }
button, input { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.pos { color: var(--good); }
.neg { color: var(--bad); }

h2 { font: 600 1.0625rem/1.2 var(--serif); margin-bottom: 12px; }

/* ---------- controls ---------- */
button { cursor: pointer; border-radius: 8px; transition: background-color .12s, color .12s, border-color .12s; }
button:disabled { opacity: .6; cursor: default; }
.primary, a.button {
  display: inline-block; background: var(--accent); color: var(--accent-ink); border: 1px solid var(--accent);
  border-radius: 8px; padding: 11px 16px; font-weight: 600; text-decoration: none; text-align: center;
}
.quiet { background: none; border: 1px solid transparent; color: var(--muted); padding: 8px 10px; margin-right: -10px; font-size: .875rem; }
.quiet:hover { color: var(--ink); background: var(--surface-2); }
.field { display: block; }
.field > span { display: block; font-size: .8125rem; color: var(--muted); margin-bottom: 4px; }
input[type="email"], input[type="password"], input[type="date"] {
  display: block; width: 100%; min-height: 44px; padding: 9px 12px;
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: 8px;
  font-size: 1rem; /* 16px keeps iOS from zooming the page on focus */
}
.err { color: var(--bad); font-size: .875rem; }
.err:empty, .status:empty { display: none; }
.status { color: var(--muted); font-size: .875rem; margin-bottom: 12px; }

/* ---------- login + setup message ---------- */
.login, .notice { max-width: 380px; margin: 0 auto; padding: 16vh 20px 40px; }
.login h1, .notice h1 { font: 600 1.75rem/1.2 var(--serif); }
.login .lede { color: var(--muted); margin: 4px 0 24px; }
.login form { display: grid; gap: 16px; }
.login .primary { width: 100%; min-height: 46px; margin-top: 4px; }
.login .err { min-height: 1.4em; }
.notice { max-width: 460px; }
.notice p { margin-top: 12px; }
.notice code { background: var(--surface-2); padding: 1px 6px; border-radius: 6px; font-size: .875em; }
.notice a.button { margin-top: 8px; }

/* ---------- header + sticky period switch ---------- */
.top, .periodbar-in, .page { max-width: 1120px; margin: 0 auto; padding-left: 16px; padding-right: 16px; }
.top { display: flex; justify-content: space-between; align-items: center; padding-top: calc(10px + env(safe-area-inset-top)); padding-bottom: 2px; }
.brand { font: 600 1.0625rem/1.2 var(--serif); }
.periodbar { position: sticky; top: 0; z-index: 5; background: var(--paper); border-bottom: 1px solid var(--line); }
.periodbar-in { padding-top: 8px; padding-bottom: 10px; }
.seg {
  display: grid; grid-template-columns: repeat(5, minmax(0, 1fr));
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: 8px; padding: 2px;
}
.seg label { position: relative; display: block; }
.seg input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.seg span {
  display: grid; place-items: center; min-height: 38px; border-radius: 6px;
  font-size: .875rem; color: var(--muted); transition: background-color .12s, color .12s;
}
.seg input:hover + span { color: var(--ink); }
.seg input:checked + span { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.custom { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 10px; max-width: 420px; }

/* ---------- page ---------- */
.page { padding-top: 16px; padding-bottom: 40px; }
.banner { background: var(--warn-bg); color: var(--warn); border-radius: 8px; padding: 8px 12px; margin-bottom: 12px; font-size: .875rem; }
.grid { display: grid; gap: 12px; grid-template-columns: minmax(0, 1fr); }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 18px 16px; min-width: 0; }
.empty { border: 1px dashed var(--line-strong); background: var(--surface-2); border-radius: 8px; padding: 24px 16px; text-align: center; color: var(--muted); }
.hint { font-size: .8125rem; margin-top: 10px; }
.warn-text { color: var(--warn); }

/* ---------- hero: the profit figure, then its chart ---------- */
.hero-title { font: 400 .9375rem/1.3 var(--sans); color: var(--muted); }
.hero-range { font-size: .8125rem; color: var(--muted); }
.hero-value {
  font: 600 clamp(2.75rem, 13.5vw, 4rem)/1.05 var(--serif); letter-spacing: -.015em;
  font-variant-numeric: lining-nums tabular-nums; margin-top: 10px; overflow-wrap: anywhere;
}
.hero-compare { font-size: .875rem; color: var(--muted); margin-top: 6px; min-height: 1.5em; }
.delta { font-weight: 600; font-variant-numeric: tabular-nums; }
.delta .arrow { font-size: .7em; }

.chart-title { margin: 22px 0 4px; padding-top: 16px; border-top: 1px solid var(--line); }
/* fixed height so the layout never jumps while scrubbing */
.readout { min-height: 2.75rem; font-size: .8125rem; line-height: 1.375rem; color: var(--muted); }
.readout p { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.readout-main { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }
.readout.is-hint .readout-main { color: var(--muted); font-weight: 400; }
.chart { margin-top: 6px; border-radius: 8px; }
.chart svg { display: block; width: 100%; touch-action: pan-y; cursor: crosshair; -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none; }
.c-grid { stroke: var(--line); stroke-width: 1; }
.c-zero { stroke: var(--line-strong); stroke-width: 1; }
.c-txt { fill: var(--muted); font: 11px var(--sans); font-variant-numeric: tabular-nums; }
.c-area { fill: var(--accent); opacity: .12; }
.c-line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.c-dot { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.c-cross { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }

/* ---------- totals tally ---------- */
.tally-line { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 7px 0; }
.tally dd, .facts dd, .foot dd { font-variant-numeric: tabular-nums; text-align: right; }
.tally .minus dt { color: var(--muted); }
.tally .total { border-top: 1px solid var(--ink); margin-top: 6px; padding-top: 10px; font-weight: 600; }
.tally .total dt { color: var(--ink); }
.tally .total dd { font: 600 1.25rem/1.2 var(--serif); font-variant-numeric: lining-nums tabular-nums; }
.facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-top: 14px; }
.facts > div { background: var(--surface-2); border-radius: 8px; padding: 10px 12px; }
.facts dt { font-size: .8125rem; color: var(--muted); }
.facts dd { text-align: left; font: 600 1.25rem/1.3 var(--serif); font-variant-numeric: lining-nums tabular-nums; }
.facts .warn { background: var(--warn-bg); }
.facts .warn dt, .facts .warn dd { color: var(--warn); }
.mark { display: inline-grid; place-items: center; width: 1.1em; height: 1.1em; margin-right: 6px; border-radius: 99px; border: 1.5px solid currentColor; font: 700 .7em/1 var(--sans); vertical-align: .12em; }

/* ---------- platform split ---------- */
.plat + .plat { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line); }
.plat-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.plat-name { font-weight: 600; }
.plat-profit { font: 600 1.25rem/1.2 var(--serif); font-variant-numeric: lining-nums tabular-nums; }
.plat-sub { font-size: .8125rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 99px; margin-right: 7px; vertical-align: .06em; background: var(--muted); }
.dot.ebay, .bar-fill.ebay { background-color: var(--ebay); }
.dot.lysted, .bar-fill.lysted { background-color: var(--lysted); }
.bar { height: 8px; margin: 8px 0 6px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.bar-fill { display: block; height: 100%; min-width: 2px; border-radius: 4px; background: var(--muted); }
/* a loss is hatched, so bar length is never mistaken for a gain */
.bar-fill.loss { background-image: repeating-linear-gradient(135deg, transparent 0 3px, var(--surface) 3px 6px); }

/* ---------- sales: compact blocks on phones, a table from 900px ---------- */
.sales { margin-top: 28px; }
.count { font: 400 .8125rem var(--sans); color: var(--muted); margin-left: 4px; font-variant-numeric: tabular-nums; }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th, td { padding: 0; text-align: left; font-weight: 400; }
.tag { display: inline-flex; align-items: center; white-space: nowrap; }
.sub { display: block; font-size: .8125rem; color: var(--muted); }
.est { margin-left: 4px; font-size: .6875rem; color: var(--muted); border: 1px solid var(--line-strong); border-radius: 6px; padding: 0 4px; white-space: nowrap; }
.needs { color: var(--warn); background: var(--warn-bg); border-radius: 6px; padding: 1px 6px; font-size: .8125rem; white-space: nowrap; }
.more { display: block; width: 100%; margin-top: 12px; min-height: 44px; background: var(--surface); border: 1px solid var(--line-strong); }
.more:hover { background: var(--surface-2); }

@media (max-width: 899px) {
  .tablewrap { border-top: 1px solid var(--line); }
  table, tbody { display: block; }
  thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  tbody tr {
    display: grid; grid-template-columns: repeat(4, minmax(0, 1fr));
    grid-template-areas: "item item item profit" "sale fees ship cost";
    gap: 10px 8px; padding: 14px 0; border-bottom: 1px solid var(--line);
  }
  td { display: block; min-width: 0; }
  .c-date, .c-plat { display: none; }
  .c-item { grid-area: item; }
  .c-item .title { display: block; font-weight: 600; line-height: 1.3; }
  .meta { display: flex; flex-wrap: wrap; gap: 0 12px; font-size: .8125rem; color: var(--muted); margin-top: 2px; }
  .c-profit { grid-area: profit; text-align: right; font: 600 1.125rem/1.3 var(--serif); font-variant-numeric: lining-nums tabular-nums; }
  .c-sale { grid-area: sale; } .c-fees { grid-area: fees; } .c-ship { grid-area: ship; } .c-cost { grid-area: cost; }
  .c-sale, .c-fees, .c-ship, .c-cost { font-size: .8125rem; }
  /* each figure carries its own label, since the header row is off-screen here */
  .c-sale::before, .c-fees::before, .c-ship::before, .c-cost::before { content: attr(data-label); display: block; font-size: .75rem; color: var(--muted); }
  .est { display: inline-block; margin-left: 0; }
  .c-fees .est, .c-ship .est { margin-left: 3px; }
}

@media (min-width: 900px) {
  .tablewrap { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; overflow-x: auto; }
  th, td { padding: 11px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; vertical-align: top; }
  th { font-size: .8125rem; color: var(--muted); border-bottom-color: var(--line-strong); }
  tbody tr:last-child td { border-bottom: 0; }
  tbody tr:hover td { background: var(--surface-2); }
  .n { text-align: right; }
  .c-date { color: var(--muted); }
  .c-item { white-space: normal; min-width: 200px; }
  .c-item .title { display: block; }
  .meta { display: none; }
  .c-profit { font-weight: 600; }
}

/* ---------- housekeeping footer ---------- */
.foot { margin-top: 32px; padding-top: 20px; border-top: 1px solid var(--line); }
.foot dl { display: grid; gap: 6px; font-size: .875rem; }
.foot dl > div { display: flex; justify-content: space-between; gap: 12px; }
.foot dt { color: var(--muted); }

/* ---------- wider screens ---------- */
@media (min-width: 600px) {
  .panel { padding: 22px; }
  .foot dl { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 24px; }
  .foot dl > div { display: block; }
  .foot dd { text-align: left; }
}
@media (min-width: 900px) {
  .top, .periodbar-in, .page { padding-left: 24px; padding-right: 24px; }
  .seg { max-width: 460px; }
  .grid { grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr); align-items: start; gap: 16px; }
  .hero { grid-row: span 2; }
  .hero-value { font-size: 4.25rem; }
}

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

/* privacy.html: plain reading page */
.privacy { max-width: 40rem; margin: 0 auto; padding: 2rem 1.25rem 4rem; line-height: 1.6; }
.privacy h1 { margin-top: 0; }
.privacy h2 { font-size: 1.05rem; margin: 1.5rem 0 .25rem; }
.privacy a { color: var(--accent, inherit); }
