:root{
  --bg:#fff;--bg2:#f1f3f6;--chat:#dde5ec;--dots:rgba(0,0,0,.05);--line:#e2e6ea;
  --text:#111b21;--muted:#687784;--accent:#2b7de9;--accent-soft:#e3effd;
  --in:#fff;--out:#dcf5cb;--meta:rgba(0,0,0,.45);--sel:#e3eefc;--pill:rgba(46,66,86,.5);
  --orange:#ee8526;--green:#22a861;--red:#e5484d;--gold:#c08a00;--shadow:0 1px 1.5px rgba(0,0,0,.13);
  color-scheme:light;
}
@media (prefers-color-scheme:dark){:root{
  --bg:#17212b;--bg2:#202c38;--chat:#0e1621;--dots:rgba(255,255,255,.035);--line:#243241;
  --text:#e8eef4;--muted:#8394a5;--accent:#5ea4f6;--accent-soft:#213448;
  --in:#1d2a37;--out:#2b5278;--meta:rgba(255,255,255,.5);--sel:#2b5278;--pill:rgba(0,0,0,.4);
  --gold:#f3c34a;--shadow:none;color-scheme:dark;
}}
*{box-sizing:border-box;margin:0;padding:0}
html,body{height:100%}
body{font:15px/1.4 system-ui,-apple-system,"Segoe UI",Roboto,Helvetica,Arial,sans-serif;background:var(--chat);color:var(--text);-webkit-font-smoothing:antialiased;overflow:hidden;-webkit-tap-highlight-color:transparent}
button{font:inherit;color:inherit;background:none;border:0;cursor:pointer}
input,textarea{font:inherit;color:inherit}
.hidden{display:none!important}
.muted{color:var(--muted)}
svg{width:22px;height:22px;fill:none;stroke:currentColor;stroke-width:2;stroke-linecap:round;stroke-linejoin:round}
svg .f{fill:currentColor;stroke:none}
.list,.msgs,.info,.sheet{scrollbar-width:thin;scrollbar-color:var(--line) transparent}

/* ---------- login ---------- */
.login{position:fixed;inset:0;display:grid;place-items:center;padding:16px;background:var(--chat)}
.login-card{width:min(380px,100%);background:var(--bg);border-radius:20px;padding:28px 24px;display:flex;flex-direction:column;gap:14px;box-shadow:0 10px 40px rgba(0,0,0,.15);text-align:center}
.login-logo{margin:0 auto}
.login-card h1{font-size:24px}
.login-card label{text-align:left}
.err{color:var(--red);font-size:14px;min-height:20px}

/* ---------- layout ---------- */
.app{display:grid;grid-template-columns:minmax(300px,380px) 1fr;height:100dvh}
.app.info-open{grid-template-columns:minmax(300px,380px) 1fr 340px}
.side{display:flex;flex-direction:column;background:var(--bg);border-right:1px solid var(--line);min-width:0;height:100dvh}
.side-head{display:flex;align-items:center;gap:8px;padding:8px 12px 8px 6px;padding-top:max(8px,env(safe-area-inset-top))}
.me{flex:1;min-width:0;display:flex;flex-direction:column;line-height:1.25}
.me b{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.me small{font-size:12px}
.net{width:9px;height:9px;border-radius:50%;background:var(--green);flex:none}
.net.off{background:var(--red);animation:blink 1s infinite}
.icon-btn{width:40px;height:40px;border-radius:50%;display:grid;place-items:center;color:var(--muted);flex:none}
.icon-btn:hover{background:var(--bg2)}
.search{padding:0 12px 8px}
.search input{width:100%;height:40px;border-radius:20px;border:1.5px solid transparent;background:var(--bg2);padding:0 16px;outline:none;font-size:16px}
.search input:focus{border-color:var(--accent);background:var(--bg)}
.filters{display:flex;gap:6px;padding:0 12px 10px;overflow-x:auto;scrollbar-width:none;border-bottom:1px solid var(--line)}
.filters::-webkit-scrollbar{display:none}
.filters button{flex:none;padding:6px 12px;border-radius:16px;background:var(--bg2);font-size:13px;font-weight:600;color:var(--muted);display:flex;gap:6px;align-items:center}
.filters button.on{background:var(--accent);color:#fff}
.cnt{background:var(--orange);color:#fff;border-radius:9px;padding:0 6px;font-size:11px;line-height:17px}
.cnt:empty{display:none}
.filters button.on .cnt{background:#fff;color:var(--accent)}

/* ---------- lista de conversas ---------- */
.list{flex:1;overflow-y:auto;overscroll-behavior:contain;padding:4px 0 max(8px,env(safe-area-inset-bottom))}
.row{display:flex;gap:12px;padding:8px 10px;cursor:pointer;align-items:center;border-radius:12px;margin:1px 6px}
.row:hover{background:var(--bg2)}
.row.sel{background:var(--sel)}
.ava{width:50px;height:50px;border-radius:50%;flex:none;display:grid;place-items:center;color:#fff;font-weight:600;font-size:18px;position:relative;background:var(--c,#7986cb)}
.ava.on::after{content:"";position:absolute;right:0;bottom:1px;width:13px;height:13px;border-radius:50%;background:var(--green);border:2.5px solid var(--bg)}
.rm{flex:1;min-width:0;display:flex;flex-direction:column;gap:2px}
.rt,.rb{display:flex;align-items:center;gap:6px;min-width:0}
.rt b{flex:1;min-width:0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;font-weight:600}
.tm{font-size:12px;color:var(--muted);flex:none}
.pv{flex:1;min-width:0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;color:var(--muted);font-size:14px}
.you{color:var(--accent)}
.badge{min-width:22px;height:22px;border-radius:11px;background:var(--orange);color:#fff;font-size:12px;font-weight:700;display:grid;place-items:center;padding:0 6px;flex:none}
.stars{font-size:11.5px;color:var(--gold);background:rgba(240,180,0,.14);padding:1px 6px;border-radius:8px;flex:none;font-weight:700}
.wait{font-size:11.5px;padding:1px 6px;border-radius:8px;background:rgba(238,133,38,.16);color:var(--orange);flex:none;font-weight:700}
.wait.late{background:rgba(229,72,77,.16);color:var(--red)}
.eye{font-size:12px;flex:none}
.tick{color:var(--accent);font-size:13px;flex:none}
.list-empty{padding:40px 20px;text-align:center;color:var(--muted)}

/* ---------- conversa ---------- */
.chat{display:flex;flex-direction:column;min-width:0;height:100dvh;position:relative;background:var(--chat) radial-gradient(var(--dots) 1px,transparent 1px) 0 0/22px 22px}
.empty{margin:auto;text-align:center;display:flex;flex-direction:column;align-items:center;gap:8px;padding:20px}
.empty-ic{width:76px;height:76px;border-radius:50%;background:var(--bg);display:grid;place-items:center;color:var(--accent);margin-bottom:6px}
.empty-ic svg{width:36px;height:36px}
.chat-head{display:flex;align-items:center;gap:10px;padding:7px 10px;background:var(--bg);border-bottom:1px solid var(--line);padding-top:max(7px,env(safe-area-inset-top));z-index:2}
.chat-head .ava{width:42px;height:42px;font-size:15px}
.back{display:none}
.ch-info{flex:1;min-width:0;text-align:left;display:flex;flex-direction:column;line-height:1.3}
.ch-info b{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.ch-info small{font-size:12.5px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.ch-info small.on{color:var(--accent)}
.viewers{background:rgba(238,133,38,.16);color:var(--orange);font-size:13px;font-weight:600;padding:6px 14px;text-align:center}
.msgs{flex:1;overflow-y:auto;overscroll-behavior:contain;padding:10px max(14px,calc((100% - 780px)/2));display:flex;flex-direction:column;gap:3px}
.loading{margin:auto;color:var(--muted)}
.day{align-self:center;margin:10px 0 6px;font-size:12.5px;font-weight:600;position:sticky;top:4px;z-index:1}
.day span,.sys span{display:inline-block;background:var(--pill);color:#fff;padding:3px 11px;border-radius:12px}
.sys{align-self:center;max-width:90%;text-align:center;margin:6px 0;font-size:13px}
.b{max-width:min(520px,85%);padding:6px 9px 7px 11px;border-radius:16px;box-shadow:var(--shadow);white-space:pre-wrap;overflow-wrap:anywhere;font-size:15px}
.b.in{align-self:flex-start;background:var(--in);border-bottom-left-radius:5px}
.b.out{align-self:flex-end;background:var(--out);border-bottom-right-radius:5px}
.b.del .tx{text-decoration:line-through;opacity:.6}
.b.sending{opacity:.55}
.meta{float:right;margin:7px 0 -5px 12px;font-size:11.5px;color:var(--meta);white-space:nowrap;user-select:none}
.meta i{font-style:normal;margin-right:5px}
.b.media{padding:3px}
.b.media .tx{padding:5px 8px 1px}
.b.media .meta{margin-right:7px}
.ph{display:block;max-width:100%;width:320px;max-height:380px;min-height:110px;object-fit:cover;border-radius:13px;cursor:zoom-in;background:var(--bg2);user-select:none;-webkit-user-drag:none}
.vid{position:relative;cursor:pointer;display:block;border-radius:13px;overflow:hidden}
.vid::after{content:"▶";position:absolute;inset:0;margin:auto;width:52px;height:52px;border-radius:50%;background:rgba(0,0,0,.55);color:#fff;display:grid;place-items:center;font-size:19px;padding-left:4px}
.noprev{width:260px;max-width:100%;height:140px;display:grid;place-items:center;border-radius:13px;background:var(--bg2);color:var(--muted)}
audio{width:270px;max-width:100%;height:40px;display:block;margin:2px 0}
.sticker{font-size:56px;line-height:1.1;padding:2px 4px}
.card{padding:3px 2px 1px;min-width:210px}
.card-h{font-weight:700;margin-bottom:3px}
.card .tx{font-size:14px}
.chip{display:inline-block;font-size:12px;font-weight:700;padding:2px 9px;border-radius:10px;margin-top:6px}
.chip.ok{background:rgba(34,168,97,.18);color:var(--green)}
.chip.wait{background:rgba(238,133,38,.18);color:var(--orange)}
.lock{display:flex;flex-direction:column;gap:6px;padding:8px 8px 4px;min-width:230px}
.lock .btns{display:flex;gap:6px;flex-wrap:wrap;margin-top:4px}
.more{align-self:center;margin:6px 0;padding:6px 14px;border-radius:14px;background:var(--bg);color:var(--accent);font-size:13px;font-weight:600;box-shadow:var(--shadow)}
.to-bottom{position:absolute;right:18px;bottom:82px;width:44px;height:44px;border-radius:50%;background:var(--bg);box-shadow:0 2px 8px rgba(0,0,0,.25);display:grid;place-items:center;color:var(--muted);z-index:3}
.composer{display:flex;align-items:flex-end;gap:6px;padding:8px max(10px,calc((100% - 800px)/2));padding-bottom:max(8px,env(safe-area-inset-bottom))}
.composer textarea{flex:1;resize:none;border:0;outline:none;background:var(--bg);border-radius:22px;padding:11px 16px;max-height:160px;min-height:44px;box-shadow:var(--shadow);font-size:16px;line-height:1.35}
.composer .icon-btn{background:var(--bg);box-shadow:var(--shadow);width:44px;height:44px}
.send{width:44px;height:44px;border-radius:50%;background:var(--accent);color:#fff;display:grid;place-items:center;flex:none;box-shadow:var(--shadow)}
.send svg{width:20px;height:20px;margin-left:2px}

/* ---------- botões e campos ---------- */
.btn{display:inline-flex;align-items:center;justify-content:center;gap:6px;height:40px;padding:0 16px;border-radius:10px;font-weight:600;background:var(--bg2);color:var(--text);white-space:nowrap}
.btn.primary{background:var(--accent);color:#fff}
.btn.accent{background:var(--accent-soft);color:var(--accent)}
.btn.danger{background:rgba(229,72,77,.14);color:var(--red)}
.btn.small{height:34px;padding:0 12px;font-size:13.5px;border-radius:17px}
.btn.wide{width:100%}
.btn:disabled{opacity:.5;cursor:default}
.link{color:var(--accent);font-weight:600;padding:4px 0;align-self:flex-start}
label{display:flex;flex-direction:column;gap:6px;font-size:13px;color:var(--muted);font-weight:600}
label input,label textarea,.sheet input,.sheet textarea,.info textarea{width:100%;border:1.5px solid var(--line);background:var(--bg2);border-radius:10px;padding:10px 12px;outline:none;font-size:16px;color:var(--text);font-weight:400}
label input:focus,label textarea:focus,.sheet input:focus,.sheet textarea:focus,.info textarea:focus{border-color:var(--accent)}
.sheet textarea{resize:vertical;min-height:110px}
.counter{font-size:12.5px;color:var(--muted);text-align:right}
.counter.ok{color:var(--green)}

/* ---------- painel de detalhes ---------- */
.info{background:var(--bg);border-left:1px solid var(--line);overflow-y:auto;height:100dvh;padding:12px 16px 24px;padding-top:max(12px,env(safe-area-inset-top))}
.info-top{display:flex;align-items:center;justify-content:space-between;margin-bottom:6px;font-weight:700}
.info .ava.big{width:96px;height:96px;font-size:34px;margin:6px auto 10px}
.info h2{text-align:center;font-size:19px}
.info .sub{text-align:center;color:var(--muted);font-size:13.5px;margin-bottom:14px}
.kv{display:grid;grid-template-columns:auto 1fr;gap:8px 12px;font-size:14px;background:var(--bg2);border-radius:12px;padding:12px;margin-bottom:14px}
.kv dt{color:var(--muted)}
.kv dd{text-align:right;font-weight:600;overflow-wrap:anywhere}
.info textarea{min-height:150px;resize:vertical}
.saved{font-size:12px;color:var(--green);min-height:16px;margin-top:4px}

/* ---------- janelas ---------- */
.modal{position:fixed;inset:0;background:rgba(0,0,0,.45);display:flex;align-items:center;justify-content:center;z-index:20;padding:16px}
.sheet{background:var(--bg);width:min(580px,100%);max-height:min(90dvh,860px);overflow-y:auto;border-radius:18px;padding:18px;box-shadow:0 10px 40px rgba(0,0,0,.35);display:flex;flex-direction:column;gap:12px}
.sheet-h{display:flex;align-items:flex-start;gap:10px}
.sheet-h div{flex:1;min-width:0}
.sheet-h h3{font-size:18px}
.sheet-h small{color:var(--muted)}
.chips{display:flex;gap:6px;flex-wrap:wrap}
.chips button{padding:6px 12px;border-radius:16px;background:var(--bg2);font-size:13.5px;font-weight:600}
.chips button.on{background:var(--accent);color:#fff}
.packs{display:grid;grid-template-columns:repeat(auto-fill,minmax(150px,1fr));gap:10px}
.pack{border-radius:14px;background:var(--bg2);overflow:hidden;cursor:pointer;text-align:left;display:flex;flex-direction:column;border:2px solid transparent}
.pack:hover{border-color:var(--accent)}
.thumbs{display:grid;grid-template-columns:repeat(3,1fr);gap:2px;aspect-ratio:3/2;overflow:hidden;background:var(--line)}
.thumbs>*{width:100%;height:100%;object-fit:cover;filter:blur(6px);transform:scale(1.15)}
.thumbs .tv{display:grid;place-items:center;background:var(--bg);color:var(--muted);font-size:20px;filter:none;transform:none}
.pack-b{padding:8px 10px}
.pack-b b{display:block;font-size:14px}
.pack-b small{color:var(--muted);font-size:12px;display:block;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.prev-row{display:flex;gap:6px;overflow-x:auto;padding-bottom:4px}
.prev-row>.pi{width:86px;height:86px;flex:none;border-radius:10px;overflow:hidden;position:relative;background:var(--bg2);display:grid;place-items:center;color:var(--muted);font-size:22px}
.prev-row .pi img{width:100%;height:100%;object-fit:cover;filter:blur(8px);transition:filter .2s;-webkit-user-drag:none;user-select:none}
.prev-row .pi.show img{filter:none}
.prev-row .pi.go{cursor:pointer}
.prev-row .pi.v.go::after{content:"▶";position:absolute;inset:0;margin:auto;width:32px;height:32px;border-radius:50%;background:rgba(0,0,0,.55);color:#fff;display:grid;place-items:center;font-size:13px;padding-left:2px}
body.secure .prev-row>.pi{width:112px;height:112px}
body.secure .thumbs>*{filter:none;transform:none}
.pack-info{display:flex;flex-direction:column;gap:4px}
.descr{background:var(--bg2);border-radius:10px;padding:10px 12px;font-size:14px;white-space:pre-wrap;line-height:1.45}
.noprev.lockapp{display:flex;flex-direction:column;gap:4px;justify-content:center;text-align:center;padding:12px}
.peek input{flex:1;min-width:0}
.lg-app{font-size:13.5px;color:var(--muted);line-height:1.5}
.lg-app a{color:var(--accent);font-weight:600}
.lg-app.hot{background:var(--accent-soft);border-radius:10px;padding:8px}
.viewer{position:fixed;inset:0;background:rgba(0,0,0,.92);z-index:30;display:flex;align-items:center;justify-content:center;padding:16px}
.viewer img,.viewer video{max-width:100%;max-height:100%;border-radius:8px;user-select:none;-webkit-user-drag:none}
.viewer .x{position:absolute;top:max(12px,env(safe-area-inset-top));right:12px;color:#fff;background:rgba(255,255,255,.14)}
.viewer p{color:#fff;text-align:center;padding:20px}
.pop{position:fixed;z-index:25;background:var(--bg);border-radius:14px;box-shadow:0 8px 30px rgba(0,0,0,.3);padding:6px;min-width:250px;max-width:calc(100vw - 24px)}
.pop button{display:flex;width:100%;align-items:center;gap:12px;padding:11px 12px;border-radius:9px;text-align:left;font-size:14.5px}
.pop button:hover{background:var(--bg2)}
.pop button.danger{color:var(--red)}
.pop .sep{height:1px;background:var(--line);margin:4px 6px}
.pop .hd{padding:8px 12px 6px;font-size:13px;color:var(--muted)}
.toast{position:fixed;left:50%;bottom:max(24px,env(safe-area-inset-bottom));transform:translate(-50%,40px);background:#1f2933;color:#fff;padding:10px 16px;border-radius:12px;font-size:14px;opacity:0;pointer-events:none;transition:.25s;z-index:40;max-width:calc(100vw - 32px);text-align:center}
.toast.show{opacity:1;transform:translate(-50%,0)}

/* ---------- administração ---------- */
.tabs{display:flex;gap:4px;background:var(--bg2);padding:4px;border-radius:12px;overflow-x:auto;scrollbar-width:none}
.tabs button{flex:1 0 auto;padding:8px 10px;border-radius:9px;font-weight:600;font-size:13.5px;color:var(--muted);white-space:nowrap}
.tabs button.on{background:var(--bg);color:var(--text);box-shadow:var(--shadow)}
.adm-sec{background:var(--bg2);border-radius:14px;padding:14px;display:flex;flex-direction:column;gap:10px;font-size:14px}
.adm-sec h4{font-size:15px}
.adm-sec label input{background:var(--bg)}
.st-line{display:flex;align-items:center;gap:8px}
.dot{width:9px;height:9px;border-radius:50%;flex:none;background:var(--muted)}
.dot.ok{background:var(--green)}
.dot.bad{background:var(--red)}
.sess{display:flex;align-items:center;gap:10px;padding:9px 0;border-top:1px solid var(--line)}
.sess:first-of-type{border-top:0}
.sess>div{flex:1;min-width:0}
.sess small{display:block;color:var(--muted);font-size:12px}
.grid2{display:grid;grid-template-columns:1fr 1fr;gap:10px}
.hint{font-size:13px;color:var(--muted);line-height:1.5}
@keyframes blink{50%{opacity:.3}}
.sheet select{width:100%;border:1.5px solid var(--line);background:var(--bg);border-radius:10px;padding:10px 12px;font-size:16px;color:var(--text)}
.creds{background:rgba(34,168,97,.14);border:1.5px solid var(--green);border-radius:12px;padding:12px;display:flex;flex-direction:column;gap:6px;font-size:14px}
.creds code{font-size:16px;font-weight:700;user-select:all}
.badge-s{font-size:11px;font-weight:700;padding:1px 7px;border-radius:8px;background:var(--bg);color:var(--muted);margin-left:4px}
.badge-s.ok{color:var(--green)}
.badge-s.bad{color:var(--red)}
.log-row{display:grid;grid-template-columns:auto 1fr;gap:2px 10px;padding:8px 0;border-top:1px solid var(--line);font-size:13px}
.log-row:first-of-type{border-top:0}
.log-row small{grid-column:2;color:var(--muted)}
.peek{display:flex;align-items:center;gap:8px}

/* ---------- proteção (só para chatters) ---------- */
body.staff .app::after{content:"";position:fixed;inset:0;pointer-events:none;z-index:50;background:var(--wm)}
body.staff .viewer::after{content:"";position:absolute;inset:0;pointer-events:none;background:var(--wm-strong)}
body.staff img,body.staff video{-webkit-user-drag:none;-webkit-touch-callout:none;user-select:none}
body.guard .ph,body.guard .thumbs,body.guard .prev-row,body.guard .viewer img{filter:blur(28px)!important}
body.guard .viewer video{visibility:hidden}

/* ---------- celular ---------- */
@media (max-width:760px){
  .app,.app.info-open{grid-template-columns:1fr}
  .chat{display:none}
  .app.chat-open .side{display:none}
  .app.chat-open .chat{display:flex}
  .back{display:grid}
  .info{position:fixed;inset:0;z-index:15;border:0}
  .msgs{padding:8px}
  .b{max-width:88%}
  .ph{width:250px}
  .composer{padding:6px 8px;padding-bottom:max(6px,env(safe-area-inset-bottom))}
  .modal{align-items:flex-end;padding:0}
  .sheet{border-radius:18px 18px 0 0;max-height:92dvh;padding-bottom:max(18px,env(safe-area-inset-bottom))}
  .to-bottom{bottom:70px;right:10px}
  .grid2{grid-template-columns:1fr}
}
@media (min-width:761px) and (max-width:1100px){
  .app.info-open{grid-template-columns:minmax(280px,340px) 1fr}
  .info{position:fixed;right:0;top:0;bottom:0;width:340px;z-index:15;box-shadow:-8px 0 30px rgba(0,0,0,.2)}
}
.big-code{display:block;font-size:17px;font-weight:700;background:var(--bg);border-radius:10px;padding:10px 12px;user-select:all;text-align:center}
.tgv{display:flex;flex-direction:column;gap:6px;margin-top:10px}
.tgv small{font-size:12.5px;line-height:1.45}
.viewer .vt{position:absolute;top:max(14px,env(safe-area-inset-top));left:14px;background:rgba(0,0,0,.6);color:#fff;font-weight:700;font-size:14px;padding:6px 12px;border-radius:14px;z-index:2}
body.staff .viewer::after{animation:wm-drift 9s linear infinite}
body.staff .viewer.timed::after{background:var(--wm-strong),var(--wm-strong);background-position:0 0,150px 75px;animation:wm-drift2 7s linear infinite}
@keyframes wm-drift{from{background-position:0 0}to{background-position:300px 150px}}
@keyframes wm-drift2{from{background-position:0 0,150px 75px}to{background-position:300px 150px,450px 225px}}
@media (prefers-reduced-motion:reduce){body.staff .viewer::after{animation-duration:30s}}
