/* Systemfy Forms — visual inspirado nas Human Interface Guidelines da Apple:
   clareza, deferência ao conteúdo, profundidade sutil, cantos arredondados, tipografia do sistema,
   alvos de toque >= 44px e modo escuro. Cores da marca extraídas da logo: roxo #3C0A70 e laranja #F66007. */
:root {
    --purple: #3c0a70;
    --orange: #f66007;
    --bg: #f5f5f7;
    --surface: #ffffff;
    --surface-2: #fafafc;
    --text: #1d1d1f;
    --muted: #6e6e73;
    --sep: rgba(60, 60, 67, .14);
    --field: #ffffff;
    --primary: var(--purple);
    --on-primary: #ffffff;
    --accent: var(--orange);
    --danger: #c4251c;
    --ok: #1f7a3e;
    --radius: 14px;
    --shadow: 0 1px 2px rgba(0,0,0,.04), 0 6px 20px rgba(0,0,0,.05);
    --side-bg: var(--purple);
    --side-w: 256px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f0a18;
    --surface: #1b1527;
    --surface-2: #221b30;
    --text: #f5f5f7;
    --muted: #a1a1aa;
    --sep: rgba(255,255,255,.12);
    --field: #241d33;
    --primary: #7c3aed;
    --danger: #ff6b61;
    --ok: #52d273;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 20px rgba(0,0,0,.35);
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI Variable", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px; line-height: 1.47; letter-spacing: -0.011em; -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 2rem; line-height: 1.15; letter-spacing: -0.03em; font-weight: 700; margin: 0 0 .5rem; }
h2 { font-size: 1.2rem; letter-spacing: -0.02em; font-weight: 600; margin: 0 0 .6rem; }
p { margin: 0 0 .75rem; }
.muted { color: var(--muted); font-size: .92rem; }
.mono, code { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: .88em; }
code { background: var(--surface-2); padding: 1px 6px; border-radius: 6px; }
.container { max-width: 1440px; margin: 0 auto; padding: 32px clamp(16px, 3vw, 44px) 8px; }

/* ===== Estrutura com menu lateral ===== */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--side-w); z-index: 30;
  display: flex; flex-direction: column; padding: 18px 12px 14px;
  background: var(--side-bg); color: #fff;
}
.side-brand { display: block; padding: 4px 10px 18px; }
.logo { height: 36px; width: auto; display: block; }
.side-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.side-label { font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: rgba(255,255,255,.6); padding: 14px 12px 6px; }
.side-link, .side-foot button {
  display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 8px 12px; border-radius: 10px;
  color: #fff; font: inherit; font-weight: 500; text-decoration: none; background: none; border: 0; width: 100%; cursor: pointer; text-align: left;
}
.side-link:hover, .side-foot button:hover { background: rgba(255,255,255,.08); text-decoration: none; }
.side-link.active { background: rgba(255,255,255,.16); color: #fff; font-weight: 600; }
.side-link.active svg { color: #fff; }
.side-link svg, .side-foot svg { width: 22px; height: 22px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; color: rgba(255,255,255,.75); }
.side-foot { border-top: 1px solid rgba(255,255,255,.15); padding-top: 10px; margin-top: 8px; }
.side-user { padding: 4px 12px 8px; font-size: .85rem; color: rgba(255,255,255,.7); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.shell-main { flex: 1; min-width: 0; margin-left: var(--side-w); display: flex; flex-direction: column; min-height: 100vh; }
.shell-main .container { width: 100%; flex: 1; margin: 0; }
.mobilebar { display: none; }
.scrim { display: none; }

@media (max-width: 900px) {
  .sidebar { transform: translateX(-102%); transition: transform .25s ease; width: min(82vw, 300px); box-shadow: var(--shadow); }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .scrim { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 25; }
  .shell-main { margin-left: 0; }
  .mobilebar {
    display: flex; align-items: center; gap: 12px; position: sticky; top: 0; z-index: 20; padding: 8px 14px;
    background: var(--side-bg);
  }
  .menu-btn { width: 44px; height: 44px; border: 0; background: none; color: #fff; border-radius: 10px; cursor: pointer; display: grid; place-items: center; }
  .menu-btn svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
  .container { padding: 18px 16px 8px; }
  h1 { font-size: 1.7rem; }
}

/* ===== Autenticação (sem menu) ===== */
.auth-wrap { max-width: 420px; margin: 0 auto; padding: 56px 20px 8px; }
.auth-logo { height: 56px; width: auto; display: block; margin: 0 auto 26px; }

/* ===== Rodapé da marca ===== */
.brand-footer { text-align: center; color: var(--muted); font-size: .85rem; padding: 28px 16px 32px; }
.brand-footer a { color: var(--primary); font-weight: 600; }
.brand-footer a:hover { color: var(--accent); text-decoration: none; }
.brand-footer .heart { color: var(--accent); }

/* ===== Componentes ===== */
.card { background: var(--surface); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; box-shadow: var(--shadow); border: 1px solid var(--sep); }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.row.between { justify-content: space-between; }
.page-head { margin-bottom: 16px; }
.page-head h1 { margin: 0; }
.grow { flex: 1 1 200px; }
.stack > * + * { margin-top: 14px; }
.inline { display: inline; margin: 0; }

label { display: block; font-weight: 600; font-size: .92rem; margin-bottom: 6px; }
input[type=text], input[type=email], input[type=password], input[type=tel], input[type=number], input[type=date], input[type=url], input[type=search], input[type=color], select, textarea {
  width: 100%; min-height: 46px; padding: 10px 14px; font: inherit; font-size: 16px; letter-spacing: inherit;
  border: 1px solid var(--sep); border-radius: 12px; background: var(--field); color: var(--text); transition: box-shadow .15s, border-color .15s;
}
input[type=color] { padding: 4px; }
textarea { min-height: 100px; resize: vertical; }
input::placeholder, textarea::placeholder { color: color-mix(in srgb, var(--muted) 75%, transparent); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 28%, transparent); }
.field { margin-bottom: 18px; }
.field.has-error input, .field.has-error select, .field.has-error textarea { border-color: var(--danger); }
.error { color: var(--danger); font-size: .88rem; margin-top: 5px; }
.help { color: var(--muted); font-size: .84rem; margin-top: 5px; }
.req { color: var(--danger); }
.choice { display: flex; align-items: center; gap: 12px; min-height: 46px; font-weight: 400; margin: 0; font-size: 1rem; }
.choice input { width: 22px; height: 22px; flex: none; accent-color: var(--primary); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 46px; padding: 8px 22px;
  border-radius: 12px; border: 0; background: var(--primary); color: var(--on-primary);
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; transition: filter .15s, transform .05s;
}
.btn:hover { filter: brightness(1.08); text-decoration: none; }
.btn:active { transform: scale(.985); }
.btn.secondary { background: color-mix(in srgb, var(--primary) 11%, transparent); color: var(--primary); }
.btn.danger { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }
.btn.small { min-height: 36px; padding: 4px 14px; font-size: .9rem; border-radius: 10px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn:focus-visible, .side-link:focus-visible, .menu-btn:focus-visible { outline: none; box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 40%, transparent); }

.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .78rem; font-weight: 600; background: color-mix(in srgb, var(--muted) 18%, transparent); color: var(--muted); }
.badge.ok { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); }
.alert { padding: 13px 16px; border-radius: 12px; margin-bottom: 16px; font-size: .95rem; }
.alert.error { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }
.alert.ok { background: color-mix(in srgb, var(--ok) 13%, transparent); color: var(--ok); }
.alert.ok strong { color: var(--text); }
pre { background: #14101d; color: #ece8f5; padding: 14px; border-radius: 12px; overflow-x: auto; font-size: .84rem; line-height: 1.5; }
.linkbox { display: flex; gap: 8px; flex-wrap: wrap; }
.linkbox input { flex: 1 1 240px; }
/* Link + botão na mesma caixa */
.utm-links { margin-top: 12px; }
.utm-links > summary { cursor: pointer; font-weight: 600; color: var(--primary); }
.utm-row { display: grid; grid-template-columns: 130px minmax(0, 1fr); gap: 10px; align-items: center; margin-top: 8px; }
@media (max-width: 640px) { .utm-row { grid-template-columns: 1fr; gap: 4px; } }
.linkbox.joined { gap: 4px; flex-wrap: nowrap; align-items: center; padding: 4px 4px 4px 0; border: 1px solid var(--sep); border-radius: 12px; background: var(--field); }
.linkbox.joined input { flex: 1 1 auto; min-width: 0; min-height: 36px; border: 0; background: transparent; text-overflow: ellipsis; }
.linkbox.joined input:focus { box-shadow: none; }
.linkbox.joined .btn { flex: none; }

/* Barra de busca e filtros em uma linha só */
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 16px; }
.filters input[type=search] { flex: 2 1 280px; width: auto; }
.filters select { flex: 1 1 180px; width: auto; }
.filters .btn { flex: none; }
/* Janela de confirmação (elemento <dialog>) */
.confirm-dialog { width: min(92vw, 460px); padding: 24px; border: 1px solid var(--sep); border-radius: var(--radius); background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.confirm-dialog::backdrop { background: rgba(0,0,0,.35); }
.confirm-dialog h2 { margin-top: 0; }
/* Relatórios: números principais em cards lado a lado */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 16px; }
.stats .card { margin-bottom: 0; }
.stat-value { font-size: 1.9rem; font-weight: 700; line-height: 1.1; color: var(--primary); }
.stat-label { margin-top: 6px; font-size: .88rem; color: var(--muted); }
.card-title { font-size: .8rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin: 0 0 14px; }
.filter-date { display: flex; align-items: center; gap: 8px; margin: 0; font-weight: 400; color: var(--muted); }
.filter-date input { width: auto; }

/* Menu de três pontinhos */
.menu { position: relative; flex: none; }
.menu > summary { list-style: none; width: 36px; padding: 0; }
.menu > summary::-webkit-details-marker { display: none; }
.menu-list { position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; min-width: 190px; padding: 6px;
  background: var(--surface); border: 1px solid var(--sep); border-radius: 12px; box-shadow: var(--shadow); }
.menu-list form { margin: 0; }
.menu-list a, .menu-list button { display: block; width: 100%; padding: 10px 12px; border: 0; border-radius: 8px; background: none;
  color: var(--text); font: inherit; font-size: .95rem; text-align: left; cursor: pointer; text-decoration: none; }
.menu-list a:hover, .menu-list button:hover { background: color-mix(in srgb, var(--text) 6%, transparent); text-decoration: none; }
.menu-list .danger { color: var(--danger); }

/* Tabelas: lista agrupada, vira cartões no celular */
table { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); border: 1px solid var(--sep); }
.card table { box-shadow: none; border: 0; border-radius: 0; background: none; }
th, td { text-align: left; padding: 13px 16px; border-bottom: 1px solid var(--sep); vertical-align: middle; }
tr:last-child td, tr:last-child th { border-bottom: 0; }

table.tenants { overflow: visible; }
table.tenants thead th:first-child { border-top-left-radius: var(--radius); }
table.tenants thead th:last-child { border-top-right-radius: var(--radius); }
th { font-size: .76rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; background: var(--surface-2); }
@media (max-width: 640px) {
  table.responsive { background: none; box-shadow: none; border: 0; }
  table.responsive thead { display: none; }
  table.responsive tr { display: block; background: var(--surface); border: 1px solid var(--sep); border-radius: var(--radius); margin-bottom: 12px; padding: 6px 14px; box-shadow: var(--shadow); }
  table.responsive td { display: flex; justify-content: space-between; align-items: center; gap: 12px; border: 0; padding: 7px 0; }
  table.responsive td::before { content: attr(data-label); font-weight: 600; color: var(--muted); font-size: .85rem; }
}

/* ===== Página pública (celular primeiro) ===== */
body.public { --page-bg: var(--surface); background: var(--page-bg); }
.public .card { box-shadow: 0 2px 6px rgba(0,0,0,.06), 0 12px 32px rgba(0,0,0,.08); }
/* Fonte do título escolhida no construtor (sem escolha: fonte padrão) */
.public-head h1, .public .success h1 { font-family: var(--title-font, inherit); letter-spacing: normal; color: var(--title-color, inherit); }
.public-wrap { max-width: 640px; margin: 0 auto; padding: 18px 14px 8px; }
.public-head { text-align: center; padding: 18px 0 10px; }
.public-head img { max-height: 64px; max-width: 70%; margin-bottom: 10px; }
.public .card { padding: 20px 18px; }
.public .btn { width: 100%; min-height: 54px; font-size: 1.05rem; border-radius: 14px; }
.public .section-title { border-left: 4px solid var(--primary); padding-left: 12px; }
.hp { position: absolute; left: -9999px; height: 0; overflow: hidden; }
.thumbs { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.thumbs img { width: 72px; height: 72px; object-fit: cover; border-radius: 10px; border: 1px solid var(--sep); }
.files { display: flex; gap: 10px; flex-wrap: wrap; }
.files img { max-width: 160px; max-height: 160px; border-radius: 10px; border: 1px solid var(--sep); }
.success { text-align: center; padding: 36px 14px; }
.success .tick { width: 72px; height: 72px; margin: 0 auto 16px; border-radius: 50%; display: grid; place-items: center;
  font-size: 2.2rem; font-weight: 700; line-height: 1; color: var(--ok); background: color-mix(in srgb, var(--ok) 14%, transparent); }
.success .success-link { margin-top: 20px; }

/* ===== Construtor ===== */
.b-section { border: 1px solid color-mix(in srgb, var(--primary) 30%, var(--sep)); }
.b-field { border: 1px solid var(--sep); border-radius: 12px; padding: 14px; margin-top: 12px; background: var(--surface-2); }
.b-field .head { display: flex; gap: 8px; justify-content: space-between; align-items: center; flex-wrap: wrap; }
.b-toggle { flex: 1; min-width: 0; padding: 0; border: 0; background: none; color: inherit; font: inherit; text-align: left; cursor: pointer; }
.b-toggle:focus-visible { outline: none; border-radius: 6px; box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 40%, transparent); }
/* Miniatura do logo no construtor */
.logo-preview { display: block; max-height: 64px; max-width: 100%; margin-top: 10px; }
/* Prévia da fonte do título no construtor */
.font-preview { margin-top: 10px; padding: 12px 14px; border: 1px dashed var(--sep); border-radius: 12px; font-size: 24px; font-weight: 700; line-height: 1.2; overflow-wrap: anywhere; }
.b-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-top: 12px; }
.sticky-save {
  position: sticky; bottom: 0; padding: 12px 0; display: flex; gap: 10px; flex-wrap: wrap; align-items: center; z-index: 5;
  background: color-mix(in srgb, var(--bg) 88%, transparent); -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
}

/* ===== Aproveitamento de espaço no painel ===== */
[hidden] { display: none !important; }
.cards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 440px), 1fr)); gap: 16px; align-items: start; }
.cards-grid > .card { margin-bottom: 0; }
.builder-layout { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 20px; align-items: start; }
.builder-side { position: sticky; top: 16px; max-height: calc(100vh - 32px); overflow: auto; }
.builder-side .card:last-child { margin-bottom: 0; }
.builder-side .card { margin-bottom: 16px; }
@media (max-width: 1100px) {
  .builder-layout { grid-template-columns: minmax(0, 1fr); }
  .builder-side { position: static; max-height: none; order: -1; }
}

/* ===== Passo a passo (página pública) ===== */
.stepper { margin: 4px 0 16px; }
.dots { display: flex; align-items: center; margin-bottom: 12px; }
.dot { flex: none; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-size: .85rem; font-weight: 700;
  background: var(--surface); color: var(--muted); border: 2px solid var(--sep); transition: background .2s, color .2s, border-color .2s; padding: 0; font-family: inherit; }
.dot.done { background: var(--primary); border-color: var(--primary); color: var(--on-primary); cursor: pointer; }
.dot.active { border-color: var(--primary); color: var(--primary); box-shadow: 0 0 0 4px color-mix(in srgb, var(--primary) 18%, transparent); }
/* Linha entre os passos: borda, para poder ser contínua, pontilhada ou tracejada (escolha do construtor) */
.dot-line { flex: 1; height: 0; border-top: 2px solid var(--sep); margin: 0 6px; }
.dot-line.done { border-top-color: var(--primary); }
.stepper.line-dotted .dot-line { border-top-style: dotted; }
.stepper.line-dashed .dot-line { border-top-style: dashed; }
.bar { height: 6px; border-radius: 6px; background: var(--sep); overflow: hidden; }
.bar > span { display: block; height: 100%; width: 0; background: var(--primary); border-radius: 6px; transition: width .3s ease; }
.steplabel { margin-top: 10px; font-size: .95rem; color: var(--muted); }
.steplabel strong { color: var(--text); }
.js-steps .step:not(.current) { display: none; }
.js-steps .step.current { animation: stepin .28s ease; }
@keyframes stepin { from { opacity: 0; transform: translateX(14px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .js-steps .step.current { animation: none; } .bar > span { transition: none; } }
.step-nav { display: flex; gap: 10px; }
.public .step-nav .btn { width: auto; flex: 1; }
.public .step-nav #backBtn { flex: 0 0 34%; }
@media (max-width: 640px) {
  .js-steps .step-nav { position: sticky; bottom: 0; padding: 12px 0 calc(12px + env(safe-area-inset-bottom)); margin: 0 -14px; padding-left: 14px; padding-right: 14px;
    background: color-mix(in srgb, var(--page-bg) 88%, transparent); -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px); }
}

/* Medidor de uso (cota) */
.meter { height: 8px; border-radius: 8px; background: var(--sep); overflow: hidden; }
.meter > span { display: block; height: 100%; background: var(--ok); border-radius: 8px; }
.meter.mid > span { background: var(--accent); }
.meter.high > span { background: var(--danger); }
