/* === Reset & Base === */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #0f0f14;
  --surface: #1a1a24;
  --surface-2: #22223a;
  --border: #2d2d4a;
  --text: #e8e8f0;
  --text-dim: #9999b3;
  --accent: #6C5CE7;
  --accent-hover: #7e6ff2;
  --user-bubble: #2d2d5e;
  --bot-bubble: #1e1e35;
  --danger: #e74c3c;
  --success: #2ecc71;
  --warning: #f39c12;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,0.3);
  --room-sidebar-w: 260px;
  --nav-h: 48px;
}

/* === Light Theme === */
[data-theme="light"] {
  --bg: #f0f2f5;
  --surface: #ffffff;
  --surface-2: #e9ecef;
  --border: #d1d5db;
  --text: #1a1a2e;
  --text-dim: #6b7280;
  --accent: #6C5CE7;
  --accent-hover: #5a4bd6;
  --user-bubble: #e0dff8;
  --bot-bubble: #f3f2ff;
  --danger: #dc2626;
  --success: #16a34a;
  --warning: #d97706;
  --shadow: 0 4px 24px rgba(0,0,0,0.08);
}

[data-theme="light"] .message .content pre {
  background: #f5f5fa;
}

[data-theme="light"] .message .content code {
  background: rgba(108, 92, 231, 0.1);
}

/* === Tooltips === */
[data-tooltip] {
  position: relative;
}

[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%) scale(0.8);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 0.35rem 0.65rem;
  border-radius: 6px;
  font-size: 0.78rem;
  font-weight: 500;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s, transform 0.15s;
  z-index: 200;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  line-height: 1.3;
}

[data-tooltip]::before {
  content: "";
  position: absolute;
  bottom: calc(100% + 3px);
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: var(--border);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 200;
}

/* Show on hover (desktop) */
[data-tooltip]:hover::after,
[data-tooltip]:hover::before {
  opacity: 1;
  transform: translateX(-50%) scale(1);
}
[data-tooltip]:hover::before {
  transform: translateX(-50%);
}

/* Show via JS class (touch devices — long press) */
[data-tooltip].tooltip-visible::after,
[data-tooltip].tooltip-visible::before {
  opacity: 1;
  transform: translateX(-50%) scale(1);
}
[data-tooltip].tooltip-visible::before {
  transform: translateX(-50%);
}

/* Footer tooltips: show ABOVE (already default) */
footer [data-tooltip]::after {
  bottom: calc(100% + 8px);
  top: auto;
}
footer [data-tooltip]::before {
  bottom: calc(100% + 3px);
  top: auto;
  border-top-color: var(--border);
  border-bottom-color: transparent;
}

/* Navbar tooltips: show BELOW instead */
#app-nav [data-tooltip]::after {
  bottom: auto;
  top: calc(100% + 8px);
  transform: translateX(-50%) scale(0.8);
}
#app-nav [data-tooltip]::before {
  bottom: auto;
  top: calc(100% + 3px);
  border-top-color: transparent;
  border-bottom-color: var(--border);
}
#app-nav [data-tooltip]:hover::after,
#app-nav [data-tooltip].tooltip-visible::after {
  transform: translateX(-50%) scale(1);
}
#app-nav [data-tooltip]:hover::before,
#app-nav [data-tooltip].tooltip-visible::before {
  transform: translateX(-50%);
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

.screen {
  display: none;
  height: 100%;
}
.screen.active {
  display: flex;
  flex-direction: column;
}

.hidden { display: none !important; }

/* === Login === */
#login-screen {
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at 50% 30%, #1a1a3e 0%, var(--bg) 70%);
}

[data-theme="light"] #login-screen {
  background: radial-gradient(ellipse at 50% 30%, #e0dff8 0%, var(--bg) 70%);
}

.login-card {
  text-align: center;
  background: var(--surface);
  padding: 3rem 2.5rem;
  border-radius: 20px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  width: 90%;
  max-width: 400px;
}

.logo { margin-bottom: 1rem; }

.login-card h1 {
  font-size: 1.8rem;
  font-weight: 700;
  margin-bottom: 0.3rem;
}

.subtitle {
  color: var(--text-dim);
  margin-bottom: 2rem;
  font-size: 0.95rem;
}

#login-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

#login-form input {
  padding: 0.85rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s;
}
#login-form input:focus { border-color: var(--accent); }

#login-form button {
  padding: 0.85rem;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}
#login-form button:hover { background: var(--accent-hover); }

.login-error {
  color: var(--danger);
  font-size: 0.88rem;
  text-align: left;
  padding: 0.5rem 0.7rem;
  background: rgba(231, 76, 60, 0.1);
  border-radius: var(--radius-sm);
  border: 1px solid rgba(231, 76, 60, 0.3);
}
.login-error.hidden { display: none; }

/* === App Nav Bar === */
#app-nav {
  height: var(--nav-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
  flex-shrink: 0;
  z-index: 50;
}

.nav-tabs {
  display: flex;
  gap: 0.25rem;
}

.nav-tab {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 1rem;
  border: none;
  background: none;
  color: var(--text-dim);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all 0.2s;
}
.nav-tab:hover { background: var(--surface-2); color: var(--text); }
.nav-tab.active { background: var(--accent); color: #fff; }
.nav-tab svg { flex-shrink: 0; }

.nav-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

#user-badge {
  font-size: 0.85rem;
  color: var(--text-dim);
  background: var(--surface-2);
  padding: 0.3rem 0.7rem;
  border-radius: 20px;
  display: inline-flex;
  align-items: center;
}

/* === App Views === */
.app-view {
  display: none;
  flex: 1;
  min-height: 0;
}
.app-view.active {
  display: flex;
}

/* === Chat View Layout === */
#chat-view {
  flex-direction: row;
  position: relative;
}

.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* === Room Sidebar === */
.room-sidebar {
  width: var(--room-sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.room-sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.8rem 1rem;
  border-bottom: 1px solid var(--border);
}
.room-sidebar-header h3 { font-size: 0.95rem; font-weight: 600; }

.room-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.4rem;
}

.room-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 0.8rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s;
  font-size: 0.9rem;
  position: relative;
}
.room-item:hover { background: var(--surface-2); }
.room-item.active { background: var(--surface-2); border: 1px solid var(--accent); }

.room-icon { color: var(--text-dim); flex-shrink: 0; display: flex; align-items: center; }
.room-item.active .room-icon { color: var(--accent); }

.room-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.room-delete {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0 0.3rem;
  opacity: 0;
  transition: all 0.15s;
}
.room-item:hover .room-delete { opacity: 1; }
.room-delete:hover { color: var(--danger); }

/* === Unread Badge === */
.unread-badge {
  background: var(--accent);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
  flex-shrink: 0;
}

/* === Header === */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.8rem 1.2rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 10;
}

.header-left { display: flex; align-items: center; gap: 0.6rem; }

.status-dot {
  width: 10px;
  height: 10px;
  background: var(--success);
  border-radius: 50%;
  box-shadow: 0 0 6px var(--success);
}

header h2 { font-size: 1.1rem; font-weight: 600; }

.header-right { display: flex; align-items: center; gap: 0.5rem; }

.icon-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 0.4rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  transition: all 0.2s;
}
.icon-btn:hover { border-color: var(--accent); color: var(--accent); }
.icon-btn.hidden { display: none; }
.icon-btn.danger:hover { border-color: var(--danger); color: var(--danger); }

.mobile-only { display: none; }

/* === Messages === */
main#chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  scroll-behavior: smooth;
  position: relative;
  background:
    radial-gradient(circle at 20% 30%, rgba(108, 92, 231, 0.06) 0%, transparent 50%),
    radial-gradient(circle at 80% 70%, rgba(108, 92, 231, 0.04) 0%, transparent 50%),
    radial-gradient(circle at 50% 50%, rgba(108, 92, 231, 0.02) 0%, transparent 70%),
    linear-gradient(rgba(108, 92, 231, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(108, 92, 231, 0.03) 1px, transparent 1px);
  background-size: 100% 100%, 100% 100%, 100% 100%, 40px 40px, 40px 40px;
}

main#chat-messages::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(1.5px 1.5px at 10% 15%, rgba(108, 92, 231, 0.12) 50%, transparent 50%),
    radial-gradient(1.5px 1.5px at 30% 45%, rgba(108, 92, 231, 0.1) 50%, transparent 50%),
    radial-gradient(1.5px 1.5px at 50% 20%, rgba(108, 92, 231, 0.08) 50%, transparent 50%),
    radial-gradient(1.5px 1.5px at 70% 60%, rgba(108, 92, 231, 0.12) 50%, transparent 50%),
    radial-gradient(1.5px 1.5px at 85% 35%, rgba(108, 92, 231, 0.1) 50%, transparent 50%),
    radial-gradient(1.5px 1.5px at 25% 75%, rgba(108, 92, 231, 0.08) 50%, transparent 50%),
    radial-gradient(1.5px 1.5px at 60% 85%, rgba(108, 92, 231, 0.1) 50%, transparent 50%),
    radial-gradient(1.5px 1.5px at 90% 90%, rgba(108, 92, 231, 0.08) 50%, transparent 50%),
    radial-gradient(1px 1px at 15% 55%, rgba(108, 92, 231, 0.06) 50%, transparent 50%),
    radial-gradient(1px 1px at 45% 95%, rgba(108, 92, 231, 0.06) 50%, transparent 50%);
  background-size: 200px 200px;
  opacity: 0.7;
  z-index: 0;
}

main#chat-messages > * {
  position: relative;
  z-index: 1;
}

[data-theme="light"] main#chat-messages {
  background:
    radial-gradient(circle at 20% 30%, rgba(108, 92, 231, 0.04) 0%, transparent 50%),
    radial-gradient(circle at 80% 70%, rgba(108, 92, 231, 0.03) 0%, transparent 50%),
    radial-gradient(circle at 50% 50%, rgba(108, 92, 231, 0.015) 0%, transparent 70%),
    linear-gradient(rgba(108, 92, 231, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(108, 92, 231, 0.04) 1px, transparent 1px);
  background-size: 100% 100%, 100% 100%, 100% 100%, 40px 40px, 40px 40px;
}

/* Drag & Drop overlay */
main#chat-messages.drag-over::after {
  content: "Dateien hier ablegen";
  position: absolute;
  inset: 0;
  background: rgba(108, 92, 231, 0.1);
  border: 2px dashed var(--accent);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  color: var(--accent);
  font-weight: 600;
  z-index: 10;
  pointer-events: none;
}

.welcome-msg {
  text-align: center;
  color: var(--text-dim);
  margin: auto;
  padding: 2rem;
}

.message {
  max-width: 80%;
  padding: 0.85rem 1.1rem;
  border-radius: var(--radius);
  line-height: 1.55;
  font-size: 0.95rem;
  animation: fadeIn 0.25s ease;
  word-wrap: break-word;
  overflow-wrap: break-word;
  position: relative;
}

.message.highlight {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  transition: outline 0.3s;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.message.user {
  align-self: flex-end;
  background: var(--user-bubble);
  border-bottom-right-radius: 4px;
}

.message.assistant {
  align-self: flex-start;
  background: var(--bot-bubble);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.message .sender {
  font-size: 0.75rem;
  color: var(--accent);
  font-weight: 600;
  margin-bottom: 0.3rem;
}

.message .content { white-space: pre-wrap; }

.message .content code {
  background: rgba(108, 92, 231, 0.15);
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  font-size: 0.88rem;
  font-family: 'SF Mono', 'Fira Code', monospace;
}

.message .content pre {
  background: #12121f;
  padding: 0.8rem;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  margin: 0.5rem 0;
  border: 1px solid var(--border);
}
.message .content pre code { background: none; padding: 0; }

.message .file-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--surface-2);
  padding: 0.3rem 0.7rem;
  border-radius: 6px;
  font-size: 0.82rem;
  color: var(--accent);
  margin-bottom: 0.3rem;
  margin-right: 0.3rem;
}

.typing-indicator {
  align-self: flex-start;
  padding: 0.8rem 1.1rem;
  background: var(--bot-bubble);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  gap: 5px;
}

.typing-indicator span {
  width: 8px;
  height: 8px;
  background: var(--text-dim);
  border-radius: 50%;
  animation: bounce 1.2s infinite;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.15s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.3s; }

@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-6px); }
}

/* === Message Actions === */
.msg-actions {
  position: absolute;
  top: 0.3rem;
  right: 0.3rem;
  opacity: 0;
  transition: opacity 0.15s;
}
.message:hover .msg-actions { opacity: 1; }

.msg-action-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  width: 28px;
  height: 28px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}
.msg-action-btn:hover { border-color: var(--accent); color: var(--accent); }

.msg-action-menu {
  position: absolute;
  top: 2rem;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  z-index: 30;
  min-width: 160px;
  overflow: hidden;
}

.msg-menu-item {
  padding: 0.5rem 0.8rem;
  cursor: pointer;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  transition: background 0.15s;
  white-space: nowrap;
}
.msg-menu-item:hover { background: var(--surface-2); }
.msg-menu-item.danger:hover { background: rgba(231, 76, 60, 0.1); color: var(--danger); }

.msg-menu-item.has-submenu {
  flex-direction: column;
  align-items: flex-start;
}

.reaction-picker {
  display: flex;
  gap: 0.3rem;
  padding: 0.3rem 0;
}

.reaction-emoji {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.2rem 0.35rem;
  cursor: pointer;
  font-size: 1.1rem;
  transition: all 0.15s;
}
.reaction-emoji:hover { border-color: var(--accent); background: var(--surface-2); transform: scale(1.2); }

/* === Reactions === */
.reactions-container {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-top: 0.4rem;
}

.reaction-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.15rem 0.5rem;
  font-size: 0.82rem;
  cursor: pointer;
  transition: all 0.15s;
}
.reaction-pill:hover { border-color: var(--accent); }
.reaction-pill.own { border-color: var(--accent); background: rgba(108, 92, 231, 0.15); }

/* === Reply Quote === */
.reply-quote {
  background: var(--surface-2);
  border-left: 3px solid var(--accent);
  border-radius: 4px;
  padding: 0.3rem 0.6rem;
  margin-bottom: 0.4rem;
  cursor: pointer;
  font-size: 0.82rem;
  max-width: 100%;
  overflow: hidden;
}
.reply-quote:hover { background: var(--border); }
.reply-quote-name { color: var(--accent); font-weight: 600; margin-right: 0.4rem; }
.reply-quote-text { color: var(--text-dim); }

/* === Edit/Reply Bars === */
.edit-bar, .reply-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.4rem 0.8rem;
  background: var(--surface-2);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  margin-bottom: 0.3rem;
  font-size: 0.85rem;
  color: var(--accent);
}

.edit-bar button, .reply-bar button {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 1.2rem;
  padding: 0 0.3rem;
}
.edit-bar button:hover, .reply-bar button:hover { color: var(--text); }

.reply-bar-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

/* === Edited Badge === */
.edited-badge {
  font-size: 0.7rem;
  color: var(--text-dim);
  margin-left: 0.4rem;
  font-weight: 400;
}

/* === Pin Indicator === */
.pin-indicator {
  color: var(--accent);
  margin-left: 0.3rem;
  display: inline-flex;
  align-items: center;
}

/* === @Mention Pill === */
.mention-pill {
  background: rgba(108, 92, 231, 0.2);
  color: var(--accent);
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  font-weight: 600;
  font-size: 0.88rem;
}

/* === Mention Dropdown === */
.mention-dropdown {
  position: absolute;
  bottom: 100%;
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  margin-bottom: 0.3rem;
  max-height: 200px;
  overflow-y: auto;
  z-index: 40;
}

.mention-item {
  padding: 0.6rem 0.8rem;
  cursor: pointer;
  font-size: 0.9rem;
  transition: background 0.15s;
  min-height: 40px;
  display: flex;
  align-items: center;
}
.mention-item:hover, .mention-item.active { background: var(--surface-2); color: var(--accent); }
.mention-item-at { color: var(--accent); margin-right: 2px; font-weight: 600; }

/* === Claude Toggle === */
.claude-toggle-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}
.claude-toggle {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 0.35rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  transition: all 0.2s;
  flex-shrink: 0;
}
.claude-toggle:hover { border-color: var(--accent); color: var(--accent); }
.claude-toggle.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 0 8px rgba(108, 92, 231, 0.4);
}
.claude-mode-label {
  font-size: 0.6rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  white-space: nowrap;
  transition: color 0.2s;
}
.claude-mode-label.ai-active { color: var(--accent); }
.claude-mode-label.user-active { color: var(--success); }

/* Mode switch toast */
.mode-toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 0.6rem 1.2rem;
  border-radius: var(--radius);
  font-size: 0.85rem;
  font-weight: 500;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
  z-index: 300;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  text-align: center;
  max-width: 90vw;
}
.mode-toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.mode-toast.fade-out {
  opacity: 0;
  transform: translateX(-50%) translateY(-10px);
}

/* === Online Dot === */
.online-dot {
  width: 8px;
  height: 8px;
  background: var(--success);
  border-radius: 50%;
  border: 2px solid var(--surface);
  position: absolute;
  bottom: 0;
  right: 0;
}

.avatar-wrapper {
  position: relative;
  display: inline-flex;
}

/* === File Preview === */
.file-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.6rem 1rem;
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.file-preview.hidden { display: none; }

.file-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--surface-2);
  padding: 0.35rem 0.7rem;
  border-radius: 20px;
  font-size: 0.82rem;
  color: var(--text);
}
.file-chip .remove {
  cursor: pointer;
  color: var(--danger);
  font-weight: bold;
  margin-left: 0.2rem;
}

/* === Footer / Input === */
footer {
  padding: 0.8rem 1rem;
  background: var(--surface);
  border-top: 1px solid var(--border);
  position: relative;
}

#chat-form {
  display: flex;
  align-items: flex-end;
  gap: 0.6rem;
  background: var(--surface-2);
  border-radius: var(--radius);
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--border);
  transition: border-color 0.2s;
}
#chat-form:focus-within { border-color: var(--accent); }

#message-input {
  flex: 1;
  background: none;
  border: none;
  color: var(--text);
  font-size: 0.95rem;
  resize: none;
  outline: none;
  max-height: 150px;
  line-height: 1.5;
  font-family: inherit;
}

#attach-btn {
  cursor: pointer;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  padding: 0.3rem;
  transition: color 0.2s;
}
#attach-btn:hover { color: var(--accent); }

#send-btn {
  background: var(--accent);
  border: none;
  color: #fff;
  padding: 0.45rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  transition: background 0.2s;
}
#send-btn:hover { background: var(--accent-hover); }
#send-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* === Sidebars (right) === */
aside#files-sidebar,
aside#history-sidebar,
aside#pins-sidebar {
  position: absolute;
  top: 0;
  right: 0;
  width: 320px;
  max-width: 90%;
  height: 100%;
  background: var(--surface);
  border-left: 1px solid var(--border);
  z-index: 20;
  display: flex;
  flex-direction: column;
  box-shadow: -4px 0 24px rgba(0,0,0,0.4);
  animation: slideIn 0.2s ease;
}
aside#files-sidebar.hidden,
aside#history-sidebar.hidden,
aside#pins-sidebar.hidden { display: none; }

aside#history-sidebar { width: 380px; }

@keyframes slideIn {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}

.sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.2rem;
  border-bottom: 1px solid var(--border);
}
.sidebar-header h3 { font-size: 1rem; }

#close-sidebar,
#close-history-sidebar,
#close-pins-sidebar {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.5rem;
  cursor: pointer;
}
#close-sidebar:hover,
#close-history-sidebar:hover,
#close-pins-sidebar:hover { color: var(--text); }

/* === Pins Sidebar === */
.pins-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.6rem;
}
.pins-list .empty-hint {
  text-align: center;
  color: var(--text-dim);
  padding: 2rem;
  font-size: 0.9rem;
}

.pin-item {
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 0.4rem;
  cursor: pointer;
  transition: background 0.15s;
}
.pin-item:hover { background: var(--surface-2); }

.pin-item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.2rem;
  font-size: 0.82rem;
}
.pin-item-header strong { color: var(--accent); }
.pin-date { color: var(--text-dim); font-size: 0.72rem; }
.pin-item-text { font-size: 0.85rem; color: var(--text-dim); word-break: break-word; }

.files-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.8rem;
}
.files-list .empty-hint {
  text-align: center;
  color: var(--text-dim);
  padding: 2rem;
  font-size: 0.9rem;
}

.file-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 0.8rem;
  border-radius: var(--radius-sm);
  transition: background 0.15s;
  text-decoration: none;
  color: var(--text);
}
.file-item:hover { background: var(--surface-2); }
.file-item .file-icon { color: var(--accent); flex-shrink: 0; }
.file-item .file-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.88rem;
}

.sidebar-upload {
  padding: 0.8rem;
  border-top: 1px solid var(--border);
}

.upload-area {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.8rem;
  border: 2px dashed var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-dim);
  font-size: 0.9rem;
  transition: all 0.2s;
}
.upload-area:hover { border-color: var(--accent); color: var(--accent); }
.upload-area.small { padding: 0.5rem; font-size: 0.82rem; }

/* === History Sidebar === */
.history-search-box {
  padding: 0.8rem;
  border-bottom: 1px solid var(--border);
}

.history-search-box input {
  width: 100%;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.9rem;
  outline: none;
}
.history-search-box input:focus { border-color: var(--accent); }

.search-filters {
  display: flex;
  gap: 0.4rem;
  padding: 0.5rem 0.8rem;
  border-bottom: 1px solid var(--border);
}

.search-filters select,
.search-filters input {
  flex: 1;
  min-width: 0;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.78rem;
  outline: none;
}
.search-filters select:focus,
.search-filters input:focus { border-color: var(--accent); }

.search-results {
  flex: 1;
  overflow-y: auto;
  padding: 0.6rem;
}
.search-results .empty-hint {
  text-align: center;
  color: var(--text-dim);
  padding: 2rem 1rem;
  font-size: 0.88rem;
}

.search-result {
  padding: 0.7rem 0.8rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s;
  margin-bottom: 0.4rem;
  border: 1px solid var(--border);
}
.search-result:hover { background: var(--surface-2); border-color: var(--accent); }

.search-result-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.3rem;
}

.search-room-badge {
  font-size: 0.72rem;
  background: rgba(108, 92, 231, 0.15);
  color: var(--accent);
  padding: 0.1rem 0.5rem;
  border-radius: 10px;
  font-weight: 500;
}

.search-date {
  font-size: 0.72rem;
  color: var(--text-dim);
}

.search-sender {
  font-size: 0.78rem;
  color: var(--accent);
  font-weight: 600;
  margin-bottom: 0.2rem;
}

.search-snippet {
  font-size: 0.82rem;
  color: var(--text-dim);
  line-height: 1.4;
  word-break: break-word;
}

.search-highlight {
  background: rgba(108, 92, 231, 0.3);
  color: var(--text);
  padding: 0.05rem 0.15rem;
  border-radius: 3px;
}

/* === File Download Card === */
.file-download-card {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  margin-top: 0.7rem;
  padding: 0.7rem 1rem;
  background: var(--surface-2);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--text);
  transition: all 0.2s;
  cursor: pointer;
}
.file-download-card:hover { background: rgba(108, 92, 231, 0.15); border-color: var(--accent-hover); }
.file-download-card svg { color: var(--accent); flex-shrink: 0; }

.file-dl-info { display: flex; flex-direction: column; gap: 0.1rem; }
.file-dl-name { font-weight: 600; font-size: 0.9rem; }
.file-dl-size { font-size: 0.75rem; color: var(--text-dim); }

/* === Modal Overlay === */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: fadeIn 0.15s ease;
}
.modal-overlay.hidden { display: none; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  width: 90%;
  max-width: 480px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}
.modal.modal-small { max-width: 360px; }

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.2rem 1.5rem;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 1.1rem; }

.modal-close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0;
  line-height: 1;
}
.modal-close:hover { color: var(--text); }

.modal-body {
  padding: 1.2rem 1.5rem;
  overflow-y: auto;
  flex: 1;
}

.modal-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1rem 0;
}

.section-title {
  font-size: 0.95rem;
  color: var(--text-dim);
  margin-bottom: 0.8rem;
}

.profile-name-display {
  font-size: 1rem;
  font-weight: 600;
  text-align: center;
  color: var(--accent);
  margin-bottom: 0.5rem;
}

/* === Admin Panel === */
.admin-section { margin-bottom: 1.5rem; }
.admin-section h4 { font-size: 0.95rem; margin-bottom: 0.8rem; color: var(--text-dim); }

.create-user-form {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.create-user-form input,
.create-user-form select,
.create-user-form textarea {
  padding: 0.7rem 0.9rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.9rem;
  outline: none;
  font-family: inherit;
  resize: vertical;
}
.create-user-form input:focus,
.create-user-form select:focus,
.create-user-form textarea:focus { border-color: var(--accent); }

.create-user-form button[type="submit"] {
  padding: 0.7rem;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}
.create-user-form button[type="submit"]:hover { background: var(--accent-hover); }

.password-field {
  display: flex;
  gap: 0.4rem;
}
.password-field input { flex: 1; }

.btn-generate {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  cursor: pointer;
  padding: 0 0.7rem;
  display: flex;
  align-items: center;
  flex-shrink: 0;
}
.btn-generate:hover { color: var(--accent); border-color: var(--accent); }

.generated-password-display {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0.7rem;
  background: rgba(108, 92, 231, 0.1);
  border: 1px solid rgba(108, 92, 231, 0.3);
  border-radius: var(--radius-sm);
  font-family: monospace;
  font-size: 0.9rem;
  color: var(--accent);
  word-break: break-all;
}
.generated-password-display .copy-pw {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 0.1rem 0.3rem;
  flex-shrink: 0;
  display: flex;
  align-items: center;
}
.generated-password-display .copy-pw:hover { color: var(--accent); }

.form-msg {
  padding: 0.5rem 0.7rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  margin-top: 0.5rem;
}
.form-msg.success { background: rgba(46, 204, 113, 0.1); color: var(--success); border: 1px solid rgba(46, 204, 113, 0.3); }
.form-msg.error { background: rgba(231, 76, 60, 0.1); color: var(--danger); border: 1px solid rgba(231, 76, 60, 0.3); }
.form-msg.hidden { display: none; }

.admin-user-list { display: flex; flex-direction: column; gap: 0.4rem; }

.admin-user-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 0.8rem;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
}

.admin-user-info { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem 0.6rem; flex: 1; min-width: 0; }
.admin-user-name { font-weight: 500; }

.admin-user-role {
  font-size: 0.75rem;
  color: var(--accent);
  background: rgba(108, 92, 231, 0.15);
  padding: 0.15rem 0.5rem;
  border-radius: 10px;
}

.admin-user-details {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  margin-top: 0.3rem;
  font-size: 0.8rem;
  color: var(--text-dim);
  width: 100%;
}

.admin-user-fullname {
  font-weight: 500;
  color: var(--text);
}

.admin-user-phone a {
  color: var(--accent);
  text-decoration: none;
}
.admin-user-phone a:hover { text-decoration: underline; }

.admin-user-login {
  font-size: 0.75rem;
  color: var(--text-dim);
}

.admin-user-actions {
  display: flex;
  gap: 0.3rem;
  align-self: flex-start;
}

.admin-user-edit {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 0.2rem 0.3rem;
  display: flex;
  align-items: center;
}
.admin-user-edit:hover { color: var(--accent); }

.admin-user-delete {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 0 0.3rem;
}
.admin-user-delete:hover { color: var(--danger); }

.admin-form-buttons {
  display: flex;
  gap: 0.5rem;
}

.admin-form-buttons button {
  flex: 1;
  padding: 0.7rem;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}

.admin-form-buttons button[type="submit"] {
  background: var(--accent);
  color: #fff;
}
.admin-form-buttons button[type="submit"]:hover { background: var(--accent-hover); }

.btn-cancel {
  background: var(--surface-2) !important;
  color: var(--text-dim) !important;
  border: 1px solid var(--border) !important;
}
.btn-cancel:hover { color: var(--text) !important; }

/* === Disabled User Styling === */
.admin-user-disabled {
  opacity: 0.5;
}
.badge-disabled {
  font-size: 0.7rem;
  color: var(--danger);
  background: rgba(231, 76, 60, 0.15);
  padding: 0.1rem 0.45rem;
  border-radius: 10px;
  font-weight: 600;
}

/* === Role Badges === */
.role-admin {
  color: var(--danger) !important;
  background: rgba(231, 76, 60, 0.15) !important;
}
.role-moderator {
  color: var(--warning) !important;
  background: rgba(243, 156, 18, 0.15) !important;
}

/* === Admin Action Buttons === */
.admin-user-toggle-disable, .admin-user-reset-pw {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 0.2rem 0.3rem;
  display: flex;
  align-items: center;
}
.admin-user-toggle-disable:hover { color: var(--warning); }
.admin-user-reset-pw:hover { color: var(--accent); }

/* === Reset Password Display === */
.reset-pw-code {
  background: var(--surface-2);
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  font-family: monospace;
  font-size: 0.9rem;
  user-select: all;
}
.copy-pw-inline {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 0.1rem;
  vertical-align: middle;
}
.copy-pw-inline:hover { color: var(--accent); }

/* === Activity Log === */
.activity-log {
  max-height: 300px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.activity-entry {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.3rem 0.5rem;
  padding: 0.4rem 0.6rem;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
}
.activity-action {
  font-weight: 600;
  color: var(--accent);
}
.activity-user {
  color: var(--text);
  font-weight: 500;
}
.activity-details {
  color: var(--text-dim);
  font-size: 0.75rem;
}
.activity-time {
  margin-left: auto;
  color: var(--text-dim);
  font-size: 0.7rem;
  white-space: nowrap;
}
.btn-load-more {
  margin-top: 0.5rem;
  padding: 0.5rem 1rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  cursor: pointer;
  font-size: 0.8rem;
  align-self: center;
}
.btn-load-more:hover { color: var(--text); background: var(--border); }
.btn-load-more.hidden { display: none; }

/* === Online Count Badge === */
.online-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  font-size: 0.65rem;
  font-weight: 700;
  color: #fff;
  background: var(--success);
  border-radius: 9px;
  padding: 0 4px;
  margin-left: 0.3rem;
}

/* === Inline Online Dot === */
.online-dot.inline {
  display: inline-block;
  position: static;
  width: 7px;
  height: 7px;
  border: none;
  margin-right: 0.3rem;
  vertical-align: middle;
}

/* === Profile Last Login === */
.profile-last-login {
  font-size: 0.8rem;
  color: var(--text-dim);
  text-align: center;
  padding: 0.2rem 0;
}

/* === Room Creation Modal === */
#create-room-form {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

#create-room-form input {
  padding: 0.7rem 0.9rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.9rem;
  outline: none;
}
#create-room-form input:focus { border-color: var(--accent); }

#create-room-form button {
  padding: 0.7rem;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}
#create-room-form button:hover { background: var(--accent-hover); }

.member-select label {
  font-size: 0.88rem;
  color: var(--text-dim);
  display: block;
  margin-bottom: 0.5rem;
}

.member-checkboxes {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  max-height: 200px;
  overflow-y: auto;
}

.member-checkbox {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.6rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.9rem;
}
.member-checkbox:hover { background: var(--surface-2); }
.member-checkbox input[type="checkbox"] { accent-color: var(--accent); width: 16px; height: 16px; }

/* === Avatars === */
.avatar-msg {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.avatar-small {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.avatar-badge {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  object-fit: cover;
  vertical-align: middle;
  margin-right: 0.3rem;
}

.avatar-initials {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  line-height: 1;
}

.avatar-initials.avatar-msg {
  font-size: 0.65rem;
}

.avatar-initials.avatar-small {
  font-size: 0.72rem;
}

.avatar-initials.avatar-badge {
  font-size: 0.6rem;
}

.msg-header {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.3rem;
}

.msg-header .sender {
  margin-bottom: 0;
}

/* Avatar Upload Preview */
.avatar-upload-wrapper {
  display: flex;
  justify-content: center;
}

.avatar-upload-label {
  cursor: pointer;
}

.avatar-preview {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 2px dashed var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.2rem;
  color: var(--text-dim);
  font-size: 0.7rem;
  overflow: hidden;
  transition: border-color 0.2s;
}

.avatar-preview:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.avatar-preview.has-image {
  border-style: solid;
  border-color: var(--accent);
}

.avatar-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* === Scrollbar === */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* === Markdown in messages === */
.message .content h1,
.message .content h2,
.message .content h3 { margin: 0.6rem 0 0.3rem; }

.message .content ul,
.message .content ol { padding-left: 1.5rem; margin: 0.3rem 0; }

.message .content blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 0.8rem;
  color: var(--text-dim);
  margin: 0.5rem 0;
}

.message .content a { color: var(--accent); text-decoration: underline; }

.message .content table { border-collapse: collapse; margin: 0.5rem 0; width: 100%; }
.message .content th,
.message .content td { border: 1px solid var(--border); padding: 0.4rem 0.6rem; font-size: 0.88rem; }
.message .content th { background: var(--surface-2); }

/* === Responsive === */

/* Tablet (iPad) */
@media (max-width: 1024px) {
  .room-sidebar { width: 220px; }
  .message { max-width: 88%; }
  .modal { max-width: 90%; }
}

/* Phone (iPhone) */
@media (max-width: 768px) {
  .room-sidebar {
    position: absolute;
    top: 0;
    left: 0;
    width: var(--room-sidebar-w);
    height: 100%;
    z-index: 25;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: 4px 0 24px rgba(0,0,0,0.4);
  }
  .room-sidebar.open { transform: translateX(0); }
  .mobile-only { display: flex; }
  .message { max-width: 95%; font-size: 0.9rem; }
  .login-card { padding: 2rem 1.5rem; }
  aside#files-sidebar,
  aside#history-sidebar,
  aside#pins-sidebar { width: 100%; max-width: 100%; }
  #app-nav { padding: 0 0.5rem; }
  #user-badge { font-size: 0.78rem; padding: 0.25rem 0.5rem; }
  .avatar-badge { width: 20px; height: 20px; }
  header { padding: 0.6rem 0.8rem; }
  header h2 { font-size: 1rem; }
  main#chat-messages { padding: 1rem 0.6rem; }
  footer { padding: 0.5rem 0.6rem; }
  #chat-form { padding: 0.4rem 0.5rem; }
  .modal { max-width: 95%; border-radius: 12px; }
  .modal-body { padding: 1rem; }
  .modal-header { padding: 1rem; }
  .avatar-msg { width: 24px; height: 24px; }
  .avatar-initials.avatar-msg { font-size: 0.58rem; }
}

/* Small phones */
@media (max-width: 380px) {
  .login-card { padding: 1.5rem 1rem; }
  .login-card h1 { font-size: 1.4rem; }
  #user-badge { display: none; }
  .nav-tab { padding: 0.3rem 0.6rem; font-size: 0.82rem; }
}

/* Safe area (notch) support for iOS */
@supports (padding: env(safe-area-inset-top)) {
  #app-nav { padding-top: env(safe-area-inset-top); }
  footer { padding-bottom: env(safe-area-inset-bottom); }
  .room-sidebar { padding-top: env(safe-area-inset-top); }
}

/* Touch-friendly sizing */
@media (hover: none) and (pointer: coarse) {
  .icon-btn { min-width: 40px; min-height: 40px; }
  .room-item { padding: 0.75rem 0.8rem; }
  .admin-user-edit, .admin-user-delete { min-width: 36px; min-height: 36px; }
  .msg-actions { opacity: 1; }
}

/* ============================
   NEW FEATURES STYLES
   ============================ */

/* === Typing Status === */
.typing-status {
  padding: 0 1rem;
  font-size: 0.8rem;
  color: var(--text-dim);
  min-height: 1.2em;
  font-style: italic;
}

/* === Code Syntax Highlighting === */
.message .content pre {
  position: relative;
}
.code-copy-btn {
  position: absolute;
  top: 0.4rem;
  right: 0.4rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 4px;
  padding: 0.2rem 0.5rem;
  font-size: 0.72rem;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 1;
}
.message .content pre:hover .code-copy-btn { opacity: 1; }
.code-copy-btn:hover { color: var(--accent); border-color: var(--accent); }
[data-theme="light"] .message .content pre code { background: #f5f5fa; }

/* === Room Search Bar === */
.room-search-bar {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.room-search-bar.hidden { display: none; }
.room-search-bar input {
  flex: 1;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.4rem 0.6rem;
  color: var(--text);
  font-size: 0.88rem;
  outline: none;
}
.room-search-bar input:focus { border-color: var(--accent); }
.room-search-counter { font-size: 0.78rem; color: var(--text-dim); white-space: nowrap; }
mark.search-highlight-active { background: var(--accent); color: #fff; }
mark.search-highlight { background: rgba(108, 92, 231, 0.3); color: var(--text); border-radius: 2px; }

/* === Read Receipts === */
.read-receipt {
  font-size: 0.7rem;
  color: var(--text-dim);
  margin-left: 0.4rem;
  display: inline-flex;
  align-items: center;
}
.read-receipt.read-all { color: var(--accent); }

/* === Voice Messages === */
.footer-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 0.3rem 0.5rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  font-size: 0.78rem;
  font-weight: 600;
  transition: all 0.15s;
  flex-shrink: 0;
}
.footer-btn:hover { border-color: var(--accent); color: var(--accent); }

.voice-recording {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.8rem;
  background: var(--surface-2);
  border-radius: var(--radius);
  flex: 1;
}
.voice-recording .rec-dot {
  width: 10px; height: 10px;
  background: var(--danger);
  border-radius: 50%;
  animation: pulse-rec 1s infinite;
}
@keyframes pulse-rec {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}
.voice-recording .rec-time { font-size: 0.88rem; color: var(--text); font-variant-numeric: tabular-nums; }
.voice-recording .rec-cancel, .voice-recording .rec-send {
  background: none; border: none; cursor: pointer; padding: 0.3rem;
}
.voice-recording .rec-cancel { color: var(--danger); font-size: 1.2rem; }
.voice-recording .rec-send { color: var(--success); }

.voice-message {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0;
}
.voice-play-btn {
  background: var(--accent);
  border: none;
  color: #fff;
  width: 32px; height: 32px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.voice-progress {
  flex: 1;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  cursor: pointer;
  position: relative;
}
.voice-progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  width: 0;
  transition: width 0.1s linear;
}
.voice-duration { font-size: 0.78rem; color: var(--text-dim); font-variant-numeric: tabular-nums; flex-shrink: 0; }

/* === GIF Panel === */
.gif-panel {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  width: 360px;
  max-width: 90vw;
  max-height: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 100;
  display: flex;
  flex-direction: column;
}
.gif-panel.hidden { display: none; }
.gif-panel-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem;
  border-bottom: 1px solid var(--border);
}
.gif-panel-header input {
  flex: 1;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.4rem 0.6rem;
  color: var(--text);
  font-size: 0.88rem;
  outline: none;
}
.gif-panel-header button {
  background: none; border: none; color: var(--text-dim); cursor: pointer; font-size: 1.3rem;
}
.gif-results {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 0.4rem;
  overflow-y: auto;
  max-height: 320px;
}
.gif-results img {
  width: 100%;
  height: 100px;
  object-fit: cover;
  border-radius: 4px;
  cursor: pointer;
  transition: opacity 0.15s;
}
.gif-results img:hover { opacity: 0.8; }
.inline-gif { max-width: 250px; max-height: 200px; border-radius: var(--radius-sm); display: block; margin: 0.3rem 0; }

/* === Schedule Badge === */
.schedule-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: var(--accent);
  color: #fff;
  font-size: 0.6rem;
  font-weight: 700;
  min-width: 14px;
  height: 14px;
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
}
.schedule-badge.hidden { display: none; }
#schedule-btn { position: relative; }
.scheduled-list { margin-top: 1rem; display: flex; flex-direction: column; gap: 0.4rem; }
.scheduled-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0.6rem;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
}
.scheduled-item-content { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scheduled-item-time { font-size: 0.75rem; color: var(--text-dim); margin-left: 0.5rem; white-space: nowrap; }
.scheduled-item-delete {
  background: none; border: none; color: var(--text-dim); cursor: pointer; font-size: 1.1rem; padding: 0 0.3rem;
}
.scheduled-item-delete:hover { color: var(--danger); }

/* === Polls === */
.poll-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.8rem;
  margin: 0.4rem 0;
}
.poll-question { font-weight: 600; margin-bottom: 0.6rem; font-size: 0.95rem; }
.poll-option {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.6rem;
  margin-bottom: 0.3rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s;
  position: relative;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
}
.poll-option:hover { border-color: var(--accent); }
.poll-option.voted { border-color: var(--accent); background: rgba(108, 92, 231, 0.1); }
.poll-option-bar {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  background: rgba(108, 92, 231, 0.15);
  transition: width 0.3s;
  z-index: 0;
}
.poll-option-text { position: relative; z-index: 1; flex: 1; font-size: 0.88rem; }
.poll-option-pct { position: relative; z-index: 1; font-size: 0.78rem; color: var(--text-dim); font-weight: 600; }
.poll-total { font-size: 0.75rem; color: var(--text-dim); margin-top: 0.3rem; text-align: right; }

/* === Forward === */
.forwarded-header {
  font-size: 0.75rem;
  color: var(--text-dim);
  font-style: italic;
  margin-bottom: 0.3rem;
  display: flex;
  align-items: center;
  gap: 0.3rem;
}
.forward-room-list { display: flex; flex-direction: column; gap: 0.3rem; }
.forward-room-item {
  padding: 0.6rem 0.8rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s;
  font-size: 0.9rem;
}
.forward-room-item:hover { background: var(--surface-2); }

/* === Thread Sidebar === */
aside#thread-sidebar {
  position: absolute;
  top: 0;
  right: 0;
  width: 360px;
  max-width: 90%;
  height: 100%;
  background: var(--surface);
  border-left: 1px solid var(--border);
  z-index: 20;
  display: flex;
  flex-direction: column;
  box-shadow: -4px 0 24px rgba(0,0,0,0.4);
  animation: slideIn 0.2s ease;
}
aside#thread-sidebar.hidden { display: none; }
.thread-parent {
  padding: 0.8rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
  max-height: 200px;
  overflow-y: auto;
}
.thread-messages {
  flex: 1;
  overflow-y: auto;
  padding: 0.6rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.thread-msg {
  padding: 0.5rem 0.7rem;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
}
.thread-msg-header {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  margin-bottom: 0.2rem;
}
.thread-msg-sender { font-size: 0.75rem; color: var(--accent); font-weight: 600; }
.thread-msg-time { font-size: 0.7rem; color: var(--text-dim); }
.thread-count-btn {
  font-size: 0.78rem;
  color: var(--accent);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.2rem 0;
  margin-top: 0.2rem;
}
.thread-count-btn:hover { text-decoration: underline; }
.thread-input-area {
  border-top: 1px solid var(--border);
  padding: 0.6rem;
}
.thread-input-area form {
  display: flex;
  gap: 0.4rem;
  align-items: flex-end;
}
.thread-input-area textarea {
  flex: 1;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.5rem;
  color: var(--text);
  font-size: 0.88rem;
  resize: none;
  outline: none;
  font-family: inherit;
  max-height: 100px;
}
.thread-input-area textarea:focus { border-color: var(--accent); }

/* === Bot Command Autocomplete === */
.command-dropdown {
  position: absolute;
  bottom: 100%;
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  margin-bottom: 0.3rem;
  max-height: 200px;
  overflow-y: auto;
  z-index: 40;
}
.command-item {
  padding: 0.5rem 0.8rem;
  cursor: pointer;
  font-size: 0.85rem;
  transition: background 0.15s;
  display: flex;
  justify-content: space-between;
}
.command-item:hover, .command-item.active { background: var(--surface-2); }
.command-item-desc { color: var(--text-dim); font-size: 0.78rem; }

/* === Translation Bubble === */
.translation-bubble {
  border-left: 3px solid var(--warning);
  padding: 0.4rem 0.6rem;
  margin-top: 0.4rem;
  font-size: 0.85rem;
  color: var(--text-dim);
  background: rgba(243, 156, 18, 0.05);
  border-radius: 0 4px 4px 0;
}

/* === Call Overlay === */
.call-overlay {
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 500;
  display: flex;
  flex-direction: column;
}
.call-overlay.hidden { display: none; }
.call-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  color: #fff;
  z-index: 1;
}
#call-status { font-size: 1rem; font-weight: 500; }
#call-timer { font-size: 0.9rem; font-variant-numeric: tabular-nums; }
.call-video-area {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}
#remote-video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #111;
}
.local-pip {
  position: absolute;
  bottom: 1rem;
  right: 1rem;
  width: 160px;
  height: 120px;
  border-radius: var(--radius-sm);
  border: 2px solid rgba(255,255,255,0.3);
  object-fit: cover;
  z-index: 2;
}
.call-controls {
  display: flex;
  justify-content: center;
  gap: 1rem;
  padding: 1.5rem;
  z-index: 1;
}
.call-btn {
  background: rgba(255,255,255,0.15);
  border: none;
  color: #fff;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}
.call-btn:hover { background: rgba(255,255,255,0.25); }
.call-btn.active { background: var(--accent); }
.call-btn-danger { background: var(--danger); }
.call-btn-danger:hover { background: #c0392b; }
.incoming-call-icon { animation: pulse-rec 1.5s infinite; }

/* === Skills === */
.skills-input-wrapper {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.4rem 0.5rem;
  cursor: text;
  min-height: 42px;
}
.skills-input-wrapper:focus-within {
  border-color: var(--accent);
}
.skills-input-wrapper input {
  flex: 1;
  min-width: 120px;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 0.9rem;
  outline: none;
  padding: 0.2rem 0;
}
.skill-chips {
  display: contents;
}
.skill-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  background: var(--accent);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 500;
  padding: 0.2rem 0.5rem;
  border-radius: 99px;
  white-space: nowrap;
  line-height: 1.3;
}
.skill-chip-remove {
  background: none;
  border: none;
  color: rgba(255,255,255,0.7);
  font-size: 0.9rem;
  cursor: pointer;
  padding: 0;
  line-height: 1;
  display: flex;
  align-items: center;
}
.skill-chip-remove:hover {
  color: #fff;
}
.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.form-label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-dim);
}
.form-hint {
  font-size: 0.75rem;
  color: var(--text-dim);
}
.admin-user-skills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin-top: 0.3rem;
}
.admin-skill-badge {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 500;
  padding: 0.1rem 0.4rem;
  border-radius: 99px;
  white-space: nowrap;
}

/* === Stat Cards === */
.stat-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}
.stat-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.5rem;
  text-align: center;
}
.stat-value {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1.2;
}
.stat-label {
  font-size: 0.7rem;
  color: var(--text-dim);
  margin-top: 0.15rem;
}

/* === Sessions List === */
.sessions-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.session-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.7rem;
  font-size: 0.8rem;
}
.session-item.current {
  border-color: var(--accent);
}
.session-info {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
  flex: 1;
}
.session-device {
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.session-meta {
  color: var(--text-dim);
  font-size: 0.72rem;
}
.session-badge {
  font-size: 0.65rem;
  background: var(--accent);
  color: #fff;
  padding: 0.1rem 0.4rem;
  border-radius: 99px;
  margin-left: 0.4rem;
  white-space: nowrap;
}
.btn-revoke {
  background: var(--danger);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 0.25rem 0.6rem;
  font-size: 0.72rem;
  cursor: pointer;
  flex-shrink: 0;
  margin-left: 0.5rem;
}
.btn-revoke:hover { opacity: 0.85; }

/* === Admin Sessions === */
.admin-sessions {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.admin-session-group h5 {
  font-size: 0.82rem;
  margin-bottom: 0.3rem;
  color: var(--text);
}

/* === Admin Token Usage === */
.admin-token-filters {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  margin-bottom: 0.6rem;
  align-items: center;
}
.admin-token-filters select,
.admin-token-filters input[type="date"] {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 0.3rem 0.5rem;
  font-size: 0.8rem;
}
.btn-small {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 0.3rem 0.7rem;
  font-size: 0.8rem;
  cursor: pointer;
}
.btn-small:hover { background: var(--accent-hover); }

.subsection-title {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-dim);
  margin: 0.6rem 0 0.3rem;
}
.admin-table-wrap {
  overflow-x: auto;
}
.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
}
.admin-table th,
.admin-table td {
  padding: 0.35rem 0.5rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
}
.admin-table th {
  background: var(--surface-2);
  font-weight: 600;
  color: var(--text-dim);
  font-size: 0.72rem;
  text-transform: uppercase;
}
.admin-table td { color: var(--text); }
.admin-table tr:hover td { background: var(--surface-2); }

/* Admin user stats inline */
.admin-user-stats-toggle {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 6px;
  padding: 0.15rem 0.4rem;
  font-size: 0.68rem;
  cursor: pointer;
}
.admin-user-stats-toggle:hover { border-color: var(--accent); color: var(--accent); }
.admin-user-stats-inline {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  gap: 0.3rem;
  margin-top: 0.4rem;
  padding: 0.4rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.admin-user-stats-inline .stat-card {
  padding: 0.3rem;
}
.admin-user-stats-inline .stat-value {
  font-size: 0.95rem;
}
.admin-user-stats-inline .stat-label {
  font-size: 0.65rem;
}

/* === E2E Indicator === */
.e2e-indicator {
  font-size: 0.85rem;
  margin-left: 0.3rem;
  cursor: help;
}
.e2e-indicator.hidden { display: none; }

/* === Responsive for new elements === */
@media (max-width: 768px) {
  aside#thread-sidebar { width: 100%; max-width: 100%; }
  .kanban-board { padding: 0.5rem; gap: 0.5rem; }
  .kanban-column { width: 260px; min-width: 260px; }
  .gif-panel { width: 100%; max-width: 100%; bottom: 60px; left: 0; transform: none; border-radius: var(--radius) var(--radius) 0 0; }
  .local-pip { width: 100px; height: 75px; }
}
