:root {
  --brand: #0E7A68;
  --brand-dark: #0B4A3E;
  --brand-soft: #ccfbf1;
  --bg: #f3f5f7;
  --panel: #ffffff;
  --line: #e3e7ec;
  --text: #1f2933;
  --muted: #6b7785;
  --danger: #c2410c;
  --danger-soft: #ffedd5;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --ok: #15803d;
  --ok-soft: #dcfce7;
  --blue: #1d4ed8;
  --blue-soft: #dbeafe;
  --bubble-in: #ffffff;
  --bubble-out: #d9f7ef;
  --bubble-bot: #eef1f4;
  --radius: 10px;
  --header-h: 54px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
body { overflow: hidden; font-size: 14px; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--brand); }
.boot { display: grid; place-items: center; height: 100vh; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden { display: none !important; }

/* ---------- Botões e campos ---------- */
.btn { border: 1px solid var(--line); background: #fff; padding: 7px 12px; border-radius: 8px; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.btn:hover { background: #f7f9fa; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.danger { color: var(--danger); border-color: #f5c9b3; }
.btn.ok { color: var(--ok); border-color: #b7e4c7; }
.btn.small { padding: 4px 9px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.icon { padding: 6px 9px; }
input[type=text], input[type=password], input[type=number], input[type=datetime-local], input[type=search], select, textarea {
  width: 100%; border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 8px 10px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(14, 122, 104, .12); }
label { display: block; font-size: 12px; color: var(--muted); margin: 10px 0 4px; }
.row { display: flex; gap: 8px; align-items: center; }
.row > * { flex: 1; }
.row > .btn { flex: 0 0 auto; }
.grow { flex: 1; }

/* ---------- Login ---------- */
.login { display: grid; place-items: center; height: 100vh; padding: 16px; background: linear-gradient(160deg, #0E7A68 0%, #0B4A3E 100%); }
.login form { background: #fff; padding: 28px; border-radius: 14px; width: 100%; max-width: 360px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.login h1 { margin: 0 0 4px; font-size: 20px; }
.login .login-logo { display: block; width: 230px; max-width: 100%; height: auto; margin: 0 auto 6px; }
.login .login-sub { text-align: center; margin-bottom: 6px; }
.login .btn { width: 100%; justify-content: center; margin-top: 16px; padding: 10px; }
.login .err { color: var(--danger); margin-top: 10px; min-height: 18px; }

/* ---------- Layout ---------- */
.shell { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
header.top { height: var(--header-h); background: var(--brand); color: #fff; display: flex; align-items: center; gap: 6px; padding: 0 12px; flex-shrink: 0; }
header.top .logo { font-weight: 700; margin-right: 10px; display: flex; align-items: center; gap: 8px; }
header.top nav { display: flex; gap: 2px; }
header.top nav button { background: transparent; border: 0; color: rgba(255,255,255,.8); padding: 8px 12px; border-radius: 8px; }
header.top nav button.active, header.top nav button:hover { background: rgba(255,255,255,.15); color: #fff; }
header.top .spacer { flex: 1; }
.presence { display: flex; align-items: center; gap: 6px; background: rgba(255,255,255,.12); border: 0; color: #fff; padding: 6px 10px; border-radius: 20px; }
.presence .dot { width: 9px; height: 9px; border-radius: 50%; background: #9ca3af; }
.presence.on .dot { background: #4ade80; box-shadow: 0 0 0 3px rgba(74, 222, 128, .25); }
.usermenu { background: transparent; border: 0; color: #fff; padding: 6px 8px; border-radius: 8px; }
.usermenu:hover { background: rgba(255,255,255,.15); }
.sim-banner { background: var(--warn-soft); color: var(--warn); padding: 6px 12px; font-size: 12px; text-align: center; flex-shrink: 0; }
main { flex: 1; min-height: 0; display: flex; }

/* ---------- Atendimentos ---------- */
.inbox { display: grid; grid-template-columns: 340px 1fr; flex: 1; min-height: 0; }
.inbox.with-details { grid-template-columns: 340px 1fr 330px; }
.list-pane { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.tabs { display: flex; flex-wrap: wrap; gap: 4px; padding: 8px; border-bottom: 1px solid var(--line); flex-shrink: 0; }
.tabs button { border: 0; background: #f3f5f7; padding: 5px 10px; border-radius: 16px; white-space: nowrap; color: var(--muted); font-size: 13px; }
.tabs button.active { background: var(--brand-soft); color: var(--brand-dark); font-weight: 600; }
.tabs .count { background: var(--line); border-radius: 10px; padding: 0 6px; margin-left: 4px; font-size: 11px; }
.tabs button.active .count { background: var(--brand); color: #fff; }
.tabs .count.alert { background: var(--danger); color: #fff; }
.list-tools { display: flex; gap: 6px; padding: 8px; border-bottom: 1px solid var(--line); flex-shrink: 0; }
.list-tools select { width: auto; max-width: 130px; }
.tickets { overflow-y: auto; flex: 1; }
.titem { display: flex; gap: 10px; padding: 10px 12px; border-bottom: 1px solid #f0f2f5; cursor: pointer; position: relative; }
.titem:hover { background: #f8fafb; }
.titem.active { background: #eaf7f4; }
.avatar { width: 40px; height: 40px; border-radius: 50%; background: #d1e7e3; color: var(--brand-dark); display: grid; place-items: center; font-weight: 700; flex-shrink: 0; font-size: 14px; }
.avatar.g { background: #fde7c9; color: #9a4b07; }
.titem .body { flex: 1; min-width: 0; }
.titem .l1 { display: flex; justify-content: space-between; gap: 6px; }
.titem .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.titem .time { font-size: 11px; color: var(--muted); white-space: nowrap; }
.titem .time.late { color: var(--danger); font-weight: 700; }
.titem .preview { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin: 2px 0 4px; }
.titem .preview.unread { color: var(--text); font-weight: 600; }
.badges { display: flex; gap: 4px; flex-wrap: wrap; }
.badge { font-size: 11px; padding: 1px 7px; border-radius: 10px; background: #eef1f4; color: #4b5563; white-space: nowrap; }
.badge.vendas { background: var(--blue-soft); color: var(--blue); }
.badge.garantia { background: var(--warn-soft); color: var(--warn); }
.badge.triagem { background: #f3e8ff; color: #7e22ce; }
.badge.novo { background: var(--danger-soft); color: var(--danger); }
.badge.em_atendimento { background: var(--brand-soft); color: var(--brand-dark); }
.badge.aguardando_cliente { background: #eef1f4; color: #4b5563; }
.badge.concluido { background: var(--ok-soft); color: var(--ok); }
.badge.perdido { background: #fee2e2; color: #b91c1c; }
.badge.nobody { background: var(--danger); color: #fff; }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }

.chat-pane { display: flex; flex-direction: column; min-height: 0; min-width: 0; background: #eef2f1; }
.chat-head { background: var(--panel); border-bottom: 1px solid var(--line); padding: 8px 12px; display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.chat-head .info { flex: 1; min-width: 0; }
.chat-head .info b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-head .actions { display: flex; gap: 6px; }
.back { display: none; }
.msgs { flex: 1; overflow-y: auto; padding: 16px 6%; display: flex; flex-direction: column; gap: 4px;
  background-image: radial-gradient(rgba(15,118,110,.05) 1px, transparent 1px); background-size: 18px 18px; }
.msg { max-width: 72%; padding: 7px 10px 5px; border-radius: 10px; box-shadow: 0 1px 1px rgba(0,0,0,.06); white-space: pre-wrap; word-wrap: break-word; line-height: 1.35; }
.msg.in { align-self: flex-start; background: var(--bubble-in); border-top-left-radius: 2px; }
.msg.out { align-self: flex-end; background: var(--bubble-out); border-top-right-radius: 2px; }
.msg.bot { align-self: flex-end; background: var(--bubble-bot); color: #4b5563; border-top-right-radius: 2px; }
.msg .meta { font-size: 10.5px; color: var(--muted); text-align: right; margin-top: 2px; display: flex; gap: 6px; justify-content: flex-end; }
.msg .meta .failed { color: var(--danger); font-weight: 600; }
.msg .who { font-size: 11px; color: var(--brand-dark); font-weight: 600; margin-bottom: 2px; }
.day-sep { align-self: center; background: #fff; color: var(--muted); font-size: 11px; padding: 3px 10px; border-radius: 8px; margin: 8px 0; box-shadow: 0 1px 1px rgba(0,0,0,.05); }
.sys-ev { align-self: center; font-size: 11px; color: var(--muted); background: rgba(255,255,255,.7); padding: 2px 10px; border-radius: 8px; }
.notice { padding: 10px 12px; font-size: 13px; display: flex; gap: 10px; align-items: center; flex-shrink: 0; }
.notice.warn { background: var(--warn-soft); color: var(--warn); }
.notice.info { background: var(--blue-soft); color: var(--blue); }
.notice.ok { background: var(--ok-soft); color: var(--ok); }
.composer { background: var(--panel); border-top: 1px solid var(--line); padding: 8px; display: flex; gap: 8px; align-items: flex-end; flex-shrink: 0; padding-bottom: max(8px, env(safe-area-inset-bottom)); }
.composer textarea { resize: none; max-height: 140px; min-height: 40px; border-radius: 20px; padding: 9px 14px; }
.composer .send { border-radius: 50%; width: 42px; height: 42px; justify-content: center; padding: 0; flex-shrink: 0; }
/* mídia nas conversas */
.msg.has-media { padding: 4px 4px 4px; }
.msg.has-media .cap { padding: 4px 6px 0; }
.msg.has-media .meta { padding: 0 6px; }
.media-img img { display: block; max-width: 280px; max-height: 320px; width: 100%; object-fit: cover; border-radius: 8px; cursor: zoom-in; }
.media-img.sticker img { max-width: 140px; background: transparent; }
.msg audio { width: 260px; max-width: 100%; display: block; height: 40px; }
.msg video { max-width: 300px; width: 100%; border-radius: 8px; display: block; background: #000; }
.media-doc { display: flex; align-items: center; gap: 10px; background: rgba(0,0,0,.05); border-radius: 8px; padding: 10px 12px; text-decoration: none; color: var(--text); min-width: 200px; }
.media-doc .ico { font-size: 26px; }
.media-doc .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; max-width: 220px; }
.media-doc .dl { color: var(--muted); }
.media-missing { padding: 8px 10px; color: var(--muted); font-size: 12px; }
.msgs.drop { outline: 3px dashed var(--brand); outline-offset: -10px; }
.up-preview { max-width: 100%; max-height: 50vh; border-radius: 8px; display: block; margin: 0 auto; }
.composer .attach { border-radius: 50%; width: 42px; height: 42px; justify-content: center; padding: 0; flex-shrink: 0; font-size: 17px; }
.composer { position: relative; }
.composer.recording > :not(.rec-bar) { visibility: hidden; }
.rec-bar { position: absolute; inset: 8px; display: flex; align-items: center; gap: 10px; background: var(--panel); }
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: #dc2626; animation: blink 1s infinite; }
.rec-time { font-variant-numeric: tabular-nums; font-weight: 600; }
@keyframes blink { 50% { opacity: .2; } }
/* respostas rápidas */
.qr-pop { position: absolute; left: 8px; right: 8px; bottom: calc(100% + 6px); background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.15); max-height: min(360px, 55vh); display: flex; flex-direction: column; z-index: 20; overflow: hidden; }
.qr-head { padding: 8px 12px; border-bottom: 1px solid var(--line); }
.qr-search { border: 0 !important; border-bottom: 1px solid var(--line) !important; border-radius: 0 !important; box-shadow: none !important; padding: 10px 12px !important; }
.qr-list { overflow-y: auto; flex: 1; }
.qr-item { padding: 8px 12px; cursor: pointer; border-bottom: 1px solid #f0f2f5; }
.qr-item:hover, .qr-item.sel { background: #eaf7f4; }
.qr-top { display: flex; gap: 8px; align-items: center; }
.qr-top code { color: var(--brand-dark); background: var(--brand-soft); padding: 1px 6px; border-radius: 6px; font-size: 12px; }
.qr-body { color: var(--muted); font-size: 12.5px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.qr-manage { border: 0; border-top: 1px solid var(--line); background: #f8fafb; padding: 9px 12px; text-align: left; color: var(--brand-dark); font-weight: 600; }
.qr-manage:hover { background: #eef5f3; }
@media (max-width: 760px) { .composer .attach { width: 36px; height: 36px; font-size: 15px; } .composer { gap: 4px; } }
.placeholder { flex: 1; display: grid; place-items: center; color: var(--muted); text-align: center; padding: 20px; }

.details-pane { background: var(--panel); border-left: 1px solid var(--line); overflow-y: auto; padding: 4px 14px 30px; min-height: 0; }
.details-pane h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 18px 0 6px; }
.status-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.status-grid .btn { justify-content: center; }
.status-grid .btn.current { outline: 2px solid var(--brand); }
.timeline { list-style: none; padding: 0; margin: 0; font-size: 12px; }
.timeline li { padding: 5px 0 5px 12px; border-left: 2px solid var(--line); position: relative; }
.timeline li::before { content: ""; position: absolute; left: -5px; top: 10px; width: 8px; height: 8px; border-radius: 50%; background: var(--brand); }
.timeline li.sla::before { background: var(--danger); }
.prev-item { font-size: 12px; padding: 6px 0; border-bottom: 1px dashed var(--line); }

/* ---------- Painel ---------- */
.page { flex: 1; overflow-y: auto; padding: 18px; }
.page-inner { max-width: 1250px; margin: 0 auto; }
.page h2 { margin: 0 0 4px; font-size: 20px; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 12px 0 16px; }
.toolbar select { width: auto; }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(165px, 1fr)); gap: 10px; margin-bottom: 14px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.kpi .v { font-size: 24px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .l { font-size: 12px; color: var(--muted); }
.kpi.alert { border-color: #f5c9b3; background: #fff8f3; }
.kpi.alert .v { color: var(--danger); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 14px; overflow-x: auto; }
.card h3 { margin: 0 0 10px; font-size: 15px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
table.t { width: 100%; border-collapse: collapse; font-size: 13px; }
table.t th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; padding: 6px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.t td { padding: 7px 8px; border-bottom: 1px solid #f0f2f5; white-space: nowrap; }
table.t td.num, table.t th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.t tr.click { cursor: pointer; }
table.t tr.click:hover { background: #f8fafb; }
.bar { height: 8px; background: var(--brand); border-radius: 4px; }
.bar-row { display: grid; grid-template-columns: 170px 1fr 40px; gap: 8px; align-items: center; margin: 6px 0; font-size: 13px; }
.dotline { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; background: #cbd5e1; }
.dotline.on { background: #22c55e; }
.dotline.pause { background: #f59e0b; }
.spark { display: flex; align-items: flex-end; gap: 3px; height: 90px; }
.spark div { flex: 1; background: var(--brand-soft); border-radius: 3px 3px 0 0; position: relative; min-height: 2px; }
.spark div span { position: absolute; bottom: 0; left: 0; right: 0; background: var(--brand); border-radius: 3px 3px 0 0; }

/* ---------- Configurações ---------- */
.subtabs { display: flex; gap: 6px; margin: 12px 0; flex-wrap: wrap; }
.subtabs button { border: 1px solid var(--line); background: #fff; padding: 7px 14px; border-radius: 20px; }
.subtabs button.active { background: var(--brand); color: #fff; border-color: var(--brand); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 0 14px; }
code.copy { background: #f1f5f9; padding: 3px 7px; border-radius: 6px; user-select: all; }

/* ---------- Modal e toasts ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 440px; max-height: 90vh; overflow-y: auto; padding: 20px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal h3 { margin: 0 0 6px; }
.modal .foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.modal .err { color: var(--danger); margin-top: 8px; min-height: 16px; font-size: 13px; }
#toasts { position: fixed; right: 14px; bottom: 14px; display: flex; flex-direction: column; gap: 8px; z-index: 60; max-width: calc(100vw - 28px); }
.toast { background: #1f2933; color: #fff; padding: 10px 14px; border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.2); max-width: 360px; cursor: pointer; animation: slidein .2s ease-out; }
.toast.alert { background: var(--danger); }
.toast.ok { background: var(--ok); }
@keyframes slidein { from { transform: translateY(10px); opacity: 0; } }
.dropdown { position: absolute; right: 10px; top: calc(var(--header-h) - 4px); background: #fff; color: var(--text); border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.18); min-width: 200px; z-index: 40; padding: 6px; }
.dropdown button { display: block; width: 100%; text-align: left; border: 0; background: transparent; padding: 9px 12px; border-radius: 6px; }
.dropdown button:hover { background: #f3f5f7; }
.dropdown .who { padding: 8px 12px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }

/* ---------- Celular ---------- */
@media (max-width: 1100px) {
  .inbox.with-details { grid-template-columns: 300px 1fr; }
  .inbox.with-details .details-pane { position: fixed; right: 0; top: var(--header-h); bottom: 0; width: min(360px, 100vw); z-index: 30; box-shadow: -10px 0 30px rgba(0,0,0,.15); }
  .inbox { grid-template-columns: 300px 1fr; }
}
@media (max-width: 760px) {
  header.top .logo span { display: none; }
  header.top nav button { padding: 8px 9px; }
  .presence .lbl { display: none; }
  .inbox, .inbox.with-details { grid-template-columns: 1fr; }
  .inbox .chat-pane { display: none; }
  .inbox.show-chat .list-pane { display: none; }
  .inbox.show-chat .chat-pane { display: flex; }
  .back { display: inline-flex; }
  .msgs { padding: 12px 10px; }
  .msg { max-width: 86%; }
  .inbox.with-details .details-pane { top: 0; width: 100vw; z-index: 45; }
  .grid2 { grid-template-columns: 1fr; }
  .page { padding: 12px; }
  .bar-row { grid-template-columns: 110px 1fr 34px; }
  .chat-head .actions .lbl { display: none; }
}

/* ---------- SaaS: cadastro, assinatura, bloqueio ---------- */
.login-foot { margin-top: 14px; text-align: center; font-size: 13px; color: var(--muted); }
.blocked-card { background: #fff; padding: 28px; border-radius: 14px; width: 100%; max-width: 460px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.blocked-card h1 { margin: 0 0 8px; font-size: 20px; color: var(--danger); }
.sim-banner.trial { background: var(--blue-soft); color: var(--blue); }
.sim-banner.danger { background: var(--danger-soft); color: var(--danger); font-weight: 600; }
.usage { height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; margin: 10px 0 4px; }
.usage div { height: 100%; background: var(--brand); }
.usage div.full { background: var(--danger); }
.plans { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; }
.plan { border: 1px solid var(--line); border-radius: 12px; padding: 14px; display: flex; flex-direction: column; gap: 6px; background: #fff; }
.plan.current { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand-soft); }
.plan .price { font-size: 22px; font-weight: 700; }
.plan .price span { font-size: 12px; color: var(--muted); font-weight: 400; }
.plan ul { margin: 4px 0 8px; padding-left: 18px; color: var(--muted); font-size: 13px; line-height: 1.6; }
.plan .btn { align-self: flex-start; }

/* Aviso para ativar notificações no celular */
.push-banner { position: fixed; left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom, 0px)); z-index: 60; max-width: 560px; margin: 0 auto;
  background: #fff; border: 1px solid var(--line, #e5e7eb); border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.18);
  display: flex; align-items: center; gap: 8px; padding: 10px 12px; font-size: 13px; }
.push-banner span { flex: 1; }

/* caixinhas de lojas no cadastro de pessoas */
.store-checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 6px 12px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; max-height: 220px; overflow: auto; }
.store-checks .chk { display: flex; align-items: center; gap: 8px; margin: 0; color: var(--text); font-weight: normal; }
.store-checks .chk input { width: auto; }
.subtabs { flex-wrap: wrap; }
