/* Price Tracker -- mobile-first PWA styling.
 *
 * No build step and no framework (see wrangler.jsonc): this file is served
 * as-is. Everything is driven by the custom properties below so light and
 * dark are one definition apart rather than a set of hardcoded hexes that
 * happen to survive both, which is what the placeholder UI did.
 */

:root {
  color-scheme: light dark;

  --bg: #ffffff;
  --surface: #ffffff;
  --surface-2: #f4f4f6;
  --surface-3: #ebecef;
  --text: #14161a;
  --muted: #6b7280;
  --border: #e2e4e9;
  --accent: #0066cc;
  --accent-text: #ffffff;
  --success: #00875a;
  --success-bg: #00875a1a;
  --warning: #b45309;
  --warning-bg: #b453091f;
  --danger: #c0392b;
  --danger-bg: #c0392b1a;

  /* The two swipe outcomes. These are the colours the card slides to reveal,
   * so they are full-strength surfaces rather than tints. */
  --swipe-buy: #00875a;
  --swipe-bin: #b0402f;

  --radius: 0.85rem;
  --radius-sm: 0.45rem;
  /* Nothing interactive goes below this. The old "stop tracking" link was
   * ~20px, which is a miss on a phone more often than a hit. */
  --tap: 44px;

  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);

  --tabbar-h: calc(58px + var(--safe-b));
  --pad-l: calc(1rem + var(--safe-l));
  --pad-r: calc(1rem + var(--safe-r));

  font-family: -apple-system, system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101114;
    --surface: #191b1f;
    --surface-2: #212328;
    --surface-3: #2a2d33;
    --text: #f2f3f5;
    --muted: #9aa0aa;
    --border: #2c2f36;
    --accent: #4d9fff;
    --accent-text: #08131f;
    --success: #3ddc97;
    --success-bg: #3ddc9722;
    --warning: #fbbf24;
    --warning-bg: #fbbf2422;
    --danger: #ff6b5e;
    --danger-bg: #ff6b5e22;

    --swipe-buy: #1c7a58;
    --swipe-bin: #a63f31;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.45;
  /* viewport-fit=cover plus a fixed tab bar means all four insets matter;
   * the placeholder only ever padded the left. */
  padding-bottom: calc(var(--tabbar-h) + 1rem);
  -webkit-tap-highlight-color: transparent;
}

/* Motion is used here to explain a gesture, so it is decoration for anyone who
 * has asked not to see it. Kept to one global rule rather than per-component
 * guards, which is the kind of thing that gets forgotten on the next addition. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* -------------------------------------------------------------- sign-in gate */

.gate {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  background: var(--bg);
  padding: 2rem calc(1.5rem + var(--safe-r)) calc(2rem + var(--safe-b))
           calc(1.5rem + var(--safe-l));
}
.gate[hidden] { display: none; }

.gate-inner { max-width: 22rem; text-align: center; }

.gate-mark {
  width: 56px;
  height: 56px;
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
  margin-bottom: 0.75rem;
}

.gate h1 { font-size: 1.5rem; margin: 0 0 0.35rem; }
.gate-blurb { color: var(--muted); margin: 0 0 1.75rem; font-size: 0.95rem; }
/* Google renders its own button here; centre whatever width it picks. */
#gsi-button { display: flex; justify-content: center; min-height: 44px; }
#gate-status { margin-top: 1rem; }

/* ------------------------------------------------------------------ header */

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding-top: var(--safe-t);
}
.app-header[hidden] { display: none; }

.app-header .bar {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.6rem var(--pad-r) 0.6rem var(--pad-l);
}

.app-header h1 {
  font-size: 1.05rem;
  font-weight: 650;
  margin: 0;
  flex: 1;
  min-width: 0;
}

/* Back out of a profile sub-screen. Sits before the title and reclaims the
 * left padding so the title does not jump when it appears. */
.back {
  background: none;
  border: 0;
  padding: 0;
  margin-left: -0.5rem;
  width: 2rem;
  min-height: 2rem;
  color: var(--accent);
  display: grid;
  place-items: center;
}
.back[hidden] { display: none; }
.back svg {
  width: 22px; height: 22px; fill: none; stroke: currentColor;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}

.count {
  font-size: 0.8rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* ------------------------------------------------------------------- chips */

.chips {
  display: flex;
  gap: 0.4rem;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 0 var(--pad-r) 0.5rem var(--pad-l);
}
.chips::-webkit-scrollbar { display: none; }
.chips:empty { display: none; }

.chip {
  flex: none;
  font: inherit;
  font-size: 0.82rem;
  line-height: 1;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text);
  white-space: nowrap;
  cursor: pointer;
}

.chip[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

/* ------------------------------------------------------------------ layout */

main { padding: 0 var(--pad-r) 0 var(--pad-l); }
main[hidden] { display: none; }

.screen[hidden] { display: none; }

h2 {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 1.5rem 0 0.5rem;
}
h2.danger-heading { color: var(--danger); }

.muted { color: var(--muted); font-size: 0.85rem; }
.err { color: var(--danger); margin-top: 0.75rem; }
.empty { color: var(--muted); text-align: center; padding: 3rem 1rem; }

/* Read aloud, never drawn. The price-change badge is an arrow plus a number,
 * which a screen reader would otherwise announce as a bare amount with no
 * indication of which way it moved. */
.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ------------------------------------------------------------------ inputs */

input, button, select, textarea { font: inherit; color: var(--text); }

input[type="text"], input[type="number"], input:not([type]), select {
  width: 100%;
  min-height: var(--tap);
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

button {
  min-height: var(--tap);
  padding: 0.6rem 1rem;
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
  cursor: pointer;
}
button:disabled { opacity: 0.5; }

button.secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  font-weight: 500;
}

button.danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--border);
  font-weight: 500;
}

button.wide { width: 100%; margin-top: 0.75rem; }

/* ------------------------------------------------------------------- cards */

/* Two layers. `.swipe` is the track that holds the coloured intent behind the
 * card; `.card` is what actually moves. Transform on the card alone keeps the
 * animation on the compositor -- animating margins or `left` here would repaint
 * a list of images on every frame. */
.swipe {
  position: relative;
  margin-top: 0.75rem;
  border-radius: var(--radius);
  overflow: hidden;
  /* Let the browser own vertical scrolling and hand us the horizontal axis,
   * so a downward flick still scrolls the list rather than fighting the
   * gesture handler. */
  touch-action: pan-y;
}

.swipe-hint {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.25rem;
  color: #fff;
  font-weight: 650;
  font-size: 0.9rem;
  opacity: 0;
}
.swipe-hint svg {
  width: 20px; height: 20px; fill: none; stroke: currentColor;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
  vertical-align: -0.25em; margin-right: 0.3rem;
}
/* Which side shows depends on the direction, set from JS on the track. */
.swipe[data-dir="right"] .swipe-hint { background: var(--swipe-buy); opacity: 1; }
.swipe[data-dir="left"]  .swipe-hint { background: var(--swipe-bin); opacity: 1; }
.swipe[data-dir="right"] .hint-bin,  .swipe[data-dir="left"] .hint-buy { visibility: hidden; }

/* Past the commit threshold the label steps up, so the gesture confirms
 * itself before you let go rather than after. */
.swipe[data-armed="1"] .swipe-hint { font-size: 1rem; }

.card {
  position: relative;
  display: flex;
  gap: 0.85rem;
  padding: 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  will-change: transform;
}
/* Only while settling back or flying out -- during a drag the transform
 * follows the finger and a transition would lag behind it. */
.card.settling { transition: transform 0.22s cubic-bezier(0.2, 0, 0, 1); }
.swipe.leaving {
  transition: height 0.2s ease 0.06s, margin-top 0.2s ease 0.06s,
              opacity 0.2s ease 0.06s;
  height: 0;
  margin-top: 0;
  opacity: 0;
}

.card .thumb {
  width: 84px;
  height: 112px;
  flex: none;
  object-fit: cover;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  /* A null image_url used to render <img src=""> which re-requests the page. */
  border: 0;
}

.card .body { min-width: 0; flex: 1; }

/* The price is the reason this app exists, so it leads and the name supports
 * it. The previous card had both at roughly one weight, which made every row
 * read as a product listing rather than a price watch. */
.price-row {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.15rem;
}

.price {
  font-size: 1.35rem;
  font-weight: 750;
  line-height: 1.15;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.was {
  text-decoration: line-through;
  color: var(--muted);
  font-weight: 400;
  font-size: 0.85rem;
}

/* Price movement since tracking started: arrow, amount, colour. Down is the
 * good direction here, so down is green -- the opposite of a stock ticker,
 * and worth stating because it looks like a bug otherwise. */
.delta {
  display: inline-flex;
  align-items: center;
  gap: 0.15rem;
  font-size: 0.82rem;
  font-weight: 650;
  padding: 0.1rem 0.4rem 0.1rem 0.3rem;
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.delta.down { color: var(--success); background: var(--success-bg); }
.delta.up { color: var(--danger); background: var(--danger-bg); }
.delta svg {
  width: 13px; height: 13px; fill: none; stroke: currentColor;
  stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round;
}

.card .name {
  font-weight: 500;
  font-size: 0.92rem;
  line-height: 1.3;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.meta { color: var(--muted); font-size: 0.8rem; margin-top: 0.15rem; }

/* Row of small facts under the name: shop, type, and the tracked size. */
.facts {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.4rem;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 1;
  padding: 0.28rem 0.5rem;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  white-space: nowrap;
}
.pill.size { background: var(--surface-3); color: var(--text); }
.pill.size.ok { background: var(--success-bg); color: var(--success); }
.pill.size.gone { background: var(--warning-bg); color: var(--warning); }
.pill.low { background: var(--success-bg); color: var(--success); }
.pill.warn { background: var(--warning-bg); color: var(--warning); }

.size-line { font-size: 0.85rem; margin-top: 0.3rem; font-weight: 500; }
.size-line.ok { color: var(--success); }
.size-line.gone { color: var(--warning); }
.size-line.dead { color: var(--muted); }

/* Shown once, under the first card, until the gesture has been used. A tap
 * target would defeat the point; this is a caption, not a control. */
.swipe-teach {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  margin: 0.6rem 0 0;
  font-size: 0.78rem;
  color: var(--muted);
}
.swipe-teach svg {
  width: 15px; height: 15px; fill: none; stroke: currentColor;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}

/* ------------------------------------------------------------ size picker */

.sizes {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.5rem;
}

.size {
  min-width: var(--tap);
  min-height: var(--tap);
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 500;
}

.size[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 700;
}

/* Sold out. data-gone rather than :disabled, because the size you are
 * currently watching stays enabled so you can stop watching it. */
.size[data-gone] {
  text-decoration: line-through;
  color: var(--muted);
  background: var(--surface-2);
  opacity: 1; /* the strike-through already reads as unavailable */
}
.size[data-gone][aria-pressed="true"] {
  /* Watched but gone: keep it legible and clearly still selected. */
  background: var(--warning-bg);
  border-color: var(--warning);
  color: var(--warning);
}

.size .low {
  display: block;
  font-size: 0.6rem;
  font-weight: 500;
  color: var(--warning);
  line-height: 1;
}

/* -------------------------------------------------------------- detail sheet */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: var(--bg);
  overflow-y: auto;
  padding: 0 var(--pad-r) calc(2rem + var(--safe-b)) var(--pad-l);
}
.sheet[hidden] { display: none; }

.sheet-bar {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--bg);
  padding: calc(0.5rem + var(--safe-t)) 0 0.5rem;
  margin-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}
.sheet-bar button {
  background: none;
  color: var(--accent);
  padding-left: 0;
  display: inline-flex;
  align-items: center;
  gap: 0.15rem;
}
.sheet-bar svg {
  width: 20px; height: 20px; fill: none; stroke: currentColor;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}

/* The detail view gets the room the two buttons used to take. A tag photo is
 * often the only way to tell two near-identical garments apart, so it is worth
 * the space. */
.hero {
  display: block;
  width: 100%;
  aspect-ratio: 3 / 4;
  max-height: 58vh;
  object-fit: contain;
  border-radius: var(--radius);
  background: var(--surface-2);
  margin-bottom: 0.85rem;
}

.detail-head { margin-bottom: 0.35rem; }
.detail-head .price { font-size: 1.75rem; }
.detail-head .name {
  font-size: 1.02rem;
  font-weight: 600;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  margin-top: 0.15rem;
}

.link {
  display: inline-block;
  margin-top: 0.5rem;
  color: var(--accent);
  font-size: 0.85rem;
  text-decoration: none;
}

/* height:auto keeps the scale uniform. Forcing a fixed height against a
 * fixed viewBox stretches the SVG horizontally, which distorts the axis
 * labels along with everything else. */
.chart {
  width: 100%;
  height: auto;
  display: block;
  margin: 0.5rem 0 0.25rem;
  overflow: visible;
}
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2;
               stroke-linejoin: round; stroke-linecap: round; }
.chart .area { fill: var(--accent); opacity: 0.1; }
.chart .dot { fill: var(--accent); }
.chart .dot.low { fill: var(--success); }
.chart .grid { stroke: var(--border); stroke-width: 1; }
.chart text { fill: var(--muted); font-size: 10px; }

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(90px, 1fr));
  gap: 0.5rem;
  margin: 0.75rem 0;
}
.stat {
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.6rem;
}
.stat .k { font-size: 0.7rem; color: var(--muted); text-transform: uppercase;
           letter-spacing: 0.04em; }
.stat .v { font-weight: 650; font-variant-numeric: tabular-nums; }

.field { display: flex; gap: 0.5rem; margin-top: 0.5rem; }
.field input { flex: 1; }
.field button { flex: none; }

.card-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.6rem;
}
.card-actions button { flex: 1; min-height: 42px; font-size: 0.9rem; }

/* ---------------------------------------------------------------- tab bar */

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: flex;
  align-items: stretch;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-b);
}
.tabbar[hidden] { display: none; }

.tabbar button {
  flex: 1;
  min-height: 58px;
  background: none;
  border: 0;
  border-radius: 0;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 500;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
}
.tabbar button[aria-selected="true"] { color: var(--accent); font-weight: 650; }
.tabbar .glyph {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Add is the only tab that starts a task rather than switching a view, so it
 * is a raised disc instead of another icon-and-label. */
.tabbar .fab { flex: 0 0 5rem; position: relative; }
.fab-disc {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.22);
  transform: translateY(-8px);
  transition: transform 0.15s ease;
}
.tabbar .fab:active .fab-disc { transform: translateY(-8px) scale(0.94); }
.tabbar .fab[aria-selected="true"] .fab-disc { transform: translateY(-8px) rotate(45deg); }
.fab-disc .glyph { width: 26px; height: 26px; stroke-width: 2.2; }

/* --------------------------------------------------------------- add screen */

.capture { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem;
           margin-top: 0.9rem; }

.capture-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  min-height: 96px;
  padding: 0.75rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 0.85rem;
  font-weight: 600;
  text-align: center;
  cursor: pointer;
}
.capture-btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}
.capture-btn input { display: none; }
.capture-btn .glyph {
  width: 26px; height: 26px; fill: none; stroke: currentColor;
  stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round;
}

.or {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin: 1.1rem 0 0.5rem;
  color: var(--muted);
  font-size: 0.78rem;
}
.or::before, .or::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.add-row { display: flex; gap: 0.5rem; }
.add-row input { flex: 1; }
.add-row button { flex: none; }

/* --------------------------------------------------------------- profile */

.account {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.9rem 0.85rem;
  margin-top: 0.9rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
/* Deliberately a monogram, not an avatar: no profile picture is fetched, so
 * nothing here depends on Google's CDN or leaks a request on every open. */
.account .mono {
  width: 42px;
  height: 42px;
  flex: none;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 700;
  font-size: 1.05rem;
}
.account .who { min-width: 0; }
.account .who b { display: block; font-weight: 600; }
.account .who span {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.menu {
  margin-top: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
}
.menu button {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  min-height: 54px;
  padding: 0 0.85rem;
  background: none;
  border: 0;
  border-radius: 0;
  color: var(--text);
  font-weight: 500;
  text-align: left;
}
.menu button + button { border-top: 1px solid var(--border); }
.menu button:active { background: var(--surface-2); }
.menu .glyph {
  width: 20px; height: 20px; flex: none; fill: none; stroke: var(--muted);
  stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
.menu span { flex: 1; }
.menu em {
  font-style: normal;
  color: var(--muted);
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}
.menu .chev {
  width: 8px; height: 8px; flex: none;
  border-right: 2px solid var(--muted);
  border-top: 2px solid var(--muted);
  transform: rotate(45deg);
  opacity: 0.6;
}

.scan-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  padding: 0.7rem 0.5rem;
  background: none;
  border: 0;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  color: var(--text);
  font-weight: 500;
  text-align: left;
}
.scan-row .code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.scan-row .when { margin-left: auto; font-size: 0.75rem; color: var(--muted);
                  font-weight: 400; }

#status { font-size: 0.75rem; color: var(--muted); margin: 0.4rem 0 0; }
#push-state, #push-status, #server-state, #delete-status { margin: 0.3rem 0; }
#push-test { margin-top: 0.5rem; }
#push-test select { margin: 0.3rem 0; }
