:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #eef1f7;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --accent: #0e7c66;
  --accent-ink: #ffffff;
  --danger: #c2410c;
  --warn: #b45309;
  --ok: #15803d;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 16px rgba(15, 23, 42, .05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1120; --surface: #111a2e; --surface-2: #18233b; --text: #e5e9f2; --muted: #94a3b8;
    --border: #23314f; --accent: #2bb596; --accent-ink: #04221b; --danger: #fb923c; --warn: #fbbf24; --ok: #4ade80;
    --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(64px + env(safe-area-inset-bottom));
}
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }

.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; text-decoration: none; color: var(--text); letter-spacing: -.01em; }
.brand span { color: var(--accent); margin-left: 2px; }
.who { color: var(--muted); font-size: 12px; }

main { max-width: 860px; margin: 0 auto; padding: 16px; }
h1 { font-size: 20px; margin: 0 0 4px; letter-spacing: -.01em; }
h2 { font-size: 15px; margin: 20px 0 8px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 5; display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--surface); border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a { text-align: center; padding: 14px 4px; text-decoration: none; color: var(--muted); font-size: 13px; font-weight: 600; }
.tabbar a.active { color: var(--accent); }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 6px 12px;
  font-size: 13px; cursor: pointer; white-space: nowrap;
}
.chip b { margin-left: 6px; color: var(--muted); font-weight: 600; }
.chip.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.chip.active b { color: inherit; }

.search { width: 100%; padding: 11px 14px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); margin-bottom: 12px; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px; margin-bottom: 10px;
}
.lead-card { display: block; text-decoration: none; color: inherit; }
.row { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.meta { color: var(--muted); font-size: 13px; }
.name { font-weight: 650; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }

.badge { display: inline-block; font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); letter-spacing: .02em; }
.badge.s-NEW { color: #2563eb; } .badge.s-CONTACTED { color: #7c3aed; } .badge.s-REPLIED { color: #0891b2; }
.badge.s-NEGOTIATING { color: var(--warn); } .badge.s-AWAITING_DEPOSIT, .badge.s-AWAITING_FINAL { color: #db2777; }
.badge.s-BUILDING, .badge.s-REVIEW { color: #0d9488; } .badge.s-DONE { color: var(--ok); } .badge.s-LOST { color: var(--danger); }
.pill-paused { color: var(--danger); font-weight: 600; font-size: 12px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 8px 14px;
  border-radius: 10px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; text-decoration: none;
  color: var(--text); font-weight: 600; font-size: 14px;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--danger); }
.btn:disabled, .btn.primary:disabled { background: var(--surface-2); border-color: var(--border); color: var(--muted); opacity: .7; cursor: not-allowed; }
.btn.wa { background: #25d366; border-color: #25d366; color: #052e16; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin: 16px 0 12px; overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 10px 12px; cursor: pointer; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.active { color: var(--accent); border-color: var(--accent); }

.chat { display: flex; flex-direction: column; gap: 6px; }
.bubble { max-width: 82%; padding: 8px 12px; border-radius: 14px; white-space: pre-wrap; word-break: break-word; font-size: 14px; }
.bubble.in { align-self: flex-start; background: var(--surface); border: 1px solid var(--border); }
.bubble.out { align-self: flex-end; background: var(--accent); color: var(--accent-ink); }
.bubble small { display: block; opacity: .7; font-size: 11px; margin-top: 2px; }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; font-size: 14px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; word-break: break-word; }

label.field { display: block; margin-bottom: 12px; font-size: 13px; color: var(--muted); }
label.field input, label.field textarea, label.field select, textarea.full {
  display: block; width: 100%; margin-top: 4px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-size: 15px;
}
textarea.full { min-height: 160px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.inline { display: flex; gap: 8px; align-items: end; }
.inline label.field { flex: 1; margin: 0; }

.empty { color: var(--muted); text-align: center; padding: 32px 0; }
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.thumbs a { display: block; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: var(--surface-2); border: 1px solid var(--border); }
.thumbs img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumbs .doc { display: flex; align-items: center; justify-content: center; font-size: 12px; color: var(--muted); height: 100%; padding: 4px; text-align: center; }

.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 10; margin: 0 auto; max-width: 480px;
  background: var(--text); color: var(--bg); padding: 12px 14px; border-radius: 12px; font-size: 14px; box-shadow: var(--shadow);
}
.toast.error { background: var(--danger); color: #fff; }
.skips li { font-size: 13px; color: var(--muted); }
