/* ===========================================================================
   Funil de Vendas - Telegram :: tema visual (escuro por padrao + claro)
   =========================================================================== */
:root {
  --tg: #3d9bff;
  --tg-dark: #2f8fff;
  --bg: #0f131c;
  --bg-soft: #141925;
  --card: #1a2030;
  --surface-2: #232b3d;
  --line: #2a3242;
  --ink: #e7eaf1;
  --muted: #8590a3;
  --ok: #2fc56e;
  --warn: #f0a93a;
  --danger: #ef5b56;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .42);
  --shadow-sm: 0 2px 10px rgba(0, 0, 0, .28);
  --r-start: #2fc56e;
  --r-message: #3d9bff;
  --r-upsell: #a786ff;
  --r-downsell: #f0a93a;
  --r-pix: #28c8bd;
  --r-end: #8590a3;
}

[data-theme="light"] {
  --tg: #1f8fe0;
  --tg-dark: #1a82cf;
  --bg: #eef1f6;
  --bg-soft: #e6eaf1;
  --card: #ffffff;
  --surface-2: #f3f5f9;
  --line: #dde2ec;
  --ink: #1b2330;
  --muted: #697384;
  --ok: #1f9d57;
  --warn: #d98a00;
  --danger: #d6453d;
  --shadow: 0 10px 28px rgba(20, 30, 55, .12);
  --shadow-sm: 0 2px 8px rgba(20, 30, 55, .08);
  --r-start: #1f9d57;
  --r-message: #2f7fd1;
  --r-upsell: #7c4dd6;
  --r-downsell: #d98a00;
  --r-pix: #0a9c95;
  --r-end: #697384;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    Helvetica, Arial, sans-serif;
  background:
    radial-gradient(1100px 560px at 50% -8%, rgba(61, 155, 255, .10), transparent),
    var(--bg);
  background-attachment: fixed;
  color: var(--ink);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--tg); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 .45em; font-weight: 700; letter-spacing: -.01em; }
h1 { font-size: 24px; }
h2 { font-size: 19px; margin-top: 4px; }
h3 { font-size: 15px; }
::selection { background: rgba(61, 155, 255, .3); }

/* ---------- Botoes ---------- */
button, .btn {
  font: inherit;
  cursor: pointer;
  border: 0;
  border-radius: var(--radius-sm);
  padding: 10px 17px;
  background: var(--tg);
  color: #fff;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background .15s, transform .06s, opacity .15s, box-shadow .15s;
}
button:hover, .btn:hover { background: var(--tg-dark); text-decoration: none; }
button:active, .btn:active { transform: translateY(1px); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.ghost, .btn.ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}
button.ghost:hover, .btn.ghost:hover { background: var(--surface-2); }
button.danger { background: var(--danger); }
button.danger:hover { background: var(--danger); filter: brightness(1.1); }
button.small, .btn.small { padding: 6px 12px; font-size: 13px; }

/* ---------- Campos ---------- */
input, textarea, select {
  font: inherit;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--ink);
  transition: border-color .15s, box-shadow .15s;
}
input::placeholder, textarea::placeholder { color: var(--muted); }
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--tg);
  box-shadow: 0 0 0 3px rgba(61, 155, 255, .22);
}
textarea { resize: vertical; min-height: 96px; }
select {
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 16px) 17px, calc(100% - 11px) 17px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 30px;
}
label.field { display: block; margin-bottom: 13px; }
label.field > span {
  display: block; font-size: 12.5px; font-weight: 600;
  color: var(--muted); margin-bottom: 5px;
}

/* ---------- Cartoes / layout ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.muted { color: var(--muted); font-size: 13px; }
.pill {
  font-size: 11.5px; font-weight: 700; padding: 4px 10px;
  border-radius: 999px; color: #fff; display: inline-block;
  letter-spacing: .01em;
}
.hidden { display: none !important; }

.toast {
  position: fixed; right: 20px; bottom: 20px; z-index: 99;
  background: #222a3a; color: #fff; padding: 12px 17px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm); box-shadow: var(--shadow);
  opacity: 0; transform: translateY(10px); transition: .22s;
  max-width: 380px; cursor: pointer; white-space: pre-wrap;
  word-wrap: break-word;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.err { background: var(--danger); border-color: transparent; }

/* Janela de confirmacao propria */
.modal-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(8, 12, 20, .62);
  display: flex; align-items: center; justify-content: center; padding: 22px;
}
.modal {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 22px; width: 100%; max-width: 380px;
  box-shadow: var(--shadow);
}
.modal-msg { margin: 0 0 18px; font-size: 15px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* alternador de tema */
.theme-toggle {
  background: transparent; border: 1px solid var(--line);
  color: var(--ink); width: 34px; height: 34px; padding: 0;
  border-radius: 50%; justify-content: center; font-size: 15px;
}
.theme-toggle:hover { background: var(--surface-2); }

/* ---------- Login ---------- */
.auth-wrap {
  min-height: 100vh; display: flex; align-items: center;
  justify-content: center; padding: 20px;
}
.auth-card { width: 100%; max-width: 392px; box-shadow: var(--shadow); }
.auth-card h1 { text-align: center; font-size: 22px; }
.auth-card .logo { text-align: center; margin-bottom: 10px; }
.auth-card .logo img {
  width: 76px; height: 76px; border-radius: 18px;
  box-shadow: var(--shadow-sm);
}
.tabs { display: flex; margin-bottom: 18px; border-bottom: 1px solid var(--line); }
.tabs button {
  flex: 1; background: none; color: var(--muted);
  border-radius: 0; border-bottom: 2px solid transparent; font-weight: 600;
}
.tabs button:hover { background: none; color: var(--ink); }
.tabs button.active { color: var(--tg); border-bottom-color: var(--tg); }

/* ---------- Topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--card);
  background: color-mix(in srgb, var(--card) 88%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  padding: 11px 22px; display: flex; align-items: center; gap: 12px;
}
.topbar .brand { font-weight: 800; font-size: 16px; letter-spacing: -.01em; }
.page { max-width: 1180px; margin: 0 auto; padding: 24px 22px 60px; }

/* ---------- Dashboard de funis ---------- */
.funnel-grid {
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(264px, 1fr));
}
.funnel-card {
  display: flex; flex-direction: column; gap: 9px;
  transition: transform .1s, border-color .15s;
}
.funnel-card:hover { transform: translateY(-2px); border-color: var(--tg); }
.funnel-card h3 { margin: 0; }
.empty { text-align: center; padding: 52px 20px; color: var(--muted); }

/* ---------- Editor ---------- */
.editor-grid {
  display: grid; grid-template-columns: 1fr 388px; gap: 20px;
  align-items: start;
}
@media (max-width: 980px) { .editor-grid { grid-template-columns: 1fr; } }

.section-title {
  font-size: 12px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--muted); font-weight: 700; margin: 22px 0 10px;
}

.node-card { margin-bottom: 14px; border-left: 3px solid var(--r-message); }
.node-card .node-head { display: flex; align-items: center; gap: 8px; }
.node-card .node-head input.node-name {
  font-weight: 700; border: 1px solid transparent; background: transparent;
  padding: 5px 7px; width: auto; flex: 1;
}
.node-card .node-head input.node-name:hover { border-color: var(--line); }
.node-card .node-head input.node-name:focus { background: var(--surface-2); }

.role-start { border-left-color: var(--r-start); }
.role-message { border-left-color: var(--r-message); }
.role-upsell { border-left-color: var(--r-upsell); }
.role-downsell { border-left-color: var(--r-downsell); }
.role-pix { border-left-color: var(--r-pix); }
.role-end { border-left-color: var(--r-end); }

.badge-start { background: var(--r-start); }
.badge-message { background: var(--r-message); }
.badge-upsell { background: var(--r-upsell); }
.badge-downsell { background: var(--r-downsell); }
.badge-pix { background: var(--r-pix); }
.badge-end { background: var(--r-end); }

.btn-row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.btn-row input { flex: 2; }
.btn-row select { flex: 3; }
.btn-row .x {
  background: var(--surface-2); color: var(--danger); padding: 8px 11px;
  border-radius: var(--radius-sm); border: 1px solid var(--line);
}
.btn-row .x:hover { background: var(--danger); color: #fff; }
.star { font-size: 18px; background: none; padding: 4px; }
.star:hover { background: none; transform: scale(1.15); }

/* ---------- Gerenciador de midias ---------- */
.media-list { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.media-list:empty { display: none; }
.media-item {
  position: relative; width: 86px; height: 86px; border-radius: var(--radius-sm);
  overflow: hidden; border: 1px solid var(--line); background: var(--surface-2);
}
.media-thumb { width: 100%; height: 100%; object-fit: cover; display: block; }
.media-tag {
  position: absolute; left: 4px; bottom: 4px; font-size: 9px; font-weight: 700;
  background: rgba(8, 12, 22, .82); color: #fff; padding: 2px 6px;
  border-radius: 5px; letter-spacing: .03em;
}
.media-x {
  position: absolute; top: 3px; right: 3px; width: 21px; height: 21px;
  padding: 0; border-radius: 50%; background: rgba(214, 69, 61, .94);
  color: #fff; font-size: 11px; justify-content: center;
}
.media-x:hover { background: var(--danger); }
.media-add {
  display: inline-block; cursor: pointer; font-size: 13px; font-weight: 600;
  color: var(--tg); border: 1px dashed var(--line); border-radius: var(--radius-sm);
  padding: 8px 14px; margin-bottom: 13px;
}
.media-add:hover { background: var(--surface-2); border-color: var(--tg); }

/* ---------- Simulador (estilo Telegram, sempre escuro) ---------- */
.sim-panel { position: sticky; top: 78px; }
.phone {
  background: #0e1621; border-radius: 22px; padding: 14px;
  border: 1px solid var(--line);
}
.phone-head {
  color: #fff; display: flex; align-items: center; gap: 9px;
  padding: 4px 6px 12px;
}
.phone-head .avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--tg); display: flex; align-items: center;
  justify-content: center; font-weight: 700;
}
.chat {
  background-image: linear-gradient(160deg, #17263a, #0b1320);
  border-radius: 14px; padding: 12px; height: 462px;
  overflow-y: auto; display: flex; flex-direction: column; gap: 8px;
}
.bubble {
  max-width: 86%; padding: 9px 12px; border-radius: 15px;
  font-size: 14px; white-space: pre-wrap; word-wrap: break-word;
}
.bubble.bot {
  background: #fff; color: #1f2933; align-self: flex-start;
  border-bottom-left-radius: 4px;
}
.bubble.user {
  background: #2b5278; color: #fff; align-self: flex-end;
  border-bottom-right-radius: 4px;
}
.bubble img, .bubble video {
  max-width: 100%; border-radius: 10px; margin-bottom: 6px; display: block;
}
.sim-buttons { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; }
.sim-buttons button {
  background: #f0f6fb; color: #1769b0; border: 1px solid #d3e6f3;
  font-size: 13px; width: 100%; justify-content: center;
}
.sim-buttons button:hover { background: #e2eff8; }
.pix-box {
  background: #0c1a2b; border: 1px solid #1f3a52; border-radius: 10px;
  padding: 9px; margin-top: 6px; color: #cfe0ef;
}
.pix-box img { width: 132px; display: block; margin: 0 auto 6px;
  border-radius: 6px; }
.pix-code {
  font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 10px;
  word-break: break-all; background: #06101c; border: 1px solid #1f3a52;
  border-radius: 6px; padding: 6px; color: #7fd6cd;
}
.sim-note { color: #8aa0b4; font-size: 12px; text-align: center; }

/* ---------- Dashboard de vendas ---------- */
.kpi-grid {
  display: grid; gap: 14px; margin-bottom: 22px;
  grid-template-columns: repeat(auto-fit, minmax(168px, 1fr));
}
.kpi {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 17px; box-shadow: var(--shadow-sm);
}
.kpi .kpi-label {
  font-size: 11.5px; color: var(--muted); font-weight: 700;
  text-transform: uppercase; letter-spacing: .05em;
}
.kpi .kpi-value {
  font-size: 27px; font-weight: 800; margin-top: 5px; letter-spacing: -.02em;
}
.range-tabs {
  display: inline-flex; border: 1px solid var(--line);
  border-radius: var(--radius-sm); overflow: hidden;
}
.range-tabs button {
  background: var(--card); color: var(--muted); border-radius: 0;
  padding: 7px 15px; font-size: 13px;
}
.range-tabs button.active { background: var(--tg); color: #fff; }
.chart-card { margin-bottom: 18px; }
.chart-card svg { display: block; }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th, table.data td {
  text-align: left; padding: 10px 11px; border-bottom: 1px solid var(--line);
}
table.data tr:last-child td { border-bottom: 0; }
table.data th {
  font-size: 11.5px; color: var(--muted); font-weight: 700;
  text-transform: uppercase; letter-spacing: .04em;
}
table.data td.num, table.data th.num { text-align: right; }
table.data tbody tr:hover { background: var(--surface-2); }
