:root {
  --bg: #f3f5f4;
  --surface: #ffffff;
  --surface-2: #eef1f0;
  --text: #15201c;
  --muted: #64716c;
  --line: #dde3e0;
  --primary: #0b7a5f;
  --primary-ink: #ffffff;
  --primary-soft: #dff2ea;
  --accent: #c2417a;
  --accent-soft: #fbe6ef;
  --warn: #9a5b00;
  --warn-soft: #fff1d6;
  --danger: #c0392b;
  --bubble-in: #ffffff;
  --bubble-out: #d9fdd3;
  --chat-bg: #ece5dd;
  --shadow: 0 8px 30px rgba(0, 0, 0, .12);
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1513; --surface: #17201d; --surface-2: #1f2a26; --text: #e7eeeb; --muted: #93a39d; --line: #2a3632;
    --primary: #20b087; --primary-ink: #04140f; --primary-soft: #143a2f; --accent: #f07aae; --accent-soft: #3a1d2a;
    --warn: #f0b552; --warn-soft: #3a2c12; --danger: #ff6b5e; --bubble-in: #1f2a26; --bubble-out: #13493a; --chat-bg: #0b100e;
    --shadow: 0 8px 30px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text);
  overscroll-behavior-y: none;
}
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--primary); }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

#app { min-height: 100%; padding-bottom: calc(64px + var(--safe-b)); }
#app.no-tabs { padding-bottom: 0; }

/* ---------- topo ---------- */
.top {
  position: sticky; top: 0; z-index: 5;
  background: var(--primary); color: var(--primary-ink);
  padding: calc(10px + var(--safe-t)) 16px 10px;
  display: flex; align-items: center; gap: 10px;
}
.top h1 { font-size: 19px; margin: 0; flex: 1; font-weight: 700; letter-spacing: -.2px; }
.top .sub { font-size: 12px; opacity: .85; font-weight: 400; }
.top .titles { flex: 1; min-width: 0; }
.top .titles h1 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 17px; }
.icon-btn {
  background: none; border: 0; color: inherit; padding: 8px; margin: -8px; border-radius: 50%;
  display: inline-flex; cursor: pointer;
}
.icon-btn:active { background: rgba(0,0,0,.12); }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; background: #f4c542; }
.dot.on { background: #7dffb5; }
.dot.off { background: #ff8a80; }

.page { padding: 12px 16px 24px; max-width: 760px; margin: 0 auto; }
.search {
  width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 10px 16px; outline: none;
}
.search:focus { border-color: var(--primary); }

/* ---------- tabs ---------- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
}
.tabs[hidden] { display: none; }
.tabs a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 6px;
  color: var(--muted); text-decoration: none; font-size: 11px; position: relative;
}
.tabs a.active { color: var(--primary); font-weight: 600; }
.tabs b {
  position: absolute; top: 4px; left: calc(50% + 6px); background: var(--accent); color: #fff;
  font-size: 10px; min-width: 17px; height: 17px; border-radius: 9px; padding: 0 4px;
  display: grid; place-items: center;
}

/* ---------- listas ---------- */
.list { background: var(--surface); border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); }
.row {
  display: flex; gap: 12px; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--line);
  text-decoration: none; color: inherit; cursor: pointer; background: none; width: 100%; text-align: left; border-left: 0; border-right: 0; border-top: 0;
}
.row:last-child { border-bottom: 0; }
.row:active { background: var(--surface-2); }
.row .main { flex: 1; min-width: 0; }
.row .title { font-weight: 600; display: flex; gap: 6px; align-items: center; }
.row .title span.name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .line2 { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .side { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; font-size: 12px; color: var(--muted); flex-shrink: 0; }
.avatar {
  width: 44px; height: 44px; border-radius: 50%; background: var(--primary-soft); color: var(--primary);
  display: grid; place-items: center; font-weight: 700; flex-shrink: 0;
}
.unread { background: var(--primary); color: var(--primary-ink); border-radius: 999px; font-size: 11px; font-weight: 700; padding: 1px 7px; }
.tag { font-size: 10.5px; font-weight: 700; padding: 1px 6px; border-radius: 6px; background: var(--accent-soft); color: var(--accent); flex-shrink: 0; text-transform: uppercase; letter-spacing: .3px; }
.tag.green { background: var(--primary-soft); color: var(--primary); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.gray { background: var(--surface-2); color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 40px 20px; }
.empty b { display: block; color: var(--text); font-size: 16px; margin-bottom: 6px; }
.section-title { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; margin: 18px 4px 8px; }

/* ---------- botões ---------- */
.btn {
  border: 0; border-radius: 12px; padding: 11px 16px; font-weight: 600; cursor: pointer;
  background: var(--surface-2); color: var(--text); display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn.primary { background: var(--primary); color: var(--primary-ink); }
.btn.danger { background: none; color: var(--danger); border: 1px solid var(--line); }
.btn.ghost { background: none; border: 1px solid var(--line); }
.btn.block { width: 100%; }
.btn.small { padding: 7px 12px; font-size: 13px; border-radius: 10px; }
.btn:disabled { opacity: .5; }
.btn:active:not(:disabled) { transform: scale(.98); }
.fab {
  position: fixed; right: 16px; bottom: calc(76px + var(--safe-b)); z-index: 6;
  width: 56px; height: 56px; border-radius: 18px; border: 0; background: var(--primary); color: var(--primary-ink);
  box-shadow: var(--shadow); display: grid; place-items: center; cursor: pointer;
}
.fab svg { width: 26px; height: 26px; }
.seg { display: flex; background: var(--surface-2); border-radius: 12px; padding: 3px; gap: 3px; margin-bottom: 12px; overflow-x: auto; scrollbar-width: none; }
.seg button { flex: 1; border: 0; background: none; padding: 8px 10px; border-radius: 9px; font-weight: 600; color: var(--muted); cursor: pointer; white-space: nowrap; font-size: 13.5px; }
.seg button.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.1); }

/* ---------- conversa ---------- */
.chat-wrap { display: flex; flex-direction: column; height: 100dvh; }
.chat {
  flex: 1; overflow-y: auto; background: var(--chat-bg); padding: 12px 12px 8px;
  display: flex; flex-direction: column; gap: 4px;
}
.bubble {
  max-width: 82%; padding: 6px 10px 4px; border-radius: 10px; background: var(--bubble-in);
  box-shadow: 0 1px 1px rgba(0,0,0,.08); white-space: pre-wrap; word-wrap: break-word; font-size: 14.5px;
}
.bubble.me { align-self: flex-end; background: var(--bubble-out); }
.bubble time { display: block; text-align: right; font-size: 10.5px; color: var(--muted); margin-top: 1px; }
.day { align-self: center; background: var(--surface); color: var(--muted); font-size: 11.5px; padding: 3px 10px; border-radius: 8px; margin: 8px 0; }
.runs-bar { background: var(--surface); border-top: 1px solid var(--line); }
.run-card { padding: 10px 14px; display: flex; gap: 10px; align-items: center; border-bottom: 1px solid var(--line); }
.run-card .main { flex: 1; min-width: 0; }
.run-card .title { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.run-card .phase { font-size: 12.5px; color: var(--primary); }
.run-card .phase.sched { color: var(--muted); }
.progress { height: 4px; background: var(--surface-2); border-radius: 2px; overflow: hidden; margin-top: 5px; }
.progress i { display: block; height: 100%; background: var(--primary); transition: width .4s; }
.pulse { animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .45; } }
.composer {
  display: flex; gap: 8px; align-items: flex-end; padding: 8px 10px calc(8px + var(--safe-b));
  background: var(--surface); border-top: 1px solid var(--line);
}
.composer textarea {
  flex: 1; resize: none; border: 1px solid var(--line); border-radius: 20px; padding: 9px 14px; max-height: 120px;
  background: var(--bg); outline: none; min-height: 40px;
}
.funnel-btn {
  height: 42px; border-radius: 21px; border: 0; padding: 0 16px; background: var(--accent); color: #fff; font-weight: 700;
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer; flex-shrink: 0;
}
.funnel-btn svg { width: 20px; height: 20px; }
.round-btn { width: 42px; height: 42px; border-radius: 50%; border: 0; background: var(--primary); color: var(--primary-ink); display: grid; place-items: center; flex-shrink: 0; cursor: pointer; }

/* ---------- bottom sheet ---------- */
.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 20; animation: fade .15s; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; background: var(--surface);
  border-radius: 20px 20px 0 0; max-height: 88dvh; display: flex; flex-direction: column;
  box-shadow: var(--shadow); animation: up .2s ease-out; max-width: 760px; margin: 0 auto;
  padding-bottom: var(--safe-b);
}
.sheet .grab { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 8px auto 2px; flex-shrink: 0; }
.sheet header { padding: 8px 16px 10px; display: flex; align-items: center; gap: 10px; }
.sheet header h2 { margin: 0; font-size: 17px; flex: 1; }
.sheet .body { overflow-y: auto; padding: 0 16px 16px; flex: 1; }
.sheet .foot { padding: 10px 16px 14px; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; }
@keyframes up { from { transform: translateY(40px); opacity: .4; } }
@keyframes fade { from { opacity: 0; } }

.pick { display: flex; align-items: center; gap: 10px; padding: 11px 12px; border-radius: 12px; cursor: pointer; border: 0; background: none; width: 100%; text-align: left; }
.pick:active { background: var(--surface-2); }
.pick .main { flex: 1; min-width: 0; }
.pick .name { font-weight: 600; font-size: 14.5px; }
.pick .meta { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kind {
  width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; flex-shrink: 0;
  background: var(--primary-soft); color: var(--primary);
}
.kind svg { width: 18px; height: 18px; }
.kind.audio { background: #e3edff; color: #2f62d6; }
.kind.media { background: var(--accent-soft); color: var(--accent); }
.kind.doc { background: var(--warn-soft); color: var(--warn); }
@media (prefers-color-scheme: dark) { .kind.audio { background: #1b2a4a; color: #8db0ff; } }

.steps { list-style: none; padding: 0; margin: 0; }
.steps li { display: flex; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px dashed var(--line); }
.steps li:last-child { border-bottom: 0; }
.steps .wait { font-size: 12px; color: var(--muted); white-space: nowrap; }
.warnbox { background: var(--warn-soft); color: var(--warn); border-radius: 12px; padding: 10px 12px; font-size: 13.5px; margin: 8px 0; }
.infobox { background: var(--primary-soft); color: var(--text); border-radius: 12px; padding: 10px 12px; font-size: 13.5px; margin: 8px 0; }

/* ---------- formulários ---------- */
label.field { display: block; margin: 12px 0; }
label.field > span { display: block; font-size: 12.5px; color: var(--muted); font-weight: 600; margin-bottom: 5px; }
.input, textarea.input, select.input {
  width: 100%; border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 10px 12px; outline: none;
}
.input:focus { border-color: var(--primary); }
textarea.input { min-height: 120px; resize: vertical; }
.check { display: flex; gap: 10px; align-items: flex-start; padding: 10px 0; cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--primary); margin: 1px 0 0; flex-shrink: 0; }
.check small { display: block; color: var(--muted); font-size: 12.5px; }
.row-inline { display: flex; gap: 8px; align-items: center; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.card h3 { margin: 0 0 4px; font-size: 16px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.qr { display: block; margin: 12px auto; width: 240px; max-width: 100%; background: #fff; padding: 8px; border-radius: 12px; }
.code { font: 700 28px/1 ui-monospace, Menlo, monospace; letter-spacing: 3px; text-align: center; padding: 16px; background: var(--surface-2); border-radius: 12px; margin: 12px 0; user-select: all; }
audio { width: 100%; height: 40px; margin-top: 6px; }
.media-preview { max-width: 100%; max-height: 260px; border-radius: 10px; display: block; margin: 8px 0; }

.edit-step { display: flex; gap: 8px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.edit-step .main { flex: 1; min-width: 0; }
.edit-step .name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.edit-step .delay { display: flex; align-items: center; gap: 4px; font-size: 12.5px; color: var(--muted); margin-top: 3px; }
.edit-step .delay input { width: 64px; padding: 4px 6px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.edit-step .ctl { display: flex; flex-direction: column; gap: 2px; }
.edit-step .ctl button { border: 0; background: var(--surface-2); border-radius: 8px; width: 32px; height: 26px; cursor: pointer; display: grid; place-items: center; }
.edit-step .ctl svg { width: 16px; height: 16px; }

.rec { display: flex; align-items: center; gap: 10px; }
.rec .dotrec { width: 12px; height: 12px; background: var(--danger); border-radius: 50%; animation: pulse 1s infinite; }

#toast {
  position: fixed; left: 50%; bottom: calc(84px + var(--safe-b)); transform: translateX(-50%) translateY(20px);
  background: #1c2522; color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px; opacity: 0; pointer-events: none;
  transition: .2s; z-index: 50; max-width: calc(100% - 32px); text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%); }
#toast.err { background: var(--danger); }

.login { max-width: 360px; margin: 0 auto; padding: 18vh 24px 24px; }
.login .logo { width: 64px; height: 64px; border-radius: 18px; display: block; margin: 0 auto 12px; }
.login h1 { text-align: center; margin: 0 0 4px; }
.login p { text-align: center; color: var(--muted); margin: 0 0 24px; }
.hidden { display: none !important; }
