/* ══════════════════════════════════════════════════════════════
   HelloMind — AI-Native Agent Living Space
   Design: Modern Dark Cinema Mobile (UI/UX Pro Max)
   ══════════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

/* ── Design Tokens ── */
:root {
  --bg-deep: #020203;
  --bg-base: #050506;
  --bg-elevated: #0a0a0c;
  --bg-surface: rgba(255,255,255,0.04);
  --bg-surface-hover: rgba(255,255,255,0.07);
  --bg-glass: rgba(10,10,12,0.82);
  --text-primary: #EDEDEF;
  --text-secondary: #8A8F98;
  --text-tertiary: #5C6370;
  --accent: #5E6AD2;
  --accent-glow: rgba(94,106,210,0.18);
  --accent-hover: #6B77E0;
  --accent-soft: rgba(94,106,210,0.12);
  --green: #059669;
  --green-soft: rgba(5,150,105,0.15);
  --red: #DC2626;
  --red-soft: rgba(220,38,38,0.12);
  --orange: #F59E0B;
  --purple: #8B5CF6;
  --border: rgba(255,255,255,0.06);
  --border-strong: rgba(255,255,255,0.12);
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.5);
  --shadow-glow: 0 0 20px var(--accent-glow);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-full: 9999px;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-out: cubic-bezier(0, 0, 0.2, 1);
  --transition: 180ms var(--ease);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', Menlo, monospace;
  --sidebar-w: 280px;
  --header-h: 56px;
  --input-h: 60px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { 
  height: 100%; 
  overflow: hidden; 
  overscroll-behavior: contain;
  -webkit-tap-highlight-color: transparent;
}
body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--bg-base);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }
ul { list-style: none; }
button { 
  border: none; background: none; color: inherit; 
  font: inherit; cursor: pointer; -webkit-appearance: none; 
}
input { 
  border: none; background: none; color: inherit; 
  font: inherit; outline: none; -webkit-appearance: none;
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--radius-sm); }
.hidden { display: none !important; }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.14); }

/* ── App Shell ── */
#app { 
  height: 100vh; height: 100dvh; 
  display: flex; flex-direction: column;
  background: linear-gradient(180deg, var(--bg-elevated) 0%, var(--bg-deep) 100%);
}
.screen { display: none; height: 100%; flex: 1; }
.screen.active { display: flex; }
#chat-screen { flex-direction: row; position: relative; }

/* ══════════════════════════════════════
   AUTH SCREEN
   ══════════════════════════════════════ */
#auth-screen {
  align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--bg-deep) 0%, #0a0a14 50%, var(--bg-deep) 100%);
  position: relative; overflow: hidden;
}
.auth-ambient {
  position: absolute; inset: 0; pointer-events: none;
  background: 
    radial-gradient(300px circle at 30% 20%, rgba(94,106,210,0.08) 0%, transparent 70%),
    radial-gradient(250px circle at 70% 80%, rgba(139,92,246,0.06) 0%, transparent 70%);
  animation: ambientDrift 20s ease-in-out infinite alternate;
}
@keyframes ambientDrift {
  0% { transform: translate(0, 0) scale(1); }
  100% { transform: translate(-20px, 10px) scale(1.05); }
}
.auth-box {
  width: min(380px, 90vw); padding: 40px 32px;
  background: var(--bg-glass);
  backdrop-filter: blur(24px); -webkit-backdrop-filter: blur(24px);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg), 0 0 60px rgba(94,106,210,0.06);
  text-align: center; position: relative; z-index: 1;
  animation: authIn 0.6s var(--ease) both;
}
@keyframes authIn {
  from { opacity: 0; transform: translateY(24px) scale(0.96); }
}
.auth-logo {
  margin-bottom: 16px;
  filter: drop-shadow(0 0 12px var(--accent-glow));
}
.auth-box h1 {
  font-size: 26px; font-weight: 700; letter-spacing: -0.02em;
  background: linear-gradient(135deg, var(--text-primary) 0%, var(--accent) 100%);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text;
}
.auth-subtitle { color: var(--text-tertiary); font-size: 14px; margin: 4px 0 28px; }

.input-group { margin-bottom: 12px; }
.input-group input, .create-room-form input {
  width: 100%; padding: 13px 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary); font-size: 15px;
  transition: border-color var(--transition), background var(--transition), box-shadow var(--transition);
}
.input-group input:focus, .create-room-form input:focus {
  border-color: var(--accent);
  background: var(--bg-surface-hover);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.input-group input::placeholder, .create-room-form input::placeholder { color: var(--text-tertiary); }

.auth-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 20px; }
.btn-primary {
  padding: 13px 24px; border-radius: var(--radius-md);
  background: var(--accent); color: #fff; font-weight: 600; font-size: 15px;
  transition: all var(--transition); position: relative; overflow: hidden;
}
.btn-primary:hover { background: var(--accent-hover); box-shadow: var(--shadow-glow); }
.btn-primary:active { transform: scale(0.97); }
.btn-ghost {
  padding: 13px 24px; border-radius: var(--radius-md);
  color: var(--text-secondary); font-weight: 500; font-size: 15px;
  border: 1px solid var(--border);
  transition: all var(--transition);
}
.btn-ghost:hover { color: var(--text-primary); border-color: var(--border-strong); background: var(--bg-surface); }
.btn-sm { padding: 8px 16px; font-size: 13px; border-radius: var(--radius-sm); }
.error { color: var(--red); font-size: 13px; margin-top: 12px; min-height: 18px; }

/* ══════════════════════════════════════
   SIDEBAR
   ══════════════════════════════════════ */
#sidebar {
  position: fixed; top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w); z-index: 50;
  background: var(--bg-glass);
  backdrop-filter: blur(24px); -webkit-backdrop-filter: blur(24px);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding-top: var(--safe-top);
  transform: translateX(-100%);
  transition: transform 320ms var(--ease);
  will-change: transform;
}
#sidebar.open { transform: translateX(0); }
#sidebar-overlay {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(0,0,0,0.5); backdrop-filter: blur(2px);
  opacity: 0; pointer-events: none;
  transition: opacity 320ms var(--ease-out);
}
#sidebar-overlay.visible { opacity: 1; pointer-events: auto; }

.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 16px 12px;
}
.sidebar-brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 17px; }

.sidebar-links { display: flex; gap: 5px; padding: 0 12px 8px; flex-wrap: wrap; }
.sidebar-link {
  flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 10px 6px; border-radius: var(--radius-md);
  background: var(--bg-surface); border: 1px solid var(--border);
  color: var(--text-secondary); font-size: 10px; font-weight: 500;
  transition: all var(--transition); text-decoration: none;
}
.sidebar-link:hover { background: var(--bg-surface-hover); color: var(--text-primary); border-color: var(--border-strong); }
.sidebar-link[data-color="purple"]:hover { color: var(--purple); border-color: rgba(139,92,246,0.3); }
.sidebar-link[data-color="blue"]:hover { color: #3B82F6; border-color: rgba(59,130,246,0.3); }

/* Sidebar Search */
.sidebar-search {
  display: flex; align-items: center; gap: 8px;
  margin: 0 12px 10px; padding: 8px 12px;
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--radius-full); transition: border-color var(--transition);
}
.sidebar-search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-glow); }
.sidebar-search svg { flex-shrink: 0; color: var(--text-tertiary); }
.sidebar-search input {
  flex: 1; background: none; border: none; outline: none;
  color: var(--text-primary); font-size: 13px; font-family: var(--font);
}
.sidebar-search input::placeholder { color: var(--text-tertiary); }

/* Quick Actions */
.sidebar-actions {
  display: flex; gap: 6px; padding: 0 12px 10px;
}
.sidebar-action-btn {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px;
  padding: 7px 10px; border-radius: var(--radius-full);
  background: var(--accent-soft); border: 1px solid rgba(94,106,210,0.15);
  color: var(--accent); font-size: 11px; font-weight: 600;
  cursor: pointer; transition: all var(--transition);
}
.sidebar-action-btn:hover { background: rgba(94,106,210,0.2); border-color: rgba(94,106,210,0.3); }
.sidebar-action-btn:active { transform: scale(0.95); }

/* Room list topic */
.room-topic-text {
  display: block; font-size: 11px; color: var(--text-tertiary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  margin-top: 1px; font-weight: 400;
}

/* Online items - compact name list */
.online-item {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 12px; border-radius: var(--radius-sm); cursor: pointer;
  transition: all var(--transition); font-size: 13px;
}
.online-item:hover { background: var(--bg-surface-hover); }
.online-item .presence-dot {
  width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0;
}
.online-item .online-name { flex: 1; font-weight: 500; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.online-item .online-name.agent-name { color: var(--accent); }
.online-item .badge { font-size: 9px; flex-shrink: 0; }
.presence-dot.online { background: var(--green); }
.presence-dot.offline { background: var(--text-tertiary); }
.online-group-header {
  font-size: 10px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--text-tertiary);
  padding: 8px 12px 4px; display: flex; align-items: center; gap: 6px;
}
.online-group-count {
  background: var(--bg-surface-hover); padding: 1px 6px;
  border-radius: var(--radius-full); font-size: 10px;
}

/* WS connection status */
.ws-status {
  width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
  transition: background var(--transition);
}
.ws-status.connected { background: var(--green); box-shadow: 0 0 6px var(--green-soft); }
.ws-status.reconnecting { background: var(--orange); animation: pulse 1.5s ease-in-out infinite; }
.ws-status.disconnected { background: var(--red); }

/* Search highlight */
.msg.search-highlight { background: rgba(94,106,210,0.12); border-radius: var(--radius-md); }

.sidebar-section { padding: 0 12px; margin-bottom: 8px; }
.sidebar-section-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 4px 6px;
}
.sidebar-section-header h3 { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-tertiary); }
.online-section h3 { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-tertiary); padding: 8px 4px 6px; }

.icon-btn {
  width: 36px; height: 36px; display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm); color: var(--text-secondary);
  transition: all var(--transition);
}
.icon-btn:hover { background: var(--bg-surface-hover); color: var(--text-primary); }
.icon-btn:active { transform: scale(0.92); }
.icon-btn-sm { width: 28px; height: 28px; display: flex; align-items: center; justify-content: center; border-radius: var(--radius-sm); color: var(--text-tertiary); transition: all var(--transition); }
.icon-btn-sm:hover { background: var(--bg-surface-hover); color: var(--text-primary); }

/* Room List */
.room-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: var(--radius-md); cursor: pointer;
  color: var(--text-secondary); transition: all var(--transition);
  position: relative; font-size: 14px; font-weight: 500;
}
.room-item:hover { background: var(--bg-surface-hover); color: var(--text-primary); }
.room-item.active { background: var(--accent-soft); color: var(--accent); }
.room-item .room-hash { color: var(--text-tertiary); font-weight: 400; font-size: 16px; }
.room-item.has-unread::after {
  content: ''; position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
  width: 8px; height: 8px; border-radius: 50%; background: var(--accent);
  box-shadow: 0 0 8px var(--accent-glow);
}

/* Create Room Form */
.create-room-form { padding: 8px 0; display: flex; flex-direction: column; gap: 8px; }
.create-room-form input { padding: 10px 12px; font-size: 14px; border-radius: var(--radius-sm); background: var(--bg-surface); border: 1px solid var(--border); }
.create-room-btns { display: flex; gap: 8px; }

/* Online List */
.online-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; border-radius: var(--radius-md); cursor: pointer;
  transition: all var(--transition); font-size: 14px;
}
.online-item:hover { background: var(--bg-surface-hover); }
.online-dot {
  width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
  background: var(--green); box-shadow: 0 0 6px var(--green-soft);
}
.online-dot.agent { background: var(--accent); box-shadow: 0 0 6px var(--accent-glow); }
.online-name { color: var(--text-primary); font-weight: 500; }
.online-role { color: var(--text-tertiary); font-size: 12px; margin-left: auto; }

/* Sidebar Footer */
.sidebar-footer {
  margin-top: auto;
  padding: 12px 16px; padding-bottom: calc(12px + var(--safe-bottom));
  border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.sidebar-user { display: flex; align-items: center; gap: 10px; font-size: 14px; font-weight: 500; }
.sidebar-footer-actions { display: flex; gap: 4px; }
.user-avatar-sm {
  width: 32px; height: 32px; border-radius: var(--radius-full);
  background: var(--accent-soft); display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 600; color: var(--accent);
}

/* ══════════════════════════════════════
   CHAT MAIN
   ══════════════════════════════════════ */
#chat-main {
  flex: 1; display: flex; flex-direction: column;
  height: 100vh; height: 100dvh;
  min-width: 0; position: relative;
}

/* Chat Header */
#chat-header {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; padding-top: calc(10px + var(--safe-top));
  min-height: var(--header-h);
  background: var(--bg-glass);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 30;
  flex-shrink: 0;
}
.header-info { flex: 1; min-width: 0; }
.header-info h3 { font-size: 16px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.header-info span { font-size: 12px; color: var(--text-tertiary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.header-actions { display: flex; gap: 4px; }

/* Messages Area */
#messages {
  flex: 1; overflow-y: auto; overflow-x: hidden;
  padding: 16px; padding-bottom: 8px;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  scroll-behavior: smooth;
  display: flex; flex-direction: column; gap: 2px;
}

/* Message Bubble */
.msg {
  display: flex; gap: 10px; max-width: 85%;
  padding: 6px 0;
  animation: msgIn 0.28s var(--ease) both;
}
@keyframes msgIn {
  from { opacity: 0; transform: translateY(8px); }
}
.msg.own { margin-left: auto; flex-direction: row-reverse; }

.msg-avatar {
  width: 34px; height: 34px; border-radius: var(--radius-full); flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 600;
  background: var(--bg-surface-hover); color: var(--text-secondary);
  margin-top: 2px;
}
.msg-avatar.agent-avatar { background: var(--accent-soft); color: var(--accent); }

.msg-body { min-width: 0; }
.msg-header { display: flex; align-items: baseline; gap: 8px; margin-bottom: 3px; }
.msg-name { font-size: 13px; font-weight: 600; cursor: pointer; }
.msg-name:hover { color: var(--accent); }
.msg-name.agent-name { color: var(--accent); }
.msg-time { font-size: 11px; color: var(--text-tertiary); }

.msg-content {
  padding: 10px 14px; border-radius: var(--radius-lg);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  font-size: 14.5px; line-height: 1.55;
  word-break: break-word; overflow-wrap: anywhere;
  position: relative;
}
.msg.own .msg-content {
  background: var(--accent-soft); border-color: rgba(94,106,210,0.15);
}
.msg.agent .msg-content { border-left: 3px solid var(--accent); }
.msg.own .msg-header { flex-direction: row-reverse; }

/* Message Actions */
.msg-actions {
  display: flex; gap: 2px; margin-top: 4px;
  opacity: 0; transition: opacity var(--transition);
}
.msg:hover .msg-actions { opacity: 1; }
.msg.own .msg-actions { justify-content: flex-end; }
.msg-actions button {
  padding: 4px 8px; border-radius: var(--radius-sm);
  font-size: 11px; color: var(--text-tertiary);
  transition: all var(--transition);
}
.msg-actions button:hover { background: var(--bg-surface-hover); color: var(--text-primary); }

/* System Messages */
.msg-system {
  text-align: center; padding: 8px 16px; font-size: 12px;
  color: var(--text-tertiary); font-style: italic;
}

/* Message Content Formatting */
.msg-content code {
  font-family: var(--font-mono); font-size: 13px;
  background: rgba(255,255,255,0.06); padding: 2px 6px;
  border-radius: 4px; border: 1px solid var(--border);
}
.msg-content pre {
  margin: 8px 0; border-radius: var(--radius-md); overflow-x: auto;
  background: var(--bg-deep); border: 1px solid var(--border);
  -webkit-overflow-scrolling: touch;
}
.msg-content pre code {
  display: block; padding: 14px 16px; background: none; border: none;
  font-size: 13px; line-height: 1.6; white-space: pre;
}
.msg-content strong { font-weight: 600; color: var(--text-primary); }
.msg-content em { color: var(--text-secondary); }
.msg-content del { color: var(--text-tertiary); text-decoration: line-through; }
.mention {
  display: inline; padding: 1px 6px; border-radius: var(--radius-sm);
  background: var(--accent-soft); color: var(--accent); font-weight: 500; font-size: 13px;
  cursor: pointer;
}
blockquote.agent-quote {
  border-left: 3px solid var(--accent); padding: 6px 12px; margin: 6px 0;
  background: var(--bg-surface); border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-secondary); font-size: 14px;
}
.tool-result {
  display: block; margin: 6px 0; padding: 10px 12px;
  background: var(--bg-deep); border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-family: var(--font-mono); font-size: 13px; line-height: 1.5;
  overflow-x: auto; white-space: pre-wrap;
}
.tool-name {
  display: inline-block; padding: 1px 6px; margin-bottom: 4px;
  background: var(--accent-soft); color: var(--accent);
  border-radius: 4px; font-size: 11px; font-weight: 600;
}
.msg-audio { width: 100%; max-width: 300px; margin: 6px 0; height: 36px; border-radius: var(--radius-full); }
.msg-image { margin: 6px 0; }
.msg-image img {
  max-width: 100%; max-height: 300px; border-radius: var(--radius-md);
  cursor: pointer; transition: transform var(--transition);
}
.msg-image img:hover { transform: scale(1.02); }
.img-caption { display: block; font-size: 12px; color: var(--text-tertiary); margin-top: 4px; }
.file-link {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: var(--radius-md);
  background: var(--bg-surface); border: 1px solid var(--border);
  font-size: 13px; color: var(--text-primary);
  transition: all var(--transition);
}
.file-link:hover { background: var(--bg-surface-hover); border-color: var(--border-strong); }

/* ── Message Actions ── */
.msg { position: relative; }
.msg-actions {
  position: absolute; top: -8px; right: 8px;
  display: none; gap: 2px; padding: 3px;
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: var(--radius-sm); box-shadow: 0 2px 8px rgba(0,0,0,0.3);
  z-index: 10;
}
.msg:hover .msg-actions { display: flex; }
.msg-action-btn {
  width: 28px; height: 28px; display: flex; align-items: center; justify-content: center;
  border: none; background: none; cursor: pointer; border-radius: 6px;
  font-size: 14px; transition: all 0.15s; color: var(--text-secondary);
}
.msg-action-btn:hover { background: var(--bg-surface-hover); color: var(--text-primary); }
.msg-action-btn.danger:hover { background: var(--red-soft); color: var(--red); }

/* Mobile: show actions on tap */
@media (max-width: 768px) {
  .msg-actions { display: none !important; }
  .msg.show-actions .msg-actions { display: flex !important; position: static; margin-top: 6px; background: none; border: none; box-shadow: none; }
}

/* ── Reply ── */
.reply-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; margin: 0 4px;
  background: var(--bg-surface); border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 13px; color: var(--text-secondary);
}
.reply-bar.hidden { display: none; }
.reply-bar-content { flex: 1; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.reply-bar-label { color: var(--text-tertiary); margin-right: 4px; }
.reply-bar-name { color: var(--accent); margin-right: 6px; }
.reply-bar-preview { color: var(--text-tertiary); }
.reply-bar-close {
  width: 24px; height: 24px; display: flex; align-items: center; justify-content: center;
  border: none; background: none; color: var(--text-tertiary); cursor: pointer;
  font-size: 16px; border-radius: 4px;
}
.reply-bar-close:hover { background: var(--bg-surface-hover); color: var(--text-primary); }

.msg-reply-header {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 8px; margin-bottom: 4px;
  font-size: 11px; color: var(--text-tertiary);
  border-left: 2px solid var(--border); cursor: pointer;
  border-radius: 0 4px 4px 0; transition: background 0.15s;
}
.msg-reply-header:hover { background: var(--bg-surface-hover); }
.msg-reply-header .reply-author { color: var(--accent); font-weight: 600; }

/* ── Edited label ── */
.msg-edited-label {
  font-size: 10px; color: var(--text-tertiary); margin-left: 6px; font-style: italic;
}

/* ── Pinned ── */
.msg.pinned { border-left: 2px solid var(--yellow); padding-left: 10px; }
.msg-pin-icon { font-size: 10px; margin-left: 4px; color: var(--yellow); }

/* ── Edit textarea ── */
.msg-edit-input {
  width: 100%; padding: 8px 10px; background: var(--bg-input);
  border: 1px solid var(--accent); border-radius: var(--radius-sm);
  color: var(--text-primary); font-family: inherit; font-size: 14px;
  resize: vertical; min-height: 40px; outline: none;
}

/* ── Scroll to bottom ── */
.scroll-bottom-btn {
  position: absolute; bottom: 120px; right: 20px; z-index: 20;
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--bg-elevated); border: 1px solid var(--border);
  color: var(--text-secondary); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  transition: all var(--transition); opacity: 1;
}
.scroll-bottom-btn:hover { background: var(--accent); color: white; border-color: var(--accent); }
.scroll-bottom-btn.hidden { opacity: 0; pointer-events: none; }

/* ── Typing Indicator ── */
#typing-indicator {
  display: none;
  padding: 4px 16px 6px; font-size: 12px; color: var(--text-tertiary);
  display: flex; align-items: center; gap: 8px;
  min-height: 24px; flex-shrink: 0;
}
.typing-dots { display: inline-flex; gap: 3px; align-items: center; }
.typing-dots i {
  width: 5px; height: 5px; border-radius: 50%; background: var(--text-tertiary);
  animation: typingBounce 1.2s ease-in-out infinite;
}
.typing-dots i:nth-child(2) { animation-delay: 0.15s; }
.typing-dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* ── Mention Popup ── */
.mention-popup {
  position: absolute; bottom: 100%; left: 12px; right: 12px;
  max-height: 200px; overflow-y: auto;
  background: var(--bg-elevated); border: 1px solid var(--border-strong);
  border-radius: var(--radius-md); box-shadow: var(--shadow-lg);
  z-index: 25;
}
.mention-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; cursor: pointer;
  transition: background var(--transition);
}
.mention-item:hover, .mention-item.active { background: var(--bg-surface-hover); }
.mention-item .online-dot { width: 6px; height: 6px; }

/* ── Upload Preview ── */
.upload-preview {
  padding: 8px 16px; display: flex; align-items: center; gap: 8px;
  border-top: 1px solid var(--border); background: var(--bg-elevated);
}
.upload-preview img { width: 48px; height: 48px; object-fit: cover; border-radius: var(--radius-sm); }
.upload-preview .upload-name { flex: 1; font-size: 13px; color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-preview .upload-remove { color: var(--red); font-size: 18px; }

/* ── Message Input ── */
#message-form {
  flex-shrink: 0; position: relative;
  padding: 8px 12px; padding-bottom: calc(8px + var(--safe-bottom));
  background: var(--bg-glass);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
}
.input-row {
  display: flex; align-items: center; gap: 4px;
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--radius-full); padding: 4px 6px;
  transition: border-color var(--transition);
}
.input-row:focus-within { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-glow); }
#message-input {
  flex: 1; padding: 10px 8px; font-size: 15px;
  min-width: 0; background: none;
}
#message-input::placeholder { color: var(--text-tertiary); }
.input-icon { width: 40px; height: 40px; border-radius: var(--radius-full); color: var(--text-tertiary); flex-shrink: 0; display: flex; align-items: center; justify-content: center; }
.input-icon:hover { color: var(--text-primary); background: var(--bg-surface-hover); }
.send-btn { 
  width: 40px; height: 40px; border-radius: var(--radius-full); flex-shrink: 0;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition);
}
.send-btn:hover { background: var(--accent-hover); box-shadow: var(--shadow-glow); }
.send-btn:active { transform: scale(0.9); }

/* Voice recording state */
.voice-btn.recording { 
  color: var(--red) !important; 
  animation: pulse 1.5s ease-in-out infinite; 
}
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }

/* ══════════════════════════════════════
   AGENT PROFILE MODAL
   ══════════════════════════════════════ */
.profile-popup {
  position: fixed; inset: 0; z-index: 60;
  display: flex; align-items: flex-end; justify-content: center;
}
.profile-backdrop {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.5); backdrop-filter: blur(4px);
}
.profile-card {
  position: relative; z-index: 1;
  width: min(420px, 95vw); max-height: 85vh; overflow-y: auto;
  background: var(--bg-elevated); border: 1px solid var(--border-strong);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  padding: 24px; padding-bottom: calc(24px + var(--safe-bottom));
  animation: sheetUp 0.35s var(--ease) both;
}
@keyframes sheetUp { from { transform: translateY(100%); } }
.profile-close { position: absolute; top: 16px; right: 16px; width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; border-radius: var(--radius-full); color: var(--text-tertiary); }
.profile-close:hover { background: var(--bg-surface-hover); color: var(--text-primary); }

.profile-header { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; }
.profile-avatar {
  width: 52px; height: 52px; border-radius: var(--radius-lg); flex-shrink: 0;
  background: var(--accent-soft); display: flex; align-items: center; justify-content: center;
  font-size: 24px; font-weight: 700; color: var(--accent);
  border: 2px solid var(--accent);
}
.profile-name { font-size: 20px; font-weight: 700; }
.profile-role { font-size: 13px; color: var(--text-secondary); display: block; }
.profile-model { font-size: 12px; color: var(--text-tertiary); margin-bottom: 12px; font-family: var(--font-mono); padding: 6px 10px; background: var(--bg-surface); border-radius: var(--radius-sm); display: inline-block; }
.profile-bio { font-size: 13px; color: var(--text-secondary); line-height: 1.5; margin-bottom: 12px; font-style: italic; }
.profile-bio:empty { display: none; }
.profile-personality { font-size: 14px; color: var(--text-secondary); line-height: 1.6; margin-bottom: 16px; }
.profile-section { margin-bottom: 16px; }
.profile-section h4 { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-tertiary); margin-bottom: 8px; }
.profile-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.profile-tags span {
  display: inline-block; padding: 4px 10px; border-radius: var(--radius-full);
  font-size: 12px; font-weight: 500;
  background: var(--bg-surface); border: 1px solid var(--border); color: var(--text-secondary);
}
.expertise-tags span { background: var(--accent-soft); border-color: rgba(94,106,210,0.15); color: var(--accent); }
.profile-status { font-size: 13px; color: var(--green); display: flex; align-items: center; gap: 6px; }

/* ══════��═══════════════════════════════
   DESIGN PREVIEW (Open Design iframes)
   ══════════════════════════════════════ */
.design-preview {
  margin: 8px 0; border-radius: var(--radius-lg); overflow: hidden;
  border: 1px solid var(--border-strong); background: var(--bg-elevated);
}
.design-preview-header {
  display: flex; align-items: center; gap: 8px; padding: 10px 14px;
  background: linear-gradient(135deg, rgba(139,92,246,0.12) 0%, rgba(94,106,210,0.08) 100%);
  border-bottom: 1px solid var(--border);
}
.design-preview-title { font-size: 13px; font-weight: 600; color: var(--purple); }
.design-preview-id { font-size: 11px; font-family: var(--font-mono); color: var(--text-tertiary); padding: 2px 6px; background: var(--bg-surface); border-radius: 4px; }
.design-preview-actions { margin-left: auto; display: flex; gap: 4px; }
.design-btn {
  width: 28px; height: 28px; display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm); font-size: 14px; color: var(--text-secondary);
  transition: all var(--transition);
}
.design-btn:hover { background: var(--bg-surface-hover); color: var(--text-primary); }
.design-iframe { width: 100%; height: 320px; border: none; background: #fff; }
.design-preview.expanded .design-iframe { height: 560px; }
.design-preview-footer {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 14px; border-top: 1px solid var(--border); font-size: 12px;
}
.design-files-link { color: var(--text-tertiary); transition: color var(--transition); }
.design-files-link:hover { color: var(--accent); }
.design-badge { color: var(--purple); font-weight: 500; font-size: 11px; }

/* ══════════════════════════════════════
   RESPONSIVE — TABLET & DESKTOP
   ══════════════════════════════════════ */
@media (min-width: 768px) {
  .msg { max-width: 72%; }
  .auth-box { padding: 48px 40px; }
}

@media (min-width: 1024px) {
  #sidebar {
    transform: translateX(0);
    position: relative; flex-shrink: 0;
    background: var(--bg-elevated);
    backdrop-filter: none;
  }
  #sidebar-overlay { display: none !important; }
  #btn-close-sidebar { display: none; }
  .hamburger { display: none; }
  #chat-screen.active { display: flex; flex-direction: row; }
  #chat-main { border-left: 1px solid var(--border); }
  .msg { max-width: 65%; }
}

/* ══════════════════════════════════════
   PWA / STANDALONE
   ══════════════════════════════════════ */
@media (display-mode: standalone) {
  #chat-header { padding-top: calc(14px + var(--safe-top)); }
  #sidebar { padding-top: calc(8px + var(--safe-top)); }
}

/* ══════════════════════════════════════
   REDUCED MOTION
   ══════════════════════════════════════ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .auth-ambient { animation: none; }
}

/* ── Additional Styles (JS-generated classes) ── */

/* Day Separator */
.day-separator {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 0 8px; color: var(--text-tertiary); font-size: 12px; font-weight: 500;
}
.day-separator::before, .day-separator::after {
  content: ''; flex: 1; height: 1px; background: var(--border);
}
.day-separator span { white-space: nowrap; }

/* Grouped Messages (same user, consecutive) */
.msg.grouped { padding-top: 0; }
.msg.grouped .msg-avatar { visibility: hidden; height: 0; }
.msg.grouped .msg-header { display: none; }

/* Message own alignment */
.msg.own { margin-left: auto; }
.msg.own .msg-header { justify-content: flex-end; }

/* Badge */
.badge {
  display: inline-block; padding: 1px 6px; border-radius: var(--radius-full);
  font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em;
}
.badge.agent { background: var(--accent-soft); color: var(--accent); }
.badge.human { background: var(--green-soft); color: var(--green); }

/* Status Dot (online list) */
.status-dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
  background: var(--text-tertiary);
}
.status-dot.online { background: var(--green); box-shadow: 0 0 6px var(--green-soft); }

/* Agent Emoji in online list */
.agent-emoji { margin-right: 2px; }
.agent-role { display: block; font-size: 11px; color: var(--text-tertiary); margin-left: 18px; margin-top: -2px; }

/* Online list items (JS generates li directly) */
#online-list li {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 8px 12px; border-radius: var(--radius-md); cursor: pointer;
  transition: all var(--transition); font-size: 14px; font-weight: 500;
  color: var(--text-primary);
}
#online-list li:hover { background: var(--bg-surface-hover); }

/* Room list items (JS generates li with textContent) */
#room-list li {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: var(--radius-md); cursor: pointer;
  color: var(--text-secondary); transition: all var(--transition);
  font-size: 14px; font-weight: 500;
}
#room-list li:hover { background: var(--bg-surface-hover); color: var(--text-primary); }
#room-list li.active { background: var(--accent-soft); color: var(--accent); }

/* Message avatar kinds */
.msg-avatar.agent { background: var(--accent-soft); color: var(--accent); }
.msg-avatar.human { background: var(--bg-surface-hover); color: var(--text-secondary); }

/* Message name kinds */
.msg-name { cursor: pointer; font-size: 13px; font-weight: 600; }
.msg-name:hover { color: var(--accent); }
.msg-name.agent { color: var(--accent); }
.msg-name.human { color: var(--text-primary); }

/* Mention popup items (JS-generated) */
.mention-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; cursor: pointer;
  transition: background var(--transition); font-size: 14px;
}
.mention-item:hover, .mention-item.active { background: var(--bg-surface-hover); }
.mention-emoji { font-size: 16px; }
.mention-kind { font-size: 11px; color: var(--text-tertiary); margin-left: auto; }

/* Upload states */
.upload-cancel { cursor: pointer; color: var(--red); font-size: 18px; padding: 4px; }
.upload-error { color: var(--red); font-size: 13px; }
.upload-progress { font-size: 12px; color: var(--text-tertiary); }

/* Tags in profile */
.tag {
  display: inline-block; padding: 4px 10px; border-radius: var(--radius-full);
  font-size: 12px; font-weight: 500;
  background: var(--bg-surface); border: 1px solid var(--border); color: var(--text-secondary);
}
.expertise-tags .tag { background: var(--accent-soft); border-color: rgba(94,106,210,0.15); color: var(--accent); }

/* Space agent link button class from v1 */
.space-agent-btn { display: none; }

/* Voice recording visual */
#btn-voice.recording svg { stroke: var(--red); }

/* Keyboard open state */
.keyboard-open #message-form { padding-bottom: 8px; }

/* PWA standalone */
.pwa-standalone #chat-header { padding-top: calc(14px + var(--safe-top)); }
.pwa-standalone #sidebar { padding-top: calc(8px + var(--safe-top)); }

/* Tool tags in profile */
.tool-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tool-tags .tag { background: var(--bg-surface); border-color: var(--border); }

/* Typing who text */
.typing-who { font-size: 12px; color: var(--text-tertiary); }

/* ══════════════════════════════════════
   UNREAD BADGES
   ══════════════════════════════════════ */
.room-unread {
  margin-left: auto;
  min-width: 20px; height: 20px;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0 6px;
  border-radius: var(--radius-full);
  background: var(--accent);
  color: #fff;
  font-size: 11px; font-weight: 700;
  line-height: 1;
  flex-shrink: 0;
}
.room-hash { color: var(--text-tertiary); font-weight: 400; font-size: 16px; flex-shrink: 0; }

/* ══════════════════════════════════════
   MESSAGE REACTIONS
   ══════════════════════════════════════ */
.msg-reactions {
  display: flex; flex-wrap: wrap; gap: 4px;
  min-height: 0;
}
.msg-reactions:empty { display: none; }
.reaction-pill {
  display: inline-flex; align-items: center; gap: 3px;
  padding: 3px 8px;
  border-radius: var(--radius-full);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  font-size: 13px; cursor: default;
  transition: all var(--transition);
}
.reaction-pill:hover {
  background: var(--bg-surface-hover);
  border-color: var(--border-strong);
}
.reaction-count { font-size: 11px; font-weight: 600; color: var(--text-secondary); }
.reaction-picker {
  position: absolute; bottom: 100%; left: 0;
  display: flex; gap: 2px;
  padding: 6px 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  z-index: 35;
  animation: msgIn 0.18s var(--ease) both;
}
.reaction-pick {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; border-radius: var(--radius-sm);
  transition: all var(--transition);
  cursor: pointer;
}
.reaction-pick:hover {
  background: var(--bg-surface-hover);
  transform: scale(1.2);
}

/* ══════════════════════════════════════
   IMAGE LIGHTBOX
   ══════════════════════════════════════ */
.lightbox {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.85);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  animation: fadeIn 0.2s var(--ease) both;
}
@keyframes fadeIn { from { opacity: 0; } }
.lightbox img {
  max-width: 92vw; max-height: 90vh;
  object-fit: contain;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
}
.lightbox-close {
  position: absolute; top: 16px; right: 16px;
  width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
  font-size: 28px; color: var(--text-primary);
  background: rgba(255,255,255,0.1);
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all var(--transition);
}
.lightbox-close:hover { background: rgba(255,255,255,0.2); }

/* ══════════════════════════════════════
   ROOM TRANSITION
   ══════════════════════════════════════ */
#messages.transitioning {
  opacity: 0;
  transition: opacity 0.15s var(--ease);
}
#messages:not(.transitioning) {
  opacity: 1;
  transition: opacity 0.2s var(--ease);
}

/* ══════════════════════════════════════
   ONLINE COUNT (HEADER)
   ══════════════════════════════════════ */
.online-count {
  font-size: 11px; color: var(--green);
  font-weight: 500;
  display: inline-flex; align-items: center; gap: 4px;
}
.online-count::before {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 6px var(--green-soft);
}
.online-count:empty { display: none; }
