:root {
  --bg: #f3f5f9; --card: #fff; --ink: #172033; --muted: #65708a; --line: #e2e6ef;
  --brand: #0f5bd8; --brand-ink: #fff; --green: #12805c; --amber: #b86e00; --red: #c8341f; --gray: #6b7385;
  --green-bg: #e3f5ec; --amber-bg: #fff2d9; --red-bg: #fde7e3; --gray-bg: #eef0f4;
  --radius: 10px; --shadow: 0 1px 2px rgba(20, 30, 60, .06), 0 2px 8px rgba(20, 30, 60, .05);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink); background: var(--bg); }
[x-cloak] { display: none !important; }
h2 { margin: 4px 0 6px; font-size: 22px; }
h3 { margin: 0 0 10px; font-size: 16px; }
h3 small { font-weight: 400; color: var(--muted); font-size: 13px; }
input, select, textarea { font: inherit; color: inherit; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: #fff; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--brand) 35%, transparent); border-color: var(--brand); }
textarea { resize: vertical; }
label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
code { font-size: 12px; background: var(--gray-bg); padding: 2px 5px; border-radius: 4px; word-break: break-all; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); }
th { font-size: 12px; color: var(--muted); font-weight: 600; }
td input { padding: 5px 7px; min-width: 70px; }
.table-wrap { overflow-x: auto; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.empty { color: var(--muted); font-size: 14px; margin: 6px 0; }
.error { color: var(--red); margin: 0; }

.btn { font: inherit; font-weight: 600; border: 1px solid var(--line); background: #fff; color: var(--ink); padding: 8px 14px; border-radius: 8px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: #c9cfdc; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.danger { color: var(--red); border-color: #f1c4bc; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: default; }
.link { background: none; border: 0; color: var(--brand); cursor: pointer; font: inherit; padding: 0; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 14px; }
.brand { font-weight: 800; font-size: 17px; display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.brand small { font-weight: 500; color: var(--muted); }
.brand.big { font-size: 22px; justify-content: center; margin-bottom: 8px; }
.logo { font-size: 1.1em; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(360px, 100%); display: grid; gap: 12px; }

/* topo */
.top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 16px; padding: 10px 16px; background: #fff; border-bottom: 1px solid var(--line); }
.tabs { display: flex; gap: 2px; overflow-x: auto; flex: 1; }
.tabs a { padding: 7px 12px; border-radius: 8px; color: var(--muted); text-decoration: none; font-weight: 600; white-space: nowrap; }
.tabs a.on { background: color-mix(in srgb, var(--brand) 10%, #fff); color: var(--brand); }
.badge { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 10px; background: var(--red); color: #fff; font-size: 12px; text-align: center; }
.who { display: flex; gap: 10px; align-items: center; font-size: 14px; white-space: nowrap; }
.wa-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.wa-dot.ok { background: #25d366; } .wa-dot.off { background: #c3c8d4; }

.view { padding: 16px; }
.view.narrow { max-width: 820px; margin: 0 auto; }
.toolbar { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar .search { flex: 1; min-width: 180px; }
.toolbar select { width: auto; }

/* quadro */
.board { display: grid; grid-template-columns: repeat(5, minmax(240px, 1fr)); gap: 12px; overflow-x: auto; padding-bottom: 8px; align-items: start; }
.col { background: #e9edf4; border-radius: var(--radius); padding: 8px; min-height: 200px; }
.col-head { display: flex; justify-content: space-between; font-weight: 700; padding: 4px 6px 8px; font-size: 14px; }
.col-head b { color: var(--muted); font-weight: 600; }
.col-fechado { background: #e0f1e9; } .col-perdido { background: #eceef2; }
.col-body { display: grid; gap: 8px; min-height: 120px; align-content: start; }
.lead-card { background: #fff; border-radius: 8px; padding: 10px; box-shadow: var(--shadow); cursor: pointer; border-left: 4px solid transparent; display: grid; gap: 4px; }
.lead-card:hover { box-shadow: 0 2px 12px rgba(20, 30, 60, .12); }
.lead-card.waiting { border-left-color: var(--amber); }
.lead-card.late { border-left-color: var(--red); }
.lead-card.fu { border-left-color: var(--amber); }
.lead-card.sortable-ghost { opacity: .4; }
.lc-top { display: flex; justify-content: space-between; gap: 6px; align-items: start; }
.lc-top strong { font-size: 14.5px; overflow: hidden; text-overflow: ellipsis; }
.lc-sub { font-size: 13px; color: var(--muted); }
.lc-msg { font-size: 13px; color: #3c4660; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.lc-status { display: flex; gap: 4px; flex-wrap: wrap; }
.tag { font-size: 11px; background: var(--gray-bg); color: var(--gray); padding: 1px 7px; border-radius: 10px; white-space: nowrap; }
.pill { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 10px; white-space: nowrap; }
.pill.red { background: var(--red-bg); color: var(--red); }
.pill.amber { background: var(--amber-bg); color: var(--amber); }
.pill.green { background: var(--green-bg); color: var(--green); }
.pill.gray { background: var(--gray-bg); color: var(--gray); }

/* para hoje */
.today-block { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 14px; }
.row-item { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); cursor: pointer; }
.row-item:first-of-type { border-top: 0; }

/* painel */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 14px; }
.kpi { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: grid; gap: 2px; }
.kpi span { font-size: 13px; color: var(--muted); }
.kpi b { font-size: 26px; }
.kpi small { color: var(--muted); font-size: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.bar-row { display: grid; grid-template-columns: 150px 1fr 34px; gap: 8px; align-items: center; font-size: 14px; margin: 5px 0; }
.bar { background: var(--gray-bg); height: 10px; border-radius: 5px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--brand); border-radius: 5px; }
.bar i.b-fechado { background: var(--green); } .bar i.b-perdido { background: #9aa1b2; }
.bar-row b { text-align: right; }

/* mensagens */
.tpl { display: grid; gap: 8px; }
.tpl-title { font-weight: 700; }
.tpl-actions { display: flex; gap: 6px; }
.plain { list-style: none; padding: 0; margin: 10px 0 0; display: grid; gap: 6px; font-size: 14px; }
.inline-form { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.inline-form input { flex: 1; min-width: 140px; }

/* gaveta */
.overlay { position: fixed; inset: 0; background: rgba(15, 22, 40, .35); z-index: 30; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100%); background: #fff; z-index: 31; box-shadow: -4px 0 24px rgba(15, 22, 40, .18); }
.drawer-inner { display: flex; flex-direction: column; height: 100%; }
.drawer-head { display: flex; justify-content: space-between; gap: 10px; padding: 14px 16px 8px; }
.drawer-head h3 { margin: 0; font-size: 19px; }
.close { font-size: 20px; color: var(--muted); }
.stage-bar { display: flex; gap: 4px; padding: 0 16px 10px; flex-wrap: wrap; }
.stage-btn { font: inherit; font-size: 12.5px; font-weight: 600; border: 1px solid var(--line); background: #fff; border-radius: 16px; padding: 4px 10px; cursor: pointer; color: var(--muted); }
.stage-btn.on { background: var(--brand); color: #fff; border-color: var(--brand); }
.stage-btn.on.s-fechado { background: var(--green); border-color: var(--green); }
.stage-btn.on.s-perdido { background: var(--gray); border-color: var(--gray); }
.subtabs { display: flex; border-bottom: 1px solid var(--line); padding: 0 16px; }
.subtabs button { font: inherit; font-weight: 600; background: none; border: 0; padding: 8px 12px; color: var(--muted); border-bottom: 2px solid transparent; cursor: pointer; }
.subtabs button.on { color: var(--brand); border-bottom-color: var(--brand); }
.chat-wrap { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.chat { flex: 1; overflow-y: auto; padding: 14px 16px; display: flex; flex-direction: column; gap: 6px; background: #f1ede6; }
.bubble { max-width: 82%; padding: 7px 10px; border-radius: 10px; white-space: pre-wrap; font-size: 14px; box-shadow: 0 1px 1px rgba(0,0,0,.06); }
.bubble.in { background: #fff; align-self: flex-start; border-top-left-radius: 2px; }
.bubble.out { background: #d8fdd2; align-self: flex-end; border-top-right-radius: 2px; }
.bubble small { display: block; text-align: right; color: var(--muted); font-size: 11px; margin-top: 2px; }
.composer { border-top: 1px solid var(--line); padding: 10px 16px 14px; display: grid; gap: 8px; }
.composer-actions { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.check { display: flex; gap: 6px; align-items: center; font-size: 13px; }
.check input { width: auto; }
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 14px 16px; overflow-y: auto; }
.fields .full { grid-column: 1 / -1; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.history { padding: 14px 16px; overflow-y: auto; display: grid; gap: 8px; align-content: start; }
.h-item { font-size: 14px; }

/* modais */
.modal { position: fixed; inset: 0; background: rgba(15, 22, 40, .4); z-index: 40; display: grid; place-items: center; padding: 16px; }
.modal-card { width: min(440px, 100%); display: grid; gap: 10px; margin: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font: inherit; border: 1px solid var(--line); background: #fff; border-radius: 16px; padding: 6px 12px; cursor: pointer; }
.chip:hover { border-color: var(--brand); color: var(--brand); }

.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: #172033; color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 50; max-width: calc(100% - 32px); font-size: 14px; }
.toast.err { background: var(--red); }

@media (max-width: 760px) {
  .top { flex-wrap: wrap; gap: 6px 12px; padding: 8px 12px; }
  .tabs { order: 3; flex-basis: 100%; }
  .who span:not(.wa-dot) { display: none; }
  .view { padding: 12px; }
  .board { grid-template-columns: repeat(5, 82vw); scroll-snap-type: x mandatory; }
  .col { scroll-snap-align: start; }
  .grid2 { grid-template-columns: 1fr; }
  .fields { grid-template-columns: 1fr; }
  .bar-row { grid-template-columns: 120px 1fr 30px; }
}

.qr { margin-top: 12px; display: grid; gap: 8px; justify-items: start; }
.qr img { width: 260px; height: 260px; border: 1px solid var(--line); border-radius: 8px; }
