/* ═══════════════════════════════════════
   style.css — Base global
   Planilha Inteligente
═══════════════════════════════════════ */

/* ── Variáveis ── */
:root {
  --bg:          #EAF2FA;
  --card:        #FFFFFF;
  --line:        #B9D7EA;
  --accent:      #5B9BC4;
  --accent-deep: #3D7EA6;
  --text-dark:   #1F3B4D;
  --text-soft:   #6C8A9C;
  --success:     #4CAF82;
  --danger:      #D98A8A;
  --anel:        rgba(61, 126, 166, 0.18);   /* anel de foco dos campos (verde dentro do estoque) */
}

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

/* O atributo hidden sempre esconde (sem isto, um "display: flex" como o de .field vence e o elemento aparece) */
[hidden] { display: none !important; }

body {
  font-family: 'Space Grotesk', sans-serif;
  background: #F3F5F8;   /* fundo neutro: o azul e o verde ficam só nos blocos de cada frente */
  color: var(--text-dark);
  min-height: 100vh;
}

/* ── Topbar (compartilhada entre páginas internas) ── */
.topbar {
  display: flex;
  align-items: center;
  gap: 32px;
  padding: 0 32px;
  height: 60px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 100;
}

.topbar-brand {
  font-family: 'Fraunces', serif;
  font-size: 17px;
  font-weight: 600;
  color: var(--accent-deep);
  white-space: nowrap;
}

.topbar-nav {
  display: flex;
  gap: 4px;
  flex: 1;
}

.topbar-nav a {
  padding: 6px 14px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-soft);
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
}

.topbar-nav a:hover {
  background: var(--bg);
  color: var(--text-dark);
}

.topbar-nav a.active {
  background: var(--bg);
  color: var(--accent-deep);
  font-weight: 600;
}

.btn-sair {
  padding: 7px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  font-family: inherit;
  font-size: 13px;
  color: var(--text-soft);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}

.btn-sair:hover {
  background: #FBEAEA;
  border-color: #EFC9C9;
  color: #A85454;
}

/* Botão de ocultar valores (criado por js/privacidade.js, fica antes do "Sair") */
.btn-olho {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  color: var(--text-dark);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.btn-olho:hover {
  background: var(--bg);
  color: var(--accent-deep);
}

.btn-olho[aria-pressed="true"] {
  background: var(--bg);
  color: var(--accent-deep);
  border-color: var(--accent-deep);
}

/* ── Página interna ── */
.pagina {
  max-width: 1100px;
  margin: 0 auto;
  padding: 36px 32px;
}

.pagina-topo {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 28px;
}

.pagina-topo h1 {
  font-family: 'Fraunces', serif;
  font-size: 30px;
  font-weight: 600;
  line-height: 1.1;
  letter-spacing: -0.01em;
  color: var(--text-dark);
}

/* ── Frentes do negócio: bloco inteiro azul (representação) ou verde (estoque) ── */
.frente {
  margin-bottom: 24px;
  padding: 20px;
  border: 1px solid var(--f-borda);
  border-radius: 16px;
  background: var(--f-fundo);
}

.frente-azul {
  --f-cor: #3D7EA6;
  --f-escura: #28597A;
  --f-hover: #326C91;
  --f-fundo: #E8F1FA;
  --f-borda: #C9DDEE;
  --f-sombra: rgba(61, 126, 166, 0.28);
}

.frente-verde {
  --f-cor: #2E8B6A;
  --f-escura: #1F6A4F;
  --f-hover: #267558;
  --f-fundo: #E7F5EE;
  --f-borda: #C4E3D3;
  --f-sombra: rgba(46, 139, 106, 0.28);
  /* Dentro do bloco verde, as cores-base do app também viram verde: links, destaques,
     fundos claros e bordas de tudo que está lá dentro seguem a frente sem regra extra. */
  --accent: #4FA585;
  --accent-deep: #1F6A4F;
  --bg: #EEF7F2;
  --line: #C4E3D3;
  --anel: rgba(46, 139, 106, 0.18);
}

.frente-verde .btn-primario { background: var(--f-cor); }
.frente-verde .btn-primario:hover { background: var(--f-hover); }

.secao-cab {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.secao-icone {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  color: #FFFFFF;
  background: var(--f-cor);
  box-shadow: 0 2px 8px var(--f-sombra);
}

.secao-textos { flex: 1; min-width: 0; }

.secao-textos h2 {
  font-size: 20px;
  font-weight: 600;
  line-height: 1.2;
  color: var(--f-escura);
}

.secao-sub {
  display: block;
  margin-top: 2px;
  font-size: 13px;
  color: var(--text-soft);
}

/* Dentro de uma frente: botão principal, tabelas e resumos na cor dela */
.frente .btn-primario { background: var(--f-cor); }
.frente .btn-primario:hover { background: var(--f-hover); }
.frente .tabela-wrapper { border-color: var(--f-borda); }
.frente .resumo-comissao,
.frente .est-resumo { border-color: var(--f-borda); }
.frente .resumo-comissao strong,
.frente .est-resumo strong { color: var(--f-escura); }

/* ── Botões ── */
.btn-primario {
  padding: 10px 20px;
  background: var(--accent-deep);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}

.btn-primario:hover { background: #336E94; }

.btn-secundario {
  padding: 10px 20px;
  background: var(--card);
  color: var(--text-dark);
  border: 1px solid #D5DEE7;
  border-radius: 8px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.btn-secundario:hover { background: #F3F5F8; border-color: #BFCCD9; }

/* ── Campos de formulário ── */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field label {
  font-size: 13px;
  font-weight: 600;
  color: #3A5568;
}

.field input,
.field textarea,
.field select {
  padding: 10px 12px;
  border: 1px solid #D5DEE7;
  border-radius: 9px;
  font-family: inherit;
  font-size: 14px;
  color: var(--text-dark);
  background: var(--card);
  resize: vertical;
  transition: border-color 0.15s, box-shadow 0.15s;
}

/* Campos de uma linha com a mesma altura (texto, número, data e listas) */
.field input:not([type="checkbox"]):not([type="radio"]),
.field select { min-height: 42px; }

.field input::placeholder,
.field textarea::placeholder {
  color: #9AAFBE;
}

.field input:hover,
.field textarea:hover,
.field select:hover { border-color: #BFCCD9; }

.field input:focus,
.field textarea:focus,
.field select:focus {
  outline: none;
  border-color: var(--accent-deep);
  box-shadow: 0 0 0 3px var(--anel);
}

/* ── Modal (janelas de cadastro) ──
   Cabeçalho e rodapé em faixas próprias, fixos enquanto o meio rola; a faixa de cor no topo
   diz de qual frente é a janela: azul (representação) ou verde (estoque, com .frente-verde). */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(16, 32, 45, 0.48);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-overlay.aberto {
  display: flex;
}

.modal {
  background: var(--card);
  border-top: 4px solid var(--accent-deep);
  border-radius: 16px;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 24px 28px;
  box-shadow: 0 24px 60px rgba(16, 32, 45, 0.28), 0 2px 8px rgba(16, 32, 45, 0.10);
}

.modal-topo {
  position: sticky;
  top: -24px;
  z-index: 2;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin: -24px -28px 22px;
  padding: 18px 20px 16px 28px;
  background: var(--card);
  border-bottom: 1px solid #E3E9EF;
}

.modal-topo h2 {
  font-size: 18px;
  font-weight: 600;
  line-height: 1.3;
  color: var(--text-dark);
}

.modal-fechar {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  padding: 0;
  background: none;
  border: none;
  border-radius: 8px;
  font-size: 22px;
  line-height: 1;
  color: var(--text-soft);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.modal-fechar:hover { background: #F3F5F8; color: var(--text-dark); }

.modal-rodape {
  position: sticky;
  bottom: -24px;
  z-index: 2;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
  margin: 20px -28px -24px;
  padding: 14px 28px;
  background: #F7F9FB;
  border-top: 1px solid #E3E9EF;
  border-radius: 0 0 16px 16px;
}

.modal-rodape .btn-primario,
.modal-rodape .btn-secundario {
  min-height: 40px;
  padding: 0 18px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 24px;
}

.field.span-2 { grid-column: span 2; }

/* ── Tabela ── */
.tabela-wrapper {
  overflow-x: auto;
  border-radius: 12px;
  border: 1px solid #DCE4EB;
  background: var(--card);
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.05);
}

.tabela {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  font-variant-numeric: tabular-nums;   /* algarismos com a mesma largura: valores alinhados */
}

.tabela thead { background: #F7F9FB; }

.tabela th {
  padding: 11px 16px;
  text-align: left;
  font-size: 11.5px;
  font-weight: 600;
  color: #5E7687;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid #E3E9EF;
  white-space: nowrap;
}

.tabela td {
  padding: 13px 16px;
  border-bottom: 1px solid #EEF2F5;
  color: var(--text-dark);
  vertical-align: middle;
}

.tabela tbody tr:last-child td { border-bottom: none; }
.tabela tbody tr:hover td { background: #F7FAFC; }

/* ── Vazio ── */
.vazio {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-soft);
  font-size: 15px;
  line-height: 1.8;
}

/* ── Badges ── */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}

.badge-sim {
  background: #DFF5EC;
  color: #2E7D5A;
}

.badge-nao {
  background: #FBEAEA;
  color: #A85454;
}

/* ── Botões de ação na tabela ── */
.acoes { display: flex; gap: 8px; }

/* Discretos: contorno fino; a cor aparece no texto e ao passar o mouse, sem disputar com os dados */
.btn-editar,
.btn-excluir {
  padding: 5px 12px;
  border-radius: 7px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  background: var(--card);
  border: 1px solid #D5DEE7;
  transition: background 0.15s, border-color 0.15s;
}

.btn-editar { color: var(--text-dark); }
.btn-editar:hover { background: #F3F5F8; border-color: #BFCCD9; }
.btn-excluir { color: #B04A4A; }
.btn-excluir:hover { background: #FBEAEA; border-color: #EBC5C5; }

/* ── Responsivo ── */
@media (max-width: 700px) {
  /* Topbar em duas linhas: marca + Sair em cima, navegação embaixo.
     Numa linha só os 5 links não cabem na largura do celular, e o excesso
     empurrava a PÁGINA INTEIRA pro lado — a marca e os cards apareciam
     cortados. Aqui a navegação vira uma faixa própria que rola sozinha,
     então nada mais estoura a largura da tela. */
  .topbar {
    flex-wrap: wrap;
    height: auto;
    padding: 10px 16px;
    gap: 10px 12px;
  }

  .topbar-brand {
    order: 1;
    flex: 1;
    font-size: 15px;
    min-width: 0;          /* permite encolher em vez de estourar a linha */
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .btn-sair {
    order: 2;
    padding: 6px 12px;
  }

  .btn-olho {
    order: 2;
    width: 32px;
    height: 32px;
  }

  .topbar-nav {
    order: 3;
    flex: none;
    width: 100%;
    gap: 4px;
    overflow-x: auto;      /* rola só a navegação, nunca a página */
    scrollbar-width: none;
    -ms-overflow-style: none;
  }

  .topbar-nav::-webkit-scrollbar { display: none; }

  /* Medidas escolhidas pra que os 5 links caibam inteiros numa tela de
     375px (soma ~333px no espaço de 343px). Em telas mais estreitas que
     isso o overflow-x acima entra em ação e a faixa rola. */
  .topbar-nav a {
    padding: 8px;
    font-size: 12px;
    white-space: nowrap;
    flex-shrink: 0;        /* sem isso os links se espremem e quebram o texto */
  }

  .pagina { padding: 24px 16px; }

  /* Título + ações (mês, "+ Nova ...") quebram em duas linhas quando não
     cabem numa só. Antes, em Empresas, o seletor de mês e o botão ficavam
     na mesma linha do título e empurravam a página inteira pro lado. */
  .pagina-topo {
    flex-wrap: wrap;
    gap: 12px;
  }

  .form-grid { grid-template-columns: 1fr; }
  .field.span-2 { grid-column: span 1; }

  .pagina-topo h1 { font-size: 26px; }
  .frente { padding: 12px; border-radius: 14px; }
  .tabela th,
  .tabela td { padding-left: 10px; padding-right: 10px; }
  .secao-textos h2 { font-size: 18px; }
  .secao-icone { width: 36px; height: 36px; }
}

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