@layer reset, tokens, base, layout, components, utilities;

/* ---------------------------------------------------------------- reset */
@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  * { margin: 0; }
  html { -webkit-text-size-adjust: none; text-size-adjust: none; interpolate-size: allow-keywords; }
  body { min-height: 100dvh; -webkit-font-smoothing: antialiased; }
  img, picture, svg, video, canvas { display: block; max-width: 100%; }
  input, button, textarea, select { font: inherit; color: inherit; }
  p, h1, h2, h3, h4 { overflow-wrap: break-word; }
  h1, h2, h3, h4 { text-wrap: balance; }
  p, li { text-wrap: pretty; }
  button { cursor: pointer; }
  [hidden] { display: none !important; }
}

/* ---------------------------------------------------------------- tokens (cores do logo) */
@layer tokens {
  :root {
    color-scheme: light dark;

    /* marca: azul-marinho #1A3355 e dourado em degradê #B08045 → #E8C37C */
    --azul-900: oklch(0.24 0.06 258);
    --azul-800: oklch(0.31 0.07 258);   /* ≈ #1A3355 */
    --azul-600: oklch(0.45 0.09 258);
    --azul-100: oklch(0.95 0.015 258);
    --ouro-700: oklch(0.58 0.09 70);    /* ≈ #B08045 */
    --ouro-500: oklch(0.72 0.1 75);
    --ouro-300: oklch(0.85 0.09 82);    /* ≈ #E8C37C */
    --degrade-ouro: linear-gradient(135deg, var(--ouro-700), var(--ouro-300) 55%, var(--ouro-500));

    --fundo: light-dark(oklch(0.985 0.004 85), oklch(0.17 0.03 258));
    --fundo-2: light-dark(oklch(0.965 0.008 85), oklch(0.21 0.035 258));
    --superficie: light-dark(#fff, oklch(0.23 0.035 258));
    --texto: light-dark(var(--azul-900), oklch(0.95 0.01 258));
    --texto-2: light-dark(oklch(0.45 0.03 258), oklch(0.75 0.02 258));
    --borda: light-dark(oklch(0.9 0.01 258), oklch(0.32 0.03 258));
    --primaria: light-dark(var(--azul-800), var(--ouro-300));
    --primaria-texto: light-dark(#fff, var(--azul-900));
    --acento: light-dark(var(--ouro-700), var(--ouro-300));
    --whats: oklch(0.62 0.17 150);
    --perigo: oklch(0.58 0.2 25);
    --ok: oklch(0.6 0.15 150);

    /* estados das obras: validados para daltonismo (todos os pares, claro e escuro) com o
       validador da skill dataviz em 21/09/2026. Hex porque o mapa (MapLibre) lê os mesmos valores
       (ver CORES_STATUS em obras.js). O cinza é neutro de propósito: "sem informação". */
    --st-breve: light-dark(#e87ba4, #d55181);
    --st-lanc: light-dark(#eda100, #c98500);
    --st-obras: light-dark(#2a78d6, #3987e5);
    --st-pronto: #008300;
    --st-confirmar: #8a93a3;

    --fonte-titulo: 'Montserrat', system-ui, sans-serif;
    --fonte: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;

    --raio: 14px;
    --raio-g: 22px;
    --sombra: 0 1px 2px oklch(0 0 0 / .06), 0 8px 24px -8px oklch(0.24 0.06 258 / .18);
    --sombra-g: 0 24px 60px -20px oklch(0.24 0.06 258 / .35);
    --lateral: max(16px, (100vw - 1240px) / 2);
    --ease: cubic-bezier(.2, .8, .2, 1);
  }
  :root[data-tema="claro"] { color-scheme: light; }
  :root[data-tema="escuro"] { color-scheme: dark; }
}

/* ---------------------------------------------------------------- base */
@layer base {
  @view-transition { navigation: auto; }

  html { scroll-behavior: smooth; scroll-padding-top: 90px; }
  body {
    font-family: var(--fonte);
    font-size: 16px;
    line-height: 1.6;
    background: var(--fundo);
    color: var(--texto);
  }
  h1, h2, h3 { font-family: var(--fonte-titulo); line-height: 1.12; letter-spacing: -0.02em; }
  h1 { font-size: clamp(2.1rem, 1.3rem + 3.6vw, 4rem); font-weight: 800; }
  h2 { font-size: clamp(1.6rem, 1.2rem + 1.6vw, 2.4rem); font-weight: 700; }
  h3 { font-size: 1.15rem; font-weight: 700; }
  a { color: inherit; text-underline-offset: 3px; }
  ::selection { background: var(--ouro-300); color: var(--azul-900); }
  :focus-visible { outline: 3px solid var(--ouro-500); outline-offset: 2px; border-radius: 6px; }
  input, select, textarea { accent-color: var(--acento); }

  @media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
    @view-transition { navigation: none; }
  }
}

/* ---------------------------------------------------------------- layout */
@layer layout {
  .conteiner { padding-inline: var(--lateral); }
  section { padding-block: clamp(56px, 8vw, 110px); }

  /* cabeçalho de vidro que encolhe com a rolagem (scroll-driven, sem esconder conteúdo) */
  .topo {
    position: sticky; top: 0; z-index: 50;
    display: flex; align-items: center; gap: 24px;
    padding: 18px var(--lateral);
    background: color-mix(in oklch, var(--fundo) 78%, transparent);
    backdrop-filter: blur(16px) saturate(1.6);
    border-bottom: 1px solid transparent;
    view-transition-name: topo;
    animation: topo-encolhe linear both;
    animation-timeline: scroll(root);
    animation-range: 0 120px;

    .marca { display: flex; align-items: center; gap: 10px; text-decoration: none; margin-right: auto; }
    .marca img { height: 42px; width: auto; }
    .marca span { font-family: var(--fonte-titulo); font-weight: 800; letter-spacing: .04em; font-size: 1.15rem; line-height: 1; }
    .marca small { display: block; font-size: .62rem; letter-spacing: .32em; color: var(--acento); font-weight: 700; margin-top: 3px; }

    nav { display: flex; gap: 4px; position: relative; isolation: isolate; }
    /* pílula que desliza até a aba da seção visível */
    .indicador { position: absolute; left: 0; top: 0; height: 100%; width: var(--w, 0); translate: var(--x, 0) 0; opacity: 0;
      border-radius: 999px; background: var(--fundo-2); box-shadow: inset 0 -2px 0 var(--ouro-500); z-index: -1;
      transition: translate .35s var(--ease), width .35s var(--ease), opacity .2s; }
    nav a[aria-current] { color: var(--texto); }
    nav a {
      text-decoration: none; padding: 8px 14px; border-radius: 999px; font-weight: 500; font-size: .95rem; color: var(--texto-2);
      transition: background .2s, color .2s;
      &:hover { background: var(--fundo-2); color: var(--texto); }
    }
  }
  @keyframes topo-encolhe {
    to { padding-block: 10px; border-bottom-color: var(--borda); }
  }

  #menu-movel {
    inset: 0 0 auto auto; margin: 12px; width: min(320px, calc(100vw - 24px));
    border: 1px solid var(--borda); border-radius: var(--raio-g); padding: 16px; background: var(--superficie); color: var(--texto);
    box-shadow: var(--sombra-g);
    nav { display: grid; gap: 4px; }
    nav a { padding: 12px 14px; border-radius: 10px; text-decoration: none; font-weight: 600; }
    nav a:hover { background: var(--fundo-2); }
    &::backdrop { background: oklch(0 0 0 / .35); backdrop-filter: blur(3px); }
    opacity: 0; translate: 0 -8px;
    transition: opacity .2s, translate .25s var(--ease), display .25s allow-discrete, overlay .25s allow-discrete;
    &:popover-open { opacity: 1; translate: 0 0; @starting-style { opacity: 0; translate: 0 -8px; } }
  }

  .rodape {
    background: var(--azul-900); color: oklch(0.9 0.01 258);
    padding: 64px var(--lateral) 32px;
    display: grid; gap: 40px; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    a { color: inherit; text-decoration: none; opacity: .85; &:hover { opacity: 1; color: var(--ouro-300); } }
    h4 { font-family: var(--fonte-titulo); color: var(--ouro-300); font-size: .8rem; letter-spacing: .18em; text-transform: uppercase; margin-bottom: 14px; }
    ul { list-style: none; padding: 0; display: grid; gap: 8px; }
    .legal { grid-column: 1 / -1; border-top: 1px solid oklch(1 0 0 / .12); padding-top: 24px; font-size: .85rem; opacity: .7; }
    .assinatura { grid-column: 1 / -1; text-align: center; font-size: .8rem; opacity: .6; margin-top: -16px;
      a { font-weight: 700; opacity: 1; } }
  }
}

/* ---------------------------------------------------------------- componentes */
@layer components {
  .btn {
    --bg: var(--primaria); --fg: var(--primaria-texto);
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 12px 22px; border-radius: 999px; border: 0; font-weight: 600; text-decoration: none; white-space: nowrap;
    background: var(--bg); color: var(--fg);
    transition: translate .2s var(--ease), box-shadow .2s, filter .2s;
    &:hover { translate: 0 -1px; box-shadow: var(--sombra); filter: brightness(1.06); }
    &:active { translate: 0 1px; }
    &:disabled { opacity: .55; cursor: progress; translate: none; }
    svg { width: 18px; height: 18px; flex: none; }
  }
  .btn-ouro { --bg: var(--degrade-ouro); --fg: var(--azul-900); background: var(--degrade-ouro); }
  .btn-whats { --bg: var(--whats); --fg: #fff; }
  .btn-leve { --bg: var(--fundo-2); --fg: var(--texto); }
  .btn-contorno { --bg: transparent; --fg: var(--texto); box-shadow: inset 0 0 0 1.5px var(--borda); }
  .btn-icone { padding: 10px; border-radius: 12px; aspect-ratio: 1; }
  .btn-p { padding: 8px 14px; font-size: .9rem; }

  .etiqueta {
    display: inline-flex; align-items: center; gap: 6px;
    font-size: .72rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
    color: var(--acento);
    &::before { content: ''; width: 22px; height: 2px; background: var(--degrade-ouro); border-radius: 2px; }
  }

  .chip {
    display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px;
    font-size: .78rem; font-weight: 600; background: var(--fundo-2); color: var(--texto-2); white-space: nowrap;
  }
  .status {
    --c: var(--st-confirmar);
    display: inline-flex; align-items: center; gap: 6px; font-size: .78rem; font-weight: 600; white-space: nowrap;
    padding: 3px 10px 3px 8px; border-radius: 999px;
    background: color-mix(in oklch, var(--c) 16%, transparent); color: light-dark(color-mix(in oklch, var(--c) 75%, black), color-mix(in oklch, var(--c) 60%, white));
    &::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--c); }
    &[data-s="Breve lançamento"] { --c: var(--st-breve); &::before { border-radius: 2px; rotate: 45deg; } }
    &[data-s="Lançamento"] { --c: var(--st-lanc); &::before { border-radius: 2px; } }
    &[data-s="Em obras"] { --c: var(--st-obras); &::before { clip-path: polygon(50% 0, 100% 100%, 0 100%); border-radius: 0; } }
    &[data-s="Pronto"] { --c: var(--st-pronto); }
  }
  .selo-mcmv {
    font-size: .7rem; font-weight: 800; letter-spacing: .06em; padding: 3px 8px; border-radius: 6px;
    background: var(--degrade-ouro); color: var(--azul-900);
  }

  /* cartão de imóvel/obra com container query */
  .cartao {
    container-type: inline-size;
    background: var(--superficie); border: 1px solid var(--borda); border-radius: var(--raio-g);
    overflow: hidden; display: grid; grid-template-rows: auto 1fr;
    transition: translate .3s var(--ease), box-shadow .3s;
    &:hover { translate: 0 -4px; box-shadow: var(--sombra-g); }
    &:has(a:focus-visible) { outline: 3px solid var(--ouro-500); }
    .foto { aspect-ratio: 4 / 3; background: var(--fundo-2); position: relative; overflow: hidden; }
    .foto img { width: 100%; height: 100%; object-fit: cover; transition: scale .6s var(--ease); }
    &:hover .foto img { scale: 1.05; }
    .foto .selos { position: absolute; inset: 12px 12px auto; display: flex; gap: 6px; flex-wrap: wrap; }
    .foto .status { background: color-mix(in oklch, var(--superficie) 88%, transparent); backdrop-filter: blur(6px); }
    .corpo { padding: 18px 20px 20px; display: grid; gap: 8px; align-content: start; }
    .incorp { font-size: .78rem; font-weight: 600; color: var(--acento); text-transform: uppercase; letter-spacing: .06em; }
    h3 a { text-decoration: none; &::after { content: ''; position: absolute; inset: 0; } }
    .local { color: var(--texto-2); font-size: .92rem; }
    .fatos { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; .chip { white-space: normal; } }
    .preco { font-family: var(--fonte-titulo); font-weight: 700; font-size: 1.15rem; margin-top: 6px; }
    .preco small { font-family: var(--fonte); font-weight: 500; font-size: .78rem; color: var(--texto-2); display: block; }
    position: relative;
  }
  @container (min-width: 520px) {
    .cartao-horizontal { grid-template-columns: 42% 1fr; grid-template-rows: none; }
    .cartao-horizontal .foto { aspect-ratio: auto; height: 100%; }
  }
  .grade-cartoes { display: grid; gap: 24px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 290px), 1fr)); }

  /* formulários */
  .campo {
    display: grid; gap: 6px;
    label { font-size: .85rem; font-weight: 600; color: var(--texto-2); }
    input, select, textarea {
      width: 100%; padding: 12px 14px; border-radius: 12px; border: 1.5px solid var(--borda); background: var(--superficie);
      transition: border-color .2s, box-shadow .2s;
      &:focus { outline: none; border-color: var(--ouro-500); box-shadow: 0 0 0 4px color-mix(in oklch, var(--ouro-500) 22%, transparent); }
      &:user-invalid { border-color: var(--perigo); }
    }
    textarea { field-sizing: content; min-height: 4lh; max-height: 12lh; resize: vertical; }
  }
  .aceite { display: flex; gap: 10px; align-items: flex-start; font-size: .85rem; color: var(--texto-2); input { margin-top: 4px; } }

  dialog.modal {
    border: 0; padding: 0; border-radius: var(--raio-g); width: min(480px, calc(100vw - 24px)); max-height: calc(100dvh - 24px);
    background: var(--superficie); color: var(--texto); box-shadow: var(--sombra-g);
    &::backdrop { background: oklch(0.2 0.05 258 / .5); backdrop-filter: blur(4px); }
    .cab { padding: 22px 24px 0; display: flex; justify-content: space-between; align-items: start; gap: 12px; }
    form { padding: 18px 24px 24px; display: grid; gap: 14px; }
    opacity: 0; scale: .96;
    transition: opacity .2s, scale .25s var(--ease), display .25s allow-discrete, overlay .25s allow-discrete;
    &[open] { opacity: 1; scale: 1; @starting-style { opacity: 0; scale: .96; } }
  }

  .aviso { padding: 12px 14px; border-radius: 12px; font-size: .9rem; background: var(--fundo-2); }
  .aviso.ok { background: color-mix(in oklch, var(--ok) 15%, transparent); }
  .aviso.erro { background: color-mix(in oklch, var(--perigo) 14%, transparent); }

  .esqueleto { background: linear-gradient(90deg, var(--fundo-2), var(--borda), var(--fundo-2)); background-size: 200% 100%; animation: brilho 1.4s infinite; border-radius: 10px; }
  @keyframes brilho { to { background-position: -200% 0; } }

  /* botão flutuante do WhatsApp + chat */
  .flutuantes { position: fixed; right: 18px; bottom: 18px; z-index: 60; display: grid; gap: 12px; justify-items: end; }
  .flutuante {
    background: var(--bg); color: var(--fg);
    width: 58px; height: 58px; border-radius: 50%; border: 0; display: grid; place-items: center; box-shadow: var(--sombra-g);
    svg { width: 28px; height: 28px; }
  }
}

/* ---------------------------------------------------------------- utilitários */
@layer utilities {
  /* aqui e não no layout: .btn (components) viria depois e ganharia do display */
  .barra-abas { display: none; }
  @media (max-width: 900px) {
    .topo > nav, .btn-whats-topo { display: none; }
    .barra-abas {
      display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; inset: auto 0 0 0; z-index: 55;
      padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); background: color-mix(in oklch, var(--superficie) 92%, transparent);
      backdrop-filter: blur(14px) saturate(1.5); border-top: 1px solid var(--borda);
      a { display: grid; justify-items: center; gap: 2px; padding: 6px 2px; text-decoration: none; font-size: .68rem; font-weight: 600;
        color: var(--texto-2); border-radius: 12px; transition: color .2s, background .2s; }
      svg { width: 22px; height: 22px; }
      a[aria-current] { color: var(--acento); background: color-mix(in oklch, var(--ouro-300) 16%, transparent); }
    }
    body { padding-bottom: 72px; }
    .flutuantes { bottom: 84px; }
  }

  .sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .texto-2 { color: var(--texto-2); }
  .centro { text-align: center; }
  .ouro-texto { background: var(--degrade-ouro); -webkit-background-clip: text; background-clip: text; color: transparent; }
}
