/* =====================================================================
   base.css — estilos partilhados por TODAS as páginas do site
   Ordem de carregamento: base.css → header_footer.css → css da página
   Conteúdo: variáveis, acessibilidade, botões/formulários base, modais,
   banner de cookies, estados de carregamento e animações.
   ===================================================================== */

:root {
  /* Cores da marca (mantidas iguais às do site original) */
  --gold: #C5B358;
  --gold-dark: #A08D47;
  --gold-header: #c9b227;
  --gold-text: #7A6A1E; /* dourado escurecido para TEXTO sobre fundo claro (contraste 5,4:1) */
  --yellow: #facc15;
  --navy: #1e2a3a;
  --navy-footer: #243447;
  --blue: #0052cc;
  --ink: #111827;
  --ink-soft: #374151;
  --muted: #6b7280;

  /* Estados */
  --success: #28a745;
  --danger: #dc2626;

  /* Altura do header fixo (usada pelo padding-top do body nas páginas internas) */
  --header-h: 93px;

  /* Movimento */
  --ease: cubic-bezier(0.22, 0.8, 0.26, 1);
  --dur: 0.7s;
}

@media (max-width: 768px) {
  :root {
    --header-h: 74px;
  }
}

@media (max-width: 480px) {
  :root {
    --header-h: 69px;
  }
}

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: 96px; /* header fixo não tapa âncoras */
}

/* Bloqueio de scroll (menu mobile / modais) — gerido por main.js */
html.no-scroll,
html.no-scroll body {
  overflow: hidden;
}

[hidden] {
  display: none !important;
}

img,
svg,
video {
  max-width: 100%;
}

/* Evita imagens deformadas quando têm width/height no HTML (reserva espaço = sem saltos de layout) */
img {
  height: auto;
}

/* ---------------------------------------------------------------------
   Acessibilidade
   --------------------------------------------------------------------- */
.sr-only {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: fixed;
  top: 8px;
  left: 8px;
  z-index: 100000;
  padding: 0.7rem 1.1rem;
  background: var(--gold);
  color: var(--navy);
  font: 600 0.95rem/1.2 'Montserrat', system-ui, sans-serif;
  border-radius: 8px;
  text-decoration: none;
  transform: translateY(-200%);
  transition: transform 0.2s var(--ease);
}

.skip-link:focus {
  transform: translateY(0);
}

:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline-offset: 0;
  box-shadow: 0 0 0 3px rgba(197, 179, 88, 0.35);
}

/* Campo-armadilha anti-spam (invisível para pessoas) */
.hp-field {
  position: absolute !important;
  left: -9999px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

/* ---------------------------------------------------------------------
   Controlos de formulário — melhor toque no telemóvel
   --------------------------------------------------------------------- */
button,
[type='submit'] {
  font-family: inherit;
}

button:disabled,
[type='submit']:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

@media (max-width: 768px) {
  /* 16px evita o zoom automático do iOS ao focar num campo */
  input,
  select,
  textarea {
    font-size: 16px !important;
  }
}

/* Mensagem de estado de formulários (substitui os alert()) */
.form-status {
  display: none;
  margin-top: 1rem;
  padding: 0.8rem 1rem;
  border-radius: 8px;
  font-size: 0.92rem;
  line-height: 1.45;
  text-align: left;
}

.form-status.is-visible {
  display: block;
  animation: fade-up 0.35s var(--ease) both;
}

.form-status--success {
  background: #ecfdf3;
  color: #067647;
  border: 1px solid #abefc6;
}

.form-status--error {
  background: #fef3f2;
  color: #b42318;
  border: 1px solid #fecdca;
}

.form-status--loading {
  background: #f3f4f6;
  color: #374151;
  border: 1px solid #e5e7eb;
}

/* ---------------------------------------------------------------------
   Modais (home, comprar, vender, sobre nós) — controlados por main.js
   --------------------------------------------------------------------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.7);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s ease;
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modal-container {
  position: relative;
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  max-height: 90dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 2rem;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  transform: translateY(18px) scale(0.97);
  transition: transform 0.3s var(--ease);
}

.modal-overlay.active .modal-container {
  transform: none;
}

.modal-close {
  position: absolute;
  top: 8px;
  right: 10px;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  line-height: 1;
  color: #666;
  background: none;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  transition: color 0.2s, background 0.2s;
}

.modal-close:hover {
  color: #111;
  background: #f3f4f6;
}

.modal-header {
  text-align: center;
  margin-bottom: 1.5rem;
  padding: 0 1.5rem;
}

.modal-header h2 {
  font-size: 1.5rem;
  color: #2a2a2a;
  margin: 0 0 0.5rem;
}

.modal-header p {
  color: #666;
  font-size: 0.95rem;
  margin: 0;
}

.modal-form .form-row {
  margin-bottom: 1rem;
}

.modal-form .form-row.two-cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.modal-form .form-group {
  display: flex;
  flex-direction: column;
  margin-bottom: 1rem;
}

.modal-form .form-row .form-group {
  margin-bottom: 0;
}

.modal-form .form-group label,
.modal-form label {
  display: block;
  margin-bottom: 0.45rem;
  font-size: 0.9rem;
  font-weight: 600;
  color: #374151;
}

.modal-form input,
.modal-form select,
.modal-form textarea {
  width: 100%;
  min-width: 0;
  padding: 0.75rem 1rem;
  font-size: 1rem;
  font-family: inherit;
  border: 2px solid #e5e7eb;
  border-radius: 8px;
  background: #fff;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.modal-form input:focus,
.modal-form select:focus,
.modal-form textarea:focus {
  outline: none;
  border-color: var(--gold);
}

.modal-form .form-actions {
  margin-top: 1.5rem;
}

.modal-form .btn-submit,
.btn-submit {
  width: 100%;
  padding: 1rem;
  font-size: 1rem;
  font-weight: 700;
  color: var(--navy);
  background: var(--gold);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s, transform 0.2s, box-shadow 0.2s;
}

.modal-form .btn-submit:hover:not(:disabled),
.btn-submit:hover:not(:disabled) {
  background: var(--gold-dark);
  transform: translateY(-1px);
  box-shadow: 0 8px 18px rgba(160, 141, 71, 0.35);
}

.form-success {
  text-align: center;
  padding: 2rem 1rem;
}

.form-success .success-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  color: #fff;
  background: var(--success);
  border-radius: 50%;
  animation: pop-in 0.5s var(--ease) both;
}

.form-success h3 {
  margin: 0 0 0.5rem;
  color: var(--success);
}

.form-success p {
  margin: 0 0 1.5rem;
  color: #666;
}

.btn-close-success {
  padding: 0.8rem 2rem;
  font-weight: 600;
  color: var(--navy);
  background: var(--gold);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-close-success:hover {
  background: var(--gold-dark);
}

@media (max-width: 600px) {
  .modal-overlay {
    padding: 12px;
    align-items: flex-end; /* "bottom sheet" no telemóvel */
  }

  .modal-container {
    padding: 1.5rem 1.25rem;
    max-height: 92dvh;
    border-radius: 18px 18px 12px 12px;
  }

  .modal-form .form-row.two-cols {
    grid-template-columns: 1fr;
  }
}

/* ---------------------------------------------------------------------
   Estados de carregamento
   --------------------------------------------------------------------- */
.loading-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem;
  color: #666;
}

.loading-spinner {
  width: 40px;
  height: 40px;
  margin-bottom: 1rem;
  border: 3px solid #eee;
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.no-results,
.state-message {
  text-align: center;
  padding: 3rem 1rem;
  color: #666;
}

.no-results h3,
.state-message h3 {
  margin: 0 0 0.5rem;
  color: #333;
}

.state-message a {
  color: var(--gold-text);
  font-weight: 600;
}

/* Skeleton (cartões a carregar) — anima só transform (rápido, sem repaint) */
.skeleton-card {
  position: relative;
  overflow: hidden;
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 10px 25px rgba(15, 23, 42, 0.08);
  min-height: 330px;
}

.skeleton-card::before {
  content: '';
  display: block;
  height: 200px;
  background: #e5e7eb;
}

.skeleton-card::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(100deg, transparent 20%, rgba(255, 255, 255, 0.65) 50%, transparent 80%);
  transform: translateX(-100%);
  animation: shimmer 1.4s infinite;
}

.skeleton-card span {
  display: block;
  height: 14px;
  margin: 18px 20px 0;
  background: #e5e7eb;
  border-radius: 6px;
}

.skeleton-card span:nth-child(2) {
  width: 55%;
}

.skeleton-card span:nth-child(3) {
  width: 75%;
}

/* ---------------------------------------------------------------------
   Banner de cookies (injetado por main.js em todas as páginas)
   --------------------------------------------------------------------- */
.cookie-popup {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 9998;
  display: none;
  justify-content: center;
  padding: 0 0.75rem;
}

.cookie-popup.is-open {
  display: flex;
}

/* Com o menu, a gaveta de filtros ou uma janela aberta, o aviso não tapa botões (volta ao fechar) */
html.no-scroll .cookie-popup {
  visibility: hidden;
}

.cookie-popup-inner {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto 0.75rem;
  padding: 0.9rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1.25rem;
  font-size: 0.9rem;
  color: #111827;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.25);
  animation: fade-up 0.5s var(--ease) both;
}

.cookie-popup-inner p {
  flex: 1;
  margin: 0;
  line-height: 1.4;
}

.cookie-popup-inner a {
  color: #111827;
  text-decoration: underline;
}

.cookie-popup-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: flex-end;
}

.cookie-popup-buttons button {
  min-height: 44px;
  padding: 0.55rem 1.2rem;
  font-size: 0.85rem;
  font-weight: 600;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.2s;
}

#cookie-accept {
  color: #fff;
  background: #111827;
}

#cookie-accept:hover {
  background: #434752;
}

#cookie-reject {
  color: #111827;
  background: #f3f4f6;
}

#cookie-reject:hover {
  background: #e5e7eb;
}

@media (max-width: 768px) {
  .cookie-popup-inner {
    flex-direction: column;
    align-items: stretch;
    gap: 0.6rem;
    margin-bottom: 0.5rem;
    padding: 0.85rem 1rem;
    font-size: 0.82rem;
  }

  .cookie-popup-buttons {
    justify-content: stretch;
  }

  .cookie-popup-buttons button {
    flex: 1;
  }
}

/* ---------------------------------------------------------------------
   Animações
   - Só usam transform e opacity (60fps, sem layout)
   - O conteúdo só fica escondido quando o JS está ativo (html.js)
   --------------------------------------------------------------------- */
@keyframes fade-up {
  from {
    opacity: 0;
    transform: translate3d(0, 18px, 0);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes pop-in {
  from {
    opacity: 0;
    transform: scale(0.6);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

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

@keyframes shimmer {
  to {
    transform: translateX(100%);
  }
}

/* Os elementos que entram pelo lado não podem criar scroll horizontal enquanto estão deslocados */
main {
  overflow-x: clip;
}

.js .reveal {
  opacity: 0;
  transform: translate3d(0, 26px, 0);
  transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease);
  will-change: opacity, transform;
}

.js .reveal--left {
  transform: translate3d(-28px, 0, 0);
}

.js .reveal--right {
  transform: translate3d(28px, 0, 0);
}

.js .reveal--zoom {
  transform: scale(0.94);
}

.js .reveal.is-visible {
  opacity: 1;
  transform: none;
  will-change: auto;
}

/* Quem prefere menos movimento: sem animações */
@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    transition-delay: 0ms !important;
  }

  .js .reveal {
    opacity: 1;
    transform: none;
  }
}
