:root {
  --bg: #F3F5FA; --surface: #FFFFFF; --ink: #141A2E; --muted: #5A6380; --line: #DCE1EC;
  --accent: #2446D8; --accent-ink: #FFFFFF; --signal: #F2A516; --soft: #E8EDFB; --ok: #1F8A5B; --late: #B4361F;
  --bubble-in: #FFFFFF; --bubble-ia: #E8EDFB; --bubble-eq: #DDF3E8; --chat-bg: #EEF1F7;
  --f-display: "Familjen Grotesk", "Helvetica Neue", Arial, sans-serif;
  --f-body: "Instrument Sans", "Segoe UI", Roboto, Arial, sans-serif;
  --r: 12px; --shadow: 0 1px 2px rgba(20, 26, 46, .06), 0 4px 16px rgba(20, 26, 46, .06);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0E1222; --surface: #161B30; --ink: #E8EBF5; --muted: #9AA3C0; --line: #2A3150;
    --accent: #7C93FF; --accent-ink: #0E1222; --signal: #F5B638; --soft: #1E2747; --ok: #4CC38A; --late: #F08A73;
    --bubble-in: #1D2340; --bubble-ia: #253063; --bubble-eq: #1B3B33; --chat-bg: #11162A;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font: 15px/1.5 var(--f-body); -webkit-font-smoothing: antialiased; }
h1, h2, h3 { font-family: var(--f-display); line-height: 1.2; margin: 0; }
h1 { font-size: 24px; } h2 { font-size: 18px; } h3 { font-size: 15px; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* botões e campos */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--surface);
  border-radius: 10px; padding: 9px 14px; cursor: pointer; font-weight: 600; text-decoration: none; color: var(--ink); white-space: nowrap; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--late); }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: default; }
label.campo { display: block; margin-bottom: 14px; }
label.campo > span { display: block; font-weight: 600; font-size: 13px; margin-bottom: 4px; }
label.campo > small { display: block; color: var(--muted); font-size: 12px; margin-top: 3px; }
input[type=text], input[type=email], input[type=password], input[type=search], input[type=number], input:not([type]), select, textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; background: var(--surface); }
textarea { resize: vertical; min-height: 70px; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.grade2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
@media (max-width: 640px) { .grade2 { grid-template-columns: 1fr; } }

/* interruptor */
.chave { display: flex; align-items: flex-start; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.chave:last-child { border-bottom: 0; }
.chave input { appearance: none; flex: none; width: 42px; height: 24px; border-radius: 99px; background: var(--line); position: relative; cursor: pointer; margin: 2px 0 0; transition: background .15s; }
.chave input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: left .15s; }
.chave input:checked { background: var(--ok); }
.chave input:checked::after { left: 21px; }
.chave b { display: block; }

/* login */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.login form { width: 100%; max-width: 380px; background: var(--surface); border-radius: 16px; padding: 28px; box-shadow: var(--shadow); }
.marca { display: flex; align-items: center; gap: 10px; font-family: var(--f-display); font-weight: 700; font-size: 19px; }
.marca img { width: 30px; height: 30px; }
.erro { color: var(--late); font-size: 14px; min-height: 20px; margin: 4px 0 10px; }

/* estrutura */
.casca { display: grid; grid-template-columns: 230px 1fr; min-height: 100%; }
.lateral { background: var(--surface); border-right: 1px solid var(--line); padding: 18px 12px; display: flex; flex-direction: column; gap: 4px;
  position: sticky; top: 0; height: 100vh; }
.lateral .marca { padding: 0 8px 16px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 10px; color: var(--ink); text-decoration: none; font-weight: 500; }
.nav a:hover { background: var(--soft); }
.nav a.ativo { background: var(--soft); color: var(--accent); font-weight: 600; }
.nav svg { width: 20px; height: 20px; flex: none; }
.nav .bolha { margin-left: auto; }
.lateral .rodape { margin-top: auto; padding: 8px; font-size: 13px; }
.principal { min-width: 0; display: flex; flex-direction: column; }
.topo { display: flex; align-items: center; gap: 12px; padding: 14px 24px; border-bottom: 1px solid var(--line); background: var(--surface); }
.topo h1 { font-size: 20px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topo select { width: auto; max-width: 240px; }
.conteudo { padding: 24px; max-width: 1100px; width: 100%; }
.cartao { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 18px; margin-bottom: 18px; }
.cartao > h2 { margin-bottom: 12px; }
.bolha { display: inline-block; min-width: 20px; padding: 1px 7px; border-radius: 99px; background: var(--accent); color: var(--accent-ink); font-size: 12px; font-weight: 700; text-align: center; }
.etiqueta { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; background: var(--soft); color: var(--muted); }
.etiqueta.equipe { background: color-mix(in srgb, var(--signal) 22%, transparent); color: var(--ink); }
.etiqueta.pausa { background: color-mix(in srgb, var(--late) 15%, transparent); color: var(--late); }
.etiqueta.ok { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.inferior { display: none; }

@media (max-width: 820px) {
  .casca { grid-template-columns: 1fr; }
  .lateral { display: none; }
  .topo { padding: 12px 16px; position: sticky; top: 0; z-index: 5; }
  .conteudo { padding: 16px 16px 90px; }
  .inferior { display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 10; background: var(--surface); border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom); }
  .inferior a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 2px; font-size: 11px; color: var(--muted); text-decoration: none; position: relative; }
  .inferior a.ativo { color: var(--accent); font-weight: 600; }
  .inferior svg { width: 22px; height: 22px; }
  .inferior .bolha { position: absolute; top: 3px; left: 54%; font-size: 10px; padding: 0 5px; min-width: 16px; }
}

/* resumo */
.numeros { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 18px; }
.numero { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; }
.numero b { display: block; font: 700 28px/1.1 var(--f-display); margin: 4px 0 2px; }
.numero span { color: var(--muted); font-size: 13px; }
.barras { display: flex; align-items: flex-end; gap: 3px; height: 140px; padding-top: 8px; }
.barras div { flex: 1; background: var(--accent); border-radius: 3px 3px 0 0; min-height: 2px; opacity: .85; position: relative; }
.barras div:hover { opacity: 1; }
.barras-eixo { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; margin-top: 6px; }
.status { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 18px; }
.status > a { text-decoration: none; color: inherit; }
.status > div, .status > a > div { display: flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: 99px; padding: 6px 14px; font-size: 14px; }
.ponto { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.ponto.ok { background: var(--ok); } .ponto.mal { background: var(--late); }

/* conversas */
.conversas { display: grid; grid-template-columns: 340px 1fr; height: calc(100vh - 61px); }
.conversas .lista { border-right: 1px solid var(--line); background: var(--surface); display: flex; flex-direction: column; min-height: 0; }
.filtros { padding: 12px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; }
.abas { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.abas button { border: 1px solid var(--line); background: var(--surface); border-radius: 99px; padding: 4px 11px; font-size: 13px; cursor: pointer; white-space: nowrap; }
.abas button.ativo { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.itens { overflow-y: auto; flex: 1; }
.item { display: block; padding: 12px 14px; border-bottom: 1px solid var(--line); text-decoration: none; color: var(--ink); }
.item:hover { background: var(--soft); }
.item.ativo { background: var(--soft); box-shadow: inset 3px 0 0 var(--accent); }
.item .l1 { display: flex; align-items: center; gap: 8px; }
.item .l1 b { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .l1 time { color: var(--muted); font-size: 12px; }
.item .l2 { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; margin-top: 2px; }
.item .l2 span:first-child { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat { display: flex; flex-direction: column; min-height: 0; background: var(--chat-bg); }
.chat-topo { display: flex; align-items: center; gap: 8px; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line); }
.chat-topo .quem { flex: 1; min-width: 0; }
.chat-topo .quem b, .chat-topo .quem span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.voltar { display: none; }
.msgs { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 6px; }
.dia { align-self: center; font-size: 12px; color: var(--muted); background: var(--surface); border-radius: 99px; padding: 2px 10px; margin: 8px 0; }
.msg { max-width: min(78%, 560px); padding: 7px 11px 5px; border-radius: 12px; background: var(--bubble-in); box-shadow: 0 1px 1px rgba(0,0,0,.05);
  white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere; align-self: flex-start; }
.msg.ia { background: var(--bubble-ia); align-self: flex-end; }
.msg.equipe { background: var(--bubble-eq); align-self: flex-end; }
.msg .meta { display: block; text-align: right; font-size: 11px; color: var(--muted); margin-top: 2px; }
.msg .autor { display: block; font-size: 11px; font-weight: 700; color: var(--muted); margin-bottom: 1px; }
.msg.transferiu { box-shadow: inset 0 0 0 2px var(--signal); }
.responder { display: flex; gap: 8px; padding: 10px 12px; background: var(--surface); border-top: 1px solid var(--line); align-items: flex-end; }
.responder textarea { min-height: 42px; max-height: 160px; resize: none; }
.faixa { padding: 8px 16px; font-size: 13px; background: color-mix(in srgb, var(--signal) 18%, var(--surface)); border-bottom: 1px solid var(--line); }
.vazio { display: grid; place-items: center; text-align: center; color: var(--muted); padding: 40px 20px; height: 100%; }
@media (max-width: 820px) {
  .conversas { grid-template-columns: 1fr; height: calc(100vh - 57px - 60px); }
  .conversas.abriu .lista { display: none; }
  .conversas:not(.abriu) .chat { display: none; }
  .voltar { display: inline-flex; }
  .chat-topo { padding: 8px 10px; gap: 6px; }
  .chat-topo .zap { display: none; }
  .conversas.abriu { height: calc(100dvh - 57px); }
  body.em-chat .inferior { display: none; }
}

/* produtos */
.barra { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.barra input[type=search] { flex: 1; min-width: 180px; }
.produtos { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.produto { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; display: flex; flex-direction: column; cursor: pointer; text-align: left; padding: 0; }
.produto:hover { border-color: var(--accent); }
.produto .foto { width: 100%; aspect-ratio: 4 / 3; background: var(--soft) center / cover no-repeat; display: grid; place-items: center; color: var(--muted); font-size: 13px; }
.produto .foto.sem { aspect-ratio: auto; height: 44px; }
.produto .info { width: 100%; padding: 10px 12px 12px; }
.produto .preco { font: 700 17px var(--f-display); margin-top: 2px; }
.produto.inativo { opacity: .55; }
.foto-campo { display: flex; gap: 12px; align-items: center; margin-bottom: 14px; }
.foto-campo .previa { width: 96px; height: 72px; border-radius: 8px; background: var(--soft) center / cover no-repeat; flex: none; border: 1px solid var(--line); }

/* janela */
dialog { border: 0; border-radius: 16px; padding: 0; width: min(560px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(14, 18, 34, .5); }
dialog form { display: flex; flex-direction: column; max-height: calc(100dvh - 24px); }
dialog .cab { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
dialog .cab h2 { flex: 1; }
dialog .corpo { padding: 18px 20px 4px; overflow-y: auto; }
dialog .acoes { padding: 12px 20px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; }
dialog .acoes .esq { margin-right: auto; }

/* tabela */
.tabela { width: 100%; border-collapse: collapse; font-size: 14px; }
.tabela th, .tabela td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tabela th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
.rolagem { overflow-x: auto; }
pre.previa-ia { white-space: pre-wrap; background: var(--soft); border-radius: 10px; padding: 12px; font-size: 13px; max-height: 320px; overflow: auto; margin: 0; }

#aviso { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); background: var(--ink); color: var(--surface); padding: 10px 16px;
  border-radius: 10px; font-size: 14px; opacity: 0; pointer-events: none; transition: .2s; z-index: 100; max-width: calc(100vw - 32px); }
#aviso.ver { opacity: 1; transform: translateX(-50%); }
#aviso.ruim { background: var(--late); color: #fff; }
@media (max-width: 820px) { #aviso { bottom: 80px; } }
