* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

html {
  height: 100%;
  height: -webkit-fill-available;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #0a0a0a;
  color: #e0e0e0;
  height: 100%;
  overflow: hidden;
  position: fixed;
  width: 100%;
}

.container {
  max-width: 700px;
  margin: 0 auto;
  padding: 20px;
}

.center-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  position: fixed;
  inset: 0;
  gap: 20px;
  padding: 24px;
}

/* ═══ Home page ═══ */
.home-page {
  position: fixed;
  inset: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
}

.home-top {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 60px 24px 32px;
  gap: 12px;
  flex-shrink: 0;
}

.home-actions {
  display: flex;
  gap: 10px;
  margin-top: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

.btn-notif {
  font-size: 13px;
  padding: 10px 20px;
}

.btn-notif-room {
  padding: 5px 8px;
  color: #888;
}

.btn-notif-room:hover {
  color: #2563eb;
  border-color: #2563eb;
}

/* Rooms section */
.rooms-section {
  padding: 0 16px 32px;
  max-width: 600px;
  width: 100%;
  margin: 0 auto;
}

.rooms-title {
  font-size: 14px;
  font-weight: 600;
  color: #555;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
  padding-left: 4px;
}

.rooms-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.room-card {
  display: block;
  background: #141414;
  border: 1px solid #1e1e1e;
  border-radius: 12px;
  padding: 12px 14px;
  text-decoration: none;
  color: #e0e0e0;
  transition: all 0.15s;
}

.room-card:hover {
  background: #1a1a1a;
  border-color: #2563eb;
}

.room-card.room-closed {
  opacity: 0.7;
}

.room-card.room-offline {
  opacity: 0.45;
}

.room-card-header {
  display: flex;
  align-items: center;
  gap: 8px;
}

.room-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.room-dot-open {
  background: #4ade80;
  box-shadow: 0 0 6px rgba(74, 222, 128, 0.4);
}

.room-dot-closed {
  background: #f87171;
}

.room-dot-offline {
  background: #555;
}

.room-card-id {
  font-weight: 700;
  font-size: 15px;
  color: #fff;
}

.room-card-users {
  font-size: 12px;
  color: #666;
  margin-left: 4px;
}

/* ═══ Auth ═══ */
.auth-box {
  background: #141414;
  border: 1px solid #222;
  border-radius: 18px;
  padding: 28px 22px;
  max-width: 360px;
  width: calc(100% - 32px);
  position: relative;
}

.auth-box h3 {
  color: #fff;
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 6px;
}

.auth-desc {
  color: #666;
  font-size: 13px;
  margin-bottom: 16px;
  line-height: 1.4;
}

.auth-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  background: #0f0f0f;
  border-radius: 10px;
  padding: 3px;
}

.auth-tab {
  flex: 1;
  padding: 8px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: #888;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
}

.auth-tab.active {
  background: #222;
  color: #fff;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 4px;
}

.auth-input {
  background: #0f0f0f;
  border: 1px solid #262626;
  border-radius: 10px;
  padding: 12px 14px;
  color: #e0e0e0;
  font-size: 16px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
  width: 100%;
}

.auth-input:focus {
  border-color: #2563eb;
}

.btn-block {
  width: 100%;
  text-align: center;
}

.auth-error {
  color: #f87171;
  font-size: 13px;
  padding: 4px 0;
}

.auth-close {
  position: absolute;
  top: 12px;
  right: 14px;
  background: none;
  border: none;
  color: #555;
  font-size: 22px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
}

.auth-close:hover {
  color: #fff;
  background: #222;
}

.qr-wrap {
  text-align: center;
  margin: 16px 0;
}

.qr-wrap img {
  width: 180px;
  height: 180px;
  border-radius: 12px;
  background: #fff;
}

.secret-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  margin-top: 4px;
  width: 100%;
}

.secret-key {
  flex: 1;
  background: #0f0f0f;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 12px;
  color: #4ade80;
  word-break: break-all;
  border: 1px solid #1e1e1e;
}

/* Profile area (top-right) */
.profile-area {
  position: fixed;
  top: 12px;
  right: 14px;
  z-index: 60;
}

.profile-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: #2563eb;
  border: 2px solid rgba(255,255,255,0.1);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s;
  overflow: hidden;
  padding: 0;
}

.profile-avatar {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.profile-btn:active { transform: scale(0.9); }

.profile-initial {
  color: #fff;
  font-size: 15px;
  font-weight: 700;
}

.profile-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: rgba(22,22,22,0.95);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 14px;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  padding: 6px;
  min-width: 180px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  animation: menuIn 0.15s ease;
}

.profile-menu-name {
  padding: 10px 14px 8px;
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  border-bottom: 1px solid #222;
  margin-bottom: 4px;
}

.profile-menu-item {
  display: block;
  width: 100%;
  padding: 10px 14px;
  border: none;
  background: transparent;
  color: #ccc;
  font-size: 14px;
  font-family: inherit;
  text-align: left;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.12s;
}

.profile-menu-item:hover { background: rgba(255,255,255,0.08); }

.profile-menu-friends {
  display: flex !important;
  align-items: center;
  justify-content: space-between;
}

.friends-badge-menu {
  background: #ef4444;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  min-width: 20px;
  height: 20px;
  border-radius: 10px;
  padding: 0 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Room card with delete */
.room-card {
  position: relative;
}

.room-card-link {
  display: block;
  text-decoration: none;
  color: inherit;
}

.room-delete-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(239,68,68,0.15);
  border: none;
  color: #f87171;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.room-delete-btn:hover { background: rgba(239,68,68,0.3); }

/* Online users section */
.online-section {
  padding: 0 16px 20px;
  max-width: 600px;
  width: 100%;
  margin: 0 auto;
}

.online-list {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 6px;
  scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}
.online-list::-webkit-scrollbar {
  height: 4px;
}
.online-list::-webkit-scrollbar-thumb {
  background: #333;
  border-radius: 2px;
}
.online-chip {
  flex-shrink: 0;
  scroll-snap-align: start;
}

.online-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px 6px 6px;
  background: #141414;
  border: 1px solid #1e1e1e;
  border-radius: 22px;
  transition: all 0.15s;
  color: #e0e0e0;
}

.online-chip:hover {
  border-color: #333;
  background: #1a1a1a;
}

.online-chip-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #2563eb;
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
}

.online-chip-avatar-ph {
  background: #2563eb;
}

.online-chip-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4ade80;
  box-shadow: 0 0 6px rgba(74,222,128,0.4);
  flex-shrink: 0;
  margin-left: -6px;
  border: 2px solid #141414;
}

.online-chip-name {
  font-size: 13px;
  font-weight: 500;
}

.online-chip-action {
  background: transparent;
  border: 1px solid #262626;
  color: #aaa;
  border-radius: 14px;
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.online-chip-action:hover {
  border-color: #2563eb;
  color: #2563eb;
}

.online-chip-add {
  padding: 4px 8px;
  font-size: 14px;
  line-height: 1;
}

.room-card-msg {
  font-size: 13px;
  color: #555;
  margin-top: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

h1 {
  font-size: 52px;
  font-weight: 800;
  color: #fff;
  letter-spacing: -1px;
}

.subtitle {
  color: #666;
  font-size: 15px;
  margin-bottom: 8px;
  text-align: center;
}

/* Buttons */
.btn {
  padding: 12px 28px;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  cursor: pointer;
  transition: all 0.15s ease;
  font-weight: 600;
  touch-action: manipulation;
  -webkit-appearance: none;
}

.btn:active {
  transform: scale(0.96);
}

.btn-primary {
  background: #2563eb;
  color: #fff;
}

.btn-primary:hover {
  background: #1d4ed8;
}

.btn-sm {
  padding: 7px 12px;
  font-size: 12px;
  border-radius: 8px;
}

.btn-danger {
  background: #dc2626;
  color: #fff;
}

.btn-danger:hover {
  background: #b91c1c;
}

.btn-success {
  background: #16a34a;
  color: #fff;
}

.btn-success:hover {
  background: #15803d;
}

.btn-outline {
  background: transparent;
  border: 1px solid #2a2a2a;
  color: #aaa;
}

.btn-outline:hover {
  border-color: #444;
  background: #161616;
}

/* Room layout */
.room-page {
  display: flex;
  flex-direction: column;
  height: 100%;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  overflow: hidden;
}

.room-header {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid #1a1a1a;
  background: #111;
  position: sticky;
  top: 0;
  z-index: 10;
  gap: 8px;
  flex-shrink: 0;
}

.home-link {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  color: #666;
  text-decoration: none;
  transition: all 0.15s;
  flex-shrink: 0;
}

.home-link:hover {
  color: #fff;
  background: #1a1a1a;
}

/* Compact icon buttons in room header */
.icon-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: transparent;
  border: none;
  color: #888;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  flex-shrink: 0;
  padding: 0;
}

.icon-btn:hover { background: #1a1a1a; color: #fff; }
.icon-btn:active { transform: scale(0.9); }

.status-open { color: #4ade80; }
.status-closed { color: #f87171; }
.status-open:hover, .status-closed:hover { background: transparent; }
.icon-btn.icon-btn-clickable:hover { background: #1a1a1a; }
.icon-btn:not(.icon-btn-clickable):not(.icon-btn-webapp):not(#copyLinkBtn):not(#notifBtnRoom) { cursor: default; }

.icon-btn-webapp { color: #60a5fa; }
.icon-btn-webapp:hover { color: #93c5fd; background: rgba(37,99,235,0.12); }

.icon-btn-flash {
  color: #4ade80 !important;
  background: rgba(74,222,128,0.15) !important;
}

.user-count-compact {
  font-size: 12px;
  color: #666;
  padding: 0 4px;
}

body.light .icon-btn { color: #666; }
body.light .icon-btn:hover { background: #f0f0f0; color: #111; }

.room-header h2 {
  font-size: 16px;
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
  letter-spacing: -0.3px;
  margin-right: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.room-header h2 > span { display: inline-flex; align-items: center; gap: 8px; }

.room-info {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #666;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.3px;
  text-transform: uppercase;
}

.badge-closed {
  background: rgba(239, 68, 68, 0.15);
  color: #f87171;
}

.badge-open {
  background: rgba(34, 197, 94, 0.15);
  color: #4ade80;
}

/* Messages */
.messages-area {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.message {
  padding: 8px 12px;
  background: #161616;
  border-radius: 12px;
  position: relative;
  max-width: 88%;
  word-break: break-word;
  border: 1px solid #1e1e1e;
}

.message.own {
  align-self: flex-end;
  background: #172554;
  border-color: #1e3a5f;
}

.message.media-msg {
  background: transparent;
  border: none;
  padding: 2px;
}

.message.media-msg.own {
  background: transparent;
  border: none;
}

.message .msg-text {
  font-size: 14px;
  line-height: 1.45;
  padding-right: 24px;
}

/* Reply preview inside message */
.msg-reply-preview {
  background: rgba(37, 99, 235, 0.1);
  border-left: 3px solid #2563eb;
  border-radius: 6px;
  padding: 6px 10px;
  margin-bottom: 6px;
  cursor: pointer;
  font-size: 12px;
}
.msg-reply-author { color: #60a5fa; font-weight: 700; }
.msg-reply-text { color: #aaa; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Quote */
.msg-quote {
  border-left: 3px solid #888;
  padding: 4px 10px;
  margin-bottom: 6px;
  color: #aaa;
  font-size: 13px;
  font-style: italic;
  background: rgba(255,255,255,0.03);
  border-radius: 4px;
}

/* Reactions */
.msg-reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
  margin-bottom: -2px;
}
.msg-reaction {
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 12px;
  padding: 2px 8px;
  font-size: 12px;
  color: #ccc;
  cursor: pointer;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.msg-reaction:hover { background: rgba(255,255,255,0.1); }
.msg-reaction.mine {
  background: rgba(37,99,235,0.2);
  border-color: rgba(37,99,235,0.4);
  color: #60a5fa;
}
.msg-reaction span { font-size: 11px; font-weight: 600; }

.msg-edited {
  font-size: 10px;
  font-style: italic;
  color: #555;
  margin-right: 6px;
}

.msg-flash {
  animation: msgFlash 1.2s ease;
}
@keyframes msgFlash {
  0%, 100% { background: initial; }
  30% { background: rgba(37,99,235,0.25); }
}

/* Reply/edit bar above input */
.reply-bar {
  display: flex;
  align-items: center;
  padding: 8px 12px;
  background: rgba(37,99,235,0.1);
  border-top: 1px solid rgba(37,99,235,0.3);
  gap: 10px;
  flex-shrink: 0;
  animation: fadeIn 0.2s ease;
}
.reply-bar-icon { color: #2563eb; flex-shrink: 0; }
.reply-bar-content { flex: 1; min-width: 0; }
.reply-bar-title { font-size: 12px; font-weight: 700; color: #60a5fa; }
.reply-bar-text {
  font-size: 12px;
  color: #aaa;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.reply-bar-close {
  background: none;
  border: none;
  color: #888;
  font-size: 20px;
  cursor: pointer;
  padding: 0 8px;
}
.reply-bar-close:hover { color: #fff; }

/* Message menu popover */
.msg-menu {
  position: fixed;
  background: rgba(22,22,22,0.97);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 14px;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  padding: 6px;
  min-width: 220px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  z-index: 100;
  animation: menuIn 0.15s ease;
}

.msg-menu-reactions {
  display: flex;
  gap: 2px;
  padding: 4px 2px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  margin-bottom: 4px;
  overflow-x: auto;
  max-width: 100%;
  scrollbar-width: none;
}
.msg-menu-reactions::-webkit-scrollbar { display: none; }
.msg-menu { max-width: calc(100vw - 16px); }

.msg-menu-emoji {
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 8px;
  transition: transform 0.12s;
}
.msg-menu-emoji:hover { background: rgba(255,255,255,0.1); transform: scale(1.2); }

.msg-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border: none;
  background: transparent;
  color: #ccc;
  font-size: 14px;
  font-family: inherit;
  text-align: left;
  border-radius: 10px;
  cursor: pointer;
}
.msg-menu-item:hover { background: rgba(255,255,255,0.08); }
.msg-menu-item > span { font-size: 16px; opacity: 0.8; }

.msg-menu-danger { color: #f87171; }
.msg-menu-danger:hover { background: rgba(239,68,68,0.1); }

body.light .msg-reply-preview { background: rgba(37,99,235,0.08); }
body.light .msg-reply-author { color: #2563eb; }
body.light .msg-reply-text { color: #666; }
body.light .msg-quote { color: #666; background: rgba(0,0,0,0.04); }
body.light .msg-reaction { background: rgba(0,0,0,0.04); border-color: rgba(0,0,0,0.08); color: #333; }
body.light .msg-reaction:hover { background: rgba(0,0,0,0.08); }
body.light .msg-menu { background: rgba(255,255,255,0.98); border-color: rgba(0,0,0,0.1); }
body.light .msg-menu-item { color: #333; }
body.light .msg-menu-item:hover { background: rgba(0,0,0,0.05); }
body.light .reply-bar { background: rgba(37,99,235,0.05); }

.msg-bot-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}

.msg-bot-avatar {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  object-fit: cover;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #16a34a;
  color: #fff;
  font-size: 11px;
}

.msg-bot-avatar-ph { background: #16a34a; }

.msg-bot-label {
  font-size: 12px;
  color: #4ade80;
  font-weight: 700;
}

/* Inline keyboard */
.msg-keyboard {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-top: 8px;
}

.msg-keyboard-row {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}

.msg-kb-btn {
  flex: 1;
  min-width: 0;
  padding: 8px 12px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 10px;
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
  text-align: center;
  display: block;
}

.msg-kb-btn:hover {
  background: rgba(255,255,255,0.14);
  border-color: rgba(255,255,255,0.2);
}

.msg-kb-btn:active { transform: scale(0.97); }

.msg-kb-webapp {
  background: rgba(37,99,235,0.2);
  border-color: rgba(37,99,235,0.4);
  color: #60a5fa;
}

.msg-kb-webapp:hover { background: rgba(37,99,235,0.3); }

.msg-kb-disabled {
  opacity: 0.5;
  cursor: default;
}

/* Mini-app overlay */
.webapp-overlay {
  padding: 0;
  z-index: 200;
}

.webapp-frame-wrap {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: #111;
}

.webapp-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: #0a0a0a;
  border-bottom: 1px solid #1a1a1a;
  color: #888;
  font-size: 13px;
}

.webapp-close {
  background: none;
  border: none;
  color: #888;
  font-size: 24px;
  cursor: pointer;
  padding: 4px 12px;
  border-radius: 6px;
}
.webapp-close:hover { color: #fff; background: #222; }

.webapp-frame {
  flex: 1;
  width: 100%;
  border: none;
  background: #fff;
}

/* Commands menu */
.commands-menu {
  position: absolute;
  bottom: 100%;
  left: 12px;
  right: 12px;
  background: rgba(22,22,22,0.95);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 14px;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  padding: 6px;
  margin-bottom: 8px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  max-height: 200px;
  overflow-y: auto;
  z-index: 30;
}

.cmd-item {
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  color: #ccc;
  display: flex;
  gap: 8px;
  align-items: baseline;
}
.cmd-item:hover { background: rgba(255,255,255,0.08); }
.cmd-item b { color: #4ade80; font-family: ui-monospace, monospace; }
.cmd-item span { color: #888; font-size: 12px; }

body.light .msg-kb-btn { background: rgba(0,0,0,0.06); border-color: rgba(0,0,0,0.1); color: #111; }
body.light .msg-kb-btn:hover { background: rgba(0,0,0,0.1); }
body.light .msg-keyboard-row .msg-kb-webapp { color: #2563eb; }
body.light .commands-menu { background: rgba(255,255,255,0.98); border-color: rgba(0,0,0,0.1); }
body.light .cmd-item { color: #333; }
body.light .cmd-item b { color: #16a34a; }
body.light .webapp-frame-wrap { background: #fff; }
body.light .webapp-header { background: #fff; border-color: #eee; }

.message .msg-time {
  font-size: 10px;
  color: #555;
  margin-top: 3px;
}

.message .delete-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  background: none;
  border: none;
  color: #444;
  cursor: pointer;
  font-size: 16px;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s;
}

.message:hover .delete-btn,
.message .delete-btn.visible {
  opacity: 1;
}

.message .delete-btn:hover,
.message .delete-btn:active {
  color: #ef4444;
  background: rgba(239, 68, 68, 0.1);
}

/* Input area */
.input-area {
  padding: 12px 14px 16px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  background: transparent;
  display: flex;
  align-items: flex-end;
  flex-shrink: 0;
  position: relative;
}

.input-glass {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  width: 100%;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 24px;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  padding: 4px 6px;
  position: relative;
}

.input-glass textarea {
  flex: 1;
  background: transparent;
  border: none;
  padding: 8px 6px;
  color: #e0e0e0;
  font-size: 15px;
  font-family: inherit;
  resize: none;
  outline: none;
  min-height: 36px;
  max-height: 100px;
  line-height: 1.4;
}

.input-glass textarea::placeholder {
  color: #666;
}

.input-icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: transparent;
  border: none;
  color: #666;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s;
  touch-action: manipulation;
}

.input-icon-btn:active {
  transform: scale(0.88);
}

.input-icon-btn:hover {
  color: #ccc;
}

.plus-btn.active {
  color: #2563eb;
  transform: rotate(45deg);
}

.send-btn-new {
  color: #2563eb;
  animation: fadeScale 0.15s ease;
}

.send-btn-new:hover {
  color: #60a5fa;
}

@keyframes fadeScale {
  from { opacity: 0; transform: scale(0.5); }
  to { opacity: 1; transform: scale(1); }
}

/* Plus menu */
.plus-menu {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 6px;
  background: rgba(30, 30, 30, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 14px;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 160px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  animation: menuIn 0.15s ease;
  z-index: 20;
}

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

.plus-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border: none;
  background: transparent;
  color: #ccc;
  font-size: 14px;
  font-family: inherit;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.12s;
  touch-action: manipulation;
}

.plus-menu-item:hover {
  background: rgba(255, 255, 255, 0.08);
}

.plus-menu-item:active {
  background: rgba(255, 255, 255, 0.12);
}

.plus-menu-item svg {
  flex-shrink: 0;
  color: #888;
}

/* Typing preview */
.typing-preview {
  padding: 6px 14px;
  font-size: 12px;
  color: #555;
  font-style: italic;
  background: #0d0d0d;
  min-height: 28px;
  word-break: break-word;
  flex-shrink: 0;
  overflow: hidden;
  max-height: 48px;
}

.typing-preview:empty {
  min-height: 0;
  padding: 0;
}

.typing-preview span {
  color: #4ade80;
  font-weight: 500;
}

/* Waiting/approval overlay */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.overlay-box {
  background: #161616;
  padding: 28px 24px;
  border-radius: 16px;
  text-align: center;
  max-width: 340px;
  width: 100%;
  border: 1px solid #222;
}

.overlay-box h3 {
  margin-bottom: 10px;
  color: #fff;
  font-size: 18px;
  font-weight: 700;
}

.overlay-box p {
  color: #777;
  margin-bottom: 20px;
  font-size: 14px;
  line-height: 1.5;
}

.loader {
  margin: 0 auto;
  width: 28px;
  height: 28px;
  border: 2.5px solid #222;
  border-top-color: #2563eb;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* Join requests */
.join-requests {
  position: fixed;
  top: 60px;
  right: 12px;
  left: 12px;
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.join-request-card {
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  animation: slideDown 0.3s ease;
  pointer-events: all;
  margin-left: auto;
  max-width: 360px;
  width: 100%;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

@keyframes slideDown {
  from { transform: translateY(-20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.join-request-card span {
  font-size: 13px;
  color: #cbd5e1;
  flex: 1;
}

/* Error page */
.error-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  gap: 12px;
}

.error-page h2 {
  color: #ef4444;
}

.hidden {
  display: none !important;
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 4px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: #222;
  border-radius: 2px;
}

/* Mobile touch: always show delete on mobile */
@media (hover: none) and (pointer: coarse) {
  .message .delete-btn {
    opacity: 0.5;
  }
}

/* Small screens */
@media (max-width: 480px) {
  h1 {
    font-size: 40px;
  }

  .room-header {
    padding: 8px 10px;
    gap: 6px;
  }

  .room-header h2 {
    font-size: 14px;
  }

  .room-info {
    gap: 4px;
  }

  .home-link {
    width: 28px;
    height: 28px;
  }

  .home-link svg {
    width: 16px;
    height: 16px;
  }


  .messages-area {
    padding: 10px;
  }

  .message {
    max-width: 92%;
    padding: 8px 10px;
  }

  .message .msg-text {
    font-size: 14px;
  }

  .input-area {
    padding: 10px 10px 14px;
    padding-bottom: max(14px, env(safe-area-inset-bottom));
  }

  .input-glass textarea {
    font-size: 16px; /* prevent iOS zoom */
  }

  .typing-preview {
    padding: 5px 10px;
    font-size: 11px;
    max-height: 36px;
  }

  .overlay-box {
    padding: 24px 20px;
  }

  .btn-sm {
    padding: 6px 10px;
    font-size: 11px;
  }
}

/* (attach/mic/vid buttons moved into plus menu) */

/* File preview bar */
.file-preview {
  padding: 8px 12px;
  background: #141414;
  border-top: 1px solid #1a1a1a;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-shrink: 0;
  animation: fadeIn 0.2s ease;
}

.file-preview-info {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

.file-preview-info span {
  font-size: 13px;
  color: #ccc;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-preview-size {
  color: #555 !important;
  flex-shrink: 0;
}

.file-preview-remove {
  background: none;
  border: none;
  color: #555;
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  flex-shrink: 0;
}

.file-preview-remove:hover {
  color: #ef4444;
  background: rgba(239, 68, 68, 0.1);
}

/* Upload progress */
.upload-progress {
  height: 3px;
  background: #1a1a1a;
  flex-shrink: 0;
  overflow: hidden;
}

.upload-bar {
  height: 100%;
  background: #2563eb;
  width: 0%;
  transition: width 0.2s ease;
  border-radius: 2px;
}

/* Message attachments */
.msg-attachment {
  margin-bottom: 6px;
}

.msg-image {
  max-width: 100%;
  max-height: 280px;
  border-radius: 8px;
  cursor: pointer;
  display: block;
  object-fit: cover;
}

.msg-video {
  max-width: 100%;
  max-height: 280px;
  border-radius: 8px;
  display: block;
  background: #000;
}

.msg-audio {
  width: 100%;
  max-width: 300px;
  height: 36px;
  display: block;
}

.msg-file-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: rgba(255,255,255,0.04);
  border: 1px solid #262626;
  border-radius: 8px;
  text-decoration: none;
  color: #ccc;
  font-size: 13px;
  transition: background 0.15s;
}

.msg-file-link:hover {
  background: rgba(255,255,255,0.08);
}

.msg-file-link small {
  color: #555;
  margin-left: auto;
  flex-shrink: 0;
}

/* Lightbox */
#lightbox {
  cursor: zoom-out;
  background: rgba(0, 0, 0, 0.95);
  padding: 20px;
}

#lightboxImg {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 4px;
}

/* Drag over */
.room-page.drag-over {
  outline: 2px dashed #2563eb;
  outline-offset: -4px;
}

/* (mic/vid buttons are now inside plus-menu) */

/* ═══ Voice recording bar ═══ */
.voice-rec-bar {
  padding: 8px 12px;
  background: #1a0a0a;
  border-top: 1px solid #2a1515;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  animation: fadeIn 0.2s ease;
}

.voice-rec-pulse {
  width: 10px;
  height: 10px;
  background: #ef4444;
  border-radius: 50%;
  animation: pulse 1s ease infinite;
  flex-shrink: 0;
}

.voice-rec-timer {
  font-size: 14px;
  font-weight: 600;
  color: #ef4444;
  font-variant-numeric: tabular-nums;
  min-width: 36px;
}

.voice-rec-label {
  font-size: 13px;
  color: #888;
  flex: 1;
}

.voice-rec-action {
  padding: 6px 14px;
  border: none;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}
.voice-rec-action.cancel {
  background: #262626;
  color: #aaa;
}
.voice-rec-action.cancel:hover { background: #333; }
.voice-rec-action.send {
  background: #2563eb;
  color: #fff;
}
.voice-rec-action.send:hover { background: #1d4ed8; }

/* ═══ Video circle record overlay ═══ */
.video-record-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
}

.video-circle-wrapper {
  width: 200px;
  height: 200px;
  position: relative;
  border-radius: 50%;
  overflow: hidden;
}

.video-circle-wrapper video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.video-circle-ring {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.video-timer {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.6);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  padding: 2px 10px;
  border-radius: 10px;
  font-variant-numeric: tabular-nums;
  z-index: 2;
}

.video-record-controls {
  display: flex;
  align-items: center;
  gap: 16px;
}

.rec-control-btn {
  border: none;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  padding: 10px 20px;
  touch-action: manipulation;
  transition: all 0.15s;
}
.rec-control-btn:active { transform: scale(0.94); }

.rec-cancel {
  background: #262626;
  color: #aaa;
}
.rec-cancel:hover { background: #333; }

.rec-stop {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #ef4444;
  color: #fff;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.rec-stop:hover { background: #dc2626; }

.rec-send {
  background: #2563eb;
  color: #fff;
}
.rec-send:hover { background: #1d4ed8; }

/* ═══ Video circle in messages ═══ */
.video-circle-msg {
  background: transparent !important;
  border: none !important;
  padding: 4px !important;
}

.msg-video-circle-wrap {
  width: 200px;
  height: 200px;
  border-radius: 50%;
  overflow: hidden;
  position: relative;
  cursor: pointer;
  border: 3px solid #2563eb;
  box-shadow: 0 0 20px rgba(37, 99, 235, 0.2);
}

.msg-video-circle {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.circle-play-icon {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.3);
  cursor: pointer;
  transition: opacity 0.15s;
}
.circle-play-icon:hover { background: rgba(0,0,0,0.4); }

.video-circle-msg .msg-time {
  text-align: center;
}
.video-circle-msg .delete-btn {
  top: -4px;
  right: -4px;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.8); }
}

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

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ═══ Mobile adjustments for recording ═══ */
@media (max-width: 480px) {
  .video-circle-wrapper {
    width: 180px;
    height: 180px;
  }
  .video-circle-wrapper .video-circle-ring {
    width: 180px;
    height: 180px;
  }
  .msg-video-circle-wrap {
    width: 160px;
    height: 160px;
  }
  .voice-rec-bar {
    padding: 6px 10px;
    gap: 8px;
  }
  .voice-rec-action {
    padding: 5px 10px;
    font-size: 11px;
  }
}

/* ═══════════════════════════════════════════════════
   LIGHT THEME
   ═══════════════════════════════════════════════════ */
body.light {
  background: #f5f5f5;
  color: #1a1a1a;
}

body.light .home-page { background: #f5f5f5; }
body.light .room-header { background: #fff; border-color: #e0e0e0; }
body.light .room-header h2 { color: #111; }
body.light .room-info { color: #888; }
body.light .home-top h1 { color: #111; }
body.light .subtitle { color: #888; }

body.light .message { background: #fff; border-color: #e5e5e5; color: #1a1a1a; }
body.light .message.own { background: #dbeafe; border-color: #bfdbfe; }
body.light .message .msg-text { color: #1a1a1a; }
body.light .message .msg-time { color: #999; }
body.light .message .delete-btn { color: #bbb; }
body.light .message.media-msg { background: transparent; border: none; }
body.light .message.media-msg.own { background: transparent; border: none; }

body.light .messages-area { background: #f0f0f0; }

body.light .input-glass {
  background: rgba(255,255,255,0.8);
  border-color: rgba(0,0,0,0.1);
}
body.light .input-glass textarea { color: #1a1a1a; }
body.light .input-glass textarea::placeholder { color: #999; }
body.light .plus-btn { color: #666; }
body.light .send-btn-new { color: #2563eb; }

body.light .plus-menu {
  background: rgba(255,255,255,0.95);
  border-color: rgba(0,0,0,0.1);
}
body.light .plus-menu-item { color: #333; }
body.light .plus-menu-item:hover { background: rgba(0,0,0,0.05); }

body.light .typing-preview { background: #e8e8e8; color: #888; }

body.light .room-card { background: #fff; border-color: #e5e5e5; }
body.light .room-card:hover { border-color: #2563eb; }
body.light .room-card-id { color: #111; }
body.light .room-card-msg { color: #888; }

body.light .overlay { background: rgba(0,0,0,0.5); }
body.light .auth-box { background: #fff; border-color: #e0e0e0; }
body.light .auth-box h3 { color: #111; }
body.light .auth-input { background: #f5f5f5; border-color: #ddd; color: #111; }
body.light .auth-tabs { background: #f0f0f0; }
body.light .auth-tab { color: #888; }
body.light .auth-tab.active { background: #fff; color: #111; }
body.light .secret-key { background: #f5f5f5; border-color: #e0e0e0; color: #16a34a; }

body.light .profile-menu { background: rgba(255,255,255,0.95); border-color: rgba(0,0,0,0.1); }
body.light .profile-menu-name { color: #111; border-color: #eee; }
body.light .profile-menu-item { color: #333; }
body.light .profile-menu-item:hover { background: rgba(0,0,0,0.05); }

body.light .btn-outline { border-color: #ddd; color: #555; }
body.light .btn-outline:hover { background: #f0f0f0; border-color: #bbb; }

body.light .badge-closed { background: rgba(239,68,68,0.1); }
body.light .badge-open { background: rgba(34,197,94,0.1); }

body.light .online-chip { background: #fff; border-color: #e5e5e5; color: #333; }
body.light .online-chip:hover { border-color: #2563eb; }

body.light .file-preview { background: #f5f5f5; border-color: #e0e0e0; }
body.light .file-preview-info span { color: #333; }
body.light .voice-rec-bar { background: #fef2f2; border-color: #fecaca; }

body.light .msg-file-link { background: rgba(0,0,0,0.03); border-color: #e0e0e0; color: #333; }
body.light .msg-file-link:hover { background: rgba(0,0,0,0.06); }

body.light .home-link { color: #999; }
body.light .home-link:hover { color: #111; background: #eee; }

body.light .input-area { background: transparent; }

body.light .rooms-title { color: #999; }

/* ═══ Friends sidebar ═══ */
.friends-toggle {
  position: fixed;
  bottom: 20px;
  left: 20px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: #2563eb;
  border: none;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(37,99,235,0.4);
  z-index: 55;
}

.friends-toggle:active { transform: scale(0.95); }

.friends-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  background: #ef4444;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  padding: 0 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #0a0a0a;
}

.friends-toggle-pulse {
  animation: pulseGlow 1s ease infinite;
}

@keyframes pulseGlow {
  0%, 100% { box-shadow: 0 4px 16px rgba(37,99,235,0.4); }
  50% { box-shadow: 0 4px 32px rgba(239,68,68,0.6); }
}

.friends-sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 320px;
  max-width: 90vw;
  background: #111;
  border-right: 1px solid #222;
  z-index: 70;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  animation: slideRight 0.2s ease;
  box-shadow: 4px 0 32px rgba(0,0,0,0.5);
}

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

.friends-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid #222;
}

.friends-header h3 {
  color: #fff;
  font-size: 16px;
  font-weight: 700;
}

.friends-close {
  background: none;
  border: none;
  color: #666;
  font-size: 24px;
  cursor: pointer;
  padding: 4px 10px;
  border-radius: 6px;
}
.friends-close:hover { color: #fff; background: #222; }

.friends-section {
  padding: 12px 14px;
}

.friends-section h4 {
  color: #666;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
  padding-left: 4px;
}

.friends-empty {
  color: #444;
  font-size: 13px;
  padding: 8px 4px;
}

.friend-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  background: #161616;
  border: 1px solid #1e1e1e;
  border-radius: 10px;
  margin-bottom: 6px;
}

.friend-row-pending {
  border-color: #2563eb;
  background: rgba(37,99,235,0.08);
}

.friend-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #2563eb;
  color: #fff;
  font-size: 14px;
  font-weight: 700;
}

.friend-avatar-ph { background: #2563eb; }

.friend-name {
  flex: 1;
  font-size: 13px;
  font-weight: 500;
  color: #e0e0e0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.friend-status {
  font-size: 11px;
  color: #666;
  font-style: italic;
}

.friend-remove-btn {
  background: none;
  border: none;
  color: #555;
  font-size: 18px;
  cursor: pointer;
  padding: 2px 8px;
  border-radius: 6px;
}

.friend-remove-btn:hover { color: #ef4444; background: rgba(239,68,68,0.1); }

/* Avatars modal */
.avatars-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 14px;
  max-height: 400px;
  overflow-y: auto;
}

.avatar-cell {
  position: relative;
  aspect-ratio: 1;
  border-radius: 12px;
  overflow: hidden;
  background: #0f0f0f;
  border: 2px solid transparent;
}

.avatar-cell.avatar-current {
  border-color: #2563eb;
}

.avatar-cell img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.avatar-actions {
  position: absolute;
  inset: auto 0 0 0;
  padding: 6px;
  background: linear-gradient(to top, rgba(0,0,0,0.9), transparent);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 4px;
}

.avatar-actions .btn {
  padding: 4px 8px;
  font-size: 11px;
}

.avatar-tag {
  font-size: 10px;
  color: #4ade80;
  font-weight: 700;
  padding: 4px 6px;
  background: rgba(74,222,128,0.15);
  border-radius: 6px;
}

/* Light theme friends sidebar */
body.light .friends-sidebar { background: #fff; border-color: #e5e5e5; }
body.light .friends-header { border-color: #eee; }
body.light .friends-header h3 { color: #111; }
body.light .friends-close { color: #888; }
body.light .friends-close:hover { color: #111; background: #f0f0f0; }
body.light .friend-row { background: #fafafa; border-color: #eee; }
body.light .friend-name { color: #111; }
body.light .friends-section h4 { color: #888; }
body.light .online-chip { background: #fff; border-color: #e5e5e5; color: #333; }
body.light .online-chip-dot { border-color: #fff; }
body.light .online-chip-action { border-color: #ddd; color: #666; }
body.light .avatar-cell { background: #f0f0f0; }

/* ═══ DM cards ═══ */
.dm-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: #141414;
  border: 1px solid #1e1e1e;
  border-radius: 12px;
  text-decoration: none;
  color: #e0e0e0;
  transition: all 0.15s;
}

.dm-card:hover {
  border-color: #2563eb;
  background: #1a1a1a;
}

.dm-avatar-wrap {
  position: relative;
  flex-shrink: 0;
}

.dm-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #2563eb;
  color: #fff;
  font-size: 16px;
  font-weight: 700;
}

.dm-avatar-ph { background: #2563eb; }
.dm-avatar-bot { background: linear-gradient(135deg, #16a34a, #22c55e); font-size: 20px; }

.bot-sub {
  font-size: 11px;
  color: #666;
  font-weight: 400;
  margin-left: 4px;
}

body.light .bot-sub { color: #999; }

.dm-online-dot {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: #4ade80;
  border: 2px solid #141414;
}

.dm-card-body {
  min-width: 0;
  flex: 1;
}

.dm-card-name {
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dm-card-msg {
  font-size: 12px;
  color: #666;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* DM header in room */
.dm-header {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.dm-header-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #2563eb;
  color: #fff;
  font-size: 13px;
  font-weight: 700;
}

.dm-header-avatar-ph { background: #2563eb; }

/* Room avatar on card and header */
.room-card-avatar {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  object-fit: cover;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #2563eb, #60a5fa);
  font-size: 20px;
}
.room-card-avatar-ph { background: linear-gradient(135deg, #2563eb, #60a5fa); }

.room-card-link-flex { display: flex; gap: 10px; align-items: center; text-decoration: none; color: inherit; }
.room-card-body { flex: 1; min-width: 0; }
.room-card-sub { font-size: 11px; color: #555; margin-left: 6px; font-weight: 400; }

#roomTitle { cursor: pointer; }
#roomTitle:hover { opacity: 0.85; }
#roomHeaderAvatar { border-radius: 8px !important; }

/* Members list */
.members-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 300px;
  overflow-y: auto;
}
.member-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  background: #141414;
  border: 1px solid #1e1e1e;
  border-radius: 10px;
  flex-wrap: wrap;
}
.member-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #2563eb;
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  flex-shrink: 0;
}
.member-avatar-ph { background: #2563eb; }
.member-name { flex: 1; font-size: 14px; color: #fff; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.member-badge {
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
}
.member-badge-creator { background: rgba(251,191,36,0.15); color: #fbbf24; }
.member-badge-admin { background: rgba(37,99,235,0.15); color: #60a5fa; }
.member-badge-online { background: transparent; color: #4ade80; padding: 0; }
.member-action {
  background: transparent;
  border: 1px solid #333;
  color: #aaa;
  border-radius: 8px;
  padding: 4px 10px;
  font-size: 11px;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
}
.member-action:hover { border-color: #555; color: #fff; }
.member-action-kick { border-color: rgba(239,68,68,0.3); color: #f87171; }
.member-action-kick:hover { background: rgba(239,68,68,0.1); color: #f87171; border-color: #ef4444; }

body.light .member-row { background: #fafafa; border-color: #eee; }
body.light .member-name { color: #111; }
body.light .member-action { border-color: #ddd; color: #555; }
body.light .member-action:hover { color: #111; border-color: #aaa; }
body.light .room-card-avatar-ph { background: linear-gradient(135deg, #2563eb, #60a5fa); }

body.light .dm-card { background: #fff; border-color: #e5e5e5; }
body.light .dm-card-name { color: #111; }
body.light .dm-online-dot { border-color: #fff; }

/* ═══ Bots ═══ */
.bots-list {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 300px;
  overflow-y: auto;
}

.bots-cabinet {
  max-height: 85vh;
  overflow-y: auto;
}

.bot-card {
  background: #0f0f0f;
  border: 1px solid #222;
  border-radius: 12px;
  padding: 10px 12px;
}

.bot-card-clickable {
  transition: border-color 0.15s;
}
.bot-card-clickable:hover {
  border-color: #2563eb;
}

.bot-card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  margin-bottom: 8px;
}

.bot-list-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #16a34a, #22c55e);
  font-size: 16px;
  flex-shrink: 0;
}

.bot-card-chevron {
  margin-left: auto;
  color: #666;
  font-size: 20px;
}

.bot-card-actions {
  display: flex;
  gap: 6px;
}
.bot-card-actions .btn { flex: 1; }

/* Detail view */
.bot-back-btn {
  background: none;
  border: none;
  color: #888;
  font-size: 14px;
  cursor: pointer;
  padding: 4px 0;
  margin-bottom: 12px;
}
.bot-back-btn:hover { color: #fff; }

.bot-detail-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding-bottom: 16px;
  border-bottom: 1px solid #222;
  margin-bottom: 16px;
}

.bot-detail-avatar-wrap {
  position: relative;
  flex-shrink: 0;
}

.bot-detail-avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  object-fit: cover;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #16a34a, #22c55e);
  font-size: 32px;
}

.bot-detail-avatar-ph { background: linear-gradient(135deg, #16a34a, #22c55e); }

.bot-avatar-edit {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #2563eb;
  border: 2px solid #141414;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.bot-detail-name {
  flex: 1;
}

.bot-detail-name > span {
  display: block;
  font-size: 18px;
  font-weight: 700;
  color: #fff;
}

.bot-avatar-remove {
  background: none;
  border: none;
  color: #888;
  font-size: 12px;
  cursor: pointer;
  padding: 4px 0;
  margin-top: 2px;
}
.bot-avatar-remove:hover { color: #ef4444; }

.bot-field {
  margin-bottom: 16px;
}

.bot-field > label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 700;
  color: #666;
  margin-bottom: 6px;
}

.bot-field-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.bot-field-row .auth-input { flex: 1; min-width: 0; }
.bot-field-row .bot-token { flex: 1; }

.bot-toggle-label {
  display: flex !important;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  color: #ccc !important;
  font-size: 14px !important;
  font-weight: 600 !important;
  text-transform: none !important;
  letter-spacing: normal !important;
}

.bot-toggle-label input { width: 40px; height: 22px; accent-color: #2563eb; cursor: pointer; }

.bot-hint {
  font-size: 11px;
  color: #666;
  margin-top: 6px;
}

.bot-link-btn {
  background: none;
  border: none;
  color: #2563eb;
  font-size: 13px;
  cursor: pointer;
  padding: 6px 0;
  margin-top: 6px;
}
.bot-link-btn:hover { text-decoration: underline; }

.bot-danger-zone {
  padding-top: 16px;
  border-top: 1px solid #222;
}

.bot-help-link {
  display: block;
  text-align: center;
  padding: 12px;
  color: #2563eb;
  text-decoration: none;
  font-size: 13px;
  margin-top: 12px;
}
.bot-help-link:hover { text-decoration: underline; }

body.light .bot-card-header { color: #111; }
body.light .bot-back-btn { color: #666; }
body.light .bot-detail-header { border-color: #eee; }
body.light .bot-detail-name > span { color: #111; }
body.light .bot-danger-zone { border-color: #eee; }
body.light .bot-toggle-label { color: #333 !important; }

.bot-card-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.bot-name {
  font-weight: 700;
  color: #4ade80;
  font-size: 14px;
}

.bot-token-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.bot-token {
  flex: 1;
  background: #1a1a1a;
  color: #fbbf24;
  font-size: 11px;
  padding: 6px 10px;
  border-radius: 6px;
  word-break: break-all;
  font-family: ui-monospace, 'SF Mono', Monaco, monospace;
  min-width: 0;
}

.bot-help {
  margin-top: 14px;
  border-top: 1px solid #222;
  padding-top: 12px;
}

.bot-help summary {
  color: #888;
  font-size: 13px;
  cursor: pointer;
  padding: 6px 4px;
  user-select: none;
}
.bot-help summary:hover { color: #ccc; }

.bot-code {
  background: #0f0f0f;
  border: 1px solid #1e1e1e;
  border-radius: 8px;
  padding: 12px;
  font-size: 11px;
  line-height: 1.5;
  color: #ccc;
  overflow-x: auto;
  margin-top: 8px;
  white-space: pre;
}

body.light .bot-card { background: #f9f9f9; border-color: #e5e5e5; }
body.light .bot-token { background: #fff; color: #b45309; border: 1px solid #e5e5e5; }
body.light .bot-code { background: #f5f5f5; border-color: #e5e5e5; color: #333; }
body.light .bot-help { border-color: #e5e5e5; }

/* DM toast */
.dm-toast {
  position: fixed;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  background: #2563eb;
  color: #fff;
  padding: 12px 20px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 8px 32px rgba(37,99,235,0.4);
  animation: dmIn 0.3s ease;
  z-index: 200;
  max-width: 90%;
}

@keyframes dmIn {
  from { opacity: 0; transform: translate(-50%, -10px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}
