:root{
  --brand:#2563eb;
  --brand-dark:#1d4ed8;
  --bg:#f4f6f9;
  --panel:#ffffff;
  --border:#e2e6ec;
  --text:#1f2430;
  --text-muted:#6b7280;
  --bubble-me:#dbeafe;
  --bubble-other:#ffffff;
  --danger:#dc2626;
  --online:#22c55e;
  --offline:#9ca3af;
  --unread:#ef4444;
  --radius:10px;
}
*{box-sizing:border-box}
/* Author CSS normally beats the UA [hidden] rule even at equal specificity
   (origin precedes specificity in the cascade), so any class below that sets
   its own `display` (e.g. .chat-active, .recording-bar) would otherwise stay
   visible while `hidden` is set. This blanket !important rule guarantees the
   hidden attribute always wins, for every element in the app. */
[hidden]{display:none !important}
body{
  margin:0;
  font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif;
  background:var(--bg);
  color:var(--text);
  height:100vh;
  overflow:hidden;
}
button{font-family:inherit;cursor:pointer}
input{font-family:inherit}

.screen{width:100vw;height:100vh;overflow:auto}

/* ---------- Login ---------- */
#screen-login,#screen-first-access{
  display:flex;align-items:center;justify-content:center;
  background:linear-gradient(135deg,var(--brand),#0ea5e9);
}
.login-card{
  background:var(--panel);
  border-radius:16px;
  padding:36px 32px;
  width:360px;
  max-width:90vw;
  box-shadow:0 20px 50px rgba(0,0,0,.25);
}
.brand{text-align:center;margin-bottom:20px}
.brand-logo{
  width:56px;height:56px;border-radius:14px;background:var(--brand);
  color:#fff;font-weight:700;font-size:20px;
  display:flex;align-items:center;justify-content:center;margin:0 auto 10px;
}
.brand h1{margin:4px 0 2px;font-size:22px}
.brand p{margin:0;color:var(--text-muted);font-size:13px}
#form-login label,#form-first-access label,#form-profile label,#form-usuario label{
  display:block;margin-bottom:14px;font-size:13px;color:var(--text-muted);font-weight:600;
}
#form-login input,#form-first-access input,#form-profile input,#form-usuario input{
  width:100%;margin-top:6px;padding:10px 12px;border:1px solid var(--border);
  border-radius:8px;font-size:14px;color:var(--text);
}
.login-hint{font-size:12px;color:var(--text-muted);text-align:center;margin-top:16px}
.form-error{
  background:#fee2e2;color:#991b1b;font-size:13px;padding:8px 10px;border-radius:8px;margin-bottom:12px;
}

.btn{border:none;border-radius:8px;padding:10px 16px;font-size:14px;font-weight:600;transition:.15s}
.btn-block{width:100%}
.btn-primary{background:var(--brand);color:#fff}
.btn-primary:hover{background:var(--brand-dark)}
.btn-secondary{background:#eef1f6;color:var(--text)}
.btn-secondary:hover{background:#dfe4ec}
.btn-danger{background:var(--danger);color:#fff}
.btn-danger:hover{background:#b91c1c}

/* ---------- App shell ---------- */
.app-shell{display:flex;height:100vh}
.sidebar{
  width:320px;min-width:280px;background:var(--panel);border-right:1px solid var(--border);
  display:flex;flex-direction:column;
}
.sidebar-header{
  display:flex;align-items:center;justify-content:space-between;padding:14px;border-bottom:1px solid var(--border);
}
.me{display:flex;align-items:center;gap:10px;min-width:0}
.me-text{display:flex;flex-direction:column;min-width:0}
.me-text strong{font-size:14px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.me-sector{font-size:12px;color:var(--text-muted)}
.sidebar-actions{display:flex;gap:4px}
.icon-btn{
  background:transparent;border:none;font-size:17px;padding:6px;border-radius:8px;line-height:1;
}
.icon-btn:hover{background:#eef1f6}

.avatar{
  width:40px;height:40px;border-radius:50%;background:var(--brand);color:#fff;
  display:flex;align-items:center;justify-content:center;font-weight:700;font-size:14px;
  flex-shrink:0;position:relative;text-transform:uppercase;
}
.avatar-lg{width:80px;height:80px;font-size:26px;margin:0 auto}
.avatar.group{background:#7c3aed}
.status-dot{
  position:absolute;bottom:-1px;right:-1px;width:11px;height:11px;border-radius:50%;
  border:2px solid var(--panel);background:var(--offline);
}
.status-dot.online{background:var(--online)}

.sidebar-search{padding:10px 12px}
.sidebar-search input{
  width:100%;padding:9px 12px;border-radius:20px;border:1px solid var(--border);font-size:13px;background:var(--bg);
}
.sidebar-filters{display:flex;gap:6px;padding:0 12px 8px}
.filter-btn{
  background:var(--bg);border:1px solid var(--border);border-radius:20px;padding:5px 12px;font-size:12px;color:var(--text-muted);
}
.filter-btn.active{background:var(--brand);color:#fff;border-color:var(--brand)}

.conversation-list{flex:1;overflow-y:auto}
.conv-item{
  display:flex;align-items:center;gap:10px;padding:10px 14px;cursor:pointer;border-bottom:1px solid #f0f2f6;
}
.conv-item:hover{background:#f6f8fb}
.conv-item.active{background:#eaf1ff}
.conv-main{flex:1;min-width:0}
.conv-top{display:flex;justify-content:space-between;align-items:baseline;gap:6px}
.conv-name{font-size:14px;font-weight:600;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.conv-time{font-size:11px;color:var(--text-muted);flex-shrink:0}
.conv-bottom{display:flex;justify-content:space-between;align-items:center;gap:6px;margin-top:2px}
.conv-preview{font-size:12px;color:var(--text-muted);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.conv-badge{
  background:var(--unread);color:#fff;font-size:11px;font-weight:700;border-radius:10px;
  min-width:18px;height:18px;display:flex;align-items:center;justify-content:center;padding:0 5px;flex-shrink:0;
}
.conv-empty-msg{padding:24px;text-align:center;color:var(--text-muted);font-size:13px}

/* ---------- Chat ---------- */
.chat-main{flex:1;display:flex;flex-direction:column;background:#eef2f7;min-width:0}
.chat-empty{flex:1;display:flex;align-items:center;justify-content:center;color:var(--text-muted)}
.chat-active{display:flex;flex-direction:column;height:100%;min-width:0}
.chat-header{
  display:flex;align-items:center;justify-content:space-between;padding:10px 16px;background:var(--panel);
  border-bottom:1px solid var(--border);
}
.chat-header-info{display:flex;align-items:center;gap:10px;cursor:pointer}
.chat-header-info strong{font-size:15px;display:block}
.chat-subtitle{font-size:12px;color:var(--text-muted)}
.chat-header-actions{display:flex;gap:4px}

.messages{flex:1;overflow-y:auto;padding:16px 22px;display:flex;flex-direction:column;gap:4px}
.msg-row{display:flex;margin-bottom:6px}
.msg-row.me{justify-content:flex-end}
.bubble{
  max-width:60%;padding:8px 12px;border-radius:12px;background:var(--bubble-other);
  box-shadow:0 1px 2px rgba(0,0,0,.06);font-size:14px;position:relative;
}
.msg-row.me .bubble{background:var(--bubble-me)}
.bubble .sender-name{font-size:11.5px;font-weight:700;color:var(--brand);margin-bottom:2px;display:block}
.bubble .forwarded-tag{font-size:11px;color:var(--text-muted);font-style:italic;margin-bottom:3px}
.bubble .msg-text{white-space:pre-wrap;word-break:break-word}
.bubble .msg-time{font-size:10.5px;color:var(--text-muted);margin-top:3px;text-align:right}
.bubble img.msg-image{max-width:260px;border-radius:8px;display:block;cursor:pointer;margin-top:2px}
.bubble video.msg-video{max-width:280px;max-height:320px;border-radius:8px;display:block;margin-top:2px;background:#000}
.bubble audio{max-width:240px;margin-top:2px}
.doc-chip{
  display:flex;align-items:center;gap:8px;background:#f3f5f9;border-radius:8px;padding:8px 10px;margin-top:2px;
}
.doc-chip .doc-icon{font-size:20px}
.doc-chip .doc-meta{flex:1;min-width:0}
.doc-chip .doc-name{font-size:13px;font-weight:600;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;display:block}
.doc-chip .doc-size{font-size:11px;color:var(--text-muted)}
.doc-chip a{font-size:12px;color:var(--brand);text-decoration:none;font-weight:600}
.msg-actions{display:flex;gap:6px;margin-top:4px;opacity:0;transition:.15s}
.msg-row:hover .msg-actions{opacity:1}
.msg-actions button{background:none;border:none;font-size:12px;color:var(--text-muted);cursor:pointer}
.msg-actions button:hover{color:var(--brand)}

.msg-row.system{justify-content:center}
.system-note{
  background:#e5e9f0;color:var(--text-muted);font-size:12px;padding:5px 12px;border-radius:14px;text-align:center;
}
.msg-row.call .bubble{background:#fef9c3}

.composer{display:flex;align-items:center;gap:6px;padding:10px 16px;background:var(--panel);border-top:1px solid var(--border)}
.composer input[type=text]{
  flex:1;padding:10px 14px;border-radius:20px;border:1px solid var(--border);font-size:14px;
}
.recording-bar{
  display:flex;align-items:center;gap:10px;padding:10px 16px;background:#fff1f1;border-top:1px solid var(--border);font-size:13px;
}
.rec-dot{width:10px;height:10px;border-radius:50%;background:var(--danger);display:inline-block;animation:pulse 1s infinite}
@keyframes pulse{0%,100%{opacity:1}50%{opacity:.3}}
.recording-bar button{margin-left:auto}
.recording-bar #btn-rec-stop{margin-left:6px}

/* ---------- Modals ---------- */
.modal-overlay{position:fixed;inset:0;background:rgba(15,23,42,.5);z-index:40}
.modal{
  position:fixed;top:50%;left:50%;transform:translate(-50%,-50%);background:var(--panel);
  border-radius:14px;padding:24px 26px;width:400px;max-width:92vw;max-height:88vh;overflow:auto;z-index:41;
  box-shadow:0 20px 60px rgba(0,0,0,.3);
}
.modal-lg{width:520px}
.modal h2{margin:0 0 16px;font-size:18px}
.modal-hint{font-size:12px;color:var(--text-muted)}
.modal-hint-inline{font-weight:400;font-size:11.5px;color:var(--text-muted)}
.modal-actions{display:flex;justify-content:flex-end;gap:8px;margin-top:18px}
.readonly-field input{background:#f3f5f9;color:var(--text-muted)}
#modal-imagem{background:transparent;box-shadow:none;padding:0;text-align:center}
#modal-imagem img{max-width:80vw;max-height:75vh;border-radius:10px}

.member-picker{max-height:260px;overflow-y:auto;border:1px solid var(--border);border-radius:8px;margin-top:8px}
.member-row{display:flex;align-items:center;gap:10px;padding:8px 10px;border-bottom:1px solid #f0f2f6}
.member-row:last-child{border-bottom:none}
.member-row input{margin-right:2px}
.member-row .m-name{font-size:13px;font-weight:600}
.member-row .m-sector{font-size:11px;color:var(--text-muted);display:block}
.member-row.disabled{opacity:.45}

.group-members-list{max-height:220px;overflow-y:auto;margin-bottom:14px}
.group-member-item{display:flex;align-items:center;gap:10px;padding:6px 0}
.group-member-item .m-info{flex:1;min-width:0}
.group-member-item .m-info strong{font-size:13px;display:block}
.group-member-item .m-info span{font-size:11px;color:var(--text-muted)}
.group-member-item button{background:none;border:none;color:var(--danger);font-size:12px;cursor:pointer}

.forward-preview{background:var(--bg);border-radius:8px;padding:10px;font-size:13px;margin-bottom:10px;color:var(--text-muted)}

.preview-envio-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(120px,1fr));gap:12px;max-height:400px;overflow-y:auto;padding:4px}
.preview-item{position:relative;border:1px solid var(--border);border-radius:10px;overflow:hidden;background:var(--bg);display:flex;flex-direction:column}
.preview-item img,.preview-item video{width:100%;height:110px;object-fit:cover;background:#000;display:block}
.preview-item .preview-doc{width:100%;height:110px;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:6px;font-size:34px;background:#eef1f6}
.preview-item .preview-name{font-size:11px;padding:6px 8px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:var(--text-muted)}
.preview-item .preview-remove{
  position:absolute;top:4px;right:4px;width:22px;height:22px;border-radius:50%;border:none;
  background:rgba(0,0,0,.6);color:#fff;font-size:13px;line-height:1;cursor:pointer;display:flex;align-items:center;justify-content:center;
}
.preview-item .preview-remove:hover{background:rgba(220,38,38,.9)}
.preview-count{font-size:12px;color:var(--text-muted);margin:-4px 0 10px}

/* ---------- Admin ---------- */
.admin-header{
  display:flex;align-items:center;justify-content:space-between;padding:16px 26px;background:var(--panel);border-bottom:1px solid var(--border);
}
.admin-header h1{font-size:18px;margin:0}
.admin-body{padding:20px 26px}
.admin-toolbar{display:flex;gap:12px;margin-bottom:16px}
.admin-toolbar input{flex:1;max-width:320px;padding:9px 12px;border-radius:8px;border:1px solid var(--border)}
.admin-table{width:100%;border-collapse:collapse;background:var(--panel);border-radius:10px;overflow:hidden}
.admin-table th,.admin-table td{padding:10px 12px;text-align:left;font-size:13px;border-bottom:1px solid var(--border)}
.admin-table th{background:#f3f5f9;color:var(--text-muted);font-weight:700;font-size:12px;text-transform:uppercase}
.tag{padding:3px 8px;border-radius:12px;font-size:11px;font-weight:700}
.tag.active{background:#dcfce7;color:#166534}
.tag.inactive{background:#fee2e2;color:#991b1b}
.tag.online{background:#dcfce7;color:#166534}
.tag.offline{background:#f1f5f9;color:#64748b}
.admin-actions{display:flex;gap:6px;flex-wrap:wrap}
.admin-actions button{
  background:#eef1f6;border:none;padding:5px 9px;border-radius:6px;font-size:11.5px;font-weight:600;
}
.admin-actions button.danger{background:#fee2e2;color:#991b1b}
.admin-actions button:hover{filter:brightness(.95)}

/* ---------- Calls ---------- */
.btn-sm{padding:6px 12px;font-size:12.5px}

.call-box{text-align:center;padding:10px}
.call-box h2{margin:14px 0 4px}
#call-status,#call-timer{color:var(--text-muted);margin:0}
.call-actions{display:flex;justify-content:center;gap:14px;margin-top:22px}

.call-video-grid{
  display:grid;grid-template-columns:repeat(auto-fit,minmax(160px,1fr));gap:8px;
  margin-top:14px;max-height:60vh;overflow-y:auto;
}
.call-video-grid.few{grid-template-columns:1fr}
.call-tile{
  position:relative;background:#111;border-radius:10px;overflow:hidden;
  aspect-ratio:4/3;display:flex;align-items:center;justify-content:center;
}
.call-tile video{width:100%;height:100%;object-fit:cover}
.call-video-grid.audio-mode .call-tile{aspect-ratio:auto;padding:18px 8px;flex-direction:column;gap:8px;background:#1f2430}
.call-tile .avatar-lg{width:56px;height:56px;font-size:20px}
.call-tile-name{
  position:absolute;left:6px;bottom:6px;background:rgba(0,0,0,.55);color:#fff;
  font-size:11.5px;font-weight:600;padding:3px 7px;border-radius:6px;
}
.call-video-grid.audio-mode .call-tile-name{position:static;background:none;color:var(--text);padding:0}

#call-local-video{
  width:110px;height:82px;border-radius:8px;border:2px solid #fff;object-fit:cover;
  margin:10px auto 0;display:block;background:#111;
}

.call-ongoing-banner{
  display:flex;align-items:center;justify-content:space-between;gap:10px;
  background:#eef2ff;color:var(--brand-dark);padding:8px 16px;font-size:13px;font-weight:600;
  border-bottom:1px solid var(--border);
}

.conv-call-badge{
  display:inline-flex;align-items:center;gap:3px;font-size:11px;color:var(--brand);font-weight:700;
}

/* ---------- Toasts ---------- */
.toast-container{position:fixed;top:16px;right:16px;z-index:60;display:flex;flex-direction:column;gap:8px}
.toast{
  background:#1f2430;color:#fff;padding:12px 16px;border-radius:10px;font-size:13px;box-shadow:0 8px 24px rgba(0,0,0,.25);
  display:flex;align-items:center;gap:10px;min-width:220px;animation:toast-in .2s ease;cursor:pointer;
}
@keyframes toast-in{from{transform:translateX(20px);opacity:0}to{transform:translateX(0);opacity:1}}
.toast .t-avatar{width:28px;height:28px;border-radius:50%;background:var(--brand);display:flex;align-items:center;justify-content:center;font-size:12px;font-weight:700;flex-shrink:0}

@media (max-width:760px){
  .sidebar{position:absolute;inset:0;z-index:5;width:100%}
  .chat-main{width:100%}
  .app-shell{position:relative}
}
