/* The Bargain Hunt — design system (spec §12).
   Deliberately not Material's default palette: deep petrol accent, cool
   neutrals, no purple anywhere. Base body text is 17px, not 14px. */

:root {
  --ink: #152232;
  --ink-muted: #5a6779;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --line: #dde2e9;
  --accent: #0f5257;
  --bargain: #1b6b4a;
  --wait: #8a6410;
  --trap: #9b3232;

  --font-display: "Archivo", "Segoe UI", system-ui, sans-serif;
  --font-body: "Source Sans 3", "Segoe UI", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;

  --tap: 48px;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(21, 34, 50, 0.06), 0 4px 12px rgba(21, 34, 50, 0.05);
}

@media (prefers-color-scheme: dark) {
  :root {
    --ink: #e8ecf1;
    --ink-muted: #94a1b2;
    --bg: #0e1620;
    --surface: #182430;
    --line: #2a3846;
    --accent: #4fa9a8;
    --bargain: #5fbf92;
    --wait: #d9a93f;
    --trap: #e07a7a;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 12px rgba(0, 0, 0, 0.25);
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  /* Painting the theme colour here as well as on body stops the white flash
     when the browser paints the page background before styles settle. */
  background: var(--bg);
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 17px;
  line-height: 1.5;
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  /* Room for the fixed bottom nav plus the phone's home indicator. */
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

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

.app {
  max-width: 620px;
  margin: 0 auto;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px 12px;
  padding-top: calc(14px + env(safe-area-inset-top));
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}

.topbar h1 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.35rem;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.topbar .sub {
  margin: 2px 0 0;
  font-size: 0.88rem;
  color: var(--ink-muted);
}

.topbar .grow {
  flex: 1;
  min-width: 0;
}

.icon-btn {
  flex: none;
  width: var(--tap);
  height: var(--tap);
  display: grid;
  place-items: center;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 50%;
  cursor: pointer;
  color: var(--ink);
}

.icon-btn:active {
  background: var(--line);
}

.icon-btn svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

main {
  padding: 16px;
  display: grid;
  gap: 16px;
}

/* ------------------------------------------------------------ bottom nav */

.nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}

.nav button {
  flex: 1;
  min-height: var(--tap);
  padding: 8px 4px 10px;
  background: none;
  border: 0;
  cursor: pointer;
  color: var(--ink-muted);
  display: grid;
  justify-items: center;
  gap: 3px;
  font-size: 0.78rem;
  font-weight: 600;
}

.nav button svg {
  width: 23px;
  height: 23px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.nav button[aria-current="page"] {
  color: var(--accent);
}

/* --------------------------------------------------------------- summary */

.summary {
  display: grid;
  gap: 4px;
}

.summary .count {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.5rem;
  letter-spacing: -0.02em;
}

.summary .breakdown {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--ink-muted);
}

.summary .note {
  margin-top: 6px;
  color: var(--ink-muted);
}

/* ------------------------------------------------------------- tearsheet */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  display: grid;
  gap: 14px;
}

.card-head {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  flex-wrap: wrap;
}

.ticker {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 1.3rem;
  letter-spacing: 0.01em;
}

.name {
  width: 100%;
  color: var(--ink-muted);
  font-size: 0.95rem;
  margin-top: -6px;
}

/* Verdict pills use a tinted background with a matching border, not a solid
   fill — solid colour blocks at that size read as alarms (spec §12). */
.pill {
  margin-left: auto;
  flex: none;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid currentColor;
  background: color-mix(in srgb, currentColor 12%, transparent);
  white-space: nowrap;
}

.pill.bargain { color: var(--bargain); }
.pill.wait    { color: var(--wait); }
.pill.trap    { color: var(--trap); }
.pill.neutral { color: var(--ink-muted); }

.prices {
  display: flex;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.prices .now {
  font-size: 1.45rem;
  font-weight: 600;
}

.prices .prev {
  color: var(--ink-muted);
  text-decoration: line-through;
}

.prices .drop {
  margin-left: auto;
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--trap);
}

.window {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--ink-muted);
  letter-spacing: 0.04em;
}

/* --------------------------------------------------------- the range bar */

.range svg {
  display: block;
  width: 100%;
  height: 26px;
  overflow: visible;
}

.range-labels {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-muted);
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}

.range-caption {
  margin-top: 6px;
  font-size: 0.92rem;
  color: var(--ink-muted);
}

/* ---------------------------------------------------------- text section */

/* Structural, not decorative — they mark the fixed parts of every tearsheet
   so he can jump straight to the part he wants (spec §12). */
.label {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--ink-muted);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.section p {
  margin: 4px 0 0;
}

.cause-type {
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid currentColor;
  background: color-mix(in srgb, currentColor 12%, transparent);
  text-transform: lowercase;
}

.cause-type.oneoff    { color: var(--bargain); }
.cause-type.fixable   { color: var(--wait); }
.cause-type.permanent { color: var(--trap); }
.cause-type.neutral   { color: var(--ink-muted); }

/* ----------------------------------------------------------- metric grid */

.metrics {
  display: grid;
  /* The floor is in rem, not px, so the grid drops to fewer columns as the
     system font size grows instead of shredding values into "Neg ati ve". */
  grid-template-columns: repeat(auto-fit, minmax(7.5rem, 1fr));
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.metric {
  padding: 9px 8px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  min-width: 0;
}

.metric .m-label {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.04em;
  color: var(--ink-muted);
  text-transform: uppercase;
  overflow-wrap: anywhere;
}

.metric .m-value {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 1rem;
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
  /* break-word, not anywhere: only split a value when it cannot fit on a
     line of its own, so "Negative" stays whole. */
  overflow-wrap: break-word;
}

/* ------------------------------------------------------- state / banners */

.state {
  text-align: center;
  padding: 40px 20px;
  display: grid;
  gap: 10px;
  justify-items: center;
}

.state h2 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.3rem;
  letter-spacing: -0.02em;
}

.state p {
  margin: 0;
  color: var(--ink-muted);
  max-width: 34ch;
}

.banner {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 11px 13px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 0.93rem;
  color: var(--ink-muted);
}

.banner.error {
  border-color: color-mix(in srgb, var(--trap) 45%, var(--line));
  color: var(--ink);
}

.btn {
  min-height: var(--tap);
  padding: 0 20px;
  border-radius: 999px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
}

@media (prefers-color-scheme: dark) {
  .btn { color: #08131a; }
}

.btn.ghost {
  background: transparent;
  color: var(--accent);
}

.btn:disabled {
  opacity: 0.55;
  cursor: default;
}

/* --------------------------------------------------------- progress/load */

.progress {
  display: grid;
  gap: 12px;
  padding: 28px 16px;
  justify-items: center;
  text-align: center;
}

.progress .track {
  width: 100%;
  max-width: 300px;
  height: 6px;
  border-radius: 3px;
  background: var(--line);
  overflow: hidden;
}

.progress .fill {
  height: 100%;
  width: 0;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.6s ease;
}

.progress .step {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--ink-muted);
  letter-spacing: 0.02em;
}

/* ---------------------------------------------------------- pull refresh */

.pull {
  display: grid;
  place-items: center;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--ink-muted);
  overflow: hidden;
  height: 0;
  transition: height 0.18s ease;
}

/* -------------------------------------------------------------- settings */

.group {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.group > h2 {
  margin: 0;
  padding: 12px 16px 8px;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

.row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-top: 1px solid var(--line);
  min-height: var(--tap);
  flex-wrap: wrap;
}

.row > .row-label {
  flex: 1;
  min-width: 45%;
}

.row .hint {
  display: block;
  font-size: 0.83rem;
  color: var(--ink-muted);
}

.row select,
.row input[type="text"],
.row input[type="password"],
.row input[type="time"],
.row input[type="number"] {
  min-height: var(--tap);
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink);
  max-width: 100%;
}

.row input[type="checkbox"] {
  width: 26px;
  height: 26px;
  accent-color: var(--accent);
  flex: none;
}

.checks {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 4px 16px 14px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 40px;
  padding: 6px 13px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg);
  cursor: pointer;
  font-size: 0.92rem;
}

.chip[aria-pressed="true"] {
  border-color: var(--accent);
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  font-weight: 600;
}

.preview {
  padding: 14px 16px;
  border-top: 1px solid var(--line);
  color: var(--ink-muted);
  font-size: 0.93rem;
}

.preview strong {
  color: var(--ink);
  font-weight: 600;
}

.key-state {
  font-family: var(--font-mono);
  font-size: 0.82rem;
}

.key-state.ok { color: var(--bargain); }
.key-state.bad { color: var(--trap); }

/* ------------------------------------------------------------- watchlist */

.watch-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-top: 1px solid var(--line);
  min-height: var(--tap);
  background: var(--surface);
}

.watch-row .w-main {
  flex: 1;
  min-width: 0;
  text-align: left;
  background: none;
  border: 0;
  padding: 6px 0;
  cursor: pointer;
  min-height: 44px;
}

.watch-row .w-ticker {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 1.05rem;
}

.watch-row .w-name {
  display: block;
  font-size: 0.85rem;
  color: var(--ink-muted);
  overflow-wrap: anywhere;
}

.remove {
  flex: none;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: transparent;
  cursor: pointer;
  color: var(--ink-muted);
  font-size: 1.1rem;
  line-height: 1;
}

.add-row {
  display: flex;
  gap: 10px;
  padding: 12px 16px;
  flex-wrap: wrap;
}

.add-row input {
  flex: 1;
  min-width: 120px;
  font-family: var(--font-mono);
}

/* Ticker entry only — the API key field must never look uppercased. */
.add-row input.ticker-input {
  text-transform: uppercase;
}

/* ------------------------------------------------------------ disclaimer */

.disclaimer {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}

.disclaimer summary {
  padding: 12px 16px;
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-muted);
  min-height: var(--tap);
  display: flex;
  align-items: center;
}

.disclaimer p {
  margin: 0;
  padding: 0 16px 16px;
  color: var(--ink-muted);
  font-size: 0.94rem;
}

.snackbar {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(84px + env(safe-area-inset-bottom));
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--ink);
  color: var(--bg);
  padding: 10px 12px 10px 18px;
  border-radius: 10px;
  box-shadow: var(--shadow);
  max-width: calc(100% - 32px);
}

.snackbar button {
  background: none;
  border: 0;
  color: var(--accent);
  font-weight: 700;
  cursor: pointer;
  min-height: 40px;
  padding: 0 8px;
}

@media (prefers-color-scheme: dark) {
  .snackbar { background: var(--surface); color: var(--ink); }
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.hidden { display: none !important; }
