/* ============================================================
   CRM de Leads — sistema de design
   Paleta quente (tom de papel/convite), tipografia serifada nos
   títulos para dar personalidade de negócio de eventos, mantendo
   a interface funcional em fonte de sistema para máxima legibilidade.
   Contraste checado pra WCAG AA, foco de teclado visível, e
   prefers-reduced-motion respeitado.
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,500;9..144,600;9..144,700&display=swap');

:root {
  /* Superfícies */
  --bg: #faf8f4;
  --panel: #ffffff;
  --surface-2: #f3efe7;

  /* Texto */
  --ink: #201d19;
  --ink-soft: #5c564d;
  --ink-muted: #8a8275;

  /* Bordas */
  --border: #e6e0d4;
  --border-strong: #d3c9b8;

  /* Marca / ação */
  --accent: #1f6b45;
  --accent-hover: #17552f;
  --accent-soft: #e4f1e9;

  /* Etapas do funil */
  --stage-1: #a3590f;       /* entrou em contato */
  --stage-1-soft: #fbeee0;
  --stage-2: #1d4fc4;       /* proposta enviada */
  --stage-2-soft: #e7edfc;
  --stage-3: #1f6b45;       /* finalizado (= accent) */
  --stage-3-soft: #e4f1e9;

  --danger: #b3261e;
  --danger-soft: #fbe9e7;

  --radius: 10px;
  --radius-lg: 14px;

  --font-display: 'Fraunces', Georgia, 'Times New Roman', serif;
  --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  --shadow-sm: 0 1px 2px rgba(32, 29, 25, 0.06);
  --shadow-md: 0 6px 20px rgba(32, 29, 25, 0.08);
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}

a { color: var(--accent); }

/* Foco de teclado visível em qualquer elemento interativo */
a:focus-visible, button:focus-visible, input:focus-visible,
select:focus-visible, textarea:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

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

h1, h2, h3 { font-family: var(--font-display); font-weight: 600; letter-spacing: -0.01em; color: var(--ink); }

/* ---------- Visualizador de Stories (Painel) ---------- */
.story-viewer {
  position: fixed; inset: 0; background: #000; z-index: 100;
  display: flex; align-items: center; justify-content: center;
}
.story-viewer.hidden { display: none; }

.story-progress-bar {
  position: absolute; top: 10px; left: 10px; right: 10px; z-index: 3;
  display: flex; gap: 4px;
}
.story-progress-segment { flex: 1; height: 3px; background: rgba(255,255,255,.35); border-radius: 3px; overflow: hidden; }
.story-progress-fill { height: 100%; width: 0%; background: #fff; }

.story-close {
  position: absolute; top: 16px; right: 14px; z-index: 4; background: rgba(0,0,0,.35);
  border: none; color: #fff; font-size: 26px; width: 38px; height: 38px; border-radius: 50%; cursor: pointer;
}

.story-nav-zone { position: absolute; top: 0; bottom: 0; width: 33%; z-index: 2; cursor: pointer; }
.story-nav-prev { left: 0; }
.story-nav-next { right: 0; }

.story-image { max-width: 100%; max-height: 100%; object-fit: contain; }

.story-caption {
  position: absolute; bottom: 90px; left: 20px; right: 20px; z-index: 3;
  color: #fff; text-align: center; font-size: 15px; text-shadow: 0 1px 4px rgba(0,0,0,.6);
}

.story-cta {
  position: absolute; bottom: 28px; left: 50%; transform: translateX(-50%); z-index: 4;
  background: #fff; color: var(--ink); text-decoration: none; font-weight: 700;
  font-size: 14px; padding: 11px 22px; border-radius: 999px;
}
.story-cta.hidden { display: none; }

/* ---------- Banner de destaque e atalhos (Painel) ---------- */
.dash-banner {
  background: linear-gradient(135deg, #1f3d2f, #1f6b45);
  border-radius: var(--radius-lg);
  padding: 20px 22px;
  margin-bottom: 16px;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  position: relative;
  overflow: hidden;
}
.dash-banner-text { flex: 1; min-width: 180px; }
.dash-banner-title { font-family: var(--font-display); font-size: 18px; font-weight: 600; margin: 0 0 4px; }
.dash-banner-subtitle { font-size: 13px; margin: 0; opacity: 0.85; }
.dash-banner-img { width: 56px; height: 56px; border-radius: 12px; object-fit: cover; flex-shrink: 0; }
.dash-banner-btn {
  background: #fff; color: var(--accent-hover); text-decoration: none; font-weight: 700;
  font-size: 13px; padding: 10px 16px; border-radius: 8px; white-space: nowrap; flex-shrink: 0;
}

.dash-shortcuts {
  display: flex; gap: 18px; overflow-x: auto; padding: 4px 2px 16px;
  -webkit-overflow-scrolling: touch;
}
.dash-shortcut {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  text-decoration: none; color: var(--ink); flex-shrink: 0; width: 68px; text-align: center;
  background: none; border: none; padding: 0; font-family: inherit; cursor: pointer; min-height: auto;
}
.dash-shortcut-icon {
  width: 52px; height: 52px; border-radius: 50%; background: var(--surface-2);
  border: 1px solid var(--border); display: flex; align-items: center; justify-content: center;
  font-size: 22px;
}
.dash-shortcut:hover .dash-shortcut-icon { background: var(--accent-soft); border-color: var(--accent); }
.dash-shortcut-label { font-size: 11px; color: var(--ink-soft); font-weight: 600; line-height: 1.3; }

/* ---------- Sidebar ---------- */
.sidebar-toggle {
  position: fixed; top: 12px; left: 12px; z-index: 60;
  background: var(--panel); border: 1px solid var(--border-strong);
  border-radius: 8px; width: 42px; height: 42px; font-size: 18px; cursor: pointer;
  box-shadow: var(--shadow-sm);
}

.sidebar-backdrop { position: fixed; inset: 0; background: rgba(32,29,25,.5); z-index: 45; display: none; }
.sidebar-backdrop.open { display: block; }

.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0; width: 244px;
  background: var(--panel); border-right: 1px solid var(--border);
  padding: 68px 12px 16px; display: flex; flex-direction: column; gap: 2px;
  z-index: 50; transform: translateX(-100%); transition: transform .2s ease;
  overflow-y: auto;
}
.sidebar.open { transform: translateX(0); }

.sidebar-brand {
  position: absolute; top: 20px; left: 22px;
  font-family: var(--font-display); font-weight: 600; font-size: 17px; letter-spacing: -0.01em;
}

.sidebar-link {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 12px; border-radius: 8px;
  color: var(--ink); text-decoration: none; font-size: 14.5px; min-height: 44px;
}
.sidebar-link:hover { background: var(--surface-2); }
.sidebar-link.active { background: var(--accent-soft); color: var(--accent-hover); font-weight: 600; }
.sidebar-icon { font-size: 16px; width: 20px; text-align: center; }

.sidebar-spacer { flex: 1; }
.sidebar-user { font-size: 12.5px; color: var(--ink-soft); padding: 8px 12px; }
.sidebar-logout { color: var(--danger); }

.app-content { padding-top: 56px; }

/* ---------- Topbar ---------- */
.topbar {
  display: flex; flex-wrap: wrap; gap: 10px 12px; justify-content: space-between; align-items: center;
  padding: 16px 20px; background: var(--panel); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.topbar h1 { font-size: 20px; margin: 0; }
.topbar-actions { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-soft); flex-wrap: wrap; }

.btn-secondary {
  color: var(--ink); text-decoration: none; border: 1px solid var(--border-strong);
  padding: 8px 12px; border-radius: 8px; font-size: 13px; min-height: 38px;
  display: inline-flex; align-items: center; background: var(--panel);
}
.btn-secondary:hover { background: var(--surface-2); }

main { padding: 20px 16px; }

/* ---------- Board / Kanban ---------- */
.board { display: flex; gap: 12px; overflow-x: auto; scroll-snap-type: x mandatory; padding-bottom: 8px; -webkit-overflow-scrolling: touch; }

.column {
  background: var(--panel); border-radius: var(--radius-lg); border: 1px solid var(--border);
  padding: 14px; flex: 0 0 86%; scroll-snap-align: start; min-height: 50vh;
}

.column h2 {
  font-family: var(--font-body); font-size: 12.5px; font-weight: 700; margin: 2px 4px 14px;
  display: flex; justify-content: space-between; align-items: center;
  color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.06em;
}
.column[data-status="entrou_contato"] h2 { color: var(--stage-1); }
.column[data-status="proposta_enviada"] h2 { color: var(--stage-2); }
.column[data-status="finalizado"] h2 { color: var(--stage-3); }

.count { background: var(--surface-2); color: var(--ink-soft); border-radius: 999px; padding: 2px 9px; font-size: 12px; font-weight: 600; }

.cards { min-height: 80px; }

.card {
  background: var(--panel); border: 1px solid var(--border); border-left: 3px solid var(--stage-1);
  border-radius: 10px; padding: 13px; margin-bottom: 10px; cursor: grab; min-height: 44px;
  box-shadow: var(--shadow-sm);
}
.card:active { box-shadow: var(--shadow-md); }
.column[data-status="proposta_enviada"] .card { border-left-color: var(--stage-2); }
.column[data-status="finalizado"] .card { border-left-color: var(--stage-3); }

.card-name { font-weight: 700; font-size: 14.5px; margin-bottom: 3px; color: var(--ink); }
.card-email { font-size: 13px; color: var(--ink-soft); }
.card-source { font-size: 11px; font-weight: 600; color: var(--accent-hover); background: var(--accent-soft); display: inline-block; padding: 2px 8px; border-radius: 999px; margin-top: 7px; }
.card-date { font-size: 11.5px; color: var(--ink-muted); margin-top: 6px; }

.sortable-ghost { opacity: 0.4; }

.empty-hint, .empty-note { font-size: 13.5px; color: var(--ink-muted); text-align: center; padding: 28px 6px; }

.scroll-hint { text-align: center; font-size: 12px; color: var(--ink-muted); margin: -4px 0 12px; }

/* ---------- Modal ---------- */
.modal-overlay { position: fixed; inset: 0; background: rgba(32,29,25,.5); display: flex; align-items: flex-end; justify-content: center; z-index: 50; }
.modal-overlay.hidden { display: none; }

.modal {
  background: #fff; border-radius: 18px 18px 0 0; padding: 22px 18px calc(20px + env(safe-area-inset-bottom));
  width: 100%; max-height: 88vh; overflow-y: auto; position: relative; box-shadow: var(--shadow-md);
}
.modal-close { position: absolute; top: 10px; right: 14px; background: none; border: none; font-size: 26px; cursor: pointer; color: var(--ink-soft); min-width: 36px; min-height: 36px; }
.modal h3 { margin: 6px 0 4px; font-size: 19px; }
.modal-meta { color: var(--ink-soft); font-size: 13px; margin: 0 0 12px; }
.modal-message { background: var(--surface-2); padding: 11px 12px; border-radius: 10px; font-size: 13.5px; }

.modal-custom-fields { margin-top: 10px; }
.custom-field-row { display: flex; justify-content: space-between; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.custom-field-row:last-child { border-bottom: none; }
.custom-field-label { color: var(--ink-soft); flex-shrink: 0; }
.custom-field-value { text-align: right; font-weight: 600; }

.modal input, .modal textarea, .modal select {
  width: 100%; padding: 12px; border: 1px solid var(--border-strong); border-radius: 9px;
  margin-bottom: 10px; font-family: inherit; font-size: 15px; min-height: 46px; background: #fff; color: var(--ink);
}
.modal textarea { min-height: 92px; }

.btn-primary {
  background: var(--accent); color: #fff; border: none; padding: 13px 16px; border-radius: 9px;
  cursor: pointer; font-weight: 700; font-size: 15px; min-height: 48px; width: 100%;
}
.btn-primary:hover { background: var(--accent-hover); }

#email-status { font-size: 13px; margin-top: 8px; }

/* ---------- Layout genérico das telas internas ---------- */
.wrap { max-width: 780px; margin: 0 auto; }
.intro { font-size: 14px; color: var(--ink-soft); margin-bottom: 20px; line-height: 1.6; }
.section-title {
  font-family: var(--font-display); font-size: 17px; font-weight: 600; margin: 30px 0 12px; color: var(--ink);
}
.feedback { background: var(--accent-soft); color: var(--accent-hover); padding: 11px 14px; border-radius: 9px; font-size: 13.5px; margin-bottom: 16px; font-weight: 500; }

input[type=text], input[type=password], input[type=email], input[type=date], input[type=number], select, textarea {
  min-height: 44px; font-size: 15px; padding: 10px 12px; border: 1px solid var(--border-strong);
  border-radius: 9px; background: #fff; color: var(--ink); font-family: inherit;
}
input::placeholder, textarea::placeholder { color: var(--ink-muted); }
button, .open-btn { min-height: 40px; font-family: inherit; }

/* ---------- Cards de estatística ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 10px; margin-bottom: 20px; }
.stat-card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 15px; box-shadow: var(--shadow-sm); }
.stat-card .stat-label { font-size: 12px; color: var(--ink-soft); margin: 0 0 5px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }
.stat-card .stat-value { font-family: var(--font-display); font-size: 27px; font-weight: 600; margin: 0; color: var(--ink); }
.stat-card .stat-sub { font-size: 12px; color: var(--ink-soft); margin-top: 4px; }

.chart-box { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 16px; margin-bottom: 20px; position: relative; height: 220px; }

.bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 11px; font-size: 13.5px; }
.bar-row .bar-label { width: 120px; flex-shrink: 0; color: var(--ink-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .bar-track { flex: 1; background: var(--surface-2); border-radius: 6px; height: 20px; overflow: hidden; }
.bar-row .bar-fill { height: 100%; background: var(--accent); border-radius: 6px; }
.bar-row .bar-count { width: 32px; text-align: right; font-weight: 700; color: var(--ink); }

/* ---------- Formulários / Listagens (forms.php, form_edit.php) ---------- */
.new-form-box, .new-auto-form {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 18px; margin-bottom: 24px; box-shadow: var(--shadow-sm);
}
.new-form-box { display: flex; gap: 10px; flex-wrap: wrap; }
.new-form-box input { flex: 1; min-width: 180px; }
.new-auto-form .row { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.new-auto-form .row > * { flex: 1; min-width: 160px; }

.form-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 16px; margin-bottom: 12px; box-shadow: var(--shadow-sm);
}
.form-card-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.form-card h3 { margin: 0; font-size: 16px; }
.form-card .meta { font-size: 12.5px; color: var(--ink-soft); margin-top: 4px; }
.form-card .stats { font-size: 12.5px; color: var(--ink-soft); }
.form-card a.open-btn {
  font-size: 13px; background: var(--accent-soft); color: var(--accent-hover);
  padding: 7px 13px; border-radius: 8px; text-decoration: none; font-weight: 700; white-space: nowrap;
}

.field-row {
  background: var(--panel); border: 1px solid var(--border); border-radius: 9px;
  padding: 12px 14px; margin-bottom: 10px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
.field-row input[type=text] { padding: 8px 10px; font-size: 13.5px; }
.field-row input.mono { font-family: var(--font-mono); }
.field-row .field-sample { font-size: 12.5px; color: var(--ink-soft); flex: 1; min-width: 100px; }
.field-row select { padding: 8px 10px; font-size: 13.5px; min-height: 40px; }
.field-row button {
  padding: 8px 14px; border-radius: 8px; border: none; background: var(--accent);
  color: #fff; font-size: 13px; font-weight: 700; cursor: pointer;
}
.field-row button:hover { background: var(--accent-hover); }
.field-row .custom-label-input { display: none; flex: 1; min-width: 160px; }
.field-name { font-family: var(--font-mono); background: var(--surface-2); padding: 3px 8px; border-radius: 6px; font-size: 12.5px; color: var(--ink); }

.mapping-item, .auto-card, .log-item, .log-row, .click-row {
  display: flex; align-items: center; justify-content: space-between; background: var(--panel);
  border: 1px solid var(--border); border-radius: 9px; padding: 12px 14px; margin-bottom: 8px; font-size: 13.5px;
  box-shadow: var(--shadow-sm);
}
.mapping-item .left { font-size: 13.5px; }
.mapping-item .crm-tag { font-weight: 700; color: var(--stage-3); margin-right: 6px; }
.mapping-item .crm-tag.custom-tag { color: #7c4dc4; }
.mapping-item button { background: none; border: none; color: var(--danger); cursor: pointer; font-size: 13px; font-weight: 600; }

.log-item, .log-row, .click-row { display: block; }
.log-item.ok, .log-row.ok { border-left: 3px solid var(--stage-3); }
.log-item.fail, .log-row.fail { border-left: 3px solid var(--danger); }
.log-item .tag, .tag { font-size: 11.5px; font-weight: 700; padding: 3px 9px; border-radius: 999px; }
.tag.ok { background: var(--stage-3-soft); color: var(--accent-hover); }
.tag.fail { background: var(--danger-soft); color: var(--danger); }
.log-item pre { background: var(--surface-2); padding: 11px; border-radius: 8px; font-size: 12px; overflow-x: auto; margin-top: 8px; font-family: var(--font-mono); }
.log-item time { color: var(--ink-muted); font-size: 12px; float: right; }

.click-row .top { display: flex; justify-content: space-between; gap: 10px; }
.click-row .link-name { font-weight: 700; }
.click-row time { color: var(--ink-muted); font-size: 11.5px; }
.click-row .utm-tags { margin-top: 7px; display: flex; gap: 6px; flex-wrap: wrap; }
.utm-tag { font-size: 10.5px; background: var(--surface-2); border: 1px solid var(--border); padding: 2px 8px; border-radius: 999px; color: var(--ink-soft); font-weight: 600; }

/* Automações WhatsApp */
.auto-card { display: block; }
.auto-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.auto-title { font-weight: 700; font-size: 15px; }
.auto-meta { font-size: 12.5px; color: var(--ink-soft); margin-top: 5px; line-height: 1.6; }
.auto-badge { font-size: 11px; padding: 3px 9px; border-radius: 999px; font-weight: 700; flex-shrink: 0; }
.auto-badge.on { background: var(--stage-3-soft); color: var(--accent-hover); }
.auto-badge.off { background: var(--surface-2); color: var(--ink-muted); }
.auto-actions button {
  font-size: 12px; padding: 6px 12px; border-radius: 7px; border: 1px solid var(--border-strong);
  background: #fff; cursor: pointer; margin-left: 6px; font-weight: 600;
}

.url-box {
  background: #211d19; color: #d9f0e2; font-family: var(--font-mono); font-size: 12.5px;
  padding: 13px 15px; border-radius: 9px; word-break: break-all; margin-bottom: 8px;
}
.url-hint { font-size: 12.5px; color: var(--ink-soft); margin-bottom: 20px; line-height: 1.6; }

.danger-zone { margin-top: 40px; border-top: 1px solid var(--border); padding-top: 18px; }
.danger-zone button { background: none; border: 1px solid var(--danger); color: var(--danger); padding: 8px 15px; border-radius: 8px; cursor: pointer; font-size: 13px; font-weight: 600; }
.rename-form { display: flex; gap: 8px; margin-bottom: 8px; }
.rename-form input { flex: 1; }
.rename-form button { padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border-strong); background: #fff; cursor: pointer; font-size: 13px; font-weight: 600; }

/* ---------- Caixa de configuração recolhível (integrações) ---------- */
.config-box {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 16px 18px; margin-bottom: 20px; box-shadow: var(--shadow-sm);
}
.config-box summary { cursor: pointer; font-weight: 700; font-size: 14.5px; }
.config-box .status-on { color: var(--accent-hover); font-weight: 500; font-size: 12.5px; }
.config-box .status-off { color: var(--stage-1); font-weight: 500; font-size: 12.5px; }

/* ---------- Barra de sincronização (WhatsApp Cliques) ---------- */
.sync-bar { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.sync-bar button {
  background: var(--accent); color: #fff; border: none; padding: 12px 18px; border-radius: 9px;
  font-size: 14px; font-weight: 700; cursor: pointer; min-height: 44px;
}
.sync-bar button:hover { background: var(--accent-hover); }
.sync-bar button:disabled { opacity: .6; cursor: default; }
.sync-status { font-size: 12.5px; color: var(--ink-soft); }

/* ---------- Chip / details "Configurar integração" ---------- */
details summary { list-style: none; }
details summary::-webkit-details-marker { display: none; }

/* ---------- Responsivo: sidebar fixa e grid de 3 colunas no desktop ---------- */
@media (min-width: 720px) {
  main { padding: 28px 32px; }

  .sidebar-toggle { display: none; }
  .sidebar-backdrop { display: none !important; }
  .sidebar { transform: translateX(0); box-shadow: none; }
  .app-content { margin-left: 244px; padding-top: 0; }

  .board { display: grid; grid-template-columns: repeat(3, minmax(240px, 1fr)); overflow-x: visible; max-width: 1240px; margin: 0 auto; }
  .column { flex: initial; min-height: 60vh; }
  .scroll-hint { display: none; }

  .modal-overlay { align-items: center; }
  .modal { border-radius: var(--radius-lg); width: 440px; max-width: 92vw; max-height: 85vh; padding: 26px; }
  .btn-primary { width: auto; }

  .stat-grid { grid-template-columns: repeat(4, minmax(0,1fr)); }
}

@media (max-width: 819px) {
  .topbar h1 { width: 100%; }
}
