:root {
  --bg: #fafafa;
  --surface: #ffffff;
  --border: #e7e7e7;
  --border-strong: #d4d4d4;
  --text: #111111;
  --muted: #6b6b6b;
  --faint: #9a9a9a;
  --accent: #111111;
  --accent-text: #ffffff;
  --hover: #f4f4f4;
  --green: #16794a;
  --green-bg: #e9f6ef;
  --red: #b42318;
  --red-bg: #fdecea;
  --amber: #9a6100;
  --amber-bg: #fdf3e1;
  --blue: #1d4ed8;
  --blue-bg: #eaf0fe;
  --radius: 10px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: Inter, system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
h1 { font-size: 22px; font-weight: 600; letter-spacing: -0.01em; margin: 0; }
h2 { font-size: 16px; font-weight: 600; margin: 0 0 4px; }
h3 { font-size: 14px; font-weight: 600; margin: 0 0 8px; }
p { margin: 0; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }
[hidden] { display: none !important; }

/* ---------- topo ---------- */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.topbar-inner { max-width: 1080px; margin: 0 auto; padding: 0 24px; height: 56px; display: flex; align-items: center; gap: 32px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; text-decoration: none; }
.brand-mark { width: 22px; height: 22px; border-radius: 6px; background: var(--accent); position: relative; }
.brand-mark::after { content: ''; position: absolute; inset: 6px 5px 6px 7px; background: #fff; clip-path: polygon(0 50%, 100% 0, 70% 100%); }
nav { display: flex; gap: 4px; flex: 1; }
nav a { text-decoration: none; color: var(--muted); padding: 6px 10px; border-radius: 6px; font-weight: 500; }
nav a:hover { color: var(--text); background: var(--hover); }
nav a.active { color: var(--text); background: var(--hover); }
.topbar-user { display: flex; align-items: center; gap: 14px; }
.topbar-user a { text-decoration: none; }

main { max-width: 1080px; margin: 0 auto; padding: 32px 24px 80px; }

/* ---------- elementos ---------- */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.page-head .sub { margin-top: 4px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.card-body { padding: 20px; }
.card + .card { margin-top: 16px; }
.stack > * + * { margin-top: 16px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.spacer { flex: 1; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 500; cursor: pointer;
  text-decoration: none; white-space: nowrap; transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--hover); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-primary:hover { background: #2a2a2a; }
.btn-danger { color: var(--red); }
.btn-danger:hover { background: var(--red-bg); border-color: #f3c3bd; }
.btn-sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn-link { background: none; border: 0; padding: 0; font: inherit; color: var(--muted); cursor: pointer; }
.btn-link:hover { color: var(--text); }

label.field { display: block; }
label.field > span { display: block; font-weight: 500; margin-bottom: 6px; }
label.field > small { display: block; color: var(--muted); margin-top: 6px; font-size: 12px; }
input[type=text], input[type=password], input[type=url], input[type=number], input[type=datetime-local], input[type=search], select, textarea {
  width: 100%; height: 38px; padding: 0 12px; border: 1px solid var(--border-strong); border-radius: 8px;
  background: var(--surface); font: inherit; color: var(--text); outline: none; transition: border-color .12s, box-shadow .12s;
}
textarea { height: auto; min-height: 110px; padding: 10px 12px; resize: vertical; }
select { appearance: none; padding-right: 32px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M3 4.5l3 3 3-3' fill='none' stroke='%236b6b6b' stroke-width='1.5'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; }
input:focus, select:focus, textarea:focus { border-color: var(--text); box-shadow: 0 0 0 3px rgba(17,17,17,.06); }

.choice { display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; border: 1px solid var(--border); border-radius: 8px; cursor: pointer; background: var(--surface); }
.choice:hover { border-color: var(--border-strong); }
.choice input { margin-top: 3px; accent-color: var(--accent); }
.choice.selected { border-color: var(--text); box-shadow: 0 0 0 1px var(--text) inset; }
.choice-list > * + * { margin-top: 8px; }

/* tabelas */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-weight: 500; color: var(--muted); font-size: 12px; padding: 10px 16px; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #fcfcfc; }

/* status */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 500; background: var(--hover); color: var(--muted); white-space: nowrap; }
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.green { background: var(--green-bg); color: var(--green); }
.badge.red { background: var(--red-bg); color: var(--red); }
.badge.amber { background: var(--amber-bg); color: var(--amber); }
.badge.blue { background: var(--blue-bg); color: var(--blue); }
.tag { display: inline-block; padding: 1px 7px; border-radius: 5px; background: var(--hover); color: var(--muted); font-size: 12px; }

.progress { height: 6px; background: #efefef; border-radius: 99px; overflow: hidden; display: flex; }
.progress > div { height: 100%; }
.progress .p-sent { background: var(--green); }
.progress .p-failed { background: var(--red); }
.progress .p-skipped { background: #c9c9c9; }

.stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; }
.stat { padding: 16px; }
.stat .num { font-size: 24px; font-weight: 600; letter-spacing: -0.02em; }
.stat .lbl { color: var(--muted); font-size: 12px; }

.alert { padding: 12px 14px; border-radius: 8px; font-size: 13px; }
.alert-warn { background: var(--amber-bg); color: #6b4400; }
.alert-error { background: var(--red-bg); color: var(--red); }
.alert-info { background: var(--hover); color: var(--muted); }

.empty { text-align: center; padding: 56px 20px; color: var(--muted); }
.empty h2 { color: var(--text); }

.tabs { display: inline-flex; background: var(--hover); padding: 3px; border-radius: 8px; gap: 2px; }
.tabs button { border: 0; background: none; padding: 6px 12px; border-radius: 6px; font: inherit; font-weight: 500; color: var(--muted); cursor: pointer; }
.tabs button.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

/* login */
.login-wrap { min-height: calc(100vh - 160px); display: grid; place-items: center; }
.login-card { width: 100%; max-width: 360px; }
.login-card .brand { justify-content: center; margin-bottom: 28px; font-size: 16px; }

/* wizard */
.steps { display: flex; gap: 0; margin-bottom: 28px; counter-reset: step; }
.steps .step { flex: 1; display: flex; align-items: center; gap: 10px; color: var(--faint); font-weight: 500; font-size: 13px; position: relative; padding-right: 12px; }
.steps .step::before { counter-increment: step; content: counter(step); width: 24px; height: 24px; flex: none; border-radius: 50%; border: 1px solid var(--border-strong); display: grid; place-items: center; font-size: 12px; background: var(--surface); }
.steps .step::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.steps .step:last-child::after { display: none; }
.steps .step.done { color: var(--muted); }
.steps .step.done::before { content: '✓'; background: var(--hover); }
.steps .step.current { color: var(--text); }
.steps .step.current::before { background: var(--accent); border-color: var(--accent); color: #fff; }
.wizard-foot { display: flex; justify-content: space-between; margin-top: 24px; }

.dropzone { border: 1.5px dashed var(--border-strong); border-radius: var(--radius); padding: 40px 20px; text-align: center; cursor: pointer; background: var(--surface); transition: border-color .12s, background .12s; }
.dropzone:hover, .dropzone.over { border-color: var(--text); background: #fcfcfc; }
.dropzone strong { display: block; margin-bottom: 4px; }

.map-row { display: grid; grid-template-columns: 1fr 1.4fr 180px; gap: 16px; align-items: center; padding: 12px 20px; border-bottom: 1px solid var(--border); }
.map-row:last-child { border-bottom: 0; }
.map-row .samples { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.option-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.option { padding: 16px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); cursor: pointer; text-align: left; font: inherit; color: inherit; }
.option:hover { border-color: var(--border-strong); }
.option.selected { border-color: var(--text); box-shadow: 0 0 0 1px var(--text) inset; }
.option:disabled { cursor: not-allowed; opacity: .55; }
.option .title { font-weight: 600; margin-bottom: 4px; word-break: break-word; }

.var-row { display: grid; grid-template-columns: 64px 1fr 1fr; gap: 12px; align-items: start; }
.var-row + .var-row { margin-top: 12px; }
.var-key { height: 38px; display: grid; place-items: center; background: var(--hover); border-radius: 8px; font-family: ui-monospace, monospace; font-size: 13px; }

.preview { background: #efeae2; border-radius: var(--radius); padding: 20px; min-height: 160px; }
.bubble { background: #fff; border-radius: 8px; padding: 8px 10px 6px; max-width: 360px; box-shadow: 0 1px 1px rgba(0,0,0,.06); white-space: pre-wrap; word-break: break-word; font-size: 13.5px; }
.bubble .b-head { font-weight: 600; margin-bottom: 4px; }
.bubble .b-foot { color: var(--muted); font-size: 12px; margin-top: 4px; }
.bubble .b-btn { border-top: 1px solid #eee; margin: 6px -10px -6px; padding: 8px; text-align: center; color: #0a84ff; font-weight: 500; }
.bubble .var { background: #fff4c2; border-radius: 3px; }
.bubble .var.missing { background: var(--red-bg); color: var(--red); }

.layout-2 { display: grid; grid-template-columns: 1.2fr 1fr; gap: 16px; align-items: start; }
.summary dt { color: var(--muted); font-size: 12px; }
.summary dd { margin: 2px 0 14px; font-weight: 500; }
.summary dd:last-child { margin-bottom: 0; }

#toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 100; }
#toast > div { background: var(--text); color: #fff; padding: 10px 16px; border-radius: 8px; font-size: 13px; box-shadow: 0 6px 24px rgba(0,0,0,.15); animation: up .18s ease-out; }
#toast > div.error { background: var(--red); }
@keyframes up { from { transform: translateY(8px); opacity: 0; } }

.spinner { width: 16px; height: 16px; border: 2px solid var(--border-strong); border-top-color: var(--text); border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading { padding: 48px; text-align: center; color: var(--muted); }

@media (max-width: 760px) {
  .topbar-inner { gap: 12px; padding: 0 16px; }
  main { padding: 24px 16px 64px; }
  .grid-2, .layout-2 { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .steps .step span { display: none; }
  .map-row { grid-template-columns: 1fr; gap: 6px; }
  .var-row { grid-template-columns: 48px 1fr; }
  .var-row > :last-child { grid-column: 2; }
  .topbar-user #me-name { display: none; }
}

/* ajustes */
.bubble { white-space: normal; }
.bubble > div { white-space: pre-wrap; }
.layout-2 > .card, .grid-2 > .card { margin-top: 0; }
.delivery { display: block; margin-top: 4px; }
@media (max-width: 760px) {
  .brand { font-size: 0; gap: 0; }
  nav { overflow-x: auto; }
  nav a { padding: 6px 8px; }
}
