:root{font-family:Inter,Arial,sans-serif;color:#172033;background:#eef2f7}
*{box-sizing:border-box}
body{margin:0}
button,input,select{font:inherit}
button{cursor:pointer}
.login-screen{position:fixed;inset:0;z-index:20;display:flex;align-items:center;justify-content:center;background:#eef2f7;padding:18px}
.login-screen.hidden{display:none}
.login-box{width:min(360px,100%);background:#fff;border:1px solid #d8e0eb;border-radius:8px;padding:22px;display:grid;gap:12px;box-shadow:0 16px 40px rgba(15,23,42,.12)}
.login-box h1{margin:0 0 4px;font-size:24px}
.login-box input{height:42px;border:1px solid #cbd5e1;border-radius:4px;padding:0 10px}
.login-box button{height:40px;border:0;border-radius:4px;background:#2563eb;color:#fff}
.login-error{min-height:18px;color:#b91c1c;font-size:13px}
.logged-out .app{filter:blur(2px);pointer-events:none}
.app{height:100vh;max-height:100vh;display:grid;grid-template-columns:340px minmax(420px,1fr);background:#f8fafc;overflow:hidden}
.sidebar,.profile{min-height:0;background:#fff}
.sidebar{height:100vh;min-height:0;border-right:1px solid #d8e0eb;display:grid;grid-template-rows:auto auto auto minmax(0,1fr);overflow:hidden}
.profile{display:none}
.brand{min-height:64px;background:#111827;color:#fff;display:grid;grid-template-columns:36px minmax(0,1fr);align-items:center;gap:8px;padding:10px 12px;position:relative}
.brand button,.account-create button,.composer button{border:0;background:#2563eb;color:#fff;border-radius:4px;height:36px;padding:0 12px}
.icon-btn{width:36px;padding:0!important;background:#1f2937!important;border:1px solid #374151!important}
.settings-wrap{position:relative}
.settings-menu{position:absolute;z-index:10;background:#fff;color:#172033;border:1px solid #d8e0eb;border-radius:6px;box-shadow:0 12px 30px rgba(15,23,42,.18);overflow:hidden}
.settings-menu.hidden{display:none}
.settings-menu{left:0;top:42px;width:220px}
.settings-menu button{width:100%;height:38px;border:0;background:#fff;color:#172033;text-align:left;border-radius:0}
.settings-menu button:hover{background:#eef6ff}
.brand-title{min-width:0;font-weight:800;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.account-list{border-bottom:1px solid #edf1f6;background:#fff;max-height:190px;overflow:auto;padding:8px;display:grid;gap:6px}
.account-list-item{width:100%;min-height:48px;display:grid;grid-template-columns:28px minmax(0,1fr) auto;align-items:center;gap:8px;border:1px solid #e2e8f0;background:#fff;color:#172033;text-align:left;border-radius:6px;padding:7px 8px}
.account-list-item:hover,.account-list-item.active{background:#eef6ff;border-color:#bfdbfe}
.account-list-item.unread{background:#fff7f7;border-color:#fecaca;border-left:4px solid #dc2626}
.account-list-item.unread strong{color:#991b1b}
.account-list-item strong,.account-list-item small{display:block;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.account-list-item small{color:#64748b;margin-top:2px;font-size:12px}
.account-list-item i{min-width:20px;height:20px;border-radius:999px;background:#dc2626;color:#fff;font-style:normal;font-size:12px;display:flex;align-items:center;justify-content:center;padding:0 6px}
.empty-switch{padding:12px;color:#64748b;font-size:13px;background:#fff}
.small-avatar{width:28px;height:28px;font-size:10px}
.chat-search{padding:10px 12px;border-bottom:1px solid #edf1f6;background:#fff;display:grid;grid-template-columns:1fr 54px;gap:8px}
.chat-search input{width:100%;height:36px;border:1px solid #cbd5e1;border-radius:4px;padding:0 10px}
.chat-search button{height:36px;border:0;background:#2563eb;color:#fff;border-radius:4px}
.conversation-list{min-height:0;overflow-y:auto;overflow-x:hidden}
.search-section-title{font-size:12px;color:#64748b;background:#f8fafc;border-bottom:1px solid #edf1f6;padding:8px 12px;text-transform:uppercase}
.stranger-result{background:#fff7ed}
.stranger-result:hover{background:#ffedd5}
.conversation{width:100%;border:0;background:#fff;display:grid;grid-template-columns:42px 1fr auto;gap:10px;padding:12px;border-bottom:1px solid #edf1f6;border-left:4px solid transparent;text-align:left;align-items:center}
.conversation:hover,.conversation.active{background:#eef6ff}
.conversation.unread{background:#fff7f7;border-left-color:#dc2626}
.conversation.unread:hover,.conversation.unread.active{background:#fee2e2}
.conversation.unread strong{color:#991b1b;font-weight:800}
.conversation strong{display:block;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.conversation small{display:block;color:#64748b;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;margin-top:4px}
.avatar{width:42px;height:42px;border-radius:50%;background:#dbeafe;color:#1d4ed8;display:flex;align-items:center;justify-content:center;font-weight:700;overflow:hidden;flex:0 0 auto}
.avatar img{width:100%;height:100%;object-fit:cover}
.group-avatar{position:relative;display:grid;grid-template-columns:1fr 1fr;grid-template-rows:1fr 1fr;gap:1px;background:#cbd5e1;padding:2px;color:#fff;box-shadow:0 0 0 2px #dbeafe}
.group-avatar i{display:flex;align-items:center;justify-content:center;font-style:normal;font-size:10px;line-height:1}
.group-avatar i:nth-child(1){background:#2563eb}
.group-avatar i:nth-child(2){background:#16a34a}
.group-avatar i:nth-child(3){background:#f59e0b}
.group-avatar i:nth-child(4){background:#9333ea}
.group-avatar b{position:absolute;right:-3px;bottom:-3px;width:18px;height:18px;border:2px solid #fff;border-radius:50%;background:#0f172a}
.group-avatar b em{position:absolute;border-radius:50%;background:#fff;font-style:normal}
.group-avatar b em:nth-child(1){width:5px;height:5px;left:6px;top:3px}
.group-avatar b em:nth-child(2){width:4px;height:4px;left:3px;top:6px;opacity:.85}
.group-avatar b em:nth-child(3){width:4px;height:4px;right:3px;top:6px;opacity:.85}
.group-avatar b:after{content:"";position:absolute;left:4px;right:4px;bottom:4px;height:5px;border-radius:999px 999px 2px 2px;background:#fff}
.group-label{color:#2563eb;font-weight:700}
.badge{background:#dc2626;color:#fff;border-radius:999px;min-width:20px;height:20px;display:flex;align-items:center;justify-content:center;font-size:12px;padding:0 6px}
.chat{height:100vh;min-height:0;display:grid;grid-template-rows:64px minmax(0,1fr) 66px;min-width:0;overflow:hidden}
.chat-header{background:#fff;border-bottom:1px solid #d8e0eb;display:flex;align-items:center;gap:12px;padding:0 18px;position:relative}
.chat-header-main{min-width:0;flex:1}
.friend-action{height:32px;border:0;background:#2563eb;color:#fff;border-radius:4px;padding:0 12px;flex:0 0 auto}
.friend-state{font-size:13px;color:#64748b;flex:0 0 auto}
.back-btn{display:none;border:1px solid #cbd5e1;background:#fff;border-radius:4px;width:36px;height:36px;font-size:26px;line-height:1}
.chat-title{font-weight:700}.chat-subtitle{color:#64748b;font-size:13px;margin-top:3px;display:flex;align-items:center;gap:6px}.empty-title,.empty-chat,.empty-block{color:#64748b}
.note-icon-btn{width:18px;height:18px;border:0;border-radius:50%;background:#dc2626;color:#fff;font-size:12px;font-weight:800;line-height:1;padding:0}
.chat-note-popover{position:absolute;left:0;top:44px;z-index:11;max-width:min(420px,70vw);background:#fff7f7;border:1px solid #fecaca;color:#991b1b;border-radius:6px;box-shadow:0 12px 30px rgba(15,23,42,.14);padding:10px 12px;white-space:pre-wrap;font-size:13px;line-height:1.45}
.empty-chat{margin:auto}.empty-block{padding:14px}
.mode-warning{margin:14px;padding:10px 12px;border:1px solid #f59e0b;background:#fffbeb;color:#92400e;border-radius:6px}
.messages{min-height:0;overflow-y:auto;overflow-x:hidden;padding:18px;display:flex;flex-direction:column;gap:10px}
.message{max-width:72%;display:flex;gap:8px;align-items:flex-end}
.message.agent{align-self:flex-end;flex-direction:row-reverse}
.bubble{background:#fff;border:1px solid #d8e0eb;border-radius:8px;padding:9px 11px;white-space:pre-wrap;line-height:1.4}
.message.agent .bubble{background:#2563eb;border-color:#2563eb;color:#fff}
.message-sender{font-size:12px;color:#64748b;margin:0 0 4px 2px}
.message-time{font-size:12px;color:#94a3b8;margin-top:5px}
.message-image,.message-video{max-width:280px;max-height:300px;border-radius:6px;display:block}
.image-preview{border:0;background:transparent;padding:0;display:block;cursor:zoom-in}
.media-caption{margin-bottom:6px}
.file-link{display:inline-flex;align-items:center;gap:6px;color:inherit;text-decoration:none;font-weight:600}
.message-actions{display:flex;align-items:center;justify-content:flex-end;gap:6px;margin-top:4px;position:relative;min-height:30px}
.selected-reactions{display:flex;gap:3px;align-items:center}
.selected-reactions span{width:24px;height:24px;display:flex;align-items:center;justify-content:center;background:#fff;border:1px solid #d8e0eb;border-radius:50%;font-size:15px}
.like-btn{width:28px;height:28px;border:1px solid #cbd5e1;background:#fff;border-radius:50%;padding:0;display:flex;align-items:center;justify-content:center}
.like-btn:before{content:"👍";font-size:15px;line-height:1;filter:grayscale(1) brightness(0) invert(1) drop-shadow(0 0 1px #334155) drop-shadow(0 0 1px #334155)}
.like-btn.liked{background:#fffbeb;border-color:#eab308}
.like-btn.liked:before{filter:sepia(1) saturate(8) hue-rotate(350deg) brightness(1.05)}
.reaction-menu{display:none;gap:4px;background:#fff;border:1px solid #d8e0eb;border-radius:999px;padding:4px;box-shadow:0 8px 22px rgba(15,23,42,.12);position:absolute;right:0;bottom:30px;z-index:4}
.reaction-menu.open{display:flex}
.reaction-menu button{width:28px;height:28px;border:0;background:#fff;border-radius:50%;font-size:17px;padding:0}
.reaction-menu button:hover{background:#eef6ff}
.composer{display:grid;grid-template-columns:48px 48px 1fr 74px;gap:8px;align-items:center;padding:12px;background:#fff;border-top:1px solid #d8e0eb}
.reply-preview{grid-column:1/-1;display:grid;grid-template-columns:minmax(0,1fr) 28px;gap:8px;align-items:center;border-left:3px solid #2563eb;background:#eef6ff;border-radius:4px;padding:8px 10px}
.reply-preview strong,.reply-preview small{display:block;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.reply-preview strong{font-size:12px;color:#1d4ed8}.reply-preview small{color:#334155;margin-top:3px}
.reply-preview button{width:28px!important;height:28px!important;border:1px solid #cbd5e1!important;background:#fff!important;color:#334155!important;border-radius:4px!important;padding:0!important}
.message-context-menu{position:fixed;z-index:50;min-width:190px;background:#fff;border:1px solid #d8e0eb;border-radius:6px;box-shadow:0 14px 36px rgba(15,23,42,.18);overflow:hidden}
.message-context-menu button{width:100%;height:38px;border:0;background:#fff;color:#172033;text-align:left;padding:0 12px}
.message-context-menu button:hover{background:#eef6ff}
.composer input,.account-create input,.account-create select{height:40px;border:1px solid #cbd5e1;border-radius:4px;padding:0 10px;min-width:0;width:100%}
.composer #imageBtn,.composer #fileBtn{height:36px;border:1px solid #cbd5e1;background:#fff;color:#334155;border-radius:4px;font-size:13px;line-height:1;padding:0}
.image-viewer{position:fixed;inset:0;z-index:30;background:rgba(15,23,42,.86);display:flex;align-items:center;justify-content:center;padding:24px}
.image-viewer.hidden{display:none}
.image-viewer img{max-width:96vw;max-height:92vh;border-radius:8px;box-shadow:0 18px 60px rgba(0,0,0,.35)}
.image-viewer button{position:absolute;top:14px;right:18px;width:40px;height:40px;border:0;border-radius:50%;background:#fff;color:#111827;font-size:28px;line-height:1}
.label{font-size:12px;color:#64748b;margin-bottom:4px}
.assign-option{display:flex;align-items:center;gap:8px;margin:8px 0;color:#334155}
.assignment-box button{height:32px;border:1px solid #cbd5e1;background:#fff;border-radius:4px;color:#334155;padding:0 10px}
.qr{width:180px;max-width:100%;border:1px solid #d8e0eb}
.account-manager,.user-manager{display:none;min-width:0;min-height:0;overflow:auto;background:#fff;border-right:1px solid #d8e0eb}
.account-mode .chat,.account-mode .profile,.user-mode .chat,.user-mode .profile{display:none}
.account-mode .account-manager{display:block;grid-column:2}
.user-mode .user-manager{display:block;grid-column:2}
.account-manager-head{padding:18px;border-bottom:1px solid #d8e0eb;background:#f8fafc;display:flex;align-items:center;justify-content:space-between;gap:12px}
.account-manager-head h2{font-size:20px;margin:0 0 6px}
.account-manager-head p{margin:0;color:#64748b}
.account-manager-head button{height:36px;border:0;background:#2563eb;color:#fff;border-radius:4px;padding:0 12px;flex:0 0 auto}
.account-create{display:grid;grid-template-columns:150px repeat(2,minmax(180px,1fr)) 140px;gap:10px 12px;padding:12px;border-bottom:1px solid #d8e0eb;align-items:end}
.account-create label{display:grid;gap:5px;min-width:0}
.account-create label span{font-size:12px;color:#64748b;font-weight:700}
.account-create .oa-field{grid-column:auto}
.account-create .wide-field{grid-column:span 2}
.account-create button{align-self:end}
.user-create{display:grid;grid-template-columns:minmax(120px,1fr) minmax(160px,1fr) minmax(120px,1fr) 100px 120px;gap:8px;padding:12px;border-bottom:1px solid #d8e0eb}
.user-create input,.user-create select{height:40px;border:1px solid #cbd5e1;border-radius:4px;padding:0 10px;min-width:0}
.user-create button,.chat-setting-btn,.assignment-box button{height:36px;border:0;background:#2563eb;color:#fff;border-radius:4px;padding:0 12px}
.chat-setting-btn{min-width:92px;font-weight:700;white-space:nowrap}
.user-layout{display:grid;grid-template-columns:minmax(280px,360px) minmax(0,1fr);min-height:0}
.users{border-right:1px solid #d8e0eb;min-height:0;overflow:auto;padding:12px;display:grid;gap:10px;align-content:start}
.user-card{border:1px solid #d8e0eb;border-radius:6px;background:#fff;overflow:hidden}
.user-card.active{border-color:#2563eb;box-shadow:0 0 0 1px #2563eb}
.user-select{width:100%;border:0;background:#fff;text-align:left;padding:12px;color:#172033}
.user-select strong{display:block}.user-select small{display:block;color:#64748b;margin-top:4px}
.user-actions{display:grid;grid-template-columns:1fr 1fr;gap:6px;padding:0 10px 10px}
.user-actions button{height:30px;border:1px solid #cbd5e1;background:#fff;color:#334155;border-radius:4px}
.user-actions .danger{color:#b91c1c;border-color:#fecaca}.user-actions button:disabled{opacity:.45;cursor:not-allowed}
.user-assigned{padding:14px;min-width:0;overflow:auto}
.user-assigned h3{font-size:18px;margin:0 0 12px}
.selected-user-editor,.managed-permission-editor{border:1px solid #d8e0eb;border-radius:6px;padding:12px;margin-bottom:14px;background:#f8fafc}
.selected-user-editor h3,.managed-permission-editor h3{font-size:16px;margin:0 0 10px}
.selected-user-form{display:grid;grid-template-columns:repeat(2,minmax(160px,1fr));gap:10px;align-items:end}
.selected-user-form label,.permission-note{display:grid;gap:5px;min-width:0}
.selected-user-form label span,.permission-note span{font-size:12px;color:#64748b;font-weight:700}
.selected-user-form input,.selected-user-form select{height:38px;border:1px solid #cbd5e1;border-radius:4px;padding:0 10px;min-width:0}
.selected-user-form .inline-check{display:flex;align-items:center;gap:8px;height:38px}
.selected-user-form .inline-check input{width:auto;height:auto}
.selected-user-form button,.permission-actions button{height:38px;border:0;background:#2563eb;color:#fff;border-radius:4px;padding:0 12px}
.selected-user-form button.secondary{background:#fff;color:#334155;border:1px solid #cbd5e1}
.managed-chat-search{width:100%;height:38px;border:1px solid #cbd5e1;border-radius:4px;padding:0 10px;margin:0 0 12px}
.assigned-conversation-list{display:grid;gap:8px}
.assigned-conversation{width:100%;border:1px solid #d8e0eb;border-radius:6px;background:#fff;display:grid;grid-template-columns:28px minmax(0,1fr) auto;gap:10px;align-items:center;text-align:left;padding:10px}
.assigned-conversation.active{border-color:#2563eb;background:#eef6ff}
.assigned-conversation strong,.assigned-conversation small{display:block;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.assigned-conversation small{color:#64748b;margin-top:3px}
.permission-target{display:grid;gap:3px;margin-bottom:10px}
.permission-target small{color:#64748b;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.permission-users{display:grid;grid-template-columns:repeat(auto-fill,minmax(150px,1fr));gap:4px 10px;margin-bottom:10px}
.permission-actions{display:flex;gap:8px;margin-top:10px}
.accounts{display:grid;grid-template-columns:repeat(auto-fill,minmax(280px,1fr));gap:12px;padding:14px;overflow:auto}
.account-card{border:1px solid #d8e0eb;border-radius:6px;background:#fff}
.account-main{display:grid;grid-template-columns:42px 1fr 12px;gap:10px;text-align:left;align-items:center;padding:12px}
.account-main strong{display:block;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.account-main small{display:block;color:#64748b;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;margin-top:4px}
.status-dot{width:10px;height:10px;border-radius:50%;background:#94a3b8}
.status-dot.online{background:#16a34a}
.status-dot.waiting{background:#f59e0b}
.account-qr{display:flex;align-items:center;gap:10px;padding:0 12px 12px;color:#64748b;font-size:13px}
.account-qr .qr{width:88px}
.account-note{padding:0 12px 12px;color:#92400e;font-size:13px}
.account-actions{display:grid;grid-template-columns:repeat(4,1fr);gap:6px;padding:0 10px 10px}
.account-actions.oa-actions{grid-template-columns:1fr 1fr}
.account-actions button{border:1px solid #cbd5e1;background:#fff;border-radius:4px;height:28px;padding:0 8px;color:#334155}
.account-actions .danger{color:#b91c1c;border-color:#fecaca}
.hidden{display:none!important}
.admin-note,.note-label{color:#b91c1c;font-weight:700}
.assignment-note{width:100%;min-height:84px;border:1px solid #fecaca;background:#fff7f7;color:#991b1b;border-radius:4px;padding:8px;resize:vertical}
.empty-assignment{font-size:13px;color:#64748b;background:#f8fafc;border:1px dashed #cbd5e1;border-radius:4px;padding:8px;margin:6px 0 10px}
.chat-setting-wrap{position:relative;flex:0 0 auto}
.chat-assignment-panel{position:absolute;right:0;top:44px;z-index:12;width:280px;background:#fff;border:1px solid #d8e0eb;border-radius:6px;box-shadow:0 14px 36px rgba(15,23,42,.18);padding:12px}
@media(max-width:1100px){.app{grid-template-columns:340px 1fr}.profile{display:none}.account-mode .account-manager,.user-mode .user-manager{grid-column:2}}
@media(max-width:720px){.app{grid-template-columns:1fr}.chat,.account-manager,.user-manager{display:none}.chat-open .sidebar,.account-mode .sidebar,.user-mode .sidebar{display:none}.chat-open .chat{display:grid}.account-mode .account-manager,.user-mode .user-manager{display:block;grid-column:1}.account-create,.user-create,.user-layout{grid-template-columns:1fr}.account-create .wide-field{grid-column:auto}.accounts{grid-template-columns:1fr}.back-btn{display:inline-block}.message{max-width:88%}}
