/* KBChatMQ style v2025031105 */
* { box-sizing: border-box; }
body { margin: 0; font-family: system-ui, -apple-system, sans-serif; background: #1a1a2e; color: #eee; -webkit-tap-highlight-color: transparent; }
.hidden { display: none !important; }

.chat-wrap { min-height: 100vh; min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.chat-card { background: #16213e; border-radius: 12px; padding: 2rem; max-width: 400px; width: 100%; }
.chat-card h1 { margin: 0 0 0.5rem 0; font-size: 1.25rem; }
.hint { font-size: 0.85rem; color: #94a3b8; margin: 0.5rem 0; }
.form-row { margin-bottom: 0.75rem; }
.form-row label { display: block; margin-bottom: 0.25rem; font-size: 0.9rem; }
.form-row input { width: 100%; padding: 0.5rem 0.75rem; border-radius: 6px; border: 1px solid #334155; background: #0f172a; color: #eee; font-size: 16px; }
.chat-card button { padding: 0.5rem 1rem; background: #3b82f6; color: #fff; border: none; border-radius: 6px; cursor: pointer; margin-top: 0.5rem; min-height: 44px; }
.chat-card button:hover { background: #2563eb; }
.error { color: #f87171; font-size: 0.9rem; margin-top: 0.5rem; }

.chat-app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; overflow: hidden; }
.chat-header { display: flex; align-items: center; gap: 0.5rem; padding: 0.5rem 1rem; background: #16213e; border-bottom: 1px solid #334155; flex-shrink: 0; }
.chat-header .btn-icon { display: none; padding: 0.5rem; background: transparent; color: #eee; border: none; font-size: 1.25rem; cursor: pointer; min-width: 44px; min-height: 44px; }
.chat-header span { flex: 1; font-size: 0.95rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-label-wrap { display: flex; align-items: center; gap: 0.35rem; flex: 1; min-width: 0; }
.user-label-wrap #userLabel { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.connection-status { font-size: 0.7rem; flex-shrink: 0; }
.connection-status.online { color: #22c55e; }
.connection-status.offline { color: #f87171; }
.btn-retry { padding: 0.2rem 0.4rem; font-size: 1rem; background: #334155; color: #e2e8f0; border: none; border-radius: 4px; cursor: pointer; flex-shrink: 0; }
.btn-retry:hover:not(:disabled) { background: #475569; color: #fff; }
.btn-retry:disabled { opacity: 0.6; cursor: not-allowed; }
.chat-header button:not(.btn-icon) { padding: 0.35rem 0.75rem; background: #64748b; color: #fff; border: none; border-radius: 6px; cursor: pointer; min-height: 36px; }

.chat-main { display: flex; flex: 1; overflow: hidden; min-height: 0; }
.chat-sidebar { width: 30%; min-width: 200px; max-width: 360px; background: #0f172a; border-right: 1px solid #334155; overflow-y: auto; display: flex; flex-direction: column; flex-shrink: 0; }
.chat-sidebar h3 { margin: 0 0 0.5rem 0; font-size: 0.95rem; padding: 0 0.5rem; }
.chat-sidebar .sidebar-tabs { display: flex; border-bottom: 1px solid #334155; }
.chat-sidebar .sidebar-tabs button { flex: 1; padding: 0.5rem 0.2rem; font-size: 1.1rem; background: transparent; color: #94a3b8; border: none; cursor: pointer; min-width: 0; }
.chat-sidebar .sidebar-tabs button.active { color: #3b82f6; border-bottom: 2px solid #3b82f6; }
.tab-panel { display: none; padding: 0.5rem 0.6rem; flex: 1; overflow-y: auto; min-height: 0; }
.tab-panel.active { display: block; }
.chat-sidebar button:not(.sidebar-tabs button) { width: 100%; padding: 0.5rem; margin-bottom: 0.5rem; background: #334155; color: #fff; border: none; border-radius: 6px; cursor: pointer; min-height: 40px; }
.chat-sidebar button:hover { background: #475569; }
.chat-sidebar ul { list-style: none; padding: 0; margin: 0; }
.chat-sidebar li { padding: 0.4rem 0.5rem; margin-bottom: 0.2rem; background: #1e293b; border-radius: 6px; cursor: pointer; font-size: 0.9rem; }
.chat-sidebar li:hover { background: #334155; }
.chat-sidebar li.active { background: #3b82f6; }
.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 0.35rem; vertical-align: middle; }
.status-dot.online { background: #22c55e; }
.status-dot.idle { background: #eab308; }
.status-dot.busy { background: #ef4444; }
.status-dot.offline { background: #64748b; }
.visitor-status-label { font-size: 0.72rem; margin-right: 0.4rem; padding: 0.15em 0.4em; border-radius: 4px; font-weight: 600; }
.visitor-status-label.online { color: #22c55e; background: rgba(34,197,94,0.2); }
.visitor-status-label.idle { color: #eab308; background: rgba(234,179,8,0.2); }
.visitor-status-label.offline { color: #64748b; background: rgba(100,116,139,0.2); }
.badge { display: inline-block; min-width: 1.2em; padding: 0.1em 0.4em; font-size: 0.75rem; background: #ef4444; color: #fff; border-radius: 10px; margin-left: 0.25rem; }
.unread-wrap { position: relative; }
.unread-badge { display: inline-flex; align-items: center; gap: 0.25rem; padding: 0.2em 0.5em; font-size: 0.85rem; background: #334155; color: #e2e8f0; border-radius: 8px; margin-left: 0.25rem; border: none; cursor: pointer; }
.unread-badge:hover { background: #475569; }
.unread-badge .unread-icon { font-size: 1rem; }
.unread-badge .unread-count { font-weight: 600; min-width: 1.2em; text-align: center; }
.unread-dropdown { position: absolute; top: 100%; right: 0; margin-top: 0.25rem; min-width: 280px; max-width: 90vw; background: #16213e; border: 1px solid #334155; border-radius: 8px; box-shadow: 0 4px 12px rgba(0,0,0,0.4); z-index: 60; max-height: 320px; }
.unread-dropdown-title { padding: 0.5rem 0.75rem; font-size: 0.85rem; color: #94a3b8; border-bottom: 1px solid #334155; }
.unread-dropdown-list { max-height: 260px; overflow-y: auto; padding: 0.25rem; }
.unread-dropdown-item { padding: 0.5rem 0.75rem; font-size: 0.9rem; cursor: pointer; border-radius: 6px; margin-bottom: 0.25rem; }
.unread-dropdown-item:hover { background: #1e293b; }
.unread-dropdown-item .room-name { font-weight: 500; color: #3b82f6; }
.unread-dropdown-item .msg-preview { font-size: 0.85rem; color: #94a3b8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.unread-dropdown-item .msg-time { font-size: 0.75rem; color: #64748b; }
.unread-dropdown-empty { padding: 1rem; text-align: center; color: #94a3b8; font-size: 0.9rem; }
.toast-container { position: fixed; bottom: 5rem; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 0.5rem; pointer-events: none; }
.toast-msg { padding: 0.75rem 1rem; background: #1e293b; border: 1px solid #334155; border-radius: 8px; font-size: 0.9rem; max-width: 320px; animation: toastIn 0.3s ease, toastOut 0.3s ease 3.5s forwards; }
.toast-msg .toast-room { font-weight: 500; color: #3b82f6; }
.toast-msg .toast-text { color: #e2e8f0; margin-top: 0.25rem; }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toastOut { from { opacity: 1; } to { opacity: 0; } }
.unread-hint { font-size: 0.8rem; color: #22c55e; margin-right: 0.5rem; }
.visitor-actions { margin-bottom: 0.5rem; }
.visitor-actions .btn-small { padding: 0.25rem 0.5rem; font-size: 0.75rem; margin-right: 0.25rem; }
.visitor-actions-row { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-bottom: 0.5rem; align-items: center; }
.visitor-actions-row .btn-small { padding: 0.3rem 0.5rem; font-size: 0.75rem; }
.visitor-history { margin-top: 0.5rem; font-size: 0.9rem; }
.visitor-history summary { cursor: pointer; color: #94a3b8; }
.visitor-date-header { font-size: 0.75rem; color: #64748b; padding: 0.35rem 0.5rem 0.15rem; margin-top: 0.5rem; border-top: 1px solid #334155; background: transparent !important; }
.visitor-date-header:first-child { margin-top: 0; border-top: none; }
.visitor-history ul { list-style: none; padding: 0; margin: 0.25rem 0 0 0; }
.company-visitors-wrap { margin-top: 1rem; padding-top: 0.75rem; border-top: 1px solid #334155; }
.company-visitors-title { font-size: 0.9rem; color: #94a3b8; margin: 0 0 0.5rem 0; }
.company-rooms-wrap { list-style: none; padding: 0; margin: 0 0 0.25rem 0; }
.company-rooms-summary { cursor: pointer; padding: 0.4rem 0.5rem; background: #1e293b; border-radius: 6px; margin-bottom: 0.25rem; font-size: 0.9rem; }
.company-rooms-summary:hover { background: #334155; }
.company-rooms-summary .company-count { color: #64748b; font-size: 0.85rem; }
.company-rooms-bar { display: flex; align-items: center; gap: 0.35rem; flex-wrap: nowrap; }
.company-rooms-title { flex: 1; cursor: pointer; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.company-rooms-actions { display: flex; gap: 0.15rem; flex-shrink: 0; align-items: center; }
.company-rooms-actions .btn-room-icon { padding: 0.15rem 0.3rem; font-size: 0.9rem; line-height: 1; background: transparent; color: #94a3b8; border: none; border-radius: 3px; cursor: pointer; }
.company-rooms-actions .btn-room-icon:hover { background: #334155; color: #e2e8f0; }
.company-rooms-actions .btn-room-delete-all:hover { color: #f87171; }
.company-rooms-actions .btn-room-expand { padding: 0.1rem 0.25rem; font-size: 0.65rem; background: transparent; color: #64748b; border: none; cursor: pointer; }
.company-rooms-actions .btn-room-expand:hover { color: #94a3b8; }
.room-select-chk { margin-right: 0.35rem; flex-shrink: 0; }
.company-rooms-list { list-style: none; padding-left: 0.5rem; margin: 0.25rem 0 0 0; border-left: 2px solid #334155; }
.company-rooms-wrap:not(.expanded) .company-rooms-list { display: none; }
.company-tab-item { list-style: none; padding: 0; margin: 0 0 0.5rem 0; }
.company-tab-summary { cursor: pointer; padding: 0.5rem; background: #1e293b; border-radius: 6px; font-size: 0.95rem; }
.company-tab-summary:hover { background: #334155; }
.company-tab-summary .company-peer-count { color: #64748b; font-size: 0.85rem; }
.company-tab-list { list-style: none; padding-left: 0.75rem; margin: 0.25rem 0 0 0; border-left: 2px solid #334155; }
.company-tab-item:not(.expanded) .company-tab-list { display: none; }
.company-tab-list li { padding: 0.35rem 0.5rem; cursor: pointer; border-radius: 4px; }
.company-tab-list li:hover { background: #334155; }
.visitor-preview { font-size: 0.8rem; color: #64748b; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.visitor-list { list-style: none; padding: 0; margin: 0; }
.visitor-list li { padding: 0.5rem; margin-bottom: 0.25rem; background: #1e293b; border-radius: 6px; cursor: pointer; display: flex; flex-wrap: wrap; align-items: center; gap: 0.25rem; }
.visitor-row { display: flex; flex-wrap: nowrap; align-items: center; gap: 0.25rem; }
.visitor-row .status-dot { flex-shrink: 0; }
.visitor-row .visitor-status-label { flex-shrink: 0; font-size: 0.65rem; }
.visitor-row .visitor-name { flex: 1; min-width: 0; max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.visitor-row .visitor-preview { flex: 1; min-width: 0; max-width: 100px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.75rem; color: #64748b; }
.visitor-name { flex: 1; min-width: 0; max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }
.visitor-name.expanded { max-width: none; white-space: normal; word-break: break-all; }
.visitor-preview { flex-basis: 100%; margin-top: 0.15rem; }
.visitor-item.visitor-online { border-left: 3px solid #22c55e; }
.visitor-item.visitor-idle { border-left: 3px solid #eab308; }
.visitor-item.visitor-offline { border-left: 3px solid #64748b; }
.visitor-list li:hover { background: #334155; }
.visitor-select-chk { flex-shrink: 0; margin-right: 0.25rem; }
.btn-delete-visitor { padding: 0 0.25rem; font-size: 0.85rem; background: transparent; color: #94a3b8; border: none; cursor: pointer; flex-shrink: 0; }
.btn-delete-visitor:hover { color: #ef4444; }
#deviceOnlineList .visitor-preview, #deviceHistoryList .visitor-preview { flex: 1; min-width: 0; max-width: 80px; overflow: hidden; text-overflow: ellipsis; }
.device-delete-wrap { margin-left: auto; flex-shrink: 0; position: relative; z-index: 10; }
.btn-clear-device-history { padding: 0.35rem 0.5rem; font-size: 0.9rem; background: #1e293b; color: #94a3b8; border: none; cursor: pointer; flex-shrink: 0; min-width: 36px; min-height: 36px; position: relative; z-index: 11; pointer-events: auto; border-radius: 4px; }
.btn-clear-device-history:hover { color: #ef4444; background: rgba(239,68,68,0.25); }
.btn-remove, .btn-clear-visitor { padding: 0 0.25rem; font-size: 0.9rem; background: transparent; color: #94a3b8; border: none; cursor: pointer; margin-left: auto; flex-shrink: 0; }
.btn-remove:hover, .btn-clear-visitor:hover { color: #ef4444; }

.chat-area { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; }
.chat-guide { flex: 1; padding: 2rem; overflow-y: auto; }
.chat-guide-content { max-width: 480px; margin: 0 auto; }
.chat-guide h2 { margin: 0 0 1rem 0; font-size: 1.25rem; }
.chat-guide ol { margin: 0.5rem 0; padding-left: 1.5rem; line-height: 1.6; }
.chat-view { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.chat-room-header { display: flex; align-items: center; justify-content: space-between; padding: 0.5rem 1rem; background: #16213e; border-bottom: 1px solid #334155; font-size: 0.95rem; flex-shrink: 0; }
.chat-room-header .room-actions { display: flex; gap: 0.25rem; }
.chat-room-header button { padding: 0.35rem 0.5rem; background: transparent; color: #94a3b8; border: none; cursor: pointer; font-size: 1rem; }
.chat-room-header .btn-debug { font-size: 1rem; }
.chat-room-header .btn-debug.active { color: #22c55e; }
.chat-room-header button:hover { color: #f87171; }
.chat-search-wrap { display: flex; align-items: center; gap: 0.5rem; padding: 0.5rem 1rem; background: #0f172a; border-bottom: 1px solid #334155; flex-shrink: 0; }
.chat-search-wrap.hidden { display: none; }
.chat-search-wrap input { flex: 1; min-width: 100px; padding: 0.35rem 0.5rem; border-radius: 4px; border: 1px solid #334155; background: #1e293b; color: #eee; font-size: 0.9rem; }
.chat-search-wrap button { padding: 0.35rem 0.5rem; background: transparent; color: #94a3b8; border: none; cursor: pointer; font-size: 0.9rem; }
.chat-search-wrap button:hover { color: #3b82f6; }
.chat-search-result { font-size: 0.8rem; color: #64748b; min-width: 4rem; text-align: center; }
.chat-msg .search-highlight { background: #eab308; color: #0f172a; padding: 0 2px; border-radius: 2px; }
.chat-msg .search-highlight.current { background: #3b82f6; color: #fff; }
.chat-msg-from-visitor { cursor: pointer; }
.chat-msg-from-visitor .chat-msg-visitor-meta { color: #3b82f6; text-decoration: underline; }
.chat-msg-from-visitor:hover .chat-msg-visitor-meta { color: #60a5fa; }
.chat-messages { flex: 1; min-height: 0; overflow-y: auto; padding: 1rem; -webkit-overflow-scrolling: touch; }
.chat-msg { margin-bottom: 0.75rem; padding: 0.5rem 0.75rem; background: #1e293b; border-radius: 8px; max-width: 85%; min-width: 60px; word-wrap: break-word; width: fit-content; }
.chat-msg.own { margin-left: auto; background: #3b82f6; }
.chat-msg .chat-msg-image-wrap,
.chat-msg .chat-msg-voice-wrap { max-width: min(280px, 85vw); }
.chat-msg-error { background: #7f1d1d; }
.chat-msg-error .error-text { color: #fca5a5; font-style: italic; }
.chat-msg .meta { font-size: 0.75rem; color: #94a3b8; margin-bottom: 0.25rem; }
.chat-input-row { display: flex; gap: 0.5rem; padding: 0.5rem 1rem; padding-bottom: max(0.5rem, env(safe-area-inset-bottom)); background: #16213e; border-top: 1px solid #334155; flex-shrink: 0; align-items: center; flex-wrap: wrap; position: relative; }
.chat-input-row input { flex: 1; min-width: 80px; padding: 0.5rem 0.75rem; border-radius: 6px; border: 1px solid #334155; background: #0f172a; color: #eee; font-size: 16px; min-height: 44px; }
.chat-input-row .chat-input-actions { display: flex; gap: 0.25rem; flex-shrink: 0; }
.chat-input-row button { padding: 0.5rem 1rem; background: #3b82f6; color: #fff; border: none; border-radius: 6px; cursor: pointer; min-height: 44px; min-width: 44px; }
.chat-input-row #btnSend { flex-shrink: 0; }
.chat-input-row #btnImage,
.chat-input-row #btnVoice { padding: 0.5rem 0.65rem; }
.chat-input-row .btn-more { display: none; padding: 0.5rem 0.75rem; background: #334155; font-size: 1.1rem; line-height: 1; }
.chat-input-row #btnVoice.recording { background: #ef4444; animation: voicePulse 1s ease-in-out infinite; }
.chat-input-menu { position: absolute; bottom: 100%; left: 0; right: 0; margin-bottom: 0.25rem; background: #1e293b; border: 1px solid #334155; border-radius: 8px; padding: 0.5rem; display: flex; flex-direction: column; gap: 0.25rem; z-index: 30; box-shadow: 0 -4px 12px rgba(0,0,0,0.3); }
.chat-input-menu.hidden { display: none !important; }
.chat-input-menu .menu-item { width: 100%; padding: 0.6rem 1rem; background: #334155; color: #eee; border: none; border-radius: 6px; cursor: pointer; text-align: left; font-size: 0.95rem; }
.chat-input-menu .menu-item:hover { background: #475569; }
@keyframes voicePulse { 50% { opacity: 0.8; } }
.chat-msg-voice-wrap { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.btn-voice-retry { padding: 0.2rem 0.5rem; font-size: 0.75rem; background: #334155; color: #e2e8f0; border: none; border-radius: 4px; cursor: pointer; white-space: nowrap; }
.btn-voice-retry:hover { background: #475569; }
.chat-msg-audio { max-width: 100%; height: 36px; flex: 1; min-width: 180px; }
.voice-size { font-size: 0.75rem; color: #94a3b8; white-space: nowrap; }
.chat-msg-image-wrap { margin: 0.25rem 0; display: block; }
.chat-msg-img { max-width: 100%; max-height: 240px; width: auto; height: auto; border-radius: 8px; display: block; cursor: pointer; object-fit: contain; vertical-align: top; }
.image-viewer-modal { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,0.92); z-index: 200; }
.image-viewer-modal.hidden { display: none !important; }
.image-viewer-overlay { position: absolute; inset: 0; cursor: pointer; z-index: 1; }
.image-viewer-content { position: relative; z-index: 2; max-width: 96vw; max-height: 96vh; display: flex; flex-direction: column; align-items: center; gap: 0.75rem; padding: 1rem; }
.image-viewer-content img { max-width: 92vw; max-height: 88vh; object-fit: contain; border-radius: 8px; }
.image-viewer-actions { display: flex; gap: 0.5rem; }
.image-viewer-actions button { padding: 0.5rem 1rem; background: #334155; color: #fff; border: none; border-radius: 6px; cursor: pointer; }
.image-viewer-actions button:hover { background: #475569; }
.chat-input-row button:disabled { opacity: 0.6; cursor: not-allowed; }
.chat-msg-img:hover { opacity: 0.95; }
.chat-msg-image-error { color: #94a3b8; font-size: 0.9rem; }
.trunk-debug-wrap { flex-shrink: 0; margin-bottom: 0.5rem; border: 1px solid #334155; border-radius: 4px; background: #0f172a; }
.trunk-debug-wrap.hidden { display: none !important; }
.trunk-debug-header { display: flex; justify-content: space-between; align-items: center; padding: 0.25rem 0.5rem; font-size: 0.75rem; color: #94a3b8; }
.trunk-debug-header button { background: transparent; border: none; color: #94a3b8; cursor: pointer; padding: 0 0.25rem; }
.trunk-debug-header button:hover { color: #fff; }
.trunk-debug-panel { min-height: 2.5rem; max-height: 120px; overflow-y: auto; font-size: 0.72rem; padding: 0.4rem; line-height: 1.4; }
.trunk-debug-line { padding: 0.15rem 0; font-family: monospace; }
.trunk-debug-line.trunk-gửi { color: #22c55e; }
.trunk-debug-line.trunk-nhận { color: #3b82f6; }
.trunk-debug-line.trunk-chia { color: #eab308; font-weight: 500; }
.trunk-debug-line.trunk-err { color: #ef4444; }
.trunk-debug-placeholder { color: #64748b; font-style: italic; padding: 0.25rem 0; }

.trunk-inline-status { margin-top: 0.35rem; padding: 0.25rem 0.5rem; background: #0f172a; border-radius: 4px; font-size: 0.72rem; }
.trunk-inline-list { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.trunk-pkt { padding: 0.1rem 0.35rem; border-radius: 3px; font-family: monospace; }
.trunk-pkt-pending { color: #94a3b8; background: #1e293b; }
.trunk-pkt-ok { color: #22c55e; background: rgba(34,197,94,0.15); }
.trunk-pkt-err { color: #ef4444; background: rgba(239,68,68,0.15); }
.trunk-receiving { margin: 0.5rem 0; padding: 0.5rem; background: #1e293b; border: 1px dashed #334155; border-radius: 6px; font-size: 0.85rem; }
.trunk-receiving .meta { color: #3b82f6; margin-bottom: 0.25rem; }
.setting-row { display: block; margin: 0.5rem 0; cursor: pointer; }
.setting-row input { margin-right: 0.5rem; }
.sidebar-footer { margin-top: auto; padding: 0.5rem 0.75rem; border-top: 1px solid #334155; flex-shrink: 0; display: flex; flex-direction: row; flex-wrap: nowrap; gap: 0.35rem; justify-content: center; align-items: center; }
.sidebar-footer .btn-settings { margin-bottom: 0; width: auto; flex: 1; min-width: 0; }
.sidebar-footer .btn-icon { min-width: 36px; padding: 0.4rem; font-size: 1.1rem; text-align: center; }
.room-actions-row { display: flex; flex-direction: row; gap: 0.5rem; margin-bottom: 0.5rem; }
.room-actions-row button { margin-bottom: 0; flex: 1; min-width: 0; }
.map-modal { padding: 0.5rem; align-items: flex-start; }
.map-modal-content { background: #16213e; border-radius: 12px; overflow: hidden; max-width: 96vw; width: 520px; max-height: 90vh; display: flex; flex-direction: column; }
.map-modal-header { display: flex; justify-content: space-between; align-items: center; padding: 0.75rem 1rem; background: #1e293b; border-bottom: 1px solid #334155; }
.map-modal-header h3 { margin: 0; font-size: 1rem; }
.btn-close-map { background: transparent; border: none; color: #94a3b8; cursor: pointer; font-size: 1.25rem; padding: 0 0.5rem; }
.btn-close-map:hover { color: #fff; }
.map-container { width: 100%; height: 320px; background: #0f172a; min-height: 240px; }
.map-container iframe { width: 100%; height: 100%; border: none; }
.map-hint { margin: 0.5rem 1rem; font-size: 0.85rem; color: #94a3b8; }
.map-link { display: inline-block; margin: 0.5rem 1rem 1rem; font-size: 0.9rem; color: #3b82f6; }
.map-link:hover { text-decoration: underline; }
.chat-msg-location-wrap { font-size: 0.9rem; }
.chat-msg-location { color: #3b82f6; text-decoration: none; }
.chat-msg-location:hover { text-decoration: underline; }
.map-link-small { font-size: 0.8rem; color: #94a3b8; margin-top: 0.25rem; display: inline-block; }
.btn-settings { width: 100%; padding: 0.5rem; background: #334155; color: #94a3b8; border: none; border-radius: 6px; cursor: pointer; font-size: 0.9rem; text-align: left; }
.btn-settings:hover { background: #475569; color: #fff; }
.settings-modal-content { max-width: 420px; max-height: 90vh; overflow-y: auto; }
.settings-sections { margin-bottom: 1rem; }
.settings-section { margin-bottom: 1.25rem; padding-bottom: 1rem; border-bottom: 1px solid #334155; }
.settings-section:last-of-type { border-bottom: none; }
.settings-section h4 { margin: 0 0 0.5rem 0; font-size: 0.95rem; color: #94a3b8; }
.setting-sub { margin-left: 1.5rem; margin-top: 0.35rem; }
.setting-sub label { display: block; font-size: 0.9rem; }
.setting-sub input { width: 80px; padding: 0.35rem; margin-left: 0.5rem; }
.settings-section textarea { width: 100%; padding: 0.5rem; border-radius: 6px; border: 1px solid #334155; background: #0f172a; color: #eee; font-size: 0.9rem; resize: vertical; min-height: 60px; }
.btn-profile { padding: 0.5rem 1rem; background: #3b82f6; color: #fff; border: none; border-radius: 6px; cursor: pointer; }
.btn-profile:hover { background: #2563eb; }
.profile-actions { margin-top: 1rem; }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 1rem; }
.modal-content { background: #16213e; padding: 1.5rem; border-radius: 12px; min-width: 280px; max-width: 100%; }
.modal-content h3 { margin: 0 0 1rem 0; }
.modal-content label { display: block; margin-bottom: 0.5rem; }
.modal-content input { width: 100%; padding: 0.5rem; border-radius: 6px; border: 1px solid #334155; background: #0f172a; color: #eee; font-size: 16px; }
.modal-content button { margin-right: 0.5rem; margin-top: 0.5rem; }
.btn-secondary { background: #64748b; }
.btn-danger { background: #dc2626; color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.room-context-members { margin: 1rem 0; max-height: 200px; overflow-y: auto; }
.room-context-members h4 { margin: 0 0 0.5rem 0; font-size: 0.9rem; color: #94a3b8; }
.room-context-members ul { list-style: none; padding: 0; margin: 0; }
.room-context-members li { padding: 0.35rem 0; font-size: 0.9rem; }
.room-context-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 1rem; }

.device-panel-view { flex: 1; display: flex; flex-direction: column; min-height: 0; background: #0f172a; overflow: hidden; }
.device-panel-view.device-panel-expanded {
  position: fixed;
  left: 0;
  right: 0;
  top: 52px;
  bottom: 0;
  z-index: 42;
  flex: none !important;
  width: 100%;
  max-width: 100%;
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.35);
}
.device-panel-header { display: flex; align-items: center; gap: 0.5rem; padding: 0.5rem 0.75rem; background: #16213e; border-bottom: 1px solid #334155; flex-shrink: 0; }
.device-panel-header .btn-icon { background: transparent; border: none; color: #e2e8f0; font-size: 1.25rem; cursor: pointer; min-width: 44px; }
.device-panel-expand { flex-shrink: 0; }

.device-widget-display-mock {
  min-height: 4.5rem;
  border-radius: 8px;
  padding: 0.5rem 0.65rem;
  background: linear-gradient(145deg, #1e293b 0%, #0f172a 100%);
  border: 1px solid #334155;
  font-size: 0.85rem;
}
.device-widget-display-mock .mock-title { font-size: 0.7rem; color: #94a3b8; text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 0.35rem; }
.device-widget-display-mock .mock-body { color: #e2e8f0; }
.device-mock-graph { height: 56px; background: repeating-linear-gradient(90deg, #3b82f633 0 8px, transparent 8px 16px); border-radius: 4px; }
.device-mock-wave { height: 48px; background: radial-gradient(ellipse 80% 60% at 50% 100%, #22d3ee55 0%, transparent 65%); }
.device-mock-qr { width: 64px; height: 64px; background: repeating-conic-gradient(#e2e8f0 0% 25%, #0f172a 0% 50%) 50% / 16px 16px; border-radius: 4px; margin: 0.25rem auto; }
.device-widget-chat-input { display: flex; flex-direction: column; gap: 0.35rem; }
.device-widget-chat-input .device-chat-input-row { display: flex; gap: 0.35rem; }
.device-widget-chat-input input { flex: 1; padding: 0.4rem 0.5rem; border-radius: 6px; border: 1px solid #475569; background: #0f172a; color: #e2e8f0; font-size: 0.9rem; }
.device-panel-title-wrap { flex: 1; min-width: 0; display: flex; align-items: center; gap: 0.35rem; }
.device-panel-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.device-panel-body { flex: 1; overflow-y: auto; padding: 1rem; min-height: 0; }
.device-setup-label { display: block; margin: 0.75rem 0; }
.device-setup-label input { width: 100%; margin-top: 0.25rem; padding: 0.5rem; border-radius: 6px; border: 1px solid #334155; background: #0f172a; color: #eee; }
.device-setup-fieldset { border: 1px solid #334155; border-radius: 8px; padding: 0.75rem; margin: 1rem 0; }
.device-setup-fieldset legend { padding: 0 0.35rem; color: #94a3b8; font-size: 0.9rem; }
.device-setup-check { display: block; margin: 0.4rem 0; cursor: pointer; font-size: 0.9rem; }
.device-setup-check input { margin-right: 0.5rem; }
.device-setup-actions { margin-top: 1rem; }
.btn-primary { padding: 0.5rem 1rem; background: #3b82f6; color: #fff; border: none; border-radius: 6px; cursor: pointer; font-size: 0.95rem; }
.btn-primary:hover { background: #2563eb; }
.device-needs-setup { font-size: 0.72rem; color: #fbbf24; margin-left: 0.35rem; vertical-align: middle; white-space: nowrap; }
.device-tab-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.35rem;
}
.device-tab-head h3 { margin: 0; flex: 1; min-width: 0; }
.device-actions-icon-bar {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.25rem;
  flex-shrink: 0;
}
.btn-device-action-icon {
  width: 36px;
  height: 36px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  line-height: 1;
  border-radius: 8px;
  border: 1px solid #475569;
  background: #1e293b;
  color: #e2e8f0;
  cursor: pointer;
}
.btn-device-action-icon:hover { background: #334155; border-color: #64748b; }

.device-list-text { display: flex; flex-direction: column; align-items: flex-start; min-width: 0; flex: 1; overflow: visible; }
#deviceOnlineList .device-list-text,
#deviceHistoryList .device-list-text {
  overflow: visible;
}
/* Tên device: không giới hạn 90px của .visitor-row (History vẫn đọc được) */
#deviceOnlineList .device-list-text .visitor-name,
#deviceHistoryList .device-list-text .visitor-name {
  max-width: 100%;
  flex: 0 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.device-session-hint {
  font-size: 0.68rem;
  line-height: 1.25;
  color: #94a3b8;
  margin-top: 0.15rem;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#deviceOnlineList .visitor-row,
#deviceHistoryList .visitor-row {
  align-items: flex-start;
}
/* History (offline): một dòng device … rút gọn, ellipsis; hover title = ID đủ */
#deviceHistoryList .device-list-text .device-id-bridge {
  flex: 0 0 auto;
  align-self: stretch;
  display: block;
  max-width: 100%;
  margin-top: 0.12rem;
  padding: 0.06rem 0.28rem;
  border-radius: 3px;
  background: rgba(30, 41, 59, 0.75);
  border: 1px solid #475569;
  font-size: 0.65rem;
  line-height: 1.2;
  color: #94a3b8;
  font-family: ui-monospace, monospace;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: default;
  user-select: text;
}
.device-control-widgets { display: flex; flex-direction: column; gap: 1rem; }
.device-control-bootstrap { gap: 0.65rem; }
.device-control-row {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 0.45rem;
  align-items: stretch;
}
.device-widget-col { min-width: 0; }
.device-widget-col .device-widget { height: 100%; box-sizing: border-box; }
.device-widget-param { display: flex; flex-direction: column; gap: 0.4rem; }
.device-widget-param .device-param-input {
  width: 100%; padding: 0.45rem 0.5rem; border-radius: 6px; border: 1px solid #334155;
  background: #0f172a; color: #eee; font-size: 0.9rem; box-sizing: border-box;
}
.device-widget-param .device-action-btn { width: 100%; }
.device-widget-param-multi .device-param-multi-fields {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 0.75rem;
  align-items: flex-end;
  margin-bottom: 0.45rem;
}
.device-widget-param-multi .device-param-field {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 5.5rem;
  flex: 1 1 6rem;
}
.device-widget-param-multi .device-param-field-label {
  font-size: 0.75rem;
  color: #94a3b8;
}
.device-widget-param-multi .device-param-input {
  width: 100%;
  padding: 0.45rem 0.5rem;
  border-radius: 6px;
  border: 1px solid #334155;
  background: #0f172a;
  color: #eee;
  font-size: 0.88rem;
  box-sizing: border-box;
}
.device-widget { padding: 0.75rem; background: #16213e; border-radius: 8px; border: 1px solid #334155; }
.device-widget h4 { margin: 0 0 0.35rem 0; font-size: 0.95rem; }
.device-widget-label { display: block; margin-bottom: 0.35rem; font-size: 0.9rem; color: #94a3b8; }
.device-toggle-btns { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.device-widget-slider input[type="range"] { width: 100%; margin: 0.5rem 0; }
.device-widget-slider .btn-apply-slider { margin-top: 0.25rem; }
.device-catalog-action-block { margin-bottom: 1rem; padding-bottom: 0.75rem; border-bottom: 1px solid #1e293b; }
.device-catalog-action-block:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }
.device-catalog-desc { margin: 0.25rem 0 0.35rem 1.5rem; font-size: 0.8rem; }
.device-catalog-custom-label { width: 100%; margin-top: 0.35rem; padding: 0.45rem 0.5rem; border-radius: 6px; border: 1px solid #334155; background: #0f172a; color: #eee; font-size: 0.9rem; box-sizing: border-box; }
.device-widget-button .device-action-btn { width: 100%; padding: 0.65rem 1rem; font-size: 0.95rem; }

.device-control-board {
  margin: 0.75rem 0 1rem;
  padding: 0.65rem 0.75rem;
  background: #111c2e;
  border: 1px solid #334155;
  border-radius: 8px;
}
.device-board-header { font-weight: 600; font-size: 0.95rem; color: #e2e8f0; margin-bottom: 0.25rem; }
.device-board-hint { margin: 0 0 0.5rem 0 !important; font-size: 0.75rem !important; }
.device-board-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 0.35rem; }
.device-board-row {
  display: flex; align-items: center; gap: 0.5rem; padding: 0.45rem 0.5rem;
  background: #16213e; border-radius: 6px; border: 1px solid #334155; cursor: pointer;
  font-size: 0.88rem;
}
.device-board-row:hover { border-color: #3b82f6; }
.device-board-name { flex: 1; min-width: 0; font-weight: 500; color: #f1f5f9; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.device-board-state { font-size: 0.72rem; color: #94a3b8; text-transform: uppercase; flex-shrink: 0; }
.device-board-row--online .device-board-state { color: #4ade80; }
.device-board-row--idle .device-board-state { color: #fbbf24; }
.device-board-row--offline .device-board-state { color: #94a3b8; }

.device-template-toolbar {
  display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: flex-end; margin: 0.5rem 0 0.75rem;
  padding: 0.65rem; background: #111c2e; border-radius: 8px; border: 1px dashed #475569;
}
.device-template-hint { width: 100%; margin: 0.35rem 0 0 !important; }
.btn-danger-text { color: #fca5a5 !important; border-color: #7f1d1d !important; }

.device-panel-setup-designer { max-width: 100%; }
.device-designer-toolbar { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: flex-end; margin: 0.75rem 0; }
.device-setup-inline { font-size: 0.9rem; color: #cbd5e1; }
.device-setup-inline select { margin-left: 0.35rem; padding: 0.4rem 0.5rem; border-radius: 6px; border: 1px solid #334155; background: #0f172a; color: #eee; min-width: 12rem; }
.device-setup-search { flex: 1; min-width: 160px; padding: 0.45rem 0.6rem; border-radius: 6px; border: 1px solid #334155; background: #0f172a; color: #eee; }
.device-designer-grid { display: grid; grid-template-columns: 1fr 1.15fr; gap: 1rem; margin-top: 0.5rem; }
@media (max-width: 720px) {
  .device-designer-grid { grid-template-columns: 1fr; }
}
.device-designer-subtitle { margin: 0 0 0.35rem 0; font-size: 0.9rem; color: #94a3b8; }
.device-palette-hint { margin: 0 0 0.5rem 0; font-size: 0.78rem; }
.device-setup-palette { display: flex; flex-wrap: wrap; gap: 0.45rem; align-content: flex-start; min-height: 120px; padding: 0.5rem; background: #0f172a; border: 1px dashed #475569; border-radius: 8px; }
.device-palette-chip { cursor: grab; padding: 0.4rem 0.55rem; font-size: 0.8rem; border-radius: 6px; background: #1e3a5f; border: 1px solid #334155; color: #e2e8f0; max-width: 100%; }
.device-palette-chip:active { cursor: grabbing; }
.device-palette-chip--static { background: #1e293b; border-color: #64748b; }
.device-setup-canvas { min-height: 180px; padding: 0.5rem; background: #0f172a; border: 2px dashed #3b82f6; border-radius: 8px; display: flex; flex-direction: column; gap: 0.5rem; }
.device-setup-canvas.device-canvas-dragover { border-color: #93c5fd; background: #172554; }
.device-canvas-grid-row {
  border: 1px solid #334155; border-radius: 8px; background: #111c2e; padding: 0.35rem 0.4rem 0.45rem;
}
.device-canvas-row-head {
  font-size: 0.72rem; color: #64748b; text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 0.25rem;
}
.device-canvas-grid-inner {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 0.35rem;
  align-items: stretch;
  min-height: 2.75rem;
  padding: 0.2rem 0;
  border-radius: 6px;
  transition: background 0.15s ease;
}
.device-canvas-grid-inner.device-canvas-inner--drag {
  background: rgba(59, 130, 246, 0.12);
  outline: 1px dashed #3b82f6;
}
.device-canvas-cell {
  position: relative;
  display: flex; flex-direction: column; gap: 0.2rem; min-width: 0;
  min-height: 3rem;
  padding: 0.5rem 0.5rem; background: #16213e; border: 1px solid #475569; border-radius: 6px;
  cursor: grab; font-size: 0.8rem;
  touch-action: none;
}
.device-canvas-cell:active { cursor: grabbing; }
.device-canvas-cell--over { outline: 2px solid #3b82f6; outline-offset: 1px; }
.device-canvas-cell-badge {
  font-size: 0.65rem; color: #38bdf8; font-family: ui-monospace, monospace; align-self: flex-start;
}
.device-canvas-row { display: flex; align-items: center; gap: 0.5rem; padding: 0.45rem 0.5rem; background: #16213e; border: 1px solid #334155; border-radius: 6px; cursor: grab; font-size: 0.85rem; }
.device-canvas-row:active { cursor: grabbing; }
.device-canvas-row.device-canvas-row--over { outline: 2px solid #3b82f6; }
.device-canvas-row-type { font-size: 0.68rem; color: #64748b; text-transform: uppercase; flex-shrink: 0; }
.device-canvas-row-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #e2e8f0; }
.device-canvas-empty { color: #64748b; font-size: 0.85rem; padding: 1rem; text-align: center; }
.device-ctx-menu {
  position: fixed; z-index: 200; min-width: 200px; padding: 0.35rem 0;
  background: #1e293b; border: 1px solid #475569; border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.45);
}
.device-ctx-menu.hidden { display: none !important; }
.device-ctx-item {
  display: block; width: 100%; text-align: left; padding: 0.5rem 0.85rem;
  background: transparent; border: none; color: #e2e8f0; font-size: 0.88rem; cursor: pointer;
}
.device-ctx-item:hover { background: #334155; }
.device-ctx-submenu-label {
  padding: 0.35rem 0.85rem 0.2rem; font-size: 0.72rem; color: #94a3b8; text-transform: uppercase;
  letter-spacing: 0.03em; border-top: 1px solid #334155; margin-top: 0.25rem;
}
.device-ctx-width-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.25rem; padding: 0.35rem 0.5rem 0.5rem;
}
.device-ctx-chip {
  padding: 0.35rem 0; font-size: 0.8rem; border-radius: 6px; border: 1px solid #475569;
  background: #0f172a; color: #cbd5e1; cursor: pointer;
}
.device-ctx-chip:hover { background: #334155; border-color: #64748b; }

.device-widget-modal-layout { margin: 0.75rem 0; padding-top: 0.5rem; border-top: 1px solid #334155; }
.device-layout-hint { margin: 0 0 0.5rem 0; }
.device-layout-fields { display: flex; flex-wrap: wrap; gap: 0.65rem; align-items: flex-end; }
.device-layout-field { font-size: 0.85rem; color: #cbd5e1; }
.device-layout-field input { width: 4.5rem; margin-left: 0.25rem; padding: 0.35rem 0.4rem; border-radius: 6px; border: 1px solid #334155; background: #0f172a; color: #eee; }
.btn-device-pin { flex-shrink: 0; background: transparent; border: none; cursor: pointer; font-size: 1rem; line-height: 1; padding: 0.15rem 0.25rem; opacity: 0.85; }
.btn-device-pin:hover { opacity: 1; }
.btn-device-pin.pinned { color: #fbbf24; }
.btn-device-open-setup { flex-shrink: 0; background: transparent; border: none; cursor: pointer; font-size: 1rem; line-height: 1; padding: 0.15rem 0.25rem; opacity: 0.85; color: #94a3b8; }
.btn-device-open-setup:hover { opacity: 1; color: #e2e8f0; }
.device-raw-section-heading { font-size: 0.82rem; font-weight: 600; color: #94a3b8; margin: 0.5rem 0 0.35rem; line-height: 1.3; }
.device-widget-modal-content { max-width: 420px; }
.device-widget-modal-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 1rem; }

/* Mobile responsive */
.sidebar-overlay { display: none; }
@media (max-width: 768px) {
  .chat-header .btn-icon { display: block; }
  .sidebar-overlay { display: block; position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 49; }
  .sidebar-overlay.hidden { display: none; }
  .chat-sidebar { position: fixed; top: 0; left: 0; bottom: 0; z-index: 50; width: min(300px, 85vw); transform: translateX(-100%); transition: transform 0.2s; box-shadow: 4px 0 12px rgba(0,0,0,0.3); }
  .chat-sidebar.open { transform: translateX(0); }
  .chat-msg { max-width: 92%; }
}
/* Màn hình nhỏ: ẩn nút ảnh/thoại, hiện nút ⋯ */
@media (max-width: 420px) {
  .chat-input-row #btnImage,
  .chat-input-row #btnVoice { display: none; }
  .chat-input-row .btn-more { display: inline-flex; align-items: center; justify-content: center; }
}
