:root {
  --bg: #0a0a0a;
  --bg-2: #101010;
  --panel: #141414;
  --panel-2: #1a1a1a;
  --ink: #f4f4f0;
  --muted: #a8a8a0;
  --faint: #7e7e77;
  --line: #232323;
  --line-2: #2f2f2f;
  --lime: #c6f24e;
  --lime-ink: #0a0a0a;
  --danger: #ff6b6b;
  --warn: #f2c94c;
  --ok: #6fe6a0;

  --display: "Outfit", system-ui, sans-serif;
  --sans: "DM Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, Consolas, monospace;

  --gut: clamp(16px, 5vw, 48px);
  --radius: 14px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

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

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

.mono { font-family: var(--mono); }

/* ---------- Auth pages ---------- */
.auth-shell {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.25rem;
  padding: var(--gut);
  background:
    radial-gradient(circle at 20% 10%, rgba(198, 242, 78, .08), transparent 40%),
    var(--bg);
}

.auth-footer { color: var(--faint); font-size: .78rem; text-align: center; }
.auth-footer a { color: var(--faint); text-decoration: underline; }
.auth-footer a:hover { color: var(--lime); }

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: clamp(1.75rem, 5vw, 2.5rem);
}

.brand {
  display: flex;
  align-items: center;
  gap: .6rem;
  margin-bottom: 1.75rem;
}

.brand .dot {
  width: 10px; height: 10px; border-radius: 50%; background: var(--lime);
  box-shadow: 0 0 12px rgba(198, 242, 78, .6);
}

.brand span {
  font-family: var(--display); font-weight: 700; font-size: 1.05rem; letter-spacing: -.02em;
}

.auth-card h1 { font-size: 1.5rem; margin: 0 0 .3rem; }
.auth-card .sub { color: var(--muted); font-size: .9rem; margin-bottom: 1.5rem; }

label { display: block; font-size: .82rem; color: var(--muted); margin: 1rem 0 .4rem; }

input, textarea, select {
  width: 100%;
  padding: .7rem .85rem;
  background: var(--bg-2);
  border: 1px solid var(--line-2);
  border-radius: 10px;
  color: var(--ink);
  font-size: .95rem;
  font-family: inherit;
  transition: border-color .15s;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--lime);
}

button {
  font-family: var(--sans);
  cursor: pointer;
}

.btn-lime {
  width: 100%;
  margin-top: 1.6rem;
  padding: .8rem;
  border: none;
  border-radius: 10px;
  background: var(--lime);
  color: var(--lime-ink);
  font-size: .95rem;
  font-weight: 700;
  transition: transform .1s, filter .15s;
}
.btn-lime:hover { filter: brightness(1.08); }
.btn-lime:active { transform: scale(.98); }

.btn-ghost {
  background: transparent;
  border: 1px solid var(--line-2);
  color: var(--ink);
  padding: .55rem 1rem;
  border-radius: 8px;
  font-size: .85rem;
  font-weight: 600;
}
.btn-ghost:hover { border-color: var(--lime); color: var(--lime); }

.error-msg {
  color: var(--danger);
  font-size: .85rem;
  margin-top: .9rem;
  min-height: 1em;
}

.success-msg {
  color: var(--ok);
  font-size: .85rem;
  margin-top: .6rem;
  min-height: 1em;
}

.auth-link {
  text-align: center;
  margin-top: 1.4rem;
  font-size: .85rem;
  color: var(--muted);
}
.auth-link a { text-decoration: none; font-weight: 600; }
.auth-link a:hover { text-decoration: underline; }

/* ---------- App shell ---------- */
.app-header {
  position: sticky; top: 0; z-index: 10;
  background: rgba(10,10,10,.85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  padding: .8rem var(--gut);
  display: flex; align-items: center; justify-content: space-between;
}

.brand-lockup { display: flex; align-items: center; gap: .65rem; }
.brand-lockup svg { width: 34px; height: 34px; flex-shrink: 0; }
.brand-name { font-family: var(--display); font-weight: 900; font-size: .95rem; line-height: 1.1; }
.brand-sub { font-size: .72rem; color: var(--lime); font-weight: 600; letter-spacing: .03em; text-transform: uppercase; }

.profile-menu { position: relative; }
.avatar-btn {
  width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--line-2);
  background: var(--panel-2); color: var(--ink); font-family: var(--display); font-weight: 700; font-size: .85rem;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.avatar-btn:hover { border-color: var(--lime); }
.profile-dropdown {
  position: absolute; right: 0; top: calc(100% + 10px);
  background: var(--panel); border: 1px solid var(--line-2); border-radius: 10px;
  padding: .9rem; width: 210px; box-shadow: 0 10px 30px rgba(0,0,0,.4);
  display: none;
}
.profile-dropdown.open { display: block; }
.profile-dropdown .p-name { font-weight: 700; font-size: .9rem; }
.profile-dropdown .p-email { color: var(--muted); font-size: .78rem; margin-bottom: .8rem; word-break: break-all; }
.profile-dropdown button { width: 100%; }

.app-main {
  max-width: 1100px;
  margin: 0 auto;
  padding: clamp(1rem, 4vw, 2rem) var(--gut) 3rem;
  display: grid;
  gap: 1.25rem;
}

.whatsapp-body {
  display: flex; flex-wrap: wrap; gap: 1.5rem; align-items: flex-start;
}
.whatsapp-body .status-col { flex: 1 1 240px; }
.whatsapp-body #qrcode {
  flex: 0 0 auto;
  display: flex; flex-direction: column; align-items: center;
  text-align: center;
  max-width: 240px;
}

@media (min-width: 720px) {
  .field-row { grid-template-columns: 1fr 1fr; }
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1rem;
}
.kpi-tile {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem;
  min-width: 0;
}
.kpi-label {
  font-size: .78rem; color: var(--muted); margin-bottom: .5rem;
  display: flex; align-items: center; gap: .3rem;
}
.kpi-value { font-family: var(--display); font-size: 1.9rem; font-weight: 700; color: var(--ink); }

.chart-wrap { position: relative; min-width: 0; height: 280px; }
.chart-wrap canvas { max-width: 100%; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: clamp(1.25rem, 3vw, 1.75rem);
  min-width: 0;
}

.stage-block { padding-top: 1.4rem; margin-top: 1.4rem; border-top: 1px solid var(--line); }
.stage-block:first-of-type { padding-top: 0; margin-top: 0; border-top: none; }

.stage-head { display: flex; align-items: center; gap: 1rem; margin-bottom: .3rem; cursor: pointer; }
.stage-head h3 { margin: 0; font-size: .95rem; display: flex; align-items: center; gap: .7rem; }
.stage-num {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border-radius: 10px; flex-shrink: 0;
  background: var(--bg-2); border: 1px solid var(--line-2);
  color: var(--lime); font-family: var(--display); font-size: 1.4rem; font-weight: 900;
}
.stage-head .chevron { margin-left: auto; color: var(--faint); transition: transform .2s; flex-shrink: 0; }
.stage-block.open .chevron { transform: rotate(180deg); }
.card h2 {
  font-size: 1rem;
  margin: 0 0 1.1rem;
  display: flex; align-items: center; gap: .5rem;
}

.status-row { display: flex; align-items: center; gap: .7rem; flex-wrap: wrap; margin-bottom: 1rem; }

.dot-status { width: 10px; height: 10px; border-radius: 50%; background: var(--faint); flex-shrink: 0; }
.dot-status.conectado { background: var(--ok); box-shadow: 0 0 10px rgba(111,230,160,.6); }
.dot-status.desconectado { background: var(--danger); }

#qrcode img {
  max-width: 200px; width: 100%; border-radius: 10px; border: 1px solid var(--line-2);
  background: #fff; padding: 8px;
}

.hint { font-size: .8rem; color: var(--faint); margin-top: .5rem; }

.toggle-row {
  display: flex; align-items: center; gap: .7rem; margin-top: .8rem;
  padding: .7rem .9rem; background: var(--bg-2); border-radius: 10px; border: 1px solid var(--line-2);
}

.switch {
  position: relative; width: 42px; height: 24px; flex-shrink: 0;
}
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute; inset: 0; background: var(--line-2); border-radius: 999px; cursor: pointer;
  transition: background .2s;
}
.switch .slider::before {
  content: ""; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px;
  background: var(--ink); border-radius: 50%; transition: transform .2s;
}
.switch input:checked + .slider { background: var(--lime); }
.switch input:checked + .slider::before { transform: translateX(18px); background: var(--lime-ink); }

.field-row { display: grid; grid-template-columns: 1fr; gap: .8rem; }

.unit-field { display: flex; gap: .5rem; }
.unit-field input { flex: 0 1 90px; min-width: 0; }
.unit-field select { flex: 1 1 auto; min-width: 0; }

.table-wrap { overflow-x: auto; margin-top: .3rem; position: relative; }
.table-scroll-hint {
  display: none;
  font-size: .72rem; color: var(--faint); text-align: right;
  margin-bottom: .4rem;
}
@media (max-width: 640px) {
  .table-scroll-hint { display: block; }
  .table-wrap { -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 24px), transparent); mask-image: linear-gradient(to right, #000 calc(100% - 24px), transparent); }
}
table { border-collapse: collapse; width: 100%; font-size: .84rem; min-width: 560px; }
th, td { border-bottom: 1px solid var(--line); padding: .6rem .7rem; text-align: left; white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: .75rem; text-transform: uppercase; letter-spacing: .03em; }
tr.due td { background: rgba(255,107,107,.08); }

.badge {
  padding: 3px 9px; border-radius: 999px; font-size: .72rem; font-weight: 600; font-family: var(--mono);
  display: inline-block;
}
.badge.aguardando_resposta { background: rgba(242,201,76,.15); color: var(--warn); }
.badge.respondido { background: rgba(111,230,160,.15); color: var(--ok); }
.badge.esgotado { background: rgba(168,168,160,.15); color: var(--faint); }
.badge.novo { background: rgba(198,242,78,.15); color: var(--lime); }
.badge.transferido { background: rgba(122, 162, 247, .15); color: #7aa2f7; }

.tooltip { position: relative; display: inline-flex; vertical-align: middle; margin-left: .3rem; }
.tooltip-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 15px; height: 15px; border-radius: 50%;
  background: var(--bg-2); border: 1px solid var(--line-2); color: var(--faint);
  font-size: .68rem; font-weight: 700; cursor: help; line-height: 1;
}
.tooltip:hover .tooltip-icon, .tooltip:focus-within .tooltip-icon { border-color: var(--lime); color: var(--lime); }
.tooltip-box {
  position: absolute; bottom: calc(100% + 8px); left: 50%; transform: translateX(-50%) translateY(4px);
  width: 230px; padding: .6rem .75rem;
  background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 8px;
  color: var(--muted); font-size: .78rem; font-weight: 400; line-height: 1.5;
  text-transform: none; letter-spacing: normal;
  box-shadow: 0 10px 25px rgba(0,0,0,.4);
  opacity: 0; visibility: hidden; pointer-events: none;
  transition: opacity .15s, transform .15s;
  z-index: 20;
}
.tooltip-box::after {
  content: ''; position: absolute; top: 100%; left: 50%; transform: translateX(-50%);
  border: 6px solid transparent; border-top-color: var(--panel-2);
}
.tooltip:hover .tooltip-box, .tooltip:focus-within .tooltip-box { opacity: 1; visibility: visible; transform: translateX(-50%) translateY(0); }

.stage-body { display: none; padding-top: .9rem; }
.stage-block.open .stage-body { display: block; }

.var-chips { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .5rem; margin-bottom: .8rem; }
.chip {
  display: inline-flex; align-items: center; gap: .3rem;
  padding: .35rem .7rem; border-radius: 999px; font-size: .8rem; font-weight: 600;
  background: var(--bg-2); border: 1px dashed var(--line-2); color: var(--ink);
  cursor: grab; user-select: none;
}
.chip:hover { border-color: var(--lime); color: var(--lime); }
.chip:active { cursor: grabbing; }

.rich-editor {
  width: 100%;
  min-height: 90px;
  padding: .7rem .85rem;
  background: var(--bg-2);
  border: 1px solid var(--line-2);
  border-radius: 10px;
  color: var(--ink);
  font-size: .95rem;
  font-family: inherit;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}
.rich-editor:focus { outline: none; border-color: var(--lime); }
.rich-editor:empty::before {
  content: attr(data-placeholder);
  color: var(--faint);
}
.rich-editor.drop-target { border-color: var(--lime); }

.tag-chip-inline {
  display: inline-flex; align-items: center;
  vertical-align: middle;
  padding: .15rem .6rem; margin: 0 .15rem;
  border-radius: 999px; font-size: .82rem; font-weight: 700;
  background: var(--lime); color: var(--lime-ink);
  line-height: 1.4;
  user-select: none;
}

.empty-state {
  text-align: center; padding: 2rem 1rem; color: var(--faint); font-size: .88rem;
}
