/*
  ByteAlert: a página é uma gôndola de loja. Os produtos são etiquetas de
  prateleira (papel branco, preço em tipo condensado e pesado); a etiqueta
  amarela de oferta aparece só quando o preço chega ao teto.
*/

@font-face {
  font-family: "Archivo";
  src: url("fonts/archivo-latin-wdth.woff2") format("woff2");
  font-weight: 100 900;
  font-stretch: 62% 125%;
  font-display: swap;
}

/* Contexto "prateleira": tudo que fica direto sobre o fundo de aço */
:root {
  --shelf: #e2e5e8;
  --rail: #b4bac1;
  --ink: #000000;
  --muted: #4d555d;
  --line: #c3c8ce;
  --focus: #0038c8;

  --paper: #fbfaf6;
  --offer: #ffdd00;
  --alarm: #c8001a;

  --step--1: 0.8125rem;
  --step-0: 1rem;
  --step-1: 1.25rem;
  --step-2: 1.5625rem;
  --step-3: 2.4375rem;
  --tag-height: 11rem;
  --rail-height: 0.75rem;
  --rail-gap: 1.5rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --shelf: #1c2228;
    --rail: #0c0f12;
    --ink: #f0f2f4;
    --muted: #a3acb5;
    --line: #36404a;
    --focus: #8fb0ff;
    --paper: #ece9e0;
  }
}

/* Contexto "papel": etiquetas, ficha e diálogos são impressos, em qualquer tema */
.paper, .tag {
  --ink: #000000;
  --muted: #55524a;
  --line: #d6d2c6;
  --focus: #0038c8;
  background: var(--paper);
  color: var(--ink);
}

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

[hidden] { display: none !important; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

body {
  margin: 0;
  background: var(--shelf);
  color: var(--ink);
  font-family: "Archivo", system-ui, sans-serif;
  font-size: var(--step-0);
  line-height: 1.5;
}

h1, h2, h3, p, ul, dl, dd { margin: 0; }
ul { padding: 0; list-style: none; }

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.brand {
  font-size: var(--step-1);
  font-weight: 900;
  font-stretch: 125%;
  letter-spacing: -0.02em;
  line-height: 1;
}
.brand--large { font-size: var(--step-3); }

.link { color: var(--focus); text-underline-offset: 3px; }
.empty { color: var(--muted); max-width: 52ch; }

/* ---------------------------------------------------------------- Botões */

.button {
  font: inherit;
  font-weight: 700;
  min-height: 44px;
  padding: 0 1.125rem;
  border: 2px solid var(--ink);
  border-radius: 2px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}
.button:hover { background: color-mix(in srgb, var(--ink) 10%, transparent); }
.button--primary { background: var(--ink); color: var(--shelf); }
.paper .button--primary { color: var(--paper); }
.button--primary:hover { background: color-mix(in srgb, var(--ink) 82%, transparent); }
.button--danger { border-color: var(--alarm); color: var(--alarm); }
.button:disabled { opacity: 0.55; cursor: progress; }

/* ------------------------------------------------------------ Formulários */

.form { display: grid; gap: 1.125rem; }
.field { display: grid; gap: 0.375rem; font-weight: 700; }
.field small { font-weight: 400; color: var(--muted); font-size: var(--step--1); }
.field input {
  font: inherit;
  min-height: 44px;
  padding: 0 0.75rem;
  border: 2px solid var(--ink);
  border-radius: 2px;
  background: #ffffff;
  color: #000000;
}
.form__error, .banner { color: var(--alarm); font-weight: 700; }
.banner { padding: 1rem 1.5rem 0; }
.banner--notice { color: var(--ink); }
@media (prefers-color-scheme: dark) {
  .banner { color: #ff9a8f; }
  .banner--notice { color: var(--ink); }
}

/* ------------------------------------------------------------------ Login */

.login {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 1.5rem;
}
.login__label {
  width: min(24rem, 100%);
  padding: 2rem 1.75rem;
  border-radius: 2px;
  box-shadow: 0 var(--rail-height) 0 var(--rail);
}
.login__lead { color: var(--muted); margin: 0.75rem 0 1.75rem; }

/* --------------------------------------------------------- Barra superior */

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1.25rem;
  padding: 1.25rem 1.5rem;
}
.topbar__status { color: var(--muted); font-size: var(--step--1); }
.topbar__actions { display: flex; gap: 0.5rem; margin-left: auto; }

.page {
  display: grid;
  gap: 2.5rem;
  padding: 0.75rem 1.5rem 3rem;
  max-width: 88rem;
}

/* -------------------------------------------------------------- Prateleira */

/* Linhas de altura fixa: o trilho da gôndola é desenhado no fundo da grade */
.shelf {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(15.5rem, 1fr));
  grid-auto-rows: var(--tag-height);
  column-gap: 0.75rem;
  row-gap: calc(var(--rail-height) + var(--rail-gap));
  padding-bottom: var(--rail-height);
  background: repeating-linear-gradient(
    to bottom,
    transparent 0 var(--tag-height),
    var(--rail) var(--tag-height) calc(var(--tag-height) + var(--rail-height)),
    transparent calc(var(--tag-height) + var(--rail-height)) calc(var(--tag-height) + var(--rail-height) + var(--rail-gap))
  );
}
.shelf li { display: grid; }

/* ---------------------------------------------------------------- Etiqueta */

.tag {
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 0.25rem;
  width: 100%;
  padding: 0.75rem 0.875rem 0.625rem;
  border: 0;
  border-radius: 2px 2px 0 0;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: transform 120ms ease-out;
}
.tag:hover { transform: translateY(-3px); }
.tag[aria-current="true"] {
  transform: translateY(-6px);
  box-shadow: inset 0 0 0 3px #000000;
}

.tag__name {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  font-size: var(--step--1);
  font-weight: 700;
  line-height: 1.3;
}

/* Preço como em etiqueta de gôndola: inteiro enorme, "R$" e centavos pequenos no alto */
.tag__price {
  display: flex;
  align-items: flex-start;
  align-self: end;
  font-stretch: 62%;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  line-height: 0.85;
}
.tag__integer { font-size: 4.25rem; letter-spacing: -0.01em; }
.tag__currency, .tag__cents { font-size: 1.375rem; line-height: 1; padding-top: 0.25rem; }
.tag__currency { margin-right: 0.25rem; }
.tag__cents { margin-left: 0.125rem; }

.tag__word {
  align-self: end;
  font-size: 2.75rem;
  font-stretch: 62%;
  font-weight: 900;
  line-height: 0.9;
}

.tag__foot {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  padding-top: 0.375rem;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: var(--step--1);
  line-height: 1.3;
}
.tag__target { color: var(--ink); font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Oferta: o preço chegou ao teto */
.tag--hit { background: var(--offer); --muted: #3d3600; --line: #000000; }

/* Esgotado: etiqueta hachurada, como uma posição vazia na gôndola */
.tag--out {
  background:
    repeating-linear-gradient(135deg, transparent 0 9px, rgb(0 0 0 / 0.07) 9px 11px),
    var(--paper);
}
.tag--out .tag__word, .tag--waiting .tag__word, .tag--paused .tag__word { color: var(--muted); }
.tag--problem .tag__word { color: var(--alarm); }
.tag--paused { opacity: 0.6; }

/* ------------------------------------------------------------------- Ficha */

.sheet {
  padding: 2rem;
  border-radius: 2px;
  min-width: 0;
}
.sheet__head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.5rem 1.5rem;
  padding-bottom: 1.25rem;
  border-bottom: 3px solid var(--ink);
}
.sheet__name {
  flex: 1 1 18rem;
  font-size: var(--step-2);
  font-weight: 900;
  font-stretch: 87%;
  line-height: 1.15;
}
.sheet__title { font-size: var(--step-0); font-weight: 800; margin: 2.25rem 0 0.75rem; }
.sheet__columns { display: grid; gap: 0 3rem; }
@media (min-width: 56rem) {
  .sheet__columns { grid-template-columns: 1fr 1fr; }
}
.sheet__actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 2.5rem; }

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
  gap: 1.25rem 2rem;
  margin-top: 1.5rem;
}
.stats dt { color: var(--muted); font-size: var(--step--1); }
.stats dd {
  font-size: var(--step-2);
  font-weight: 800;
  font-stretch: 75%;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}
.stats small { display: block; font-size: var(--step--1); font-weight: 400; font-stretch: 100%; color: var(--muted); }

.rows li {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.25rem 1rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--line);
}
.rows time { color: var(--muted); font-size: var(--step--1); }

.table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.table th, .table td { padding: 0.5rem 0; border-bottom: 1px solid var(--line); text-align: left; font-weight: 400; }
.table th { color: var(--muted); font-size: var(--step--1); }
.table .num { text-align: right; }

/* ------------------------------------------------------- Buscas automáticas */

.searches__head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.75rem; margin-bottom: 1rem; }
.searches__title { font-size: var(--step-1); font-weight: 900; font-stretch: 87%; }
.searches { display: grid; gap: 0.75rem; }

.search { border-radius: 2px; min-width: 0; }
.search__summary {
  display: grid;
  grid-template-columns: minmax(8rem, 1fr) minmax(0, 2fr) auto;
  align-items: baseline;
  gap: 0.25rem 1.5rem;
  padding: 1rem 1.25rem;
  cursor: pointer;
}
.search__term { font-size: var(--step-1); font-weight: 900; font-stretch: 75%; line-height: 1.2; }
.search__status { color: var(--muted); }
.search__target { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.search[open] .search__summary { border-bottom: 3px solid var(--ink); }
.search__body { padding: 0.5rem 1.25rem 1.25rem; }
.search__more { color: var(--muted); font-size: var(--step--1); margin-top: 0.75rem; }
.search__actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 1.25rem; }

.table--offers td:first-child, .table--offers th:first-child { width: 1%; padding-right: 1.25rem; white-space: nowrap; text-align: left; }
.table--offers td:nth-child(2), .table--offers th:nth-child(2) { width: 1%; padding-right: 1.25rem; white-space: nowrap; color: var(--muted); }
.offer-price { font-weight: 800; font-stretch: 75%; font-size: var(--step-1); }
/* Mesma etiqueta amarela das ofertas: preço dentro do alvo */
.offer-price--hit { background: var(--offer); padding: 0.0625rem 0.375rem; border-radius: 2px; }

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.field-row input { width: 100%; }
.field-note { color: var(--muted); font-size: var(--step--1); margin-top: -0.5rem; }

@media (max-width: 40rem) {
  .search__summary { grid-template-columns: 1fr auto; }
  .search__status { grid-column: 1 / -1; grid-row: 2; }
  .table--offers thead { display: none; }
  .table--offers tr { display: grid; grid-template-columns: auto 1fr; gap: 0 0.75rem; padding: 0.5rem 0; border-bottom: 1px solid var(--line); }
  .table--offers td { border: 0; padding: 0; width: auto !important; }
  .table--offers td:nth-child(3) { grid-column: 1 / -1; }
}

/* ----------------------------------------------------------------- Gráfico */

.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart__grid { stroke: var(--line); stroke-width: 1; }
.chart__axis { fill: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.chart__line { fill: none; stroke: var(--ink); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart__dot { fill: var(--ink); stroke: var(--paper); stroke-width: 2; }
.chart__target { stroke: var(--alarm); stroke-width: 1.5; stroke-dasharray: 6 4; }
.chart__target-label { fill: var(--ink); font-size: 12px; font-weight: 700; }
.chart__cursor { stroke: var(--muted); stroke-width: 1; }
.chart__tooltip {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  padding: 0.375rem 0.625rem;
  border-radius: 2px;
  background: #000000;
  color: #ffffff;
  font-size: var(--step--1);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.chart__tooltip strong { display: block; font-size: var(--step-0); font-stretch: 75%; }

/* ---------------------------------------------------------------- Diálogos */

.dialog {
  width: min(28rem, calc(100vw - 2rem));
  padding: 1.75rem;
  border: 0;
  border-radius: 2px;
}
.dialog::backdrop { background: rgb(8 11 14 / 0.65); }
.dialog__title { font-size: var(--step-2); font-weight: 900; font-stretch: 87%; line-height: 1.15; }
.dialog__lead { color: var(--muted); }
.dialog__section { display: grid; gap: 0.75rem; justify-items: start; padding-top: 1.125rem; border-top: 1px solid var(--line); }
.dialog__subtitle { font-size: var(--step-0); font-weight: 800; }
.dialog__actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 0.5rem; }
.dialog__actions #logout { margin-right: auto; }

@media (max-width: 34rem) {
  .topbar, .page { padding-inline: 1rem; }
  .topbar__actions { margin-left: 0; width: 100%; }
  .topbar__actions .button { flex: 1; }
  .sheet { padding: 1.25rem; }
}

@media (prefers-reduced-motion: reduce) {
  .tag { transition: none; }
}
