/* feira — estilo. Mobile-first; tokens claro/escuro via prefers-color-scheme
   (os mesmos do datahidro/levabici). Tipografia: IBM Plex Mono vendorada
   (lib/fonts/) pra marca, rótulos e números; texto corrido em fonte do sistema.

   Cor de marca = cmocean.phase, a paleta cíclica do Câmera Topográfica (a
   faixa sob o topo é o ciclo inteiro). Os dois lados da feira têm cada um a
   sua matiz — oferta (verde-água, f12) e procura (magenta, f4) — mas a cor
   NUNCA vai sozinha: o selo sempre diz "oferta"/"procura" por extenso.

   A CSP do backend proíbe style="" inline: tudo aqui é classe. */

@font-face {
  font-family: 'IBM Plex Mono';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('/lib/fonts/ibm-plex-mono-400.woff2') format('woff2');
}
@font-face {
  font-family: 'IBM Plex Mono';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('/lib/fonts/ibm-plex-mono-600.woff2') format('woff2');
}
@font-face {
  font-family: 'IBM Plex Mono';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('/lib/fonts/ibm-plex-mono-700.woff2') format('woff2');
}

:root {
  color-scheme: light;
  --page: #f7f5ef;
  --surface: #ffffff;
  --surface-2: #ebe8df;
  --ink: #121210;
  --ink-2: #4d4b45;
  --muted: #6f6d66;
  --hairline: #e2dfd5;
  --border: #cfcbbf;
  --danger: #b3261e;
  --danger-bg: #fbe9e7;
  --warn-bg: #fdf3dc;
  --warn-border: #e8c26a;
  --focus: #2c6fd6;

  /* texto/selo de cada lado: escuros o bastante pra 4,5:1 sobre --page e com branco em cima */
  --offer: #0a7a64;
  --offer-bg: #e0f1ec;
  --demand: #b3206f;
  --demand-bg: #f8e3ee;

  /* cmocean.phase — cíclica: f15 emenda de volta em f0 */
  --cycle: #a8780d, #be6828, #cf5643, #db4066, #df2a93, #d529c4, #c041e5, #a25cf3,
    #7d73f0, #5285dc, #2c90bc, #19959c, #0c987c, #249a52, #5e9420, #8b860d, #a8780d;

  --font: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, 'SFMono-Regular', Menlo, monospace;
  --width: 1080px;
  --narrow: 680px;
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #11110f;
    --surface: #1b1b18;
    --surface-2: #262521;
    --ink: #f4f2ea;
    --ink-2: #c4c1b6;
    --muted: #9a978d;
    --hairline: #2c2b27;
    --border: #3d3b36;
    --danger: #ff8a80;
    --danger-bg: #3a1a17;
    --warn-bg: #3a2f12;
    --warn-border: #8a6d1f;
    --focus: #6ea8ff;
    --offer: #4fd1b3;
    --offer-bg: #12332c;
    --demand: #ff7cc0;
    --demand-bg: #3a1529;
  }
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--page);
  color: var(--ink);
  font: 16px/1.5 var(--font);
  -webkit-tap-highlight-color: transparent;
}

a { color: inherit; text-underline-offset: 0.18em; }
img { max-width: 100%; display: block; }
[hidden] { display: none !important; }
h1, h2, h3 { line-height: 1.2; margin: 0; }
p { margin: 0; }
code { font-family: var(--mono); font-size: 0.92em; background: var(--surface-2); padding: 0.1em 0.35em; border-radius: 5px; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
h1[tabindex="-1"]:focus { outline: none; } /* foco programático ao trocar de tela */

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

.icon { width: 1.15em; height: 1.15em; fill: currentColor; flex: none; }

/* ------------------------------------------------------------ topo */

.topbar {
  width: 100%;
  max-width: var(--width);
  margin: 0 auto;
  padding: 14px 16px 12px;
  padding-top: max(14px, env(safe-area-inset-top));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  font: 700 1.12rem/1 var(--mono);
  letter-spacing: -0.01em;
  text-decoration: none;
  color: var(--muted);
  white-space: nowrap;
}
.brand-dot { margin: 0 0.05em; }
.brand-hidro { color: var(--ink); }

.topnav { display: flex; align-items: center; gap: 14px; }
.topnav-link { font: 400 0.85rem/1 var(--mono); color: var(--ink-2); }

.stripe { height: 5px; background: linear-gradient(90deg, var(--cycle)); }

.banner, .noscript {
  margin: 0;
  padding: 8px 16px;
  text-align: center;
  font: 600 0.78rem/1.35 var(--mono);
  background: var(--warn-bg);
  border-bottom: 1px solid var(--warn-border);
}
.noscript { text-align: left; font: 1rem/1.5 var(--font); padding: 16px; }

/* ------------------------------------------------------------ botões */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  padding: 10px 18px;
  border: 1.5px solid transparent;
  border-radius: 999px;
  font: 600 0.92rem/1.1 var(--mono);
  text-decoration: none;
  cursor: pointer;
  transition: transform 0.06s ease, background-color 0.15s ease;
}
.btn:active { transform: scale(0.98); }
.btn[disabled] { opacity: 0.55; cursor: progress; }
.btn-primary { background: var(--ink); color: var(--page); }
.btn-ghost { background: transparent; color: var(--ink); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: var(--danger); color: #fff; }
@media (prefers-color-scheme: dark) { .btn-danger { color: #1b0503; } }
.btn-whatsapp { background: var(--offer); color: var(--page); }
.btn-small { min-height: 38px; padding: 6px 14px; font-size: 0.85rem; }
.btn-wide { width: 100%; }

/* ------------------------------------------------------------ telas */

#main { flex: 1; width: 100%; }

.view {
  max-width: var(--width);
  margin: 0 auto;
  padding: 20px 16px 40px;
}
#view-ad, #view-form, #view-about, #view-missing { max-width: var(--narrow); }

.lead { color: var(--ink-2); font-size: 1.04rem; max-width: 62ch; }

.back {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin: 0 0 18px -4px;
  font: 400 0.85rem/1 var(--mono);
  color: var(--ink-2);
  text-decoration: none;
}
.back:hover { text-decoration: underline; }

/* ------------------------------------------------------------ filtros */

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 20px 0 6px;
}

.segmented {
  display: inline-flex;
  padding: 3px;
  border-radius: 999px;
  background: var(--surface-2);
}
.segmented button {
  min-height: 40px;
  padding: 0 16px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--ink-2);
  font: 600 0.85rem/1 var(--mono);
  cursor: pointer;
}
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgb(0 0 0 / 0.12); }
.segmented .count { color: var(--muted); font-weight: 400; margin-left: 5px; }

.search {
  flex: 1 1 200px;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 46px;
  padding: 0 14px;
  border: 1.5px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
}
.search:focus-within { border-color: var(--focus); }
.search input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font: 1rem var(--font);
}

.list-status { min-height: 1.4em; margin: 8px 2px 10px; font: 400 0.8rem/1.4 var(--mono); color: var(--muted); }

/* ------------------------------------------------------------ vitrine */

.cards {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr));
  gap: 14px;
}

.card {
  position: relative;
  height: 100%;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
  transition: border-color 0.15s ease, transform 0.15s ease;
}
.card:hover { border-color: var(--border); transform: translateY(-1px); }
.card:focus-within { border-color: var(--focus); }
.card.is-inactive { opacity: 0.62; }

.card-photo { aspect-ratio: 4 / 3; width: 100%; object-fit: cover; background: var(--surface-2); }

.card-body { display: flex; flex-direction: column; gap: 8px; padding: 14px 16px 16px; flex: 1; }
.card-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }

.card-title { font: 700 1.06rem/1.25 var(--mono); letter-spacing: -0.01em; overflow-wrap: anywhere; }
.card-title a { text-decoration: none; }
/* o card inteiro é clicável, mas o link de verdade (e o nome acessível) é o título */
.card-title a::after { content: ''; position: absolute; inset: 0; }

.card-terms { font: 600 0.98rem/1.3 var(--mono); overflow-wrap: anywhere; }
.card-desc {
  color: var(--ink-2);
  font-size: 0.93rem;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
}
.card-foot { margin-top: auto; padding-top: 6px; font: 400 0.76rem/1.3 var(--mono); color: var(--muted); }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  font: 700 0.7rem/1.2 var(--mono);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
}
.kind-oferta .badge-kind { background: var(--offer-bg); color: var(--offer); }
.kind-procura .badge-kind { background: var(--demand-bg); color: var(--demand); }
.kind-oferta .card-terms, .kind-oferta .ad-terms { color: var(--offer); }
.kind-procura .card-terms, .kind-procura .ad-terms { color: var(--demand); }
.badge-state { background: var(--surface-2); color: var(--ink-2); }

.empty { margin: 36px 0; display: grid; justify-items: center; gap: 16px; text-align: center; color: var(--ink-2); }

.toggle { display: flex; align-items: center; gap: 10px; margin-top: 22px; font-size: 0.9rem; color: var(--ink-2); cursor: pointer; }
.toggle input { width: 20px; height: 20px; accent-color: var(--ink); flex: none; }

/* ------------------------------------------------------------ um anúncio */

.ad-head { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.ad-title { font: 700 clamp(1.5rem, 5vw, 2.1rem)/1.15 var(--mono); letter-spacing: -0.02em; overflow-wrap: anywhere; }
.ad-terms { margin-top: 10px; font: 600 1.25rem/1.3 var(--mono); overflow-wrap: anywhere; }

.chip-row { list-style: none; display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0 0; padding: 0; }
.chip-row li { padding: 4px 11px; border: 1px solid var(--border); border-radius: 999px; font: 400 0.8rem/1.3 var(--mono); color: var(--ink-2); }

.gallery { margin: 0 0 20px; }
.gallery-main { width: 100%; max-height: 70vh; object-fit: contain; border-radius: var(--radius); background: var(--surface-2); }
.gallery-thumbs { list-style: none; display: flex; gap: 8px; margin: 8px 0 0; padding: 0; }
.gallery-thumbs button { padding: 0; border: 2px solid transparent; border-radius: 10px; background: none; cursor: pointer; overflow: hidden; }
.gallery-thumbs button[aria-current="true"] { border-color: var(--ink); }
.gallery-thumbs img { width: 64px; height: 64px; object-fit: cover; }

.ad-desc { margin-top: 20px; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 1.04rem; }

.panel { margin-top: 24px; padding: 18px; border: 1px solid var(--hairline); border-radius: var(--radius); background: var(--surface); }
.panel h2 { font: 700 0.78rem/1.2 var(--mono); letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); margin-bottom: 10px; }
.contact-name { font: 700 1.1rem/1.3 var(--mono); overflow-wrap: anywhere; }
.contact-note { margin-top: 6px; color: var(--ink-2); overflow-wrap: anywhere; }
.contact-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }

.ad-meta { margin-top: 18px; font: 400 0.8rem/1.6 var(--mono); color: var(--muted); }

.ad-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--hairline); }

/* ------------------------------------------------------------ formulário */

#view-form h1, #view-about h1, #view-missing h1 { font: 700 1.7rem/1.15 var(--mono); letter-spacing: -0.02em; margin-bottom: 18px; }

.field { margin: 0 0 22px; padding: 0; border: 0; min-width: 0; }
/* :not(.btn) — o "adicionar foto" é um <label class="btn">: sem isto o
   display:block daqui ganharia do inline-flex do botão e desalinharia tudo. */
.field label:not(.btn), .field legend { display: block; margin: 0 0 6px; padding: 0; font: 600 0.9rem/1.3 var(--mono); }
fieldset.field label:not(.btn) { margin-top: 16px; }
fieldset.field .chips label, fieldset.field .kind-choice label { margin-top: 0; }
.optional { font-weight: 400; color: var(--muted); font-size: 0.8rem; margin-left: 4px; }
.hint { font-size: 0.86rem; color: var(--muted); margin: 0 0 10px; }
.center { text-align: center; }

input[type="text"], input[type="tel"], input[type="password"], textarea, select {
  width: 100%;
  min-height: 48px;
  padding: 11px 14px;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
  font: 1rem/1.4 var(--font);  /* ≥16px: o iOS não dá zoom ao focar */
}
textarea { resize: vertical; min-height: 120px; }
input:focus, textarea:focus, select:focus { outline: 0; border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 25%, transparent); }
[aria-invalid="true"] { border-color: var(--danger) !important; }

.field-meta { display: flex; justify-content: space-between; gap: 10px; min-height: 1.3em; margin-top: 4px; }
.counter { margin-left: auto; font: 400 0.75rem/1.3 var(--mono); color: var(--muted); }
.counter.is-over { color: var(--danger); font-weight: 700; }
.field-error { margin-top: 4px; font-size: 0.86rem; color: var(--danger); }

.kind-choice { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.kind-option { position: relative; display: block; cursor: pointer; }
.kind-option input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.kind-option span {
  display: block;
  height: 100%;
  padding: 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.kind-option strong { display: block; font: 700 1rem/1.2 var(--mono); }
.kind-option small { display: block; margin-top: 4px; font: 400 0.8rem/1.35 var(--font); color: var(--muted); }
.kind-option input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }
.kind-option.kind-oferta input:checked + span { border-color: var(--offer); background: var(--offer-bg); }
.kind-option.kind-oferta input:checked + span strong { color: var(--offer); }
.kind-option.kind-procura input:checked + span { border-color: var(--demand); background: var(--demand-bg); }
.kind-option.kind-procura input:checked + span strong { color: var(--demand); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { position: relative; cursor: pointer; }
.chip input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.chip span {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 0 15px;
  border: 1.5px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  font: 400 0.86rem/1 var(--mono);
}
.chip input:checked + span { background: var(--ink); border-color: var(--ink); color: var(--page); font-weight: 600; }
.chip input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }

.photos { list-style: none; display: flex; flex-wrap: wrap; gap: 10px; margin: 0 0 12px; padding: 0; }
.photos:empty { display: none; }
.photo { position: relative; width: 104px; }
.photo img { width: 104px; height: 104px; object-fit: cover; border-radius: 12px; background: var(--surface-2); }
.photo.is-cover img { outline: 3px solid var(--ink); outline-offset: -3px; }
.photo-tag { position: absolute; left: 6px; top: 6px; padding: 2px 7px; border-radius: 999px; background: var(--ink); color: var(--page); font: 700 0.62rem/1.4 var(--mono); letter-spacing: 0.05em; text-transform: uppercase; }
.photo-tools { display: flex; gap: 4px; margin-top: 4px; }
.photo-tools button { flex: 1; min-height: 32px; padding: 0 4px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--ink-2); font: 400 0.7rem/1 var(--mono); cursor: pointer; }
.photo.is-busy img { opacity: 0.4; }

.form-error { margin: 0 0 16px; padding: 12px 14px; border-radius: 12px; background: var(--danger-bg); color: var(--danger); font-size: 0.93rem; }
.form-error ul { margin: 6px 0 0; padding-left: 1.2em; }
.form-actions { margin-top: 8px; }
#form-footnote { margin-top: 12px; }

/* ------------------------------------------------------------ como funciona */

.prose h2 { font: 700 1.15rem/1.25 var(--mono); margin: 32px 0 10px; }
.prose h3 { font: 700 1rem/1.25 var(--mono); margin: 0 0 6px; }
.prose p + p, .prose ul, .prose pre { margin-top: 12px; }
.prose ul { padding-left: 1.2em; }
.prose li + li { margin-top: 6px; }
.doors { list-style: none; counter-reset: door; margin: 0; padding: 0; display: grid; gap: 12px; }
.doors > li { counter-increment: door; padding: 16px 18px; border: 1px solid var(--hairline); border-radius: var(--radius); background: var(--surface); }
.doors h3::before { content: counter(door) '. '; color: var(--muted); }
.example { margin: 12px 0 0; padding: 12px 14px; border-radius: 12px; background: var(--surface-2); font: 400 0.84rem/1.5 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere; }
.changelog { margin-top: 32px; font-size: 0.9rem; color: var(--ink-2); }
.changelog summary { cursor: pointer; font: 600 0.85rem/1.4 var(--mono); }
.changelog dt { margin-top: 12px; font: 700 0.82rem/1.4 var(--mono); }
.changelog dd { margin: 2px 0 0; }

/* ------------------------------------------------------------ rodapé, diálogos, toast */

.footer {
  padding: 22px 16px;
  padding-bottom: max(22px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--hairline);
  text-align: center;
  font: 400 0.78rem/1.8 var(--mono);
  color: var(--muted);
}

.dialog {
  width: min(92vw, 420px);
  padding: 22px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
  color: var(--ink);
}
.dialog::backdrop { background: rgb(0 0 0 / 0.5); }
.dialog h2 { font: 700 1.15rem/1.25 var(--mono); margin-bottom: 8px; }
.dialog p { color: var(--ink-2); font-size: 0.95rem; }
.dialog input[type="password"] { margin-top: 14px; }
.dialog .toggle { margin-top: 12px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: max(20px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 10;
  width: max-content;
  max-width: min(92vw, 520px);
  padding: 12px 18px;
  border-radius: 14px;
  background: var(--ink);
  color: var(--page);
  font-size: 0.92rem;
  box-shadow: 0 6px 24px rgb(0 0 0 / 0.25);
}

@media (max-width: 420px) {
  .topnav-link { display: none; }  /* "como funciona" também está no rodapé */
  .segmented { width: 100%; }
  .segmented button { flex: 1; padding: 0 8px; }
}

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