/* ChatAI Node Client – giao diện đăng nhập và chat */
:root {
	--chat-bg: #0f0f12;
	--chat-surface: #18181c;
	--chat-header-bg: #1a1a20;
	--chat-send-bg: #1e1e24;
	--chat-msg-bg: #222228;
	--chat-msg-me-bg: #2a2a32;
	--chat-border: #2e2e36;
	--chat-primary: #6366f1;
	--chat-primary-hover: #4f46e5;
	--chat-text: #e4e4e7;
	--chat-muted: #71717a;
}

* { box-sizing: border-box; }
body { margin: 0; font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; font-size: 15px; line-height: 1.5; color: var(--chat-text); background: var(--chat-bg); height: 100vh; display: flex; flex-direction: column; }

/* Ẩn hẳn màn login khi đăng nhập thành công; màn chat chiếm toàn màn hình, căn giữa */
.hidden { display: none !important; }
.chat-login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.chat-login-box { background: var(--chat-surface); padding: 2rem; border-radius: 12px; border: 1px solid var(--chat-border); width: 100%; max-width: 400px; }
.chat-login-box h1 { margin: 0 0 0.5rem 0; font-size: 1.5rem; color: var(--chat-text); }
.chat-tagline { color: var(--chat-muted); margin-bottom: 0.5rem; font-size: 0.9rem; }
.chat-login-hint { font-size: 0.8rem; color: var(--chat-muted); margin-bottom: 1rem; padding: 0.5rem; background: rgba(0,0,0,0.2); border-radius: 6px; }
.chat-login-hint code { font-size: 0.85em; }
.chat-login-box label { display: block; margin-bottom: 0.75rem; font-size: 0.9rem; color: var(--chat-muted); }
.chat-login-box input { width: 100%; padding: 0.65rem 0.8rem; margin-top: 0.25rem; box-sizing: border-box; border: 1px solid var(--chat-border); border-radius: 8px; font-size: 1rem; background: var(--chat-bg); color: var(--chat-text); }
.chat-login-box input:focus { outline: none; border-color: var(--chat-primary); }
.chat-login-actions { margin-top: 1.25rem; }
.chat-login-box button { width: 100%; padding: 0.75rem; background: var(--chat-primary); color: #fff; border: none; border-radius: 8px; cursor: pointer; font-size: 1rem; font-weight: 600; }
.chat-login-box button:hover { background: var(--chat-primary-hover); }
.chat-error { color: #f87171; font-size: 0.9rem; margin-top: 0.5rem; }
.chat-error.hidden { display: none; }

.chat-app { display: flex; flex-direction: row; height: 100vh; max-width: 1000px; margin: 0 auto; width: 100%; background: var(--chat-surface); box-shadow: 0 0 0 1px var(--chat-border); }
.chat-main { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.chat-sidebar { width: 240px; min-width: 240px; background: var(--chat-header-bg); border-right: 1px solid var(--chat-border); display: flex; flex-direction: column; }
.chat-sidebar-tabs { display: flex; align-items: center; border-bottom: 1px solid var(--chat-border); }
.chat-sidebar-tabs .chat-tab { flex: 1; padding: 0.6rem 0.4rem; font-size: 0.85rem; border: none; background: transparent; color: var(--chat-muted); cursor: pointer; }
.chat-sidebar-tabs .chat-tab.active { background: var(--chat-surface); color: var(--chat-text); font-weight: 600; }
.chat-btn-sidebar-close { flex: 0; padding: 0.4rem 0.6rem; font-size: 1.2rem; line-height: 1; border: none; background: transparent; color: var(--chat-muted); cursor: pointer; border-radius: 4px; }
.chat-btn-sidebar-close:hover { background: var(--chat-msg-bg); color: var(--chat-text); }
.chat-sidebar-content { flex: 1; overflow-y: auto; padding: 0.5rem; }
.chat-panel { display: block; }
.chat-panel.hidden { display: none; }
.chat-room-list { list-style: none; margin: 0; padding: 0; }
.chat-room-item { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; padding: 0.6rem 0.75rem; margin-bottom: 0.25rem; border-radius: 8px; cursor: pointer; color: var(--chat-text); }
.chat-room-item:hover { background: rgba(99, 102, 241, 0.15); }
.chat-room-item.active { background: rgba(99, 102, 241, 0.2); border-left: 3px solid var(--chat-primary); padding-left: calc(0.75rem - 3px); }
.chat-room-item-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-unread-dot { flex-shrink: 0; min-width: 18px; height: 18px; padding: 0 5px; line-height: 18px; font-size: 0.7rem; font-weight: 700; text-align: center; border-radius: 9px; background: #ef4444; color: #fff; }
.chat-room-item:not(.has-unread) .chat-unread-dot { display: none; }
.chat-sidebar-section { list-style: none; font-size: 0.75rem; font-weight: 600; color: var(--chat-muted); padding: 0.5rem 0.75rem 0.25rem; cursor: default; }
.chat-group-actions { margin-left: 0.5rem; }
.chat-group-actions.hidden { display: none; }

.chat-settings-section { margin-bottom: 1rem; }
.chat-settings-section .chat-label { display: block; font-size: 0.85rem; color: var(--chat-muted); margin-bottom: 0.35rem; }
.chat-settings-section .chat-input { width: 100%; padding: 0.5rem; border: 1px solid var(--chat-border); border-radius: 6px; background: var(--chat-bg); color: var(--chat-text); font-size: 0.95rem; }
.chat-hint { font-size: 0.8rem; color: var(--chat-muted); margin-top: 0.35rem; }
.chat-settings-actions { margin-top: 1rem; }

.chat-header { display: flex; align-items: center; gap: 0.5rem; padding: 0.6rem 0.75rem; background: var(--chat-header-bg); border-bottom: 1px solid var(--chat-border); flex-wrap: wrap; }
.chat-current-account { font-size: 0.9rem; color: var(--chat-text); padding: 0.25rem 0.5rem; background: var(--chat-msg-bg); border-radius: 6px; border: 1px solid var(--chat-border); white-space: nowrap; max-width: 160px; overflow: hidden; text-overflow: ellipsis; flex-shrink: 0; }
.chat-current-account strong { color: var(--chat-primary); }
.chat-btn-header-menu { background: transparent; border: none; color: var(--chat-muted); padding: 0.35rem 0.6rem; font-size: 1.1rem; cursor: pointer; border-radius: 6px; }
.chat-btn-header-menu:hover { background: var(--chat-msg-bg); color: var(--chat-text); }
.chat-header-menu-dropdown { position: absolute; top: 100%; right: 0.5rem; margin-top: 0.25rem; background: var(--chat-surface); border: 1px solid var(--chat-border); border-radius: 8px; padding: 0.5rem 0.75rem; min-width: 180px; box-shadow: 0 4px 12px rgba(0,0,0,0.3); z-index: 150; display: flex; flex-direction: column; gap: 0.5rem; }
.chat-header-menu-dropdown.hidden { display: none !important; }
.chat-header { position: relative; }
.chat-current-room { font-weight: 600; padding: 0.2rem 0.5rem; background: rgba(99, 102, 241, 0.2); border-radius: 4px; font-size: 0.85rem; max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }
.chat-current-room[title]:hover { opacity: 0.9; }
.chat-ws-status { width: 8px; height: 8px; border-radius: 50%; background: var(--chat-muted); flex-shrink: 0; }
.chat-ws-status.connected { background: #22c55e; }
.chat-ws-status.disconnected { background: #ef4444; }
.chat-btn { padding: 0.4rem 0.8rem; border-radius: 6px; font-size: 0.9rem; cursor: pointer; border: none; display: inline-block; background: var(--chat-msg-bg); color: var(--chat-text); }
.chat-btn-logout { background: rgba(239, 68, 68, 0.2); color: #f87171; }
.chat-btn-logout:hover { background: rgba(239, 68, 68, 0.3); }
.chat-btn-primary { background: var(--chat-primary); color: #fff; }
.chat-btn-primary:hover { background: var(--chat-primary-hover); }

.chat-errors { padding: 0.5rem 1rem; background: rgba(239, 68, 68, 0.15); color: #f87171; font-size: 0.9rem; }
.chat-errors.hidden { display: none; }

.chat-messages-wrap { flex: 1; display: flex; flex-direction: column; min-height: 0; background: var(--chat-bg); padding: 1rem; position: relative; }
.chat-home-view { flex: 1; display: flex; align-items: center; justify-content: center; min-height: 200px; padding: 2rem; }
.chat-home-view.hidden { display: none; }
.chat-home-inner { max-width: 480px; text-align: center; }
.chat-home-title { font-size: 1.25rem; margin: 0 0 1rem; color: var(--chat-fg, #333); }
.chat-home-intro { margin: 0 0 0.75rem; color: var(--chat-fg-muted, #666); line-height: 1.5; }
.chat-home-hint { margin: 0; font-size: 0.9rem; color: var(--chat-fg-muted, #666); }
.chat-messages-scroll-wrap { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.chat-messages-scroll-wrap.hidden { display: none; }
.chat-messages-scroll { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.chat-messages { display: flex; flex-direction: column; gap: 0.75rem; min-height: 120px; padding: 0.25rem 0; }
.chat-msg { max-width: 85%; width: fit-content; padding: 0.6rem 0.9rem; border-radius: 12px; background: var(--chat-msg-bg); border: 1px solid var(--chat-border); }
.chat-msg-me { align-self: flex-end; background: var(--chat-msg-me-bg); border-color: var(--chat-primary); }
.chat-msg-head { margin-bottom: 0.35rem; }
.chat-msg-name { font-weight: 600; font-size: 0.9rem; color: var(--chat-primary); }
.chat-msg-time { font-size: 0.75rem; color: var(--chat-muted); margin-left: 0.5rem; }
.chat-msg-body { word-wrap: break-word; }
.chat-msg-text { margin: 0 0 0.25rem 0; line-height: 1.45; white-space: pre-wrap; }
.chat-msg-text.chat-msg-text-truncate { max-height: 4.5em; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; cursor: pointer; }
.chat-msg-text.chat-msg-text-truncate.expanded { max-height: none; -webkit-line-clamp: unset; }
.chat-msg-text:last-child { margin-bottom: 0; }
.chat-msg-img { max-width: 100%; height: auto; border-radius: 8px; display: block; }
.chat-msg-audio { max-width: 100%; height: 36px; margin-top: 0.25rem; }
.chat-date-sep { text-align: center; margin: 0.75rem 0; font-size: 0.8rem; color: var(--chat-muted); }
.chat-msg-pending { opacity: 0.8; }
.chat-msg-visitor-link { color: inherit; text-decoration: underline; cursor: pointer; }
.chat-msg-visitor-link:hover { opacity: 0.9; }
.chat-visitor-status { font-size: 0.65rem; margin-right: 0.25rem; }
.chat-visitor-status.online { color: #22c55e; }
.chat-visitor-status.offline { color: var(--chat-muted); opacity: 0.6; }

.chat-send-area { padding: 0.75rem 1rem; background: var(--chat-send-bg); border-top: 1px solid var(--chat-border); flex-shrink: 0; }
.chat-send-inner { display: flex; flex-direction: column; gap: 0.5rem; }
.chat-input-msg { width: 100%; min-height: 52px; padding: 0.6rem 0.8rem; border: 1px solid var(--chat-border); border-radius: 8px; font-size: 1rem; font-family: inherit; resize: none; background: var(--chat-bg); color: var(--chat-text); }
.chat-input-msg:focus { outline: none; border-color: var(--chat-primary); }
.chat-send-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.chat-btn-upload { cursor: pointer; }
.chat-btn-upload:hover { background: var(--chat-border); }
.chat-btn-voice.recording { background: #ef4444; color: #fff; }
.chat-btn-send { background: var(--chat-primary); color: #fff; font-weight: 600; }
.chat-btn-send:hover { background: var(--chat-primary-hover); }

.chat-btn-menu { display: none; background: transparent; color: inherit; border: none; padding: 0.5rem 0.75rem; font-size: 1.25rem; cursor: pointer; }

/* Modal tạo nhóm */
.chat-modal { position: fixed; inset: 0; z-index: 300; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.chat-modal.hidden { display: none !important; }
.chat-modal-overlay { position: absolute; inset: 0; background: rgba(0,0,0,0.6); }
.chat-modal-box { position: relative; background: var(--chat-surface); border: 1px solid var(--chat-border); border-radius: 12px; padding: 1.25rem; width: 100%; max-width: 360px; max-height: 85vh; overflow: hidden; display: flex; flex-direction: column; }
.chat-modal-title { margin: 0 0 1rem 0; font-size: 1.15rem; color: var(--chat-text); }
.chat-modal-box .chat-input { width: 100%; padding: 0.5rem 0.75rem; margin-top: 0.25rem; }
.chat-modal-friends { max-height: 200px; overflow-y: auto; margin-top: 0.5rem; padding: 0.5rem 0; border: 1px solid var(--chat-border); border-radius: 8px; background: var(--chat-bg); }
.chat-modal-friends label { display: flex; align-items: center; gap: 0.5rem; padding: 0.4rem 0.75rem; cursor: pointer; font-size: 0.9rem; color: var(--chat-text); }
.chat-modal-friends label:hover { background: rgba(99, 102, 241, 0.1); }
.chat-modal-friends input[type="checkbox"] { margin: 0; }
.chat-modal-actions { margin-top: 1rem; display: flex; gap: 0.5rem; justify-content: flex-end; }

@media (max-width: 768px) {
	.chat-btn-menu { display: block; }
	.chat-sidebar { position: fixed; left: 0; top: 0; bottom: 0; z-index: 200; width: 280px; max-width: 85vw; transform: translateX(-100%); transition: transform 0.25s ease; }
	.chat-sidebar.open { transform: translateX(0); }
	.chat-sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 199; }
	.chat-sidebar-overlay.show { display: block; }
	.chat-msg { max-width: 92%; }
	.chat-current-account { max-width: 120px; }
}
