:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #1c2430;
  --muted: #667085;
  --border: #d9dee6;
  --primary: #1f5fd1;
  --primary-dark: #184aa6;
  --danger: #c0362c;
  --radius: 8px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--primary); }
h1 { font-size: 1.6rem; margin: 0 0 0.5rem; }
h2 { font-size: 1rem; margin: 1.25rem 0 0.5rem; }
h2:first-child { margin-top: 0; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar nav { display: flex; align-items: center; gap: 1rem; }
.brand { font-weight: 700; color: var(--text); text-decoration: none; }

main { margin: 0 auto; padding: 1.5rem 1rem 3rem; }
main.narrow { max-width: 640px; }
main.wide { max-width: 1200px; }

.card, .panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
}
.card.small { max-width: 380px; margin: 2rem auto; }
.card.center { text-align: center; }
.lead-text { color: var(--muted); margin-top: 0; }
.muted { color: var(--muted); font-size: 0.875rem; }
.nowrap { white-space: nowrap; }
.break { overflow-wrap: anywhere; }

/* Forms */
.field { margin-bottom: 1rem; flex: 1; min-width: 0; }
.row { display: flex; gap: 1rem; }
label { display: block; font-weight: 600; font-size: 0.9rem; margin-bottom: 0.25rem; }
.check label { font-weight: 400; }
.req { color: var(--danger); }

input[type="text"], input[type="email"], input[type="tel"], input[type="password"],
input[type="search"], input[type="date"], select, textarea {
  width: 100%;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  font: inherit;
}
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}
input[aria-invalid="true"] { border-color: var(--danger); }
.field-error { color: var(--danger); font-size: 0.85rem; margin: 0.25rem 0 0; }

.consent-note { margin: 0.75rem 0 0; }
.hp { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }

button, .button {
  display: inline-block;
  padding: 0.55rem 1rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}
button.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
button.primary:hover { background: var(--primary-dark); }
button.danger { background: #fff; border-color: var(--danger); color: var(--danger); }
button.danger:hover { background: var(--danger); color: #fff; }
button.link { border: 0; background: none; padding: 0; color: var(--primary); text-decoration: underline; }
form.inline { display: inline; }

.alert { padding: 0.65rem 0.85rem; border-radius: 6px; }
.alert.error { background: #fdecea; color: #8a231b; border: 1px solid #f3c1bc; }

/* Dashboard */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 0.75rem; margin: 1rem 0; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.9rem 1rem; }
.tile-num { display: block; font-size: 1.6rem; font-weight: 700; }
.tile-label { color: var(--muted); font-size: 0.85rem; }

.summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 0.75rem; margin-bottom: 1.25rem; }
.summary .panel { padding: 1rem; }
ul.plain { list-style: none; margin: 0; padding: 0; }
ul.plain li { display: flex; justify-content: space-between; gap: 0.5rem; padding: 0.2rem 0; }

.filters { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; margin-bottom: 0.75rem; }
.filters input[type="search"] { flex: 2 1 240px; width: auto; }
.filters select, .filters input[type="date"] { width: auto; }
.inline-label { display: flex; align-items: center; gap: 0.35rem; margin: 0; font-weight: 400; }

.section-title { margin: 1.5rem 0 0.5rem; }
.bulk-bar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 0.5rem; min-height: 2.5rem; }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.danger:disabled:hover { background: #fff; color: var(--danger); }
button.link.danger-link { color: var(--danger); }
th.tick, td.tick { width: 2rem; }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: 0.925rem; }
th, td { text-align: left; padding: 0.6rem 0.75rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); background: #fafbfc; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafbfc; }

.badge { display: inline-block; padding: 0.1rem 0.5rem; border-radius: 999px; font-size: 0.78rem; font-weight: 600; white-space: nowrap; background: #eef1f5; color: #344054; }
.band-hot { background: #fde4e1; color: #a1281e; }
.band-warm { background: #fdf0d5; color: #8a5a00; }
.band-cold { background: #e3effd; color: #1b4f9c; }
.status-new { background: #e3effd; color: #1b4f9c; }
.status-contacted { background: #ece8fd; color: #4b3aa8; }
.status-qualified { background: #fdf0d5; color: #8a5a00; }
.status-won { background: #dff5e6; color: #1a6b38; }
.status-lost { background: #eef1f5; color: #586174; }
.overdue { color: var(--danger); font-weight: 600; }

.pager { display: flex; align-items: center; justify-content: center; gap: 1rem; margin-top: 1rem; }
.empty { padding: 2rem; text-align: center; color: var(--muted); background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius); }

/* Lead detail */
.detail-head { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; margin-bottom: 1rem; }
.detail-head h1 { margin: 0 0.5rem 0 0; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; align-items: start; }
dl { display: grid; grid-template-columns: 8.5rem 1fr; gap: 0.35rem 0.75rem; margin: 0; }
dt { color: var(--muted); }
dd { margin: 0; min-width: 0; }
.message { white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; }
.stack-row { display: flex; gap: 0.5rem; }
.panel textarea { margin-bottom: 0.5rem; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 0.6rem 0 0.6rem 0.75rem; border-left: 3px solid var(--border); margin-bottom: 0.5rem; }
.timeline li.kind-note { border-left-color: var(--primary); }
.timeline li.kind-repeat { border-left-color: #d08a00; }
.timeline li.kind-email { border-left-color: var(--danger); }
.head-actions { margin-left: auto; display: flex; gap: 0.5rem; }
.button.whatsapp { border-color: #1a8f4c; color: #14713c; }
.alert.info { background: #eaf2fe; color: #173f7d; border: 1px solid #c3d8f8; }
.danger-zone { margin-top: 1.5rem; padding-top: 1rem; border-top: 1px solid var(--border); }

@media (max-width: 760px) {
  .row, .detail-grid { display: block; }
  dl { grid-template-columns: 1fr; }
  dt { margin-top: 0.4rem; }
}
