/* =========================================================================
   style.css — Megavale Card · Rede de Estabelecimentos
   ========================================================================= */

/* -------------------------------------------------------------------------
   0. Tokens de design
   ------------------------------------------------------------------------- */
:root {
  --color-brand-green:   #00B388;
  --color-brand-orange:  #F7941D;
  --color-brand-red:     #D01550;   /* #E8175D escurecido ~15% → passa WCAG AA sobre branco */
  --color-brand-red-raw: #E8175D;   /* uso decorativo / gradiente */
  --color-bg:            #F5F5F5;
  --color-surface:       #FFFFFF;
  --color-text:          #1A1A1A;
  --color-text-muted:    #666666;
  --color-border:        #E0E0E0;
  --color-focus:         #005FCC;

  --header-height: 64px;
  --sidebar-width: 380px;

  --radius-sm:  6px;
  --radius-md:  10px;
  --radius-lg:  16px;

  --shadow-sm:  0 1px 3px rgba(0,0,0,.10), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md:  0 4px 12px rgba(0,0,0,.10);
  --shadow-lg:  0 8px 24px rgba(0,0,0,.14);

  --font:        'Inter', system-ui, -apple-system, sans-serif;
  --transition:  150ms ease;
}

/* -------------------------------------------------------------------------
   1. Reset e base
   ------------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 16px;
  scroll-behavior: smooth;
  height: 100%;
}

body {
  font-family: var(--font);
  color: var(--color-text);
  background: var(--color-bg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  height: 100%;
  overflow: hidden;
}

img { display: block; max-width: 100%; }
ul  { list-style: none; }
a   { color: inherit; text-decoration: none; }

button {
  cursor: pointer;
  font-family: var(--font);
  border: none;
  background: none;
}

/* Foco visível global (WCAG 2.4.7) */
:focus-visible {
  outline: 3px solid var(--color-focus);
  outline-offset: 2px;
}

.hidden { display: none !important; }

/* -------------------------------------------------------------------------
   2. Header
   ------------------------------------------------------------------------- */
.header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-height);
  background: var(--color-surface);
  box-shadow: var(--shadow-sm);
  z-index: 1000;
}

.header__inner {
  max-width: 100%;
  height: 100%;
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 20px;
}

.header__logo-img {
  height: 38px;
  width: auto;
}

.header__tagline {
  font-size: 0.875rem;
  color: var(--color-text-muted);
  font-weight: 400;
  border-left: 2px solid var(--color-border);
  padding-left: 20px;
}

/* -------------------------------------------------------------------------
   3. Layout principal (sidebar + mapa)
   ------------------------------------------------------------------------- */
.layout {
  display: flex;
  height: calc(100vh - var(--header-height));
  margin-top: var(--header-height);
  overflow: hidden;
  position: relative;
}

/* -------------------------------------------------------------------------
   4. Sidebar
   ------------------------------------------------------------------------- */
.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 10;
  height: 100%;
}

.sidebar__mobile-header,
.map-menu-button,
.sidebar-backdrop { display: none; }

/* -------------------------------------------------------------------------
   5. Filtros
   ------------------------------------------------------------------------- */
.filters {
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}

.filters__row {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.filters__actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.filters__actions .btn--primary {
  flex: 1;
  justify-content: center;
}

/* Campos */
.field {}
.field__label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: 4px;
}

.field__input,
.field__select {
  width: 100%;
  height: 42px;
  padding: 0 12px;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.9375rem;
  color: var(--color-text);
  background: var(--color-surface);
  transition: border-color var(--transition);
  appearance: none;
  -webkit-appearance: none;
}

.field__select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%23666' d='M6 8L0 0h12z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

.field__input:focus,
.field__select:focus {
  outline: none;
  border-color: var(--color-brand-red);
  box-shadow: 0 0 0 3px rgba(208,21,80,.15);
}

.field__input::placeholder { color: var(--color-text-muted); opacity: .7; }

/* -------------------------------------------------------------------------
   6. Autocomplete
   ------------------------------------------------------------------------- */
.autocomplete { position: relative; }

.autocomplete__lista {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  background: var(--color-surface);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  max-height: 220px;
  overflow-y: auto;
  z-index: 200;
  display: none;
}

.autocomplete__lista.aberto { display: block; }

.autocomplete__item {
  padding: 10px 12px;
  font-size: 0.9375rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  transition: background var(--transition);
}

.autocomplete__item:hover,
.autocomplete__item[aria-selected="true"] {
  background: rgba(208,21,80,.07);
}

.autocomplete__item-nome { font-weight: 500; }
.autocomplete__item-qtd {
  font-size: 0.8125rem;
  color: var(--color-text-muted);
  white-space: nowrap;
}

/* -------------------------------------------------------------------------
   7. Botões
   ------------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 38px;
  padding: 0 16px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 600;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
  white-space: nowrap;
}

.btn--primary {
  background: var(--color-brand-red);
  color: #fff;
}
.btn--primary:hover { background: #b5103f; }

.btn--outline {
  border: 1.5px solid var(--color-brand-red);
  color: var(--color-brand-red);
}
.btn--outline:hover { background: rgba(208,21,80,.07); }

.btn--ghost {
  color: var(--color-text-muted);
  border: 1.5px solid var(--color-border);
}
.btn--ghost:hover { background: var(--color-bg); }

.btn__icon {
  width: 18px;
  height: 18px;
  fill: currentColor;
  flex-shrink: 0;
}

/* -------------------------------------------------------------------------
   8. Resultado / contador
   ------------------------------------------------------------------------- */
.resultado-info {
  padding: 10px 20px;
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}

.resultado-info__texto {
  font-size: 0.875rem;
  color: var(--color-text-muted);
}

.resultado-info__texto strong {
  color: var(--color-text);
  font-weight: 700;
}

/* Aviso de truncamento */
.aviso-truncamento {
  margin: 0 20px 0;
  padding: 10px 14px;
  background: #FFF8E7;
  border: 1px solid #F7941D;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 0.8125rem;
  color: #7a4500;
  flex-shrink: 0;
}

.aviso-truncamento__icon {
  width: 18px; height: 18px;
  fill: #F7941D;
  flex-shrink: 0;
  margin-top: 1px;
}

/* -------------------------------------------------------------------------
   9. Lista de estabelecimentos
   ------------------------------------------------------------------------- */
.lista-wrapper {
  flex: 1;
  overflow-y: auto;
  padding: 12px 0;
  overscroll-behavior: contain;
}

/* Estado vazio / loading */
.lista-estado {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 40px 24px;
  text-align: center;
  color: var(--color-text-muted);
  font-size: 0.9375rem;
}

.lista-estado svg {
  width: 40px; height: 40px;
  fill: var(--color-border);
}

/* Spinner */
.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-brand-red);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Cards */
.lista { padding-bottom: 12px; }

.card {
  padding: 14px 20px;
  cursor: pointer;
  border-bottom: 1px solid var(--color-border);
  transition: background var(--transition);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.card:hover  { background: rgba(208,21,80,.04); }
.card:focus  { outline: none; background: rgba(208,21,80,.07); }
.card.card--ativo { background: rgba(208,21,80,.06); border-left: 3px solid var(--color-brand-red); }

.card__nome {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--color-text);
  line-height: 1.3;
}

.card__endereco {
  font-size: 0.8125rem;
  color: var(--color-text-muted);
  line-height: 1.4;
}

.card__sem-coord {
  font-size: 0.75rem;
  color: #999;
  font-style: italic;
}

.card__badges {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 4px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.badge--qrcode    { background: #E3F2FD; color: #1565C0; }

/* -------------------------------------------------------------------------
   10. Área do mapa
   ------------------------------------------------------------------------- */
.map-area {
  flex: 1;
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

#mapa-container {
  flex: 1;
  width: 100%;
  height: 100%;
  min-height: 400px;
  background: #e8e0d8;
}

/* Tabs mobile — ocultas no desktop */
.tabs-mobile { display: none; }

/* -------------------------------------------------------------------------
   11. Popup do Leaflet — customização
   ------------------------------------------------------------------------- */
.leaflet-popup-content-wrapper {
  border-radius: var(--radius-md) !important;
  box-shadow: var(--shadow-lg) !important;
  padding: 0 !important;
  overflow: hidden;
}

.leaflet-popup-content {
  margin: 0 !important;
  width: 260px !important;
}

.popup {
  padding: 16px;
}

.popup__nome {
  font-size: 0.9375rem;
  font-weight: 700;
  color: var(--color-text);
  line-height: 1.3;
  margin-bottom: 6px;
}

.popup__endereco {
  font-size: 0.8125rem;
  color: var(--color-text-muted);
  line-height: 1.5;
  margin-bottom: 10px;
}

.popup__badges {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 12px;
}

.popup__link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  background: var(--color-brand-red);
  color: #fff;
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  font-weight: 600;
  transition: background var(--transition);
  width: 100%;
  justify-content: center;
}

.popup__link:hover { background: #b5103f; }

.popup__link svg {
  width: 15px; height: 15px;
  fill: currentColor;
}

/* -------------------------------------------------------------------------
   12. Bolhas de cluster customizadas (UF / cidade)
   ------------------------------------------------------------------------- */
.bolha-uf,
.bolha-cidade {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  border-radius: 50%;
  color: #fff;
  font-family: var(--font);
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--shadow-md);
  transition: transform var(--transition), opacity var(--transition);
  border: 3px solid rgba(255,255,255,.6);
  line-height: 1.2;
}

.bolha-uf:hover,
.bolha-cidade:hover { transform: scale(1.08); }

.bolha-uf {
  background: var(--color-brand-red);
  width: 64px; height: 64px;
  font-size: 1.25rem;
}

.bolha-uf__qtd {
  font-size: 0.625rem;
  font-weight: 400;
  opacity: .9;
}

.bolha-cidade {
  background: var(--color-brand-green);
  width: 52px; height: 52px;
  font-size: 0.625rem;
  text-align: center;
  padding: 4px;
}

.bolha-cidade__nome { font-size: 0.6875rem; }
.bolha-cidade__qtd  { font-size: 0.5625rem; opacity: .85; }

/* Marcadores individuais */
.marcador {
  width: 14px;
  height: 14px;
  background: var(--color-brand-red);
  border-radius: 50%;
  border: 2.5px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,.3);
}

/* -------------------------------------------------------------------------
   13. Modal
   ------------------------------------------------------------------------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: fadeIn .15s ease;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 420px;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
  box-shadow: var(--shadow-lg);
  animation: slideUp .2s ease;
}

@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.modal__fechar {
  position: absolute;
  top: 12px; right: 12px;
  width: 32px; height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: var(--color-text-muted);
  transition: background var(--transition);
  z-index: 1;
}

.modal__fechar:hover { background: var(--color-bg); }
.modal__fechar svg { width: 20px; height: 20px; fill: currentColor; }

.modal__body {
  padding: 24px;
}

/* -------------------------------------------------------------------------
   14. Scrollbar customizada (webkit)
   ------------------------------------------------------------------------- */
.lista-wrapper::-webkit-scrollbar { width: 6px; }
.lista-wrapper::-webkit-scrollbar-track { background: transparent; }
.lista-wrapper::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: 3px;
}
.lista-wrapper::-webkit-scrollbar-thumb:hover { background: #bbb; }

/* -------------------------------------------------------------------------
   15. Responsividade — Tablet (768–1023px)
   ------------------------------------------------------------------------- */
@media (max-width: 1023px) {
  :root { --sidebar-width: 320px; }
}

/* -------------------------------------------------------------------------
   16. Responsividade — Mobile (< 768px)
   ------------------------------------------------------------------------- */
@media (max-width: 767px) {
  :root {
    --header-height: 0px;
  }

  body { overflow: hidden; }
  .header { display: none; }

  /* Layout empilhado */
  .layout {
    height: 100dvh;
    margin-top: 0;
    overflow: hidden;
  }

  /* Header compacto */
  .header__inner { padding: 0 16px; gap: 12px; }
  .header__logo-img { height: 30px; }
  .header__tagline { display: none; }

  /* Gaveta de filtros sobre o mapa */
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(390px, calc(100vw - 24px));
    height: 100dvh;
    border: 0;
    box-shadow: var(--shadow-lg);
    transform: translateX(-105%);
    transition: transform 220ms ease;
    z-index: 1200;
    visibility: hidden;
  }

  .sidebar.sidebar--visivel { transform: translateX(0); visibility: visible; }
  .sidebar__mobile-header { display: flex; min-height: 64px; padding: 12px 16px; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--color-border); }
  .sidebar__mobile-logo { width: 132px; height: auto; }
  .sidebar__close { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 50%; color: var(--color-text); }
  .sidebar__close:active { background: var(--color-bg); }
  .sidebar__close svg { width: 24px; height: 24px; fill: currentColor; }
  .sidebar-backdrop { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, .32); opacity: 0; visibility: hidden; transition: opacity 220ms ease, visibility 220ms ease; z-index: 1100; }
  .sidebar-backdrop.sidebar-backdrop--visivel { opacity: 1; visibility: visible; }

  /* Mapa ocupa toda a área disponível */
  .map-area {
    height: 100dvh;
    display: flex;
  }

  .map-menu-button { position: absolute; top: max(16px, env(safe-area-inset-top)); left: 16px; z-index: 800; min-height: 48px; display: inline-flex; align-items: center; gap: 8px; padding: 0 16px; border-radius: 24px; background: var(--color-surface); color: var(--color-text); box-shadow: var(--shadow-md); font-size: .9375rem; font-weight: 600; }
  .map-menu-button svg { width: 22px; height: 22px; fill: currentColor; }
  .tabs-mobile { display: none; }

  /* Filtros com padding maior para toque */
  .filters { padding: 14px 16px 12px; }

  .filters__row { gap: 10px; }

  .field__input,
  .field__select {
    height: 48px;
    font-size: 1rem;
    padding: 0 14px;
  }

  .field__select { padding-right: 40px; }

  .field__label {
    font-size: 0.75rem;
    margin-bottom: 5px;
  }

  /* Botões de ação — tamanho de toque mínimo 44px */
  .filters__actions {
    flex-wrap: nowrap;
    gap: 8px;
    margin-top: 14px;
  }

  .btn {
    height: 44px;
    padding: 0 14px;
    font-size: 0.875rem;
  }

  .btn--primary { flex: 1; }
  .btn--outline { flex: 1; }

  /* Contador de resultados */
  .resultado-info { padding: 8px 16px; }
  .resultado-info__texto { font-size: 0.8125rem; }

  /* Cards da lista */
  .card { padding: 14px 16px; }
  .card__nome { font-size: 1rem; }
  .card__endereco { font-size: 0.875rem; }

  /* Tabs mobile */
  .tabs-mobile {
    display: flex;
    background: var(--color-surface);
    border-bottom: 2px solid var(--color-border);
    height: 48px;
    flex-shrink: 0;
    position: sticky;
    top: var(--header-height);
    z-index: 100;
    box-shadow: var(--shadow-sm);
  }

  .tab {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--color-text-muted);
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;
    transition: color var(--transition), border-color var(--transition);
    padding-bottom: 2px;
    /* Área mínima de toque */
    min-height: 44px;
  }

  .tab svg {
    width: 18px; height: 18px;
    fill: currentColor;
  }

  .tab--active {
    color: var(--color-brand-red);
    border-bottom-color: var(--color-brand-red);
  }

  /* Popup do mapa menor em telas pequenas */
  .leaflet-popup-content {
    width: 220px !important;
  }

  .popup { padding: 12px; }
  .popup__nome { font-size: 0.875rem; }
  .popup__link { height: 38px; font-size: 0.8125rem; }

  /* Aviso de truncamento */
  .aviso-truncamento { margin: 0 16px 0; font-size: 0.8125rem; }

  /* NavegaÃ§Ã£o mÃ³vel usa apenas o botÃ£o flutuante Buscar. */
  .tabs-mobile { display: none; }
}
