/* levabici — estilo. Mobile-first; tokens claro/escuro trocam via
   prefers-color-scheme. A escala de nota (1–5) é vermelho→verde em
   OKLCH com luminosidade monotônica; a cor NUNCA aparece sem o
   número junto. Tipografia: IBM Plex Mono vendorada (lib/fonts/). */

@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: 500;
  font-display: swap;
  src: url('lib/fonts/ibm-plex-mono-500.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:        #f9f9f7;
  --surface:     #fcfcfb;
  --ink:         #0b0b0b;
  --ink-2:       #52514e;
  --muted:       #898781;
  --hairline:    #e1e0d9;
  --border:      rgba(11, 11, 11, 0.10);
  --accent:      #2a78d6;
  --accent-ink:  #ffffff;
  --danger:      #d03b3b;
  --warn-bg:     #fdf3dc;
  --warn-border: #e8c26a;
  --rec-ink:     #8a5d00;
  --danger-bg:   #fbe9e9;
  /* escala de nota 1→5: vermelho (pior) → verde (melhor), OKLCH com
     luminosidade monotônica (ordem legível mesmo pra daltonismo);
     mesma paleta nos dois temas */
  --score-1: #90272d;
  --score-2: #a35303;
  --score-3: #a37d1e;
  --score-4: #9fa531;
  --score-5: #6bc87b;
  /* atrito 0/1/2 nas barrinhas de estatística (0 = nada = neutro;
     azuis pra não disputar com a rampa da nota) */
  --friction-0: #e1e0d9;
  --friction-1: #6da7ec;
  --friction-2: #1c5cab;
  --tabbar-h: 58px;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page:        #0d0d0d;
    --surface:     #1a1a19;
    --ink:         #ffffff;
    --ink-2:       #c3c2b7;
    --muted:       #898781;
    --hairline:    #2c2c2a;
    --border:      rgba(255, 255, 255, 0.10);
    --accent:      #3987e5;
    --warn-bg:     #33290f;
    --warn-border: #7a6120;
    --rec-ink:     #e0a624;
    --danger-bg:   #351515;
    --friction-0:  #383835;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--page);
  color: var(--ink);
  font-family: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 15px;
  line-height: 1.45;
}

a { color: var(--accent); }

/* ícones-silhueta inline (fill: currentColor) — sem emojis coloridos */
.icon {
  width: 1.1em;
  height: 1.1em;
  vertical-align: -0.18em;
  display: inline-block;
}

.tab-icon svg { width: 1.25rem; height: 1.25rem; display: block; margin: 0 auto; }
.tab-plus { font-size: 1.15rem; line-height: 1.25rem; }
.rank-mode .icon { width: 1.25em; height: 1.25em; }

/* ---------- cabeçalho ---------- */

.app-header {
  padding: calc(10px + env(safe-area-inset-top)) 16px 8px;
  background: var(--surface);
  border-bottom: 1px solid var(--hairline);
}

.app-header h1 { margin: 0; font-size: 1.5rem; letter-spacing: -0.02em; }
.app-header h1 a { color: var(--ink); text-decoration: none; }
.app-header .accent { color: var(--accent); }
.tagline { margin: 2px 0 0; font-size: 0.8rem; color: var(--ink-2); }

/* ---------- estrutura ---------- */

#main { max-width: 720px; margin: 0 auto; }

.view { padding: 16px 16px calc(var(--tabbar-h) + 24px + env(safe-area-inset-bottom)); }

.view-full { padding: 0; max-width: none; }

h2 { font-size: 1.1rem; margin: 20px 0 4px; }
.hint { margin: 0 0 12px; font-size: 0.85rem; color: var(--ink-2); }
.empty { color: var(--ink-2); padding: 24px 0; text-align: center; }

.note {
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.85rem;
  margin: 12px 0 0;
}

.backlink { display: inline-block; margin-bottom: 8px; text-decoration: none; font-size: 0.9rem; }

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

.btn {
  display: inline-block;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 0.95rem;
  font-family: inherit;
  background: var(--surface);
  color: var(--ink);
  text-decoration: none;
  text-align: center;
  cursor: pointer;
}

.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn-big { display: block; width: 100%; padding: 14px; font-size: 1.05rem; }
.btn-ghost { background: none; border: none; color: var(--accent); padding: 8px 4px; font-size: 0.85rem; }
.btn-danger { color: var(--danger); }
.page-actions { margin-top: 28px; display: flex; flex-wrap: wrap; gap: 4px 16px; }

/* ---------- selo de nota ----------
   Ponto colorido + número em tinta normal: a cor nunca carrega o
   valor sozinha (regra de socorro da paleta). */

.score-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.score-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1px solid var(--border);
  flex: none;
}

.score-max { font-weight: 400; color: var(--muted); font-size: 0.8em; }

/* ---------- filtro de modal ---------- */

.mode-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 4px 0 10px;
}

.mode-filter button {
  font-family: inherit;
  font-size: 0.85rem;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 99px;
  background: var(--surface);
  color: var(--ink-2);
  cursor: pointer;
}

.mode-filter button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
}

/* ---------- novidades ---------- */

.news-list { list-style: none; margin: 0; padding: 0; }

.news-row {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  margin: 0 0 8px;
  color: var(--ink);
  text-decoration: none;
}

.news-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.news-company { font-weight: 600; overflow-wrap: anywhere; }
.news-date { margin-left: auto; color: var(--muted); font-size: 0.78rem; font-variant-numeric: tabular-nums; }
.news-route { color: var(--ink-2); font-size: 0.85rem; margin-top: 2px; }
.news-excerpt { color: var(--ink-2); font-size: 0.85rem; margin-top: 4px; }
.news-row .answer-badges { margin-top: 6px; }
.news-photos { display: flex; gap: 6px; margin-top: 8px; }
.news-photos img {
  width: 56px; height: 56px; object-fit: cover;
  border-radius: 8px; border: 1px solid var(--border);
}

/* ---------- ranking ---------- */

.ranking { list-style: none; margin: 0; padding: 0; }

.ranking li { margin: 0 0 8px; }

.ranking a {
  display: grid;
  grid-template-columns: auto auto 1fr auto;
  gap: 10px;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  color: var(--ink);
  text-decoration: none;
}

.rank-pos { color: var(--muted); font-variant-numeric: tabular-nums; min-width: 1.6em; text-align: right; }
.rank-mode { font-size: 1.2rem; }
.rank-name { font-weight: 600; overflow-wrap: anywhere; }
.rank-count { display: block; font-size: 0.78rem; color: var(--ink-2); font-weight: 400; }

/* ---------- cartão da empresa ---------- */

.company-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
}

.company-card .company-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.company-card h2 { margin: 0; font-size: 1.25rem; }
.company-card .mode-tag { color: var(--ink-2); font-size: 0.9rem; }

.company-hero {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 12px 0 4px;
}

.company-hero .hero-score { font-size: 2.4rem; font-weight: 700; line-height: 1; }
.company-hero .score-dot { width: 20px; height: 20px; }
.company-hero .hero-sub { font-size: 0.85rem; color: var(--ink-2); }

.stat-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 10px;
  align-items: center;
  padding: 7px 0;
  border-top: 1px solid var(--hairline);
  font-size: 0.85rem;
}

.stat-row .stat-label { color: var(--ink-2); }
.stat-row .stat-text { color: var(--ink); text-align: right; }

.stat-bar {
  grid-column: 1 / -1;
  display: flex;
  gap: 2px; /* espaçador de 2px entre segmentos, do método de dataviz */
  height: 6px;
  border-radius: 3px;
  overflow: hidden;
}

.stat-bar span { display: block; height: 100%; }

/* ---------- lista de avaliações ---------- */

.review-list { list-style: none; margin: 0; padding: 0; }

.review-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  margin: 0 0 10px;
}

.review-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.review-route { font-weight: 600; overflow-wrap: anywhere; }
.review-date { color: var(--muted); font-size: 0.82rem; }

.badge {
  font-size: 0.72rem;
  padding: 1px 8px;
  border-radius: 99px;
  border: 1px solid var(--border);
  color: var(--ink-2);
  white-space: nowrap;
}

.badge-example { background: var(--warn-bg); border-color: var(--warn-border); }
.badge-local { background: var(--warn-bg); border-color: var(--warn-border); }
a.badge-source { text-decoration: none; color: var(--accent); }

.review-actions { display: flex; gap: 8px; margin-top: 10px; }

.btn-mini {
  font-size: 0.78rem;
  font-family: inherit;
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--page);
  color: var(--ink-2);
  cursor: pointer;
}

.btn-mini-danger { color: var(--danger); }

.answer-badges { margin: 8px 0 0; display: flex; flex-wrap: wrap; gap: 4px; }

.review-body { margin: 8px 0 0; font-size: 0.92rem; }
.review-by { margin: 6px 0 0; font-size: 0.82rem; color: var(--muted); }
.company-alt { margin: 2px 0 0; }
.map-link { margin: 10px 0 0; font-size: 0.85rem; }

.review-photos { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.review-photos img {
  width: 72px; height: 72px; object-fit: cover;
  border-radius: 8px; border: 1px solid var(--border); cursor: zoom-in;
}
/* ---------- lightbox ---------- */

#lightbox {
  position: fixed;
  inset: 0;
  z-index: 2000; /* acima da tabbar e dos panes do Leaflet */
  background: rgba(0, 0, 0, 0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
  padding: 16px;
}

/* o display:flex acima venceria o [hidden] do user-agent e deixaria o
   overlay invisível cobrindo o app inteiro — reafirma o escondido */
#lightbox[hidden] { display: none; }

#lightbox img {
  max-width: 94vw;
  max-height: 88vh;
  object-fit: contain;
  border-radius: 8px;
}

/* ---------- mapa ---------- */

#view-map { position: relative; }

/* pílulas sobre o mapa; left livra o controle de zoom do Leaflet */
.map-mode-filter {
  position: absolute;
  top: 10px;
  left: 54px;
  right: 10px;
  z-index: 500;
  margin: 0;
  justify-content: flex-end;
}

#map {
  height: calc(100dvh - 92px - var(--tabbar-h) - env(safe-area-inset-bottom));
  min-height: 320px;
}

.map-legend {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  font: 0.78rem/1.5 'IBM Plex Mono', monospace;
  color: var(--ink);
}

.map-legend .legend-title { font-weight: 700; margin-bottom: 2px; }
.map-legend .legend-note { color: var(--ink-2); max-width: 180px; }
.legend-swatch {
  display: inline-block; width: 18px; height: 5px;
  border-radius: 2px; vertical-align: middle; margin-right: 6px;
}

.map-popup { font-size: 0.9rem; }
.map-popup .popup-company { font-weight: 700; }
.map-popup .popup-route { color: var(--ink-2); }

/* Leaflet herda o tema escuro só nos controles próprios do app;
   os tiles OSM ficam claros (a escala de nota foi validada contra
   fundo claro). */
@media (prefers-color-scheme: dark) {
  .leaflet-container { background: #262626; }
}

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

fieldset {
  border: 1px solid var(--hairline);
  border-radius: 12px;
  background: var(--surface);
  margin: 0 0 16px;
  padding: 12px 14px 16px;
}

legend { font-weight: 700; font-size: 0.95rem; padding: 0 6px; }

form label { display: block; margin: 14px 0 4px; font-size: 0.9rem; font-weight: 600; }

.req { color: var(--danger); }

/* “!” = recomendado (Warning nas shapes); “*” = obrigatório (Violation) */
.rec { color: var(--rec-ink); font-weight: 700; }

#ranking-search {
  width: 100%;
  padding: 10px;
  font-size: 1rem;
  font-family: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin: 0 0 10px;
}

input[type="text"], input[type="date"], select, textarea {
  width: 100%;
  padding: 10px;
  font-size: 1rem;
  font-family: inherit;
  color: var(--ink);
  background: var(--page);
  border: 1px solid var(--border);
  border-radius: 8px;
}

input[type="file"] { font-size: 0.9rem; }

/* Tom Select no tema da casa (claro/escuro via tokens) */
.ts-wrapper.single .ts-control,
.ts-wrapper.focus .ts-control {
  background: var(--page);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  font-size: 1rem;
  box-shadow: none;
}

.ts-control input { color: var(--ink); font-size: 1rem; }

.ts-dropdown {
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-top: 4px;
}

.ts-dropdown .option, .ts-dropdown .create, .ts-dropdown .no-results { padding: 9px 10px; }
.ts-dropdown .active { background: var(--accent); color: var(--accent-ink); }
.ts-dropdown .active .ts-count, .ts-dropdown .active .score-max { color: inherit; }

.ts-company { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.ts-chip { display: inline-flex; align-items: center; flex: none; }
.ts-count { color: var(--muted); font-size: 0.78rem; margin-left: 8px; }

/* nota 1–5: segmentos grandes de tocar */
.score-picker { display: flex; gap: 6px; }

.score-picker label {
  flex: 1;
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 0 8px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--page);
  cursor: pointer;
  font-variant-numeric: tabular-nums;
}

.score-picker input { position: absolute; opacity: 0; pointer-events: none; }
.score-picker .score-dot { width: 16px; height: 16px; }
.score-picker label.checked { outline: 2px solid var(--accent); outline-offset: -1px; font-weight: 700; }
.score-picker label:focus-within { outline: 2px solid var(--accent); outline-offset: -1px; }

.radio-group { display: flex; flex-wrap: wrap; gap: 6px; }

.radio-group label {
  margin: 0;
  font-weight: 400;
  font-size: 0.88rem;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 99px;
  background: var(--page);
  cursor: pointer;
}

.radio-group input { position: absolute; opacity: 0; pointer-events: none; }
.radio-group label.checked { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.radio-group label:focus-within { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Quando: texto ISO + calendário próprio (popover) */
.date-row { position: relative; display: flex; gap: 6px; }
.date-row input[type="text"] { flex: 1; }
#btn-date-picker {
  flex: none;
  width: 44px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--page);
  font-size: 1.1rem;
  cursor: pointer;
}

.cal-pop {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  width: min(310px, 86vw);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  padding: 10px;
  z-index: 500;
}

.cal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 6px;
}

.cal-head button, .cal-months button, .cal-grid button {
  border: none;
  background: none;
  font-family: inherit;
  font-size: 0.92rem;
  color: var(--ink);
  border-radius: 8px;
  cursor: pointer;
  padding: 6px;
}

.cal-head button:hover, .cal-months button:hover, .cal-grid button:hover {
  background: var(--page);
}

.cal-title { font-weight: 700; }

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
  text-align: center;
}

.cal-grid button { min-height: 36px; font-variant-numeric: tabular-nums; }
.cal-week span { color: var(--muted); font-size: 0.72rem; padding: 2px 0; }

.cal-months {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  text-align: center;
}

.cal-months button { min-height: 40px; }

.cal-now { outline: 1px solid var(--accent); outline-offset: -1px; }
.cal-selected { background: var(--accent) !important; color: var(--accent-ink); font-weight: 700; }
.cal-hint { margin-top: 8px; font-size: 0.72rem; color: var(--muted); text-align: center; }

.photo-previews { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.photo-previews .thumb { position: relative; }
.photo-previews img { width: 72px; height: 72px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); }
.photo-previews button {
  position: absolute; top: -6px; right: -6px;
  width: 22px; height: 22px; border-radius: 50%;
  border: none; background: var(--danger); color: #fff;
  font-size: 0.8rem; line-height: 1; cursor: pointer;
}

/* validação SHACL-espelhada */
.form-validation { border-radius: 10px; padding: 10px 12px; margin: 0 0 12px; font-size: 0.88rem; }
.form-validation.has-violations { background: var(--danger-bg); border: 1px solid var(--danger); }
.form-validation.warnings-only { background: var(--warn-bg); border: 1px solid var(--warn-border); }
.form-validation ul { margin: 4px 0 0; padding-left: 18px; }
.form-validation .v-violation::marker { color: var(--danger); }

/* ---------- barra de navegação ---------- */

.tabbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--hairline);
  z-index: 1000; /* acima dos panes do Leaflet */
}

.tabbar a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  font-size: 0.72rem;
  color: var(--ink-2);
  text-decoration: none;
}

.tabbar a.active { color: var(--accent); font-weight: 700; }
.tabbar .tab-icon { font-size: 1.15rem; line-height: 1; }

@media (min-width: 720px) {
  .app-header { text-align: center; }
  #map { border-radius: 0; }
}
