/* ==========================================================================
   KRYO — "MONTE SEU SITE" (configurador ao vivo)
   Só carregado por monte-seu-site/index.html. Usa os tokens e utilitários de
   tokens.css/base.css já existentes — aqui só o que é específico da ferramenta.
   ========================================================================== */

@layer components {
  .builder-hero {
    padding-block: 6rem 3rem;
  }

  .builder-hero__eyebrow {
    display: inline-block;
    margin-bottom: 1.25rem;
    padding: 0.25rem 1rem;
    border: 1px solid var(--c-border-accent);
    background: var(--c-surface-panel);
    color: var(--c-accent);
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    border-radius: var(--r-full);
  }

  /* ---------- Galeria de templates ---------- */
  .template-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.5rem;
  }

  .template-card {
    background: var(--c-ground-3);
    border: 1px solid var(--c-border-hair);
    border-radius: var(--r-xl);
    box-shadow: var(--shadow-accent);
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }

  .template-card__mock {
    aspect-ratio: 4 / 3;
    padding: 0.9rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    background: linear-gradient(160deg, #f7f1e6, #efe5d3 65%, #c98a3c 145%);
  }
  .template-card__mock-bar {
    height: 0.55rem;
    border-radius: var(--r-full);
    background: rgb(43 39 31 / 0.14);
  }
  .template-card__mock-row {
    flex: 1;
    display: flex;
    gap: 0.6rem;
  }
  .template-card__mock-block {
    flex: 1;
    border-radius: var(--r-md);
    background: rgb(255 255 255 / 0.55);
  }
  .template-card__mock-dot {
    width: 0.4rem;
    height: 0.4rem;
    border-radius: 50%;
    background: rgb(43 39 31 / 0.22);
  }
  .template-card__mock-dots { display: flex; gap: 0.3rem; margin-bottom: 0.2rem; }

  .template-card__body {
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    flex: 1;
  }
  .template-card__title { font-weight: 600; font-size: 1.125rem; }
  .template-card__desc { color: var(--c-text-muted); font-size: 0.9rem; line-height: 1.6; flex: 1; }
  .template-card__tags { display: flex; flex-wrap: wrap; gap: 0.4rem; }
  .template-card__tag {
    font-size: 0.7rem;
    padding: 0.2rem 0.6rem;
    border-radius: var(--r-full);
    background: var(--c-surface);
    color: var(--c-text-muted);
  }

  /* ---------- Área de preview (moldura de "navegador") ---------- */
  .preview-shell {
    border: 1px solid var(--c-border-hair);
    border-radius: var(--r-xl);
    overflow: hidden;
    background: var(--c-ground-3);
    box-shadow: var(--shadow-accent-strong);
  }
  .preview-shell__bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.65rem 1rem;
    background: var(--c-ground-2);
    border-bottom: 1px solid var(--c-border-hair);
  }
  .preview-shell__dots { display: flex; gap: 0.4rem; }
  .preview-shell__dots span {
    width: 0.55rem; height: 0.55rem; border-radius: 50%;
    background: var(--c-border-soft);
  }
  .preview-shell__label {
    font-size: 0.75rem;
    color: var(--c-text-faint);
    flex: 1;
    text-align: center;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .device-toggle { display: flex; gap: 0.25rem; }
  .device-toggle button {
    padding: 0.35rem 0.7rem;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: var(--r-md);
    color: var(--c-text-muted);
  }
  .device-toggle button[aria-pressed="true"] {
    background: var(--c-ground-3);
    color: var(--c-text-strong);
    box-shadow: var(--shadow-accent);
  }

  .preview-shell__viewport {
    background: var(--c-ground-2);
    display: flex;
    justify-content: center;
    padding: 1.5rem;
    transition: padding 200ms var(--ease);
  }
  .preview-shell__frame-wrap {
    width: 100%;
    height: 62vh;
    min-height: 420px;
    max-height: 780px;
    border-radius: var(--r-md);
    overflow: hidden;
    box-shadow: var(--shadow-accent);
    transition: width 260ms var(--ease);
    background: #fff;
  }
  .preview-shell__viewport[data-device="mobile"] .preview-shell__frame-wrap {
    width: 375px;
  }
  .preview-shell__frame-wrap iframe {
    width: 100%;
    height: 100%;
    border: 0;
    display: block;
  }

  /* Placeholder "escolha um template acima": não tem conteúdo para
     mostrar, então não precisa reservar quase a tela toda (era 74vh —
     motivo do botão "Editar" aparecer muito abaixo, ver melhorias.md). */
  .preview-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    min-height: 260px;
    padding: 3rem 2rem;
    border: 1px dashed var(--c-border-soft);
    border-radius: var(--r-xl);
    color: var(--c-text-faint);
    text-align: center;
  }

  /* ---------- Painel de edição ---------- */
  .edit-panel {
    background: var(--c-ground-3);
    border: 1px solid var(--c-border-hair);
    border-radius: var(--r-xl);
    box-shadow: var(--shadow-accent);
    padding: 1.75rem;
    display: grid;
    gap: 1.5rem;
  }
  .edit-panel[hidden] { display: none; }

  .field-group { display: grid; gap: 0.5rem; }
  .field-group label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--c-text-body);
  }
  .field-group input[type="text"] {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--c-border-hair);
    border-radius: var(--r-md);
    background: var(--c-ground);
    color: var(--c-text-strong);
    font-size: 0.95rem;
  }
  .field-group input[type="text"]:focus-visible {
    outline: 2px solid var(--c-accent);
    outline-offset: 1px;
  }
  .field-group__hint { font-size: 0.78rem; color: var(--c-text-faint); }

  .upload-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
  }
  @media (max-width: 420px) {
    .upload-grid { grid-template-columns: 1fr; }
  }
  .upload-slot {
    border: 1px dashed var(--c-border-soft);
    border-radius: var(--r-lg);
    padding: 0.9rem;
    display: grid;
    gap: 0.6rem;
    text-align: center;
  }
  .upload-slot__preview {
    aspect-ratio: 4 / 5;
    border-radius: var(--r-md);
    background: var(--c-ground-2);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    color: var(--c-text-faint);
  }
  .upload-slot__preview img {
    width: 100%; height: 100%; object-fit: cover;
  }
  .upload-slot__preview svg { width: 28%; height: 28%; opacity: 0.5; }
  .upload-slot__label { font-size: 0.85rem; font-weight: 600; }
  .upload-slot input[type="file"] { font-size: 0.75rem; }
  .upload-slot__status { font-size: 0.75rem; color: var(--c-text-faint); min-height: 1em; }
  .upload-slot__status[data-state="ok"] { color: var(--c-success); }
  .upload-slot__status[data-state="erro"] { color: var(--c-danger); }

  .edit-panel__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: center;
    justify-content: space-between;
    padding-top: 0.5rem;
    border-top: 1px solid var(--c-border-hair);
  }

  /* ---------- CTA final ---------- */
  .builder-cta {
    background: var(--c-ground-2);
    border: 1px solid var(--c-border-hair);
    border-radius: var(--r-xl);
    padding: 2rem;
    text-align: center;
  }
  .builder-cta p { color: var(--c-text-muted); }

  .builder-note {
    font-size: 0.85rem;
    color: var(--c-text-faint);
    text-align: center;
    max-width: 42rem;
    margin-inline: auto;
  }

  /* ---------- Link "limpar dados" ---------- */
  .link-quiet {
    font-size: 0.8rem;
    color: var(--c-text-faint);
    text-decoration: underline;
    text-underline-offset: 3px;
  }

  /* Botão "Editar — usar meu nome e minhas fotos": texto comprido dentro
     de um pill rounded-full estourava as bordas no celular (melhorias.md).
     max-width + fonte/padding menores a partir de 480px resolvem sem
     mudar o texto. */
  #editToggleBtn {
    max-width: 100%;
  }
  @media (max-width: 480px) {
    #editToggleBtn {
      font-size: 0.85rem;
      padding: 0.85rem 1.25rem;
      line-height: 1.35;
    }
  }

  /* ---------- Seleção de sexo dos textos do preview ---------- */
  .gender-toggle {
    display: inline-flex;
    padding: 0.25rem;
    border-radius: var(--r-full);
    background: var(--c-ground-2);
    border: 1px solid var(--c-border-hair);
    gap: 0.25rem;
  }
  .gender-toggle input {
    position: absolute;
    opacity: 0;
    width: 1px;
    height: 1px;
  }
  .gender-toggle label {
    padding: 0.5rem 1.1rem;
    border-radius: var(--r-full);
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--c-text-muted);
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
  }
  .gender-toggle input:checked + label {
    background: var(--c-ground);
    color: var(--c-accent-strong);
    box-shadow: var(--shadow-elevation-sm, 0 1px 3px rgb(0 0 0 / 0.15));
  }
  .gender-toggle input:focus-visible + label {
    outline: 2px solid var(--c-accent);
    outline-offset: 2px;
  }

  /* ---------- Botão Salvar + confirmação ---------- */
  .save-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 1rem;
  }
  .save-btn {
    padding: 0.85rem 1.75rem;
    border-radius: var(--r-full);
    background: var(--c-accent);
    color: var(--c-on-accent, #fff);
    font-weight: 700;
    font-size: 0.95rem;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    transition: transform 0.15s ease, background 0.2s ease;
  }
  .save-btn:hover { background: var(--c-accent-strong); }
  .save-btn:active { transform: scale(0.97); }
  .save-btn:disabled { opacity: 0.5; cursor: default; transform: none; }

  .save-confirm {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--c-success);
    opacity: 0;
    transform: translateY(4px);
    transition: opacity 0.25s ease, transform 0.25s ease;
  }
  .save-confirm.is-visible {
    opacity: 1;
    transform: translateY(0);
  }

  .field-group__pending {
    font-size: 0.78rem;
    color: var(--c-accent-strong);
    font-weight: 600;
  }
  .field-group__pending[hidden] { display: none; }

  @media (max-width: 640px) {
    .preview-shell__viewport { padding: 0.75rem; }
    .preview-shell__frame-wrap { height: 60vh; min-height: 360px; }
    .preview-shell__viewport[data-device="mobile"] .preview-shell__frame-wrap { width: 100%; max-width: 375px; }
    .preview-empty { min-height: 200px; padding: 2rem 1.25rem; }
  }
}
