/* ===== Layout estilo Marketplace V2 (Refatorado) ===== */

body,
html {
  margin: 0;
  padding: 0;
  width: 100%;
  overflow-x: hidden;
  background: #f3f4f6;
}

/* Ocupar toda a tela como a original */
main.container {
  padding: 0;
  margin: 0;
  width: 100%;
  max-width: none;
}

main.container h1 {
  font-size: 1.2rem;
  text-align: center;
  margin: 0.5rem 0 0.8rem 0;
  color: #222;
}

/* --- Container Grid e Cards --- */
.materiais-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.4rem;
  padding: 0.2rem;
  margin-top: 0.2rem;
  margin-bottom: 0.5rem;
}

@media (min-width: 768px) {
  .materiais-grid {
    grid-template-columns: repeat(6, 1fr);
  }
}

@media (min-width: 1024px) {
  .materiais-grid {
    grid-template-columns: repeat(8, 1fr);
  }
}

/* --- ESTILO DOS CARDS AJUSTADOS PARA MOBILE --- */
.material-card {
  width: 100%;
  margin: 0;
  border: 1px solid #ddd;
  border-radius: 8px;
  background: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  /* Reduzimos o padding para caber melhor no mobile */
  padding: 2px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  transition: transform 0.2s ease, box-shadow 0.2s ease, border 0.2s ease;
  cursor: pointer;
  box-sizing: border-box;
}

.material-card:hover {
  transform: scale(1.03);
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.15);
}

.material-card.selected {
  border: 2px solid var(--primary-color, #00796b);
  transform: scale(1.02);
}

.material-img-wrapper {
  width: 100%;
  height: 80px;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #f9f9f9;
  border-radius: 4px 4px 0 0;
  margin-bottom: 2px;
  overflow: hidden;
}

@media (min-width: 768px) {
  .material-img-wrapper {
    height: 80px;
  }

  .material-card {
    padding: 4px;
  }
}

.material-img-wrapper img {
  object-fit: cover;
  width: 100%;
  height: 100%;
  border-radius: 0;
  cursor: zoom-in;
}

.material-title {
  /* Fonte menor e com quebra de linha ajustada no mobile */
  font-size: 0.65rem;
  font-weight: bold;
  color: #333;
  margin: 0.2rem 0;
  padding: 0 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  text-align: center;
}

/* --- Títulos Categoria --- */
.categoria-header {
  width: 100%;
  padding: 4px 8px;
  font-size: 0.9rem;
  font-weight: bold;
  text-align: left;
  border-bottom: 1px solid #ddd;
  margin: 4px 0 0 0;
  color: #555;
}

.preco-input-group .material-price-input {
  font-weight: 700;
  border-color: #0b5ed7 !important;
  /* Borda azul para guiar o olhar */
  background-color: #f4f8ff;
  /* Fundo bem sutilmente azulado */
  color: #000;
}

/* --- Skeleton Loading --- */
.card-placeholder {
  width: 100%;
  height: 120px;
  border-radius: 8px;
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 37%, #f0f0f0 63%);
  background-size: 400% 100%;
  animation: shimmer 1.2s infinite;
}

@media (min-width: 768px) {
  .card-placeholder {
    height: 140px;
  }
}

@keyframes shimmer {
  0% {
    background-position: -400px 0;
  }

  100% {
    background-position: 400px 0;
  }
}

/* --- Propriedades (Expansão) --- */
.propriedades-container {
  display: none;
  width: 100%;
  padding-top: 4px;
  border-top: 1px solid #f0f0f0;
  margin-top: 2px;
  flex-direction: column;
  gap: 2px;
}

.material-card.expanded .propriedades-container {
  display: flex;
}

.propriedade-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  font-size: 0.65rem;
}

.propriedade-name {
  font-weight: 600;
  color: #444;
  margin-bottom: 1px;
  text-align: center;
  /* Para propriedades longas no mobile */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

/* --- Inputs e Botões (Unificados e Alinhados) --- */
/* --- Inputs e Botões (Unificados e Alinhados) --- */
.preco-input-group,
.propriedade-price {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1px;
  /* Espaço mínimo entre botões e input */
  width: 100%;
}

.material-price-input {
  /* Largura aumentada para caber mais dígitos */
  width: 52px !important;
  height: 22px !important;
  text-align: center;
  padding: 0 !important;
  font-size: 0.75rem;
  border: 1px solid #ccc;
  border-radius: 4px;
  margin: 0 !important;
  box-sizing: border-box;
}

.btn-maior,
.btn-menor {
  /* Botões levemente reduzidos (20px) para compensar o input maior */
  width: 20px !important;
  height: 22px !important;
  background-color: #eee;
  border: 1px solid #ccc;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  padding: 0;
  margin: 0;
  line-height: 1;
  color: #333;
}

/* Telas um pouco maiores (tablets, desktops) */
@media (min-width: 480px) {
  .material-price-input {
    width: 60px !important;
    /* Input ainda maior no desktop */
    height: 24px !important;
    font-size: 0.85rem;
  }

  .btn-maior,
  .btn-menor {
    width: 24px !important;
    /* Botões voltam ao tamanho normal */
    height: 24px !important;
    font-size: 0.85rem;
  }

  .preco-input-group,
  .propriedade-price {
    gap: 2px;
  }
}

.remover-btn {
  font-size: 0.6rem;
  padding: 2px 4px;
  background: transparent;
  border: 1px solid #ccc;
  border-radius: 4px;
  cursor: pointer;
  color: #555;
  width: 90%;
  margin-top: auto !important;
  /* Empurra o botão pro rodapé do card */
  margin-bottom: 4px;
  /* Descola um pouco da borda inferior */
}

.remover-btn:hover {
  background-color: #f8d7da;
  border-color: #f5c6cb;
  color: #a94442;
}

/* --- Barra de busca e Filtro --- */
#material-search-bar {
  margin-top: 1rem;
  margin-bottom: 0.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 0 10px;
}

.search-row {
  width: 100%;
  max-width: 420px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

#material-search-input {
  flex: 1;
  height: 36px;
  padding: 0 0.8rem;
  border: 1px solid #ccc;
  border-radius: 6px;
  font-size: 1rem;
  box-sizing: border-box;
}

.btn-filtro {
  width: 44px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  background: #007bff;
  color: #fff;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  margin: 0;
  box-sizing: border-box;
}

.btn-filtro:hover {
  background: #0056b3;
}

#material-nao-encontrado {
  font-size: 13px;
  margin: 2px 0 8px;
  color: #555;
  text-align: center;
}

/* --- Paginação --- */
.paginacao-materiais {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 1rem;
  margin: 1rem 0 5rem 0;
  /* Margem inferior extra para não ficar atrás do botão flutuante */
}

.paginacao-materiais span {
  font-weight: bold;
  font-size: 1rem;
}

.paginacao-materiais button {
  background-color: var(--primary-color, #00796b);
  color: #fff;
  font-size: 0.9rem;
  padding: 0.3rem 0.9rem;
  border: none;
  border-radius: 6px;
  cursor: pointer;
}

.paginacao-materiais button:disabled {
  background-color: #ccc;
  cursor: not-allowed;
}



/* --- Modais e Overlays --- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.modal.hidden {
  display: none;
}

.modal-content {
  background: white;
  padding: 20px;
  border-radius: 10px;
  width: 90%;
  max-width: 400px;
}

.image-zoom-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.9);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
}

.image-zoom-overlay.hidden {
  display: none !important;
}

.zoom-container img {
  max-width: 90vw;
  max-height: 90vh;
  border-radius: 8px;
}

.observacoes-container {
  margin-top: 15px;
  padding: 10px;
  background: #fff;
  border-radius: 8px;
  border: 1px solid #ddd;
}

.tag {
  background: #f0f0f0;
  border: 1px solid #ccc;
  padding: 5px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  cursor: pointer;
}

.tag:hover {
  background: #e0e0e0;
}

.input-obs-wrapper {
  display: flex;
  align-items: center;
  gap: 5px;
  border: 1px solid #ccc;
  border-radius: 6px;
  padding: 5px;
}

#observacoes {
  flex: 1;
  border: none;
  font-size: 0.9rem;
  outline: none;
}

#char-count {
  font-size: 0.7rem;
  color: #888;
  padding-right: 5px;
}

.tags-predefinidas {
  display: flex !important;
  flex-wrap: wrap !important;
  gap: 6px !important;
  margin: 8px 0 !important;
}

.tag-compacta {
  background: #eef2f7 !important;
  border: 1px solid #d1d9e0 !important;
  padding: 4px 10px !important;
  border-radius: 12px !important;
  font-size: 0.7rem !important;
  color: #444 !important;
  cursor: pointer !important;
  white-space: nowrap !important;
  flex: 0 0 auto !important;
  /* O botão não pode crescer */
  width: auto !important;
  /* Garante que o botão use apenas o espaço do texto */
}

.tag-compacta:hover {
  background: #dbe2eb;
}

/* O card expande automaticamente e sem travamentos quando qualquer input interno recebe foco */
.material-card:focus-within {
  border-color: var(--primary-color, #007bff);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  /* Se você usa uma altura fixa ou min-height para expandir, coloque aqui também */
}

/* Garante que os elementos internos apareçam ao focar via CSS */
.material-card:focus-within .propriedades-container {
  display: flex !important;
  /* ou block/grid dependendo do seu layout */
}