* { 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; }
.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: 220px; min-width: 180px; background: #0f172a; border-right: 1px solid #334155; overflow-y: auto; display: flex; flex-direction: column; }
.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.25rem; font-size: 0.8rem; background: transparent; color: #94a3b8; border: none; cursor: pointer; }
.chat-sidebar .sidebar-tabs button.active { color: #3b82f6; border-bottom: 2px solid #3b82f6; }
.tab-panel { display: none; padding: 0.75rem; flex: 1; overflow-y: auto; }
.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.5rem; margin-bottom: 0.25rem; background: #1e293b; border-radius: 6px; cursor: pointer; }
.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; opacity: 0.6; }
.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-block; min-width: 1.2em; padding: 0.15em 0.5em; font-size: 0.8rem; background: #ef4444; color: #fff; border-radius: 10px; margin-left: 0.25rem; border: none; cursor: pointer; }
.unread-badge:hover { background: #dc2626; }
.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-history { margin-top: 0.5rem; font-size: 0.9rem; }
.visitor-history summary { cursor: pointer; color: #94a3b8; }
.visitor-history ul { list-style: none; padding: 0; margin: 0.25rem 0 0 0; }
.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; }
.visitor-list li:hover { background: #334155; }
.btn-remove { float: right; padding: 0 0.35rem; font-size: 1rem; background: transparent; color: #94a3b8; border: none; cursor: pointer; }
.btn-remove:hover { color: #ef4444; }

.chat-area { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.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 button:hover { color: #f87171; }
.chat-messages { flex: 1; 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%; word-wrap: break-word; }
.chat-msg.own { margin-left: auto; background: #3b82f6; }
.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; }
.chat-input-row input { flex: 1; 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 button { padding: 0.5rem 1rem; background: #3b82f6; color: #fff; border: none; border-radius: 6px; cursor: pointer; min-height: 44px; }

.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; }

/* 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: 260px; 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%; }
}
