/* K-Chat — Popup flutuante */
.chat-popup{position:fixed;bottom:16px;right:16px;width:380px;height:520px;max-height:80vh;background:#fff;border-radius:14px;box-shadow:0 8px 40px rgba(0,0,0,.18);z-index:900;display:flex;flex-direction:column;overflow:hidden;transition:all .2s ease;font-family:system-ui,-apple-system,sans-serif;}
.chat-popup.minimized{max-height:52px;width:320px;cursor:pointer;}
.chat-popup.expanded{width:480px;max-height:70vh;}

/* Header */
.chat-header{background:#0f1f3d;color:#fff;padding:12px 16px;display:flex;align-items:center;justify-content:space-between;cursor:pointer;flex-shrink:0;user-select:none;}
.chat-header-left{display:flex;align-items:center;gap:8px;}
.chat-header-title{font-size:15px;font-weight:700;letter-spacing:-.3px;}
.chat-header-badge{background:#ef4444;color:#fff;font-size:10px;font-weight:700;min-width:18px;height:18px;border-radius:9px;display:flex;align-items:center;justify-content:center;padding:0 5px;}
.chat-header-actions{display:flex;gap:4px;}
.chat-header-actions button{background:none;border:none;color:#94a3b8;font-size:14px;cursor:pointer;padding:4px 6px;border-radius:4px;line-height:1;}
.chat-header-actions button:hover{color:#fff;background:rgba(255,255,255,.1);}

/* Search */
.chat-search{padding:8px 12px;border-bottom:1px solid #f1f5f9;flex-shrink:0;}
.chat-search input{width:100%;padding:7px 12px;border:1px solid #e2e8f0;border-radius:8px;font-size:13px;outline:none;background:#f8fafc;}
.chat-search input:focus{border-color:#3b82f6;background:#fff;}

/* Room list */
.chat-rooms{flex:1;overflow-y:auto;min-height:0;}
.chat-room-item{display:flex;align-items:center;gap:10px;padding:10px 14px;cursor:pointer;border-bottom:1px solid #f8fafc;transition:background .1s;}
.chat-room-item:hover{background:#f1f5f9;}
.chat-room-item.active{background:#eff6ff;}
.chat-room-avatar{width:40px;height:40px;border-radius:50%;background:#e2e8f0;display:flex;align-items:center;justify-content:center;font-size:14px;font-weight:700;color:#475569;flex-shrink:0;position:relative;}
.chat-room-avatar.online::after{content:"";position:absolute;bottom:1px;right:1px;width:10px;height:10px;background:#22c55e;border-radius:50%;border:2px solid #fff;}
.chat-room-info{flex:1;min-width:0;}
.chat-room-name{font-size:13px;font-weight:600;color:#0f172a;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}
.chat-room-preview{font-size:12px;color:#64748b;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;margin-top:1px;}
.chat-room-preview .typing{color:#3b82f6;font-style:italic;}
.chat-room-meta{display:flex;flex-direction:column;align-items:flex-end;gap:2px;flex-shrink:0;}
.chat-room-time{font-size:10px;color:#94a3b8;}
.chat-room-unread{background:#3b82f6;color:#fff;font-size:10px;font-weight:700;min-width:18px;height:18px;border-radius:9px;display:flex;align-items:center;justify-content:center;padding:0 5px;}

/* New chat button */
.chat-new-btn{padding:10px 14px;border-top:1px solid #f1f5f9;flex-shrink:0;}
.chat-new-btn button{width:100%;padding:8px;background:#3b82f6;color:#fff;border:none;border-radius:8px;font-size:13px;font-weight:600;cursor:pointer;}
.chat-new-btn button:hover{background:#2563eb;}

/* Chat view (conversation) */
.chat-view{display:flex;flex-direction:column;flex:1;min-height:0;overflow:hidden;}
.chat-conv-header{padding:10px 14px;border-bottom:1px solid #f1f5f9;display:flex;align-items:center;gap:10px;flex-shrink:0;}
.chat-conv-back{background:none;border:none;font-size:16px;cursor:pointer;padding:2px 6px;color:#64748b;}
.chat-conv-back:hover{color:#0f172a;}
.chat-conv-name{font-size:14px;font-weight:600;color:#0f172a;}
.chat-conv-status{font-size:11px;color:#22c55e;}
.chat-conv-status.offline{color:#94a3b8;}
.chat-conv-menu{background:none;border:none;color:#64748b;font-size:20px;line-height:1;cursor:pointer;padding:4px 6px;border-radius:8px;}
.chat-conv-menu:hover{background:#f1f5f9;color:#0f172a;}

/* Messages */
.chat-messages{flex:1;overflow-y:auto;padding:12px 14px;display:flex;flex-direction:column;gap:4px;min-height:0;background:#f8fafc;}
.chat-msg{max-width:80%;padding:8px 12px;border-radius:12px;font-size:13px;line-height:1.4;word-wrap:break-word;position:relative;}
.chat-msg.mine{align-self:flex-end;background:#3b82f6;color:#fff;border-bottom-right-radius:4px;}
.chat-msg.other{align-self:flex-start;background:#fff;color:#0f172a;border-bottom-left-radius:4px;box-shadow:0 1px 2px rgba(0,0,0,.06);}
.chat-msg-sender{font-size:11px;font-weight:600;color:#7c3aed;margin-bottom:2px;}
.chat-msg-text{white-space:pre-wrap;}
.chat-msg-meta{display:flex;align-items:center;justify-content:flex-end;gap:4px;margin-top:3px;}
.chat-msg-time{font-size:10px;opacity:.7;}
.chat-msg-ticks{font-size:10px;}
.chat-msg.mine .chat-msg-ticks{color:rgba(255,255,255,.8);}
.chat-msg-ticks.read{color:#60d8ff;}
.chat-msg-reply{font-size:11px;padding:4px 8px;background:rgba(0,0,0,.06);border-radius:6px;border-left:3px solid #3b82f6;margin-bottom:4px;color:#64748b;}
.chat-msg.mine .chat-msg-reply{background:rgba(255,255,255,.15);color:rgba(255,255,255,.8);}
.chat-msg-forwarded{font-size:10px;color:#94a3b8;margin-bottom:2px;font-style:italic;}
.chat-msg.mine .chat-msg-forwarded{color:rgba(255,255,255,.6);}
.chat-msg-edited{font-size:10px;font-style:italic;opacity:.6;}
.chat-msg-reactions{display:flex;gap:4px;margin-top:4px;flex-wrap:wrap;}
.chat-msg-reaction{font-size:11px;background:#f1f5f9;border-radius:10px;padding:1px 6px;cursor:pointer;border:1px solid #e2e8f0;}
.chat-msg-reaction:hover{background:#e2e8f0;}
.chat-msg-reaction.mine{border-color:#3b82f6;background:#eff6ff;}
.chat-msg-file{display:flex;align-items:center;gap:8px;padding:6px 10px;background:rgba(0,0,0,.05);border-radius:8px;margin-top:4px;cursor:pointer;text-decoration:none;color:inherit;}
.chat-msg.mine .chat-msg-file{background:rgba(255,255,255,.15);}
.chat-msg-file-icon{font-size:18px;}
.chat-msg-file-info{font-size:11px;line-height:1.3;}
.chat-msg-img{max-width:220px;max-height:200px;border-radius:8px;cursor:pointer;margin-top:4px;}
.chat-msg-media{display:flex;flex-direction:column;gap:6px;margin-top:4px;text-decoration:none;color:inherit;}
.chat-msg-media-caption{font-size:11px;opacity:.85;}

/* Date separator */
.chat-date-sep{text-align:center;font-size:11px;color:#94a3b8;padding:8px 0;position:relative;}
.chat-date-sep span{background:#f8fafc;padding:0 10px;position:relative;z-index:1;}

/* Typing */
.chat-typing{font-size:11px;color:#3b82f6;padding:4px 14px;font-style:italic;min-height:20px;flex-shrink:0;}

/* Composer */
.chat-composer{padding:8px 12px;border-top:1px solid #f1f5f9;display:flex;align-items:flex-end;gap:8px;flex-shrink:0;background:#fff;}
.chat-composer-input{flex:1;max-height:100px;min-height:18px;padding:8px 12px;border:1px solid #e2e8f0;border-radius:20px;font-size:13px;resize:none;outline:none;line-height:1.4;font-family:inherit;overflow-y:auto;}
.chat-composer-input:focus{border-color:#3b82f6;}
.chat-composer-btn{background:none;border:none;font-size:18px;cursor:pointer;padding:4px;color:#94a3b8;flex-shrink:0;}
.chat-composer-btn:hover{color:#3b82f6;}
.chat-composer-send{background:#3b82f6;color:#fff;border:none;width:34px;height:34px;border-radius:50%;cursor:pointer;display:flex;align-items:center;justify-content:center;font-size:16px;flex-shrink:0;}
.chat-composer-send:hover{background:#2563eb;}

/* Reply preview in composer */
.chat-reply-preview{padding:6px 12px;background:#eff6ff;border-left:3px solid #3b82f6;margin:0 12px 0;border-radius:0 6px 6px 0;font-size:12px;color:#64748b;display:flex;align-items:center;justify-content:space-between;}
.chat-reply-close{background:none;border:none;font-size:14px;cursor:pointer;color:#94a3b8;padding:0 4px;}

/* New chat modal */
.chat-modal-overlay{position:fixed;inset:0;background:rgba(0,0,0,.3);z-index:950;display:flex;align-items:center;justify-content:center;}
.chat-modal{background:#fff;border-radius:12px;width:340px;max-height:420px;display:flex;flex-direction:column;box-shadow:0 8px 30px rgba(0,0,0,.15);}
.chat-modal-header{padding:14px 16px;font-size:14px;font-weight:700;border-bottom:1px solid #f1f5f9;display:flex;align-items:center;justify-content:space-between;}
.chat-modal-header button{background:none;border:none;font-size:16px;cursor:pointer;color:#64748b;}
.chat-modal-search{padding:8px 12px;}
.chat-modal-search input{width:100%;padding:7px 12px;border:1px solid #e2e8f0;border-radius:8px;font-size:13px;outline:none;}
.chat-modal-list{flex:1;overflow-y:auto;padding:4px 0;}
.chat-modal-user{display:flex;align-items:center;gap:10px;padding:8px 14px;cursor:pointer;}
.chat-modal-user:hover{background:#f1f5f9;}
.chat-modal-user-avatar{width:34px;height:34px;border-radius:50%;background:#e2e8f0;display:flex;align-items:center;justify-content:center;font-size:12px;font-weight:700;color:#475569;}
.chat-modal-user-name{font-size:13px;font-weight:500;}
.chat-modal-user-email{font-size:11px;color:#94a3b8;}
.chat-floating-menu{position:fixed;min-width:180px;background:#fff;border:1px solid #e2e8f0;border-radius:10px;box-shadow:0 10px 30px rgba(15,23,42,.15);padding:6px;z-index:999;}
.chat-floating-item{display:block;width:100%;text-align:left;background:none;border:none;border-radius:8px;padding:8px 10px;font-size:13px;color:#0f172a;cursor:pointer;}
.chat-floating-item:hover{background:#f8fafc;}

/* Topbar chat icon */
.topbar-chat-btn{position:relative;background:none;border:none;font-size:18px;cursor:pointer;padding:6px 8px;color:#64748b;border-radius:6px;}
.topbar-chat-btn:hover{background:#f1f5f9;color:#0f172a;}
.topbar-chat-badge{position:absolute;top:2px;right:2px;background:#ef4444;color:#fff;font-size:9px;font-weight:700;min-width:16px;height:16px;border-radius:8px;display:flex;align-items:center;justify-content:center;padding:0 4px;}

/* Empty state */
.chat-empty{display:flex;flex-direction:column;align-items:center;justify-content:center;flex:1;color:#94a3b8;gap:8px;padding:40px 20px;text-align:center;}
.chat-empty-icon{font-size:40px;}
.chat-empty-text{font-size:13px;}

/* ═══════════════════════════════════════ */
/* CAMADA 2 — Interface completa na #main */
/* ═══════════════════════════════════════ */
.comm-main-active{overflow:hidden !important;padding:0 !important;}
@keyframes chatToastIn{from{transform:translateY(20px);opacity:0;}to{transform:translateY(0);opacity:1;}}
.kchat-area{display:flex;flex-direction:column;height:100%;min-height:0;min-width:0;overflow:hidden;background:#f8fafc;}
.kchat-conv-header{padding:12px 16px;background:#fff;border-bottom:1px solid #e2e8f0;display:flex;align-items:center;gap:12px;flex-shrink:0;}
/* Sidebar injection */
.kchat-sb-header{padding:10px 12px;display:flex;align-items:center;justify-content:space-between;border-bottom:1px solid var(--border);}
.kchat-sb-header span{font-size:13px;font-weight:700;color:var(--text);}
.kchat-newgrp-btn{width:28px;height:28px;border-radius:50%;background:#3b82f6;color:#fff;border:none;font-size:16px;cursor:pointer;display:flex;align-items:center;justify-content:center;line-height:1;}
.kchat-newgrp-btn:hover{background:#2563eb;}
.kchat-sb-search{padding:8px 10px;}
.kchat-sb-search input{width:100%;padding:6px 10px;border:1px solid var(--border);border-radius:8px;font-size:12px;outline:none;background:#f8fafc;}
.kchat-sb-search input:focus{border-color:#3b82f6;background:#fff;}
.kchat-sb-rooms{flex:1;overflow-y:auto;}

/* Mobile */
@media(max-width:768px){
  .kchat-sidebar{width:100%;}
  .kchat-main{display:none;}
  .kchat-layout.chat-open .kchat-sidebar{display:none;}
  .kchat-layout.chat-open .kchat-main{display:flex;width:100%;}
}
@media(max-width:480px){
  .chat-popup{bottom:0;right:0;left:0;width:100%;max-height:100vh;border-radius:14px 14px 0 0;}
  .chat-popup.expanded{width:100%;max-height:100vh;}
}
