:root {
  --bg: #f5f4f0;
  --surface: #ffffff;
  --surface-2: #efeee8;
  --text: #1c1b18;
  --muted: #6b6860;
  --line: #e2e0d8;
  --accent: #0e7c66;
  --accent-ink: #ffffff;
  --accent-soft: #e0f1ec;
  --warn: #9a5b07;
  --warn-soft: #fbefd9;
  --danger: #b42318;
  --danger-soft: #fdeceb;
  --info: #2f4fb5;
  --info-soft: #e8edfb;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(20, 20, 15, .06), 0 4px 14px rgba(20, 20, 15, .05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121211;
    --surface: #1c1b19;
    --surface-2: #262521;
    --text: #ecebe6;
    --muted: #a3a097;
    --line: #34322d;
    --accent: #43c3a2;
    --accent-ink: #062a21;
    --accent-soft: #16352d;
    --warn: #f0b25a;
    --warn-soft: #3a2b12;
    --danger: #f18a80;
    --danger-soft: #3d1a17;
    --info: #9db2f5;
    --info-soft: #1d2540;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--accent); }
button, input, textarea, select { font: inherit; color: inherit; }
input, textarea, select { font-size: 16px; } /* evita zoom no iPhone */

.shell { max-width: 640px; margin: 0 auto; min-height: 100vh; padding-bottom: calc(84px + env(safe-area-inset-bottom)); }

/* topo */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
}
.top h1 { font-size: 24px; line-height: 1.15; margin: 0; flex: 1; letter-spacing: -0.01em; }
.top .sub { display: block; font-size: 13px; font-weight: 400; color: var(--muted); letter-spacing: 0; margin-top: 2px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); display: grid; place-items: center; cursor: pointer;
}
.icon-btn svg { width: 20px; height: 20px; }

main { padding: 4px 16px 16px; }

/* navegação de baixo */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: flex; justify-content: center;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs-in { display: flex; width: 100%; max-width: 640px; }
.tab {
  flex: 1; border: 0; background: none; padding: 8px 2px 10px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  color: var(--muted); font-size: 11px; font-weight: 500; position: relative;
}
.tab svg { width: 24px; height: 24px; }
.tab.on { color: var(--accent); }
.badge {
  position: absolute; top: 4px; left: calc(50% + 6px);
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--danger); color: #fff; font-size: 11px; font-weight: 700; line-height: 18px; text-align: center;
}

/* blocos */
.sec { margin: 18px 0 8px; font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; display: flex; justify-content: space-between; align-items: baseline; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; margin: 10px 0; box-shadow: var(--shadow);
}
.card.compact { padding: 12px 14px; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.strong { font-weight: 600; }
.title { font-weight: 650; font-size: 17px; line-height: 1.25; }
.clamp2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.mt8 { margin-top: 8px; } .mt12 { margin-top: 12px; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.chip.accent { background: var(--accent-soft); color: var(--accent); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.danger { background: var(--danger-soft); color: var(--danger); }
.chip.info { background: var(--info-soft); color: var(--info); }

.quote {
  margin-top: 10px; padding: 10px 12px; border-radius: 12px;
  background: var(--surface-2); white-space: pre-wrap; word-break: break-word;
}
.quote .label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 2px; }
.fixed-text { margin-top: 10px; padding: 10px 12px; border-radius: 12px; border: 1px dashed var(--line); white-space: pre-wrap; }
.note { margin-top: 10px; font-size: 13px; color: var(--muted); }
.note.warn { color: var(--warn); }

.lead-line { margin-top: 6px; font-size: 14px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 12px; }
.lead-line a { text-decoration: none; }

label.field { display: block; margin-top: 12px; font-size: 13px; font-weight: 600; color: var(--muted); }
label.field > span { display: block; margin-bottom: 4px; }
textarea, input[type=text], input[type=url], input[type=password], input[type=datetime-local], input[type=search], select {
  width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 10px 12px; color: var(--text);
}
textarea { min-height: 92px; resize: vertical; line-height: 1.4; }
textarea:focus, input:focus, select:focus { outline: 2px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 0; border-color: transparent; }

.actions { display: flex; gap: 8px; margin-top: 12px; }
.btn {
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  padding: 11px 14px; border-radius: 12px; font-weight: 600; cursor: pointer; flex: 1; min-height: 44px;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { color: var(--danger); }
.btn.ghost { background: transparent; }
.btn.small { flex: 0 0 auto; padding: 7px 12px; min-height: 36px; font-size: 14px; }
.btn:disabled { opacity: .45; cursor: default; }

.empty { text-align: center; padding: 48px 16px; color: var(--muted); }
.empty svg { width: 44px; height: 44px; color: var(--accent); opacity: .8; }
.empty .title { color: var(--text); margin: 8px 0 4px; }

.banner { background: var(--info-soft); color: var(--info); border-radius: 12px; padding: 10px 12px; margin-top: 8px; font-size: 14px; font-weight: 500; }
.banner.accent { background: var(--accent-soft); color: var(--accent); }
.banner .btn { margin-top: 8px; }

/* etapas (abas do CRM) */
.stages { display: flex; gap: 6px; overflow-x: auto; margin: 0 -16px; padding: 4px 16px 10px; scrollbar-width: none; }
.stages::-webkit-scrollbar { display: none; }
.stage {
  flex: 0 0 auto; border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 7px 12px; font-size: 14px; font-weight: 600; cursor: pointer; color: var(--muted);
}
.stage .n { margin-left: 6px; font-weight: 700; color: var(--text); }
.stage.on { background: var(--text); border-color: var(--text); color: var(--bg); }
.stage.on .n { color: var(--bg); }

.lead-item { cursor: pointer; }
.lead-item:active { transform: scale(.995); }

/* painel deslizante (detalhe do lead) */
.overlay { position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, .35); display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  width: 100%; max-width: 640px; max-height: 92vh; overflow-y: auto;
  background: var(--bg); border-radius: 20px 20px 0 0; padding: 8px 16px calc(24px + env(safe-area-inset-bottom));
}
.grabber { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 10px; }
.kv { display: grid; grid-template-columns: 76px minmax(0, 1fr); gap: 6px 10px; font-size: 15px; align-items: center; }
.kv .k { color: var(--muted); font-size: 14px; }
.kv .row { min-width: 0; }
.kv .grow { overflow-wrap: anywhere; }
.timeline { margin: 0; padding: 0; list-style: none; font-size: 14px; }
.timeline li { padding: 6px 0; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 8px; }
.timeline li:last-child { border-bottom: 0; }

/* conversa */
.chat { display: flex; flex-direction: column; gap: 8px; padding-bottom: 76px; }
.msg { max-width: 82%; padding: 9px 12px; border-radius: 16px; white-space: pre-wrap; word-break: break-word; }
.msg.ia { background: var(--surface); border: 1px solid var(--line); align-self: flex-start; border-bottom-left-radius: 6px; }
.msg.giovanna { background: var(--accent); color: var(--accent-ink); align-self: flex-end; border-bottom-right-radius: 6px; }
.msg .when { display: block; font-size: 11px; opacity: .7; margin-top: 3px; }
.composer {
  position: fixed; left: 0; right: 0; bottom: calc(62px + env(safe-area-inset-bottom)); z-index: 5;
  display: flex; justify-content: center; background: var(--bg); border-top: 1px solid var(--line);
}
.composer-in { display: flex; gap: 8px; width: 100%; max-width: 640px; padding: 8px 16px; }
.composer textarea { min-height: 44px; max-height: 140px; height: 44px; }
.composer .btn { flex: 0 0 auto; }

/* placar */
.var-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.big { font-size: 30px; font-weight: 700; letter-spacing: -0.02em; line-height: 1; }
.funnel { margin-top: 10px; display: grid; gap: 6px; }
.fl { display: grid; grid-template-columns: 118px 1fr 64px; gap: 8px; align-items: center; font-size: 13px; }
.bar { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.fl .v { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
.progress { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; margin-top: 6px; }
.progress > i { display: block; height: 100%; background: var(--accent); }

.switch { position: relative; width: 50px; height: 30px; flex: 0 0 auto; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; border-radius: 15px; background: var(--line); transition: .2s; cursor: pointer; }
.switch span::after { content: ""; position: absolute; width: 24px; height: 24px; left: 3px; top: 3px; border-radius: 50%; background: #fff; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(20px); }

/* login */
.login { max-width: 360px; margin: 0 auto; padding: calc(64px + env(safe-area-inset-top)) 24px 24px; text-align: center; }
.login img { width: 72px; height: 72px; border-radius: 18px; }
.login h1 { font-size: 26px; margin: 14px 0 4px; }
.login form { margin-top: 24px; text-align: left; }
.login .btn { width: 100%; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(96px + env(safe-area-inset-bottom)); z-index: 30;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; font-weight: 500;
  max-width: calc(100% - 32px); box-shadow: 0 6px 20px rgba(0,0,0,.18);
}
.toast.err { background: var(--danger); color: #fff; }
.spin { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
