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

[hidden] { display: none !important; }

/* Paleta Motrix */
:root {
  --navy:       #1a2740;
  --blue:       #4d8ec4;
  --blue-light: #6ab4d8;
  --blue-pale:  #e8f3fb;
  --gray-bg:    #f4f6f9;
  --gray-border:#e2e6ed;
  --text:       #1a2740;
  --text-muted: #64748b;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--gray-bg);
  color: var(--text);
  min-height: 100vh;
}

/* ============================================================
   LOADING
============================================================ */

#loading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  color: var(--text-muted);
}

/* ============================================================
   HEADER
============================================================ */

header {
  background: #fff;
  border-bottom: 1px solid var(--gray-border);
  padding: 0 32px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-logo {
  height: 32px;
  width: auto;
  display: block;
}

.header-user {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 0.88rem;
}

#user-nome {
  color: var(--text-muted);
  font-weight: 500;
}

.badge {
  background: var(--blue-pale);
  color: var(--blue);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 99px;
}

.btn-sair {
  background: none;
  border: 1px solid var(--gray-border);
  border-radius: 6px;
  padding: 6px 14px;
  font-size: 0.85rem;
  color: var(--text-muted);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}

.btn-sair:hover {
  border-color: var(--blue);
  color: var(--blue);
}

/* ============================================================
   MAIN / LAYOUT
============================================================ */

main {
  max-width: 960px;
  margin: 0 auto;
  padding: 32px 24px;
}

section h2 {
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 20px;
  color: var(--navy);
}

#titulo-lojas {
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

#contador-lojas {
  display: block;
  font-size: 0.82rem;
  font-weight: 400;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ============================================================
   LISTA DE LOJAS — cabeçalho + filtro
============================================================ */

.lojas-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.lojas-header h2 {
  margin-bottom: 0;
}

#filtro-lojas {
  border: 1px solid var(--gray-border);
  border-radius: 6px;
  padding: 8px 14px;
  font-size: 0.9rem;
  width: 280px;
  outline: none;
  transition: border-color 0.15s;
  color: var(--text);
}

#filtro-lojas:focus {
  border-color: var(--blue);
}

/* ============================================================
   TABELA DE LOJAS
============================================================ */

.tabela-wrapper {
  overflow-x: auto;
  background: #fff;
  border-radius: 10px;
  border: 1px solid var(--gray-border);
  box-shadow: 0 1px 4px rgba(26, 39, 64, 0.06);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

thead {
  background: var(--gray-bg);
  border-bottom: 2px solid var(--gray-border);
}

th {
  text-align: left;
  padding: 12px 16px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  white-space: nowrap;
}

td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--gray-border);
  color: var(--text);
  font-size: 0.83rem;
}

.td-cnpj {
  font-family: monospace;
  color: #666;
  white-space: nowrap;
  width: 1%;
}

td[data-label="Cidade"] {
  white-space: nowrap;
  width: 1%;
}

.badge-status {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  padding: 3px 10px;
  border-radius: 99px;
  white-space: nowrap;
}

.badge-status--ativo {
  background: #e6f4ea;
  color: #1e7e34;
}

.badge-status--inativo {
  background: #f0f0f0;
  color: #888;
}

.btn-editar-vendedor {
  background: none;
  border: 1px solid var(--blue);
  color: var(--blue);
  padding: 3px 10px;
  border-radius: 4px;
  font-size: 0.75rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  line-height: 1.4;
}

.btn-editar-vendedor:hover {
  background: var(--blue);
  color: #fff;
}

.th-sort {
  cursor: pointer;
  user-select: none;
}

.th-sort:hover {
  color: var(--blue);
}

.sort-icon {
  color: var(--blue);
  font-size: 0.8rem;
}

tr:last-child td {
  border-bottom: none;
}

.linha-clicavel {
  cursor: pointer;
  transition: background 0.1s;
}

.linha-clicavel:hover {
  background: var(--blue-pale);
}

/* ============================================================
   GRID DE CARDS (usado apenas para vendedores)
============================================================ */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}

.card {
  background: #fff;
  border-radius: 10px;
  padding: 20px;
  box-shadow: 0 1px 4px rgba(26, 39, 64, 0.07);
  border: 1px solid var(--gray-border);
}

.card-topo-vendedor {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.card-topo-vendedor .card-titulo {
  margin-bottom: 0;
}

.card-titulo {
  font-weight: 600;
  font-size: 1rem;
  margin-bottom: 6px;
  color: #1a1a2e;
}

.card-info {
  font-size: 0.85rem;
  color: #666;
  line-height: 1.5;
}

.vazio {
  color: #888;
  font-size: 0.9rem;
  padding: 8px 0;
}

/* ============================================================
   DETALHE DA LOJA
============================================================ */

.btn-voltar {
  background: none;
  border: none;
  color: var(--blue);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  padding: 0;
  margin-bottom: 20px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.btn-voltar:hover {
  color: var(--navy);
  text-decoration: underline;
}

.detalhe-card {
  background: #fff;
  border-radius: 10px;
  padding: 24px;
  border: 1px solid var(--gray-border);
  margin-bottom: 28px;
  box-shadow: 0 1px 4px rgba(26, 39, 64, 0.06);
}

.detalhe-topo {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 8px;
  gap: 16px;
}

.detalhe-grupo {
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: var(--blue-pale);
  border-left: 3px solid var(--blue);
  border-radius: 6px;
  padding: 10px 14px;
  margin-top: 6px;
  margin-bottom: 28px;
}

.detalhe-grupo-nome {
  font-size: 1rem;
  font-weight: 700;
  color: var(--navy);
}

.detalhe-grupo-cnpj {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-family: monospace;
}

.detalhe-card h2 {
  font-size: 1.4rem;
  margin-top: 4px;
}

.badge-classificacao {
  background: var(--blue-pale);
  color: var(--blue);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 4px 12px;
  border-radius: 99px;
  white-space: nowrap;
  flex-shrink: 0;
}

.detalhe-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px 24px;
}

.detalhe-grid > div {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.detalhe-full {
  grid-column: 1 / -1;
}

.detalhe-secao {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid #f0f0f0;
}

.detalhe-secao h4 {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #888;
  margin-bottom: 14px;
}

.bancos-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
}

.banco-card {
  background: #f8f9fa;
  border: 1px solid #e8eaed;
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 0.83rem;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.banco-nome {
  font-weight: 600;
  color: #1a1a2e;
  margin-bottom: 4px;
  display: block;
  line-height: 1.4;
}

.label {
  font-size: 0.75rem;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}

.secao-vendedores {
  margin-top: 8px;
}

.secao-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.secao-header h3 {
  font-size: 1.1rem;
  font-weight: 600;
}

/* ============================================================
   BOTÕES
============================================================ */

.btn-primario {
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 8px 18px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-primario:hover {
  background: var(--navy);
}

.btn-primario:disabled {
  background: var(--gray-border);
  color: var(--text-muted);
  cursor: not-allowed;
}

.btn-secundario {
  background: #fff;
  color: var(--text-muted);
  border: 1px solid var(--gray-border);
  border-radius: 6px;
  padding: 8px 18px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.btn-secundario:hover {
  background: var(--gray-bg);
  border-color: var(--blue);
}

/* ============================================================
   MODAL
============================================================ */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 200;
}

.modal-caixa {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: #fff;
  border-radius: 12px;
  padding: 28px;
  width: calc(100% - 32px);
  max-width: 420px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  z-index: 201;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.modal-caixa h3 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 20px;
  flex-shrink: 0;
}

.modal-caixa form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
}

.modal-caixa label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.85rem;
  font-weight: 500;
  color: #444;
}

.modal-caixa select {
  border: 1px solid #d0d0d0;
  border-radius: 6px;
  padding: 9px 12px;
  font-size: 0.95rem;
  width: 100%;
  outline: none;
  background: #fff;
  transition: border-color 0.15s;
}

.modal-caixa select:focus {
  border-color: var(--blue);
}

.modal-caixa input {
  border: 1px solid #d0d0d0;
  border-radius: 6px;
  padding: 9px 12px;
  font-size: 0.95rem;
  width: 100%;
  outline: none;
  transition: border-color 0.15s;
}

.modal-caixa input:focus {
  border-color: var(--blue);
}

.modal-caixa input:disabled {
  background: var(--gray-bg);
  color: var(--text-muted);
  cursor: not-allowed;
}

.modal-botoes {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 6px;
}

.modal-caixa--largo {
  max-width: 600px;
  width: calc(100% - 32px);
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.form-grid .form-full {
  grid-column: 1 / -1;
}

/* ============================================================
   RESPONSIVO — MOBILE (até 640px)
============================================================ */

@media (max-width: 640px) {

  /* Header */
  header {
    height: auto;
    padding: 12px 16px;
    flex-wrap: wrap;
    gap: 8px;
  }

  header h1 {
    font-size: 1rem;
  }

  .header-user {
    font-size: 0.82rem;
    gap: 8px;
  }

  #user-promotora {
    display: none;
  }

  /* Main */
  main {
    padding: 20px 16px;
  }

  /* Filtro + título */
  .lojas-header {
    flex-direction: column;
    align-items: stretch;
  }

  #filtro-lojas {
    width: 100%;
  }

  /* Tabela → cards no mobile */
  .tabela-wrapper {
    border: none;
    background: transparent;
    box-shadow: none;
  }

  table, tbody, tr, td {
    display: block;
    width: 100%;
  }

  thead {
    display: none;
  }

  tr.linha-clicavel {
    background: #fff;
    border-radius: 10px;
    border: 1px solid #e8eaed;
    padding: 14px 16px;
    margin-bottom: 10px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  }

  tr.linha-clicavel:hover {
    border-color: var(--blue);
    background: var(--blue-pale);
  }

  td {
    padding: 3px 0;
    border: none;
    font-size: 0.88rem;
  }

  /* Razão social em destaque */
  td[data-label="Razão Social"] {
    font-weight: 600;
    font-size: 0.95rem;
    color: #1a1a2e;
    margin-bottom: 6px;
  }

  /* Label antes de cada célula */
  td[data-label="CNPJ"]::before,
  td[data-label="Cidade"]::before,
  td[data-label="Classificação"]::before {
    content: attr(data-label) ": ";
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    color: #999;
    letter-spacing: 0.04em;
  }

  /* Detalhe da loja */
  .detalhe-card {
    padding: 16px;
  }

  .detalhe-topo {
    flex-direction: column;
    gap: 8px;
  }

  .detalhe-grid {
    grid-template-columns: 1fr;
  }

  /* Seção vendedores */
  .secao-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  .secao-header .btn-primario {
    width: 100%;
    text-align: center;
  }

  /* Botão voltar */
  .btn-voltar {
    font-size: 0.9rem;
    padding: 8px 0;
  }

  /* Grid de vendedores */
  .grid {
    grid-template-columns: 1fr;
  }

  /* Modal */
  .modal-caixa {
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    transform: none;
    border-radius: 16px 16px 0 0;
    width: 100%;
    max-width: 100%;
    max-height: 92vh;
    padding: 24px 20px 36px;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .modal-botoes {
    flex-direction: column-reverse;
    gap: 8px;
  }

  .modal-botoes button {
    width: 100%;
    padding: 12px;
    font-size: 1rem;
  }
}
