/* ============================================================================
   SISTEMA DE MARGEM - Vitrola Administrativo
   CSS Mobile-First
   ============================================================================ */

/* ===== CONTAINER PRINCIPAL ===== */
.margem-container {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 20px;
}

/* ===== MENSAGEM SEM PERMISSÃO ===== */
.margem-sem-permissao {
  background: #fff3cd;
  border: 1px solid #ffc107;
  border-left: 4px solid #ffc107;
  border-radius: 8px;
  padding: 20px;
  text-align: center;
  color: #856404;
}

.margem-sem-permissao p {
  margin: 8px 0;
}

/* ===== FILTROS ===== */
.margem-filtros {
  background: #fff;
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  overflow: hidden;
}

/* ===== TOGGLE DE MODO (CLIENTE / VENDEDOR) ===== */
.margem-modo-toggle {
  display: flex;
  gap: 0;
  margin-bottom: 20px;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  overflow: hidden;
}

.margem-modo-btn {
  flex: 1;
  padding: 10px 16px;
  border: none;
  background: #f8f9fa;
  color: #666;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  font-family: 'Rubik', sans-serif;
}

.margem-modo-btn.active {
  background: #c21a26;
  color: #fff;
}

@media (hover: hover) {
  .margem-modo-btn:not(.active):hover {
    background: #e9ecef;
  }
}

/* ===== SELECT DE VENDEDOR ===== */
.margem-vendedor-select {
  width: 100%;
  padding: 14px;
  border: 2px solid #e0e0e0;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 500;
  color: #333;
  background: #fff;
  min-height: 48px;
  cursor: pointer;
  transition: border-color 0.2s;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23666' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

.margem-vendedor-select:focus {
  outline: none;
  border-color: #c21a26;
}

.margem-vendedor-select:disabled {
  background-color: #f0f0f0;
  color: #999;
  cursor: not-allowed;
}

/* ===== PESQUISA DE CLIENTES ===== */
.margem-pesquisa-section {
  margin-bottom: 20px;
}

/* ===== RESULTADOS DA PESQUISA ===== */
.margem-pesquisa-resultados {
  margin-top: 12px;
  background: #f8f9fa;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  overflow: hidden;
}

.margem-resultados-header {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px;
  background: #fff;
  border-bottom: 1px solid #e0e0e0;
}

.margem-resultados-count {
  font-size: 14px;
  color: #666;
  font-weight: 500;
}

.margem-resultados-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.margem-selecionados-count {
  font-size: 13px;
  font-weight: 600;
  color: #155724;
}

.margem-resultados-acoes {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.margem-btn-selecionar-todos,
.margem-btn-limpar-selecao {
  padding: 8px 12px;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  background: #fff;
  color: #666;
}

@media (hover: hover) {
  .margem-btn-selecionar-todos:hover {
    background: #c21a26;
    border-color: #c21a26;
    color: #fff;
  }

  .margem-btn-limpar-selecao:hover {
    background: #6c757d;
    border-color: #6c757d;
    color: #fff;
  }
}

/* ===== LISTA DE CLIENTES (PESQUISA) ===== */
.margem-lista-clientes {
  max-height: 300px;
  overflow-y: auto;
}

.margem-cliente-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-bottom: 1px solid #e9ecef;
  cursor: pointer;
  transition: background-color 0.2s;
}

.margem-cliente-item:last-child {
  border-bottom: none;
}

.margem-cliente-item.margem-cliente-selecionado {
  background-color: #f0faf3;
}

@media (hover: hover) {
  .margem-cliente-item:hover {
    background-color: #f0f4f8;
  }
}

.margem-cliente-checkbox {
  width: 18px;
  height: 18px;
  accent-color: #c21a26;
  cursor: pointer;
  flex-shrink: 0;
}

.margem-cliente-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-width: 0;
}

.margem-cliente-codigo {
  font-size: 12px;
  color: #999;
  font-weight: 500;
}

.margem-cliente-nome {
  font-size: 14px;
  color: #333;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.margem-loading-mini,
.margem-sem-resultados-cliente,
.margem-erro-mini {
  padding: 20px;
  text-align: center;
  color: #666;
  font-size: 14px;
}

.margem-erro-mini {
  color: #c21a26;
}

/* ===== CHECKBOX PERÍODO AUTOMÁTICO ===== */
.margem-periodo-auto-section {
  margin-bottom: 20px;
}

.margem-periodo-auto-label {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  color: #333;
  padding: 10px 12px;
  background: #f0faf3;
  border: 1px solid #c3e6cb;
  border-radius: 8px;
  transition: all 0.2s;
}

@media (hover: hover) {
  .margem-periodo-auto-label:hover {
    background: #e2f5e9;
  }
}

.margem-periodo-auto-label input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: #28a745;
  cursor: pointer;
  flex-shrink: 0;
}

.margem-periodo-auto-label input[type="checkbox"]:not(:checked)~span {
  color: #888;
}

/* ===== FILTRO DE PERÍODO ===== */
.margem-periodo-section {
  margin-bottom: 16px;
}

.margem-datas {
  display: flex;
  flex-direction: row;
  gap: 12px;
}

.margem-data-group {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.margem-data-group label {
  font-size: 14px;
  font-weight: 600;
  color: #333;
}

.margem-data-group input[type="date"] {
  width: 100%;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  padding: 12px;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  font-size: 16px;
  min-height: 48px;
  transition: border-color 0.2s;
}

.margem-data-group input[type="date"]:focus {
  outline: none;
  border-color: #c21a26;
}

.margem-data-group input[type="date"]:disabled {
  background-color: #f0f0f0;
  color: #999;
  cursor: not-allowed;
  border-color: #ddd;
}

/* ===== BOTÃO CONSULTAR ===== */
.margem-consultar-btn {
  width: 100%;
  padding: 14px 20px;
  background: linear-gradient(135deg, #c21a26 0%, #e74c3c 100%);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  transition: all 0.3s ease;
  font-family: 'Rubik', sans-serif;
  max-width: 400px;
  margin: 0 auto;
}

@media (hover: hover) {
  .margem-consultar-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(194, 26, 38, 0.3);
  }
}

.margem-consultar-btn:active:not(:disabled) {
  transform: translateY(0);
}

.margem-consultar-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* ===== RESUMO ===== */
.margem-resumo {
  background: linear-gradient(135deg, #c21a26 0%, #2a0509 100%);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 16px;
  color: #fff;
}

.margem-resumo-periodo {
  font-size: 14px;
  opacity: 0.9;
  margin-bottom: 12px;
  text-align: center;
}

.margem-resumo-cards {
  display: flex;
  flex-direction: row;
  gap: 12px;
}

.margem-resumo-card {
  flex: 1;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 10px;
  padding: 20px;
  text-align: center;
}

.margem-resumo-label {
  display: block;
  font-size: 14px;
  opacity: 0.9;
  margin-bottom: 4px;
}

.margem-resumo-valor {
  display: block;
  font-size: 20px;
  font-weight: 700;
}

/* ===== RESULTADOS ===== */
.margem-resultados {
  min-height: 200px;
}

.margem-lista {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ===== LOADING ===== */
.margem-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  color: #666;
}

.margem-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid #f0f0f0;
  border-top-color: #c21a26;
  border-radius: 50%;
  animation: margem-spin 0.8s linear infinite;
  margin-bottom: 12px;
}

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

/* ===== ESTADO VAZIO ===== */
.margem-vazio {
  text-align: center;
  padding: 40px 20px;
  color: #999;
}

.margem-vazio svg {
  margin-bottom: 16px;
  opacity: 0.5;
}

.margem-vazio p {
  margin: 0;
  font-size: 14px;
  line-height: 1.5;
}

/* ===== SEM RESULTADOS / ERRO ===== */
.margem-sem-resultados-periodo,
.margem-erro {
  text-align: center;
  padding: 30px 20px;
  background: #f8f9fa;
  border-radius: 8px;
  color: #666;
  font-size: 14px;
}

.margem-erro {
  background: #fff5f5;
  color: #c21a26;
  border: 1px solid #f5c6cb;
}

/* ===== ACCORDION POR ANO ===== */
.margem-accordion-item {
  background: #fff;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.margem-accordion-header {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px;
  background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
  border: none;
  border-bottom: 1px solid #e0e0e0;
  cursor: pointer;
  transition: background-color 0.2s;
  text-align: left;
  font-family: 'Rubik', sans-serif;
}

@media (hover: hover) {
  .margem-accordion-header:hover {
    background: linear-gradient(135deg, #eef0f2 0%, #dee2e6 100%);
  }
}

.margem-accordion-titulo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.margem-accordion-chevron {
  color: #c21a26;
  flex-shrink: 0;
  transition: transform 0.25s ease;
}

.margem-accordion-item.open .margem-accordion-chevron {
  transform: rotate(180deg);
}

.margem-accordion-ano {
  font-size: 20px;
  font-weight: 700;
  color: #333;
}

.margem-accordion-qtd {
  font-size: 13px;
  font-weight: 500;
  color: #888;
}

.margem-accordion-subtotal {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
}

.margem-accordion-subtotal-valor {
  font-size: 16px;
  font-weight: 700;
  color: #333;
}

.margem-accordion-subtotal-margem {
  font-size: 14px;
  font-weight: 600;
  color: #007bff;
}

.margem-accordion-subtotal-perc {
  font-size: 13px;
  font-weight: 600;
  color: #28a745;
}

.margem-accordion-body {
  background: #fff;
}

/* ===== TABELA CONSOLIDADA DENTRO DO ACCORDION ===== */
.margem-tabela-scroll {
  width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
}

/* --------------------------------------------------------------------------
   MOBILE: evita "scroll duplo" da tabela
   Em `css/estilos-gerais.css` existe uma regra global (@media max-width: 768px)
   que transforma TODO `table` em `display: block` e aplica `overflow-x: auto`.
   Aqui a tabela já está dentro de um wrapper rolável (`.margem-tabela-scroll`),
   então no celular acabam existindo dois elementos roláveis no eixo X, deixando
   o arraste horizontal "travado"/pouco fluido.
   -------------------------------------------------------------------------- */
.margem-tabela-scroll>table {
  display: table;
  width: 100%;
  max-width: none;
  margin: 0;
  overflow: visible;
}

.margem-tabela {
  width: 100%;
  border-collapse: collapse;
  font-size: 15px;
  margin: 0;
}

.margem-tabela-consolidada {
  min-width: 540px;
}

.margem-tabela th {
  background: #f8f9fa;
  color: #666;
  font-weight: 600;
  padding: 14px 16px;
  text-align: right;
  border-bottom: 2px solid #e0e0e0;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
}

.margem-tabela th.margem-col-mes {
  text-align: left;
}

.margem-tabela td {
  padding: 14px 16px;
  text-align: right;
  border-bottom: 1px solid #f0f0f0;
  white-space: nowrap;
}

.margem-tabela td.margem-col-mes {
  text-align: left;
  font-weight: 600;
  color: #333;
}

.margem-tabela tbody tr:last-child td {
  border-bottom: none;
}

@media (hover: hover) {
  .margem-tabela tbody tr:hover {
    background: #fafbfc;
  }
}

/* Destaque de devolução em vermelho */
.margem-tabela td.margem-valor-negativo {
  color: #dc3545;
  font-weight: 500;
}

/* ============================================================================
   RESPONSIVO
   ============================================================================ */

@media (max-width: 1023px) {
  .margem-container {
    max-width: 800px;
  }

  .margem-consultar-btn {
    max-width: none;
    margin: 0;
  }
}

@media (max-width: 767px) {
  .margem-container {
    padding: 0;
  }

  .margem-filtros {
    padding: 16px;
  }

  .margem-resumo {
    padding: 16px;
  }

  .margem-resumo-cards {
    flex-direction: column;
    gap: 10px;
  }

  .margem-resumo-card {
    flex: auto;
    padding: 14px;
  }

  .margem-tabela {
    font-size: 14px;
  }

  .margem-tabela th {
    padding: 12px 14px;
  }

  .margem-tabela td {
    padding: 12px 14px;
  }

  .margem-accordion-header {
    padding: 16px;
  }

  .margem-accordion-ano {
    font-size: 18px;
  }

  .margem-accordion-subtotal-valor {
    font-size: 15px;
  }

  .margem-accordion-subtotal-margem {
    font-size: 13px;
  }
}

@media (max-width: 479px) {
  .margem-datas {
    flex-direction: column;
  }

  .margem-data-group {
    flex: auto;
  }

  .margem-resultados-header {
    flex-direction: column;
    align-items: stretch;
  }

  .margem-tabela {
    font-size: 13px;
  }

  .margem-tabela th {
    font-size: 11px;
    padding: 10px 12px;
  }

  .margem-tabela td {
    padding: 10px 12px;
  }
}