:root {
  --accent: #6d4aff; --accent-soft: #efeaff; --accent-ink: #3f25b8;
  --bg: #f6f6f8; --panel: #ffffff; --line: #e6e5ea; --line-strong: #d4d2da;
  --ink: #1d1b22; --ink-2: #5d5a66; --ink-3: #908d99;
  --ok: #1f8f5f; --ok-soft: #e3f5ec; --warn: #b26b00; --warn-soft: #fff2dc; --bad: #c63a3a; --bad-soft: #fdeaea;
  --note: #fff7d6; --out: #e9f9ef; --radius: 10px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink); font-size: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line-strong); background: var(--panel); border-radius: 8px; padding: 6px 12px; }
button:hover { border-color: var(--ink-3); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: var(--accent-ink); }
button.ghost { border-color: transparent; background: transparent; }
button.ghost:hover { background: var(--bg); }
button.danger { color: var(--bad); }
button:disabled { opacity: .5; cursor: default; }
input, textarea, select { border: 1px solid var(--line-strong); border-radius: 8px; padding: 7px 10px; background: #fff; width: 100%; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
label { display: block; font-size: 12px; color: var(--ink-2); margin: 10px 0 4px; }
h2 { font-size: 18px; margin: 0 0 12px; font-weight: 600; }
h3 { font-size: 14px; margin: 0 0 8px; font-weight: 600; }
.muted { color: var(--ink-3); }
.small { font-size: 12px; }
.row { display: flex; gap: 8px; align-items: center; }
.grow { flex: 1; min-width: 0; }
.pill { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 11px; font-weight: 600; background: var(--bg); color: var(--ink-2); white-space: nowrap; }
.pill.bot { background: var(--accent-soft); color: var(--accent-ink); }
.pill.queue { background: var(--warn-soft); color: var(--warn); }
.pill.open { background: var(--ok-soft); color: var(--ok); }
.pill.closed { background: var(--bg); color: var(--ink-3); }
.badge { background: var(--ok); color: #fff; border-radius: 99px; font-size: 11px; font-weight: 700; padding: 1px 7px; }
.badge.warn { background: var(--warn); }

/* login */
.login { max-width: 340px; margin: 12vh auto; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px; }
.login .logo { font-weight: 800; font-size: 20px; margin-bottom: 4px; }
.err { color: var(--bad); font-size: 13px; margin-top: 8px; min-height: 18px; }

/* layout */
.shell { display: grid; grid-template-columns: 210px 1fr; height: 100vh; }
.side { background: #17151d; color: #d9d6e3; display: flex; flex-direction: column; padding: 14px 10px; }
.side .brand { font-weight: 800; font-size: 17px; color: #fff; padding: 4px 10px 16px; }
.side .brand span { color: #a996ff; }
.side a { display: flex; justify-content: space-between; align-items: center; color: inherit; text-decoration: none; padding: 9px 10px; border-radius: 8px; margin-bottom: 2px; }
.side a:hover { background: #24212d; }
.side a.on { background: #2e2a3a; color: #fff; }
.side .me { margin-top: auto; border-top: 1px solid #2e2a3a; padding: 12px 10px 0; font-size: 13px; }
.side .me button { background: transparent; color: #d9d6e3; border-color: #3a3547; font-size: 12px; padding: 4px 8px; }
.switch { display: flex; align-items: center; gap: 8px; cursor: pointer; margin: 8px 0; }
.switch input { display: none; }
.switch .tr { width: 32px; height: 18px; border-radius: 9px; background: #4a4458; position: relative; transition: .2s; }
.switch .tr::after { content: ''; position: absolute; width: 14px; height: 14px; border-radius: 50%; background: #fff; top: 2px; left: 2px; transition: .2s; }
.switch input:checked + .tr { background: var(--ok); }
.switch input:checked + .tr::after { left: 16px; }
.main { overflow: hidden; display: flex; flex-direction: column; min-width: 0; }
.page { padding: 20px 24px; overflow: auto; height: 100%; }

/* caixa de entrada */
.inbox { display: grid; grid-template-columns: 330px 1fr 300px; height: 100vh; }
.inbox.nopanel { grid-template-columns: 330px 1fr; }
.list { border-right: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
.list .head { padding: 12px; border-bottom: 1px solid var(--line); }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 8px; }
.tabs button { border: none; background: var(--bg); padding: 5px 10px; font-size: 12px; border-radius: 99px; display: flex; gap: 5px; align-items: center; }
.tabs button.on { background: var(--ink); color: #fff; }
.convs { overflow: auto; flex: 1; }
.conv { padding: 11px 12px; border-bottom: 1px solid var(--line); cursor: pointer; display: flex; gap: 10px; }
.conv:hover { background: #faf9fc; }
.conv.on { background: var(--accent-soft); }
.avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--accent-soft); color: var(--accent-ink); display: grid; place-items: center; font-weight: 700; flex: none; }
.conv .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv .prev { color: var(--ink-2); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.conv .meta { display: flex; gap: 6px; align-items: center; margin-top: 5px; font-size: 11px; color: var(--ink-3); }
.chat { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: #efeae2; }
.chat .top { background: var(--panel); border-bottom: 1px solid var(--line); padding: 10px 14px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.chat .top select { width: auto; }
.msgs { flex: 1; overflow: auto; padding: 16px 6%; display: flex; flex-direction: column; gap: 6px; }
.bubble { max-width: 70%; padding: 7px 10px 5px; border-radius: 9px; background: #fff; box-shadow: 0 1px 0 rgba(0,0,0,.06); white-space: pre-wrap; word-wrap: break-word; line-height: 1.4; }
.bubble.out { align-self: flex-end; background: #d9fdd3; }
.bubble.bot { align-self: flex-end; background: var(--accent-soft); }
.bubble.note { align-self: center; background: var(--note); max-width: 80%; border: 1px dashed #e6cf6b; }
.bubble .who { font-size: 11px; font-weight: 700; color: var(--accent-ink); margin-bottom: 2px; }
.bubble .time { font-size: 10px; color: var(--ink-3); text-align: right; margin-top: 2px; }
.bubble .time .e { color: var(--bad); font-weight: 700; }
.bubble img { max-width: 260px; max-height: 300px; border-radius: 6px; display: block; margin-bottom: 4px; cursor: zoom-in; }
.bubble audio, .bubble video { max-width: 260px; display: block; }
.sys { align-self: center; font-size: 11px; color: var(--ink-2); background: rgba(255,255,255,.75); padding: 3px 10px; border-radius: 8px; }
.day { align-self: center; font-size: 11px; background: #fff; padding: 3px 10px; border-radius: 8px; color: var(--ink-2); margin: 6px 0; }
.composer { background: var(--panel); border-top: 1px solid var(--line); padding: 10px; position: relative; }
.composer.note textarea { background: var(--note); }
.composer textarea { resize: none; height: 64px; }
.composer .bar { display: flex; gap: 8px; align-items: center; margin-top: 6px; }
.qr-pop { position: absolute; bottom: 100%; left: 10px; right: 10px; background: #fff; border: 1px solid var(--line-strong); border-radius: 10px; max-height: 240px; overflow: auto; box-shadow: 0 8px 24px rgba(0,0,0,.12); }
.qr-pop div { padding: 8px 12px; cursor: pointer; border-bottom: 1px solid var(--line); }
.qr-pop div.on, .qr-pop div:hover { background: var(--accent-soft); }
.qr-pop b { color: var(--accent-ink); }
.empty { display: grid; place-items: center; height: 100%; color: var(--ink-3); text-align: center; padding: 20px; }
.panel { border-left: 1px solid var(--line); background: var(--panel); overflow: auto; padding: 14px; }
.panel .sec { border-bottom: 1px solid var(--line); padding-bottom: 14px; margin-bottom: 14px; }
.qcard { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin-bottom: 8px; cursor: pointer; }
.qcard:hover { border-color: var(--accent); }

/* funil */
.kanban { display: flex; gap: 12px; overflow-x: auto; height: calc(100vh - 110px); padding-bottom: 8px; }
.col { min-width: 250px; width: 250px; background: #eceaf1; border-radius: 12px; display: flex; flex-direction: column; max-height: 100%; }
.col .ch { padding: 10px 12px; font-weight: 600; display: flex; justify-content: space-between; align-items: center; }
.col .ch .sum { font-size: 11px; color: var(--ink-2); font-weight: 400; }
.col .cards { overflow: auto; padding: 0 8px 8px; flex: 1; min-height: 60px; }
.col.drop { outline: 2px dashed var(--accent); }
.card { background: #fff; border-radius: 9px; padding: 10px; margin-bottom: 8px; box-shadow: 0 1px 2px rgba(0,0,0,.08); cursor: grab; }
.card .t { font-weight: 600; margin-bottom: 4px; }
.card .d { font-size: 12px; color: var(--ink-2); }
.card .f { display: flex; justify-content: space-between; margin-top: 8px; font-size: 11px; color: var(--ink-3); }

/* tabelas e configurações */
table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--ink-2); font-weight: 600; background: #faf9fc; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #faf9fc; }
.box { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin-bottom: 16px; max-width: 860px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.qrimg { width: 260px; height: 260px; border: 1px solid var(--line); border-radius: 10px; display: block; margin: 10px 0; }

/* modal e aviso */
.overlay { position: fixed; inset: 0; background: rgba(20,18,28,.45); display: grid; place-items: center; z-index: 50; }
.modal { background: #fff; border-radius: 14px; padding: 20px; width: min(560px, 94vw); max-height: 90vh; overflow: auto; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.overlay img.zoom { max-width: 92vw; max-height: 92vh; border-radius: 8px; }
#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; opacity: 0; pointer-events: none; transition: .2s; z-index: 99; }
#toast.on { opacity: 1; }

@media (max-width: 1100px) { .inbox { grid-template-columns: 300px 1fr; } .panel { display: none; } }
@media (max-width: 760px) {
  html, body { height: 100%; overflow: hidden; }
  .shell { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); height: 100vh; height: 100dvh; }
  .side { flex-direction: row; align-items: center; overflow-x: auto; padding: 6px; gap: 2px; padding-top: max(6px, env(safe-area-inset-top)); }
  .side .brand { display: none; }
  .side a { padding: 8px 10px; margin: 0; white-space: nowrap; font-size: 14px; gap: 4px; }
  .side .me { display: flex; align-items: center; gap: 6px; margin: 0 0 0 auto; border: 0; padding: 0 4px; }
  .side .me > div:first-child, .side .me #availt { display: none; }
  .side .me .switch { margin: 0; }
  .main { min-height: 0; }
  .page { padding: 14px; }
  .inbox, .inbox.nopanel { grid-template-columns: minmax(0, 1fr); height: 100%; min-height: 0; }
  .list, .chat { min-width: 0; min-height: 0; }
  .inbox.has-conv .list { display: none; }
  .inbox:not(.has-conv) .chat { display: none; }
  .tabs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .tabs button { white-space: nowrap; flex: none; }
  .chat .top { padding: 8px 10px; gap: 6px; }
  .chat .top .avatar { display: none; }
  .chat .top .grow { min-width: 0; flex-basis: calc(100% - 110px); }
  .chat .top select, .chat .top button { font-size: 13px; padding: 5px 8px; }
  .chat .top select { max-width: 150px; }
  .msgs { padding: 10px 8px; }
  .bubble { max-width: 85%; }
  .bubble img { max-width: 200px; }
  .composer { padding: 8px; padding-bottom: max(8px, env(safe-area-inset-bottom)); }
  .composer textarea { height: 52px; font-size: 16px; }
  .panel { display: none; }
  .inbox.show-panel .panel { display: block; position: absolute; inset: 0; z-index: 20; padding-top: 56px; }
  .inbox.show-panel { position: relative; }
  #panelclose { display: inline-block !important; position: absolute; top: 10px; right: 10px; }
  .grid2 { grid-template-columns: 1fr; }
  .box { padding: 12px; overflow-x: auto; }
  #ctable { overflow-x: auto; }
  table { min-width: 560px; }
  .kanban { height: calc(100dvh - 140px); }
  .col { min-width: 82vw; width: 82vw; }
  input, textarea, select { font-size: 16px; }
}
#info, #panelclose { display: none; }
@media (max-width: 1100px) { #info { display: inline-block; } }
@media (max-width: 1100px) and (min-width: 761px) {
  .inbox.show-panel { grid-template-columns: 300px 1fr 300px; }
  .inbox.show-panel .panel { display: block; }
}

/* cabeçalho do chat compacto */
.chat .top { flex-wrap: wrap; row-gap: 6px; }
.chat .top .grow { min-width: 200px; }
.chat .top .grow > div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat .top select { max-width: 170px; padding: 6px 8px; }
.chat .top button { white-space: nowrap; padding: 6px 10px; }

.pbanner { display: flex; gap: 8px; align-items: center; background: var(--accent-soft); color: var(--accent-ink); padding: 8px 12px; font-size: 13px; border-bottom: 1px solid var(--line); }
.pbanner button { padding: 4px 10px; font-size: 12px; }
