:root {
  --graphite: #26292d;
  --graphite-2: #34383d;
  --bg: #f4f2ee;
  --panel: #ffffff;
  --line: #e4e0d8;
  --text: #1f2326;
  --muted: #6b7075;
  --accent: #b08d57;
  --accent-soft: #efe6d4;
  --in: #ffffff;
  --out: #e9e0cd;
  --ok: #2e7d4f;
  --warn: #b26a00;
  --bad: #b3372f;
  --radius: 12px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; background: var(--bg); color: var(--text); }
[hidden] { display: none !important; }
button { font: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }

.app {
  height: 100dvh;
  display: grid;
  grid-template-columns: 340px 1fr;
  grid-template-rows: 56px 1fr;
  grid-template-areas: "top top" "side chat";
}

/* topo */
.topbar { grid-area: top; background: var(--graphite); color: #fff; display: flex; align-items: center; gap: 12px; padding: 0 16px; }
.logo { width: 34px; height: 34px; border-radius: 8px; background: #000; object-fit: contain; }
.brand { display: flex; flex-direction: column; line-height: 1.15; }
.brand strong { font-size: 15px; }
.brand span { font-size: 12px; color: #c9c4b8; }
.spacer { flex: 1; }
.who { font-size: 13px; color: #d9d5cb; }
.chip { font-size: 12px; background: var(--graphite-2); border: 1px solid #4a4f55; padding: 4px 10px; border-radius: 999px; color: #e6e2d8; }

/* lista */
.sidebar { grid-area: side; background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.search { padding: 12px 12px 6px; }
.search input { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
.filters { display: flex; gap: 10px; align-items: center; padding: 6px 12px 10px; border-bottom: 1px solid var(--line); }
.filters select { flex: 1; min-width: 0; padding: 7px 8px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.toggle { display: flex; align-items: center; gap: 6px; font-size: 13px; white-space: nowrap; color: var(--muted); }
.list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.item { display: grid; grid-template-columns: 42px 1fr auto; gap: 10px; padding: 12px; border-bottom: 1px solid var(--line); cursor: pointer; }
.item:hover { background: #faf8f4; }
.item.active { background: var(--accent-soft); }
.avatar { width: 42px; height: 42px; border-radius: 50%; background: var(--graphite); color: #fff; display: grid; place-items: center; font-weight: 600; }
.item .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .sub { font-size: 12px; color: var(--accent); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .prev { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .meta { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; font-size: 12px; color: var(--muted); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); }
.dot.win-open { background: var(--ok); }
.dot.win-closed { background: #b9b4a9; }
.dot.win-unknown { background: var(--warn); }
.list-empty { padding: 24px; text-align: center; color: var(--muted); font-size: 14px; }

/* chat */
.chat { grid-area: chat; position: relative; min-width: 0; min-height: 0; display: flex; }
.empty { margin: auto; text-align: center; color: var(--muted); }
.empty-logo { width: 72px; height: 72px; border-radius: 16px; background: #000; margin-bottom: 8px; }
.chat-view { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.chat-head { display: flex; align-items: center; gap: 10px; padding: 10px 14px; background: var(--panel); border-bottom: 1px solid var(--line); }
.who-chat { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.who-chat strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.phone { font-size: 12px; color: var(--muted); letter-spacing: .2px; }
.badge { font-size: 12px; padding: 5px 10px; border-radius: 999px; font-weight: 600; white-space: nowrap; }
.badge.open { background: #e2f1e8; color: var(--ok); }
.badge.closed { background: #eceae5; color: #5d6166; }
.badge.unknown { background: #fbeed7; color: var(--warn); }
.icon-btn { background: none; border: 0; font-size: 20px; padding: 6px 10px; border-radius: 8px; color: var(--graphite); }
.icon-btn:hover { background: var(--bg); }
.only-mobile { display: none; }

.messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 6px; background: var(--bg); }
.day { align-self: center; font-size: 12px; color: var(--muted); background: #e9e5dc; padding: 3px 10px; border-radius: 999px; margin: 8px 0; }
.bubble { max-width: min(78%, 560px); padding: 8px 12px 6px; border-radius: var(--radius); box-shadow: 0 1px 1px rgba(0,0,0,.06); white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14.5px; line-height: 1.4; }
.bubble.in { align-self: flex-start; background: var(--in); border-top-left-radius: 4px; }
.bubble.out { align-self: flex-end; background: var(--out); border-top-right-radius: 4px; }
.bubble .who-line { font-size: 11px; color: var(--accent); font-weight: 600; margin-bottom: 2px; }
.bubble .ph { font-style: italic; color: var(--muted); }
.bubble .time { display: block; text-align: right; font-size: 11px; color: var(--muted); margin-top: 2px; }
.bubble .time .err { color: var(--bad); font-weight: 600; }

.notice { padding: 10px 14px; font-size: 13px; background: #fbeed7; color: #6b4300; border-top: 1px solid #f0d9ae; }
.composer { display: flex; gap: 8px; align-items: flex-end; padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); background: var(--panel); border-top: 1px solid var(--line); }
.composer textarea { flex: 1; resize: none; max-height: 140px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); line-height: 1.35; }
.composer textarea:disabled { opacity: .6; }
.btn { padding: 10px 16px; border-radius: 10px; border: 1px solid transparent; font-weight: 600; }
.btn.primary { background: var(--graphite); color: #fff; }
.btn.primary:hover:not(:disabled) { background: #000; }
.btn.ghost { background: #fff; border-color: var(--line); color: var(--graphite); }
.btn.ghost:hover { background: var(--accent-soft); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* resumo */
.summary { position: absolute; top: 0; right: 0; bottom: 0; width: 300px; background: var(--panel); border-left: 1px solid var(--line); box-shadow: -6px 0 18px rgba(0,0,0,.08); padding: 14px; overflow-y: auto; z-index: 5; }
.summary-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.summary dt { font-size: 12px; color: var(--muted); margin-top: 14px; }
.summary dd { margin: 2px 0 0; font-weight: 600; }

/* modal */
.modal { position: fixed; inset: 0; background: rgba(20,22,24,.5); display: grid; place-items: center; z-index: 20; padding: 12px; }
.modal-card { background: #fff; border-radius: 16px; width: min(560px, 100%); max-height: min(640px, 92dvh); display: flex; flex-direction: column; overflow: hidden; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px 6px; }
.tabs { display: flex; gap: 6px; padding: 4px 16px; }
.tab { background: none; border: 0; padding: 8px 12px; border-radius: 8px; color: var(--muted); font-weight: 600; }
.tab.active { background: var(--accent-soft); color: var(--graphite); }
.tpl-search { margin: 8px 16px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
.tpl-body { overflow-y: auto; padding: 4px 16px 16px; display: flex; flex-direction: column; gap: 8px; }
.tpl { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; display: grid; grid-template-columns: 1fr auto; gap: 4px 8px; }
.tpl:hover:not(.disabled) { border-color: var(--accent); background: #fdfbf6; cursor: pointer; }
.tpl.disabled { opacity: .55; cursor: not-allowed; }
.tpl strong { font-size: 14px; }
.tpl p { grid-column: 1 / -1; margin: 0; font-size: 13px; color: var(--muted); white-space: pre-wrap; }
.star { background: none; border: 0; font-size: 18px; color: #c4bfb3; padding: 0 4px; }
.star.on { color: var(--accent); }
.banner { border-radius: 10px; padding: 10px 12px; font-size: 13px; background: #fbeed7; color: #6b4300; }
.editor-row { display: grid; gap: 6px; border: 1px solid var(--line); border-radius: 12px; padding: 10px; }
.editor-row input, .editor-row textarea { padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; width: 100%; }
.editor-actions { display: flex; gap: 8px; justify-content: space-between; margin-top: 4px; }
.hint { font-size: 12px; color: var(--muted); }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--graphite); color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 30; max-width: 90vw; }
.toast.bad { background: var(--bad); }

/* celular: uma coluna por vez */
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; grid-template-areas: "top" "side"; }
  .chat { display: none; grid-area: side; }
  .app.chat-open .sidebar { display: none; }
  .app.chat-open .chat { display: flex; }
  .only-mobile { display: inline-block; }
  .who, .chip { display: none; }
  .chat-head { display: grid; grid-template-columns: auto 1fr auto; gap: 2px 8px; }
  .chat-head .badge { grid-column: 2 / 4; grid-row: 2; justify-self: start; }
  .phone { white-space: nowrap; }
  .summary { width: 100%; }
  .bubble { max-width: 88%; }
}

/* navegação */
.nav { display: flex; gap: 4px; margin-left: 18px; }
.navbtn { background: none; border: 0; color: #cfcabd; padding: 8px 14px; border-radius: 8px; font-weight: 600; }
.navbtn:hover { background: var(--graphite-2); }
.navbtn.active { background: var(--accent); color: #fff; }

/* mídia e localização nas bolhas */
.bubble img.m { display: block; max-width: 260px; max-height: 260px; width: 100%; border-radius: 8px; object-fit: cover; background: #ddd; }
.bubble audio { width: 240px; max-width: 100%; }
.bubble video { max-width: 280px; width: 100%; border-radius: 8px; }
.bubble a.file, .bubble a.loc { display: inline-flex; gap: 8px; align-items: center; color: var(--graphite); font-weight: 600; text-decoration: none; background: rgba(0,0,0,.05); padding: 8px 10px; border-radius: 8px; }
.bubble a.file:hover, .bubble a.loc:hover { background: rgba(0,0,0,.1); }
.emoji { display: grid; grid-template-columns: repeat(10, 1fr); gap: 2px; padding: 8px; background: #fff; border-top: 1px solid var(--line); max-height: 150px; overflow-y: auto; }
.emoji button { background: none; border: 0; font-size: 22px; padding: 4px; border-radius: 6px; }
.emoji button:hover { background: var(--accent-soft); }

/* funil (kanban) */
.funnel { grid-row: 2; grid-column: 1 / -1; display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); }
.app.mode-funnel .sidebar, .app.mode-funnel .chat { display: none; }
.funnel-bar { display: flex; gap: 10px; align-items: center; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.funnel-bar select, .funnel-bar input { padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; min-width: 0; }
.funnel-bar select { font-weight: 700; text-transform: uppercase; letter-spacing: .3px; }
.funnel-bar input { flex: 0 1 260px; }
.fsum { margin-left: auto; color: var(--muted); font-size: 14px; }
.board { flex: 1; display: flex; gap: 12px; padding: 14px 16px; overflow: auto; align-items: flex-start; }
.col { flex: 0 0 300px; display: flex; flex-direction: column; max-height: 100%; background: transparent; }
.col-head { text-align: center; padding: 10px 6px 8px; border-top: 3px solid var(--c, #c9d6e6); background: var(--panel); border-radius: 10px 10px 0 0; position: sticky; top: 0; }
.col-head strong { display: block; font-size: 12.5px; letter-spacing: .6px; text-transform: uppercase; }
.col-head span { font-size: 12px; color: var(--muted); }
.col-body { flex: 1; overflow-y: auto; padding: 8px 0 24px; display: flex; flex-direction: column; gap: 8px; min-height: 120px; border-radius: 0 0 10px 10px; }
.col.over .col-body { background: rgba(176,141,87,.15); outline: 2px dashed var(--accent); outline-offset: -2px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; display: grid; gap: 4px; cursor: grab; font-size: 13px; }
.card:hover { border-color: var(--accent); box-shadow: 0 2px 8px rgba(0,0,0,.06); }
.card.dragging { opacity: .4; }
.card .row { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.card .nm { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .dt { color: var(--muted); font-size: 12px; white-space: nowrap; }
.card .orig { color: var(--muted); font-size: 12px; }
.card .emp { color: #2b64b8; font-size: 15px; }
.card .val { font-weight: 600; }
.card .val.none { color: #2b64b8; font-weight: 400; }
.tags { display: flex; gap: 4px; flex-wrap: wrap; }
.tag { font-size: 11px; background: #fbf1c8; border: 1px solid #e6d58c; color: #6b5a1c; padding: 1px 6px; border-radius: 4px; }
.card .foot { display: flex; justify-content: space-between; align-items: center; gap: 6px; margin-top: 2px; }
.card .age { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 4px; }
.card .age i { width: 7px; height: 7px; border-radius: 50%; background: #d94b7a; display: inline-block; }
.card .age i.fresh { background: var(--ok); }
.card .age i.mid { background: var(--warn); }
.card .acts { display: flex; gap: 4px; }
.card .acts button { border: 1px solid var(--line); background: #fff; border-radius: 6px; font-size: 12px; padding: 3px 8px; }
.card .acts button:hover { background: var(--accent-soft); }
.stage-pick { display: grid; gap: 6px; padding: 8px 16px 16px; }
.stage-pick button { text-align: left; padding: 12px; border: 1px solid var(--line); border-left: 6px solid var(--c); border-radius: 10px; background: #fff; font-weight: 600; }
.stage-pick button[disabled] { opacity: .5; }

@media (max-width: 820px) {
  .nav { margin-left: 4px; }
  .navbtn { padding: 8px 10px; }
  .brand span { display: none; }
  .funnel { grid-row: 2; }
  .col { flex-basis: 84vw; }
  .board { scroll-snap-type: x mandatory; padding: 10px; }
  .col { scroll-snap-align: start; }
  .fsum { width: 100%; margin: 0; }
  .card { cursor: default; }
  .emoji { grid-template-columns: repeat(8, 1fr); }
}

/* login / instalação */
.login-body { min-height: 100dvh; display: grid; place-items: center; padding: 20px; background: var(--graphite); }
.login-card { width: min(380px, 100%); background: var(--panel); border-radius: 16px; padding: 28px 26px; box-shadow: 0 10px 40px rgba(0,0,0,.35); display: flex; flex-direction: column; gap: 12px; }
.login-card h1 { margin: 0; font-size: 22px; }
.login-card .muted { margin: 0 0 6px; color: var(--muted); font-size: 14px; }
.login-card form { display: flex; flex-direction: column; gap: 12px; }
.login-card label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); font-weight: 600; }
.login-card input { padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--text); font-weight: 400; }
.login-card .logo.big { width: 56px; height: 56px; border-radius: 12px; align-self: flex-start; }
.login-err { margin: 0; color: var(--bad); font-size: 13px; }
.login-card .pw { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 18px; background: var(--accent-soft); padding: 10px 12px; border-radius: 10px; word-break: break-all; user-select: all; }

/* topo: ações do usuário */
.topbtn { background: transparent; border: 1px solid #4a4f55; color: #e6e2d8; padding: 5px 10px; border-radius: 8px; font-size: 12.5px; }
.topbtn:hover { background: var(--graphite-2); }
@media (max-width: 820px) { .topbtn.opt { display: none; } }

/* diálogos (equipe / senha) */
.form-col { display: flex; flex-direction: column; gap: 10px; padding: 14px; }
.form-col label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); font-weight: 600; }
.form-col input[type=text], .form-col input[type=email], .form-col input[type=password] { padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
.form-col .check { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; color: var(--text); }
.form-col .err { margin: 0; color: var(--bad); font-size: 13px; }
.team-list { display: flex; flex-direction: column; max-height: 52vh; overflow-y: auto; }
.team-row { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; padding: 10px 14px; border-bottom: 1px solid var(--line); font-size: 13px; }
.team-row .t-name { font-weight: 600; }
.team-row .t-sub { color: var(--muted); font-size: 12px; grid-column: 1; }
.team-row .t-acts { grid-row: 1 / span 2; grid-column: 2; display: flex; gap: 6px; align-items: center; }
.team-row.off { opacity: .55; }
.pw-box { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 17px; background: var(--accent-soft); padding: 10px 12px; border-radius: 10px; word-break: break-all; user-select: all; }
.btn.small { padding: 6px 10px; font-size: 12.5px; }
.pipe-pick { display: flex; flex-wrap: wrap; gap: 6px 14px; }
